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 | |
| 33 | #include "ipw2200.h" |
| 34 | |
Zhu Yi | ae4af61 | 2006-04-13 17:20:34 +0800 | [diff] [blame] | 35 | |
| 36 | #ifndef KBUILD_EXTMOD |
| 37 | #define VK "k" |
| 38 | #else |
| 39 | #define VK |
| 40 | #endif |
| 41 | |
| 42 | #ifdef CONFIG_IPW2200_DEBUG |
| 43 | #define VD "d" |
| 44 | #else |
| 45 | #define VD |
| 46 | #endif |
| 47 | |
| 48 | #ifdef CONFIG_IPW2200_MONITOR |
| 49 | #define VM "m" |
| 50 | #else |
| 51 | #define VM |
| 52 | #endif |
| 53 | |
| 54 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 55 | #define VP "p" |
| 56 | #else |
| 57 | #define VP |
| 58 | #endif |
| 59 | |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 60 | #ifdef CONFIG_IPW2200_RADIOTAP |
Zhu Yi | ae4af61 | 2006-04-13 17:20:34 +0800 | [diff] [blame] | 61 | #define VR "r" |
| 62 | #else |
| 63 | #define VR |
| 64 | #endif |
| 65 | |
| 66 | #ifdef CONFIG_IPW2200_QOS |
| 67 | #define VQ "q" |
| 68 | #else |
| 69 | #define VQ |
| 70 | #endif |
| 71 | |
Zhu Yi | ee2c4ad | 2007-07-12 16:09:47 +0800 | [diff] [blame] | 72 | #define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 73 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" |
Zhu Yi | 171e7b2 | 2006-02-15 07:17:56 +0800 | [diff] [blame] | 74 | #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation" |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 75 | #define DRV_VERSION IPW2200_VERSION |
| 76 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 77 | #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1) |
| 78 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 79 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 80 | MODULE_VERSION(DRV_VERSION); |
| 81 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 82 | MODULE_LICENSE("GPL"); |
Ben Hutchings | 873395a | 2009-11-07 21:59:10 +0000 | [diff] [blame^] | 83 | MODULE_FIRMWARE("ipw2200-ibss.fw"); |
| 84 | #ifdef CONFIG_IPW2200_MONITOR |
| 85 | MODULE_FIRMWARE("ipw2200-sniffer.fw"); |
| 86 | #endif |
| 87 | MODULE_FIRMWARE("ipw2200-bss.fw"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 88 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 89 | static int cmdlog = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 90 | static int debug = 0; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 91 | static int default_channel = 0; |
| 92 | static int network_mode = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 93 | |
| 94 | static u32 ipw_debug_level; |
Tim Gardner | 5c7f9b7 | 2008-10-14 10:38:03 -0600 | [diff] [blame] | 95 | static int associate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 96 | static int auto_create = 1; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 97 | static int led_support = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 98 | static int disable = 0; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 99 | static int bt_coexist = 0; |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 100 | static int hwcrypto = 0; |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 101 | static int roaming = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 102 | static const char ipw_modes[] = { |
| 103 | 'a', 'b', 'g', '?' |
| 104 | }; |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 105 | static int antenna = CFG_SYS_ANTENNA_BOTH; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 106 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 107 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 108 | static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */ |
| 109 | #endif |
| 110 | |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 111 | static struct ieee80211_rate ipw2200_rates[] = { |
| 112 | { .bitrate = 10 }, |
| 113 | { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 114 | { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 115 | { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 116 | { .bitrate = 60 }, |
| 117 | { .bitrate = 90 }, |
| 118 | { .bitrate = 120 }, |
| 119 | { .bitrate = 180 }, |
| 120 | { .bitrate = 240 }, |
| 121 | { .bitrate = 360 }, |
| 122 | { .bitrate = 480 }, |
| 123 | { .bitrate = 540 } |
| 124 | }; |
| 125 | |
| 126 | #define ipw2200_a_rates (ipw2200_rates + 4) |
| 127 | #define ipw2200_num_a_rates 8 |
| 128 | #define ipw2200_bg_rates (ipw2200_rates + 0) |
| 129 | #define ipw2200_num_bg_rates 12 |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 130 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 131 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 132 | static int qos_enable = 0; |
| 133 | static int qos_burst_enable = 0; |
| 134 | static int qos_no_ack_mask = 0; |
| 135 | static int burst_duration_CCK = 0; |
| 136 | static int burst_duration_OFDM = 0; |
| 137 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 138 | static struct libipw_qos_parameters def_qos_parameters_OFDM = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 139 | {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, |
| 140 | QOS_TX3_CW_MIN_OFDM}, |
| 141 | {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, |
| 142 | QOS_TX3_CW_MAX_OFDM}, |
| 143 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 144 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 145 | {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, |
| 146 | QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} |
| 147 | }; |
| 148 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 149 | static struct libipw_qos_parameters def_qos_parameters_CCK = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 150 | {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, |
| 151 | QOS_TX3_CW_MIN_CCK}, |
| 152 | {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, |
| 153 | QOS_TX3_CW_MAX_CCK}, |
| 154 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 155 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 156 | {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, |
| 157 | QOS_TX3_TXOP_LIMIT_CCK} |
| 158 | }; |
| 159 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 160 | static struct libipw_qos_parameters def_parameters_OFDM = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 161 | {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, |
| 162 | DEF_TX3_CW_MIN_OFDM}, |
| 163 | {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, |
| 164 | DEF_TX3_CW_MAX_OFDM}, |
| 165 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 166 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 167 | {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, |
| 168 | DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} |
| 169 | }; |
| 170 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 171 | static struct libipw_qos_parameters def_parameters_CCK = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 172 | {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, |
| 173 | DEF_TX3_CW_MIN_CCK}, |
| 174 | {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, |
| 175 | DEF_TX3_CW_MAX_CCK}, |
| 176 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 177 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 178 | {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, |
| 179 | DEF_TX3_TXOP_LIMIT_CCK} |
| 180 | }; |
| 181 | |
| 182 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; |
| 183 | |
| 184 | static int from_priority_to_tx_queue[] = { |
| 185 | IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, |
| 186 | IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 |
| 187 | }; |
| 188 | |
| 189 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); |
| 190 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 191 | 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] | 192 | *qos_param); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 193 | 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] | 194 | *qos_param); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 195 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 196 | |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 197 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 198 | static void ipw_remove_current_network(struct ipw_priv *priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 199 | static void ipw_rx(struct ipw_priv *priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 200 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 201 | struct clx2_tx_queue *txq, int qindex); |
| 202 | static int ipw_queue_reset(struct ipw_priv *priv); |
| 203 | |
| 204 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 205 | int len, int sync); |
| 206 | |
| 207 | static void ipw_tx_queue_free(struct ipw_priv *); |
| 208 | |
| 209 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); |
| 210 | static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); |
| 211 | static void ipw_rx_queue_replenish(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 212 | static int ipw_up(struct ipw_priv *); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 213 | static void ipw_bg_up(struct work_struct *work); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 214 | static void ipw_down(struct ipw_priv *); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 215 | static void ipw_bg_down(struct work_struct *work); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 216 | static int ipw_config(struct ipw_priv *); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 217 | static int init_supported_rates(struct ipw_priv *priv, |
| 218 | struct ipw_supported_rates *prates); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 219 | static void ipw_set_hwcrypto_keys(struct ipw_priv *); |
| 220 | static void ipw_send_wep_keys(struct ipw_priv *, int); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 221 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 222 | static int snprint_line(char *buf, size_t count, |
| 223 | const u8 * data, u32 len, u32 ofs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 224 | { |
| 225 | int out, i, j, l; |
| 226 | char c; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 227 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 228 | out = snprintf(buf, count, "%08X", ofs); |
| 229 | |
| 230 | for (l = 0, i = 0; i < 2; i++) { |
| 231 | out += snprintf(buf + out, count - out, " "); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 232 | for (j = 0; j < 8 && l < len; j++, l++) |
| 233 | out += snprintf(buf + out, count - out, "%02X ", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 234 | data[(i * 8 + j)]); |
| 235 | for (; j < 8; j++) |
| 236 | out += snprintf(buf + out, count - out, " "); |
| 237 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 238 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 239 | out += snprintf(buf + out, count - out, " "); |
| 240 | for (l = 0, i = 0; i < 2; i++) { |
| 241 | out += snprintf(buf + out, count - out, " "); |
| 242 | for (j = 0; j < 8 && l < len; j++, l++) { |
| 243 | c = data[(i * 8 + j)]; |
| 244 | if (!isascii(c) || !isprint(c)) |
| 245 | c = '.'; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 246 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 247 | out += snprintf(buf + out, count - out, "%c", c); |
| 248 | } |
| 249 | |
| 250 | for (; j < 8; j++) |
| 251 | out += snprintf(buf + out, count - out, " "); |
| 252 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 253 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 254 | return out; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 255 | } |
| 256 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 257 | static void printk_buf(int level, const u8 * data, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 258 | { |
| 259 | char line[81]; |
| 260 | u32 ofs = 0; |
| 261 | if (!(ipw_debug_level & level)) |
| 262 | return; |
| 263 | |
| 264 | while (len) { |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 265 | snprint_line(line, sizeof(line), &data[ofs], |
| 266 | min(len, 16U), ofs); |
| 267 | printk(KERN_DEBUG "%s\n", line); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 268 | ofs += 16; |
| 269 | len -= min(len, 16U); |
| 270 | } |
| 271 | } |
| 272 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 273 | static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len) |
| 274 | { |
| 275 | size_t out = size; |
| 276 | u32 ofs = 0; |
| 277 | int total = 0; |
| 278 | |
| 279 | while (size && len) { |
| 280 | out = snprint_line(output, size, &data[ofs], |
| 281 | min_t(size_t, len, 16U), ofs); |
| 282 | |
| 283 | ofs += 16; |
| 284 | output += out; |
| 285 | size -= out; |
| 286 | len -= min_t(size_t, len, 16U); |
| 287 | total += out; |
| 288 | } |
| 289 | return total; |
| 290 | } |
| 291 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 292 | /* 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] | 293 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); |
| 294 | #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) |
| 295 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 296 | /* 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] | 297 | static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); |
| 298 | #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) |
| 299 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 300 | /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 301 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); |
| 302 | static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) |
| 303 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 304 | IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, |
| 305 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 306 | _ipw_write_reg8(a, b, c); |
| 307 | } |
| 308 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 309 | /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 310 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); |
| 311 | static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) |
| 312 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 313 | IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, |
| 314 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 315 | _ipw_write_reg16(a, b, c); |
| 316 | } |
| 317 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 318 | /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 319 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); |
| 320 | static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) |
| 321 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 322 | IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, |
| 323 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 324 | _ipw_write_reg32(a, b, c); |
| 325 | } |
| 326 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 327 | /* 8-bit direct write (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 328 | static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs, |
| 329 | u8 val) |
| 330 | { |
| 331 | writeb(val, ipw->hw_base + ofs); |
| 332 | } |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 333 | |
| 334 | /* 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] | 335 | #define ipw_write8(ipw, ofs, val) do { \ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 336 | IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \ |
| 337 | __LINE__, (u32)(ofs), (u32)(val)); \ |
| 338 | _ipw_write8(ipw, ofs, val); \ |
| 339 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 340 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 341 | /* 16-bit direct write (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 342 | static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs, |
| 343 | u16 val) |
| 344 | { |
| 345 | writew(val, ipw->hw_base + ofs); |
| 346 | } |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 347 | |
| 348 | /* 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] | 349 | #define ipw_write16(ipw, ofs, val) do { \ |
| 350 | IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \ |
| 351 | __LINE__, (u32)(ofs), (u32)(val)); \ |
| 352 | _ipw_write16(ipw, ofs, val); \ |
| 353 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 354 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 355 | /* 32-bit direct write (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 356 | static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs, |
| 357 | u32 val) |
| 358 | { |
| 359 | writel(val, ipw->hw_base + ofs); |
| 360 | } |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 361 | |
| 362 | /* 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] | 363 | #define ipw_write32(ipw, ofs, val) do { \ |
| 364 | IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \ |
| 365 | __LINE__, (u32)(ofs), (u32)(val)); \ |
| 366 | _ipw_write32(ipw, ofs, val); \ |
| 367 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 368 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 369 | /* 8-bit direct read (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 370 | static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 371 | { |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 372 | return readb(ipw->hw_base + ofs); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 373 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 374 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 375 | /* 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] | 376 | #define ipw_read8(ipw, ofs) ({ \ |
| 377 | IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \ |
| 378 | (u32)(ofs)); \ |
| 379 | _ipw_read8(ipw, ofs); \ |
| 380 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 381 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 382 | /* 16-bit direct read (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 383 | static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 384 | { |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 385 | return readw(ipw->hw_base + ofs); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 386 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 387 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 388 | /* 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] | 389 | #define ipw_read16(ipw, ofs) ({ \ |
| 390 | IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \ |
| 391 | (u32)(ofs)); \ |
| 392 | _ipw_read16(ipw, ofs); \ |
| 393 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 394 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 395 | /* 32-bit direct read (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 396 | static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 397 | { |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 398 | return readl(ipw->hw_base + ofs); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 399 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 400 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 401 | /* 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] | 402 | #define ipw_read32(ipw, ofs) ({ \ |
| 403 | IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \ |
| 404 | (u32)(ofs)); \ |
| 405 | _ipw_read32(ipw, ofs); \ |
| 406 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 407 | |
| 408 | static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 409 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 410 | #define ipw_read_indirect(a, b, c, d) ({ \ |
| 411 | IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \ |
| 412 | __LINE__, (u32)(b), (u32)(d)); \ |
| 413 | _ipw_read_indirect(a, b, c, d); \ |
| 414 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 415 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 416 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 417 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, |
| 418 | int num); |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 419 | #define ipw_write_indirect(a, b, c, d) do { \ |
| 420 | IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \ |
| 421 | __LINE__, (u32)(b), (u32)(d)); \ |
| 422 | _ipw_write_indirect(a, b, c, d); \ |
| 423 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 424 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 425 | /* 32-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 426 | 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] | 427 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 428 | 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] | 429 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 430 | _ipw_write32(priv, IPW_INDIRECT_DATA, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 431 | } |
| 432 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 433 | /* 8-bit indirect write (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 434 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) |
| 435 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 436 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 437 | u32 dif_len = reg - aligned_addr; |
| 438 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 439 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 440 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 441 | _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 442 | } |
| 443 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 444 | /* 16-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 445 | 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] | 446 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 447 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 448 | u32 dif_len = (reg - aligned_addr) & (~0x1ul); |
| 449 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 450 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 451 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 452 | _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 453 | } |
| 454 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 455 | /* 8-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 456 | static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) |
| 457 | { |
| 458 | u32 word; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 459 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 460 | IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 461 | word = _ipw_read32(priv, IPW_INDIRECT_DATA); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 462 | return (word >> ((reg & 0x3) * 8)) & 0xff; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 463 | } |
| 464 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 465 | /* 32-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 466 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) |
| 467 | { |
| 468 | u32 value; |
| 469 | |
| 470 | IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); |
| 471 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 472 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 473 | value = _ipw_read32(priv, IPW_INDIRECT_DATA); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 474 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); |
| 475 | return value; |
| 476 | } |
| 477 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 478 | /* General purpose, no alignment requirement, iterative (multi-byte) read, */ |
| 479 | /* for area above 1st 4K of SRAM/reg space */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 480 | static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
| 481 | int num) |
| 482 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 483 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 484 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 485 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 486 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 487 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
| 488 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 489 | if (num <= 0) { |
| 490 | return; |
| 491 | } |
| 492 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 493 | /* Read the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 494 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 495 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 496 | /* Start reading at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 497 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 498 | *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 499 | aligned_addr += 4; |
| 500 | } |
| 501 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 502 | /* Read all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 503 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 504 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 505 | *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 506 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 507 | /* Read the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 508 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 509 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 510 | for (i = 0; num > 0; i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 511 | *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 512 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 513 | } |
| 514 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 515 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 516 | /* for area above 1st 4K of SRAM/reg space */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 517 | 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] | 518 | int num) |
| 519 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 520 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 521 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 522 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 523 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 524 | 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] | 525 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 526 | if (num <= 0) { |
| 527 | return; |
| 528 | } |
| 529 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 530 | /* Write the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 531 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 532 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 533 | /* Start writing at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 534 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 535 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 536 | aligned_addr += 4; |
| 537 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 538 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 539 | /* Write all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 540 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 541 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 542 | _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 543 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 544 | /* Write the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 545 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 546 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 547 | for (i = 0; num > 0; i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 548 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 549 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 550 | } |
| 551 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 552 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 553 | /* for 1st 4K of SRAM/regs space */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 554 | 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] | 555 | int num) |
| 556 | { |
| 557 | memcpy_toio((priv->hw_base + addr), buf, num); |
| 558 | } |
| 559 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 560 | /* Set bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 561 | static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 562 | { |
| 563 | ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); |
| 564 | } |
| 565 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 566 | /* Clear bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 567 | static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 568 | { |
| 569 | ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); |
| 570 | } |
| 571 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 572 | static inline void __ipw_enable_interrupts(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 573 | { |
| 574 | if (priv->status & STATUS_INT_ENABLED) |
| 575 | return; |
| 576 | priv->status |= STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 577 | ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 578 | } |
| 579 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 580 | static inline void __ipw_disable_interrupts(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 581 | { |
| 582 | if (!(priv->status & STATUS_INT_ENABLED)) |
| 583 | return; |
| 584 | priv->status &= ~STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 585 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 586 | } |
| 587 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 588 | static inline void ipw_enable_interrupts(struct ipw_priv *priv) |
| 589 | { |
| 590 | unsigned long flags; |
| 591 | |
| 592 | spin_lock_irqsave(&priv->irq_lock, flags); |
| 593 | __ipw_enable_interrupts(priv); |
| 594 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 595 | } |
| 596 | |
| 597 | static inline void ipw_disable_interrupts(struct ipw_priv *priv) |
| 598 | { |
| 599 | unsigned long flags; |
| 600 | |
| 601 | spin_lock_irqsave(&priv->irq_lock, flags); |
| 602 | __ipw_disable_interrupts(priv); |
| 603 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 604 | } |
| 605 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 606 | static char *ipw_error_desc(u32 val) |
| 607 | { |
| 608 | switch (val) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 609 | case IPW_FW_ERROR_OK: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 610 | return "ERROR_OK"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 611 | case IPW_FW_ERROR_FAIL: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 612 | return "ERROR_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 613 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 614 | return "MEMORY_UNDERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 615 | case IPW_FW_ERROR_MEMORY_OVERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 616 | return "MEMORY_OVERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 617 | case IPW_FW_ERROR_BAD_PARAM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 618 | return "BAD_PARAM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 619 | case IPW_FW_ERROR_BAD_CHECKSUM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 620 | return "BAD_CHECKSUM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 621 | case IPW_FW_ERROR_NMI_INTERRUPT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 622 | return "NMI_INTERRUPT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 623 | case IPW_FW_ERROR_BAD_DATABASE: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 624 | return "BAD_DATABASE"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 625 | case IPW_FW_ERROR_ALLOC_FAIL: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 626 | return "ALLOC_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 627 | case IPW_FW_ERROR_DMA_UNDERRUN: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 628 | return "DMA_UNDERRUN"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 629 | case IPW_FW_ERROR_DMA_STATUS: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 630 | return "DMA_STATUS"; |
| 631 | case IPW_FW_ERROR_DINO_ERROR: |
| 632 | return "DINO_ERROR"; |
| 633 | case IPW_FW_ERROR_EEPROM_ERROR: |
| 634 | return "EEPROM_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 635 | case IPW_FW_ERROR_SYSASSERT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 636 | return "SYSASSERT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 637 | case IPW_FW_ERROR_FATAL_ERROR: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 638 | return "FATAL_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 639 | default: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 640 | return "UNKNOWN_ERROR"; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 644 | static void ipw_dump_error_log(struct ipw_priv *priv, |
| 645 | struct ipw_fw_error *error) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 646 | { |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 647 | u32 i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 648 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 649 | if (!error) { |
| 650 | IPW_ERROR("Error allocating and capturing error log. " |
| 651 | "Nothing to dump.\n"); |
| 652 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 653 | } |
| 654 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 655 | IPW_ERROR("Start IPW Error Log Dump:\n"); |
| 656 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", |
| 657 | error->status, error->config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 658 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 659 | for (i = 0; i < error->elem_len; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 660 | 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] | 661 | ipw_error_desc(error->elem[i].desc), |
| 662 | error->elem[i].time, |
| 663 | error->elem[i].blink1, |
| 664 | error->elem[i].blink2, |
| 665 | error->elem[i].link1, |
| 666 | error->elem[i].link2, error->elem[i].data); |
| 667 | for (i = 0; i < error->log_len; i++) |
| 668 | IPW_ERROR("%i\t0x%08x\t%i\n", |
| 669 | error->log[i].time, |
James Ketrenos | 286568a | 2005-08-30 10:34:25 -0500 | [diff] [blame] | 670 | error->log[i].data, error->log[i].event); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 671 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 672 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 673 | static inline int ipw_is_init(struct ipw_priv *priv) |
| 674 | { |
| 675 | return (priv->status & STATUS_INIT) ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 676 | } |
| 677 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 678 | 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] | 679 | { |
| 680 | u32 addr, field_info, field_len, field_count, total_len; |
| 681 | |
| 682 | IPW_DEBUG_ORD("ordinal = %i\n", ord); |
| 683 | |
| 684 | if (!priv || !val || !len) { |
| 685 | IPW_DEBUG_ORD("Invalid argument\n"); |
| 686 | return -EINVAL; |
| 687 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 688 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 689 | /* verify device ordinal tables have been initialized */ |
| 690 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { |
| 691 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); |
| 692 | return -EINVAL; |
| 693 | } |
| 694 | |
| 695 | switch (IPW_ORD_TABLE_ID_MASK & ord) { |
| 696 | case IPW_ORD_TABLE_0_MASK: |
| 697 | /* |
| 698 | * TABLE 0: Direct access to a table of 32 bit values |
| 699 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 700 | * This is a very simple table with the data directly |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 701 | * read from the table |
| 702 | */ |
| 703 | |
| 704 | /* remove the table id from the ordinal */ |
| 705 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 706 | |
| 707 | /* boundary check */ |
| 708 | if (ord > priv->table0_len) { |
| 709 | IPW_DEBUG_ORD("ordinal value (%i) longer then " |
| 710 | "max (%i)\n", ord, priv->table0_len); |
| 711 | return -EINVAL; |
| 712 | } |
| 713 | |
| 714 | /* verify we have enough room to store the value */ |
| 715 | if (*len < sizeof(u32)) { |
| 716 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 717 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 718 | return -EINVAL; |
| 719 | } |
| 720 | |
| 721 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 722 | ord, priv->table0_addr + (ord << 2)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 723 | |
| 724 | *len = sizeof(u32); |
| 725 | ord <<= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 726 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case IPW_ORD_TABLE_1_MASK: |
| 730 | /* |
| 731 | * TABLE 1: Indirect access to a table of 32 bit values |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 732 | * |
| 733 | * This is a fairly large table of u32 values each |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 734 | * representing starting addr for the data (which is |
| 735 | * also a u32) |
| 736 | */ |
| 737 | |
| 738 | /* remove the table id from the ordinal */ |
| 739 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 740 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 741 | /* boundary check */ |
| 742 | if (ord > priv->table1_len) { |
| 743 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 744 | return -EINVAL; |
| 745 | } |
| 746 | |
| 747 | /* verify we have enough room to store the value */ |
| 748 | if (*len < sizeof(u32)) { |
| 749 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 750 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 751 | return -EINVAL; |
| 752 | } |
| 753 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 754 | *((u32 *) val) = |
| 755 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 756 | *len = sizeof(u32); |
| 757 | break; |
| 758 | |
| 759 | case IPW_ORD_TABLE_2_MASK: |
| 760 | /* |
| 761 | * TABLE 2: Indirect access to a table of variable sized values |
| 762 | * |
| 763 | * This table consist of six values, each containing |
| 764 | * - dword containing the starting offset of the data |
| 765 | * - dword containing the lengh in the first 16bits |
| 766 | * and the count in the second 16bits |
| 767 | */ |
| 768 | |
| 769 | /* remove the table id from the ordinal */ |
| 770 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 771 | |
| 772 | /* boundary check */ |
| 773 | if (ord > priv->table2_len) { |
| 774 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 775 | return -EINVAL; |
| 776 | } |
| 777 | |
| 778 | /* get the address of statistic */ |
| 779 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 780 | |
| 781 | /* get the second DW of statistics ; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 782 | * two 16-bit words - first is length, second is count */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 783 | field_info = |
| 784 | ipw_read_reg32(priv, |
| 785 | priv->table2_addr + (ord << 3) + |
| 786 | sizeof(u32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 787 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 788 | /* get each entry length */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 789 | field_len = *((u16 *) & field_info); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 790 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 791 | /* get number of entries */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 792 | field_count = *(((u16 *) & field_info) + 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 793 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 794 | /* abort if not enought memory */ |
| 795 | total_len = field_len * field_count; |
| 796 | if (total_len > *len) { |
| 797 | *len = total_len; |
| 798 | return -EINVAL; |
| 799 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 800 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 801 | *len = total_len; |
| 802 | if (!total_len) |
| 803 | return 0; |
| 804 | |
| 805 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 806 | "field_info = 0x%08x\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 807 | addr, total_len, field_info); |
| 808 | ipw_read_indirect(priv, addr, val, total_len); |
| 809 | break; |
| 810 | |
| 811 | default: |
| 812 | IPW_DEBUG_ORD("Invalid ordinal!\n"); |
| 813 | return -EINVAL; |
| 814 | |
| 815 | } |
| 816 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | static void ipw_init_ordinals(struct ipw_priv *priv) |
| 821 | { |
| 822 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 823 | priv->table0_len = ipw_read32(priv, priv->table0_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 824 | |
| 825 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", |
| 826 | priv->table0_addr, priv->table0_len); |
| 827 | |
| 828 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); |
| 829 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); |
| 830 | |
| 831 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", |
| 832 | priv->table1_addr, priv->table1_len); |
| 833 | |
| 834 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); |
| 835 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 836 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 837 | |
| 838 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", |
| 839 | priv->table2_addr, priv->table2_len); |
| 840 | |
| 841 | } |
| 842 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 843 | static u32 ipw_register_toggle(u32 reg) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 844 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 845 | reg &= ~IPW_START_STANDBY; |
| 846 | if (reg & IPW_GATE_ODMA) |
| 847 | reg &= ~IPW_GATE_ODMA; |
| 848 | if (reg & IPW_GATE_IDMA) |
| 849 | reg &= ~IPW_GATE_IDMA; |
| 850 | if (reg & IPW_GATE_ADMA) |
| 851 | reg &= ~IPW_GATE_ADMA; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 852 | return reg; |
| 853 | } |
| 854 | |
| 855 | /* |
| 856 | * LED behavior: |
| 857 | * - On radio ON, turn on any LEDs that require to be on during start |
| 858 | * - On initialization, start unassociated blink |
| 859 | * - On association, disable unassociated blink |
| 860 | * - On disassociation, start unassociated blink |
| 861 | * - On radio OFF, turn off any LEDs started during radio on |
| 862 | * |
| 863 | */ |
Zhu Yi | ede6111 | 2006-01-24 16:37:10 +0800 | [diff] [blame] | 864 | #define LD_TIME_LINK_ON msecs_to_jiffies(300) |
| 865 | #define LD_TIME_LINK_OFF msecs_to_jiffies(2700) |
| 866 | #define LD_TIME_ACT_ON msecs_to_jiffies(250) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 867 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 868 | static void ipw_led_link_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 869 | { |
| 870 | unsigned long flags; |
| 871 | u32 led; |
| 872 | |
| 873 | /* If configured to not use LEDs, or nic_type is 1, |
| 874 | * then we don't toggle a LINK led */ |
| 875 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 876 | return; |
| 877 | |
| 878 | spin_lock_irqsave(&priv->lock, flags); |
| 879 | |
| 880 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 881 | !(priv->status & STATUS_LED_LINK_ON)) { |
| 882 | IPW_DEBUG_LED("Link LED On\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 883 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 884 | led |= priv->led_association_on; |
| 885 | |
| 886 | led = ipw_register_toggle(led); |
| 887 | |
| 888 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 889 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 890 | |
| 891 | priv->status |= STATUS_LED_LINK_ON; |
| 892 | |
| 893 | /* If we aren't associated, schedule turning the LED off */ |
| 894 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 895 | queue_delayed_work(priv->workqueue, |
| 896 | &priv->led_link_off, |
| 897 | LD_TIME_LINK_ON); |
| 898 | } |
| 899 | |
| 900 | spin_unlock_irqrestore(&priv->lock, flags); |
| 901 | } |
| 902 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 903 | static void ipw_bg_led_link_on(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 904 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 905 | struct ipw_priv *priv = |
| 906 | container_of(work, struct ipw_priv, led_link_on.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 907 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 908 | ipw_led_link_on(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 909 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 910 | } |
| 911 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 912 | static void ipw_led_link_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 913 | { |
| 914 | unsigned long flags; |
| 915 | u32 led; |
| 916 | |
| 917 | /* If configured not to use LEDs, or nic type is 1, |
| 918 | * then we don't goggle the LINK led. */ |
| 919 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 920 | return; |
| 921 | |
| 922 | spin_lock_irqsave(&priv->lock, flags); |
| 923 | |
| 924 | if (priv->status & STATUS_LED_LINK_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 925 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 926 | led &= priv->led_association_off; |
| 927 | led = ipw_register_toggle(led); |
| 928 | |
| 929 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 930 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 931 | |
| 932 | IPW_DEBUG_LED("Link LED Off\n"); |
| 933 | |
| 934 | priv->status &= ~STATUS_LED_LINK_ON; |
| 935 | |
| 936 | /* If we aren't associated and the radio is on, schedule |
| 937 | * turning the LED on (blink while unassociated) */ |
| 938 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 939 | !(priv->status & STATUS_ASSOCIATED)) |
| 940 | queue_delayed_work(priv->workqueue, &priv->led_link_on, |
| 941 | LD_TIME_LINK_OFF); |
| 942 | |
| 943 | } |
| 944 | |
| 945 | spin_unlock_irqrestore(&priv->lock, flags); |
| 946 | } |
| 947 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 948 | static void ipw_bg_led_link_off(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 949 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 950 | struct ipw_priv *priv = |
| 951 | container_of(work, struct ipw_priv, led_link_off.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 952 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 953 | ipw_led_link_off(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 954 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 955 | } |
| 956 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 957 | static void __ipw_led_activity_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 958 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 959 | u32 led; |
| 960 | |
| 961 | if (priv->config & CFG_NO_LED) |
| 962 | return; |
| 963 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 964 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 965 | return; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 966 | |
| 967 | if (!(priv->status & STATUS_LED_ACT_ON)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 968 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 969 | led |= priv->led_activity_on; |
| 970 | |
| 971 | led = ipw_register_toggle(led); |
| 972 | |
| 973 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 974 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 975 | |
| 976 | IPW_DEBUG_LED("Activity LED On\n"); |
| 977 | |
| 978 | priv->status |= STATUS_LED_ACT_ON; |
| 979 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 980 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 981 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 982 | LD_TIME_ACT_ON); |
| 983 | } else { |
| 984 | /* Reschedule LED off for full time period */ |
| 985 | cancel_delayed_work(&priv->led_act_off); |
| 986 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 987 | LD_TIME_ACT_ON); |
| 988 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 989 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 990 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 991 | #if 0 |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 992 | void ipw_led_activity_on(struct ipw_priv *priv) |
| 993 | { |
| 994 | unsigned long flags; |
| 995 | spin_lock_irqsave(&priv->lock, flags); |
| 996 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 997 | spin_unlock_irqrestore(&priv->lock, flags); |
| 998 | } |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 999 | #endif /* 0 */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1000 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1001 | static void ipw_led_activity_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1002 | { |
| 1003 | unsigned long flags; |
| 1004 | u32 led; |
| 1005 | |
| 1006 | if (priv->config & CFG_NO_LED) |
| 1007 | return; |
| 1008 | |
| 1009 | spin_lock_irqsave(&priv->lock, flags); |
| 1010 | |
| 1011 | if (priv->status & STATUS_LED_ACT_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1012 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1013 | led &= priv->led_activity_off; |
| 1014 | |
| 1015 | led = ipw_register_toggle(led); |
| 1016 | |
| 1017 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1018 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1019 | |
| 1020 | IPW_DEBUG_LED("Activity LED Off\n"); |
| 1021 | |
| 1022 | priv->status &= ~STATUS_LED_ACT_ON; |
| 1023 | } |
| 1024 | |
| 1025 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1026 | } |
| 1027 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1028 | static void ipw_bg_led_activity_off(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1029 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1030 | struct ipw_priv *priv = |
| 1031 | container_of(work, struct ipw_priv, led_act_off.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 1032 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1033 | ipw_led_activity_off(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 1034 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1035 | } |
| 1036 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1037 | static void ipw_led_band_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1038 | { |
| 1039 | unsigned long flags; |
| 1040 | u32 led; |
| 1041 | |
| 1042 | /* Only nic type 1 supports mode LEDs */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1043 | if (priv->config & CFG_NO_LED || |
| 1044 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1045 | return; |
| 1046 | |
| 1047 | spin_lock_irqsave(&priv->lock, flags); |
| 1048 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1049 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1050 | if (priv->assoc_network->mode == IEEE_A) { |
| 1051 | led |= priv->led_ofdm_on; |
| 1052 | led &= priv->led_association_off; |
| 1053 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); |
| 1054 | } else if (priv->assoc_network->mode == IEEE_G) { |
| 1055 | led |= priv->led_ofdm_on; |
| 1056 | led |= priv->led_association_on; |
| 1057 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); |
| 1058 | } else { |
| 1059 | led &= priv->led_ofdm_off; |
| 1060 | led |= priv->led_association_on; |
| 1061 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); |
| 1062 | } |
| 1063 | |
| 1064 | led = ipw_register_toggle(led); |
| 1065 | |
| 1066 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1067 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1068 | |
| 1069 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1070 | } |
| 1071 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1072 | static void ipw_led_band_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1073 | { |
| 1074 | unsigned long flags; |
| 1075 | u32 led; |
| 1076 | |
| 1077 | /* Only nic type 1 supports mode LEDs */ |
| 1078 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) |
| 1079 | return; |
| 1080 | |
| 1081 | spin_lock_irqsave(&priv->lock, flags); |
| 1082 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1083 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1084 | led &= priv->led_ofdm_off; |
| 1085 | led &= priv->led_association_off; |
| 1086 | |
| 1087 | led = ipw_register_toggle(led); |
| 1088 | |
| 1089 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1090 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1091 | |
| 1092 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1093 | } |
| 1094 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1095 | static void ipw_led_radio_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1096 | { |
| 1097 | ipw_led_link_on(priv); |
| 1098 | } |
| 1099 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1100 | static void ipw_led_radio_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1101 | { |
| 1102 | ipw_led_activity_off(priv); |
| 1103 | ipw_led_link_off(priv); |
| 1104 | } |
| 1105 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1106 | static void ipw_led_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1107 | { |
| 1108 | /* Set the Link Led on for all nic types */ |
| 1109 | ipw_led_link_on(priv); |
| 1110 | } |
| 1111 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1112 | static void ipw_led_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1113 | { |
| 1114 | ipw_led_activity_off(priv); |
| 1115 | ipw_led_link_off(priv); |
| 1116 | |
| 1117 | if (priv->status & STATUS_RF_KILL_MASK) |
| 1118 | ipw_led_radio_off(priv); |
| 1119 | } |
| 1120 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1121 | static void ipw_led_init(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1122 | { |
| 1123 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; |
| 1124 | |
| 1125 | /* Set the default PINs for the link and activity leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1126 | priv->led_activity_on = IPW_ACTIVITY_LED; |
| 1127 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1128 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1129 | priv->led_association_on = IPW_ASSOCIATED_LED; |
| 1130 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1131 | |
| 1132 | /* Set the default PINs for the OFDM leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1133 | priv->led_ofdm_on = IPW_OFDM_LED; |
| 1134 | priv->led_ofdm_off = ~(IPW_OFDM_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1135 | |
| 1136 | switch (priv->nic_type) { |
| 1137 | case EEPROM_NIC_TYPE_1: |
| 1138 | /* In this NIC type, the LEDs are reversed.... */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1139 | priv->led_activity_on = IPW_ASSOCIATED_LED; |
| 1140 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); |
| 1141 | priv->led_association_on = IPW_ACTIVITY_LED; |
| 1142 | priv->led_association_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1143 | |
| 1144 | if (!(priv->config & CFG_NO_LED)) |
| 1145 | ipw_led_band_on(priv); |
| 1146 | |
| 1147 | /* And we don't blink link LEDs for this nic, so |
| 1148 | * just return here */ |
| 1149 | return; |
| 1150 | |
| 1151 | case EEPROM_NIC_TYPE_3: |
| 1152 | case EEPROM_NIC_TYPE_2: |
| 1153 | case EEPROM_NIC_TYPE_4: |
| 1154 | case EEPROM_NIC_TYPE_0: |
| 1155 | break; |
| 1156 | |
| 1157 | default: |
| 1158 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", |
| 1159 | priv->nic_type); |
| 1160 | priv->nic_type = EEPROM_NIC_TYPE_0; |
| 1161 | break; |
| 1162 | } |
| 1163 | |
| 1164 | if (!(priv->config & CFG_NO_LED)) { |
| 1165 | if (priv->status & STATUS_ASSOCIATED) |
| 1166 | ipw_led_link_on(priv); |
| 1167 | else |
| 1168 | ipw_led_link_off(priv); |
| 1169 | } |
| 1170 | } |
| 1171 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1172 | static void ipw_led_shutdown(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1173 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1174 | ipw_led_activity_off(priv); |
| 1175 | ipw_led_link_off(priv); |
| 1176 | ipw_led_band_off(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1177 | cancel_delayed_work(&priv->led_link_on); |
| 1178 | cancel_delayed_work(&priv->led_link_off); |
| 1179 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1180 | } |
| 1181 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1182 | /* |
| 1183 | * The following adds a new attribute to the sysfs representation |
| 1184 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) |
| 1185 | * used for controling the debug level. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1186 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1187 | * See the level definitions in ipw for details. |
| 1188 | */ |
| 1189 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 1190 | { |
| 1191 | return sprintf(buf, "0x%08X\n", ipw_debug_level); |
| 1192 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1193 | |
| 1194 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, |
| 1195 | size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1196 | { |
| 1197 | char *p = (char *)buf; |
| 1198 | u32 val; |
| 1199 | |
| 1200 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1201 | p++; |
| 1202 | if (p[0] == 'x' || p[0] == 'X') |
| 1203 | p++; |
| 1204 | val = simple_strtoul(p, &p, 16); |
| 1205 | } else |
| 1206 | val = simple_strtoul(p, &p, 10); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1207 | if (p == buf) |
| 1208 | printk(KERN_INFO DRV_NAME |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1209 | ": %s is not in hex or decimal form.\n", buf); |
| 1210 | else |
| 1211 | ipw_debug_level = val; |
| 1212 | |
| 1213 | return strnlen(buf, count); |
| 1214 | } |
| 1215 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1216 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1217 | show_debug_level, store_debug_level); |
| 1218 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1219 | static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) |
| 1220 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 1221 | /* length = 1st dword in log */ |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1222 | return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); |
| 1223 | } |
| 1224 | |
| 1225 | static void ipw_capture_event_log(struct ipw_priv *priv, |
| 1226 | u32 log_len, struct ipw_event *log) |
| 1227 | { |
| 1228 | u32 base; |
| 1229 | |
| 1230 | if (log_len) { |
| 1231 | base = ipw_read32(priv, IPW_EVENT_LOG); |
| 1232 | ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), |
| 1233 | (u8 *) log, sizeof(*log) * log_len); |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) |
| 1238 | { |
| 1239 | struct ipw_fw_error *error; |
| 1240 | u32 log_len = ipw_get_event_log_len(priv); |
| 1241 | u32 base = ipw_read32(priv, IPW_ERROR_LOG); |
| 1242 | u32 elem_len = ipw_read_reg32(priv, base); |
| 1243 | |
| 1244 | error = kmalloc(sizeof(*error) + |
| 1245 | sizeof(*error->elem) * elem_len + |
| 1246 | sizeof(*error->log) * log_len, GFP_ATOMIC); |
| 1247 | if (!error) { |
| 1248 | IPW_ERROR("Memory allocation for firmware error log " |
| 1249 | "failed.\n"); |
| 1250 | return NULL; |
| 1251 | } |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1252 | error->jiffies = jiffies; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1253 | error->status = priv->status; |
| 1254 | error->config = priv->config; |
| 1255 | error->elem_len = elem_len; |
| 1256 | error->log_len = log_len; |
| 1257 | error->elem = (struct ipw_error_elem *)error->payload; |
Zhu Yi | 3b26b11 | 2005-11-17 13:58:30 +0800 | [diff] [blame] | 1258 | error->log = (struct ipw_event *)(error->elem + elem_len); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1259 | |
| 1260 | ipw_capture_event_log(priv, log_len, error->log); |
| 1261 | |
| 1262 | if (elem_len) |
| 1263 | ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, |
| 1264 | sizeof(*error->elem) * elem_len); |
| 1265 | |
| 1266 | return error; |
| 1267 | } |
| 1268 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1269 | static ssize_t show_event_log(struct device *d, |
| 1270 | struct device_attribute *attr, char *buf) |
| 1271 | { |
| 1272 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1273 | u32 log_len = ipw_get_event_log_len(priv); |
Reinette Chatre | 412e9e7 | 2007-12-18 22:01:02 -0800 | [diff] [blame] | 1274 | u32 log_size; |
| 1275 | struct ipw_event *log; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1276 | u32 len = 0, i; |
| 1277 | |
Reinette Chatre | 412e9e7 | 2007-12-18 22:01:02 -0800 | [diff] [blame] | 1278 | /* not using min() because of its strict type checking */ |
| 1279 | log_size = PAGE_SIZE / sizeof(*log) > log_len ? |
| 1280 | sizeof(*log) * log_len : PAGE_SIZE; |
| 1281 | log = kzalloc(log_size, GFP_KERNEL); |
| 1282 | if (!log) { |
| 1283 | IPW_ERROR("Unable to allocate memory for log\n"); |
| 1284 | return 0; |
| 1285 | } |
| 1286 | log_len = log_size / sizeof(*log); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1287 | ipw_capture_event_log(priv, log_len, log); |
| 1288 | |
| 1289 | len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); |
| 1290 | for (i = 0; i < log_len; i++) |
| 1291 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1292 | "\n%08X%08X%08X", |
| 1293 | log[i].time, log[i].event, log[i].data); |
| 1294 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
Reinette Chatre | 412e9e7 | 2007-12-18 22:01:02 -0800 | [diff] [blame] | 1295 | kfree(log); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1296 | return len; |
| 1297 | } |
| 1298 | |
| 1299 | static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL); |
| 1300 | |
| 1301 | static ssize_t show_error(struct device *d, |
| 1302 | struct device_attribute *attr, char *buf) |
| 1303 | { |
| 1304 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1305 | u32 len = 0, i; |
| 1306 | if (!priv->error) |
| 1307 | return 0; |
| 1308 | len += snprintf(buf + len, PAGE_SIZE - len, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1309 | "%08lX%08X%08X%08X", |
| 1310 | priv->error->jiffies, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1311 | priv->error->status, |
| 1312 | priv->error->config, priv->error->elem_len); |
| 1313 | for (i = 0; i < priv->error->elem_len; i++) |
| 1314 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1315 | "\n%08X%08X%08X%08X%08X%08X%08X", |
| 1316 | priv->error->elem[i].time, |
| 1317 | priv->error->elem[i].desc, |
| 1318 | priv->error->elem[i].blink1, |
| 1319 | priv->error->elem[i].blink2, |
| 1320 | priv->error->elem[i].link1, |
| 1321 | priv->error->elem[i].link2, |
| 1322 | priv->error->elem[i].data); |
| 1323 | |
| 1324 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1325 | "\n%08X", priv->error->log_len); |
| 1326 | for (i = 0; i < priv->error->log_len; i++) |
| 1327 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1328 | "\n%08X%08X%08X", |
| 1329 | priv->error->log[i].time, |
| 1330 | priv->error->log[i].event, |
| 1331 | priv->error->log[i].data); |
| 1332 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1333 | return len; |
| 1334 | } |
| 1335 | |
| 1336 | static ssize_t clear_error(struct device *d, |
| 1337 | struct device_attribute *attr, |
| 1338 | const char *buf, size_t count) |
| 1339 | { |
| 1340 | struct ipw_priv *priv = dev_get_drvdata(d); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 1341 | |
| 1342 | kfree(priv->error); |
| 1343 | priv->error = NULL; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1344 | return count; |
| 1345 | } |
| 1346 | |
| 1347 | static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error); |
| 1348 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1349 | static ssize_t show_cmd_log(struct device *d, |
| 1350 | struct device_attribute *attr, char *buf) |
| 1351 | { |
| 1352 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1353 | u32 len = 0, i; |
| 1354 | if (!priv->cmdlog) |
| 1355 | return 0; |
| 1356 | for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; |
| 1357 | (i != priv->cmdlog_pos) && (PAGE_SIZE - len); |
| 1358 | i = (i + 1) % priv->cmdlog_len) { |
| 1359 | len += |
| 1360 | snprintf(buf + len, PAGE_SIZE - len, |
| 1361 | "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, |
| 1362 | priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, |
| 1363 | priv->cmdlog[i].cmd.len); |
| 1364 | len += |
| 1365 | snprintk_buf(buf + len, PAGE_SIZE - len, |
| 1366 | (u8 *) priv->cmdlog[i].cmd.param, |
| 1367 | priv->cmdlog[i].cmd.len); |
| 1368 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1369 | } |
| 1370 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1371 | return len; |
| 1372 | } |
| 1373 | |
| 1374 | static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL); |
| 1375 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 1376 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 1377 | static void ipw_prom_free(struct ipw_priv *priv); |
| 1378 | static int ipw_prom_alloc(struct ipw_priv *priv); |
| 1379 | static ssize_t store_rtap_iface(struct device *d, |
| 1380 | struct device_attribute *attr, |
| 1381 | const char *buf, size_t count) |
| 1382 | { |
| 1383 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1384 | int rc = 0; |
| 1385 | |
| 1386 | if (count < 1) |
| 1387 | return -EINVAL; |
| 1388 | |
| 1389 | switch (buf[0]) { |
| 1390 | case '0': |
| 1391 | if (!rtap_iface) |
| 1392 | return count; |
| 1393 | |
| 1394 | if (netif_running(priv->prom_net_dev)) { |
| 1395 | IPW_WARNING("Interface is up. Cannot unregister.\n"); |
| 1396 | return count; |
| 1397 | } |
| 1398 | |
| 1399 | ipw_prom_free(priv); |
| 1400 | rtap_iface = 0; |
| 1401 | break; |
| 1402 | |
| 1403 | case '1': |
| 1404 | if (rtap_iface) |
| 1405 | return count; |
| 1406 | |
| 1407 | rc = ipw_prom_alloc(priv); |
| 1408 | if (!rc) |
| 1409 | rtap_iface = 1; |
| 1410 | break; |
| 1411 | |
| 1412 | default: |
| 1413 | return -EINVAL; |
| 1414 | } |
| 1415 | |
| 1416 | if (rc) { |
| 1417 | IPW_ERROR("Failed to register promiscuous network " |
| 1418 | "device (error %d).\n", rc); |
| 1419 | } |
| 1420 | |
| 1421 | return count; |
| 1422 | } |
| 1423 | |
| 1424 | static ssize_t show_rtap_iface(struct device *d, |
| 1425 | struct device_attribute *attr, |
| 1426 | char *buf) |
| 1427 | { |
| 1428 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1429 | if (rtap_iface) |
| 1430 | return sprintf(buf, "%s", priv->prom_net_dev->name); |
| 1431 | else { |
| 1432 | buf[0] = '-'; |
| 1433 | buf[1] = '1'; |
| 1434 | buf[2] = '\0'; |
| 1435 | return 3; |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface, |
| 1440 | store_rtap_iface); |
| 1441 | |
| 1442 | static ssize_t store_rtap_filter(struct device *d, |
| 1443 | struct device_attribute *attr, |
| 1444 | const char *buf, size_t count) |
| 1445 | { |
| 1446 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1447 | |
| 1448 | if (!priv->prom_priv) { |
| 1449 | IPW_ERROR("Attempting to set filter without " |
| 1450 | "rtap_iface enabled.\n"); |
| 1451 | return -EPERM; |
| 1452 | } |
| 1453 | |
| 1454 | priv->prom_priv->filter = simple_strtol(buf, NULL, 0); |
| 1455 | |
| 1456 | IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n", |
| 1457 | BIT_ARG16(priv->prom_priv->filter)); |
| 1458 | |
| 1459 | return count; |
| 1460 | } |
| 1461 | |
| 1462 | static ssize_t show_rtap_filter(struct device *d, |
| 1463 | struct device_attribute *attr, |
| 1464 | char *buf) |
| 1465 | { |
| 1466 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1467 | return sprintf(buf, "0x%04X", |
| 1468 | priv->prom_priv ? priv->prom_priv->filter : 0); |
| 1469 | } |
| 1470 | |
| 1471 | static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter, |
| 1472 | store_rtap_filter); |
| 1473 | #endif |
| 1474 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1475 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
| 1476 | char *buf) |
| 1477 | { |
| 1478 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1479 | return sprintf(buf, "%d\n", priv->ieee->scan_age); |
| 1480 | } |
| 1481 | |
| 1482 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, |
| 1483 | const char *buf, size_t count) |
| 1484 | { |
| 1485 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1486 | struct net_device *dev = priv->net_dev; |
| 1487 | char buffer[] = "00000000"; |
| 1488 | unsigned long len = |
| 1489 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; |
| 1490 | unsigned long val; |
| 1491 | char *p = buffer; |
| 1492 | |
| 1493 | IPW_DEBUG_INFO("enter\n"); |
| 1494 | |
| 1495 | strncpy(buffer, buf, len); |
| 1496 | buffer[len] = 0; |
| 1497 | |
| 1498 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1499 | p++; |
| 1500 | if (p[0] == 'x' || p[0] == 'X') |
| 1501 | p++; |
| 1502 | val = simple_strtoul(p, &p, 16); |
| 1503 | } else |
| 1504 | val = simple_strtoul(p, &p, 10); |
| 1505 | if (p == buffer) { |
| 1506 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); |
| 1507 | } else { |
| 1508 | priv->ieee->scan_age = val; |
| 1509 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); |
| 1510 | } |
| 1511 | |
| 1512 | IPW_DEBUG_INFO("exit\n"); |
| 1513 | return len; |
| 1514 | } |
| 1515 | |
| 1516 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); |
| 1517 | |
| 1518 | static ssize_t show_led(struct device *d, struct device_attribute *attr, |
| 1519 | char *buf) |
| 1520 | { |
| 1521 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1522 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); |
| 1523 | } |
| 1524 | |
| 1525 | static ssize_t store_led(struct device *d, struct device_attribute *attr, |
| 1526 | const char *buf, size_t count) |
| 1527 | { |
| 1528 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1529 | |
| 1530 | IPW_DEBUG_INFO("enter\n"); |
| 1531 | |
| 1532 | if (count == 0) |
| 1533 | return 0; |
| 1534 | |
| 1535 | if (*buf == 0) { |
| 1536 | IPW_DEBUG_LED("Disabling LED control.\n"); |
| 1537 | priv->config |= CFG_NO_LED; |
| 1538 | ipw_led_shutdown(priv); |
| 1539 | } else { |
| 1540 | IPW_DEBUG_LED("Enabling LED control.\n"); |
| 1541 | priv->config &= ~CFG_NO_LED; |
| 1542 | ipw_led_init(priv); |
| 1543 | } |
| 1544 | |
| 1545 | IPW_DEBUG_INFO("exit\n"); |
| 1546 | return count; |
| 1547 | } |
| 1548 | |
| 1549 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); |
| 1550 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1551 | static ssize_t show_status(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1552 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1553 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1554 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1555 | return sprintf(buf, "0x%08x\n", (int)p->status); |
| 1556 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1557 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1558 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 1559 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1560 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
| 1561 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1562 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1563 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1564 | return sprintf(buf, "0x%08x\n", (int)p->config); |
| 1565 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1566 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1567 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); |
| 1568 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1569 | static ssize_t show_nic_type(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1570 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1571 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1572 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1573 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1574 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1575 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1576 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); |
| 1577 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1578 | static ssize_t show_ucode_version(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1579 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1580 | { |
| 1581 | u32 len = sizeof(u32), tmp = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1582 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1583 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1584 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1585 | return 0; |
| 1586 | |
| 1587 | return sprintf(buf, "0x%08x\n", tmp); |
| 1588 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1589 | |
| 1590 | 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] | 1591 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1592 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, |
| 1593 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1594 | { |
| 1595 | u32 len = sizeof(u32), tmp = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1596 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1597 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1598 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1599 | return 0; |
| 1600 | |
| 1601 | return sprintf(buf, "0x%08x\n", tmp); |
| 1602 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1603 | |
| 1604 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1605 | |
| 1606 | /* |
| 1607 | * Add a device attribute to view/control the delay between eeprom |
| 1608 | * operations. |
| 1609 | */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1610 | static ssize_t show_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1611 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1612 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1613 | struct ipw_priv *p = dev_get_drvdata(d); |
| 1614 | int n = p->eeprom_delay; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1615 | return sprintf(buf, "%i\n", n); |
| 1616 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1617 | static ssize_t store_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1618 | struct device_attribute *attr, |
| 1619 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1620 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1621 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1622 | sscanf(buf, "%i", &p->eeprom_delay); |
| 1623 | return strnlen(buf, count); |
| 1624 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1625 | |
| 1626 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, |
| 1627 | show_eeprom_delay, store_eeprom_delay); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1628 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1629 | static ssize_t show_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1630 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1631 | { |
| 1632 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1633 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1634 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1635 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1636 | return sprintf(buf, "0x%08x\n", reg); |
| 1637 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1638 | static ssize_t store_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1639 | struct device_attribute *attr, |
| 1640 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1641 | { |
| 1642 | u32 reg; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1643 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1644 | |
| 1645 | sscanf(buf, "%x", ®); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1646 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1647 | return strnlen(buf, count); |
| 1648 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1649 | |
| 1650 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, |
| 1651 | show_command_event_reg, store_command_event_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1652 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1653 | static ssize_t show_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1654 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1655 | { |
| 1656 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1657 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1658 | |
| 1659 | reg = ipw_read_reg32(p, 0x301100); |
| 1660 | return sprintf(buf, "0x%08x\n", reg); |
| 1661 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1662 | static ssize_t store_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1663 | struct device_attribute *attr, |
| 1664 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1665 | { |
| 1666 | u32 reg; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1667 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1668 | |
| 1669 | sscanf(buf, "%x", ®); |
| 1670 | ipw_write_reg32(p, 0x301100, reg); |
| 1671 | return strnlen(buf, count); |
| 1672 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1673 | |
| 1674 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, |
| 1675 | show_mem_gpio_reg, store_mem_gpio_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1676 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1677 | static ssize_t show_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1678 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1679 | { |
| 1680 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1681 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1682 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1683 | if (priv->status & STATUS_INDIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1684 | reg = ipw_read_reg32(priv, priv->indirect_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1685 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1686 | reg = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1687 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1688 | return sprintf(buf, "0x%08x\n", reg); |
| 1689 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1690 | static ssize_t store_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1691 | struct device_attribute *attr, |
| 1692 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1693 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1694 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1695 | |
| 1696 | sscanf(buf, "%x", &priv->indirect_dword); |
| 1697 | priv->status |= STATUS_INDIRECT_DWORD; |
| 1698 | return strnlen(buf, count); |
| 1699 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1700 | |
| 1701 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, |
| 1702 | show_indirect_dword, store_indirect_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1703 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1704 | static ssize_t show_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1705 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1706 | { |
| 1707 | u8 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1708 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1709 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1710 | if (priv->status & STATUS_INDIRECT_BYTE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1711 | reg = ipw_read_reg8(priv, priv->indirect_byte); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1712 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1713 | reg = 0; |
| 1714 | |
| 1715 | return sprintf(buf, "0x%02x\n", reg); |
| 1716 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1717 | static ssize_t store_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1718 | struct device_attribute *attr, |
| 1719 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1720 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1721 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1722 | |
| 1723 | sscanf(buf, "%x", &priv->indirect_byte); |
| 1724 | priv->status |= STATUS_INDIRECT_BYTE; |
| 1725 | return strnlen(buf, count); |
| 1726 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1727 | |
| 1728 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1729 | show_indirect_byte, store_indirect_byte); |
| 1730 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1731 | static ssize_t show_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1732 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1733 | { |
| 1734 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1735 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1736 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1737 | if (priv->status & STATUS_DIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1738 | reg = ipw_read32(priv, priv->direct_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1739 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1740 | reg = 0; |
| 1741 | |
| 1742 | return sprintf(buf, "0x%08x\n", reg); |
| 1743 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1744 | static ssize_t store_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1745 | struct device_attribute *attr, |
| 1746 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1747 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1748 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1749 | |
| 1750 | sscanf(buf, "%x", &priv->direct_dword); |
| 1751 | priv->status |= STATUS_DIRECT_DWORD; |
| 1752 | return strnlen(buf, count); |
| 1753 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1754 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1755 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, |
| 1756 | show_direct_dword, store_direct_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1757 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1758 | static int rf_kill_active(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1759 | { |
| 1760 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) |
| 1761 | priv->status |= STATUS_RF_KILL_HW; |
| 1762 | else |
| 1763 | priv->status &= ~STATUS_RF_KILL_HW; |
| 1764 | |
| 1765 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; |
| 1766 | } |
| 1767 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1768 | 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] | 1769 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1770 | { |
| 1771 | /* 0 - RF kill not enabled |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1772 | 1 - SW based RF kill active (sysfs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1773 | 2 - HW based RF kill active |
| 1774 | 3 - Both HW and SW baed RF kill active */ |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1775 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1776 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1777 | (rf_kill_active(priv) ? 0x2 : 0x0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1778 | return sprintf(buf, "%i\n", val); |
| 1779 | } |
| 1780 | |
| 1781 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) |
| 1782 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1783 | if ((disable_radio ? 1 : 0) == |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1784 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1785 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1786 | |
| 1787 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", |
| 1788 | disable_radio ? "OFF" : "ON"); |
| 1789 | |
| 1790 | if (disable_radio) { |
| 1791 | priv->status |= STATUS_RF_KILL_SW; |
| 1792 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 1793 | if (priv->workqueue) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1794 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 1795 | cancel_delayed_work(&priv->request_direct_scan); |
| 1796 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 1797 | cancel_delayed_work(&priv->scan_event); |
| 1798 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1799 | queue_work(priv->workqueue, &priv->down); |
| 1800 | } else { |
| 1801 | priv->status &= ~STATUS_RF_KILL_SW; |
| 1802 | if (rf_kill_active(priv)) { |
| 1803 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1804 | "disabled by HW switch\n"); |
| 1805 | /* Make sure the RF_KILL check timer is running */ |
| 1806 | cancel_delayed_work(&priv->rf_kill); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1807 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 1808 | round_jiffies_relative(2 * HZ)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1809 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1810 | queue_work(priv->workqueue, &priv->up); |
| 1811 | } |
| 1812 | |
| 1813 | return 1; |
| 1814 | } |
| 1815 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1816 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
| 1817 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1818 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1819 | struct ipw_priv *priv = dev_get_drvdata(d); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1820 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1821 | ipw_radio_kill_sw(priv, buf[0] == '1'); |
| 1822 | |
| 1823 | return count; |
| 1824 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1825 | |
| 1826 | 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] | 1827 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1828 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, |
| 1829 | char *buf) |
| 1830 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1831 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1832 | int pos = 0, len = 0; |
| 1833 | if (priv->config & CFG_SPEED_SCAN) { |
| 1834 | while (priv->speed_scan[pos] != 0) |
| 1835 | len += sprintf(&buf[len], "%d ", |
| 1836 | priv->speed_scan[pos++]); |
| 1837 | return len + sprintf(&buf[len], "\n"); |
| 1838 | } |
| 1839 | |
| 1840 | return sprintf(buf, "0\n"); |
| 1841 | } |
| 1842 | |
| 1843 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, |
| 1844 | const char *buf, size_t count) |
| 1845 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1846 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1847 | int channel, pos = 0; |
| 1848 | const char *p = buf; |
| 1849 | |
| 1850 | /* list of space separated channels to scan, optionally ending with 0 */ |
| 1851 | while ((channel = simple_strtol(p, NULL, 0))) { |
| 1852 | if (pos == MAX_SPEED_SCAN - 1) { |
| 1853 | priv->speed_scan[pos] = 0; |
| 1854 | break; |
| 1855 | } |
| 1856 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1857 | if (libipw_is_valid_channel(priv->ieee, channel)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1858 | priv->speed_scan[pos++] = channel; |
| 1859 | else |
| 1860 | IPW_WARNING("Skipping invalid channel request: %d\n", |
| 1861 | channel); |
| 1862 | p = strchr(p, ' '); |
| 1863 | if (!p) |
| 1864 | break; |
| 1865 | while (*p == ' ' || *p == '\t') |
| 1866 | p++; |
| 1867 | } |
| 1868 | |
| 1869 | if (pos == 0) |
| 1870 | priv->config &= ~CFG_SPEED_SCAN; |
| 1871 | else { |
| 1872 | priv->speed_scan_pos = 0; |
| 1873 | priv->config |= CFG_SPEED_SCAN; |
| 1874 | } |
| 1875 | |
| 1876 | return count; |
| 1877 | } |
| 1878 | |
| 1879 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, |
| 1880 | store_speed_scan); |
| 1881 | |
| 1882 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, |
| 1883 | char *buf) |
| 1884 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1885 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1886 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); |
| 1887 | } |
| 1888 | |
| 1889 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, |
| 1890 | const char *buf, size_t count) |
| 1891 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1892 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1893 | if (buf[0] == '1') |
| 1894 | priv->config |= CFG_NET_STATS; |
| 1895 | else |
| 1896 | priv->config &= ~CFG_NET_STATS; |
| 1897 | |
| 1898 | return count; |
| 1899 | } |
| 1900 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1901 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, |
| 1902 | show_net_stats, store_net_stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1903 | |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1904 | static ssize_t show_channels(struct device *d, |
| 1905 | struct device_attribute *attr, |
| 1906 | char *buf) |
| 1907 | { |
| 1908 | struct ipw_priv *priv = dev_get_drvdata(d); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1909 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1910 | int len = 0, i; |
| 1911 | |
| 1912 | len = sprintf(&buf[len], |
| 1913 | "Displaying %d channels in 2.4Ghz band " |
| 1914 | "(802.11bg):\n", geo->bg_channels); |
| 1915 | |
| 1916 | for (i = 0; i < geo->bg_channels; i++) { |
| 1917 | len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n", |
| 1918 | geo->bg[i].channel, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1919 | geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1920 | " (radar spectrum)" : "", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1921 | ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) || |
| 1922 | (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)) |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1923 | ? "" : ", IBSS", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1924 | geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1925 | "passive only" : "active/passive", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1926 | geo->bg[i].flags & LIBIPW_CH_B_ONLY ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1927 | "B" : "B/G"); |
| 1928 | } |
| 1929 | |
| 1930 | len += sprintf(&buf[len], |
| 1931 | "Displaying %d channels in 5.2Ghz band " |
| 1932 | "(802.11a):\n", geo->a_channels); |
| 1933 | for (i = 0; i < geo->a_channels; i++) { |
| 1934 | len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n", |
| 1935 | geo->a[i].channel, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1936 | geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1937 | " (radar spectrum)" : "", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1938 | ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) || |
| 1939 | (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)) |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1940 | ? "" : ", IBSS", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1941 | geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1942 | "passive only" : "active/passive"); |
| 1943 | } |
| 1944 | |
| 1945 | return len; |
| 1946 | } |
| 1947 | |
| 1948 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 1949 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1950 | static void notify_wx_assoc_event(struct ipw_priv *priv) |
| 1951 | { |
| 1952 | union iwreq_data wrqu; |
| 1953 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1954 | if (priv->status & STATUS_ASSOCIATED) |
| 1955 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); |
| 1956 | else |
| 1957 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 1958 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); |
| 1959 | } |
| 1960 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1961 | static void ipw_irq_tasklet(struct ipw_priv *priv) |
| 1962 | { |
| 1963 | u32 inta, inta_mask, handled = 0; |
| 1964 | unsigned long flags; |
| 1965 | int rc = 0; |
| 1966 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1967 | spin_lock_irqsave(&priv->irq_lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1968 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1969 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 1970 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
| 1971 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1972 | |
| 1973 | /* Add any cached INTA values that need to be handled */ |
| 1974 | inta |= priv->isr_inta; |
| 1975 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1976 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 1977 | |
| 1978 | spin_lock_irqsave(&priv->lock, flags); |
| 1979 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1980 | /* handle all the justifications for the interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1981 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1982 | ipw_rx(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1983 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1984 | } |
| 1985 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1986 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1987 | IPW_DEBUG_HC("Command completed.\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1988 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1989 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1990 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1991 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1992 | } |
| 1993 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1994 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1995 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1996 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1997 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1998 | } |
| 1999 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2000 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2001 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2002 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2003 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2004 | } |
| 2005 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2006 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2007 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2008 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2009 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2010 | } |
| 2011 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2012 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2013 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2014 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2015 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2016 | } |
| 2017 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2018 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2019 | IPW_WARNING("STATUS_CHANGE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2020 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2021 | } |
| 2022 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2023 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2024 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2025 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2026 | } |
| 2027 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2028 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2029 | IPW_WARNING("HOST_CMD_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2030 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2031 | } |
| 2032 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2033 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2034 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2035 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2036 | } |
| 2037 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2038 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2039 | IPW_WARNING("PHY_OFF_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2040 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2041 | } |
| 2042 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2043 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2044 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
| 2045 | priv->status |= STATUS_RF_KILL_HW; |
| 2046 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 2047 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2048 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 2049 | cancel_delayed_work(&priv->request_direct_scan); |
| 2050 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 2051 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2052 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2053 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2054 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2055 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2056 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2057 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2058 | IPW_WARNING("Firmware error detected. Restarting.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2059 | if (priv->error) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2060 | IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2061 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
| 2062 | struct ipw_fw_error *error = |
| 2063 | ipw_alloc_error_log(priv); |
| 2064 | ipw_dump_error_log(priv, error); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 2065 | kfree(error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2066 | } |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2067 | } else { |
| 2068 | priv->error = ipw_alloc_error_log(priv); |
| 2069 | if (priv->error) |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2070 | IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2071 | else |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2072 | IPW_DEBUG_FW("Error allocating sysfs 'error' " |
| 2073 | "log.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2074 | if (ipw_debug_level & IPW_DL_FW_ERRORS) |
| 2075 | ipw_dump_error_log(priv, priv->error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2076 | } |
| 2077 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2078 | /* XXX: If hardware encryption is for WPA/WPA2, |
| 2079 | * we have to notify the supplicant. */ |
| 2080 | if (priv->ieee->sec.encrypt) { |
| 2081 | priv->status &= ~STATUS_ASSOCIATED; |
| 2082 | notify_wx_assoc_event(priv); |
| 2083 | } |
| 2084 | |
| 2085 | /* Keep the restart process from trying to send host |
| 2086 | * commands by clearing the INIT status bit */ |
| 2087 | priv->status &= ~STATUS_INIT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2088 | |
| 2089 | /* Cancel currently queued command. */ |
| 2090 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2091 | wake_up_interruptible(&priv->wait_command_queue); |
| 2092 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2093 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2094 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2095 | } |
| 2096 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2097 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2098 | IPW_ERROR("Parity error\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2099 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | if (handled != inta) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2103 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2104 | } |
| 2105 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 2106 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2107 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2108 | /* enable all interrupts */ |
| 2109 | ipw_enable_interrupts(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2110 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2111 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2112 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
| 2113 | static char *get_cmd_string(u8 cmd) |
| 2114 | { |
| 2115 | switch (cmd) { |
| 2116 | IPW_CMD(HOST_COMPLETE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2117 | IPW_CMD(POWER_DOWN); |
| 2118 | IPW_CMD(SYSTEM_CONFIG); |
| 2119 | IPW_CMD(MULTICAST_ADDRESS); |
| 2120 | IPW_CMD(SSID); |
| 2121 | IPW_CMD(ADAPTER_ADDRESS); |
| 2122 | IPW_CMD(PORT_TYPE); |
| 2123 | IPW_CMD(RTS_THRESHOLD); |
| 2124 | IPW_CMD(FRAG_THRESHOLD); |
| 2125 | IPW_CMD(POWER_MODE); |
| 2126 | IPW_CMD(WEP_KEY); |
| 2127 | IPW_CMD(TGI_TX_KEY); |
| 2128 | IPW_CMD(SCAN_REQUEST); |
| 2129 | IPW_CMD(SCAN_REQUEST_EXT); |
| 2130 | IPW_CMD(ASSOCIATE); |
| 2131 | IPW_CMD(SUPPORTED_RATES); |
| 2132 | IPW_CMD(SCAN_ABORT); |
| 2133 | IPW_CMD(TX_FLUSH); |
| 2134 | IPW_CMD(QOS_PARAMETERS); |
| 2135 | IPW_CMD(DINO_CONFIG); |
| 2136 | IPW_CMD(RSN_CAPABILITIES); |
| 2137 | IPW_CMD(RX_KEY); |
| 2138 | IPW_CMD(CARD_DISABLE); |
| 2139 | IPW_CMD(SEED_NUMBER); |
| 2140 | IPW_CMD(TX_POWER); |
| 2141 | IPW_CMD(COUNTRY_INFO); |
| 2142 | IPW_CMD(AIRONET_INFO); |
| 2143 | IPW_CMD(AP_TX_POWER); |
| 2144 | IPW_CMD(CCKM_INFO); |
| 2145 | IPW_CMD(CCX_VER_INFO); |
| 2146 | IPW_CMD(SET_CALIBRATION); |
| 2147 | IPW_CMD(SENSITIVITY_CALIB); |
| 2148 | IPW_CMD(RETRY_LIMIT); |
| 2149 | IPW_CMD(IPW_PRE_POWER_DOWN); |
| 2150 | IPW_CMD(VAP_BEACON_TEMPLATE); |
| 2151 | IPW_CMD(VAP_DTIM_PERIOD); |
| 2152 | IPW_CMD(EXT_SUPPORTED_RATES); |
| 2153 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); |
| 2154 | IPW_CMD(VAP_QUIET_INTERVALS); |
| 2155 | IPW_CMD(VAP_CHANNEL_SWITCH); |
| 2156 | IPW_CMD(VAP_MANDATORY_CHANNELS); |
| 2157 | IPW_CMD(VAP_CELL_PWR_LIMIT); |
| 2158 | IPW_CMD(VAP_CF_PARAM_SET); |
| 2159 | IPW_CMD(VAP_SET_BEACONING_STATE); |
| 2160 | IPW_CMD(MEASUREMENT); |
| 2161 | IPW_CMD(POWER_CAPABILITY); |
| 2162 | IPW_CMD(SUPPORTED_CHANNELS); |
| 2163 | IPW_CMD(TPC_REPORT); |
| 2164 | IPW_CMD(WME_INFO); |
| 2165 | IPW_CMD(PRODUCTION_COMMAND); |
| 2166 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2167 | return "UNKNOWN"; |
| 2168 | } |
| 2169 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2170 | |
| 2171 | #define HOST_COMPLETE_TIMEOUT HZ |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2172 | |
| 2173 | 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] | 2174 | { |
| 2175 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2176 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2177 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2178 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2179 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2180 | IPW_ERROR("Failed to send %s: Already sending a command.\n", |
| 2181 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2182 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2183 | return -EAGAIN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | priv->status |= STATUS_HCMD_ACTIVE; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2187 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2188 | if (priv->cmdlog) { |
| 2189 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; |
| 2190 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; |
| 2191 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; |
| 2192 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, |
| 2193 | cmd->len); |
| 2194 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; |
| 2195 | } |
| 2196 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2197 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
| 2198 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, |
| 2199 | priv->status); |
Zhu Yi | f516dbc | 2006-01-24 16:36:44 +0800 | [diff] [blame] | 2200 | |
| 2201 | #ifndef DEBUG_CMD_WEP_KEY |
| 2202 | if (cmd->cmd == IPW_CMD_WEP_KEY) |
| 2203 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); |
| 2204 | else |
| 2205 | #endif |
| 2206 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); |
| 2207 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2208 | 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] | 2209 | if (rc) { |
| 2210 | priv->status &= ~STATUS_HCMD_ACTIVE; |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2211 | IPW_ERROR("Failed to send %s: Reason %d\n", |
| 2212 | get_cmd_string(cmd->cmd), rc); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2213 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2214 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2215 | } |
| 2216 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2217 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2218 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 2219 | !(priv-> |
| 2220 | status & STATUS_HCMD_ACTIVE), |
| 2221 | HOST_COMPLETE_TIMEOUT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2222 | if (rc == 0) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2223 | spin_lock_irqsave(&priv->lock, flags); |
| 2224 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2225 | IPW_ERROR("Failed to send %s: Command timed out.\n", |
| 2226 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2227 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2228 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2229 | rc = -EIO; |
| 2230 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2231 | } |
| 2232 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 2233 | } else |
| 2234 | rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2235 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2236 | if (priv->status & STATUS_RF_KILL_HW) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2237 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", |
| 2238 | get_cmd_string(cmd->cmd)); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2239 | rc = -EIO; |
| 2240 | goto exit; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2241 | } |
| 2242 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2243 | exit: |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2244 | if (priv->cmdlog) { |
| 2245 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; |
| 2246 | priv->cmdlog_pos %= priv->cmdlog_len; |
| 2247 | } |
| 2248 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2249 | } |
| 2250 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2251 | static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2252 | { |
| 2253 | struct host_cmd cmd = { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2254 | .cmd = command, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2255 | }; |
| 2256 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2257 | return __ipw_send_cmd(priv, &cmd); |
| 2258 | } |
| 2259 | |
| 2260 | static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, |
| 2261 | void *data) |
| 2262 | { |
| 2263 | struct host_cmd cmd = { |
| 2264 | .cmd = command, |
| 2265 | .len = len, |
| 2266 | .param = data, |
| 2267 | }; |
| 2268 | |
| 2269 | return __ipw_send_cmd(priv, &cmd); |
| 2270 | } |
| 2271 | |
| 2272 | static int ipw_send_host_complete(struct ipw_priv *priv) |
| 2273 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2274 | if (!priv) { |
| 2275 | IPW_ERROR("Invalid args\n"); |
| 2276 | return -1; |
| 2277 | } |
| 2278 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2279 | return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2280 | } |
| 2281 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2282 | static int ipw_send_system_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2283 | { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2284 | return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, |
| 2285 | sizeof(priv->sys_config), |
| 2286 | &priv->sys_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2287 | } |
| 2288 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2289 | 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] | 2290 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2291 | if (!priv || !ssid) { |
| 2292 | IPW_ERROR("Invalid args\n"); |
| 2293 | return -1; |
| 2294 | } |
| 2295 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2296 | 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] | 2297 | ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2298 | } |
| 2299 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2300 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2301 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2302 | if (!priv || !mac) { |
| 2303 | IPW_ERROR("Invalid args\n"); |
| 2304 | return -1; |
| 2305 | } |
| 2306 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2307 | IPW_DEBUG_INFO("%s: Setting MAC to %pM\n", |
| 2308 | priv->net_dev->name, mac); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2309 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2310 | 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] | 2311 | } |
| 2312 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2313 | /* |
| 2314 | * NOTE: This must be executed from our workqueue as it results in udelay |
| 2315 | * being called which may corrupt the keyboard if executed on default |
| 2316 | * workqueue |
| 2317 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2318 | static void ipw_adapter_restart(void *adapter) |
| 2319 | { |
| 2320 | struct ipw_priv *priv = adapter; |
| 2321 | |
| 2322 | if (priv->status & STATUS_RF_KILL_MASK) |
| 2323 | return; |
| 2324 | |
| 2325 | ipw_down(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2326 | |
| 2327 | if (priv->assoc_network && |
| 2328 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) |
| 2329 | ipw_remove_current_network(priv); |
| 2330 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2331 | if (ipw_up(priv)) { |
| 2332 | IPW_ERROR("Failed to up device\n"); |
| 2333 | return; |
| 2334 | } |
| 2335 | } |
| 2336 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2337 | static void ipw_bg_adapter_restart(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2338 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2339 | struct ipw_priv *priv = |
| 2340 | container_of(work, struct ipw_priv, adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2341 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2342 | ipw_adapter_restart(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2343 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2344 | } |
| 2345 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2346 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
| 2347 | |
| 2348 | static void ipw_scan_check(void *data) |
| 2349 | { |
| 2350 | struct ipw_priv *priv = data; |
| 2351 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
| 2352 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2353 | "adapter after (%dms).\n", |
| 2354 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2355 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2356 | } |
| 2357 | } |
| 2358 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2359 | static void ipw_bg_scan_check(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2360 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2361 | struct ipw_priv *priv = |
| 2362 | container_of(work, struct ipw_priv, scan_check.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2363 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2364 | ipw_scan_check(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2365 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2366 | } |
| 2367 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2368 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
| 2369 | struct ipw_scan_request_ext *request) |
| 2370 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2371 | return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2372 | sizeof(*request), request); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | static int ipw_send_scan_abort(struct ipw_priv *priv) |
| 2376 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2377 | if (!priv) { |
| 2378 | IPW_ERROR("Invalid args\n"); |
| 2379 | return -1; |
| 2380 | } |
| 2381 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2382 | return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) |
| 2386 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2387 | struct ipw_sensitivity_calib calib = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2388 | .beacon_rssi_raw = cpu_to_le16(sens), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2389 | }; |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2390 | |
| 2391 | return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2392 | &calib); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | static int ipw_send_associate(struct ipw_priv *priv, |
| 2396 | struct ipw_associate *associate) |
| 2397 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2398 | if (!priv || !associate) { |
| 2399 | IPW_ERROR("Invalid args\n"); |
| 2400 | return -1; |
| 2401 | } |
| 2402 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 2403 | return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate), |
| 2404 | associate); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | static int ipw_send_supported_rates(struct ipw_priv *priv, |
| 2408 | struct ipw_supported_rates *rates) |
| 2409 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2410 | if (!priv || !rates) { |
| 2411 | IPW_ERROR("Invalid args\n"); |
| 2412 | return -1; |
| 2413 | } |
| 2414 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2415 | return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2416 | rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | static int ipw_set_random_seed(struct ipw_priv *priv) |
| 2420 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2421 | u32 val; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2422 | |
| 2423 | if (!priv) { |
| 2424 | IPW_ERROR("Invalid args\n"); |
| 2425 | return -1; |
| 2426 | } |
| 2427 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2428 | get_random_bytes(&val, sizeof(val)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2429 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2430 | 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] | 2431 | } |
| 2432 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2433 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
| 2434 | { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2435 | __le32 v = cpu_to_le32(phy_off); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2436 | if (!priv) { |
| 2437 | IPW_ERROR("Invalid args\n"); |
| 2438 | return -1; |
| 2439 | } |
| 2440 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2441 | 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] | 2442 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2443 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2444 | 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] | 2445 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2446 | if (!priv || !power) { |
| 2447 | IPW_ERROR("Invalid args\n"); |
| 2448 | return -1; |
| 2449 | } |
| 2450 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2451 | 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] | 2452 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2453 | |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2454 | static int ipw_set_tx_power(struct ipw_priv *priv) |
| 2455 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2456 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2457 | struct ipw_tx_power tx_power; |
| 2458 | s8 max_power; |
| 2459 | int i; |
| 2460 | |
| 2461 | memset(&tx_power, 0, sizeof(tx_power)); |
| 2462 | |
| 2463 | /* configure device for 'G' band */ |
| 2464 | tx_power.ieee_mode = IPW_G_MODE; |
| 2465 | tx_power.num_channels = geo->bg_channels; |
| 2466 | for (i = 0; i < geo->bg_channels; i++) { |
| 2467 | max_power = geo->bg[i].max_power; |
| 2468 | tx_power.channels_tx_power[i].channel_number = |
| 2469 | geo->bg[i].channel; |
| 2470 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2471 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2472 | } |
| 2473 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2474 | return -EIO; |
| 2475 | |
| 2476 | /* configure device to also handle 'B' band */ |
| 2477 | tx_power.ieee_mode = IPW_B_MODE; |
| 2478 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2479 | return -EIO; |
| 2480 | |
| 2481 | /* configure device to also handle 'A' band */ |
| 2482 | if (priv->ieee->abg_true) { |
| 2483 | tx_power.ieee_mode = IPW_A_MODE; |
| 2484 | tx_power.num_channels = geo->a_channels; |
| 2485 | for (i = 0; i < tx_power.num_channels; i++) { |
| 2486 | max_power = geo->a[i].max_power; |
| 2487 | tx_power.channels_tx_power[i].channel_number = |
| 2488 | geo->a[i].channel; |
| 2489 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2490 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2491 | } |
| 2492 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2493 | return -EIO; |
| 2494 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2495 | return 0; |
| 2496 | } |
| 2497 | |
| 2498 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) |
| 2499 | { |
| 2500 | struct ipw_rts_threshold rts_threshold = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2501 | .rts_threshold = cpu_to_le16(rts), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2502 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2503 | |
| 2504 | if (!priv) { |
| 2505 | IPW_ERROR("Invalid args\n"); |
| 2506 | return -1; |
| 2507 | } |
| 2508 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2509 | return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, |
| 2510 | sizeof(rts_threshold), &rts_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) |
| 2514 | { |
| 2515 | struct ipw_frag_threshold frag_threshold = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2516 | .frag_threshold = cpu_to_le16(frag), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2517 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2518 | |
| 2519 | if (!priv) { |
| 2520 | IPW_ERROR("Invalid args\n"); |
| 2521 | return -1; |
| 2522 | } |
| 2523 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2524 | return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, |
| 2525 | sizeof(frag_threshold), &frag_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) |
| 2529 | { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2530 | __le32 param; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2531 | |
| 2532 | if (!priv) { |
| 2533 | IPW_ERROR("Invalid args\n"); |
| 2534 | return -1; |
| 2535 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2536 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2537 | /* If on battery, set to 3, if AC set to CAM, else user |
| 2538 | * level */ |
| 2539 | switch (mode) { |
| 2540 | case IPW_POWER_BATTERY: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2541 | param = cpu_to_le32(IPW_POWER_INDEX_3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2542 | break; |
| 2543 | case IPW_POWER_AC: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2544 | param = cpu_to_le32(IPW_POWER_MODE_CAM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2545 | break; |
| 2546 | default: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2547 | param = cpu_to_le32(mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2548 | break; |
| 2549 | } |
| 2550 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2551 | return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2552 | ¶m); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2553 | } |
| 2554 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2555 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
| 2556 | { |
| 2557 | struct ipw_retry_limit retry_limit = { |
| 2558 | .short_retry_limit = slimit, |
| 2559 | .long_retry_limit = llimit |
| 2560 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2561 | |
| 2562 | if (!priv) { |
| 2563 | IPW_ERROR("Invalid args\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2564 | return -1; |
| 2565 | } |
| 2566 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2567 | 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] | 2568 | &retry_limit); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | /* |
| 2572 | * The IPW device contains a Microwire compatible EEPROM that stores |
| 2573 | * various data like the MAC address. Usually the firmware has exclusive |
| 2574 | * access to the eeprom, but during device initialization (before the |
| 2575 | * device driver has sent the HostComplete command to the firmware) the |
| 2576 | * device driver has read access to the EEPROM by way of indirect addressing |
| 2577 | * through a couple of memory mapped registers. |
| 2578 | * |
| 2579 | * The following is a simplified implementation for pulling data out of the |
| 2580 | * the eeprom, along with some helper functions to find information in |
| 2581 | * the per device private data's copy of the eeprom. |
| 2582 | * |
| 2583 | * NOTE: To better understand how these functions work (i.e what is a chip |
| 2584 | * select and why do have to keep driving the eeprom clock?), read |
| 2585 | * just about any data sheet for a Microwire compatible EEPROM. |
| 2586 | */ |
| 2587 | |
| 2588 | /* write a 32 bit value into the indirect accessor register */ |
| 2589 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) |
| 2590 | { |
| 2591 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2592 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2593 | /* the eeprom requires some time to complete the operation */ |
| 2594 | udelay(p->eeprom_delay); |
| 2595 | |
| 2596 | return; |
| 2597 | } |
| 2598 | |
| 2599 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2600 | static void eeprom_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2601 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2602 | eeprom_write_reg(priv, 0); |
| 2603 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2604 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2605 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2609 | static void eeprom_disable_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2610 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2611 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2612 | eeprom_write_reg(priv, 0); |
| 2613 | eeprom_write_reg(priv, EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | /* push a single bit down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2617 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2618 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2619 | int d = (bit ? EEPROM_BIT_DI : 0); |
| 2620 | eeprom_write_reg(p, EEPROM_BIT_CS | d); |
| 2621 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | /* push an opcode followed by an address down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2625 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2626 | { |
| 2627 | int i; |
| 2628 | |
| 2629 | eeprom_cs(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2630 | eeprom_write_bit(priv, 1); |
| 2631 | eeprom_write_bit(priv, op & 2); |
| 2632 | eeprom_write_bit(priv, op & 1); |
| 2633 | for (i = 7; i >= 0; i--) { |
| 2634 | eeprom_write_bit(priv, addr & (1 << i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | /* pull 16 bits off the eeprom, one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2639 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2640 | { |
| 2641 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2642 | u16 r = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2643 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2644 | /* Send READ Opcode */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2645 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2646 | |
| 2647 | /* Send dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2648 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2649 | |
| 2650 | /* Read the byte off the eeprom one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2651 | for (i = 0; i < 16; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2652 | u32 data = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2653 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2654 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2655 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); |
| 2656 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2657 | } |
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 | /* Send another dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2660 | eeprom_write_reg(priv, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2661 | eeprom_disable_cs(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2662 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2663 | return r; |
| 2664 | } |
| 2665 | |
| 2666 | /* helper function for pulling the mac address out of the private */ |
| 2667 | /* data's copy of the eeprom data */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2668 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2669 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2670 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | /* |
| 2674 | * Either the device driver (i.e. the host) or the firmware can |
| 2675 | * load eeprom data into the designated region in SRAM. If neither |
| 2676 | * happens then the FW will shutdown with a fatal error. |
| 2677 | * |
| 2678 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE |
| 2679 | * bit needs region of shared SRAM needs to be non-zero. |
| 2680 | */ |
| 2681 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) |
| 2682 | { |
| 2683 | int i; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2684 | __le16 *eeprom = (__le16 *) priv->eeprom; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2685 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2686 | IPW_DEBUG_TRACE(">>\n"); |
| 2687 | |
| 2688 | /* read entire contents of eeprom into private buffer */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2689 | for (i = 0; i < 128; i++) |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2690 | eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2691 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2692 | /* |
| 2693 | If the data looks correct, then copy it to our private |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2694 | copy. Otherwise let the firmware know to perform the operation |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2695 | on its own. |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2696 | */ |
Alexey Dobriyan | 386093e | 2006-02-01 03:04:57 -0800 | [diff] [blame] | 2697 | if (priv->eeprom[EEPROM_VERSION] != 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2698 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
| 2699 | |
| 2700 | /* write the eeprom data to sram */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2701 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2702 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2703 | |
| 2704 | /* Do not load eeprom data on fatal error or suspend */ |
| 2705 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 2706 | } else { |
| 2707 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); |
| 2708 | |
| 2709 | /* Load eeprom data on fatal error or suspend */ |
| 2710 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); |
| 2711 | } |
| 2712 | |
| 2713 | IPW_DEBUG_TRACE("<<\n"); |
| 2714 | } |
| 2715 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2716 | 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] | 2717 | { |
| 2718 | count >>= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2719 | if (!count) |
| 2720 | return; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2721 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2722 | while (count--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2723 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) |
| 2727 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2728 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2729 | CB_NUMBER_OF_ELEMENTS_SMALL * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2730 | sizeof(struct command_block)); |
| 2731 | } |
| 2732 | |
| 2733 | static int ipw_fw_dma_enable(struct ipw_priv *priv) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2734 | { /* start dma engine but no transfers yet */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2735 | |
| 2736 | IPW_DEBUG_FW(">> : \n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2737 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2738 | /* Start the dma */ |
| 2739 | ipw_fw_dma_reset_command_blocks(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2740 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2741 | /* Write CB base address */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2742 | 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] | 2743 | |
| 2744 | IPW_DEBUG_FW("<< : \n"); |
| 2745 | return 0; |
| 2746 | } |
| 2747 | |
| 2748 | static void ipw_fw_dma_abort(struct ipw_priv *priv) |
| 2749 | { |
| 2750 | u32 control = 0; |
| 2751 | |
| 2752 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2753 | |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 2754 | /* set the Stop and Abort bit */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2755 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2756 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2757 | priv->sram_desc.last_cb_index = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2758 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2759 | IPW_DEBUG_FW("<< \n"); |
| 2760 | } |
| 2761 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2762 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
| 2763 | struct command_block *cb) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2764 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2765 | u32 address = |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2766 | IPW_SHARED_SRAM_DMA_CONTROL + |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2767 | (sizeof(struct command_block) * index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2768 | IPW_DEBUG_FW(">> :\n"); |
| 2769 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2770 | ipw_write_indirect(priv, address, (u8 *) cb, |
| 2771 | (int)sizeof(struct command_block)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2772 | |
| 2773 | IPW_DEBUG_FW("<< :\n"); |
| 2774 | return 0; |
| 2775 | |
| 2776 | } |
| 2777 | |
| 2778 | static int ipw_fw_dma_kick(struct ipw_priv *priv) |
| 2779 | { |
| 2780 | u32 control = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2781 | u32 index = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2782 | |
| 2783 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2784 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2785 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2786 | ipw_fw_dma_write_command_block(priv, index, |
| 2787 | &priv->sram_desc.cb_list[index]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2788 | |
| 2789 | /* Enable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2790 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 2791 | IPW_RESET_REG_MASTER_DISABLED | |
| 2792 | IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2793 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2794 | /* Set the Start bit. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2795 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2796 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2797 | |
| 2798 | IPW_DEBUG_FW("<< :\n"); |
| 2799 | return 0; |
| 2800 | } |
| 2801 | |
| 2802 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) |
| 2803 | { |
| 2804 | u32 address; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2805 | u32 register_value = 0; |
| 2806 | u32 cb_fields_address = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2807 | |
| 2808 | IPW_DEBUG_FW(">> :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2809 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2810 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2811 | |
| 2812 | /* Read the DMA Controlor register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2813 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
| 2814 | 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] | 2815 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2816 | /* Print the CB values */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2817 | cb_fields_address = address; |
| 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 ControlField 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); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2823 | 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] | 2824 | |
| 2825 | cb_fields_address += sizeof(u32); |
| 2826 | register_value = ipw_read_reg32(priv, cb_fields_address); |
| 2827 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", |
| 2828 | register_value); |
| 2829 | |
| 2830 | cb_fields_address += sizeof(u32); |
| 2831 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2832 | 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] | 2833 | |
| 2834 | IPW_DEBUG_FW(">> :\n"); |
| 2835 | } |
| 2836 | |
| 2837 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) |
| 2838 | { |
| 2839 | u32 current_cb_address = 0; |
| 2840 | u32 current_cb_index = 0; |
| 2841 | |
| 2842 | IPW_DEBUG_FW("<< :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2843 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2844 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2845 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2846 | sizeof(struct command_block); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2847 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2848 | 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] | 2849 | current_cb_index, current_cb_address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2850 | |
| 2851 | IPW_DEBUG_FW(">> :\n"); |
| 2852 | return current_cb_index; |
| 2853 | |
| 2854 | } |
| 2855 | |
| 2856 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, |
| 2857 | u32 src_address, |
| 2858 | u32 dest_address, |
| 2859 | u32 length, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2860 | int interrupt_enabled, int is_last) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2861 | { |
| 2862 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2863 | 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] | 2864 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
| 2865 | CB_DEST_SIZE_LONG; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2866 | struct command_block *cb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2867 | u32 last_cb_element = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2868 | |
| 2869 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", |
| 2870 | src_address, dest_address, length); |
| 2871 | |
| 2872 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) |
| 2873 | return -1; |
| 2874 | |
| 2875 | last_cb_element = priv->sram_desc.last_cb_index; |
| 2876 | cb = &priv->sram_desc.cb_list[last_cb_element]; |
| 2877 | priv->sram_desc.last_cb_index++; |
| 2878 | |
| 2879 | /* Calculate the new CB control word */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2880 | if (interrupt_enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2881 | control |= CB_INT_ENABLED; |
| 2882 | |
| 2883 | if (is_last) |
| 2884 | control |= CB_LAST_VALID; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2885 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2886 | control |= length; |
| 2887 | |
| 2888 | /* Calculate the CB Element's checksum value */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2889 | cb->status = control ^ src_address ^ dest_address; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2890 | |
| 2891 | /* Copy the Source and Destination addresses */ |
| 2892 | cb->dest_addr = dest_address; |
| 2893 | cb->source_addr = src_address; |
| 2894 | |
| 2895 | /* Copy the Control Word last */ |
| 2896 | cb->control = control; |
| 2897 | |
| 2898 | return 0; |
| 2899 | } |
| 2900 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2901 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address, |
| 2902 | int nr, u32 dest_address, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2903 | { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2904 | int ret, i; |
| 2905 | u32 size; |
| 2906 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2907 | IPW_DEBUG_FW(">> \n"); |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2908 | IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n", |
| 2909 | nr, dest_address, len); |
| 2910 | |
| 2911 | for (i = 0; i < nr; i++) { |
| 2912 | size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH); |
| 2913 | ret = ipw_fw_dma_add_command_block(priv, src_address[i], |
| 2914 | dest_address + |
| 2915 | i * CB_MAX_LENGTH, size, |
| 2916 | 0, 0); |
| 2917 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2918 | IPW_DEBUG_FW_INFO(": Failed\n"); |
| 2919 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2920 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2921 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2922 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2923 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2924 | IPW_DEBUG_FW("<< \n"); |
| 2925 | return 0; |
| 2926 | } |
| 2927 | |
| 2928 | static int ipw_fw_dma_wait(struct ipw_priv *priv) |
| 2929 | { |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2930 | u32 current_index = 0, previous_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2931 | u32 watchdog = 0; |
| 2932 | |
| 2933 | IPW_DEBUG_FW(">> : \n"); |
| 2934 | |
| 2935 | current_index = ipw_fw_dma_command_block_index(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2936 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2937 | (int)priv->sram_desc.last_cb_index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2938 | |
| 2939 | while (current_index < priv->sram_desc.last_cb_index) { |
| 2940 | udelay(50); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2941 | previous_index = current_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2942 | current_index = ipw_fw_dma_command_block_index(priv); |
| 2943 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2944 | if (previous_index < current_index) { |
| 2945 | watchdog = 0; |
| 2946 | continue; |
| 2947 | } |
| 2948 | if (++watchdog > 400) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2949 | IPW_DEBUG_FW_INFO("Timeout\n"); |
| 2950 | ipw_fw_dma_dump_command_block(priv); |
| 2951 | ipw_fw_dma_abort(priv); |
| 2952 | return -1; |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | ipw_fw_dma_abort(priv); |
| 2957 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2958 | /*Disable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2959 | ipw_set_bit(priv, IPW_RESET_REG, |
| 2960 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2961 | |
| 2962 | IPW_DEBUG_FW("<< dmaWaitSync \n"); |
| 2963 | return 0; |
| 2964 | } |
| 2965 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2966 | static void ipw_remove_current_network(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2967 | { |
| 2968 | struct list_head *element, *safe; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2969 | struct libipw_network *network = NULL; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2970 | unsigned long flags; |
| 2971 | |
| 2972 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2973 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2974 | network = list_entry(element, struct libipw_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2975 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 2976 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2977 | list_add_tail(&network->list, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2978 | &priv->ieee->network_free_list); |
| 2979 | } |
| 2980 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2981 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | /** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2985 | * Check that card is still alive. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2986 | * Reads debug register from domain0. |
| 2987 | * If card is present, pre-defined value should |
| 2988 | * be found there. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2989 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2990 | * @param priv |
| 2991 | * @return 1 if card is present, 0 otherwise |
| 2992 | */ |
| 2993 | static inline int ipw_alive(struct ipw_priv *priv) |
| 2994 | { |
| 2995 | return ipw_read32(priv, 0x90) == 0xd55555d5; |
| 2996 | } |
| 2997 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2998 | /* timeout in msec, attempted in 10-msec quanta */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2999 | 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] | 3000 | int timeout) |
| 3001 | { |
| 3002 | int i = 0; |
| 3003 | |
| 3004 | do { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3005 | if ((ipw_read32(priv, addr) & mask) == mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3006 | return i; |
| 3007 | mdelay(10); |
| 3008 | i += 10; |
| 3009 | } while (i < timeout); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3010 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3011 | return -ETIME; |
| 3012 | } |
| 3013 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3014 | /* These functions load the firmware and micro code for the operation of |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3015 | * the ipw hardware. It assumes the buffer has all the bits for the |
| 3016 | * image and the caller is handling the memory allocation and clean up. |
| 3017 | */ |
| 3018 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3019 | static int ipw_stop_master(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3020 | { |
| 3021 | int rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3022 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3023 | IPW_DEBUG_TRACE(">> \n"); |
| 3024 | /* stop master. typical delay - 0 */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3025 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3026 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3027 | /* timeout is in msec, polled in 10-msec quanta */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3028 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3029 | IPW_RESET_REG_MASTER_DISABLED, 100); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3030 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3031 | IPW_ERROR("wait for stop master failed after 100ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3032 | return -1; |
| 3033 | } |
| 3034 | |
| 3035 | IPW_DEBUG_INFO("stop master %dms\n", rc); |
| 3036 | |
| 3037 | return rc; |
| 3038 | } |
| 3039 | |
| 3040 | static void ipw_arc_release(struct ipw_priv *priv) |
| 3041 | { |
| 3042 | IPW_DEBUG_TRACE(">> \n"); |
| 3043 | mdelay(5); |
| 3044 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3045 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3046 | |
| 3047 | /* no one knows timing, for safety add some delay */ |
| 3048 | mdelay(5); |
| 3049 | } |
| 3050 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3051 | struct fw_chunk { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3052 | __le32 address; |
| 3053 | __le32 length; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3054 | }; |
| 3055 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3056 | 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] | 3057 | { |
| 3058 | int rc = 0, i, addr; |
| 3059 | u8 cr = 0; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3060 | __le16 *image; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3061 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3062 | image = (__le16 *) data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3063 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3064 | IPW_DEBUG_TRACE(">> \n"); |
| 3065 | |
| 3066 | rc = ipw_stop_master(priv); |
| 3067 | |
| 3068 | if (rc < 0) |
| 3069 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3070 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3071 | for (addr = IPW_SHARED_LOWER_BOUND; |
| 3072 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3073 | ipw_write32(priv, addr, 0); |
| 3074 | } |
| 3075 | |
| 3076 | /* no ucode (yet) */ |
| 3077 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); |
| 3078 | /* destroy DMA queues */ |
| 3079 | /* reset sequence */ |
| 3080 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3081 | 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] | 3082 | ipw_arc_release(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3083 | 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] | 3084 | mdelay(1); |
| 3085 | |
| 3086 | /* reset PHY */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3087 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3088 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3089 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3090 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3091 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3092 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3093 | /* enable ucode store */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 3094 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
| 3095 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3096 | mdelay(1); |
| 3097 | |
| 3098 | /* write ucode */ |
| 3099 | /** |
| 3100 | * @bug |
| 3101 | * Do NOT set indirect address register once and then |
| 3102 | * store data to indirect data register in the loop. |
| 3103 | * It seems very reasonable, but in this case DINO do not |
| 3104 | * accept ucode. It is essential to set address each time. |
| 3105 | */ |
| 3106 | /* load new ipw uCode */ |
| 3107 | for (i = 0; i < len / 2; i++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3108 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3109 | le16_to_cpu(image[i])); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3110 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3111 | /* enable DINO */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3112 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
| 3113 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3114 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3115 | /* this is where the igx / win driver deveates from the VAP driver. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3116 | |
| 3117 | /* wait for alive response */ |
| 3118 | for (i = 0; i < 100; i++) { |
| 3119 | /* poll for incoming data */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3120 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3121 | if (cr & DINO_RXFIFO_DATA) |
| 3122 | break; |
| 3123 | mdelay(1); |
| 3124 | } |
| 3125 | |
| 3126 | if (cr & DINO_RXFIFO_DATA) { |
| 3127 | /* alive_command_responce size is NOT multiple of 4 */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3128 | __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3129 | |
| 3130 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3131 | response_buffer[i] = |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3132 | cpu_to_le32(ipw_read_reg32(priv, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3133 | IPW_BASEBAND_RX_FIFO_READ)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3134 | memcpy(&priv->dino_alive, response_buffer, |
| 3135 | sizeof(priv->dino_alive)); |
| 3136 | if (priv->dino_alive.alive_command == 1 |
| 3137 | && priv->dino_alive.ucode_valid == 1) { |
| 3138 | rc = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3139 | IPW_DEBUG_INFO |
| 3140 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " |
| 3141 | "of %02d/%02d/%02d %02d:%02d\n", |
| 3142 | priv->dino_alive.software_revision, |
| 3143 | priv->dino_alive.software_revision, |
| 3144 | priv->dino_alive.device_identifier, |
| 3145 | priv->dino_alive.device_identifier, |
| 3146 | priv->dino_alive.time_stamp[0], |
| 3147 | priv->dino_alive.time_stamp[1], |
| 3148 | priv->dino_alive.time_stamp[2], |
| 3149 | priv->dino_alive.time_stamp[3], |
| 3150 | priv->dino_alive.time_stamp[4]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3151 | } else { |
| 3152 | IPW_DEBUG_INFO("Microcode is not alive\n"); |
| 3153 | rc = -EINVAL; |
| 3154 | } |
| 3155 | } else { |
| 3156 | IPW_DEBUG_INFO("No alive response from DINO\n"); |
| 3157 | rc = -ETIME; |
| 3158 | } |
| 3159 | |
| 3160 | /* disable DINO, otherwise for some reason |
| 3161 | firmware have problem getting alive resp. */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3162 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3163 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3164 | return rc; |
| 3165 | } |
| 3166 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3167 | 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] | 3168 | { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3169 | int ret = -1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3170 | int offset = 0; |
| 3171 | struct fw_chunk *chunk; |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3172 | int total_nr = 0; |
| 3173 | int i; |
| 3174 | struct pci_pool *pool; |
| 3175 | u32 *virts[CB_NUMBER_OF_ELEMENTS_SMALL]; |
| 3176 | dma_addr_t phys[CB_NUMBER_OF_ELEMENTS_SMALL]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3177 | |
| 3178 | IPW_DEBUG_TRACE("<< : \n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3179 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3180 | pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0); |
| 3181 | if (!pool) { |
| 3182 | IPW_ERROR("pci_pool_create failed\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3183 | return -ENOMEM; |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3184 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3185 | |
| 3186 | /* Start the Dma */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3187 | ret = ipw_fw_dma_enable(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3188 | |
Alexander Beregalov | 0ee904c | 2009-04-11 14:50:23 +0000 | [diff] [blame] | 3189 | /* the DMA is already ready this would be a bug. */ |
| 3190 | BUG_ON(priv->sram_desc.last_cb_index > 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3191 | |
| 3192 | do { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3193 | u32 chunk_len; |
| 3194 | u8 *start; |
| 3195 | int size; |
| 3196 | int nr = 0; |
| 3197 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3198 | chunk = (struct fw_chunk *)(data + offset); |
| 3199 | offset += sizeof(struct fw_chunk); |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3200 | chunk_len = le32_to_cpu(chunk->length); |
| 3201 | start = data + offset; |
| 3202 | |
| 3203 | nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH; |
| 3204 | for (i = 0; i < nr; i++) { |
| 3205 | virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL, |
| 3206 | &phys[total_nr]); |
| 3207 | if (!virts[total_nr]) { |
| 3208 | ret = -ENOMEM; |
| 3209 | goto out; |
| 3210 | } |
| 3211 | size = min_t(u32, chunk_len - i * CB_MAX_LENGTH, |
| 3212 | CB_MAX_LENGTH); |
| 3213 | memcpy(virts[total_nr], start, size); |
| 3214 | start += size; |
| 3215 | total_nr++; |
| 3216 | /* We don't support fw chunk larger than 64*8K */ |
| 3217 | BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL); |
| 3218 | } |
| 3219 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3220 | /* build DMA packet and queue up for sending */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3221 | /* dma to chunk->address, the chunk->length bytes from data + |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3222 | * offeset*/ |
| 3223 | /* Dma loading */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3224 | ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr], |
| 3225 | nr, le32_to_cpu(chunk->address), |
| 3226 | chunk_len); |
| 3227 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3228 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
| 3229 | goto out; |
| 3230 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3231 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3232 | offset += chunk_len; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3233 | } while (offset < len); |
| 3234 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3235 | /* Run the DMA and wait for the answer */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3236 | ret = ipw_fw_dma_kick(priv); |
| 3237 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3238 | IPW_ERROR("dmaKick Failed\n"); |
| 3239 | goto out; |
| 3240 | } |
| 3241 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3242 | ret = ipw_fw_dma_wait(priv); |
| 3243 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3244 | IPW_ERROR("dmaWaitSync Failed\n"); |
| 3245 | goto out; |
| 3246 | } |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3247 | out: |
| 3248 | for (i = 0; i < total_nr; i++) |
| 3249 | pci_pool_free(pool, virts[i], phys[i]); |
| 3250 | |
| 3251 | pci_pool_destroy(pool); |
| 3252 | |
| 3253 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | /* stop nic */ |
| 3257 | static int ipw_stop_nic(struct ipw_priv *priv) |
| 3258 | { |
| 3259 | int rc = 0; |
| 3260 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3261 | /* stop */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3262 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3263 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3264 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3265 | IPW_RESET_REG_MASTER_DISABLED, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3266 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3267 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3268 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3269 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3270 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3271 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3272 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3273 | return rc; |
| 3274 | } |
| 3275 | |
| 3276 | static void ipw_start_nic(struct ipw_priv *priv) |
| 3277 | { |
| 3278 | IPW_DEBUG_TRACE(">>\n"); |
| 3279 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3280 | /* prvHwStartNic release ARC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3281 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 3282 | IPW_RESET_REG_MASTER_DISABLED | |
| 3283 | IPW_RESET_REG_STOP_MASTER | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3284 | CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3285 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3286 | /* enable power management */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3287 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
| 3288 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3289 | |
| 3290 | IPW_DEBUG_TRACE("<<\n"); |
| 3291 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3292 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3293 | static int ipw_init_nic(struct ipw_priv *priv) |
| 3294 | { |
| 3295 | int rc; |
| 3296 | |
| 3297 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3298 | /* reset */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3299 | /*prvHwInitNic */ |
| 3300 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3301 | 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] | 3302 | |
| 3303 | /* low-level PLL activation */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3304 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
| 3305 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3306 | |
| 3307 | /* wait for clock stabilization */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3308 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
| 3309 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3310 | if (rc < 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3311 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
| 3312 | |
| 3313 | /* assert SW reset */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3314 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3315 | |
| 3316 | udelay(10); |
| 3317 | |
| 3318 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3319 | 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] | 3320 | |
| 3321 | IPW_DEBUG_TRACE(">>\n"); |
| 3322 | return 0; |
| 3323 | } |
| 3324 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3325 | /* Call this function from process context, it will sleep in request_firmware. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3326 | * Probe is an ok place to call this from. |
| 3327 | */ |
| 3328 | static int ipw_reset_nic(struct ipw_priv *priv) |
| 3329 | { |
| 3330 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3331 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3332 | |
| 3333 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3334 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3335 | rc = ipw_init_nic(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3336 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3337 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3338 | /* Clear the 'host command active' bit... */ |
| 3339 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 3340 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3341 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 3342 | wake_up_interruptible(&priv->wait_state); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3343 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3344 | |
| 3345 | IPW_DEBUG_TRACE("<<\n"); |
| 3346 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3347 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3348 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3349 | |
| 3350 | struct ipw_fw { |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3351 | __le32 ver; |
| 3352 | __le32 boot_size; |
| 3353 | __le32 ucode_size; |
| 3354 | __le32 fw_size; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3355 | u8 data[0]; |
| 3356 | }; |
| 3357 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3358 | static int ipw_get_fw(struct ipw_priv *priv, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3359 | const struct firmware **raw, const char *name) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3360 | { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3361 | struct ipw_fw *fw; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3362 | int rc; |
| 3363 | |
| 3364 | /* ask firmware_class module to get the boot firmware off disk */ |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3365 | rc = request_firmware(raw, name, &priv->pci_dev->dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3366 | if (rc < 0) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3367 | IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3368 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3369 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3370 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3371 | if ((*raw)->size < sizeof(*fw)) { |
| 3372 | IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3373 | return -EINVAL; |
| 3374 | } |
| 3375 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3376 | fw = (void *)(*raw)->data; |
| 3377 | |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3378 | if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) + |
| 3379 | le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3380 | IPW_ERROR("%s is too small or corrupt (%zd)\n", |
| 3381 | name, (*raw)->size); |
| 3382 | return -EINVAL; |
| 3383 | } |
| 3384 | |
| 3385 | 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] | 3386 | name, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3387 | le32_to_cpu(fw->ver) >> 16, |
| 3388 | le32_to_cpu(fw->ver) & 0xff, |
| 3389 | (*raw)->size - sizeof(*fw)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3390 | return 0; |
| 3391 | } |
| 3392 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3393 | #define IPW_RX_BUF_SIZE (3000) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3394 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3395 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3396 | struct ipw_rx_queue *rxq) |
| 3397 | { |
| 3398 | unsigned long flags; |
| 3399 | int i; |
| 3400 | |
| 3401 | spin_lock_irqsave(&rxq->lock, flags); |
| 3402 | |
| 3403 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3404 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3405 | |
| 3406 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3407 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3408 | /* In the reset function, these buffers may have been allocated |
| 3409 | * to an SKB, so we need to unmap and free potential storage */ |
| 3410 | if (rxq->pool[i].skb != NULL) { |
| 3411 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3412 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3413 | dev_kfree_skb(rxq->pool[i].skb); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3414 | rxq->pool[i].skb = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3415 | } |
| 3416 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3417 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3418 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3419 | /* Set us so that we have processed and used all buffers, but have |
| 3420 | * not restocked the Rx queue with fresh buffers */ |
| 3421 | rxq->read = rxq->write = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3422 | rxq->free_count = 0; |
| 3423 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3424 | } |
| 3425 | |
| 3426 | #ifdef CONFIG_PM |
| 3427 | static int fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3428 | static const struct firmware *raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3429 | |
| 3430 | static void free_firmware(void) |
| 3431 | { |
| 3432 | if (fw_loaded) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3433 | release_firmware(raw); |
| 3434 | raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3435 | fw_loaded = 0; |
| 3436 | } |
| 3437 | } |
| 3438 | #else |
| 3439 | #define free_firmware() do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3440 | #endif |
| 3441 | |
| 3442 | static int ipw_load(struct ipw_priv *priv) |
| 3443 | { |
| 3444 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3445 | const struct firmware *raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3446 | #endif |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3447 | struct ipw_fw *fw; |
| 3448 | u8 *boot_img, *ucode_img, *fw_img; |
| 3449 | u8 *name = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3450 | int rc = 0, retries = 3; |
| 3451 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3452 | switch (priv->ieee->iw_mode) { |
| 3453 | case IW_MODE_ADHOC: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3454 | name = "ipw2200-ibss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3455 | break; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3456 | #ifdef CONFIG_IPW2200_MONITOR |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3457 | case IW_MODE_MONITOR: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3458 | name = "ipw2200-sniffer.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 | #endif |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3461 | case IW_MODE_INFRA: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3462 | name = "ipw2200-bss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3463 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3464 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3465 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3466 | if (!name) { |
| 3467 | rc = -EINVAL; |
| 3468 | goto error; |
| 3469 | } |
| 3470 | |
| 3471 | #ifdef CONFIG_PM |
| 3472 | if (!fw_loaded) { |
| 3473 | #endif |
| 3474 | rc = ipw_get_fw(priv, &raw, name); |
| 3475 | if (rc < 0) |
| 3476 | goto error; |
| 3477 | #ifdef CONFIG_PM |
| 3478 | } |
| 3479 | #endif |
| 3480 | |
| 3481 | fw = (void *)raw->data; |
| 3482 | boot_img = &fw->data[0]; |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3483 | ucode_img = &fw->data[le32_to_cpu(fw->boot_size)]; |
| 3484 | fw_img = &fw->data[le32_to_cpu(fw->boot_size) + |
| 3485 | le32_to_cpu(fw->ucode_size)]; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3486 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3487 | if (rc < 0) |
| 3488 | goto error; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3489 | |
| 3490 | if (!priv->rxq) |
| 3491 | priv->rxq = ipw_rx_queue_alloc(priv); |
| 3492 | else |
| 3493 | ipw_rx_queue_reset(priv, priv->rxq); |
| 3494 | if (!priv->rxq) { |
| 3495 | IPW_ERROR("Unable to initialize Rx queue\n"); |
| 3496 | goto error; |
| 3497 | } |
| 3498 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3499 | retry: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3500 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3501 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3502 | priv->status &= ~STATUS_INT_ENABLED; |
| 3503 | |
| 3504 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3505 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3506 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3507 | ipw_stop_nic(priv); |
| 3508 | |
| 3509 | rc = ipw_reset_nic(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3510 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3511 | IPW_ERROR("Unable to reset NIC\n"); |
| 3512 | goto error; |
| 3513 | } |
| 3514 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3515 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
| 3516 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3517 | |
| 3518 | /* DMA the initial boot firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3519 | 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] | 3520 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3521 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3522 | goto error; |
| 3523 | } |
| 3524 | |
| 3525 | /* kick start the device */ |
| 3526 | ipw_start_nic(priv); |
| 3527 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3528 | /* wait for the device to finish its initial startup sequence */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3529 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3530 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3531 | if (rc < 0) { |
| 3532 | IPW_ERROR("device failed to boot initial fw image\n"); |
| 3533 | goto error; |
| 3534 | } |
| 3535 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); |
| 3536 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3537 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3538 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3539 | |
| 3540 | /* DMA the ucode into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3541 | 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] | 3542 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3543 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3544 | goto error; |
| 3545 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3546 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3547 | /* stop nic */ |
| 3548 | ipw_stop_nic(priv); |
| 3549 | |
| 3550 | /* DMA bss firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3551 | 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] | 3552 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3553 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3554 | goto error; |
| 3555 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3556 | #ifdef CONFIG_PM |
| 3557 | fw_loaded = 1; |
| 3558 | #endif |
| 3559 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3560 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 3561 | |
| 3562 | rc = ipw_queue_reset(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3563 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3564 | IPW_ERROR("Unable to initialize queues\n"); |
| 3565 | goto error; |
| 3566 | } |
| 3567 | |
| 3568 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3569 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3570 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3571 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3572 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3573 | /* kick start the device */ |
| 3574 | ipw_start_nic(priv); |
| 3575 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3576 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3577 | if (retries > 0) { |
| 3578 | IPW_WARNING("Parity error. Retrying init.\n"); |
| 3579 | retries--; |
| 3580 | goto retry; |
| 3581 | } |
| 3582 | |
| 3583 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); |
| 3584 | rc = -EIO; |
| 3585 | goto error; |
| 3586 | } |
| 3587 | |
| 3588 | /* wait for the device */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3589 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3590 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3591 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3592 | IPW_ERROR("device failed to start within 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3593 | goto error; |
| 3594 | } |
| 3595 | IPW_DEBUG_INFO("device response after %dms\n", rc); |
| 3596 | |
| 3597 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3598 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3599 | |
| 3600 | /* read eeprom data and initialize the eeprom region of sram */ |
| 3601 | priv->eeprom_delay = 1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3602 | ipw_eeprom_init_sram(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3603 | |
| 3604 | /* enable interrupts */ |
| 3605 | ipw_enable_interrupts(priv); |
| 3606 | |
| 3607 | /* Ensure our queue has valid packets */ |
| 3608 | ipw_rx_queue_replenish(priv); |
| 3609 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3610 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3611 | |
| 3612 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3613 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3614 | |
| 3615 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3616 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3617 | #endif |
| 3618 | return 0; |
| 3619 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3620 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3621 | if (priv->rxq) { |
| 3622 | ipw_rx_queue_free(priv, priv->rxq); |
| 3623 | priv->rxq = NULL; |
| 3624 | } |
| 3625 | ipw_tx_queue_free(priv); |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3626 | if (raw) |
| 3627 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3628 | #ifdef CONFIG_PM |
| 3629 | fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3630 | raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3631 | #endif |
| 3632 | |
| 3633 | return rc; |
| 3634 | } |
| 3635 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3636 | /** |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3637 | * DMA services |
| 3638 | * |
| 3639 | * Theory of operation |
| 3640 | * |
| 3641 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 3642 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 3643 | * |
| 3644 | * 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] | 3645 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 3646 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3647 | * Tx queue resumed. |
| 3648 | * |
| 3649 | * The IPW operates with six queues, one receive queue in the device's |
| 3650 | * sram, one transmit queue for sending commands to the device firmware, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3651 | * and four transmit queues for data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3652 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3653 | * The four transmit queues allow for performing quality of service (qos) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3654 | * transmissions as per the 802.11 protocol. Currently Linux does not |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3655 | * provide a mechanism to the user for utilizing prioritized queues, so |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3656 | * we only utilize the first data transmit queue (queue1). |
| 3657 | */ |
| 3658 | |
| 3659 | /** |
| 3660 | * Driver allocates buffers of this size for Rx |
| 3661 | */ |
| 3662 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 3663 | /** |
| 3664 | * ipw_rx_queue_space - Return number of free slots available in queue. |
| 3665 | */ |
| 3666 | static int ipw_rx_queue_space(const struct ipw_rx_queue *q) |
| 3667 | { |
| 3668 | int s = q->read - q->write; |
| 3669 | if (s <= 0) |
| 3670 | s += RX_QUEUE_SIZE; |
| 3671 | /* keep some buffer to not confuse full and empty queue */ |
| 3672 | s -= 2; |
| 3673 | if (s < 0) |
| 3674 | s = 0; |
| 3675 | return s; |
| 3676 | } |
| 3677 | |
| 3678 | static inline int ipw_tx_queue_space(const struct clx2_queue *q) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3679 | { |
| 3680 | int s = q->last_used - q->first_empty; |
| 3681 | if (s <= 0) |
| 3682 | s += q->n_bd; |
| 3683 | s -= 2; /* keep some reserve to not confuse empty and full situations */ |
| 3684 | if (s < 0) |
| 3685 | s = 0; |
| 3686 | return s; |
| 3687 | } |
| 3688 | |
| 3689 | static inline int ipw_queue_inc_wrap(int index, int n_bd) |
| 3690 | { |
| 3691 | return (++index == n_bd) ? 0 : index; |
| 3692 | } |
| 3693 | |
| 3694 | /** |
| 3695 | * Initialize common DMA queue structure |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3696 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3697 | * @param q queue to init |
| 3698 | * @param count Number of BD's to allocate. Should be power of 2 |
| 3699 | * @param read_register Address for 'read' register |
| 3700 | * (not offset within BAR, full address) |
| 3701 | * @param write_register Address for 'write' register |
| 3702 | * (not offset within BAR, full address) |
| 3703 | * @param base_register Address for 'base' register |
| 3704 | * (not offset within BAR, full address) |
| 3705 | * @param size Address for 'size' register |
| 3706 | * (not offset within BAR, full address) |
| 3707 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3708 | 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] | 3709 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3710 | { |
| 3711 | q->n_bd = count; |
| 3712 | |
| 3713 | q->low_mark = q->n_bd / 4; |
| 3714 | if (q->low_mark < 4) |
| 3715 | q->low_mark = 4; |
| 3716 | |
| 3717 | q->high_mark = q->n_bd / 8; |
| 3718 | if (q->high_mark < 2) |
| 3719 | q->high_mark = 2; |
| 3720 | |
| 3721 | q->first_empty = q->last_used = 0; |
| 3722 | q->reg_r = read; |
| 3723 | q->reg_w = write; |
| 3724 | |
| 3725 | ipw_write32(priv, base, q->dma_addr); |
| 3726 | ipw_write32(priv, size, count); |
| 3727 | ipw_write32(priv, read, 0); |
| 3728 | ipw_write32(priv, write, 0); |
| 3729 | |
| 3730 | _ipw_read32(priv, 0x90); |
| 3731 | } |
| 3732 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3733 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3734 | struct clx2_tx_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3735 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3736 | { |
| 3737 | struct pci_dev *dev = priv->pci_dev; |
| 3738 | |
| 3739 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); |
| 3740 | if (!q->txb) { |
| 3741 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); |
| 3742 | return -ENOMEM; |
| 3743 | } |
| 3744 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3745 | q->bd = |
| 3746 | 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] | 3747 | if (!q->bd) { |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3748 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3749 | sizeof(q->bd[0]) * count); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3750 | kfree(q->txb); |
| 3751 | q->txb = NULL; |
| 3752 | return -ENOMEM; |
| 3753 | } |
| 3754 | |
| 3755 | ipw_queue_init(priv, &q->q, count, read, write, base, size); |
| 3756 | return 0; |
| 3757 | } |
| 3758 | |
| 3759 | /** |
| 3760 | * Free one TFD, those at index [txq->q.last_used]. |
| 3761 | * Do NOT advance any indexes |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3762 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3763 | * @param dev |
| 3764 | * @param txq |
| 3765 | */ |
| 3766 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, |
| 3767 | struct clx2_tx_queue *txq) |
| 3768 | { |
| 3769 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; |
| 3770 | struct pci_dev *dev = priv->pci_dev; |
| 3771 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3772 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3773 | /* classify bd */ |
| 3774 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) |
| 3775 | /* nothing to cleanup after for host commands */ |
| 3776 | return; |
| 3777 | |
| 3778 | /* sanity check */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3779 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
| 3780 | IPW_ERROR("Too many chunks: %i\n", |
| 3781 | le32_to_cpu(bd->u.data.num_chunks)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3782 | /** @todo issue fatal error, it is quite serious situation */ |
| 3783 | return; |
| 3784 | } |
| 3785 | |
| 3786 | /* unmap chunks if any */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3787 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
| 3788 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), |
| 3789 | le16_to_cpu(bd->u.data.chunk_len[i]), |
| 3790 | PCI_DMA_TODEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3791 | if (txq->txb[txq->q.last_used]) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 3792 | libipw_txb_free(txq->txb[txq->q.last_used]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3793 | txq->txb[txq->q.last_used] = NULL; |
| 3794 | } |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | /** |
| 3799 | * Deallocate DMA queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3800 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3801 | * Empty queue by removing and destroying all BD's. |
| 3802 | * Free all buffers. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3803 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3804 | * @param dev |
| 3805 | * @param q |
| 3806 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3807 | 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] | 3808 | { |
| 3809 | struct clx2_queue *q = &txq->q; |
| 3810 | struct pci_dev *dev = priv->pci_dev; |
| 3811 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3812 | if (q->n_bd == 0) |
| 3813 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3814 | |
| 3815 | /* first, empty all BD's */ |
| 3816 | for (; q->first_empty != q->last_used; |
| 3817 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3818 | ipw_queue_tx_free_tfd(priv, txq); |
| 3819 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3820 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3821 | /* free buffers belonging to queue itself */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3822 | 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] | 3823 | q->dma_addr); |
| 3824 | kfree(txq->txb); |
| 3825 | |
| 3826 | /* 0 fill whole structure */ |
| 3827 | memset(txq, 0, sizeof(*txq)); |
| 3828 | } |
| 3829 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3830 | /** |
| 3831 | * Destroy all DMA queues and structures |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3832 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3833 | * @param priv |
| 3834 | */ |
| 3835 | static void ipw_tx_queue_free(struct ipw_priv *priv) |
| 3836 | { |
| 3837 | /* Tx CMD queue */ |
| 3838 | ipw_queue_tx_free(priv, &priv->txq_cmd); |
| 3839 | |
| 3840 | /* Tx queues */ |
| 3841 | ipw_queue_tx_free(priv, &priv->txq[0]); |
| 3842 | ipw_queue_tx_free(priv, &priv->txq[1]); |
| 3843 | ipw_queue_tx_free(priv, &priv->txq[2]); |
| 3844 | ipw_queue_tx_free(priv, &priv->txq[3]); |
| 3845 | } |
| 3846 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3847 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3848 | { |
| 3849 | /* First 3 bytes are manufacturer */ |
| 3850 | bssid[0] = priv->mac_addr[0]; |
| 3851 | bssid[1] = priv->mac_addr[1]; |
| 3852 | bssid[2] = priv->mac_addr[2]; |
| 3853 | |
| 3854 | /* Last bytes are random */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3855 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3856 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3857 | bssid[0] &= 0xfe; /* clear multicast bit */ |
| 3858 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3859 | } |
| 3860 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3861 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3862 | { |
| 3863 | struct ipw_station_entry entry; |
| 3864 | int i; |
| 3865 | |
| 3866 | for (i = 0; i < priv->num_stations; i++) { |
| 3867 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { |
| 3868 | /* Another node is active in network */ |
| 3869 | priv->missed_adhoc_beacons = 0; |
| 3870 | if (!(priv->config & CFG_STATIC_CHANNEL)) |
| 3871 | /* when other nodes drop out, we drop out */ |
| 3872 | priv->config &= ~CFG_ADHOC_PERSIST; |
| 3873 | |
| 3874 | return i; |
| 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | if (i == MAX_STATIONS) |
| 3879 | return IPW_INVALID_STATION; |
| 3880 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3881 | IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3882 | |
| 3883 | entry.reserved = 0; |
| 3884 | entry.support_mode = 0; |
| 3885 | memcpy(entry.mac_addr, bssid, ETH_ALEN); |
| 3886 | memcpy(priv->stations[i], bssid, ETH_ALEN); |
| 3887 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3888 | &entry, sizeof(entry)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3889 | priv->num_stations++; |
| 3890 | |
| 3891 | return i; |
| 3892 | } |
| 3893 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3894 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3895 | { |
| 3896 | int i; |
| 3897 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3898 | for (i = 0; i < priv->num_stations; i++) |
| 3899 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3900 | return i; |
| 3901 | |
| 3902 | return IPW_INVALID_STATION; |
| 3903 | } |
| 3904 | |
| 3905 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) |
| 3906 | { |
| 3907 | int err; |
| 3908 | |
Hong Liu | 7b99659 | 2005-08-25 17:36:13 +0800 | [diff] [blame] | 3909 | if (priv->status & STATUS_ASSOCIATING) { |
| 3910 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); |
| 3911 | queue_work(priv->workqueue, &priv->disassociate); |
| 3912 | return; |
| 3913 | } |
| 3914 | |
| 3915 | if (!(priv->status & STATUS_ASSOCIATED)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3916 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
| 3917 | return; |
| 3918 | } |
| 3919 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3920 | IPW_DEBUG_ASSOC("Disassocation attempt from %pM " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3921 | "on channel %d.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3922 | priv->assoc_request.bssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3923 | priv->assoc_request.channel); |
| 3924 | |
| 3925 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); |
| 3926 | priv->status |= STATUS_DISASSOCIATING; |
| 3927 | |
| 3928 | if (quiet) |
| 3929 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; |
| 3930 | else |
| 3931 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 3932 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3933 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 3934 | if (err) { |
| 3935 | IPW_DEBUG_HC("Attempt to send [dis]associate command " |
| 3936 | "failed.\n"); |
| 3937 | return; |
| 3938 | } |
| 3939 | |
| 3940 | } |
| 3941 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3942 | static int ipw_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3943 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3944 | struct ipw_priv *priv = data; |
| 3945 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) |
| 3946 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3947 | ipw_send_disassociate(data, 0); |
Zhu Yi | b8ddafd | 2008-11-27 13:42:20 +0800 | [diff] [blame] | 3948 | netif_carrier_off(priv->net_dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3949 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3950 | } |
| 3951 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3952 | static void ipw_bg_disassociate(struct work_struct *work) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3953 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3954 | struct ipw_priv *priv = |
| 3955 | container_of(work, struct ipw_priv, disassociate); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3956 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3957 | ipw_disassociate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3958 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3959 | } |
| 3960 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3961 | static void ipw_system_config(struct work_struct *work) |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 3962 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3963 | struct ipw_priv *priv = |
| 3964 | container_of(work, struct ipw_priv, system_config); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 3965 | |
| 3966 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 3967 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 3968 | priv->sys_config.accept_all_data_frames = 1; |
| 3969 | priv->sys_config.accept_non_directed_frames = 1; |
| 3970 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 3971 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 3972 | } |
| 3973 | #endif |
| 3974 | |
| 3975 | ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | struct ipw_status_code { |
| 3979 | u16 status; |
| 3980 | const char *reason; |
| 3981 | }; |
| 3982 | |
| 3983 | static const struct ipw_status_code ipw_status_codes[] = { |
| 3984 | {0x00, "Successful"}, |
| 3985 | {0x01, "Unspecified failure"}, |
| 3986 | {0x0A, "Cannot support all requested capabilities in the " |
| 3987 | "Capability information field"}, |
| 3988 | {0x0B, "Reassociation denied due to inability to confirm that " |
| 3989 | "association exists"}, |
| 3990 | {0x0C, "Association denied due to reason outside the scope of this " |
| 3991 | "standard"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3992 | {0x0D, |
| 3993 | "Responding station does not support the specified authentication " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3994 | "algorithm"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3995 | {0x0E, |
| 3996 | "Received an Authentication frame with authentication sequence " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3997 | "transaction sequence number out of expected sequence"}, |
| 3998 | {0x0F, "Authentication rejected because of challenge failure"}, |
| 3999 | {0x10, "Authentication rejected due to timeout waiting for next " |
| 4000 | "frame in sequence"}, |
| 4001 | {0x11, "Association denied because AP is unable to handle additional " |
| 4002 | "associated stations"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4003 | {0x12, |
| 4004 | "Association denied due to requesting station not supporting all " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4005 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4006 | {0x13, |
| 4007 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4008 | "short preamble operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4009 | {0x14, |
| 4010 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4011 | "PBCC encoding"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4012 | {0x15, |
| 4013 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4014 | "channel agility"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4015 | {0x19, |
| 4016 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4017 | "short slot operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4018 | {0x1A, |
| 4019 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4020 | "DSSS-OFDM operation"}, |
| 4021 | {0x28, "Invalid Information Element"}, |
| 4022 | {0x29, "Group Cipher is not valid"}, |
| 4023 | {0x2A, "Pairwise Cipher is not valid"}, |
| 4024 | {0x2B, "AKMP is not valid"}, |
| 4025 | {0x2C, "Unsupported RSN IE version"}, |
| 4026 | {0x2D, "Invalid RSN IE Capabilities"}, |
| 4027 | {0x2E, "Cipher suite is rejected per security policy"}, |
| 4028 | }; |
| 4029 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4030 | static const char *ipw_get_status_code(u16 status) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4031 | { |
| 4032 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4033 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4034 | if (ipw_status_codes[i].status == (status & 0xff)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4035 | return ipw_status_codes[i].reason; |
| 4036 | return "Unknown status value."; |
| 4037 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4038 | |
| 4039 | static void inline average_init(struct average *avg) |
| 4040 | { |
| 4041 | memset(avg, 0, sizeof(*avg)); |
| 4042 | } |
| 4043 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4044 | #define DEPTH_RSSI 8 |
| 4045 | #define DEPTH_NOISE 16 |
| 4046 | static s16 exponential_average(s16 prev_avg, s16 val, u8 depth) |
| 4047 | { |
| 4048 | return ((depth-1)*prev_avg + val)/depth; |
| 4049 | } |
| 4050 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4051 | static void average_add(struct average *avg, s16 val) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4052 | { |
| 4053 | avg->sum -= avg->entries[avg->pos]; |
| 4054 | avg->sum += val; |
| 4055 | avg->entries[avg->pos++] = val; |
| 4056 | if (unlikely(avg->pos == AVG_ENTRIES)) { |
| 4057 | avg->init = 1; |
| 4058 | avg->pos = 0; |
| 4059 | } |
| 4060 | } |
| 4061 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4062 | static s16 average_value(struct average *avg) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4063 | { |
| 4064 | if (!unlikely(avg->init)) { |
| 4065 | if (avg->pos) |
| 4066 | return avg->sum / avg->pos; |
| 4067 | return 0; |
| 4068 | } |
| 4069 | |
| 4070 | return avg->sum / AVG_ENTRIES; |
| 4071 | } |
| 4072 | |
| 4073 | static void ipw_reset_stats(struct ipw_priv *priv) |
| 4074 | { |
| 4075 | u32 len = sizeof(u32); |
| 4076 | |
| 4077 | priv->quality = 0; |
| 4078 | |
| 4079 | average_init(&priv->average_missed_beacons); |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4080 | priv->exp_avg_rssi = -60; |
| 4081 | priv->exp_avg_noise = -85 + 0x100; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4082 | |
| 4083 | priv->last_rate = 0; |
| 4084 | priv->last_missed_beacons = 0; |
| 4085 | priv->last_rx_packets = 0; |
| 4086 | priv->last_tx_packets = 0; |
| 4087 | priv->last_tx_failures = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4088 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4089 | /* Firmware managed, reset only when NIC is restarted, so we have to |
| 4090 | * normalize on the current value */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4091 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4092 | &priv->last_rx_err, &len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4093 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4094 | &priv->last_tx_failures, &len); |
| 4095 | |
| 4096 | /* Driver managed, reset with each association */ |
| 4097 | priv->missed_adhoc_beacons = 0; |
| 4098 | priv->missed_beacons = 0; |
| 4099 | priv->tx_packets = 0; |
| 4100 | priv->rx_packets = 0; |
| 4101 | |
| 4102 | } |
| 4103 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4104 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4105 | { |
| 4106 | u32 i = 0x80000000; |
| 4107 | u32 mask = priv->rates_mask; |
| 4108 | /* If currently associated in B mode, restrict the maximum |
| 4109 | * rate match to B rates */ |
| 4110 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4111 | mask &= LIBIPW_CCK_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4112 | |
| 4113 | /* TODO: Verify that the rate is supported by the current rates |
| 4114 | * list. */ |
| 4115 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4116 | while (i && !(mask & i)) |
| 4117 | i >>= 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4118 | switch (i) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4119 | case LIBIPW_CCK_RATE_1MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4120 | return 1000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4121 | case LIBIPW_CCK_RATE_2MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4122 | return 2000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4123 | case LIBIPW_CCK_RATE_5MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4124 | return 5500000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4125 | case LIBIPW_OFDM_RATE_6MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4126 | return 6000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4127 | case LIBIPW_OFDM_RATE_9MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4128 | return 9000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4129 | case LIBIPW_CCK_RATE_11MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4130 | return 11000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4131 | case LIBIPW_OFDM_RATE_12MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4132 | return 12000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4133 | case LIBIPW_OFDM_RATE_18MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4134 | return 18000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4135 | case LIBIPW_OFDM_RATE_24MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4136 | return 24000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4137 | case LIBIPW_OFDM_RATE_36MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4138 | return 36000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4139 | case LIBIPW_OFDM_RATE_48MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4140 | return 48000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4141 | case LIBIPW_OFDM_RATE_54MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4142 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4143 | } |
| 4144 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4145 | if (priv->ieee->mode == IEEE_B) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4146 | return 11000000; |
| 4147 | else |
| 4148 | return 54000000; |
| 4149 | } |
| 4150 | |
| 4151 | static u32 ipw_get_current_rate(struct ipw_priv *priv) |
| 4152 | { |
| 4153 | u32 rate, len = sizeof(rate); |
| 4154 | int err; |
| 4155 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4156 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4157 | return 0; |
| 4158 | |
| 4159 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4160 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4161 | &len); |
| 4162 | if (err) { |
| 4163 | IPW_DEBUG_INFO("failed querying ordinals.\n"); |
| 4164 | return 0; |
| 4165 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4166 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4167 | return ipw_get_max_rate(priv); |
| 4168 | |
| 4169 | switch (rate) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4170 | case IPW_TX_RATE_1MB: |
| 4171 | return 1000000; |
| 4172 | case IPW_TX_RATE_2MB: |
| 4173 | return 2000000; |
| 4174 | case IPW_TX_RATE_5MB: |
| 4175 | return 5500000; |
| 4176 | case IPW_TX_RATE_6MB: |
| 4177 | return 6000000; |
| 4178 | case IPW_TX_RATE_9MB: |
| 4179 | return 9000000; |
| 4180 | case IPW_TX_RATE_11MB: |
| 4181 | return 11000000; |
| 4182 | case IPW_TX_RATE_12MB: |
| 4183 | return 12000000; |
| 4184 | case IPW_TX_RATE_18MB: |
| 4185 | return 18000000; |
| 4186 | case IPW_TX_RATE_24MB: |
| 4187 | return 24000000; |
| 4188 | case IPW_TX_RATE_36MB: |
| 4189 | return 36000000; |
| 4190 | case IPW_TX_RATE_48MB: |
| 4191 | return 48000000; |
| 4192 | case IPW_TX_RATE_54MB: |
| 4193 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | return 0; |
| 4197 | } |
| 4198 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4199 | #define IPW_STATS_INTERVAL (2 * HZ) |
| 4200 | static void ipw_gather_stats(struct ipw_priv *priv) |
| 4201 | { |
| 4202 | u32 rx_err, rx_err_delta, rx_packets_delta; |
| 4203 | u32 tx_failures, tx_failures_delta, tx_packets_delta; |
| 4204 | u32 missed_beacons_percent, missed_beacons_delta; |
| 4205 | u32 quality = 0; |
| 4206 | u32 len = sizeof(u32); |
| 4207 | s16 rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4208 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4209 | rate_quality; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4210 | u32 max_rate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4211 | |
| 4212 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 4213 | priv->quality = 0; |
| 4214 | return; |
| 4215 | } |
| 4216 | |
| 4217 | /* Update the statistics */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4218 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4219 | &priv->missed_beacons, &len); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4220 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4221 | priv->last_missed_beacons = priv->missed_beacons; |
| 4222 | if (priv->assoc_request.beacon_interval) { |
| 4223 | missed_beacons_percent = missed_beacons_delta * |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4224 | (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4225 | (IPW_STATS_INTERVAL * 10); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4226 | } else { |
| 4227 | missed_beacons_percent = 0; |
| 4228 | } |
| 4229 | average_add(&priv->average_missed_beacons, missed_beacons_percent); |
| 4230 | |
| 4231 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); |
| 4232 | rx_err_delta = rx_err - priv->last_rx_err; |
| 4233 | priv->last_rx_err = rx_err; |
| 4234 | |
| 4235 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); |
| 4236 | tx_failures_delta = tx_failures - priv->last_tx_failures; |
| 4237 | priv->last_tx_failures = tx_failures; |
| 4238 | |
| 4239 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; |
| 4240 | priv->last_rx_packets = priv->rx_packets; |
| 4241 | |
| 4242 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; |
| 4243 | priv->last_tx_packets = priv->tx_packets; |
| 4244 | |
| 4245 | /* Calculate quality based on the following: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4246 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4247 | * Missed beacon: 100% = 0, 0% = 70% missed |
| 4248 | * Rate: 60% = 1Mbs, 100% = Max |
| 4249 | * Rx and Tx errors represent a straight % of total Rx/Tx |
| 4250 | * RSSI: 100% = > -50, 0% = < -80 |
| 4251 | * Rx errors: 100% = 0, 0% = 50% missed |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4252 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4253 | * The lowest computed quality is used. |
| 4254 | * |
| 4255 | */ |
| 4256 | #define BEACON_THRESHOLD 5 |
| 4257 | beacon_quality = 100 - missed_beacons_percent; |
| 4258 | if (beacon_quality < BEACON_THRESHOLD) |
| 4259 | beacon_quality = 0; |
| 4260 | else |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4261 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4262 | (100 - BEACON_THRESHOLD); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4263 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4264 | beacon_quality, missed_beacons_percent); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4265 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4266 | priv->last_rate = ipw_get_current_rate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4267 | max_rate = ipw_get_max_rate(priv); |
| 4268 | rate_quality = priv->last_rate * 40 / max_rate + 60; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4269 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
| 4270 | rate_quality, priv->last_rate / 1000000); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4271 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4272 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4273 | rx_quality = 100 - (rx_err_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4274 | (rx_packets_delta + rx_err_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4275 | else |
| 4276 | rx_quality = 100; |
| 4277 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", |
| 4278 | rx_quality, rx_err_delta, rx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4279 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4280 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4281 | tx_quality = 100 - (tx_failures_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4282 | (tx_packets_delta + tx_failures_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4283 | else |
| 4284 | tx_quality = 100; |
| 4285 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", |
| 4286 | tx_quality, tx_failures_delta, tx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4287 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4288 | rssi = priv->exp_avg_rssi; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4289 | signal_quality = |
| 4290 | (100 * |
| 4291 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4292 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - |
| 4293 | (priv->ieee->perfect_rssi - rssi) * |
| 4294 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + |
| 4295 | 62 * (priv->ieee->perfect_rssi - rssi))) / |
| 4296 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4297 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); |
| 4298 | if (signal_quality > 100) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4299 | signal_quality = 100; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4300 | else if (signal_quality < 1) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4301 | signal_quality = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4302 | |
Zhu Yi | 61fb9ed | 2006-04-13 17:19:55 +0800 | [diff] [blame] | 4303 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4304 | signal_quality, rssi); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4305 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 4306 | quality = min(rx_quality, signal_quality); |
| 4307 | quality = min(tx_quality, quality); |
| 4308 | quality = min(rate_quality, quality); |
| 4309 | quality = min(beacon_quality, quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4310 | if (quality == beacon_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4311 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
| 4312 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4313 | if (quality == rate_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4314 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
| 4315 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4316 | if (quality == tx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4317 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
| 4318 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4319 | if (quality == rx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4320 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
| 4321 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4322 | if (quality == signal_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4323 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
| 4324 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4325 | |
| 4326 | priv->quality = quality; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4327 | |
| 4328 | queue_delayed_work(priv->workqueue, &priv->gather_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4329 | IPW_STATS_INTERVAL); |
| 4330 | } |
| 4331 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4332 | static void ipw_bg_gather_stats(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4333 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4334 | struct ipw_priv *priv = |
| 4335 | container_of(work, struct ipw_priv, gather_stats.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4336 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4337 | ipw_gather_stats(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4338 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4339 | } |
| 4340 | |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4341 | /* Missed beacon behavior: |
| 4342 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. |
| 4343 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. |
| 4344 | * Above disassociate threshold, give up and stop scanning. |
| 4345 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4346 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4347 | int missed_count) |
| 4348 | { |
| 4349 | priv->notif_missed_beacons = missed_count; |
| 4350 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4351 | if (missed_count > priv->disassociate_threshold && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4352 | priv->status & STATUS_ASSOCIATED) { |
| 4353 | /* If associated and we've hit the missed |
| 4354 | * beacon threshold, disassociate, turn |
| 4355 | * off roaming, and abort any active scans */ |
| 4356 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4357 | IPW_DL_STATE | IPW_DL_ASSOC, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4358 | "Missed beacon: %d - disassociate\n", missed_count); |
| 4359 | priv->status &= ~STATUS_ROAMING; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4360 | if (priv->status & STATUS_SCANNING) { |
| 4361 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 4362 | IPW_DL_STATE, |
| 4363 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4364 | queue_work(priv->workqueue, &priv->abort_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4365 | } |
| 4366 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4367 | queue_work(priv->workqueue, &priv->disassociate); |
| 4368 | return; |
| 4369 | } |
| 4370 | |
| 4371 | if (priv->status & STATUS_ROAMING) { |
| 4372 | /* If we are currently roaming, then just |
| 4373 | * print a debug statement... */ |
| 4374 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4375 | "Missed beacon: %d - roam in progress\n", |
| 4376 | missed_count); |
| 4377 | return; |
| 4378 | } |
| 4379 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 4380 | if (roaming && |
| 4381 | (missed_count > priv->roaming_threshold && |
| 4382 | missed_count <= priv->disassociate_threshold)) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4383 | /* If we are not already roaming, set the ROAM |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4384 | * bit in the status and kick off a scan. |
| 4385 | * This can happen several times before we reach |
| 4386 | * disassociate_threshold. */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4387 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4388 | "Missed beacon: %d - initiate " |
| 4389 | "roaming\n", missed_count); |
| 4390 | if (!(priv->status & STATUS_ROAMING)) { |
| 4391 | priv->status |= STATUS_ROAMING; |
| 4392 | if (!(priv->status & STATUS_SCANNING)) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4393 | queue_delayed_work(priv->workqueue, |
| 4394 | &priv->request_scan, 0); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4395 | } |
| 4396 | return; |
| 4397 | } |
| 4398 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 4399 | if (priv->status & STATUS_SCANNING && |
| 4400 | missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4401 | /* Stop scan to keep fw from getting |
| 4402 | * stuck (only if we aren't roaming -- |
| 4403 | * otherwise we'll never scan more than 2 or 3 |
| 4404 | * channels..) */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4405 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
| 4406 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4407 | queue_work(priv->workqueue, &priv->abort_scan); |
| 4408 | } |
| 4409 | |
| 4410 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4411 | } |
| 4412 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4413 | static void ipw_scan_event(struct work_struct *work) |
| 4414 | { |
| 4415 | union iwreq_data wrqu; |
| 4416 | |
| 4417 | struct ipw_priv *priv = |
| 4418 | container_of(work, struct ipw_priv, scan_event.work); |
| 4419 | |
| 4420 | wrqu.data.length = 0; |
| 4421 | wrqu.data.flags = 0; |
| 4422 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); |
| 4423 | } |
| 4424 | |
| 4425 | static void handle_scan_event(struct ipw_priv *priv) |
| 4426 | { |
| 4427 | /* Only userspace-requested scan completion events go out immediately */ |
| 4428 | if (!priv->user_requested_scan) { |
| 4429 | if (!delayed_work_pending(&priv->scan_event)) |
| 4430 | queue_delayed_work(priv->workqueue, &priv->scan_event, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 4431 | round_jiffies_relative(msecs_to_jiffies(4000))); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4432 | } else { |
| 4433 | union iwreq_data wrqu; |
| 4434 | |
| 4435 | priv->user_requested_scan = 0; |
| 4436 | cancel_delayed_work(&priv->scan_event); |
| 4437 | |
| 4438 | wrqu.data.length = 0; |
| 4439 | wrqu.data.flags = 0; |
| 4440 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); |
| 4441 | } |
| 4442 | } |
| 4443 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4444 | /** |
| 4445 | * Handle host notification packet. |
| 4446 | * Called from interrupt routine |
| 4447 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4448 | static void ipw_rx_notification(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4449 | struct ipw_rx_notification *notif) |
| 4450 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4451 | DECLARE_SSID_BUF(ssid); |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4452 | u16 size = le16_to_cpu(notif->size); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4453 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4454 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4455 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4456 | switch (notif->subtype) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4457 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
| 4458 | struct notif_association *assoc = ¬if->u.assoc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4459 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4460 | switch (assoc->state) { |
| 4461 | case CMAS_ASSOCIATED:{ |
| 4462 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4463 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4464 | "associated: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4465 | print_ssid(ssid, priv->essid, |
| 4466 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4467 | priv->bssid); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4468 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4469 | switch (priv->ieee->iw_mode) { |
| 4470 | case IW_MODE_INFRA: |
| 4471 | memcpy(priv->ieee->bssid, |
| 4472 | priv->bssid, ETH_ALEN); |
| 4473 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4474 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4475 | case IW_MODE_ADHOC: |
| 4476 | memcpy(priv->ieee->bssid, |
| 4477 | priv->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4478 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4479 | /* clear out the station table */ |
| 4480 | priv->num_stations = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4481 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4482 | IPW_DEBUG_ASSOC |
| 4483 | ("queueing adhoc check\n"); |
| 4484 | queue_delayed_work(priv-> |
| 4485 | workqueue, |
| 4486 | &priv-> |
| 4487 | adhoc_check, |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4488 | le16_to_cpu(priv-> |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4489 | assoc_request. |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4490 | beacon_interval)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4491 | break; |
| 4492 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4493 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4494 | priv->status &= ~STATUS_ASSOCIATING; |
| 4495 | priv->status |= STATUS_ASSOCIATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 4496 | queue_work(priv->workqueue, |
| 4497 | &priv->system_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4498 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 4499 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4500 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 4501 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control)) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4502 | if ((priv->status & STATUS_AUTH) && |
| 4503 | (IPW_GET_PACKET_STYPE(¬if->u.raw) |
| 4504 | == IEEE80211_STYPE_ASSOC_RESP)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4505 | if ((sizeof |
| 4506 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4507 | libipw_assoc_response) |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4508 | <= size) |
| 4509 | && (size <= 2314)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4510 | struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4511 | libipw_rx_stats |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4512 | stats = { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4513 | .len = size - 1, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4514 | }; |
| 4515 | |
| 4516 | IPW_DEBUG_QOS |
| 4517 | ("QoS Associate " |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4518 | "size %d\n", size); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4519 | libipw_rx_mgt(priv-> |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4520 | ieee, |
| 4521 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4522 | libipw_hdr_4addr |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4523 | *) |
| 4524 | ¬if->u.raw, &stats); |
| 4525 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4526 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4527 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4528 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4529 | schedule_work(&priv->link_up); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4530 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4531 | break; |
| 4532 | } |
| 4533 | |
| 4534 | case CMAS_AUTHENTICATED:{ |
| 4535 | if (priv-> |
| 4536 | status & (STATUS_ASSOCIATED | |
| 4537 | STATUS_AUTH)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4538 | struct notif_authenticate *auth |
| 4539 | = ¬if->u.auth; |
| 4540 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4541 | IPW_DL_STATE | |
| 4542 | IPW_DL_ASSOC, |
| 4543 | "deauthenticated: '%s' " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4544 | "%pM" |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4545 | ": (0x%04X) - %s \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4546 | print_ssid(ssid, |
| 4547 | priv-> |
| 4548 | essid, |
| 4549 | priv-> |
| 4550 | essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4551 | priv->bssid, |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4552 | le16_to_cpu(auth->status), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4553 | ipw_get_status_code |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4554 | (le16_to_cpu |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4555 | (auth->status))); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4556 | |
| 4557 | priv->status &= |
| 4558 | ~(STATUS_ASSOCIATING | |
| 4559 | STATUS_AUTH | |
| 4560 | STATUS_ASSOCIATED); |
| 4561 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4562 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4563 | break; |
| 4564 | } |
| 4565 | |
| 4566 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4567 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4568 | "authenticated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4569 | print_ssid(ssid, priv->essid, |
| 4570 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4571 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4572 | break; |
| 4573 | } |
| 4574 | |
| 4575 | case CMAS_INIT:{ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4576 | if (priv->status & STATUS_AUTH) { |
| 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 | *resp; |
| 4580 | resp = |
| 4581 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4582 | libipw_assoc_response |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4583 | *)¬if->u.raw; |
| 4584 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4585 | IPW_DL_STATE | |
| 4586 | IPW_DL_ASSOC, |
| 4587 | "association failed (0x%04X): %s\n", |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4588 | le16_to_cpu(resp->status), |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4589 | ipw_get_status_code |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4590 | (le16_to_cpu |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4591 | (resp->status))); |
| 4592 | } |
| 4593 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4594 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4595 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4596 | "disassociated: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4597 | print_ssid(ssid, priv->essid, |
| 4598 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4599 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4600 | |
| 4601 | priv->status &= |
| 4602 | ~(STATUS_DISASSOCIATING | |
| 4603 | STATUS_ASSOCIATING | |
| 4604 | STATUS_ASSOCIATED | STATUS_AUTH); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4605 | if (priv->assoc_network |
| 4606 | && (priv->assoc_network-> |
| 4607 | capability & |
| 4608 | WLAN_CAPABILITY_IBSS)) |
| 4609 | ipw_remove_current_network |
| 4610 | (priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4611 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4612 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4613 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4614 | break; |
| 4615 | } |
| 4616 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4617 | case CMAS_RX_ASSOC_RESP: |
| 4618 | break; |
| 4619 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4620 | default: |
| 4621 | IPW_ERROR("assoc: unknown (%d)\n", |
| 4622 | assoc->state); |
| 4623 | break; |
| 4624 | } |
| 4625 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4626 | break; |
| 4627 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4628 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4629 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
| 4630 | struct notif_authenticate *auth = ¬if->u.auth; |
| 4631 | switch (auth->state) { |
| 4632 | case CMAS_AUTHENTICATED: |
| 4633 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4634 | "authenticated: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4635 | print_ssid(ssid, priv->essid, |
| 4636 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4637 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4638 | priv->status |= STATUS_AUTH; |
| 4639 | break; |
| 4640 | |
| 4641 | case CMAS_INIT: |
| 4642 | if (priv->status & STATUS_AUTH) { |
| 4643 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4644 | IPW_DL_ASSOC, |
| 4645 | "authentication failed (0x%04X): %s\n", |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4646 | le16_to_cpu(auth->status), |
| 4647 | ipw_get_status_code(le16_to_cpu |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4648 | (auth-> |
| 4649 | status))); |
| 4650 | } |
| 4651 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4652 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4653 | "deauthenticated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4654 | print_ssid(ssid, priv->essid, |
| 4655 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4656 | priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4657 | |
| 4658 | priv->status &= ~(STATUS_ASSOCIATING | |
| 4659 | STATUS_AUTH | |
| 4660 | STATUS_ASSOCIATED); |
| 4661 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4662 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4663 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4664 | |
| 4665 | case CMAS_TX_AUTH_SEQ_1: |
| 4666 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4667 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); |
| 4668 | break; |
| 4669 | case CMAS_RX_AUTH_SEQ_2: |
| 4670 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4671 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); |
| 4672 | break; |
| 4673 | case CMAS_AUTH_SEQ_1_PASS: |
| 4674 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4675 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); |
| 4676 | break; |
| 4677 | case CMAS_AUTH_SEQ_1_FAIL: |
| 4678 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4679 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); |
| 4680 | break; |
| 4681 | case CMAS_TX_AUTH_SEQ_3: |
| 4682 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4683 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); |
| 4684 | break; |
| 4685 | case CMAS_RX_AUTH_SEQ_4: |
| 4686 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4687 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); |
| 4688 | break; |
| 4689 | case CMAS_AUTH_SEQ_2_PASS: |
| 4690 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4691 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); |
| 4692 | break; |
| 4693 | case CMAS_AUTH_SEQ_2_FAIL: |
| 4694 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4695 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); |
| 4696 | break; |
| 4697 | case CMAS_TX_ASSOC: |
| 4698 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4699 | IPW_DL_ASSOC, "TX_ASSOC\n"); |
| 4700 | break; |
| 4701 | case CMAS_RX_ASSOC_RESP: |
| 4702 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4703 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4704 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4705 | break; |
| 4706 | case CMAS_ASSOCIATED: |
| 4707 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4708 | IPW_DL_ASSOC, "ASSOCIATED\n"); |
| 4709 | break; |
| 4710 | default: |
| 4711 | IPW_DEBUG_NOTIF("auth: failure - %d\n", |
| 4712 | auth->state); |
| 4713 | break; |
| 4714 | } |
| 4715 | break; |
| 4716 | } |
| 4717 | |
| 4718 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
| 4719 | struct notif_channel_result *x = |
| 4720 | ¬if->u.channel_result; |
| 4721 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4722 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4723 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
| 4724 | x->channel_num); |
| 4725 | } else { |
| 4726 | IPW_DEBUG_SCAN("Scan result of wrong size %d " |
| 4727 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4728 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4729 | } |
| 4730 | break; |
| 4731 | } |
| 4732 | |
| 4733 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
| 4734 | struct notif_scan_complete *x = ¬if->u.scan_complete; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4735 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4736 | IPW_DEBUG_SCAN |
| 4737 | ("Scan completed: type %d, %d channels, " |
| 4738 | "%d status\n", x->scan_type, |
| 4739 | x->num_channels, x->status); |
| 4740 | } else { |
| 4741 | IPW_ERROR("Scan completed of wrong size %d " |
| 4742 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4743 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4744 | } |
| 4745 | |
| 4746 | priv->status &= |
| 4747 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 4748 | |
James Ketrenos | a0e04ab | 2005-08-25 00:49:43 -0500 | [diff] [blame] | 4749 | wake_up_interruptible(&priv->wait_state); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4750 | cancel_delayed_work(&priv->scan_check); |
| 4751 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4752 | if (priv->status & STATUS_EXIT_PENDING) |
| 4753 | break; |
| 4754 | |
| 4755 | priv->ieee->scans++; |
| 4756 | |
| 4757 | #ifdef CONFIG_IPW2200_MONITOR |
| 4758 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4759 | priv->status |= STATUS_SCAN_FORCED; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4760 | queue_delayed_work(priv->workqueue, |
| 4761 | &priv->request_scan, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4762 | break; |
| 4763 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4764 | priv->status &= ~STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4765 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 4766 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 4767 | /* Do queued direct scans first */ |
| 4768 | if (priv->status & STATUS_DIRECT_SCAN_PENDING) { |
| 4769 | queue_delayed_work(priv->workqueue, |
| 4770 | &priv->request_direct_scan, 0); |
| 4771 | } |
| 4772 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4773 | if (!(priv->status & (STATUS_ASSOCIATED | |
| 4774 | STATUS_ASSOCIATING | |
| 4775 | STATUS_ROAMING | |
| 4776 | STATUS_DISASSOCIATING))) |
| 4777 | queue_work(priv->workqueue, &priv->associate); |
| 4778 | else if (priv->status & STATUS_ROAMING) { |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4779 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4780 | /* If a scan completed and we are in roam mode, then |
| 4781 | * the scan that completed was the one requested as a |
| 4782 | * result of entering roam... so, schedule the |
| 4783 | * roam work */ |
| 4784 | queue_work(priv->workqueue, |
| 4785 | &priv->roam); |
| 4786 | else |
| 4787 | /* Don't schedule if we aborted the scan */ |
| 4788 | priv->status &= ~STATUS_ROAMING; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4789 | } else if (priv->status & STATUS_SCAN_PENDING) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4790 | queue_delayed_work(priv->workqueue, |
| 4791 | &priv->request_scan, 0); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4792 | else if (priv->config & CFG_BACKGROUND_SCAN |
| 4793 | && priv->status & STATUS_ASSOCIATED) |
| 4794 | queue_delayed_work(priv->workqueue, |
Stephen Hemminger | 1c9d5e4 | 2007-06-22 21:34:06 -0700 | [diff] [blame] | 4795 | &priv->request_scan, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 4796 | round_jiffies_relative(HZ)); |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 4797 | |
| 4798 | /* Send an empty event to user space. |
| 4799 | * We don't send the received data on the event because |
| 4800 | * it would require us to do complex transcoding, and |
| 4801 | * we want to minimise the work done in the irq handler |
| 4802 | * Use a request to extract the data. |
| 4803 | * Also, we generate this even for any scan, regardless |
| 4804 | * on how the scan was initiated. User space can just |
| 4805 | * sync on periodic scan to get fresh data... |
| 4806 | * Jean II */ |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4807 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4808 | handle_scan_event(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4809 | break; |
| 4810 | } |
| 4811 | |
| 4812 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
| 4813 | struct notif_frag_length *x = ¬if->u.frag_len; |
| 4814 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4815 | if (size == sizeof(*x)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4816 | IPW_ERROR("Frag length: %d\n", |
| 4817 | le16_to_cpu(x->frag_length)); |
| 4818 | else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4819 | IPW_ERROR("Frag length of wrong size %d " |
| 4820 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4821 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4822 | break; |
| 4823 | } |
| 4824 | |
| 4825 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
| 4826 | struct notif_link_deterioration *x = |
| 4827 | ¬if->u.link_deterioration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4828 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4829 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4830 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Cahill, Ben M | 1297715 | 2006-03-08 02:58:02 +0800 | [diff] [blame] | 4831 | "link deterioration: type %d, cnt %d\n", |
| 4832 | x->silence_notification_type, |
| 4833 | x->silence_count); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4834 | memcpy(&priv->last_link_deterioration, x, |
| 4835 | sizeof(*x)); |
| 4836 | } else { |
| 4837 | IPW_ERROR("Link Deterioration of wrong size %d " |
| 4838 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4839 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4840 | } |
| 4841 | break; |
| 4842 | } |
| 4843 | |
| 4844 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
| 4845 | IPW_ERROR("Dino config\n"); |
| 4846 | if (priv->hcmd |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4847 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4848 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4849 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4850 | break; |
| 4851 | } |
| 4852 | |
| 4853 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
| 4854 | struct notif_beacon_state *x = ¬if->u.beacon_state; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4855 | if (size != sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4856 | IPW_ERROR |
| 4857 | ("Beacon state of wrong size %d (should " |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4858 | "be %zd)\n", size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4859 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4860 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4861 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4862 | if (le32_to_cpu(x->state) == |
| 4863 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) |
| 4864 | ipw_handle_missed_beacon(priv, |
| 4865 | le32_to_cpu(x-> |
| 4866 | number)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4867 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4868 | break; |
| 4869 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4870 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4871 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
| 4872 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4873 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4874 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
| 4875 | "0x%02x station %d\n", |
| 4876 | x->key_state, x->security_type, |
| 4877 | x->station_index); |
| 4878 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4879 | } |
| 4880 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4881 | IPW_ERROR |
| 4882 | ("TGi Tx Key of wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4883 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4884 | break; |
| 4885 | } |
| 4886 | |
| 4887 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
| 4888 | struct notif_calibration *x = ¬if->u.calibration; |
| 4889 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4890 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4891 | memcpy(&priv->calib, x, sizeof(*x)); |
| 4892 | IPW_DEBUG_INFO("TODO: Calibration\n"); |
| 4893 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4894 | } |
| 4895 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4896 | IPW_ERROR |
| 4897 | ("Calibration of wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4898 | size, sizeof(*x)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4899 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4900 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4901 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4902 | case HOST_NOTIFICATION_NOISE_STATS:{ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4903 | if (size == sizeof(u32)) { |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4904 | priv->exp_avg_noise = |
| 4905 | exponential_average(priv->exp_avg_noise, |
| 4906 | (u8) (le32_to_cpu(notif->u.noise.value) & 0xff), |
| 4907 | DEPTH_NOISE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4908 | break; |
| 4909 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4910 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4911 | IPW_ERROR |
| 4912 | ("Noise stat is wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4913 | size, sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4914 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4915 | } |
| 4916 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4917 | default: |
Zhu Yi | 1dd31b6 | 2006-02-20 18:28:09 -0800 | [diff] [blame] | 4918 | IPW_DEBUG_NOTIF("Unknown notification: " |
| 4919 | "subtype=%d,flags=0x%2x,size=%d\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4920 | notif->subtype, notif->flags, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4921 | } |
| 4922 | } |
| 4923 | |
| 4924 | /** |
| 4925 | * Destroys all DMA structures and initialise them again |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4926 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4927 | * @param priv |
| 4928 | * @return error code |
| 4929 | */ |
| 4930 | static int ipw_queue_reset(struct ipw_priv *priv) |
| 4931 | { |
| 4932 | int rc = 0; |
| 4933 | /** @todo customize queue sizes */ |
| 4934 | int nTx = 64, nTxCmd = 8; |
| 4935 | ipw_tx_queue_free(priv); |
| 4936 | /* Tx CMD queue */ |
| 4937 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4938 | IPW_TX_CMD_QUEUE_READ_INDEX, |
| 4939 | IPW_TX_CMD_QUEUE_WRITE_INDEX, |
| 4940 | IPW_TX_CMD_QUEUE_BD_BASE, |
| 4941 | IPW_TX_CMD_QUEUE_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4942 | if (rc) { |
| 4943 | IPW_ERROR("Tx Cmd queue init failed\n"); |
| 4944 | goto error; |
| 4945 | } |
| 4946 | /* Tx queue(s) */ |
| 4947 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4948 | IPW_TX_QUEUE_0_READ_INDEX, |
| 4949 | IPW_TX_QUEUE_0_WRITE_INDEX, |
| 4950 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4951 | if (rc) { |
| 4952 | IPW_ERROR("Tx 0 queue init failed\n"); |
| 4953 | goto error; |
| 4954 | } |
| 4955 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4956 | IPW_TX_QUEUE_1_READ_INDEX, |
| 4957 | IPW_TX_QUEUE_1_WRITE_INDEX, |
| 4958 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4959 | if (rc) { |
| 4960 | IPW_ERROR("Tx 1 queue init failed\n"); |
| 4961 | goto error; |
| 4962 | } |
| 4963 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4964 | IPW_TX_QUEUE_2_READ_INDEX, |
| 4965 | IPW_TX_QUEUE_2_WRITE_INDEX, |
| 4966 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4967 | if (rc) { |
| 4968 | IPW_ERROR("Tx 2 queue init failed\n"); |
| 4969 | goto error; |
| 4970 | } |
| 4971 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4972 | IPW_TX_QUEUE_3_READ_INDEX, |
| 4973 | IPW_TX_QUEUE_3_WRITE_INDEX, |
| 4974 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4975 | if (rc) { |
| 4976 | IPW_ERROR("Tx 3 queue init failed\n"); |
| 4977 | goto error; |
| 4978 | } |
| 4979 | /* statistics */ |
| 4980 | priv->rx_bufs_min = 0; |
| 4981 | priv->rx_pend_max = 0; |
| 4982 | return rc; |
| 4983 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4984 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4985 | ipw_tx_queue_free(priv); |
| 4986 | return rc; |
| 4987 | } |
| 4988 | |
| 4989 | /** |
| 4990 | * Reclaim Tx queue entries no more used by NIC. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4991 | * |
Stefano Brivio | 8ff9d21 | 2008-01-12 23:12:26 +0100 | [diff] [blame] | 4992 | * When FW advances 'R' index, all entries between old and |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4993 | * new 'R' index need to be reclaimed. As result, some free space |
| 4994 | * forms. If there is enough free space (> low mark), wake Tx queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4995 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4996 | * @note Need to protect against garbage in 'R' index |
| 4997 | * @param priv |
| 4998 | * @param txq |
| 4999 | * @param qindex |
| 5000 | * @return Number of used entries remains in the queue |
| 5001 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5002 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5003 | struct clx2_tx_queue *txq, int qindex) |
| 5004 | { |
| 5005 | u32 hw_tail; |
| 5006 | int used; |
| 5007 | struct clx2_queue *q = &txq->q; |
| 5008 | |
| 5009 | hw_tail = ipw_read32(priv, q->reg_r); |
| 5010 | if (hw_tail >= q->n_bd) { |
| 5011 | IPW_ERROR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5012 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
| 5013 | hw_tail, q->n_bd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5014 | goto done; |
| 5015 | } |
| 5016 | for (; q->last_used != hw_tail; |
| 5017 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 5018 | ipw_queue_tx_free_tfd(priv, txq); |
| 5019 | priv->tx_packets++; |
| 5020 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5021 | done: |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5022 | if ((ipw_tx_queue_space(q) > q->low_mark) && |
David S. Miller | 521c4d9 | 2008-07-22 18:32:47 -0700 | [diff] [blame] | 5023 | (qindex >= 0)) |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 5024 | netif_wake_queue(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5025 | used = q->first_empty - q->last_used; |
| 5026 | if (used < 0) |
| 5027 | used += q->n_bd; |
| 5028 | |
| 5029 | return used; |
| 5030 | } |
| 5031 | |
| 5032 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 5033 | int len, int sync) |
| 5034 | { |
| 5035 | struct clx2_tx_queue *txq = &priv->txq_cmd; |
| 5036 | struct clx2_queue *q = &txq->q; |
| 5037 | struct tfd_frame *tfd; |
| 5038 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5039 | if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5040 | IPW_ERROR("No space for Tx\n"); |
| 5041 | return -EBUSY; |
| 5042 | } |
| 5043 | |
| 5044 | tfd = &txq->bd[q->first_empty]; |
| 5045 | txq->txb[q->first_empty] = NULL; |
| 5046 | |
| 5047 | memset(tfd, 0, sizeof(*tfd)); |
| 5048 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; |
| 5049 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 5050 | priv->hcmd_seq++; |
| 5051 | tfd->u.cmd.index = hcmd; |
| 5052 | tfd->u.cmd.length = len; |
| 5053 | memcpy(tfd->u.cmd.payload, buf, len); |
| 5054 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 5055 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 5056 | _ipw_read32(priv, 0x90); |
| 5057 | |
| 5058 | return 0; |
| 5059 | } |
| 5060 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5061 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5062 | * Rx theory of operation |
| 5063 | * |
| 5064 | * The host allocates 32 DMA target addresses and passes the host address |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5065 | * 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] | 5066 | * 0 to 31 |
| 5067 | * |
| 5068 | * Rx Queue Indexes |
| 5069 | * The host/firmware share two index registers for managing the Rx buffers. |
| 5070 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5071 | * The READ index maps to the first position that the firmware may be writing |
| 5072 | * to -- the driver can read up to (but not including) this position and get |
| 5073 | * good data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5074 | * The READ index is managed by the firmware once the card is enabled. |
| 5075 | * |
| 5076 | * The WRITE index maps to the last position the driver has read from -- the |
| 5077 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 5078 | * |
| 5079 | * 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] | 5080 | * WRITE = READ. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5081 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5082 | * 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] | 5083 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 5084 | * |
| 5085 | * When the firmware places a packet in a buffer it will advance the READ index |
| 5086 | * and fire the RX interrupt. The driver can then query the READ index and |
| 5087 | * process as many packets as possible, moving the WRITE index forward as it |
| 5088 | * resets the Rx queue buffers with new memory. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5089 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5090 | * The management in the driver is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5091 | * + 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] | 5092 | * 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] | 5093 | * to replensish the ipw->rxq->rx_free. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5094 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
| 5095 | * ipw->rxq is replenished and the READ INDEX is updated (updating the |
| 5096 | * 'processed' and 'read' driver indexes as well) |
| 5097 | * + A received packet is processed and handed to the kernel network stack, |
| 5098 | * detached from the ipw->rxq. The driver 'processed' index is updated. |
| 5099 | * + 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] | 5100 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
| 5101 | * 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] | 5102 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 5103 | * |
| 5104 | * |
| 5105 | * Driver sequence: |
| 5106 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5107 | * ipw_rx_queue_alloc() Allocates rx_free |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5108 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
| 5109 | * ipw_rx_queue_restock |
| 5110 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 5111 | * queue, updates firmware pointers, and updates |
| 5112 | * the WRITE index. If insufficient rx_free buffers |
| 5113 | * are available, schedules ipw_rx_queue_replenish |
| 5114 | * |
| 5115 | * -- enable interrupts -- |
| 5116 | * 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] | 5117 | * READ INDEX, detaching the SKB from the pool. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5118 | * Moves the packet buffer from queue to rx_used. |
| 5119 | * Calls ipw_rx_queue_restock to refill any empty |
| 5120 | * slots. |
| 5121 | * ... |
| 5122 | * |
| 5123 | */ |
| 5124 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5125 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5126 | * If there are slots in the RX queue that need to be restocked, |
| 5127 | * and we have free pre-allocated buffers, fill the ranks as much |
| 5128 | * as we can pulling from rx_free. |
| 5129 | * |
| 5130 | * This moves the 'write' index forward to catch up with 'processed', and |
| 5131 | * also updates the memory address in the firmware to reference the new |
| 5132 | * target buffer. |
| 5133 | */ |
| 5134 | static void ipw_rx_queue_restock(struct ipw_priv *priv) |
| 5135 | { |
| 5136 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5137 | struct list_head *element; |
| 5138 | struct ipw_rx_mem_buffer *rxb; |
| 5139 | unsigned long flags; |
| 5140 | int write; |
| 5141 | |
| 5142 | spin_lock_irqsave(&rxq->lock, flags); |
| 5143 | write = rxq->write; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5144 | while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5145 | element = rxq->rx_free.next; |
| 5146 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
| 5147 | list_del(element); |
| 5148 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5149 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5150 | rxb->dma_addr); |
| 5151 | rxq->queue[rxq->write] = rxb; |
| 5152 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; |
| 5153 | rxq->free_count--; |
| 5154 | } |
| 5155 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5156 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5157 | /* If the pre-allocated buffer pool is dropping low, schedule to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5158 | * refill it */ |
| 5159 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 5160 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 5161 | |
| 5162 | /* 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] | 5163 | if (write != rxq->write) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5164 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | /* |
| 5168 | * 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] | 5169 | * Also restock the Rx queue via ipw_rx_queue_restock. |
| 5170 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5171 | * This is called as a scheduled work item (except for during intialization) |
| 5172 | */ |
| 5173 | static void ipw_rx_queue_replenish(void *data) |
| 5174 | { |
| 5175 | struct ipw_priv *priv = data; |
| 5176 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5177 | struct list_head *element; |
| 5178 | struct ipw_rx_mem_buffer *rxb; |
| 5179 | unsigned long flags; |
| 5180 | |
| 5181 | spin_lock_irqsave(&rxq->lock, flags); |
| 5182 | while (!list_empty(&rxq->rx_used)) { |
| 5183 | element = rxq->rx_used.next; |
| 5184 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5185 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5186 | if (!rxb->skb) { |
| 5187 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", |
| 5188 | priv->net_dev->name); |
| 5189 | /* We don't reschedule replenish work here -- we will |
| 5190 | * call the restock method and if it still needs |
| 5191 | * more buffers it will schedule replenish */ |
| 5192 | break; |
| 5193 | } |
| 5194 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5195 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5196 | rxb->dma_addr = |
| 5197 | pci_map_single(priv->pci_dev, rxb->skb->data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5198 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5199 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5200 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 5201 | rxq->free_count++; |
| 5202 | } |
| 5203 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5204 | |
| 5205 | ipw_rx_queue_restock(priv); |
| 5206 | } |
| 5207 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5208 | static void ipw_bg_rx_queue_replenish(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5209 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5210 | struct ipw_priv *priv = |
| 5211 | container_of(work, struct ipw_priv, rx_replenish); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5212 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5213 | ipw_rx_queue_replenish(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5214 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5215 | } |
| 5216 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5217 | /* 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] | 5218 | * 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] | 5219 | * 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] | 5220 | * non NULL it is unmapped and freed |
| 5221 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5222 | 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] | 5223 | { |
| 5224 | int i; |
| 5225 | |
| 5226 | if (!rxq) |
| 5227 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5228 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5229 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 5230 | if (rxq->pool[i].skb != NULL) { |
| 5231 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5232 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5233 | dev_kfree_skb(rxq->pool[i].skb); |
| 5234 | } |
| 5235 | } |
| 5236 | |
| 5237 | kfree(rxq); |
| 5238 | } |
| 5239 | |
| 5240 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) |
| 5241 | { |
| 5242 | struct ipw_rx_queue *rxq; |
| 5243 | int i; |
| 5244 | |
Takis | c75f474 | 2005-12-01 01:41:45 -0800 | [diff] [blame] | 5245 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
Panagiotis Issaris | ad18b0e | 2005-09-05 04:14:10 +0200 | [diff] [blame] | 5246 | if (unlikely(!rxq)) { |
| 5247 | IPW_ERROR("memory allocation failed\n"); |
| 5248 | return NULL; |
| 5249 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5250 | spin_lock_init(&rxq->lock); |
| 5251 | INIT_LIST_HEAD(&rxq->rx_free); |
| 5252 | INIT_LIST_HEAD(&rxq->rx_used); |
| 5253 | |
| 5254 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5255 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5256 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 5257 | |
| 5258 | /* Set us so that we have processed and used all buffers, but have |
| 5259 | * not restocked the Rx queue with fresh buffers */ |
| 5260 | rxq->read = rxq->write = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5261 | rxq->free_count = 0; |
| 5262 | |
| 5263 | return rxq; |
| 5264 | } |
| 5265 | |
| 5266 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) |
| 5267 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5268 | rate &= ~LIBIPW_BASIC_RATE_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5269 | if (ieee_mode == IEEE_A) { |
| 5270 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5271 | case LIBIPW_OFDM_RATE_6MB: |
| 5272 | return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5273 | 1 : 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5274 | case LIBIPW_OFDM_RATE_9MB: |
| 5275 | return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5276 | 1 : 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5277 | case LIBIPW_OFDM_RATE_12MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5278 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5279 | rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; |
| 5280 | case LIBIPW_OFDM_RATE_18MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5281 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5282 | rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; |
| 5283 | case LIBIPW_OFDM_RATE_24MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5284 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5285 | rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; |
| 5286 | case LIBIPW_OFDM_RATE_36MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5287 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5288 | rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; |
| 5289 | case LIBIPW_OFDM_RATE_48MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5290 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5291 | rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; |
| 5292 | case LIBIPW_OFDM_RATE_54MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5293 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5294 | rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5295 | default: |
| 5296 | return 0; |
| 5297 | } |
| 5298 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5299 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5300 | /* B and G mixed */ |
| 5301 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5302 | case LIBIPW_CCK_RATE_1MB: |
| 5303 | return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0; |
| 5304 | case LIBIPW_CCK_RATE_2MB: |
| 5305 | return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0; |
| 5306 | case LIBIPW_CCK_RATE_5MB: |
| 5307 | return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0; |
| 5308 | case LIBIPW_CCK_RATE_11MB: |
| 5309 | return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | /* If we are limited to B modulations, bail at this point */ |
| 5313 | if (ieee_mode == IEEE_B) |
| 5314 | return 0; |
| 5315 | |
| 5316 | /* G */ |
| 5317 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5318 | case LIBIPW_OFDM_RATE_6MB: |
| 5319 | return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0; |
| 5320 | case LIBIPW_OFDM_RATE_9MB: |
| 5321 | return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0; |
| 5322 | case LIBIPW_OFDM_RATE_12MB: |
| 5323 | return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; |
| 5324 | case LIBIPW_OFDM_RATE_18MB: |
| 5325 | return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; |
| 5326 | case LIBIPW_OFDM_RATE_24MB: |
| 5327 | return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; |
| 5328 | case LIBIPW_OFDM_RATE_36MB: |
| 5329 | return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; |
| 5330 | case LIBIPW_OFDM_RATE_48MB: |
| 5331 | return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; |
| 5332 | case LIBIPW_OFDM_RATE_54MB: |
| 5333 | return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | return 0; |
| 5337 | } |
| 5338 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5339 | static int ipw_compatible_rates(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5340 | const struct libipw_network *network, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5341 | struct ipw_supported_rates *rates) |
| 5342 | { |
| 5343 | int num_rates, i; |
| 5344 | |
| 5345 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5346 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5347 | rates->num_rates = 0; |
| 5348 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5349 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5350 | network->rates[i])) { |
| 5351 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5352 | if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5353 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5354 | "rate %02X\n", |
| 5355 | network->rates[i]); |
| 5356 | rates->supported_rates[rates->num_rates++] = |
| 5357 | network->rates[i]; |
| 5358 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5359 | } |
| 5360 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5361 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5362 | network->rates[i], priv->rates_mask); |
| 5363 | continue; |
| 5364 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5365 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5366 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
| 5367 | } |
| 5368 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5369 | num_rates = min(network->rates_ex_len, |
| 5370 | (u8) (IPW_MAX_RATES - num_rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5371 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5372 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5373 | network->rates_ex[i])) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5374 | if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5375 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5376 | "rate %02X\n", |
| 5377 | network->rates_ex[i]); |
| 5378 | rates->supported_rates[rates->num_rates++] = |
| 5379 | network->rates[i]; |
| 5380 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5381 | } |
| 5382 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5383 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5384 | network->rates_ex[i], priv->rates_mask); |
| 5385 | continue; |
| 5386 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5387 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5388 | rates->supported_rates[rates->num_rates++] = |
| 5389 | network->rates_ex[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5390 | } |
| 5391 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5392 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5393 | } |
| 5394 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5395 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5396 | const struct ipw_supported_rates *src) |
| 5397 | { |
| 5398 | u8 i; |
| 5399 | for (i = 0; i < src->num_rates; i++) |
| 5400 | dest->supported_rates[i] = src->supported_rates[i]; |
| 5401 | dest->num_rates = src->num_rates; |
| 5402 | } |
| 5403 | |
| 5404 | /* TODO: Look at sniffed packets in the air to determine if the basic rate |
| 5405 | * mask should ever be used -- right now all callers to add the scan rates are |
| 5406 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ |
| 5407 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5408 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5409 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5410 | u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? |
| 5411 | LIBIPW_BASIC_RATE_MASK : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5412 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5413 | if (rate_mask & LIBIPW_CCK_RATE_1MB_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_1MB; |
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_2MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5418 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5419 | LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB; |
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_5MB_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_5MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5424 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5425 | if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5426 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5427 | LIBIPW_CCK_RATE_11MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5428 | } |
| 5429 | |
| 5430 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5431 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5432 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5433 | u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? |
| 5434 | LIBIPW_BASIC_RATE_MASK : 0; |
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_6MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5437 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5438 | LIBIPW_OFDM_RATE_6MB; |
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_9MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5441 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5442 | LIBIPW_OFDM_RATE_9MB; |
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_12MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5445 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5446 | LIBIPW_OFDM_RATE_12MB; |
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_18MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5449 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5450 | LIBIPW_OFDM_RATE_18MB; |
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_24MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5453 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5454 | LIBIPW_OFDM_RATE_24MB; |
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_36MB_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_36MB; |
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_48MB_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_48MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5463 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5464 | if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5465 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5466 | LIBIPW_OFDM_RATE_54MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | struct ipw_network_match { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5470 | struct libipw_network *network; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5471 | struct ipw_supported_rates rates; |
| 5472 | }; |
| 5473 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5474 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
| 5475 | struct ipw_network_match *match, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5476 | struct libipw_network *network, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5477 | int roaming) |
| 5478 | { |
| 5479 | struct ipw_supported_rates rates; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5480 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5481 | |
| 5482 | /* Verify that this network's capability is compatible with the |
| 5483 | * current mode (AdHoc or Infrastructure) */ |
| 5484 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5485 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5486 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5487 | "capability mismatch.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5488 | print_ssid(ssid, network->ssid, |
| 5489 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5490 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5491 | return 0; |
| 5492 | } |
| 5493 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5494 | if (unlikely(roaming)) { |
| 5495 | /* If we are roaming, then ensure check if this is a valid |
| 5496 | * network to try and roam to */ |
| 5497 | if ((network->ssid_len != match->network->ssid_len) || |
| 5498 | memcmp(network->ssid, match->network->ssid, |
| 5499 | network->ssid_len)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5500 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5501 | "because of non-network ESSID.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5502 | print_ssid(ssid, network->ssid, |
| 5503 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5504 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5505 | return 0; |
| 5506 | } |
| 5507 | } else { |
| 5508 | /* If an ESSID has been configured then compare the broadcast |
| 5509 | * ESSID to ours */ |
| 5510 | if ((priv->config & CFG_STATIC_ESSID) && |
| 5511 | ((network->ssid_len != priv->essid_len) || |
| 5512 | memcmp(network->ssid, priv->essid, |
| 5513 | min(network->ssid_len, priv->essid_len)))) { |
| 5514 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5515 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5516 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5517 | print_ssid(ssid, network->ssid, |
| 5518 | network->ssid_len), |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5519 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5520 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5521 | "because of ESSID mismatch: '%s'.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5522 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5523 | print_ssid(ssid, priv->essid, |
| 5524 | priv->essid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5525 | return 0; |
| 5526 | } |
| 5527 | } |
| 5528 | |
| 5529 | /* If the old network rate is better than this one, don't bother |
| 5530 | * testing everything else. */ |
| 5531 | |
| 5532 | if (network->time_stamp[0] < match->network->time_stamp[0]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5533 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5534 | "current network.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5535 | print_ssid(ssid, match->network->ssid, |
| 5536 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5537 | return 0; |
| 5538 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5539 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5540 | "current network.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5541 | print_ssid(ssid, match->network->ssid, |
| 5542 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5543 | return 0; |
| 5544 | } |
| 5545 | |
| 5546 | /* Now go through and see if the requested network is valid... */ |
| 5547 | if (priv->ieee->scan_age != 0 && |
| 5548 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5549 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5550 | "because of age: %ums.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5551 | print_ssid(ssid, network->ssid, |
| 5552 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5553 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5554 | jiffies_to_msecs(jiffies - |
| 5555 | network->last_scanned)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5556 | return 0; |
| 5557 | } |
| 5558 | |
| 5559 | if ((priv->config & CFG_STATIC_CHANNEL) && |
| 5560 | (network->channel != priv->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5561 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5562 | "because of channel mismatch: %d != %d.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5563 | print_ssid(ssid, network->ssid, |
| 5564 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5565 | network->bssid, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5566 | network->channel, priv->channel); |
| 5567 | return 0; |
| 5568 | } |
| 5569 | |
| 5570 | /* Verify privacy compatability */ |
| 5571 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
| 5572 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5573 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5574 | "because of privacy mismatch: %s != %s.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5575 | print_ssid(ssid, network->ssid, |
| 5576 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5577 | network->bssid, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5578 | priv-> |
| 5579 | capability & CAP_PRIVACY_ON ? "on" : "off", |
| 5580 | network-> |
| 5581 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : |
| 5582 | "off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5583 | return 0; |
| 5584 | } |
| 5585 | |
| 5586 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5587 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
| 5588 | "because of the same BSSID match: %pM" |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5589 | ".\n", print_ssid(ssid, network->ssid, |
| 5590 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5591 | network->bssid, |
| 5592 | priv->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5593 | return 0; |
| 5594 | } |
| 5595 | |
| 5596 | /* Filter out any incompatible freq / mode combinations */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5597 | if (!libipw_is_valid_mode(priv->ieee, network->mode)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5598 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5599 | "because of invalid frequency/mode " |
| 5600 | "combination.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5601 | print_ssid(ssid, network->ssid, |
| 5602 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5603 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5604 | return 0; |
| 5605 | } |
| 5606 | |
| 5607 | /* Ensure that the rates supported by the driver are compatible with |
| 5608 | * this AP, including verification of basic rates (mandatory) */ |
| 5609 | if (!ipw_compatible_rates(priv, network, &rates)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5610 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5611 | "because configured rate mask excludes " |
| 5612 | "AP mandatory rate.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5613 | print_ssid(ssid, network->ssid, |
| 5614 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5615 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5616 | return 0; |
| 5617 | } |
| 5618 | |
| 5619 | if (rates.num_rates == 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5620 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5621 | "because of no compatible rates.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5622 | print_ssid(ssid, network->ssid, |
| 5623 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5624 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5625 | return 0; |
| 5626 | } |
| 5627 | |
| 5628 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5629 | * want to put too much policy logic here; intelligent scan selection |
| 5630 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5631 | |
| 5632 | /* Set up 'new' AP to this network */ |
| 5633 | ipw_copy_rates(&match->rates, &rates); |
| 5634 | match->network = network; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5635 | IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5636 | print_ssid(ssid, network->ssid, network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5637 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5638 | |
| 5639 | return 1; |
| 5640 | } |
| 5641 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5642 | static void ipw_merge_adhoc_network(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5643 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5644 | DECLARE_SSID_BUF(ssid); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5645 | struct ipw_priv *priv = |
| 5646 | container_of(work, struct ipw_priv, merge_networks); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5647 | struct libipw_network *network = NULL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5648 | struct ipw_network_match match = { |
| 5649 | .network = priv->assoc_network |
| 5650 | }; |
| 5651 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5652 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5653 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5654 | /* First pass through ROAM process -- look for a better |
| 5655 | * network */ |
| 5656 | unsigned long flags; |
| 5657 | |
| 5658 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 5659 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 5660 | if (network != priv->assoc_network) |
| 5661 | ipw_find_adhoc_network(priv, &match, network, |
| 5662 | 1); |
| 5663 | } |
| 5664 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 5665 | |
| 5666 | if (match.network == priv->assoc_network) { |
| 5667 | IPW_DEBUG_MERGE("No better ADHOC in this network to " |
| 5668 | "merge to.\n"); |
| 5669 | return; |
| 5670 | } |
| 5671 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5672 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5673 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
| 5674 | IPW_DEBUG_MERGE("remove network %s\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5675 | print_ssid(ssid, priv->essid, |
| 5676 | priv->essid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5677 | ipw_remove_current_network(priv); |
| 5678 | } |
| 5679 | |
| 5680 | ipw_disassociate(priv); |
| 5681 | priv->assoc_network = match.network; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5682 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5683 | return; |
| 5684 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5685 | } |
| 5686 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5687 | static int ipw_best_network(struct ipw_priv *priv, |
| 5688 | struct ipw_network_match *match, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5689 | struct libipw_network *network, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5690 | { |
| 5691 | struct ipw_supported_rates rates; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5692 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5693 | |
| 5694 | /* Verify that this network's capability is compatible with the |
| 5695 | * current mode (AdHoc or Infrastructure) */ |
| 5696 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && |
Jouni Malinen | 2474385 | 2005-08-14 20:59:59 -0700 | [diff] [blame] | 5697 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5698 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5699 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5700 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5701 | "capability mismatch.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5702 | print_ssid(ssid, network->ssid, |
| 5703 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5704 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5705 | return 0; |
| 5706 | } |
| 5707 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5708 | if (unlikely(roaming)) { |
| 5709 | /* If we are roaming, then ensure check if this is a valid |
| 5710 | * network to try and roam to */ |
| 5711 | if ((network->ssid_len != match->network->ssid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5712 | memcmp(network->ssid, match->network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5713 | network->ssid_len)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5714 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5715 | "because of non-network ESSID.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5716 | print_ssid(ssid, network->ssid, |
| 5717 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5718 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5719 | return 0; |
| 5720 | } |
| 5721 | } else { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5722 | /* If an ESSID has been configured then compare the broadcast |
| 5723 | * ESSID to ours */ |
| 5724 | if ((priv->config & CFG_STATIC_ESSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5725 | ((network->ssid_len != priv->essid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5726 | memcmp(network->ssid, priv->essid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5727 | min(network->ssid_len, priv->essid_len)))) { |
| 5728 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5729 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5730 | print_ssid(ssid, network->ssid, |
| 5731 | network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5732 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5733 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5734 | "because of ESSID mismatch: '%s'.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5735 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5736 | print_ssid(ssid, priv->essid, |
| 5737 | priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5738 | return 0; |
| 5739 | } |
| 5740 | } |
| 5741 | |
| 5742 | /* If the old network rate is better than this one, don't bother |
| 5743 | * testing everything else. */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5744 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5745 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5746 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5747 | print_ssid(ssid, network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5748 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5749 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because " |
| 5750 | "'%s (%pM)' has a stronger signal.\n", |
| 5751 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5752 | print_ssid(ssid, match->network->ssid, |
| 5753 | match->network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5754 | match->network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5755 | return 0; |
| 5756 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5757 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5758 | /* If this network has already had an association attempt within the |
| 5759 | * last 3 seconds, do not try and associate again... */ |
| 5760 | if (network->last_associate && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5761 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5762 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5763 | "because of storming (%ums since last " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5764 | "assoc attempt).\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5765 | print_ssid(ssid, network->ssid, |
| 5766 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5767 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5768 | jiffies_to_msecs(jiffies - |
| 5769 | network->last_associate)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5770 | return 0; |
| 5771 | } |
| 5772 | |
| 5773 | /* Now go through and see if the requested network is valid... */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5774 | if (priv->ieee->scan_age != 0 && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5775 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5776 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5777 | "because of age: %ums.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5778 | print_ssid(ssid, network->ssid, |
| 5779 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5780 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5781 | jiffies_to_msecs(jiffies - |
| 5782 | network->last_scanned)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5783 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5784 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5785 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5786 | if ((priv->config & CFG_STATIC_CHANNEL) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5787 | (network->channel != priv->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5788 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5789 | "because of channel mismatch: %d != %d.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5790 | print_ssid(ssid, network->ssid, |
| 5791 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5792 | network->bssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5793 | network->channel, priv->channel); |
| 5794 | return 0; |
| 5795 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5796 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5797 | /* Verify privacy compatability */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5798 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5799 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5800 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5801 | "because of privacy mismatch: %s != %s.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5802 | print_ssid(ssid, network->ssid, |
| 5803 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5804 | network->bssid, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5805 | priv->capability & CAP_PRIVACY_ON ? "on" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5806 | "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5807 | network->capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5808 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5809 | return 0; |
| 5810 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5811 | |
| 5812 | if ((priv->config & CFG_STATIC_BSSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5813 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5814 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
| 5815 | "because of BSSID mismatch: %pM.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5816 | print_ssid(ssid, network->ssid, |
| 5817 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5818 | network->bssid, priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5819 | return 0; |
| 5820 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5821 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5822 | /* Filter out any incompatible freq / mode combinations */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5823 | if (!libipw_is_valid_mode(priv->ieee, network->mode)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5824 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5825 | "because of invalid frequency/mode " |
| 5826 | "combination.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5827 | print_ssid(ssid, network->ssid, |
| 5828 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5829 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5830 | return 0; |
| 5831 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5832 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5833 | /* Filter out invalid channel in current GEO */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5834 | if (!libipw_is_valid_channel(priv->ieee, network->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5835 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5836 | "because of invalid channel in current GEO\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5837 | print_ssid(ssid, network->ssid, |
| 5838 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5839 | network->bssid); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5840 | return 0; |
| 5841 | } |
| 5842 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5843 | /* Ensure that the rates supported by the driver are compatible with |
| 5844 | * this AP, including verification of basic rates (mandatory) */ |
| 5845 | if (!ipw_compatible_rates(priv, network, &rates)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5846 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5847 | "because configured rate mask excludes " |
| 5848 | "AP mandatory rate.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5849 | print_ssid(ssid, network->ssid, |
| 5850 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5851 | network->bssid); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5852 | return 0; |
| 5853 | } |
| 5854 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5855 | if (rates.num_rates == 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5856 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5857 | "because of no compatible rates.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5858 | print_ssid(ssid, network->ssid, |
| 5859 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5860 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5861 | return 0; |
| 5862 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5863 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5864 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5865 | * want to put too much policy logic here; intelligent scan selection |
| 5866 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5867 | |
| 5868 | /* Set up 'new' AP to this network */ |
| 5869 | ipw_copy_rates(&match->rates, &rates); |
| 5870 | match->network = network; |
| 5871 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5872 | IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5873 | print_ssid(ssid, network->ssid, network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5874 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5875 | |
| 5876 | return 1; |
| 5877 | } |
| 5878 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5879 | static void ipw_adhoc_create(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5880 | struct libipw_network *network) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5881 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5882 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5883 | int i; |
| 5884 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5885 | /* |
| 5886 | * For the purposes of scanning, we can set our wireless mode |
| 5887 | * to trigger scans across combinations of bands, but when it |
| 5888 | * comes to creating a new ad-hoc network, we have tell the FW |
| 5889 | * exactly which band to use. |
| 5890 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5891 | * We also have the possibility of an invalid channel for the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5892 | * chossen band. Attempting to create a new ad-hoc network |
| 5893 | * with an invalid channel for wireless mode will trigger a |
| 5894 | * FW fatal error. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5895 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5896 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5897 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 5898 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5899 | network->mode = IEEE_A; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5900 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5901 | BUG_ON(i == -1); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5902 | if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5903 | IPW_WARNING("Overriding invalid channel\n"); |
| 5904 | priv->channel = geo->a[0].channel; |
| 5905 | } |
| 5906 | break; |
| 5907 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5908 | case LIBIPW_24GHZ_BAND: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5909 | if (priv->ieee->mode & IEEE_G) |
| 5910 | network->mode = IEEE_G; |
| 5911 | else |
| 5912 | network->mode = IEEE_B; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5913 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5914 | BUG_ON(i == -1); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5915 | if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5916 | IPW_WARNING("Overriding invalid channel\n"); |
| 5917 | priv->channel = geo->bg[0].channel; |
| 5918 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5919 | break; |
| 5920 | |
| 5921 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5922 | IPW_WARNING("Overriding invalid channel\n"); |
| 5923 | if (priv->ieee->mode & IEEE_A) { |
| 5924 | network->mode = IEEE_A; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5925 | priv->channel = geo->a[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5926 | } else if (priv->ieee->mode & IEEE_G) { |
| 5927 | network->mode = IEEE_G; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5928 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5929 | } else { |
| 5930 | network->mode = IEEE_B; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5931 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5932 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5933 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | network->channel = priv->channel; |
| 5937 | priv->config |= CFG_ADHOC_PERSIST; |
| 5938 | ipw_create_bssid(priv, network->bssid); |
| 5939 | network->ssid_len = priv->essid_len; |
| 5940 | memcpy(network->ssid, priv->essid, priv->essid_len); |
| 5941 | memset(&network->stats, 0, sizeof(network->stats)); |
| 5942 | network->capability = WLAN_CAPABILITY_IBSS; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5943 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
| 5944 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5945 | if (priv->capability & CAP_PRIVACY_ON) |
| 5946 | network->capability |= WLAN_CAPABILITY_PRIVACY; |
| 5947 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5948 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5949 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5950 | memcpy(network->rates_ex, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5951 | &priv->rates.supported_rates[network->rates_len], |
| 5952 | network->rates_ex_len); |
| 5953 | network->last_scanned = 0; |
| 5954 | network->flags = 0; |
| 5955 | network->last_associate = 0; |
| 5956 | network->time_stamp[0] = 0; |
| 5957 | network->time_stamp[1] = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5958 | network->beacon_interval = 100; /* Default */ |
| 5959 | network->listen_interval = 10; /* Default */ |
| 5960 | network->atim_window = 0; /* Default */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5961 | network->wpa_ie_len = 0; |
| 5962 | network->rsn_ie_len = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5963 | } |
| 5964 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5965 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
| 5966 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5967 | struct ipw_tgi_tx_key key; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5968 | |
| 5969 | if (!(priv->ieee->sec.flags & (1 << index))) |
| 5970 | return; |
| 5971 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5972 | key.key_id = index; |
| 5973 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); |
| 5974 | key.security_type = type; |
| 5975 | key.station_index = 0; /* always 0 for BSS */ |
| 5976 | key.flags = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5977 | /* 0 for new key; previous value of counter (after fatal error) */ |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 5978 | key.tx_counter[0] = cpu_to_le32(0); |
| 5979 | key.tx_counter[1] = cpu_to_le32(0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5980 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5981 | 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] | 5982 | } |
| 5983 | |
| 5984 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5985 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5986 | struct ipw_wep_key key; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5987 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5988 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5989 | key.cmd_id = DINO_CMD_WEP_KEY; |
| 5990 | key.seq_num = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5991 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5992 | /* Note: AES keys cannot be set for multiple times. |
| 5993 | * Only set it at the first time. */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5994 | for (i = 0; i < 4; i++) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5995 | key.key_index = i | type; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5996 | if (!(priv->ieee->sec.flags & (1 << i))) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5997 | key.key_size = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5998 | continue; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5999 | } |
| 6000 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6001 | key.key_size = priv->ieee->sec.key_sizes[i]; |
| 6002 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6003 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6004 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6005 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6006 | } |
| 6007 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6008 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
| 6009 | { |
| 6010 | if (priv->ieee->host_encrypt) |
| 6011 | return; |
| 6012 | |
| 6013 | switch (level) { |
| 6014 | case SEC_LEVEL_3: |
| 6015 | priv->sys_config.disable_unicast_decryption = 0; |
| 6016 | priv->ieee->host_decrypt = 0; |
| 6017 | break; |
| 6018 | case SEC_LEVEL_2: |
| 6019 | priv->sys_config.disable_unicast_decryption = 1; |
| 6020 | priv->ieee->host_decrypt = 1; |
| 6021 | break; |
| 6022 | case SEC_LEVEL_1: |
| 6023 | priv->sys_config.disable_unicast_decryption = 0; |
| 6024 | priv->ieee->host_decrypt = 0; |
| 6025 | break; |
| 6026 | case SEC_LEVEL_0: |
| 6027 | priv->sys_config.disable_unicast_decryption = 1; |
| 6028 | break; |
| 6029 | default: |
| 6030 | break; |
| 6031 | } |
| 6032 | } |
| 6033 | |
| 6034 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) |
| 6035 | { |
| 6036 | if (priv->ieee->host_encrypt) |
| 6037 | return; |
| 6038 | |
| 6039 | switch (level) { |
| 6040 | case SEC_LEVEL_3: |
| 6041 | priv->sys_config.disable_multicast_decryption = 0; |
| 6042 | break; |
| 6043 | case SEC_LEVEL_2: |
| 6044 | priv->sys_config.disable_multicast_decryption = 1; |
| 6045 | break; |
| 6046 | case SEC_LEVEL_1: |
| 6047 | priv->sys_config.disable_multicast_decryption = 0; |
| 6048 | break; |
| 6049 | case SEC_LEVEL_0: |
| 6050 | priv->sys_config.disable_multicast_decryption = 1; |
| 6051 | break; |
| 6052 | default: |
| 6053 | break; |
| 6054 | } |
| 6055 | } |
| 6056 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6057 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
| 6058 | { |
| 6059 | switch (priv->ieee->sec.level) { |
| 6060 | case SEC_LEVEL_3: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 6061 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 6062 | ipw_send_tgi_tx_key(priv, |
| 6063 | DCT_FLAG_EXT_SECURITY_CCM, |
| 6064 | priv->ieee->sec.active_key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6065 | |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6066 | if (!priv->ieee->host_mc_decrypt) |
| 6067 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6068 | break; |
| 6069 | case SEC_LEVEL_2: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 6070 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 6071 | ipw_send_tgi_tx_key(priv, |
| 6072 | DCT_FLAG_EXT_SECURITY_TKIP, |
| 6073 | priv->ieee->sec.active_key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6074 | break; |
| 6075 | case SEC_LEVEL_1: |
| 6076 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Hong Liu | 29cb843 | 2005-09-12 10:43:33 -0500 | [diff] [blame] | 6077 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
| 6078 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6079 | break; |
| 6080 | case SEC_LEVEL_0: |
| 6081 | default: |
| 6082 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6083 | } |
| 6084 | } |
| 6085 | |
| 6086 | static void ipw_adhoc_check(void *data) |
| 6087 | { |
| 6088 | struct ipw_priv *priv = data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6089 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6090 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6091 | !(priv->config & CFG_ADHOC_PERSIST)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6092 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 6093 | IPW_DL_STATE | IPW_DL_ASSOC, |
| 6094 | "Missed beacon: %d - disassociate\n", |
| 6095 | priv->missed_adhoc_beacons); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6096 | ipw_remove_current_network(priv); |
| 6097 | ipw_disassociate(priv); |
| 6098 | return; |
| 6099 | } |
| 6100 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6101 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 6102 | le16_to_cpu(priv->assoc_request.beacon_interval)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6103 | } |
| 6104 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6105 | static void ipw_bg_adhoc_check(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6106 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6107 | struct ipw_priv *priv = |
| 6108 | container_of(work, struct ipw_priv, adhoc_check.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6109 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6110 | ipw_adhoc_check(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6111 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6112 | } |
| 6113 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6114 | static void ipw_debug_config(struct ipw_priv *priv) |
| 6115 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6116 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6117 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
| 6118 | "[CFG 0x%08X]\n", priv->config); |
| 6119 | if (priv->config & CFG_STATIC_CHANNEL) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6120 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6121 | else |
| 6122 | IPW_DEBUG_INFO("Channel unlocked.\n"); |
| 6123 | if (priv->config & CFG_STATIC_ESSID) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6124 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6125 | print_ssid(ssid, priv->essid, priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6126 | else |
| 6127 | IPW_DEBUG_INFO("ESSID unlocked.\n"); |
| 6128 | if (priv->config & CFG_STATIC_BSSID) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6129 | IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6130 | else |
| 6131 | IPW_DEBUG_INFO("BSSID unlocked.\n"); |
| 6132 | if (priv->capability & CAP_PRIVACY_ON) |
| 6133 | IPW_DEBUG_INFO("PRIVACY on\n"); |
| 6134 | else |
| 6135 | IPW_DEBUG_INFO("PRIVACY off\n"); |
| 6136 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); |
| 6137 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6138 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 6139 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6140 | { |
| 6141 | /* TODO: Verify that this works... */ |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6142 | struct ipw_fixed_rate fr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6143 | u32 reg; |
| 6144 | u16 mask = 0; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6145 | u16 new_tx_rates = priv->rates_mask; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6146 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6147 | /* Identify 'current FW band' and match it with the fixed |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6148 | * Tx rates */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6149 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6150 | switch (priv->ieee->freq_band) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6151 | case LIBIPW_52GHZ_BAND: /* A only */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6152 | /* IEEE_A */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6153 | if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6154 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6155 | IPW_DEBUG_WX |
| 6156 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6157 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6158 | break; |
| 6159 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6160 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6161 | new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6162 | break; |
| 6163 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6164 | default: /* 2.4Ghz or Mixed */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6165 | /* IEEE_B */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6166 | if (mode == IEEE_B) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6167 | if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6168 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6169 | IPW_DEBUG_WX |
| 6170 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6171 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6172 | } |
| 6173 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6174 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6175 | |
| 6176 | /* IEEE_G */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6177 | if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK | |
| 6178 | LIBIPW_OFDM_RATES_MASK)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6179 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6180 | IPW_DEBUG_WX |
| 6181 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6182 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6183 | break; |
| 6184 | } |
| 6185 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6186 | if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) { |
| 6187 | mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1); |
| 6188 | new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6189 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6190 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6191 | if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) { |
| 6192 | mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1); |
| 6193 | new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6194 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6195 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6196 | if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) { |
| 6197 | mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1); |
| 6198 | new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6199 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6200 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6201 | new_tx_rates |= mask; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6202 | break; |
| 6203 | } |
| 6204 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6205 | fr.tx_rates = cpu_to_le16(new_tx_rates); |
| 6206 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6207 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6208 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6209 | } |
| 6210 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6211 | static void ipw_abort_scan(struct ipw_priv *priv) |
| 6212 | { |
| 6213 | int err; |
| 6214 | |
| 6215 | if (priv->status & STATUS_SCAN_ABORTING) { |
| 6216 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); |
| 6217 | return; |
| 6218 | } |
| 6219 | priv->status |= STATUS_SCAN_ABORTING; |
| 6220 | |
| 6221 | err = ipw_send_scan_abort(priv); |
| 6222 | if (err) |
| 6223 | IPW_DEBUG_HC("Request to abort scan failed.\n"); |
| 6224 | } |
| 6225 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6226 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
| 6227 | struct ipw_scan_request_ext *scan, |
| 6228 | int scan_type) |
| 6229 | { |
| 6230 | int channel_index = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6231 | const struct libipw_geo *geo; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6232 | int i; |
| 6233 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6234 | geo = libipw_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6235 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6236 | if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6237 | int start = channel_index; |
| 6238 | for (i = 0; i < geo->a_channels; i++) { |
| 6239 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6240 | geo->a[i].channel == priv->channel) |
| 6241 | continue; |
| 6242 | channel_index++; |
| 6243 | scan->channels_list[channel_index] = geo->a[i].channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6244 | ipw_set_scan_type(scan, channel_index, |
| 6245 | geo->a[i]. |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6246 | flags & LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6247 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : |
| 6248 | scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | if (start != channel_index) { |
| 6252 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | |
| 6253 | (channel_index - start); |
| 6254 | channel_index++; |
| 6255 | } |
| 6256 | } |
| 6257 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6258 | if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6259 | int start = channel_index; |
| 6260 | if (priv->config & CFG_SPEED_SCAN) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6261 | int index; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6262 | u8 channels[LIBIPW_24GHZ_CHANNELS] = { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6263 | /* nop out the list */ |
| 6264 | [0] = 0 |
| 6265 | }; |
| 6266 | |
| 6267 | u8 channel; |
Zhu Yi | 7dd2459 | 2009-07-27 10:10:20 +0800 | [diff] [blame] | 6268 | while (channel_index < IPW_SCAN_CHANNELS - 1) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6269 | channel = |
| 6270 | priv->speed_scan[priv->speed_scan_pos]; |
| 6271 | if (channel == 0) { |
| 6272 | priv->speed_scan_pos = 0; |
| 6273 | channel = priv->speed_scan[0]; |
| 6274 | } |
| 6275 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6276 | channel == priv->channel) { |
| 6277 | priv->speed_scan_pos++; |
| 6278 | continue; |
| 6279 | } |
| 6280 | |
| 6281 | /* If this channel has already been |
| 6282 | * added in scan, break from loop |
| 6283 | * and this will be the first channel |
| 6284 | * in the next scan. |
| 6285 | */ |
| 6286 | if (channels[channel - 1] != 0) |
| 6287 | break; |
| 6288 | |
| 6289 | channels[channel - 1] = 1; |
| 6290 | priv->speed_scan_pos++; |
| 6291 | channel_index++; |
| 6292 | scan->channels_list[channel_index] = channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6293 | index = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6294 | libipw_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6295 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6296 | geo->bg[index]. |
| 6297 | flags & |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6298 | LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6299 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6300 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6301 | } |
| 6302 | } else { |
| 6303 | for (i = 0; i < geo->bg_channels; i++) { |
| 6304 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6305 | geo->bg[i].channel == priv->channel) |
| 6306 | continue; |
| 6307 | channel_index++; |
| 6308 | scan->channels_list[channel_index] = |
| 6309 | geo->bg[i].channel; |
| 6310 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6311 | geo->bg[i]. |
| 6312 | flags & |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6313 | LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6314 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6315 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6316 | } |
| 6317 | } |
| 6318 | |
| 6319 | if (start != channel_index) { |
| 6320 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | |
| 6321 | (channel_index - start); |
| 6322 | } |
| 6323 | } |
| 6324 | } |
| 6325 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6326 | static int ipw_passive_dwell_time(struct ipw_priv *priv) |
| 6327 | { |
| 6328 | /* staying on passive channels longer than the DTIM interval during a |
| 6329 | * scan, while associated, causes the firmware to cancel the scan |
| 6330 | * without notification. Hence, don't stay on passive channels longer |
| 6331 | * than the beacon interval. |
| 6332 | */ |
| 6333 | if (priv->status & STATUS_ASSOCIATED |
| 6334 | && priv->assoc_network->beacon_interval > 10) |
| 6335 | return priv->assoc_network->beacon_interval - 10; |
| 6336 | else |
| 6337 | return 120; |
| 6338 | } |
| 6339 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6340 | 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] | 6341 | { |
| 6342 | struct ipw_scan_request_ext scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6343 | int err = 0, scan_type; |
| 6344 | |
| 6345 | if (!(priv->status & STATUS_INIT) || |
| 6346 | (priv->status & STATUS_EXIT_PENDING)) |
| 6347 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6348 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6349 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6350 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6351 | if (direct && (priv->direct_scan_ssid_len == 0)) { |
| 6352 | IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n"); |
| 6353 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; |
| 6354 | goto done; |
| 6355 | } |
| 6356 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6357 | if (priv->status & STATUS_SCANNING) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6358 | IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n"); |
| 6359 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6360 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6361 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6362 | } |
| 6363 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6364 | if (!(priv->status & STATUS_SCAN_FORCED) && |
| 6365 | priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6366 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6367 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6368 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6369 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6370 | } |
| 6371 | |
| 6372 | if (priv->status & STATUS_RF_KILL_MASK) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6373 | IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n"); |
| 6374 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6375 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6376 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | memset(&scan, 0, sizeof(scan)); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6380 | scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee)); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6381 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6382 | if (type == IW_SCAN_TYPE_PASSIVE) { |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6383 | IPW_DEBUG_WX("use passive scanning\n"); |
| 6384 | scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN; |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6385 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6386 | cpu_to_le16(ipw_passive_dwell_time(priv)); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6387 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 6388 | goto send_request; |
| 6389 | } |
| 6390 | |
| 6391 | /* Use active scan by default. */ |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6392 | if (priv->config & CFG_SPEED_SCAN) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6393 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6394 | cpu_to_le16(30); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6395 | else |
| 6396 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6397 | cpu_to_le16(20); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6398 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6399 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6400 | cpu_to_le16(20); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6401 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6402 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
| 6403 | cpu_to_le16(ipw_passive_dwell_time(priv)); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6404 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6405 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6406 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6407 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6408 | u8 channel; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6409 | u8 band = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6410 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6411 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 6412 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6413 | band = (u8) (IPW_A_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6414 | channel = priv->channel; |
| 6415 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6416 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6417 | case LIBIPW_24GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6418 | band = (u8) (IPW_B_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6419 | channel = priv->channel; |
| 6420 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6421 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6422 | default: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6423 | band = (u8) (IPW_B_MODE << 6) | 1; |
| 6424 | channel = 9; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6425 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6426 | } |
| 6427 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6428 | scan.channels_list[0] = band; |
| 6429 | scan.channels_list[1] = channel; |
| 6430 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6431 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6432 | /* NOTE: The card will sit on this channel for this time |
| 6433 | * period. Scan aborts are timing sensitive and frequently |
| 6434 | * result in firmware restarts. As such, it is best to |
| 6435 | * set a small dwell_time here and just keep re-issuing |
| 6436 | * scans. Otherwise fast channel hopping will not actually |
| 6437 | * hop channels. |
| 6438 | * |
| 6439 | * TODO: Move SPEED SCAN support to all modes and bands */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6440 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6441 | cpu_to_le16(2000); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6442 | } else { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6443 | #endif /* CONFIG_IPW2200_MONITOR */ |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6444 | /* Honor direct scans first, otherwise if we are roaming make |
| 6445 | * this a direct scan for the current network. Finally, |
| 6446 | * ensure that every other scan is a fast channel hop scan */ |
| 6447 | if (direct) { |
| 6448 | err = ipw_send_ssid(priv, priv->direct_scan_ssid, |
| 6449 | priv->direct_scan_ssid_len); |
| 6450 | if (err) { |
| 6451 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6452 | "failed\n"); |
| 6453 | goto done; |
| 6454 | } |
| 6455 | |
| 6456 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
| 6457 | } else if ((priv->status & STATUS_ROAMING) |
| 6458 | || (!(priv->status & STATUS_ASSOCIATED) |
| 6459 | && (priv->config & CFG_STATIC_ESSID) |
| 6460 | && (le32_to_cpu(scan.full_scan_index) % 2))) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6461 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 6462 | if (err) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6463 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6464 | "failed.\n"); |
| 6465 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6466 | } |
| 6467 | |
| 6468 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6469 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6470 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6471 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6472 | ipw_add_scan_channels(priv, &scan, scan_type); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6473 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6474 | } |
| 6475 | #endif |
| 6476 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6477 | send_request: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6478 | err = ipw_send_scan_request_ext(priv, &scan); |
| 6479 | if (err) { |
| 6480 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6481 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6482 | } |
| 6483 | |
| 6484 | priv->status |= STATUS_SCANNING; |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6485 | if (direct) { |
| 6486 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; |
| 6487 | priv->direct_scan_ssid_len = 0; |
| 6488 | } else |
| 6489 | priv->status &= ~STATUS_SCAN_PENDING; |
| 6490 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6491 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6492 | IPW_SCAN_CHECK_WATCHDOG); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6493 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6494 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6495 | return err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6496 | } |
| 6497 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6498 | static void ipw_request_passive_scan(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6499 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6500 | struct ipw_priv *priv = |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6501 | container_of(work, struct ipw_priv, request_passive_scan.work); |
| 6502 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6503 | } |
| 6504 | |
| 6505 | static void ipw_request_scan(struct work_struct *work) |
| 6506 | { |
| 6507 | struct ipw_priv *priv = |
| 6508 | container_of(work, struct ipw_priv, request_scan.work); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6509 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0); |
| 6510 | } |
| 6511 | |
| 6512 | static void ipw_request_direct_scan(struct work_struct *work) |
| 6513 | { |
| 6514 | struct ipw_priv *priv = |
| 6515 | container_of(work, struct ipw_priv, request_direct_scan.work); |
| 6516 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6517 | } |
| 6518 | |
| 6519 | static void ipw_bg_abort_scan(struct work_struct *work) |
| 6520 | { |
| 6521 | struct ipw_priv *priv = |
| 6522 | container_of(work, struct ipw_priv, abort_scan); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6523 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6524 | ipw_abort_scan(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6525 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6526 | } |
| 6527 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6528 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
| 6529 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6530 | /* This is called when wpa_supplicant loads and closes the driver |
| 6531 | * interface. */ |
Hong Liu | cdd1fa1 | 2005-08-31 18:14:27 +0800 | [diff] [blame] | 6532 | priv->ieee->wpa_enabled = value; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6533 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6534 | } |
| 6535 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6536 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
| 6537 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6538 | struct libipw_device *ieee = priv->ieee; |
| 6539 | struct libipw_security sec = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6540 | .flags = SEC_AUTH_MODE, |
| 6541 | }; |
| 6542 | int ret = 0; |
| 6543 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6544 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6545 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
| 6546 | ieee->open_wep = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6547 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6548 | sec.auth_mode = WLAN_AUTH_OPEN; |
| 6549 | ieee->open_wep = 1; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 6550 | } else if (value & IW_AUTH_ALG_LEAP) { |
| 6551 | sec.auth_mode = WLAN_AUTH_LEAP; |
| 6552 | ieee->open_wep = 1; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6553 | } else |
| 6554 | return -EINVAL; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6555 | |
| 6556 | if (ieee->set_security) |
| 6557 | ieee->set_security(ieee->dev, &sec); |
| 6558 | else |
| 6559 | ret = -EOPNOTSUPP; |
| 6560 | |
| 6561 | return ret; |
| 6562 | } |
| 6563 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 6564 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
| 6565 | int wpa_ie_len) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6566 | { |
| 6567 | /* make sure WPA is enabled */ |
| 6568 | ipw_wpa_enable(priv, 1); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6569 | } |
| 6570 | |
| 6571 | static int ipw_set_rsn_capa(struct ipw_priv *priv, |
| 6572 | char *capabilities, int length) |
| 6573 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6574 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
| 6575 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6576 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 6577 | capabilities); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6578 | } |
| 6579 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6580 | /* |
| 6581 | * WE-18 support |
| 6582 | */ |
| 6583 | |
| 6584 | /* SIOCSIWGENIE */ |
| 6585 | static int ipw_wx_set_genie(struct net_device *dev, |
| 6586 | struct iw_request_info *info, |
| 6587 | union iwreq_data *wrqu, char *extra) |
| 6588 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6589 | struct ipw_priv *priv = libipw_priv(dev); |
| 6590 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6591 | u8 *buf; |
| 6592 | int err = 0; |
| 6593 | |
| 6594 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
| 6595 | (wrqu->data.length && extra == NULL)) |
| 6596 | return -EINVAL; |
| 6597 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6598 | if (wrqu->data.length) { |
| 6599 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 6600 | if (buf == NULL) { |
| 6601 | err = -ENOMEM; |
| 6602 | goto out; |
| 6603 | } |
| 6604 | |
| 6605 | memcpy(buf, extra, wrqu->data.length); |
| 6606 | kfree(ieee->wpa_ie); |
| 6607 | ieee->wpa_ie = buf; |
| 6608 | ieee->wpa_ie_len = wrqu->data.length; |
| 6609 | } else { |
| 6610 | kfree(ieee->wpa_ie); |
| 6611 | ieee->wpa_ie = NULL; |
| 6612 | ieee->wpa_ie_len = 0; |
| 6613 | } |
| 6614 | |
| 6615 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6616 | out: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6617 | return err; |
| 6618 | } |
| 6619 | |
| 6620 | /* SIOCGIWGENIE */ |
| 6621 | static int ipw_wx_get_genie(struct net_device *dev, |
| 6622 | struct iw_request_info *info, |
| 6623 | union iwreq_data *wrqu, char *extra) |
| 6624 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6625 | struct ipw_priv *priv = libipw_priv(dev); |
| 6626 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6627 | int err = 0; |
| 6628 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6629 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
| 6630 | wrqu->data.length = 0; |
| 6631 | goto out; |
| 6632 | } |
| 6633 | |
| 6634 | if (wrqu->data.length < ieee->wpa_ie_len) { |
| 6635 | err = -E2BIG; |
| 6636 | goto out; |
| 6637 | } |
| 6638 | |
| 6639 | wrqu->data.length = ieee->wpa_ie_len; |
| 6640 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6641 | |
| 6642 | out: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6643 | return err; |
| 6644 | } |
| 6645 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6646 | static int wext_cipher2level(int cipher) |
| 6647 | { |
| 6648 | switch (cipher) { |
| 6649 | case IW_AUTH_CIPHER_NONE: |
| 6650 | return SEC_LEVEL_0; |
| 6651 | case IW_AUTH_CIPHER_WEP40: |
| 6652 | case IW_AUTH_CIPHER_WEP104: |
| 6653 | return SEC_LEVEL_1; |
| 6654 | case IW_AUTH_CIPHER_TKIP: |
| 6655 | return SEC_LEVEL_2; |
| 6656 | case IW_AUTH_CIPHER_CCMP: |
| 6657 | return SEC_LEVEL_3; |
| 6658 | default: |
| 6659 | return -1; |
| 6660 | } |
| 6661 | } |
| 6662 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6663 | /* SIOCSIWAUTH */ |
| 6664 | static int ipw_wx_set_auth(struct net_device *dev, |
| 6665 | struct iw_request_info *info, |
| 6666 | union iwreq_data *wrqu, char *extra) |
| 6667 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6668 | struct ipw_priv *priv = libipw_priv(dev); |
| 6669 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6670 | struct iw_param *param = &wrqu->param; |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6671 | struct lib80211_crypt_data *crypt; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6672 | unsigned long flags; |
| 6673 | int ret = 0; |
| 6674 | |
| 6675 | switch (param->flags & IW_AUTH_INDEX) { |
| 6676 | case IW_AUTH_WPA_VERSION: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6677 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6678 | case IW_AUTH_CIPHER_PAIRWISE: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6679 | ipw_set_hw_decrypt_unicast(priv, |
| 6680 | wext_cipher2level(param->value)); |
| 6681 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6682 | case IW_AUTH_CIPHER_GROUP: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6683 | ipw_set_hw_decrypt_multicast(priv, |
| 6684 | wext_cipher2level(param->value)); |
| 6685 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6686 | case IW_AUTH_KEY_MGMT: |
| 6687 | /* |
| 6688 | * ipw2200 does not use these parameters |
| 6689 | */ |
| 6690 | break; |
| 6691 | |
| 6692 | case IW_AUTH_TKIP_COUNTERMEASURES: |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6693 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6694 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6695 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6696 | |
| 6697 | flags = crypt->ops->get_flags(crypt->priv); |
| 6698 | |
| 6699 | if (param->value) |
| 6700 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6701 | else |
| 6702 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6703 | |
| 6704 | crypt->ops->set_flags(flags, crypt->priv); |
| 6705 | |
| 6706 | break; |
| 6707 | |
| 6708 | case IW_AUTH_DROP_UNENCRYPTED:{ |
| 6709 | /* HACK: |
| 6710 | * |
| 6711 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6712 | * is loaded and unloaded, regardless of if WPA is being |
| 6713 | * used. No other calls are made which can be used to |
| 6714 | * determine if encryption will be used or not prior to |
| 6715 | * association being expected. If encryption is not being |
| 6716 | * used, drop_unencrypted is set to false, else true -- we |
| 6717 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6718 | * be set. |
| 6719 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6720 | struct libipw_security sec = { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6721 | .flags = SEC_ENABLED, |
| 6722 | .enabled = param->value, |
| 6723 | }; |
| 6724 | priv->ieee->drop_unencrypted = param->value; |
| 6725 | /* We only change SEC_LEVEL for open mode. Others |
| 6726 | * are set by ipw_wpa_set_encryption. |
| 6727 | */ |
| 6728 | if (!param->value) { |
| 6729 | sec.flags |= SEC_LEVEL; |
| 6730 | sec.level = SEC_LEVEL_0; |
| 6731 | } else { |
| 6732 | sec.flags |= SEC_LEVEL; |
| 6733 | sec.level = SEC_LEVEL_1; |
| 6734 | } |
| 6735 | if (priv->ieee->set_security) |
| 6736 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6737 | break; |
| 6738 | } |
| 6739 | |
| 6740 | case IW_AUTH_80211_AUTH_ALG: |
| 6741 | ret = ipw_wpa_set_auth_algs(priv, param->value); |
| 6742 | break; |
| 6743 | |
| 6744 | case IW_AUTH_WPA_ENABLED: |
| 6745 | ret = ipw_wpa_enable(priv, param->value); |
Zhu Yi | e3c5a64 | 2006-04-13 17:21:13 +0800 | [diff] [blame] | 6746 | ipw_disassociate(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6747 | break; |
| 6748 | |
| 6749 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6750 | ieee->ieee802_1x = param->value; |
| 6751 | break; |
| 6752 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6753 | case IW_AUTH_PRIVACY_INVOKED: |
| 6754 | ieee->privacy_invoked = param->value; |
| 6755 | break; |
| 6756 | |
| 6757 | default: |
| 6758 | return -EOPNOTSUPP; |
| 6759 | } |
| 6760 | return ret; |
| 6761 | } |
| 6762 | |
| 6763 | /* SIOCGIWAUTH */ |
| 6764 | static int ipw_wx_get_auth(struct net_device *dev, |
| 6765 | struct iw_request_info *info, |
| 6766 | union iwreq_data *wrqu, char *extra) |
| 6767 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6768 | struct ipw_priv *priv = libipw_priv(dev); |
| 6769 | struct libipw_device *ieee = priv->ieee; |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6770 | struct lib80211_crypt_data *crypt; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6771 | struct iw_param *param = &wrqu->param; |
| 6772 | int ret = 0; |
| 6773 | |
| 6774 | switch (param->flags & IW_AUTH_INDEX) { |
| 6775 | case IW_AUTH_WPA_VERSION: |
| 6776 | case IW_AUTH_CIPHER_PAIRWISE: |
| 6777 | case IW_AUTH_CIPHER_GROUP: |
| 6778 | case IW_AUTH_KEY_MGMT: |
| 6779 | /* |
| 6780 | * wpa_supplicant will control these internally |
| 6781 | */ |
| 6782 | ret = -EOPNOTSUPP; |
| 6783 | break; |
| 6784 | |
| 6785 | case IW_AUTH_TKIP_COUNTERMEASURES: |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6786 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6787 | if (!crypt || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6788 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6789 | |
| 6790 | param->value = (crypt->ops->get_flags(crypt->priv) & |
| 6791 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; |
| 6792 | |
| 6793 | break; |
| 6794 | |
| 6795 | case IW_AUTH_DROP_UNENCRYPTED: |
| 6796 | param->value = ieee->drop_unencrypted; |
| 6797 | break; |
| 6798 | |
| 6799 | case IW_AUTH_80211_AUTH_ALG: |
| 6800 | param->value = ieee->sec.auth_mode; |
| 6801 | break; |
| 6802 | |
| 6803 | case IW_AUTH_WPA_ENABLED: |
| 6804 | param->value = ieee->wpa_enabled; |
| 6805 | break; |
| 6806 | |
| 6807 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6808 | param->value = ieee->ieee802_1x; |
| 6809 | break; |
| 6810 | |
| 6811 | case IW_AUTH_ROAMING_CONTROL: |
| 6812 | case IW_AUTH_PRIVACY_INVOKED: |
| 6813 | param->value = ieee->privacy_invoked; |
| 6814 | break; |
| 6815 | |
| 6816 | default: |
| 6817 | return -EOPNOTSUPP; |
| 6818 | } |
| 6819 | return 0; |
| 6820 | } |
| 6821 | |
| 6822 | /* SIOCSIWENCODEEXT */ |
| 6823 | static int ipw_wx_set_encodeext(struct net_device *dev, |
| 6824 | struct iw_request_info *info, |
| 6825 | union iwreq_data *wrqu, char *extra) |
| 6826 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6827 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6828 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 6829 | |
| 6830 | if (hwcrypto) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6831 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6832 | /* IPW HW can't build TKIP MIC, |
| 6833 | host decryption still needed */ |
| 6834 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) |
| 6835 | priv->ieee->host_mc_decrypt = 1; |
| 6836 | else { |
| 6837 | priv->ieee->host_encrypt = 0; |
| 6838 | priv->ieee->host_encrypt_msdu = 1; |
| 6839 | priv->ieee->host_decrypt = 1; |
| 6840 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6841 | } else { |
| 6842 | priv->ieee->host_encrypt = 0; |
| 6843 | priv->ieee->host_encrypt_msdu = 0; |
| 6844 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6845 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6846 | } |
| 6847 | } |
| 6848 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6849 | return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6850 | } |
| 6851 | |
| 6852 | /* SIOCGIWENCODEEXT */ |
| 6853 | static int ipw_wx_get_encodeext(struct net_device *dev, |
| 6854 | struct iw_request_info *info, |
| 6855 | union iwreq_data *wrqu, char *extra) |
| 6856 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6857 | struct ipw_priv *priv = libipw_priv(dev); |
| 6858 | return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6859 | } |
| 6860 | |
| 6861 | /* SIOCSIWMLME */ |
| 6862 | static int ipw_wx_set_mlme(struct net_device *dev, |
| 6863 | struct iw_request_info *info, |
| 6864 | union iwreq_data *wrqu, char *extra) |
| 6865 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6866 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6867 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 6868 | __le16 reason; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6869 | |
| 6870 | reason = cpu_to_le16(mlme->reason_code); |
| 6871 | |
| 6872 | switch (mlme->cmd) { |
| 6873 | case IW_MLME_DEAUTH: |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 6874 | /* silently ignore */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6875 | break; |
| 6876 | |
| 6877 | case IW_MLME_DISASSOC: |
| 6878 | ipw_disassociate(priv); |
| 6879 | break; |
| 6880 | |
| 6881 | default: |
| 6882 | return -EOPNOTSUPP; |
| 6883 | } |
| 6884 | return 0; |
| 6885 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6886 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 6887 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6888 | |
| 6889 | /* QoS */ |
| 6890 | /* |
| 6891 | * get the modulation type of the current network or |
| 6892 | * the card current mode |
| 6893 | */ |
Adrian Bunk | 53d0bcf | 2006-03-04 13:14:31 +0100 | [diff] [blame] | 6894 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6895 | { |
| 6896 | u8 mode = 0; |
| 6897 | |
| 6898 | if (priv->status & STATUS_ASSOCIATED) { |
| 6899 | unsigned long flags; |
| 6900 | |
| 6901 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6902 | mode = priv->assoc_network->mode; |
| 6903 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6904 | } else { |
| 6905 | mode = priv->ieee->mode; |
| 6906 | } |
| 6907 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); |
| 6908 | return mode; |
| 6909 | } |
| 6910 | |
| 6911 | /* |
| 6912 | * Handle management frame beacon and probe response |
| 6913 | */ |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6914 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
| 6915 | int active_network, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6916 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6917 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6918 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6919 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6920 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6921 | network->qos_data.active = network->qos_data.supported; |
| 6922 | |
| 6923 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6924 | if (active_network && |
| 6925 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6926 | network->qos_data.active = network->qos_data.supported; |
| 6927 | |
| 6928 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 6929 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 6930 | (network->qos_data.old_param_count != |
| 6931 | network->qos_data.param_count)) { |
| 6932 | network->qos_data.old_param_count = |
| 6933 | network->qos_data.param_count; |
| 6934 | schedule_work(&priv->qos_activate); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6935 | IPW_DEBUG_QOS("QoS parameters change call " |
| 6936 | "qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6937 | } |
| 6938 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6939 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
| 6940 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6941 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6942 | else |
| 6943 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6944 | &def_parameters_OFDM, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6945 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6946 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
| 6947 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); |
| 6948 | schedule_work(&priv->qos_activate); |
| 6949 | } |
| 6950 | |
| 6951 | network->qos_data.active = 0; |
| 6952 | network->qos_data.supported = 0; |
| 6953 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6954 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6955 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { |
| 6956 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) |
John W. Linville | c5d3dce | 2008-09-30 17:17:26 -0400 | [diff] [blame] | 6957 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6958 | if ((network->ssid_len == |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6959 | priv->assoc_network->ssid_len) && |
| 6960 | !memcmp(network->ssid, |
| 6961 | priv->assoc_network->ssid, |
| 6962 | network->ssid_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6963 | queue_work(priv->workqueue, |
| 6964 | &priv->merge_networks); |
| 6965 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6966 | } |
| 6967 | |
| 6968 | return 0; |
| 6969 | } |
| 6970 | |
| 6971 | /* |
| 6972 | * This function set up the firmware to support QoS. It sends |
| 6973 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO |
| 6974 | */ |
| 6975 | static int ipw_qos_activate(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6976 | struct libipw_qos_data *qos_network_data) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6977 | { |
| 6978 | int err; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6979 | struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS]; |
| 6980 | struct libipw_qos_parameters *active_one = NULL; |
| 6981 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6982 | u32 burst_duration; |
| 6983 | int i; |
| 6984 | u8 type; |
| 6985 | |
| 6986 | type = ipw_qos_current_mode(priv); |
| 6987 | |
| 6988 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); |
| 6989 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); |
| 6990 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); |
| 6991 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); |
| 6992 | |
| 6993 | if (qos_network_data == NULL) { |
| 6994 | if (type == IEEE_B) { |
| 6995 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); |
| 6996 | active_one = &def_parameters_CCK; |
| 6997 | } else |
| 6998 | active_one = &def_parameters_OFDM; |
| 6999 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7000 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7001 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 7002 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7003 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 7004 | cpu_to_le16(burst_duration); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7005 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7006 | if (type == IEEE_B) { |
| 7007 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", |
| 7008 | type); |
| 7009 | if (priv->qos_data.qos_enable == 0) |
| 7010 | active_one = &def_parameters_CCK; |
| 7011 | else |
| 7012 | active_one = priv->qos_data.def_qos_parm_CCK; |
| 7013 | } else { |
| 7014 | if (priv->qos_data.qos_enable == 0) |
| 7015 | active_one = &def_parameters_OFDM; |
| 7016 | else |
| 7017 | active_one = priv->qos_data.def_qos_parm_OFDM; |
| 7018 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7019 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7020 | } else { |
| 7021 | unsigned long flags; |
| 7022 | int active; |
| 7023 | |
| 7024 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7025 | active_one = &(qos_network_data->parameters); |
| 7026 | qos_network_data->old_param_count = |
| 7027 | qos_network_data->param_count; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7028 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7029 | active = qos_network_data->supported; |
| 7030 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7031 | |
| 7032 | if (active == 0) { |
| 7033 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 7034 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
| 7035 | qos_parameters[QOS_PARAM_SET_ACTIVE]. |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 7036 | tx_op_limit[i] = cpu_to_le16(burst_duration); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7037 | } |
| 7038 | } |
| 7039 | |
| 7040 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7041 | err = ipw_send_qos_params_command(priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7042 | (struct libipw_qos_parameters *) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7043 | &(qos_parameters[0])); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7044 | if (err) |
| 7045 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); |
| 7046 | |
| 7047 | return err; |
| 7048 | } |
| 7049 | |
| 7050 | /* |
| 7051 | * send IPW_CMD_WME_INFO to the firmware |
| 7052 | */ |
| 7053 | static int ipw_qos_set_info_element(struct ipw_priv *priv) |
| 7054 | { |
| 7055 | int ret = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7056 | struct libipw_qos_information_element qos_info; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7057 | |
| 7058 | if (priv == NULL) |
| 7059 | return -1; |
| 7060 | |
| 7061 | qos_info.elementID = QOS_ELEMENT_ID; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7062 | qos_info.length = sizeof(struct libipw_qos_information_element) - 2; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7063 | |
| 7064 | qos_info.version = QOS_VERSION_1; |
| 7065 | qos_info.ac_info = 0; |
| 7066 | |
| 7067 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); |
| 7068 | qos_info.qui_type = QOS_OUI_TYPE; |
| 7069 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; |
| 7070 | |
| 7071 | ret = ipw_send_qos_info_command(priv, &qos_info); |
| 7072 | if (ret != 0) { |
| 7073 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); |
| 7074 | } |
| 7075 | return ret; |
| 7076 | } |
| 7077 | |
| 7078 | /* |
| 7079 | * Set the QoS parameter with the association request structure |
| 7080 | */ |
| 7081 | static int ipw_qos_association(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7082 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7083 | { |
| 7084 | int err = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7085 | struct libipw_qos_data *qos_data = NULL; |
| 7086 | struct libipw_qos_data ibss_data = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7087 | .supported = 1, |
| 7088 | .active = 1, |
| 7089 | }; |
| 7090 | |
| 7091 | switch (priv->ieee->iw_mode) { |
| 7092 | case IW_MODE_ADHOC: |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 7093 | BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7094 | |
| 7095 | qos_data = &ibss_data; |
| 7096 | break; |
| 7097 | |
| 7098 | case IW_MODE_INFRA: |
| 7099 | qos_data = &network->qos_data; |
| 7100 | break; |
| 7101 | |
| 7102 | default: |
| 7103 | BUG(); |
| 7104 | break; |
| 7105 | } |
| 7106 | |
| 7107 | err = ipw_qos_activate(priv, qos_data); |
| 7108 | if (err) { |
| 7109 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; |
| 7110 | return err; |
| 7111 | } |
| 7112 | |
| 7113 | if (priv->qos_data.qos_enable && qos_data->supported) { |
| 7114 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); |
| 7115 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; |
| 7116 | return ipw_qos_set_info_element(priv); |
| 7117 | } |
| 7118 | |
| 7119 | return 0; |
| 7120 | } |
| 7121 | |
| 7122 | /* |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 7123 | * handling the beaconing responses. if we get different QoS setting |
| 7124 | * off the network from the associated setting, adjust the QoS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7125 | * setting |
| 7126 | */ |
| 7127 | static int ipw_qos_association_resp(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7128 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7129 | { |
| 7130 | int ret = 0; |
| 7131 | unsigned long flags; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7132 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7133 | int set_qos_param = 0; |
| 7134 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7135 | if ((priv == NULL) || (network == NULL) || |
| 7136 | (priv->assoc_network == NULL)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7137 | return ret; |
| 7138 | |
| 7139 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7140 | return ret; |
| 7141 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7142 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7143 | return ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7144 | |
| 7145 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7146 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7147 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7148 | sizeof(struct libipw_qos_data)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7149 | priv->assoc_network->qos_data.active = 1; |
| 7150 | if ((network->qos_data.old_param_count != |
| 7151 | network->qos_data.param_count)) { |
| 7152 | set_qos_param = 1; |
| 7153 | network->qos_data.old_param_count = |
| 7154 | network->qos_data.param_count; |
| 7155 | } |
| 7156 | |
| 7157 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7158 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
| 7159 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7160 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7161 | else |
| 7162 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7163 | &def_parameters_OFDM, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7164 | priv->assoc_network->qos_data.active = 0; |
| 7165 | priv->assoc_network->qos_data.supported = 0; |
| 7166 | set_qos_param = 1; |
| 7167 | } |
| 7168 | |
| 7169 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7170 | |
| 7171 | if (set_qos_param == 1) |
| 7172 | schedule_work(&priv->qos_activate); |
| 7173 | |
| 7174 | return ret; |
| 7175 | } |
| 7176 | |
| 7177 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) |
| 7178 | { |
| 7179 | u32 ret = 0; |
| 7180 | |
| 7181 | if ((priv == NULL)) |
| 7182 | return 0; |
| 7183 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7184 | if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7185 | ret = priv->qos_data.burst_duration_CCK; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7186 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7187 | ret = priv->qos_data.burst_duration_OFDM; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7188 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7189 | return ret; |
| 7190 | } |
| 7191 | |
| 7192 | /* |
| 7193 | * Initialize the setting of QoS global |
| 7194 | */ |
| 7195 | static void ipw_qos_init(struct ipw_priv *priv, int enable, |
| 7196 | int burst_enable, u32 burst_duration_CCK, |
| 7197 | u32 burst_duration_OFDM) |
| 7198 | { |
| 7199 | priv->qos_data.qos_enable = enable; |
| 7200 | |
| 7201 | if (priv->qos_data.qos_enable) { |
| 7202 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; |
| 7203 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; |
| 7204 | IPW_DEBUG_QOS("QoS is enabled\n"); |
| 7205 | } else { |
| 7206 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; |
| 7207 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; |
| 7208 | IPW_DEBUG_QOS("QoS is not enabled\n"); |
| 7209 | } |
| 7210 | |
| 7211 | priv->qos_data.burst_enable = burst_enable; |
| 7212 | |
| 7213 | if (burst_enable) { |
| 7214 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; |
| 7215 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; |
| 7216 | } else { |
| 7217 | priv->qos_data.burst_duration_CCK = 0; |
| 7218 | priv->qos_data.burst_duration_OFDM = 0; |
| 7219 | } |
| 7220 | } |
| 7221 | |
| 7222 | /* |
| 7223 | * map the packet priority to the right TX Queue |
| 7224 | */ |
| 7225 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) |
| 7226 | { |
| 7227 | if (priority > 7 || !priv->qos_data.qos_enable) |
| 7228 | priority = 0; |
| 7229 | |
| 7230 | return from_priority_to_tx_queue[priority] - 1; |
| 7231 | } |
| 7232 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7233 | static int ipw_is_qos_active(struct net_device *dev, |
| 7234 | struct sk_buff *skb) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7235 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7236 | struct ipw_priv *priv = libipw_priv(dev); |
| 7237 | struct libipw_qos_data *qos_data = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7238 | int active, supported; |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7239 | u8 *daddr = skb->data + ETH_ALEN; |
| 7240 | int unicast = !is_multicast_ether_addr(daddr); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7241 | |
| 7242 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7243 | return 0; |
| 7244 | |
| 7245 | qos_data = &priv->assoc_network->qos_data; |
| 7246 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7247 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7248 | if (unicast == 0) |
| 7249 | qos_data->active = 0; |
| 7250 | else |
| 7251 | qos_data->active = qos_data->supported; |
| 7252 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7253 | active = qos_data->active; |
| 7254 | supported = qos_data->supported; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7255 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
| 7256 | "unicast %d\n", |
| 7257 | priv->qos_data.qos_enable, active, supported, unicast); |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7258 | if (active && priv->qos_data.qos_enable) |
| 7259 | return 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7260 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7261 | return 0; |
| 7262 | |
| 7263 | } |
| 7264 | /* |
| 7265 | * add QoS parameter to the TX command |
| 7266 | */ |
| 7267 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, |
| 7268 | u16 priority, |
| 7269 | struct tfd_data *tfd) |
| 7270 | { |
| 7271 | int tx_queue_id = 0; |
| 7272 | |
| 7273 | |
| 7274 | tx_queue_id = from_priority_to_tx_queue[priority] - 1; |
| 7275 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; |
| 7276 | |
| 7277 | if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) { |
| 7278 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 7279 | 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] | 7280 | } |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7281 | return 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7282 | } |
| 7283 | |
| 7284 | /* |
| 7285 | * background support to run QoS activate functionality |
| 7286 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7287 | static void ipw_bg_qos_activate(struct work_struct *work) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7288 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7289 | struct ipw_priv *priv = |
| 7290 | container_of(work, struct ipw_priv, qos_activate); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7291 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7292 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7293 | |
| 7294 | if (priv->status & STATUS_ASSOCIATED) |
| 7295 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); |
| 7296 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7297 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7298 | } |
| 7299 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7300 | static int ipw_handle_probe_response(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7301 | struct libipw_probe_response *resp, |
| 7302 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7303 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7304 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7305 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7306 | (network == priv->assoc_network)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7307 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7308 | ipw_qos_handle_probe_response(priv, active_network, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7309 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7310 | return 0; |
| 7311 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7312 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7313 | static int ipw_handle_beacon(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7314 | struct libipw_beacon *resp, |
| 7315 | struct libipw_network *network) |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7316 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7317 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7318 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7319 | (network == priv->assoc_network)); |
| 7320 | |
| 7321 | ipw_qos_handle_probe_response(priv, active_network, network); |
| 7322 | |
| 7323 | return 0; |
| 7324 | } |
| 7325 | |
| 7326 | static int ipw_handle_assoc_response(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7327 | struct libipw_assoc_response *resp, |
| 7328 | struct libipw_network *network) |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7329 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7330 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7331 | ipw_qos_association_resp(priv, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7332 | return 0; |
| 7333 | } |
| 7334 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7335 | 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] | 7336 | *qos_param) |
| 7337 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7338 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
| 7339 | sizeof(*qos_param) * 3, qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7340 | } |
| 7341 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7342 | 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] | 7343 | *qos_param) |
| 7344 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7345 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
| 7346 | qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7347 | } |
| 7348 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7349 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7350 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7351 | static int ipw_associate_network(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7352 | struct libipw_network *network, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7353 | struct ipw_supported_rates *rates, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7354 | { |
| 7355 | int err; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7356 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7357 | |
| 7358 | if (priv->config & CFG_FIXED_RATE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7359 | ipw_set_fixed_rate(priv, network->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7360 | |
| 7361 | if (!(priv->config & CFG_STATIC_ESSID)) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7362 | priv->essid_len = min(network->ssid_len, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7363 | (u8) IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7364 | memcpy(priv->essid, network->ssid, priv->essid_len); |
| 7365 | } |
| 7366 | |
| 7367 | network->last_associate = jiffies; |
| 7368 | |
| 7369 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); |
| 7370 | priv->assoc_request.channel = network->channel; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7371 | priv->assoc_request.auth_key = 0; |
| 7372 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7373 | if ((priv->capability & CAP_PRIVACY_ON) && |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7374 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7375 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7376 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
| 7377 | |
Zhu Yi | 1ba61e0 | 2006-02-15 13:00:55 +0800 | [diff] [blame] | 7378 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7379 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7380 | |
| 7381 | } else if ((priv->capability & CAP_PRIVACY_ON) && |
| 7382 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) |
| 7383 | priv->assoc_request.auth_type = AUTH_LEAP; |
| 7384 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7385 | priv->assoc_request.auth_type = AUTH_OPEN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7386 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7387 | if (priv->ieee->wpa_ie_len) { |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7388 | priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7389 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
| 7390 | priv->ieee->wpa_ie_len); |
| 7391 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7392 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7393 | /* |
| 7394 | * It is valid for our ieee device to support multiple modes, but |
| 7395 | * 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] | 7396 | * just one mode. |
| 7397 | */ |
| 7398 | if (network->mode & priv->ieee->mode & IEEE_A) |
| 7399 | priv->assoc_request.ieee_mode = IPW_A_MODE; |
| 7400 | else if (network->mode & priv->ieee->mode & IEEE_G) |
| 7401 | priv->assoc_request.ieee_mode = IPW_G_MODE; |
| 7402 | else if (network->mode & priv->ieee->mode & IEEE_B) |
| 7403 | priv->assoc_request.ieee_mode = IPW_B_MODE; |
| 7404 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7405 | priv->assoc_request.capability = cpu_to_le16(network->capability); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7406 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7407 | && !(priv->config & CFG_PREAMBLE_LONG)) { |
| 7408 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; |
| 7409 | } else { |
| 7410 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; |
| 7411 | |
| 7412 | /* Clear the short preamble if we won't be supporting it */ |
| 7413 | priv->assoc_request.capability &= |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7414 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7415 | } |
| 7416 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7417 | /* Clear capability bits that aren't used in Ad Hoc */ |
| 7418 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7419 | priv->assoc_request.capability &= |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7420 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7421 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7422 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7423 | "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] | 7424 | roaming ? "Rea" : "A", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7425 | print_ssid(ssid, priv->essid, priv->essid_len), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7426 | network->channel, |
| 7427 | ipw_modes[priv->assoc_request.ieee_mode], |
| 7428 | rates->num_rates, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7429 | (priv->assoc_request.preamble_length == |
| 7430 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", |
| 7431 | network->capability & |
| 7432 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7433 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7434 | priv->capability & CAP_PRIVACY_ON ? |
| 7435 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7436 | "(open)") : "", |
| 7437 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7438 | priv->capability & CAP_PRIVACY_ON ? |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7439 | '1' + priv->ieee->sec.active_key : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7440 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7441 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7442 | priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7443 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7444 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7445 | priv->assoc_request.assoc_type = HC_IBSS_START; |
| 7446 | priv->assoc_request.assoc_tsf_msw = 0; |
| 7447 | priv->assoc_request.assoc_tsf_lsw = 0; |
| 7448 | } else { |
| 7449 | if (unlikely(roaming)) |
| 7450 | priv->assoc_request.assoc_type = HC_REASSOCIATE; |
| 7451 | else |
| 7452 | priv->assoc_request.assoc_type = HC_ASSOCIATE; |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7453 | priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]); |
| 7454 | 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] | 7455 | } |
| 7456 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7457 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7458 | |
| 7459 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7460 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7461 | priv->assoc_request.atim_window = cpu_to_le16(network->atim_window); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7462 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7463 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7464 | priv->assoc_request.atim_window = 0; |
| 7465 | } |
| 7466 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7467 | priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7468 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7469 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 7470 | if (err) { |
| 7471 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); |
| 7472 | return err; |
| 7473 | } |
| 7474 | |
| 7475 | rates->ieee_mode = priv->assoc_request.ieee_mode; |
| 7476 | rates->purpose = IPW_RATE_CONNECT; |
| 7477 | ipw_send_supported_rates(priv, rates); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7478 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7479 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
| 7480 | priv->sys_config.dot11g_auto_detection = 1; |
| 7481 | else |
| 7482 | priv->sys_config.dot11g_auto_detection = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7483 | |
| 7484 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7485 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 7486 | else |
| 7487 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 7488 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7489 | err = ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7490 | if (err) { |
| 7491 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); |
| 7492 | return err; |
| 7493 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7494 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7495 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7496 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7497 | if (err) { |
| 7498 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7499 | return err; |
| 7500 | } |
| 7501 | |
| 7502 | /* |
| 7503 | * If preemption is enabled, it is possible for the association |
| 7504 | * to complete before we return from ipw_send_associate. Therefore |
| 7505 | * we have to be sure and update our priviate data first. |
| 7506 | */ |
| 7507 | priv->channel = network->channel; |
| 7508 | memcpy(priv->bssid, network->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7509 | priv->status |= STATUS_ASSOCIATING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7510 | priv->status &= ~STATUS_SECURITY_UPDATED; |
| 7511 | |
| 7512 | priv->assoc_network = network; |
| 7513 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7514 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7515 | ipw_qos_association(priv, network); |
| 7516 | #endif |
| 7517 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7518 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 7519 | if (err) { |
| 7520 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7521 | return err; |
| 7522 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7523 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7524 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7525 | print_ssid(ssid, priv->essid, priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7526 | priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7527 | |
| 7528 | return 0; |
| 7529 | } |
| 7530 | |
| 7531 | static void ipw_roam(void *data) |
| 7532 | { |
| 7533 | struct ipw_priv *priv = data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7534 | struct libipw_network *network = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7535 | struct ipw_network_match match = { |
| 7536 | .network = priv->assoc_network |
| 7537 | }; |
| 7538 | |
| 7539 | /* The roaming process is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7540 | * |
| 7541 | * 1. Missed beacon threshold triggers the roaming process by |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7542 | * setting the status ROAM bit and requesting a scan. |
| 7543 | * 2. When the scan completes, it schedules the ROAM work |
| 7544 | * 3. The ROAM work looks at all of the known networks for one that |
| 7545 | * is a better network than the currently associated. If none |
| 7546 | * found, the ROAM process is over (ROAM bit cleared) |
| 7547 | * 4. If a better network is found, a disassociation request is |
| 7548 | * sent. |
| 7549 | * 5. When the disassociation completes, the roam work is again |
| 7550 | * scheduled. The second time through, the driver is no longer |
| 7551 | * associated, and the newly selected network is sent an |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7552 | * association request. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7553 | * 6. At this point ,the roaming process is complete and the ROAM |
| 7554 | * status bit is cleared. |
| 7555 | */ |
| 7556 | |
| 7557 | /* If we are no longer associated, and the roaming bit is no longer |
| 7558 | * set, then we are not actively roaming, so just return */ |
| 7559 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) |
| 7560 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7561 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7562 | if (priv->status & STATUS_ASSOCIATED) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7563 | /* First pass through ROAM process -- look for a better |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7564 | * network */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7565 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7566 | u8 rssi = priv->assoc_network->stats.rssi; |
| 7567 | priv->assoc_network->stats.rssi = -128; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7568 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7569 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 7570 | if (network != priv->assoc_network) |
| 7571 | ipw_best_network(priv, &match, network, 1); |
| 7572 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7573 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7574 | priv->assoc_network->stats.rssi = rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7575 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7576 | if (match.network == priv->assoc_network) { |
| 7577 | IPW_DEBUG_ASSOC("No better APs in this network to " |
| 7578 | "roam to.\n"); |
| 7579 | priv->status &= ~STATUS_ROAMING; |
| 7580 | ipw_debug_config(priv); |
| 7581 | return; |
| 7582 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7583 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7584 | ipw_send_disassociate(priv, 1); |
| 7585 | priv->assoc_network = match.network; |
| 7586 | |
| 7587 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7588 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7589 | |
| 7590 | /* Second pass through ROAM process -- request association */ |
| 7591 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); |
| 7592 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); |
| 7593 | priv->status &= ~STATUS_ROAMING; |
| 7594 | } |
| 7595 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7596 | static void ipw_bg_roam(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7597 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7598 | struct ipw_priv *priv = |
| 7599 | container_of(work, struct ipw_priv, roam); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7600 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7601 | ipw_roam(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7602 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7603 | } |
| 7604 | |
| 7605 | static int ipw_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7606 | { |
| 7607 | struct ipw_priv *priv = data; |
| 7608 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7609 | struct libipw_network *network = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7610 | struct ipw_network_match match = { |
| 7611 | .network = NULL |
| 7612 | }; |
| 7613 | struct ipw_supported_rates *rates; |
| 7614 | struct list_head *element; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7615 | unsigned long flags; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7616 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7617 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7618 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 7619 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); |
| 7620 | return 0; |
| 7621 | } |
| 7622 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7623 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7624 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
| 7625 | "progress)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7626 | return 0; |
| 7627 | } |
| 7628 | |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 7629 | if (priv->status & STATUS_DISASSOCIATING) { |
| 7630 | IPW_DEBUG_ASSOC("Not attempting association (in " |
| 7631 | "disassociating)\n "); |
| 7632 | queue_work(priv->workqueue, &priv->associate); |
| 7633 | return 0; |
| 7634 | } |
| 7635 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7636 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7637 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
| 7638 | "initialized)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7639 | return 0; |
| 7640 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7641 | |
| 7642 | if (!(priv->config & CFG_ASSOCIATE) && |
Alexey Fisher | 3e4127f | 2008-11-06 09:51:16 +0100 | [diff] [blame] | 7643 | !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7644 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7645 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7646 | } |
| 7647 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7648 | /* Protect our use of the network_list */ |
| 7649 | spin_lock_irqsave(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7650 | list_for_each_entry(network, &priv->ieee->network_list, list) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7651 | ipw_best_network(priv, &match, network, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7652 | |
| 7653 | network = match.network; |
| 7654 | rates = &match.rates; |
| 7655 | |
| 7656 | if (network == NULL && |
| 7657 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7658 | priv->config & CFG_ADHOC_CREATE && |
| 7659 | priv->config & CFG_STATIC_ESSID && |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7660 | priv->config & CFG_STATIC_CHANNEL) { |
| 7661 | /* Use oldest network if the free list is empty */ |
| 7662 | if (list_empty(&priv->ieee->network_free_list)) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7663 | struct libipw_network *oldest = NULL; |
| 7664 | struct libipw_network *target; |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7665 | |
| 7666 | list_for_each_entry(target, &priv->ieee->network_list, list) { |
| 7667 | if ((oldest == NULL) || |
| 7668 | (target->last_scanned < oldest->last_scanned)) |
| 7669 | oldest = target; |
| 7670 | } |
| 7671 | |
| 7672 | /* If there are no more slots, expire the oldest */ |
| 7673 | list_del(&oldest->list); |
| 7674 | target = oldest; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7675 | IPW_DEBUG_ASSOC("Expired '%s' (%pM) from " |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7676 | "network list.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7677 | print_ssid(ssid, target->ssid, |
| 7678 | target->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7679 | target->bssid); |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7680 | list_add_tail(&target->list, |
| 7681 | &priv->ieee->network_free_list); |
| 7682 | } |
| 7683 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7684 | element = priv->ieee->network_free_list.next; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7685 | network = list_entry(element, struct libipw_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7686 | ipw_adhoc_create(priv, network); |
| 7687 | rates = &priv->rates; |
| 7688 | list_del(element); |
| 7689 | list_add_tail(&network->list, &priv->ieee->network_list); |
| 7690 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7691 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7692 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7693 | /* If we reached the end of the list, then we don't have any valid |
| 7694 | * matching APs */ |
| 7695 | if (!network) { |
| 7696 | ipw_debug_config(priv); |
| 7697 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7698 | if (!(priv->status & STATUS_SCANNING)) { |
| 7699 | if (!(priv->config & CFG_SPEED_SCAN)) |
| 7700 | queue_delayed_work(priv->workqueue, |
| 7701 | &priv->request_scan, |
| 7702 | SCAN_INTERVAL); |
| 7703 | else |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7704 | queue_delayed_work(priv->workqueue, |
| 7705 | &priv->request_scan, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7706 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7707 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7708 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7709 | } |
| 7710 | |
| 7711 | ipw_associate_network(priv, network, rates, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7712 | |
| 7713 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7714 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7715 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7716 | static void ipw_bg_associate(struct work_struct *work) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7717 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7718 | struct ipw_priv *priv = |
| 7719 | container_of(work, struct ipw_priv, associate); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7720 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7721 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7722 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7723 | } |
| 7724 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7725 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
| 7726 | struct sk_buff *skb) |
| 7727 | { |
| 7728 | struct ieee80211_hdr *hdr; |
| 7729 | u16 fc; |
| 7730 | |
| 7731 | hdr = (struct ieee80211_hdr *)skb->data; |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 7732 | fc = le16_to_cpu(hdr->frame_control); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7733 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 7734 | return; |
| 7735 | |
| 7736 | fc &= ~IEEE80211_FCTL_PROTECTED; |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 7737 | hdr->frame_control = cpu_to_le16(fc); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7738 | switch (priv->ieee->sec.level) { |
| 7739 | case SEC_LEVEL_3: |
| 7740 | /* Remove CCMP HDR */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7741 | memmove(skb->data + LIBIPW_3ADDR_LEN, |
| 7742 | skb->data + LIBIPW_3ADDR_LEN + 8, |
| 7743 | skb->len - LIBIPW_3ADDR_LEN - 8); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7744 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7745 | break; |
| 7746 | case SEC_LEVEL_2: |
| 7747 | break; |
| 7748 | case SEC_LEVEL_1: |
| 7749 | /* Remove IV */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7750 | memmove(skb->data + LIBIPW_3ADDR_LEN, |
| 7751 | skb->data + LIBIPW_3ADDR_LEN + 4, |
| 7752 | skb->len - LIBIPW_3ADDR_LEN - 4); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7753 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7754 | break; |
| 7755 | case SEC_LEVEL_0: |
| 7756 | break; |
| 7757 | default: |
| 7758 | printk(KERN_ERR "Unknow security level %d\n", |
| 7759 | priv->ieee->sec.level); |
| 7760 | break; |
| 7761 | } |
| 7762 | } |
| 7763 | |
| 7764 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
| 7765 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7766 | struct libipw_rx_stats *stats) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7767 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7768 | struct net_device *dev = priv->net_dev; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7769 | struct libipw_hdr_4addr *hdr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7770 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7771 | |
| 7772 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7773 | dev->trans_start = jiffies; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7774 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7775 | /* We only process data packets if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7776 | * interface is open */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7777 | 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] | 7778 | skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7779 | dev->stats.rx_errors++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7780 | priv->wstats.discard.misc++; |
| 7781 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7782 | return; |
| 7783 | } else if (unlikely(!netif_running(priv->net_dev))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7784 | dev->stats.rx_dropped++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7785 | priv->wstats.discard.misc++; |
| 7786 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7787 | return; |
| 7788 | } |
| 7789 | |
| 7790 | /* Advance skb->data to the start of the actual payload */ |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 7791 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7792 | |
| 7793 | /* Set the size of the skb to the size of the frame */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7794 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7795 | |
| 7796 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7797 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7798 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7799 | hdr = (struct libipw_hdr_4addr *)rxb->skb->data; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7800 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7801 | (is_multicast_ether_addr(hdr->addr1) ? |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7802 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7803 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
| 7804 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7805 | if (!libipw_rx(priv->ieee, rxb->skb, stats)) |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7806 | dev->stats.rx_errors++; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7807 | else { /* libipw_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7808 | rxb->skb = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7809 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7810 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7811 | } |
| 7812 | |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 7813 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7814 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, |
| 7815 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7816 | struct libipw_rx_stats *stats) |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7817 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7818 | struct net_device *dev = priv->net_dev; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7819 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7820 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7821 | |
| 7822 | /* initial pull of some data */ |
| 7823 | u16 received_channel = frame->received_channel; |
| 7824 | u8 antennaAndPhy = frame->antennaAndPhy; |
| 7825 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ |
| 7826 | u16 pktrate = frame->rate; |
| 7827 | |
| 7828 | /* Magic struct that slots into the radiotap header -- no reason |
| 7829 | * to build this manually element by element, we can write it much |
| 7830 | * more efficiently than we can parse it. ORDER MATTERS HERE */ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7831 | struct ipw_rt_hdr *ipw_rt; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7832 | |
| 7833 | short len = le16_to_cpu(pkt->u.frame.length); |
| 7834 | |
| 7835 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7836 | dev->trans_start = jiffies; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7837 | |
| 7838 | /* We only process data packets if the |
| 7839 | * interface is open */ |
| 7840 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
| 7841 | skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7842 | dev->stats.rx_errors++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7843 | priv->wstats.discard.misc++; |
| 7844 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7845 | return; |
| 7846 | } else if (unlikely(!netif_running(priv->net_dev))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7847 | dev->stats.rx_dropped++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7848 | priv->wstats.discard.misc++; |
| 7849 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7850 | return; |
| 7851 | } |
| 7852 | |
| 7853 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7854 | * that now */ |
| 7855 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7856 | /* FIXME: Should alloc bigger skb instead */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7857 | dev->stats.rx_dropped++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7858 | priv->wstats.discard.misc++; |
| 7859 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7860 | return; |
| 7861 | } |
| 7862 | |
| 7863 | /* copy the frame itself */ |
| 7864 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), |
| 7865 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); |
| 7866 | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7867 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; |
| 7868 | |
| 7869 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7870 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 7871 | 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] | 7872 | |
| 7873 | /* Big bitfield of all the fields we provide in radiotap */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 7874 | ipw_rt->rt_hdr.it_present = cpu_to_le32( |
| 7875 | (1 << IEEE80211_RADIOTAP_TSFT) | |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 7876 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7877 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7878 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7879 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7880 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7881 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7882 | |
| 7883 | /* Zero the flags, we'll add to them as we go */ |
| 7884 | ipw_rt->rt_flags = 0; |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 7885 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | |
| 7886 | frame->parent_tsf[2] << 16 | |
| 7887 | frame->parent_tsf[1] << 8 | |
| 7888 | frame->parent_tsf[0]); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7889 | |
| 7890 | /* Convert signal to DBM */ |
| 7891 | ipw_rt->rt_dbmsignal = antsignal; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 7892 | ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7893 | |
| 7894 | /* Convert the channel data and set the flags */ |
| 7895 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); |
| 7896 | if (received_channel > 14) { /* 802.11a */ |
| 7897 | ipw_rt->rt_chbitmask = |
| 7898 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7899 | } else if (antennaAndPhy & 32) { /* 802.11b */ |
| 7900 | ipw_rt->rt_chbitmask = |
| 7901 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7902 | } else { /* 802.11g */ |
| 7903 | ipw_rt->rt_chbitmask = |
Al Viro | 472caf8 | 2007-12-27 01:50:54 -0500 | [diff] [blame] | 7904 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7905 | } |
| 7906 | |
| 7907 | /* set the rate in multiples of 500k/s */ |
| 7908 | switch (pktrate) { |
| 7909 | case IPW_TX_RATE_1MB: |
| 7910 | ipw_rt->rt_rate = 2; |
| 7911 | break; |
| 7912 | case IPW_TX_RATE_2MB: |
| 7913 | ipw_rt->rt_rate = 4; |
| 7914 | break; |
| 7915 | case IPW_TX_RATE_5MB: |
| 7916 | ipw_rt->rt_rate = 10; |
| 7917 | break; |
| 7918 | case IPW_TX_RATE_6MB: |
| 7919 | ipw_rt->rt_rate = 12; |
| 7920 | break; |
| 7921 | case IPW_TX_RATE_9MB: |
| 7922 | ipw_rt->rt_rate = 18; |
| 7923 | break; |
| 7924 | case IPW_TX_RATE_11MB: |
| 7925 | ipw_rt->rt_rate = 22; |
| 7926 | break; |
| 7927 | case IPW_TX_RATE_12MB: |
| 7928 | ipw_rt->rt_rate = 24; |
| 7929 | break; |
| 7930 | case IPW_TX_RATE_18MB: |
| 7931 | ipw_rt->rt_rate = 36; |
| 7932 | break; |
| 7933 | case IPW_TX_RATE_24MB: |
| 7934 | ipw_rt->rt_rate = 48; |
| 7935 | break; |
| 7936 | case IPW_TX_RATE_36MB: |
| 7937 | ipw_rt->rt_rate = 72; |
| 7938 | break; |
| 7939 | case IPW_TX_RATE_48MB: |
| 7940 | ipw_rt->rt_rate = 96; |
| 7941 | break; |
| 7942 | case IPW_TX_RATE_54MB: |
| 7943 | ipw_rt->rt_rate = 108; |
| 7944 | break; |
| 7945 | default: |
| 7946 | ipw_rt->rt_rate = 0; |
| 7947 | break; |
| 7948 | } |
| 7949 | |
| 7950 | /* antenna number */ |
| 7951 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ |
| 7952 | |
| 7953 | /* set the preamble flag if we have it */ |
| 7954 | if ((antennaAndPhy & 64)) |
| 7955 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7956 | |
| 7957 | /* Set the size of the skb to the size of the frame */ |
| 7958 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7959 | |
| 7960 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7961 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7962 | if (!libipw_rx(priv->ieee, rxb->skb, stats)) |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7963 | dev->stats.rx_errors++; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7964 | else { /* libipw_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7965 | rxb->skb = NULL; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7966 | /* no LED during capture */ |
| 7967 | } |
| 7968 | } |
| 7969 | #endif |
| 7970 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7971 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7972 | #define libipw_is_probe_response(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7973 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \ |
| 7974 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP ) |
| 7975 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7976 | #define libipw_is_management(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7977 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 7978 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7979 | #define libipw_is_control(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7980 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) |
| 7981 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7982 | #define libipw_is_data(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7983 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) |
| 7984 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7985 | #define libipw_is_assoc_request(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7986 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ) |
| 7987 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7988 | #define libipw_is_reassoc_request(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7989 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
| 7990 | |
| 7991 | static void ipw_handle_promiscuous_rx(struct ipw_priv *priv, |
| 7992 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7993 | struct libipw_rx_stats *stats) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7994 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7995 | struct net_device *dev = priv->prom_net_dev; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7996 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7997 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7998 | struct ipw_rt_hdr *ipw_rt; |
| 7999 | |
| 8000 | /* First cache any information we need before we overwrite |
| 8001 | * the information provided in the skb from the hardware */ |
| 8002 | struct ieee80211_hdr *hdr; |
| 8003 | u16 channel = frame->received_channel; |
| 8004 | u8 phy_flags = frame->antennaAndPhy; |
| 8005 | s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8006 | s8 noise = (s8) le16_to_cpu(frame->noise); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8007 | u8 rate = frame->rate; |
| 8008 | short len = le16_to_cpu(pkt->u.frame.length); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8009 | struct sk_buff *skb; |
| 8010 | int hdr_only = 0; |
| 8011 | u16 filter = priv->prom_priv->filter; |
| 8012 | |
| 8013 | /* If the filter is set to not include Rx frames then return */ |
| 8014 | if (filter & IPW_PROM_NO_RX) |
| 8015 | return; |
| 8016 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8017 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8018 | dev->trans_start = jiffies; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8019 | |
| 8020 | if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8021 | dev->stats.rx_errors++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8022 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 8023 | return; |
| 8024 | } |
| 8025 | |
| 8026 | /* We only process data packets if the interface is open */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8027 | if (unlikely(!netif_running(dev))) { |
| 8028 | dev->stats.rx_dropped++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8029 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 8030 | return; |
| 8031 | } |
| 8032 | |
| 8033 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 8034 | * that now */ |
| 8035 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 8036 | /* FIXME: Should alloc bigger skb instead */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8037 | dev->stats.rx_dropped++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8038 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 8039 | return; |
| 8040 | } |
| 8041 | |
| 8042 | hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8043 | if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8044 | if (filter & IPW_PROM_NO_MGMT) |
| 8045 | return; |
| 8046 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 8047 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8048 | } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8049 | if (filter & IPW_PROM_NO_CTL) |
| 8050 | return; |
| 8051 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 8052 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8053 | } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8054 | if (filter & IPW_PROM_NO_DATA) |
| 8055 | return; |
| 8056 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 8057 | hdr_only = 1; |
| 8058 | } |
| 8059 | |
| 8060 | /* Copy the SKB since this is for the promiscuous side */ |
| 8061 | skb = skb_copy(rxb->skb, GFP_ATOMIC); |
| 8062 | if (skb == NULL) { |
| 8063 | IPW_ERROR("skb_clone failed for promiscuous copy.\n"); |
| 8064 | return; |
| 8065 | } |
| 8066 | |
| 8067 | /* copy the frame data to write after where the radiotap header goes */ |
| 8068 | ipw_rt = (void *)skb->data; |
| 8069 | |
| 8070 | if (hdr_only) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8071 | len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8072 | |
| 8073 | memcpy(ipw_rt->payload, hdr, len); |
| 8074 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8075 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 8076 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8077 | 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] | 8078 | |
| 8079 | /* Set the size of the skb to the size of the frame */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8080 | skb_put(skb, sizeof(*ipw_rt) + len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8081 | |
| 8082 | /* Big bitfield of all the fields we provide in radiotap */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8083 | ipw_rt->rt_hdr.it_present = cpu_to_le32( |
| 8084 | (1 << IEEE80211_RADIOTAP_TSFT) | |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 8085 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8086 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 8087 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 8088 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 8089 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 8090 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 8091 | |
| 8092 | /* Zero the flags, we'll add to them as we go */ |
| 8093 | ipw_rt->rt_flags = 0; |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 8094 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | |
| 8095 | frame->parent_tsf[2] << 16 | |
| 8096 | frame->parent_tsf[1] << 8 | |
| 8097 | frame->parent_tsf[0]); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8098 | |
| 8099 | /* Convert to DBM */ |
| 8100 | ipw_rt->rt_dbmsignal = signal; |
| 8101 | ipw_rt->rt_dbmnoise = noise; |
| 8102 | |
| 8103 | /* Convert the channel data and set the flags */ |
| 8104 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel)); |
| 8105 | if (channel > 14) { /* 802.11a */ |
| 8106 | ipw_rt->rt_chbitmask = |
| 8107 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 8108 | } else if (phy_flags & (1 << 5)) { /* 802.11b */ |
| 8109 | ipw_rt->rt_chbitmask = |
| 8110 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 8111 | } else { /* 802.11g */ |
| 8112 | ipw_rt->rt_chbitmask = |
Al Viro | 472caf8 | 2007-12-27 01:50:54 -0500 | [diff] [blame] | 8113 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8114 | } |
| 8115 | |
| 8116 | /* set the rate in multiples of 500k/s */ |
| 8117 | switch (rate) { |
| 8118 | case IPW_TX_RATE_1MB: |
| 8119 | ipw_rt->rt_rate = 2; |
| 8120 | break; |
| 8121 | case IPW_TX_RATE_2MB: |
| 8122 | ipw_rt->rt_rate = 4; |
| 8123 | break; |
| 8124 | case IPW_TX_RATE_5MB: |
| 8125 | ipw_rt->rt_rate = 10; |
| 8126 | break; |
| 8127 | case IPW_TX_RATE_6MB: |
| 8128 | ipw_rt->rt_rate = 12; |
| 8129 | break; |
| 8130 | case IPW_TX_RATE_9MB: |
| 8131 | ipw_rt->rt_rate = 18; |
| 8132 | break; |
| 8133 | case IPW_TX_RATE_11MB: |
| 8134 | ipw_rt->rt_rate = 22; |
| 8135 | break; |
| 8136 | case IPW_TX_RATE_12MB: |
| 8137 | ipw_rt->rt_rate = 24; |
| 8138 | break; |
| 8139 | case IPW_TX_RATE_18MB: |
| 8140 | ipw_rt->rt_rate = 36; |
| 8141 | break; |
| 8142 | case IPW_TX_RATE_24MB: |
| 8143 | ipw_rt->rt_rate = 48; |
| 8144 | break; |
| 8145 | case IPW_TX_RATE_36MB: |
| 8146 | ipw_rt->rt_rate = 72; |
| 8147 | break; |
| 8148 | case IPW_TX_RATE_48MB: |
| 8149 | ipw_rt->rt_rate = 96; |
| 8150 | break; |
| 8151 | case IPW_TX_RATE_54MB: |
| 8152 | ipw_rt->rt_rate = 108; |
| 8153 | break; |
| 8154 | default: |
| 8155 | ipw_rt->rt_rate = 0; |
| 8156 | break; |
| 8157 | } |
| 8158 | |
| 8159 | /* antenna number */ |
| 8160 | ipw_rt->rt_antenna = (phy_flags & 3); |
| 8161 | |
| 8162 | /* set the preamble flag if we have it */ |
| 8163 | if (phy_flags & (1 << 6)) |
| 8164 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 8165 | |
| 8166 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len); |
| 8167 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8168 | if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8169 | dev->stats.rx_errors++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8170 | dev_kfree_skb_any(skb); |
| 8171 | } |
| 8172 | } |
| 8173 | #endif |
| 8174 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 8175 | static int is_network_packet(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8176 | struct libipw_hdr_4addr *header) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8177 | { |
| 8178 | /* Filter incoming packets to determine if they are targetted toward |
| 8179 | * this network, discarding packets coming from ourselves */ |
| 8180 | switch (priv->ieee->iw_mode) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8181 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8182 | /* packets from our adapter are dropped (echo) */ |
| 8183 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) |
| 8184 | return 0; |
| 8185 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8186 | /* {broad,multi}cast packets to our BSSID go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 8187 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8188 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8189 | |
| 8190 | /* packets to our adapter go through */ |
| 8191 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 8192 | ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8193 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8194 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8195 | /* packets from our adapter are dropped (echo) */ |
| 8196 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) |
| 8197 | return 0; |
| 8198 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8199 | /* {broad,multi}cast packets to our BSS go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 8200 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8201 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
| 8202 | |
| 8203 | /* packets to our adapter go through */ |
| 8204 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 8205 | ETH_ALEN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8206 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8207 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8208 | return 1; |
| 8209 | } |
| 8210 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8211 | #define IPW_PACKET_RETRY_TIME HZ |
| 8212 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 8213 | static int is_duplicate_packet(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8214 | struct libipw_hdr_4addr *header) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8215 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8216 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 8217 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 8218 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 8219 | u16 *last_seq, *last_frag; |
| 8220 | unsigned long *last_time; |
| 8221 | |
| 8222 | switch (priv->ieee->iw_mode) { |
| 8223 | case IW_MODE_ADHOC: |
| 8224 | { |
| 8225 | struct list_head *p; |
| 8226 | struct ipw_ibss_seq *entry = NULL; |
| 8227 | u8 *mac = header->addr2; |
| 8228 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; |
| 8229 | |
| 8230 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 8231 | entry = |
| 8232 | list_entry(p, struct ipw_ibss_seq, list); |
| 8233 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 8234 | break; |
| 8235 | } |
| 8236 | if (p == &priv->ibss_mac_hash[index]) { |
| 8237 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 8238 | if (!entry) { |
| 8239 | IPW_ERROR |
| 8240 | ("Cannot malloc new mac entry\n"); |
| 8241 | return 0; |
| 8242 | } |
| 8243 | memcpy(entry->mac, mac, ETH_ALEN); |
| 8244 | entry->seq_num = seq; |
| 8245 | entry->frag_num = frag; |
| 8246 | entry->packet_time = jiffies; |
| 8247 | list_add(&entry->list, |
| 8248 | &priv->ibss_mac_hash[index]); |
| 8249 | return 0; |
| 8250 | } |
| 8251 | last_seq = &entry->seq_num; |
| 8252 | last_frag = &entry->frag_num; |
| 8253 | last_time = &entry->packet_time; |
| 8254 | break; |
| 8255 | } |
| 8256 | case IW_MODE_INFRA: |
| 8257 | last_seq = &priv->last_seq_num; |
| 8258 | last_frag = &priv->last_frag_num; |
| 8259 | last_time = &priv->last_packet_time; |
| 8260 | break; |
| 8261 | default: |
| 8262 | return 0; |
| 8263 | } |
| 8264 | if ((*last_seq == seq) && |
| 8265 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { |
| 8266 | if (*last_frag == frag) |
| 8267 | goto drop; |
| 8268 | if (*last_frag + 1 != frag) |
| 8269 | /* out-of-order fragment */ |
| 8270 | goto drop; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8271 | } else |
| 8272 | *last_seq = seq; |
| 8273 | |
Zhu Yi | f57ce7c | 2005-07-13 12:22:15 -0500 | [diff] [blame] | 8274 | *last_frag = frag; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8275 | *last_time = jiffies; |
| 8276 | return 0; |
| 8277 | |
| 8278 | drop: |
Zhu Yi | 87b016c | 2005-08-05 17:17:35 +0800 | [diff] [blame] | 8279 | /* Comment this line now since we observed the card receives |
| 8280 | * duplicate packets but the FCTL_RETRY bit is not set in the |
| 8281 | * IBSS mode with fragmentation enabled. |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 8282 | BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8283 | return 1; |
| 8284 | } |
| 8285 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8286 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
| 8287 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8288 | struct libipw_rx_stats *stats) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8289 | { |
| 8290 | struct sk_buff *skb = rxb->skb; |
| 8291 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8292 | struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8293 | (skb->data + IPW_RX_FRAME_SIZE); |
| 8294 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8295 | libipw_rx_mgt(priv->ieee, header, stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8296 | |
| 8297 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 8298 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8299 | IEEE80211_STYPE_PROBE_RESP) || |
| 8300 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8301 | IEEE80211_STYPE_BEACON))) { |
| 8302 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) |
| 8303 | ipw_add_station(priv, header->addr2); |
| 8304 | } |
| 8305 | |
| 8306 | if (priv->config & CFG_NET_STATS) { |
| 8307 | IPW_DEBUG_HC("sending stat packet\n"); |
| 8308 | |
| 8309 | /* Set the size of the skb to the size of the full |
| 8310 | * ipw header and 802.11 frame */ |
| 8311 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + |
| 8312 | IPW_RX_FRAME_SIZE); |
| 8313 | |
| 8314 | /* Advance past the ipw packet header to the 802.11 frame */ |
| 8315 | skb_pull(skb, IPW_RX_FRAME_SIZE); |
| 8316 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8317 | /* Push the libipw_rx_stats before the 802.11 frame */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8318 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
| 8319 | |
| 8320 | skb->dev = priv->ieee->dev; |
| 8321 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8322 | /* Point raw at the libipw_stats */ |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 8323 | skb_reset_mac_header(skb); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8324 | |
| 8325 | skb->pkt_type = PACKET_OTHERHOST; |
Harvey Harrison | c1b4aa3 | 2009-01-29 13:26:44 -0800 | [diff] [blame] | 8326 | skb->protocol = cpu_to_be16(ETH_P_80211_STATS); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8327 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
| 8328 | netif_rx(skb); |
| 8329 | rxb->skb = NULL; |
| 8330 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8331 | } |
| 8332 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8333 | /* |
| 8334 | * Main entry function for recieving a packet with 80211 headers. This |
| 8335 | * should be called when ever the FW has notified us that there is a new |
| 8336 | * skb in the recieve queue. |
| 8337 | */ |
| 8338 | static void ipw_rx(struct ipw_priv *priv) |
| 8339 | { |
| 8340 | struct ipw_rx_mem_buffer *rxb; |
| 8341 | struct ipw_rx_packet *pkt; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8342 | struct libipw_hdr_4addr *header; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8343 | u32 r, w, i; |
| 8344 | u8 network_packet; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8345 | u8 fill_rx = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8346 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8347 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
| 8348 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8349 | i = priv->rxq->read; |
| 8350 | |
| 8351 | if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2)) |
| 8352 | fill_rx = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8353 | |
| 8354 | while (i != r) { |
| 8355 | rxb = priv->rxq->queue[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8356 | if (unlikely(rxb == NULL)) { |
| 8357 | printk(KERN_CRIT "Queue not allocated!\n"); |
| 8358 | break; |
| 8359 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8360 | priv->rxq->queue[i] = NULL; |
| 8361 | |
| 8362 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8363 | IPW_RX_BUF_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8364 | PCI_DMA_FROMDEVICE); |
| 8365 | |
| 8366 | pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 8367 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", |
| 8368 | pkt->header.message_type, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8369 | pkt->header.rx_seq_num, pkt->header.control_bits); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8370 | |
| 8371 | switch (pkt->header.message_type) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8372 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8373 | struct libipw_rx_stats stats = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 8374 | .rssi = pkt->u.frame.rssi_dbm - |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8375 | IPW_RSSI_TO_DBM, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8376 | .signal = |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8377 | pkt->u.frame.rssi_dbm - |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8378 | IPW_RSSI_TO_DBM + 0x100, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8379 | .noise = |
| 8380 | le16_to_cpu(pkt->u.frame.noise), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8381 | .rate = pkt->u.frame.rate, |
| 8382 | .mac_time = jiffies, |
| 8383 | .received_channel = |
| 8384 | pkt->u.frame.received_channel, |
| 8385 | .freq = |
| 8386 | (pkt->u.frame. |
| 8387 | control & (1 << 0)) ? |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8388 | LIBIPW_24GHZ_BAND : |
| 8389 | LIBIPW_52GHZ_BAND, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8390 | .len = le16_to_cpu(pkt->u.frame.length), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8391 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8392 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8393 | if (stats.rssi != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8394 | stats.mask |= LIBIPW_STATMASK_RSSI; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8395 | if (stats.signal != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8396 | stats.mask |= LIBIPW_STATMASK_SIGNAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8397 | if (stats.noise != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8398 | stats.mask |= LIBIPW_STATMASK_NOISE; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8399 | if (stats.rate != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8400 | stats.mask |= LIBIPW_STATMASK_RATE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8401 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8402 | priv->rx_packets++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8403 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8404 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 8405 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) |
| 8406 | ipw_handle_promiscuous_rx(priv, rxb, &stats); |
| 8407 | #endif |
| 8408 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8409 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8410 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8411 | #ifdef CONFIG_IPW2200_RADIOTAP |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8412 | |
| 8413 | ipw_handle_data_packet_monitor(priv, |
| 8414 | rxb, |
| 8415 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8416 | #else |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8417 | ipw_handle_data_packet(priv, rxb, |
| 8418 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8419 | #endif |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8420 | break; |
| 8421 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8422 | #endif |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8423 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8424 | header = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8425 | (struct libipw_hdr_4addr *)(rxb->skb-> |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 8426 | data + |
| 8427 | IPW_RX_FRAME_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8428 | /* TODO: Check Ad-Hoc dest/source and make sure |
| 8429 | * that we are actually parsing these packets |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8430 | * correctly -- we should probably use the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8431 | * frame control of the packet and disregard |
| 8432 | * the current iw_mode */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8433 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8434 | network_packet = |
| 8435 | is_network_packet(priv, header); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8436 | if (network_packet && priv->assoc_network) { |
| 8437 | priv->assoc_network->stats.rssi = |
| 8438 | stats.rssi; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 8439 | priv->exp_avg_rssi = |
| 8440 | exponential_average(priv->exp_avg_rssi, |
| 8441 | stats.rssi, DEPTH_RSSI); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8442 | } |
| 8443 | |
| 8444 | IPW_DEBUG_RX("Frame: len=%u\n", |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8445 | le16_to_cpu(pkt->u.frame.length)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8446 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8447 | if (le16_to_cpu(pkt->u.frame.length) < |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8448 | libipw_get_hdrlen(le16_to_cpu( |
Zhu Yi | 9d0be03 | 2006-02-15 06:18:19 +0800 | [diff] [blame] | 8449 | header->frame_ctl))) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8450 | IPW_DEBUG_DROP |
| 8451 | ("Received packet is too small. " |
| 8452 | "Dropping.\n"); |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8453 | priv->net_dev->stats.rx_errors++; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8454 | priv->wstats.discard.misc++; |
| 8455 | break; |
| 8456 | } |
| 8457 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8458 | switch (WLAN_FC_GET_TYPE |
| 8459 | (le16_to_cpu(header->frame_ctl))) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8460 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8461 | case IEEE80211_FTYPE_MGMT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8462 | ipw_handle_mgmt_packet(priv, rxb, |
| 8463 | &stats); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8464 | break; |
| 8465 | |
| 8466 | case IEEE80211_FTYPE_CTL: |
| 8467 | break; |
| 8468 | |
| 8469 | case IEEE80211_FTYPE_DATA: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8470 | if (unlikely(!network_packet || |
| 8471 | is_duplicate_packet(priv, |
| 8472 | header))) |
| 8473 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8474 | IPW_DEBUG_DROP("Dropping: " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 8475 | "%pM, " |
| 8476 | "%pM, " |
| 8477 | "%pM\n", |
| 8478 | header->addr1, |
| 8479 | header->addr2, |
| 8480 | header->addr3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8481 | break; |
| 8482 | } |
| 8483 | |
| 8484 | ipw_handle_data_packet(priv, rxb, |
| 8485 | &stats); |
| 8486 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8487 | break; |
| 8488 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8489 | break; |
| 8490 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8491 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8492 | case RX_HOST_NOTIFICATION_TYPE:{ |
| 8493 | IPW_DEBUG_RX |
| 8494 | ("Notification: subtype=%02X flags=%02X size=%d\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8495 | pkt->u.notification.subtype, |
| 8496 | pkt->u.notification.flags, |
Zhu Yi | 720eeb4 | 2006-12-05 14:41:40 +0800 | [diff] [blame] | 8497 | le16_to_cpu(pkt->u.notification.size)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8498 | ipw_rx_notification(priv, &pkt->u.notification); |
| 8499 | break; |
| 8500 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8501 | |
| 8502 | default: |
| 8503 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", |
| 8504 | pkt->header.message_type); |
| 8505 | break; |
| 8506 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8507 | |
| 8508 | /* For now we just don't re-use anything. We can tweak this |
| 8509 | * later to try and re-use notification packets and SKBs that |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8510 | * fail to Rx correctly */ |
| 8511 | if (rxb->skb != NULL) { |
| 8512 | dev_kfree_skb_any(rxb->skb); |
| 8513 | rxb->skb = NULL; |
| 8514 | } |
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 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8517 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8518 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8519 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8520 | i = (i + 1) % RX_QUEUE_SIZE; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8521 | |
| 8522 | /* If there are a lot of unsued frames, restock the Rx queue |
| 8523 | * so the ucode won't assert */ |
| 8524 | if (fill_rx) { |
| 8525 | priv->rxq->read = i; |
| 8526 | ipw_rx_queue_replenish(priv); |
| 8527 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8528 | } |
| 8529 | |
| 8530 | /* Backtrack one entry */ |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8531 | priv->rxq->read = i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8532 | ipw_rx_queue_restock(priv); |
| 8533 | } |
| 8534 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8535 | #define DEFAULT_RTS_THRESHOLD 2304U |
| 8536 | #define MIN_RTS_THRESHOLD 1U |
| 8537 | #define MAX_RTS_THRESHOLD 2304U |
| 8538 | #define DEFAULT_BEACON_INTERVAL 100U |
| 8539 | #define DEFAULT_SHORT_RETRY_LIMIT 7U |
| 8540 | #define DEFAULT_LONG_RETRY_LIMIT 4U |
| 8541 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8542 | /** |
| 8543 | * ipw_sw_reset |
| 8544 | * @option: options to control different reset behaviour |
| 8545 | * 0 = reset everything except the 'disable' module_param |
| 8546 | * 1 = reset everything and print out driver info (for probe only) |
| 8547 | * 2 = reset everything |
| 8548 | */ |
| 8549 | static int ipw_sw_reset(struct ipw_priv *priv, int option) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8550 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8551 | int band, modulation; |
| 8552 | int old_mode = priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8553 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8554 | /* Initialize module parameter values here */ |
| 8555 | priv->config = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8556 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8557 | /* We default to disabling the LED code as right now it causes |
| 8558 | * too many systems to lock up... */ |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8559 | if (!led_support) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8560 | priv->config |= CFG_NO_LED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8561 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8562 | if (associate) |
| 8563 | priv->config |= CFG_ASSOCIATE; |
| 8564 | else |
| 8565 | IPW_DEBUG_INFO("Auto associate disabled.\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8566 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8567 | if (auto_create) |
| 8568 | priv->config |= CFG_ADHOC_CREATE; |
| 8569 | else |
| 8570 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); |
| 8571 | |
Zhu Yi | 17ed081 | 2006-01-24 16:36:31 +0800 | [diff] [blame] | 8572 | priv->config &= ~CFG_STATIC_ESSID; |
| 8573 | priv->essid_len = 0; |
| 8574 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 8575 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8576 | if (disable && option) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8577 | priv->status |= STATUS_RF_KILL_SW; |
| 8578 | IPW_DEBUG_INFO("Radio disabled.\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8579 | } |
| 8580 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8581 | if (default_channel != 0) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8582 | priv->config |= CFG_STATIC_CHANNEL; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8583 | priv->channel = default_channel; |
| 8584 | IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8585 | /* TODO: Validate that provided channel is in range */ |
| 8586 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8587 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8588 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
| 8589 | burst_duration_CCK, burst_duration_OFDM); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8590 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8591 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8592 | switch (network_mode) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8593 | case 1: |
| 8594 | priv->ieee->iw_mode = IW_MODE_ADHOC; |
| 8595 | priv->net_dev->type = ARPHRD_ETHER; |
| 8596 | |
| 8597 | break; |
| 8598 | #ifdef CONFIG_IPW2200_MONITOR |
| 8599 | case 2: |
| 8600 | priv->ieee->iw_mode = IW_MODE_MONITOR; |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8601 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8602 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8603 | #else |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8604 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8605 | #endif |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8606 | break; |
| 8607 | #endif |
| 8608 | default: |
| 8609 | case 0: |
| 8610 | priv->net_dev->type = ARPHRD_ETHER; |
| 8611 | priv->ieee->iw_mode = IW_MODE_INFRA; |
| 8612 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8613 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8614 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8615 | if (hwcrypto) { |
| 8616 | priv->ieee->host_encrypt = 0; |
| 8617 | priv->ieee->host_encrypt_msdu = 0; |
| 8618 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 8619 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8620 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8621 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8622 | |
Zhu Yi | e402c93 | 2005-08-05 17:20:40 +0800 | [diff] [blame] | 8623 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
| 8624 | priv->ieee->host_open_frag = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8625 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8626 | if ((priv->pci_dev->device == 0x4223) || |
| 8627 | (priv->pci_dev->device == 0x4224)) { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8628 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8629 | printk(KERN_INFO DRV_NAME |
| 8630 | ": Detected Intel PRO/Wireless 2915ABG Network " |
| 8631 | "Connection\n"); |
| 8632 | priv->ieee->abg_true = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8633 | band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND; |
| 8634 | modulation = LIBIPW_OFDM_MODULATION | |
| 8635 | LIBIPW_CCK_MODULATION; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8636 | priv->adapter = IPW_2915ABG; |
| 8637 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8638 | } else { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8639 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8640 | printk(KERN_INFO DRV_NAME |
| 8641 | ": Detected Intel PRO/Wireless 2200BG Network " |
| 8642 | "Connection\n"); |
| 8643 | |
| 8644 | priv->ieee->abg_true = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8645 | band = LIBIPW_24GHZ_BAND; |
| 8646 | modulation = LIBIPW_OFDM_MODULATION | |
| 8647 | LIBIPW_CCK_MODULATION; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8648 | priv->adapter = IPW_2200BG; |
| 8649 | priv->ieee->mode = IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8650 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8651 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8652 | priv->ieee->freq_band = band; |
| 8653 | priv->ieee->modulation = modulation; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8654 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8655 | priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8656 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8657 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8658 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8659 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8660 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8661 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; |
| 8662 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8663 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8664 | /* If power management is turned on, default to AC mode */ |
| 8665 | priv->power_mode = IPW_POWER_AC; |
| 8666 | priv->tx_power = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8667 | |
Zhu Yi | 0ece35b | 2005-08-05 17:26:51 +0800 | [diff] [blame] | 8668 | return old_mode == priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8669 | } |
| 8670 | |
| 8671 | /* |
| 8672 | * This file defines the Wireless Extension handlers. It does not |
| 8673 | * define any methods of hardware manipulation and relies on the |
| 8674 | * functions defined in ipw_main to provide the HW interaction. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8675 | * |
| 8676 | * The exception to this is the use of the ipw_get_ordinal() |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8677 | * function used to poll the hardware vs. making unecessary calls. |
| 8678 | * |
| 8679 | */ |
| 8680 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8681 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
| 8682 | { |
| 8683 | if (channel == 0) { |
| 8684 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); |
| 8685 | priv->config &= ~CFG_STATIC_CHANNEL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8686 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8687 | "parameters.\n"); |
| 8688 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8689 | return 0; |
| 8690 | } |
| 8691 | |
| 8692 | priv->config |= CFG_STATIC_CHANNEL; |
| 8693 | |
| 8694 | if (priv->channel == channel) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8695 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
| 8696 | channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8697 | return 0; |
| 8698 | } |
| 8699 | |
| 8700 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); |
| 8701 | priv->channel = channel; |
| 8702 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8703 | #ifdef CONFIG_IPW2200_MONITOR |
| 8704 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8705 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8706 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8707 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8708 | "channel change.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8709 | ipw_abort_scan(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8710 | } |
| 8711 | |
| 8712 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) |
| 8713 | udelay(10); |
| 8714 | |
| 8715 | if (priv->status & STATUS_SCANNING) |
| 8716 | IPW_DEBUG_SCAN("Still scanning...\n"); |
| 8717 | else |
| 8718 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", |
| 8719 | 1000 - i); |
| 8720 | |
| 8721 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8722 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8723 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 8724 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8725 | /* Network configuration changed -- force [re]association */ |
| 8726 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); |
| 8727 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8728 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8729 | |
| 8730 | return 0; |
| 8731 | } |
| 8732 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8733 | static int ipw_wx_set_freq(struct net_device *dev, |
| 8734 | struct iw_request_info *info, |
| 8735 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8736 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8737 | struct ipw_priv *priv = libipw_priv(dev); |
| 8738 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8739 | struct iw_freq *fwrq = &wrqu->freq; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8740 | int ret = 0, i; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8741 | u8 channel, flags; |
| 8742 | int band; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8743 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8744 | if (fwrq->m == 0) { |
| 8745 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8746 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8747 | ret = ipw_set_channel(priv, 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8748 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8749 | return ret; |
| 8750 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8751 | /* if setting by freq convert to channel */ |
| 8752 | if (fwrq->e == 1) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8753 | channel = libipw_freq_to_channel(priv->ieee, fwrq->m); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8754 | if (channel == 0) |
| 8755 | return -EINVAL; |
| 8756 | } else |
| 8757 | channel = fwrq->m; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8758 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8759 | if (!(band = libipw_is_valid_channel(priv->ieee, channel))) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8760 | return -EINVAL; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8761 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8762 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8763 | i = libipw_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8764 | if (i == -1) |
| 8765 | return -EINVAL; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8766 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8767 | flags = (band == LIBIPW_24GHZ_BAND) ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8768 | geo->bg[i].flags : geo->a[i].flags; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8769 | if (flags & LIBIPW_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8770 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
| 8771 | return -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8772 | } |
| 8773 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8774 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8775 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8776 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8777 | ret = ipw_set_channel(priv, channel); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8778 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8779 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8780 | } |
| 8781 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8782 | static int ipw_wx_get_freq(struct net_device *dev, |
| 8783 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8784 | union iwreq_data *wrqu, char *extra) |
| 8785 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8786 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8787 | |
| 8788 | wrqu->freq.e = 0; |
| 8789 | |
| 8790 | /* If we are associated, trying to associate, or have a statically |
| 8791 | * configured CHANNEL then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8792 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8793 | if (priv->config & CFG_STATIC_CHANNEL || |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8794 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) { |
| 8795 | int i; |
| 8796 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8797 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8798 | BUG_ON(i == -1); |
| 8799 | wrqu->freq.e = 1; |
| 8800 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8801 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 8802 | case LIBIPW_52GHZ_BAND: |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8803 | wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000; |
| 8804 | break; |
| 8805 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8806 | case LIBIPW_24GHZ_BAND: |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8807 | wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000; |
| 8808 | break; |
| 8809 | |
| 8810 | default: |
| 8811 | BUG(); |
| 8812 | } |
| 8813 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8814 | wrqu->freq.m = 0; |
| 8815 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8816 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8817 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
| 8818 | return 0; |
| 8819 | } |
| 8820 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8821 | static int ipw_wx_set_mode(struct net_device *dev, |
| 8822 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8823 | union iwreq_data *wrqu, char *extra) |
| 8824 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8825 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8826 | int err = 0; |
| 8827 | |
| 8828 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); |
| 8829 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8830 | switch (wrqu->mode) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8831 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8832 | case IW_MODE_MONITOR: |
| 8833 | #endif |
| 8834 | case IW_MODE_ADHOC: |
| 8835 | case IW_MODE_INFRA: |
| 8836 | break; |
| 8837 | case IW_MODE_AUTO: |
| 8838 | wrqu->mode = IW_MODE_INFRA; |
| 8839 | break; |
| 8840 | default: |
| 8841 | return -EINVAL; |
| 8842 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8843 | if (wrqu->mode == priv->ieee->iw_mode) |
| 8844 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8845 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8846 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8847 | |
| 8848 | ipw_sw_reset(priv, 0); |
| 8849 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8850 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8851 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8852 | priv->net_dev->type = ARPHRD_ETHER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8853 | |
| 8854 | if (wrqu->mode == IW_MODE_MONITOR) |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8855 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8856 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8857 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8858 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8859 | #endif |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8860 | #endif /* CONFIG_IPW2200_MONITOR */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8861 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8862 | /* Free the existing firmware and reset the fw_loaded |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 8863 | * flag so ipw_load() will bring in the new firmware */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8864 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8865 | |
| 8866 | priv->ieee->iw_mode = wrqu->mode; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8867 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8868 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8869 | mutex_unlock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8870 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8871 | } |
| 8872 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8873 | static int ipw_wx_get_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8874 | struct iw_request_info *info, |
| 8875 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8876 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8877 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8878 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8879 | wrqu->mode = priv->ieee->iw_mode; |
| 8880 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8881 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8882 | return 0; |
| 8883 | } |
| 8884 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8885 | /* Values are in microsecond */ |
| 8886 | static const s32 timeout_duration[] = { |
| 8887 | 350000, |
| 8888 | 250000, |
| 8889 | 75000, |
| 8890 | 37000, |
| 8891 | 25000, |
| 8892 | }; |
| 8893 | |
| 8894 | static const s32 period_duration[] = { |
| 8895 | 400000, |
| 8896 | 700000, |
| 8897 | 1000000, |
| 8898 | 1000000, |
| 8899 | 1000000 |
| 8900 | }; |
| 8901 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8902 | static int ipw_wx_get_range(struct net_device *dev, |
| 8903 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8904 | union iwreq_data *wrqu, char *extra) |
| 8905 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8906 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8907 | struct iw_range *range = (struct iw_range *)extra; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8908 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8909 | int i = 0, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8910 | |
| 8911 | wrqu->data.length = sizeof(*range); |
| 8912 | memset(range, 0, sizeof(*range)); |
| 8913 | |
| 8914 | /* 54Mbs == ~27 Mb/s real (802.11g) */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8915 | range->throughput = 27 * 1000 * 1000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8916 | |
| 8917 | range->max_qual.qual = 100; |
| 8918 | /* TODO: Find real max RSSI and stick here */ |
| 8919 | range->max_qual.level = 0; |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8920 | range->max_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8921 | range->max_qual.updated = 7; /* Updated all three */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8922 | |
| 8923 | range->avg_qual.qual = 70; |
| 8924 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8925 | range->avg_qual.level = 0; /* FIXME to real average level */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8926 | range->avg_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8927 | range->avg_qual.updated = 7; /* Updated all three */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8928 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8929 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8930 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8931 | for (i = 0; i < range->num_bitrates; i++) |
| 8932 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8933 | 500000; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8934 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8935 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
| 8936 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 8937 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 8938 | |
| 8939 | range->encoding_size[0] = 5; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8940 | range->encoding_size[1] = 13; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8941 | range->num_encoding_sizes = 2; |
| 8942 | range->max_encoding_tokens = WEP_KEYS; |
| 8943 | |
| 8944 | /* Set the Wireless Extension versions */ |
| 8945 | range->we_version_compiled = WIRELESS_EXT; |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8946 | range->we_version_source = 18; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8947 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8948 | i = 0; |
| 8949 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8950 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8951 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8952 | (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY)) |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8953 | continue; |
| 8954 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8955 | range->freq[i].i = geo->bg[j].channel; |
| 8956 | range->freq[i].m = geo->bg[j].freq * 100000; |
| 8957 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8958 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8959 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8960 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8961 | |
| 8962 | if (priv->ieee->mode & IEEE_A) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8963 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8964 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8965 | (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY)) |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8966 | continue; |
| 8967 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8968 | range->freq[i].i = geo->a[j].channel; |
| 8969 | range->freq[i].m = geo->a[j].freq * 100000; |
| 8970 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8971 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8972 | } |
| 8973 | } |
| 8974 | |
| 8975 | range->num_channels = i; |
| 8976 | range->num_frequency = i; |
| 8977 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8978 | mutex_unlock(&priv->mutex); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8979 | |
| 8980 | /* Event capability (kernel + driver) */ |
| 8981 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 8982 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 8983 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | |
| 8984 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8985 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8986 | |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8987 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 8988 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 8989 | |
Dan Williams | 374fdfb | 2007-12-12 10:25:07 -0500 | [diff] [blame] | 8990 | range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE; |
| 8991 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8992 | IPW_DEBUG_WX("GET Range\n"); |
| 8993 | return 0; |
| 8994 | } |
| 8995 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8996 | static int ipw_wx_set_wap(struct net_device *dev, |
| 8997 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8998 | union iwreq_data *wrqu, char *extra) |
| 8999 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9000 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9001 | |
| 9002 | static const unsigned char any[] = { |
| 9003 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 9004 | }; |
| 9005 | static const unsigned char off[] = { |
| 9006 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 9007 | }; |
| 9008 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9009 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9010 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9011 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9012 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
| 9013 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 9014 | /* we disable mandatory BSSID association */ |
| 9015 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); |
| 9016 | priv->config &= ~CFG_STATIC_BSSID; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9017 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 9018 | "parameters.\n"); |
| 9019 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9020 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9021 | return 0; |
| 9022 | } |
| 9023 | |
| 9024 | priv->config |= CFG_STATIC_BSSID; |
| 9025 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 9026 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9027 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9028 | return 0; |
| 9029 | } |
| 9030 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 9031 | IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n", |
| 9032 | wrqu->ap_addr.sa_data); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9033 | |
| 9034 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); |
| 9035 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9036 | /* Network configuration changed -- force [re]association */ |
| 9037 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); |
| 9038 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9039 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9040 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9041 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9042 | return 0; |
| 9043 | } |
| 9044 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9045 | static int ipw_wx_get_wap(struct net_device *dev, |
| 9046 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9047 | union iwreq_data *wrqu, char *extra) |
| 9048 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9049 | struct ipw_priv *priv = libipw_priv(dev); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 9050 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9051 | /* If we are associated, trying to associate, or have a statically |
| 9052 | * configured BSSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9053 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9054 | if (priv->config & CFG_STATIC_BSSID || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9055 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 9056 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9057 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9058 | } else |
| 9059 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 9060 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 9061 | IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", |
| 9062 | wrqu->ap_addr.sa_data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9063 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9064 | return 0; |
| 9065 | } |
| 9066 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9067 | static int ipw_wx_set_essid(struct net_device *dev, |
| 9068 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9069 | union iwreq_data *wrqu, char *extra) |
| 9070 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9071 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 9072 | int length; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9073 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9074 | |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 9075 | mutex_lock(&priv->mutex); |
| 9076 | |
| 9077 | if (!wrqu->essid.flags) |
| 9078 | { |
| 9079 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); |
| 9080 | ipw_disassociate(priv); |
| 9081 | priv->config &= ~CFG_STATIC_ESSID; |
| 9082 | ipw_associate(priv); |
| 9083 | mutex_unlock(&priv->mutex); |
| 9084 | return 0; |
| 9085 | } |
| 9086 | |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9087 | length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9088 | |
| 9089 | priv->config |= CFG_STATIC_ESSID; |
| 9090 | |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9091 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length) |
| 9092 | && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9093 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9094 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9095 | return 0; |
| 9096 | } |
| 9097 | |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9098 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", |
| 9099 | print_ssid(ssid, extra, length), length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9100 | |
| 9101 | priv->essid_len = length; |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9102 | memcpy(priv->essid, extra, priv->essid_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9103 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9104 | /* Network configuration changed -- force [re]association */ |
| 9105 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); |
| 9106 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9107 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9108 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9109 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9110 | return 0; |
| 9111 | } |
| 9112 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9113 | static int ipw_wx_get_essid(struct net_device *dev, |
| 9114 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9115 | union iwreq_data *wrqu, char *extra) |
| 9116 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9117 | struct ipw_priv *priv = libipw_priv(dev); |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9118 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9119 | |
| 9120 | /* If we are associated, trying to associate, or have a statically |
| 9121 | * configured ESSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9122 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9123 | if (priv->config & CFG_STATIC_ESSID || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9124 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 9125 | IPW_DEBUG_WX("Getting essid: '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9126 | print_ssid(ssid, priv->essid, priv->essid_len)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9127 | memcpy(extra, priv->essid, priv->essid_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9128 | wrqu->essid.length = priv->essid_len; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9129 | wrqu->essid.flags = 1; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9130 | } else { |
| 9131 | IPW_DEBUG_WX("Getting essid: ANY\n"); |
| 9132 | wrqu->essid.length = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9133 | wrqu->essid.flags = 0; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9134 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9135 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9136 | return 0; |
| 9137 | } |
| 9138 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9139 | static int ipw_wx_set_nick(struct net_device *dev, |
| 9140 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9141 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9142 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9143 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9144 | |
| 9145 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); |
| 9146 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) |
| 9147 | return -E2BIG; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9148 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9149 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9150 | memset(priv->nick, 0, sizeof(priv->nick)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9151 | memcpy(priv->nick, extra, wrqu->data.length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9152 | IPW_DEBUG_TRACE("<<\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9153 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9154 | return 0; |
| 9155 | |
| 9156 | } |
| 9157 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9158 | static int ipw_wx_get_nick(struct net_device *dev, |
| 9159 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9160 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9161 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9162 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9163 | IPW_DEBUG_WX("Getting nick\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9164 | mutex_lock(&priv->mutex); |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9165 | wrqu->data.length = strlen(priv->nick); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9166 | memcpy(extra, priv->nick, wrqu->data.length); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9167 | wrqu->data.flags = 1; /* active */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9168 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9169 | return 0; |
| 9170 | } |
| 9171 | |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9172 | static int ipw_wx_set_sens(struct net_device *dev, |
| 9173 | struct iw_request_info *info, |
| 9174 | union iwreq_data *wrqu, char *extra) |
| 9175 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9176 | struct ipw_priv *priv = libipw_priv(dev); |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9177 | int err = 0; |
| 9178 | |
| 9179 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); |
| 9180 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); |
| 9181 | mutex_lock(&priv->mutex); |
| 9182 | |
| 9183 | if (wrqu->sens.fixed == 0) |
| 9184 | { |
| 9185 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
| 9186 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 9187 | goto out; |
| 9188 | } |
| 9189 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || |
| 9190 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { |
| 9191 | err = -EINVAL; |
| 9192 | goto out; |
| 9193 | } |
| 9194 | |
| 9195 | priv->roaming_threshold = wrqu->sens.value; |
| 9196 | priv->disassociate_threshold = 3*wrqu->sens.value; |
| 9197 | out: |
| 9198 | mutex_unlock(&priv->mutex); |
| 9199 | return err; |
| 9200 | } |
| 9201 | |
| 9202 | static int ipw_wx_get_sens(struct net_device *dev, |
| 9203 | struct iw_request_info *info, |
| 9204 | union iwreq_data *wrqu, char *extra) |
| 9205 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9206 | struct ipw_priv *priv = libipw_priv(dev); |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9207 | mutex_lock(&priv->mutex); |
| 9208 | wrqu->sens.fixed = 1; |
| 9209 | wrqu->sens.value = priv->roaming_threshold; |
| 9210 | mutex_unlock(&priv->mutex); |
| 9211 | |
| 9212 | IPW_DEBUG_WX("GET roaming threshold -> %s %d \n", |
| 9213 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
| 9214 | |
| 9215 | return 0; |
| 9216 | } |
| 9217 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9218 | static int ipw_wx_set_rate(struct net_device *dev, |
| 9219 | struct iw_request_info *info, |
| 9220 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9221 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9222 | /* TODO: We should use semaphores or locks for access to priv */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9223 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9224 | u32 target_rate = wrqu->bitrate.value; |
| 9225 | u32 fixed, mask; |
| 9226 | |
| 9227 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ |
| 9228 | /* value = X, fixed = 1 means only rate X */ |
| 9229 | /* value = X, fixed = 0 means all rates lower equal X */ |
| 9230 | |
| 9231 | if (target_rate == -1) { |
| 9232 | fixed = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9233 | mask = LIBIPW_DEFAULT_RATES_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9234 | /* Now we should reassociate */ |
| 9235 | goto apply; |
| 9236 | } |
| 9237 | |
| 9238 | mask = 0; |
| 9239 | fixed = wrqu->bitrate.fixed; |
| 9240 | |
| 9241 | if (target_rate == 1000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9242 | mask |= LIBIPW_CCK_RATE_1MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9243 | if (target_rate == 1000000) |
| 9244 | goto apply; |
| 9245 | |
| 9246 | if (target_rate == 2000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9247 | mask |= LIBIPW_CCK_RATE_2MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9248 | if (target_rate == 2000000) |
| 9249 | goto apply; |
| 9250 | |
| 9251 | if (target_rate == 5500000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9252 | mask |= LIBIPW_CCK_RATE_5MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9253 | if (target_rate == 5500000) |
| 9254 | goto apply; |
| 9255 | |
| 9256 | if (target_rate == 6000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9257 | mask |= LIBIPW_OFDM_RATE_6MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9258 | if (target_rate == 6000000) |
| 9259 | goto apply; |
| 9260 | |
| 9261 | if (target_rate == 9000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9262 | mask |= LIBIPW_OFDM_RATE_9MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9263 | if (target_rate == 9000000) |
| 9264 | goto apply; |
| 9265 | |
| 9266 | if (target_rate == 11000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9267 | mask |= LIBIPW_CCK_RATE_11MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9268 | if (target_rate == 11000000) |
| 9269 | goto apply; |
| 9270 | |
| 9271 | if (target_rate == 12000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9272 | mask |= LIBIPW_OFDM_RATE_12MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9273 | if (target_rate == 12000000) |
| 9274 | goto apply; |
| 9275 | |
| 9276 | if (target_rate == 18000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9277 | mask |= LIBIPW_OFDM_RATE_18MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9278 | if (target_rate == 18000000) |
| 9279 | goto apply; |
| 9280 | |
| 9281 | if (target_rate == 24000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9282 | mask |= LIBIPW_OFDM_RATE_24MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9283 | if (target_rate == 24000000) |
| 9284 | goto apply; |
| 9285 | |
| 9286 | if (target_rate == 36000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9287 | mask |= LIBIPW_OFDM_RATE_36MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9288 | if (target_rate == 36000000) |
| 9289 | goto apply; |
| 9290 | |
| 9291 | if (target_rate == 48000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9292 | mask |= LIBIPW_OFDM_RATE_48MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9293 | if (target_rate == 48000000) |
| 9294 | goto apply; |
| 9295 | |
| 9296 | if (target_rate == 54000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9297 | mask |= LIBIPW_OFDM_RATE_54MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9298 | if (target_rate == 54000000) |
| 9299 | goto apply; |
| 9300 | |
| 9301 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); |
| 9302 | return -EINVAL; |
| 9303 | |
| 9304 | apply: |
| 9305 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", |
| 9306 | mask, fixed ? "fixed" : "sub-rates"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9307 | mutex_lock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9308 | if (mask == LIBIPW_DEFAULT_RATES_MASK) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9309 | priv->config &= ~CFG_FIXED_RATE; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9310 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
| 9311 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9312 | priv->config |= CFG_FIXED_RATE; |
| 9313 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9314 | if (priv->rates_mask == mask) { |
| 9315 | IPW_DEBUG_WX("Mask set to current mask.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9316 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9317 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9318 | } |
| 9319 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9320 | priv->rates_mask = mask; |
| 9321 | |
| 9322 | /* Network configuration changed -- force [re]association */ |
| 9323 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); |
| 9324 | if (!ipw_disassociate(priv)) |
| 9325 | ipw_associate(priv); |
| 9326 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9327 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9328 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9329 | } |
| 9330 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9331 | static int ipw_wx_get_rate(struct net_device *dev, |
| 9332 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9333 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9334 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9335 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9336 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9337 | wrqu->bitrate.value = priv->last_rate; |
Zhu Yi | 455936c | 2006-04-13 17:20:05 +0800 | [diff] [blame] | 9338 | wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9339 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9340 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
| 9341 | return 0; |
| 9342 | } |
| 9343 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9344 | static int ipw_wx_set_rts(struct net_device *dev, |
| 9345 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9346 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9347 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9348 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9349 | mutex_lock(&priv->mutex); |
Zhu Yi | ea8862d | 2007-01-11 17:32:54 +0800 | [diff] [blame] | 9350 | if (wrqu->rts.disabled || !wrqu->rts.fixed) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9351 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 9352 | else { |
| 9353 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9354 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9355 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9356 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9357 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9358 | priv->rts_threshold = wrqu->rts.value; |
| 9359 | } |
| 9360 | |
| 9361 | ipw_send_rts_threshold(priv, priv->rts_threshold); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9362 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9363 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
| 9364 | return 0; |
| 9365 | } |
| 9366 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9367 | static int ipw_wx_get_rts(struct net_device *dev, |
| 9368 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9369 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9370 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9371 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9372 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9373 | wrqu->rts.value = priv->rts_threshold; |
| 9374 | wrqu->rts.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9375 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9376 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9377 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
| 9378 | return 0; |
| 9379 | } |
| 9380 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9381 | static int ipw_wx_set_txpow(struct net_device *dev, |
| 9382 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9383 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9384 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9385 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9386 | int err = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9387 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9388 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9389 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9390 | err = -EINPROGRESS; |
| 9391 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9392 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9393 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9394 | if (!wrqu->power.fixed) |
| 9395 | wrqu->power.value = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9396 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9397 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9398 | err = -EINVAL; |
| 9399 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9400 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9401 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9402 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9403 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9404 | err = -EINVAL; |
| 9405 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9406 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9407 | |
| 9408 | priv->tx_power = wrqu->power.value; |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9409 | err = ipw_set_tx_power(priv); |
| 9410 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9411 | mutex_unlock(&priv->mutex); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9412 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9413 | } |
| 9414 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9415 | static int ipw_wx_get_txpow(struct net_device *dev, |
| 9416 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9417 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9418 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9419 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9420 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9421 | wrqu->power.value = priv->tx_power; |
| 9422 | wrqu->power.fixed = 1; |
| 9423 | wrqu->power.flags = IW_TXPOW_DBM; |
| 9424 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9425 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9426 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9427 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
Zhu Yi | 22501c8 | 2005-08-11 10:49:17 +0800 | [diff] [blame] | 9428 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9429 | |
| 9430 | return 0; |
| 9431 | } |
| 9432 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9433 | static int ipw_wx_set_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9434 | struct iw_request_info *info, |
| 9435 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9436 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9437 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9438 | mutex_lock(&priv->mutex); |
Zhu Yi | ea8862d | 2007-01-11 17:32:54 +0800 | [diff] [blame] | 9439 | if (wrqu->frag.disabled || !wrqu->frag.fixed) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9440 | priv->ieee->fts = DEFAULT_FTS; |
| 9441 | else { |
| 9442 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9443 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9444 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9445 | return -EINVAL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9446 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9447 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9448 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
| 9449 | } |
| 9450 | |
| 9451 | ipw_send_frag_threshold(priv, wrqu->frag.value); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9452 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9453 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
| 9454 | return 0; |
| 9455 | } |
| 9456 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9457 | static int ipw_wx_get_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9458 | struct iw_request_info *info, |
| 9459 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9460 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9461 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9462 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9463 | wrqu->frag.value = priv->ieee->fts; |
| 9464 | wrqu->frag.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9465 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9466 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9467 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
| 9468 | |
| 9469 | return 0; |
| 9470 | } |
| 9471 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9472 | static int ipw_wx_set_retry(struct net_device *dev, |
| 9473 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9474 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9475 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9476 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9477 | |
| 9478 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) |
| 9479 | return -EINVAL; |
| 9480 | |
| 9481 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) |
| 9482 | return 0; |
| 9483 | |
Zhu Yi | d5f7ac2 | 2006-08-21 11:38:17 +0800 | [diff] [blame] | 9484 | if (wrqu->retry.value < 0 || wrqu->retry.value >= 255) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9485 | return -EINVAL; |
| 9486 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9487 | mutex_lock(&priv->mutex); |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9488 | if (wrqu->retry.flags & IW_RETRY_SHORT) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9489 | priv->short_retry_limit = (u8) wrqu->retry.value; |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9490 | else if (wrqu->retry.flags & IW_RETRY_LONG) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9491 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9492 | else { |
| 9493 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 9494 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9495 | } |
| 9496 | |
| 9497 | ipw_send_retry_limit(priv, priv->short_retry_limit, |
| 9498 | priv->long_retry_limit); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9499 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9500 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
| 9501 | priv->short_retry_limit, priv->long_retry_limit); |
| 9502 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9503 | } |
| 9504 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9505 | static int ipw_wx_get_retry(struct net_device *dev, |
| 9506 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9507 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9508 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9509 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9510 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9511 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9512 | wrqu->retry.disabled = 0; |
| 9513 | |
| 9514 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9515 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9516 | return -EINVAL; |
| 9517 | } |
| 9518 | |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9519 | if (wrqu->retry.flags & IW_RETRY_LONG) { |
| 9520 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9521 | wrqu->retry.value = priv->long_retry_limit; |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9522 | } else if (wrqu->retry.flags & IW_RETRY_SHORT) { |
| 9523 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9524 | wrqu->retry.value = priv->short_retry_limit; |
| 9525 | } else { |
| 9526 | wrqu->retry.flags = IW_RETRY_LIMIT; |
| 9527 | wrqu->retry.value = priv->short_retry_limit; |
| 9528 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9529 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9530 | |
| 9531 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); |
| 9532 | |
| 9533 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9534 | } |
| 9535 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9536 | static int ipw_wx_set_scan(struct net_device *dev, |
| 9537 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9538 | union iwreq_data *wrqu, char *extra) |
| 9539 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9540 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9541 | struct iw_scan_req *req = (struct iw_scan_req *)extra; |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9542 | struct delayed_work *work = NULL; |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9543 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9544 | mutex_lock(&priv->mutex); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9545 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9546 | priv->user_requested_scan = 1; |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9547 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9548 | if (wrqu->data.length == sizeof(struct iw_scan_req)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9549 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9550 | int len = min((int)req->essid_len, |
| 9551 | (int)sizeof(priv->direct_scan_ssid)); |
| 9552 | memcpy(priv->direct_scan_ssid, req->essid, len); |
| 9553 | priv->direct_scan_ssid_len = len; |
| 9554 | work = &priv->request_direct_scan; |
| 9555 | } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { |
| 9556 | work = &priv->request_passive_scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9557 | } |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9558 | } else { |
| 9559 | /* Normal active broadcast scan */ |
| 9560 | work = &priv->request_scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9561 | } |
James Ketrenos | 8935f39 | 2005-10-05 15:59:08 -0500 | [diff] [blame] | 9562 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9563 | mutex_unlock(&priv->mutex); |
| 9564 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9565 | IPW_DEBUG_WX("Start scan\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9566 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9567 | queue_delayed_work(priv->workqueue, work, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9568 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9569 | return 0; |
| 9570 | } |
| 9571 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9572 | static int ipw_wx_get_scan(struct net_device *dev, |
| 9573 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9574 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9575 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9576 | struct ipw_priv *priv = libipw_priv(dev); |
| 9577 | return libipw_wx_get_scan(priv->ieee, info, wrqu, extra); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9578 | } |
| 9579 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9580 | static int ipw_wx_set_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9581 | struct iw_request_info *info, |
| 9582 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9583 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9584 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9585 | int ret; |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9586 | u32 cap = priv->capability; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9587 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9588 | mutex_lock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9589 | ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9590 | |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9591 | /* In IBSS mode, we need to notify the firmware to update |
| 9592 | * the beacon info after we changed the capability. */ |
| 9593 | if (cap != priv->capability && |
| 9594 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 9595 | priv->status & STATUS_ASSOCIATED) |
| 9596 | ipw_disassociate(priv); |
| 9597 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9598 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9599 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9600 | } |
| 9601 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9602 | static int ipw_wx_get_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9603 | struct iw_request_info *info, |
| 9604 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9605 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9606 | struct ipw_priv *priv = libipw_priv(dev); |
| 9607 | return libipw_wx_get_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9608 | } |
| 9609 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9610 | static int ipw_wx_set_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9611 | struct iw_request_info *info, |
| 9612 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9613 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9614 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9615 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9616 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9617 | if (wrqu->power.disabled) { |
| 9618 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); |
| 9619 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); |
| 9620 | if (err) { |
| 9621 | IPW_DEBUG_WX("failed setting power mode.\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 err; |
| 9624 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9625 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9626 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9627 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9628 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9629 | |
| 9630 | switch (wrqu->power.flags & IW_POWER_MODE) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9631 | case IW_POWER_ON: /* If not specified */ |
| 9632 | case IW_POWER_MODE: /* If set all mask */ |
Jean Delvare | c03983a | 2007-10-19 23:22:55 +0200 | [diff] [blame] | 9633 | case IW_POWER_ALL_R: /* If explicitly state all */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9634 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9635 | default: /* Otherwise we don't support it */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9636 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
| 9637 | wrqu->power.flags); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9638 | mutex_unlock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9639 | return -EOPNOTSUPP; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9640 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9641 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9642 | /* If the user hasn't specified a power management mode yet, default |
| 9643 | * to BATTERY */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9644 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9645 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9646 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9647 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9648 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9649 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
| 9650 | if (err) { |
| 9651 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9652 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9653 | return err; |
| 9654 | } |
| 9655 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9656 | 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] | 9657 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9658 | return 0; |
| 9659 | } |
| 9660 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9661 | static int ipw_wx_get_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9662 | struct iw_request_info *info, |
| 9663 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9664 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9665 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9666 | mutex_lock(&priv->mutex); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9667 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9668 | wrqu->power.disabled = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9669 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9670 | wrqu->power.disabled = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9671 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9672 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9673 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9674 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9675 | return 0; |
| 9676 | } |
| 9677 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9678 | static int ipw_wx_set_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9679 | struct iw_request_info *info, |
| 9680 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9681 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9682 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9683 | int mode = *(int *)extra; |
| 9684 | int err; |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9685 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9686 | mutex_lock(&priv->mutex); |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9687 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9688 | mode = IPW_POWER_AC; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9689 | |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9690 | if (IPW_POWER_LEVEL(priv->power_mode) != mode) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9691 | err = ipw_send_power_mode(priv, mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9692 | if (err) { |
| 9693 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9694 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9695 | return err; |
| 9696 | } |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9697 | priv->power_mode = IPW_POWER_ENABLED | mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9698 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9699 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9700 | return 0; |
| 9701 | } |
| 9702 | |
| 9703 | #define MAX_WX_STRING 80 |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9704 | static int ipw_wx_get_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9705 | struct iw_request_info *info, |
| 9706 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9707 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9708 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9709 | int level = IPW_POWER_LEVEL(priv->power_mode); |
| 9710 | char *p = extra; |
| 9711 | |
| 9712 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); |
| 9713 | |
| 9714 | switch (level) { |
| 9715 | case IPW_POWER_AC: |
| 9716 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); |
| 9717 | break; |
| 9718 | case IPW_POWER_BATTERY: |
| 9719 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); |
| 9720 | break; |
| 9721 | default: |
| 9722 | p += snprintf(p, MAX_WX_STRING - (p - extra), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9723 | "(Timeout %dms, Period %dms)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9724 | timeout_duration[level - 1] / 1000, |
| 9725 | period_duration[level - 1] / 1000); |
| 9726 | } |
| 9727 | |
| 9728 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9729 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9730 | |
| 9731 | wrqu->data.length = p - extra + 1; |
| 9732 | |
| 9733 | return 0; |
| 9734 | } |
| 9735 | |
| 9736 | static int ipw_wx_set_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9737 | struct iw_request_info *info, |
| 9738 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9739 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9740 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9741 | int mode = *(int *)extra; |
| 9742 | u8 band = 0, modulation = 0; |
| 9743 | |
| 9744 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9745 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9746 | return -EINVAL; |
| 9747 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9748 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9749 | if (priv->adapter == IPW_2915ABG) { |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9750 | priv->ieee->abg_true = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9751 | if (mode & IEEE_A) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9752 | band |= LIBIPW_52GHZ_BAND; |
| 9753 | modulation |= LIBIPW_OFDM_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9754 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9755 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9756 | } else { |
| 9757 | if (mode & IEEE_A) { |
| 9758 | IPW_WARNING("Attempt to set 2200BG into " |
| 9759 | "802.11a mode\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9760 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9761 | return -EINVAL; |
| 9762 | } |
| 9763 | |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9764 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9765 | } |
| 9766 | |
| 9767 | if (mode & IEEE_B) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9768 | band |= LIBIPW_24GHZ_BAND; |
| 9769 | modulation |= LIBIPW_CCK_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9770 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9771 | priv->ieee->abg_true = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9772 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9773 | if (mode & IEEE_G) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9774 | band |= LIBIPW_24GHZ_BAND; |
| 9775 | modulation |= LIBIPW_OFDM_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9776 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9777 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9778 | |
| 9779 | priv->ieee->mode = mode; |
| 9780 | priv->ieee->freq_band = band; |
| 9781 | priv->ieee->modulation = modulation; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9782 | init_supported_rates(priv, &priv->rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9783 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9784 | /* Network configuration changed -- force [re]association */ |
| 9785 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); |
| 9786 | if (!ipw_disassociate(priv)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9787 | ipw_send_supported_rates(priv, &priv->rates); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9788 | ipw_associate(priv); |
| 9789 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9790 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9791 | /* Update the band LEDs */ |
| 9792 | ipw_led_band_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9793 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9794 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9795 | mode & IEEE_A ? 'a' : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9796 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9797 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9798 | return 0; |
| 9799 | } |
| 9800 | |
| 9801 | static int ipw_wx_get_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9802 | struct iw_request_info *info, |
| 9803 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9804 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9805 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9806 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9807 | switch (priv->ieee->mode) { |
| 9808 | case IEEE_A: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9809 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
| 9810 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9811 | case IEEE_B: |
| 9812 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); |
| 9813 | break; |
| 9814 | case IEEE_A | IEEE_B: |
| 9815 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); |
| 9816 | break; |
| 9817 | case IEEE_G: |
| 9818 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); |
| 9819 | break; |
| 9820 | case IEEE_A | IEEE_G: |
| 9821 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); |
| 9822 | break; |
| 9823 | case IEEE_B | IEEE_G: |
| 9824 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); |
| 9825 | break; |
| 9826 | case IEEE_A | IEEE_B | IEEE_G: |
| 9827 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); |
| 9828 | break; |
| 9829 | default: |
| 9830 | strncpy(extra, "unknown", MAX_WX_STRING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9831 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9832 | } |
| 9833 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9834 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
| 9835 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9836 | wrqu->data.length = strlen(extra) + 1; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9837 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9838 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9839 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9840 | } |
| 9841 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9842 | static int ipw_wx_set_preamble(struct net_device *dev, |
| 9843 | struct iw_request_info *info, |
| 9844 | union iwreq_data *wrqu, char *extra) |
| 9845 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9846 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9847 | int mode = *(int *)extra; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9848 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9849 | /* Switching from SHORT -> LONG requires a disassociation */ |
| 9850 | if (mode == 1) { |
| 9851 | if (!(priv->config & CFG_PREAMBLE_LONG)) { |
| 9852 | priv->config |= CFG_PREAMBLE_LONG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9853 | |
| 9854 | /* Network configuration changed -- force [re]association */ |
| 9855 | IPW_DEBUG_ASSOC |
| 9856 | ("[re]association triggered due to preamble change.\n"); |
| 9857 | if (!ipw_disassociate(priv)) |
| 9858 | ipw_associate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9859 | } |
| 9860 | goto done; |
| 9861 | } |
| 9862 | |
| 9863 | if (mode == 0) { |
| 9864 | priv->config &= ~CFG_PREAMBLE_LONG; |
| 9865 | goto done; |
| 9866 | } |
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 -EINVAL; |
| 9869 | |
| 9870 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9871 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9872 | return 0; |
| 9873 | } |
| 9874 | |
| 9875 | static int ipw_wx_get_preamble(struct net_device *dev, |
| 9876 | struct iw_request_info *info, |
| 9877 | union iwreq_data *wrqu, char *extra) |
| 9878 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9879 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9880 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9881 | if (priv->config & CFG_PREAMBLE_LONG) |
| 9882 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); |
| 9883 | else |
| 9884 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9885 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9886 | return 0; |
| 9887 | } |
| 9888 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9889 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9890 | static int ipw_wx_set_monitor(struct net_device *dev, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9891 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9892 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9893 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9894 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9895 | int *parms = (int *)extra; |
| 9896 | int enable = (parms[0] > 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9897 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9898 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9899 | if (enable) { |
| 9900 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 9901 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9902 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 9903 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9904 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9905 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9906 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9907 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9908 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9909 | ipw_set_channel(priv, parms[1]); |
| 9910 | } else { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9911 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9912 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9913 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9914 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9915 | priv->net_dev->type = ARPHRD_ETHER; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9916 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9917 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9918 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9919 | return 0; |
| 9920 | } |
| 9921 | |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 9922 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9923 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9924 | static int ipw_wx_reset(struct net_device *dev, |
| 9925 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9926 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9927 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9928 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9929 | IPW_DEBUG_WX("RESET\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9930 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9931 | return 0; |
| 9932 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9933 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9934 | static int ipw_wx_sw_reset(struct net_device *dev, |
| 9935 | struct iw_request_info *info, |
| 9936 | union iwreq_data *wrqu, char *extra) |
| 9937 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9938 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9939 | union iwreq_data wrqu_sec = { |
| 9940 | .encoding = { |
| 9941 | .flags = IW_ENCODE_DISABLED, |
| 9942 | }, |
| 9943 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9944 | int ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9945 | |
| 9946 | IPW_DEBUG_WX("SW_RESET\n"); |
| 9947 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9948 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9949 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 9950 | ret = ipw_sw_reset(priv, 2); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9951 | if (!ret) { |
| 9952 | free_firmware(); |
| 9953 | ipw_adapter_restart(priv); |
| 9954 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9955 | |
| 9956 | /* The SW reset bit might have been toggled on by the 'disable' |
| 9957 | * module parameter, so take appropriate action */ |
| 9958 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); |
| 9959 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9960 | mutex_unlock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9961 | libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9962 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9963 | |
| 9964 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 9965 | /* Configuration likely changed -- force [re]association */ |
| 9966 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " |
| 9967 | "reset.\n"); |
| 9968 | if (!ipw_disassociate(priv)) |
| 9969 | ipw_associate(priv); |
| 9970 | } |
| 9971 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9972 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9973 | |
| 9974 | return 0; |
| 9975 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9976 | |
| 9977 | /* Rebase the WE IOCTLs to zero for the handler array */ |
| 9978 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9979 | static iw_handler ipw_wx_handlers[] = { |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 9980 | IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9981 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, |
| 9982 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, |
| 9983 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, |
| 9984 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9985 | IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens, |
| 9986 | IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9987 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
| 9988 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, |
| 9989 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, |
| 9990 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, |
| 9991 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, |
| 9992 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, |
| 9993 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, |
| 9994 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, |
| 9995 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, |
| 9996 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, |
| 9997 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, |
| 9998 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, |
| 9999 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, |
| 10000 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, |
| 10001 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, |
| 10002 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, |
| 10003 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, |
| 10004 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, |
| 10005 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, |
| 10006 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, |
| 10007 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, |
| 10008 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, |
| 10009 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10010 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
| 10011 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, |
| 10012 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, |
| 10013 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10014 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
| 10015 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, |
| 10016 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, |
| 10017 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, |
| 10018 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, |
| 10019 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, |
| 10020 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10021 | }; |
| 10022 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10023 | enum { |
| 10024 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, |
| 10025 | IPW_PRIV_GET_POWER, |
| 10026 | IPW_PRIV_SET_MODE, |
| 10027 | IPW_PRIV_GET_MODE, |
| 10028 | IPW_PRIV_SET_PREAMBLE, |
| 10029 | IPW_PRIV_GET_PREAMBLE, |
| 10030 | IPW_PRIV_RESET, |
| 10031 | IPW_PRIV_SW_RESET, |
| 10032 | #ifdef CONFIG_IPW2200_MONITOR |
| 10033 | IPW_PRIV_SET_MONITOR, |
| 10034 | #endif |
| 10035 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10036 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10037 | static struct iw_priv_args ipw_priv_args[] = { |
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_SET_POWER, |
| 10040 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10041 | .name = "set_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_GET_POWER, |
| 10044 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 10045 | .name = "get_power"}, |
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_SET_MODE, |
| 10048 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10049 | .name = "set_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10050 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10051 | .cmd = IPW_PRIV_GET_MODE, |
| 10052 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 10053 | .name = "get_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10054 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10055 | .cmd = IPW_PRIV_SET_PREAMBLE, |
| 10056 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10057 | .name = "set_preamble"}, |
| 10058 | { |
| 10059 | .cmd = IPW_PRIV_GET_PREAMBLE, |
| 10060 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, |
| 10061 | .name = "get_preamble"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10062 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10063 | IPW_PRIV_RESET, |
| 10064 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10065 | { |
| 10066 | IPW_PRIV_SW_RESET, |
| 10067 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, |
| 10068 | #ifdef CONFIG_IPW2200_MONITOR |
| 10069 | { |
| 10070 | IPW_PRIV_SET_MONITOR, |
| 10071 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, |
| 10072 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10073 | }; |
| 10074 | |
| 10075 | static iw_handler ipw_priv_handler[] = { |
| 10076 | ipw_wx_set_powermode, |
| 10077 | ipw_wx_get_powermode, |
| 10078 | ipw_wx_set_wireless_mode, |
| 10079 | ipw_wx_get_wireless_mode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10080 | ipw_wx_set_preamble, |
| 10081 | ipw_wx_get_preamble, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10082 | ipw_wx_reset, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10083 | ipw_wx_sw_reset, |
| 10084 | #ifdef CONFIG_IPW2200_MONITOR |
| 10085 | ipw_wx_set_monitor, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10086 | #endif |
| 10087 | }; |
| 10088 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10089 | static struct iw_handler_def ipw_wx_handler_def = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10090 | .standard = ipw_wx_handlers, |
| 10091 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), |
| 10092 | .num_private = ARRAY_SIZE(ipw_priv_handler), |
| 10093 | .num_private_args = ARRAY_SIZE(ipw_priv_args), |
| 10094 | .private = ipw_priv_handler, |
| 10095 | .private_args = ipw_priv_args, |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 10096 | .get_wireless_stats = ipw_get_wireless_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10097 | }; |
| 10098 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10099 | /* |
| 10100 | * Get wireless statistics. |
| 10101 | * Called by /proc/net/wireless |
| 10102 | * Also called by SIOCGIWSTATS |
| 10103 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10104 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10105 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10106 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10107 | struct iw_statistics *wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10108 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10109 | wstats = &priv->wstats; |
| 10110 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10111 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10112 | * netdev->get_wireless_stats seems to be called before fw is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10113 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
| 10114 | * and associated; if not associcated, the values are all meaningless |
| 10115 | * anyway, so set them all to NULL and INVALID */ |
| 10116 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 10117 | wstats->miss.beacon = 0; |
| 10118 | wstats->discard.retries = 0; |
| 10119 | wstats->qual.qual = 0; |
| 10120 | wstats->qual.level = 0; |
| 10121 | wstats->qual.noise = 0; |
| 10122 | wstats->qual.updated = 7; |
| 10123 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10124 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10125 | return wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10126 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10127 | |
| 10128 | wstats->qual.qual = priv->quality; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 10129 | wstats->qual.level = priv->exp_avg_rssi; |
| 10130 | wstats->qual.noise = priv->exp_avg_noise; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10131 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 10132 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10133 | |
| 10134 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); |
| 10135 | wstats->discard.retries = priv->last_tx_failures; |
| 10136 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; |
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 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
| 10139 | goto fail_get_ordinal; |
| 10140 | wstats->discard.retries += tx_retry; */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10141 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10142 | return wstats; |
| 10143 | } |
| 10144 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10145 | /* net device stuff */ |
| 10146 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 10147 | static void init_sys_config(struct ipw_sys_config *sys_config) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10148 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10149 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10150 | sys_config->bt_coexistence = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10151 | sys_config->answer_broadcast_ssid_probe = 0; |
| 10152 | sys_config->accept_all_data_frames = 0; |
| 10153 | sys_config->accept_non_directed_frames = 1; |
| 10154 | sys_config->exclude_unicast_unencrypted = 0; |
| 10155 | sys_config->disable_unicast_decryption = 1; |
| 10156 | sys_config->exclude_multicast_unencrypted = 0; |
| 10157 | sys_config->disable_multicast_decryption = 1; |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 10158 | if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B) |
| 10159 | antenna = CFG_SYS_ANTENNA_BOTH; |
| 10160 | sys_config->antenna_diversity = antenna; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10161 | 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] | 10162 | sys_config->dot11g_auto_detection = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10163 | sys_config->enable_cts_to_self = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10164 | sys_config->bt_coexist_collision_thr = 0; |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 10165 | 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] | 10166 | sys_config->silence_threshold = 0x1e; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10167 | } |
| 10168 | |
| 10169 | static int ipw_net_open(struct net_device *dev) |
| 10170 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10171 | IPW_DEBUG_INFO("dev->open\n"); |
David S. Miller | 521c4d9 | 2008-07-22 18:32:47 -0700 | [diff] [blame] | 10172 | netif_start_queue(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10173 | return 0; |
| 10174 | } |
| 10175 | |
| 10176 | static int ipw_net_stop(struct net_device *dev) |
| 10177 | { |
| 10178 | IPW_DEBUG_INFO("dev->close\n"); |
| 10179 | netif_stop_queue(dev); |
| 10180 | return 0; |
| 10181 | } |
| 10182 | |
| 10183 | /* |
| 10184 | todo: |
| 10185 | |
| 10186 | 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] | 10187 | we need to heavily modify the libipw_skb_to_txb. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10188 | */ |
| 10189 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10190 | 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] | 10191 | int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10192 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10193 | struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10194 | txb->fragments[0]->data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10195 | int i = 0; |
| 10196 | struct tfd_frame *tfd; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10197 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10198 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10199 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10200 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10201 | struct clx2_tx_queue *txq = &priv->txq[0]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10202 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10203 | struct clx2_queue *q = &txq->q; |
| 10204 | u8 id, hdr_len, unicast; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10205 | int fc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10206 | |
Zhu Yi | b8ddafd | 2008-11-27 13:42:20 +0800 | [diff] [blame] | 10207 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 10208 | goto drop; |
| 10209 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10210 | hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10211 | switch (priv->ieee->iw_mode) { |
| 10212 | case IW_MODE_ADHOC: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10213 | unicast = !is_multicast_ether_addr(hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10214 | id = ipw_find_station(priv, hdr->addr1); |
| 10215 | if (id == IPW_INVALID_STATION) { |
| 10216 | id = ipw_add_station(priv, hdr->addr1); |
| 10217 | if (id == IPW_INVALID_STATION) { |
| 10218 | IPW_WARNING("Attempt to send data to " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 10219 | "invalid cell: %pM\n", |
| 10220 | hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10221 | goto drop; |
| 10222 | } |
| 10223 | } |
| 10224 | break; |
| 10225 | |
| 10226 | case IW_MODE_INFRA: |
| 10227 | default: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10228 | unicast = !is_multicast_ether_addr(hdr->addr3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10229 | id = 0; |
| 10230 | break; |
| 10231 | } |
| 10232 | |
| 10233 | tfd = &txq->bd[q->first_empty]; |
| 10234 | txq->txb[q->first_empty] = txb; |
| 10235 | memset(tfd, 0, sizeof(*tfd)); |
| 10236 | tfd->u.data.station_number = id; |
| 10237 | |
| 10238 | tfd->control_flags.message_type = TX_FRAME_TYPE; |
| 10239 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 10240 | |
| 10241 | tfd->u.data.cmd_id = DINO_CMD_TX; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10242 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10243 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10244 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10245 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10246 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10247 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10248 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10249 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
| 10250 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10251 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10252 | fc = le16_to_cpu(hdr->frame_ctl); |
| 10253 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10254 | |
| 10255 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); |
| 10256 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10257 | if (likely(unicast)) |
| 10258 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10259 | |
| 10260 | if (txb->encrypted && !priv->ieee->host_encrypt) { |
| 10261 | switch (priv->ieee->sec.level) { |
| 10262 | case SEC_LEVEL_3: |
| 10263 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10264 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10265 | /* XXX: ACK flag must be set for CCMP even if it |
| 10266 | * is a multicast/broadcast packet, because CCMP |
| 10267 | * group communication encrypted by GTK is |
| 10268 | * actually done by the AP. */ |
| 10269 | if (!unicast) |
| 10270 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10271 | |
| 10272 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10273 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; |
| 10274 | tfd->u.data.key_index = 0; |
| 10275 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10276 | break; |
| 10277 | case SEC_LEVEL_2: |
| 10278 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10279 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10280 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10281 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; |
| 10282 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10283 | break; |
| 10284 | case SEC_LEVEL_1: |
| 10285 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10286 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 10287 | tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx; |
| 10288 | if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <= |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10289 | 40) |
| 10290 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; |
| 10291 | else |
| 10292 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; |
| 10293 | break; |
| 10294 | case SEC_LEVEL_0: |
| 10295 | break; |
| 10296 | default: |
| 10297 | printk(KERN_ERR "Unknow security level %d\n", |
| 10298 | priv->ieee->sec.level); |
| 10299 | break; |
| 10300 | } |
| 10301 | } else |
| 10302 | /* No hardware encryption */ |
| 10303 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; |
| 10304 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10305 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 10306 | if (fc & IEEE80211_STYPE_QOS_DATA) |
| 10307 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data)); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10308 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10309 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10310 | /* payload */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10311 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
| 10312 | txb->nr_frags)); |
| 10313 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", |
| 10314 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); |
| 10315 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { |
| 10316 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", |
| 10317 | i, le32_to_cpu(tfd->u.data.num_chunks), |
| 10318 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10319 | 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] | 10320 | i, tfd->u.data.num_chunks, |
| 10321 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10322 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10323 | txb->fragments[i]->len - hdr_len); |
| 10324 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10325 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10326 | cpu_to_le32(pci_map_single |
| 10327 | (priv->pci_dev, |
| 10328 | txb->fragments[i]->data + hdr_len, |
| 10329 | txb->fragments[i]->len - hdr_len, |
| 10330 | PCI_DMA_TODEVICE)); |
| 10331 | tfd->u.data.chunk_len[i] = |
| 10332 | cpu_to_le16(txb->fragments[i]->len - hdr_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10333 | } |
| 10334 | |
| 10335 | if (i != txb->nr_frags) { |
| 10336 | struct sk_buff *skb; |
| 10337 | u16 remaining_bytes = 0; |
| 10338 | int j; |
| 10339 | |
| 10340 | for (j = i; j < txb->nr_frags; j++) |
| 10341 | remaining_bytes += txb->fragments[j]->len - hdr_len; |
| 10342 | |
| 10343 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", |
| 10344 | remaining_bytes); |
| 10345 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); |
| 10346 | if (skb != NULL) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10347 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10348 | for (j = i; j < txb->nr_frags; j++) { |
| 10349 | int size = txb->fragments[j]->len - hdr_len; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10350 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10351 | printk(KERN_INFO "Adding frag %d %d...\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10352 | j, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10353 | memcpy(skb_put(skb, size), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10354 | txb->fragments[j]->data + hdr_len, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10355 | } |
| 10356 | dev_kfree_skb_any(txb->fragments[i]); |
| 10357 | txb->fragments[i] = skb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10358 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10359 | cpu_to_le32(pci_map_single |
| 10360 | (priv->pci_dev, skb->data, |
Al Viro | 4958730 | 2007-12-27 01:57:47 -0500 | [diff] [blame] | 10361 | remaining_bytes, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10362 | PCI_DMA_TODEVICE)); |
| 10363 | |
Marcin Slusarz | 5c05863 | 2008-02-13 00:06:12 +0100 | [diff] [blame] | 10364 | le32_add_cpu(&tfd->u.data.num_chunks, 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10365 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10366 | } |
| 10367 | |
| 10368 | /* kick DMA */ |
| 10369 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 10370 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 10371 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 10372 | if (ipw_tx_queue_space(q) < q->high_mark) |
James Ketrenos | f697014 | 2006-02-14 09:10:51 +0800 | [diff] [blame] | 10373 | netif_stop_queue(priv->net_dev); |
| 10374 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10375 | return NETDEV_TX_OK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10376 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10377 | drop: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10378 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10379 | libipw_txb_free(txb); |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10380 | return NETDEV_TX_OK; |
| 10381 | } |
| 10382 | |
| 10383 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) |
| 10384 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10385 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10386 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10387 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10388 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10389 | #else |
| 10390 | struct clx2_tx_queue *txq = &priv->txq[0]; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10391 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10392 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 10393 | if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark) |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10394 | return 1; |
| 10395 | |
| 10396 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10397 | } |
| 10398 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10399 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10400 | static void ipw_handle_promiscuous_tx(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10401 | struct libipw_txb *txb) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10402 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10403 | struct libipw_rx_stats dummystats; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10404 | struct ieee80211_hdr *hdr; |
| 10405 | u8 n; |
| 10406 | u16 filter = priv->prom_priv->filter; |
| 10407 | int hdr_only = 0; |
| 10408 | |
| 10409 | if (filter & IPW_PROM_NO_TX) |
| 10410 | return; |
| 10411 | |
| 10412 | memset(&dummystats, 0, sizeof(dummystats)); |
| 10413 | |
| 10414 | /* Filtering of fragment chains is done agains the first fragment */ |
| 10415 | hdr = (void *)txb->fragments[0]->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10416 | if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10417 | if (filter & IPW_PROM_NO_MGMT) |
| 10418 | return; |
| 10419 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 10420 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10421 | } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10422 | if (filter & IPW_PROM_NO_CTL) |
| 10423 | return; |
| 10424 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 10425 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10426 | } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10427 | if (filter & IPW_PROM_NO_DATA) |
| 10428 | return; |
| 10429 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 10430 | hdr_only = 1; |
| 10431 | } |
| 10432 | |
| 10433 | for(n=0; n<txb->nr_frags; ++n) { |
| 10434 | struct sk_buff *src = txb->fragments[n]; |
| 10435 | struct sk_buff *dst; |
| 10436 | struct ieee80211_radiotap_header *rt_hdr; |
| 10437 | int len; |
| 10438 | |
| 10439 | if (hdr_only) { |
| 10440 | hdr = (void *)src->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10441 | len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10442 | } else |
| 10443 | len = src->len; |
| 10444 | |
Johannes Berg | 007e5dd | 2008-11-27 23:13:38 +0100 | [diff] [blame] | 10445 | dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC); |
| 10446 | if (!dst) |
| 10447 | continue; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10448 | |
| 10449 | rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr)); |
| 10450 | |
| 10451 | rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION; |
| 10452 | rt_hdr->it_pad = 0; |
| 10453 | rt_hdr->it_present = 0; /* after all, it's just an idea */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 10454 | rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10455 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10456 | *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16( |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10457 | ieee80211chan2mhz(priv->channel)); |
| 10458 | if (priv->channel > 14) /* 802.11a */ |
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_OFDM | |
| 10461 | IEEE80211_CHAN_5GHZ); |
| 10462 | else if (priv->ieee->mode == IEEE_B) /* 802.11b */ |
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_CCK | |
| 10465 | IEEE80211_CHAN_2GHZ); |
| 10466 | else /* 802.11g */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10467 | *(__le16*)skb_put(dst, sizeof(u16)) = |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10468 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10469 | IEEE80211_CHAN_2GHZ); |
| 10470 | |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 10471 | rt_hdr->it_len = cpu_to_le16(dst->len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10472 | |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 10473 | skb_copy_from_linear_data(src, skb_put(dst, len), len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10474 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10475 | if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats)) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10476 | dev_kfree_skb_any(dst); |
| 10477 | } |
| 10478 | } |
| 10479 | #endif |
| 10480 | |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 10481 | static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb, |
| 10482 | struct net_device *dev, int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10483 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10484 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10485 | unsigned long flags; |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 10486 | netdev_tx_t ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10487 | |
| 10488 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10489 | spin_lock_irqsave(&priv->lock, flags); |
| 10490 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10491 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10492 | if (rtap_iface && netif_running(priv->prom_net_dev)) |
| 10493 | ipw_handle_promiscuous_tx(priv, txb); |
| 10494 | #endif |
| 10495 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10496 | ret = ipw_tx_skb(priv, txb, pri); |
| 10497 | if (ret == NETDEV_TX_OK) |
| 10498 | __ipw_led_activity_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10499 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10500 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10501 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10502 | } |
| 10503 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10504 | static void ipw_net_set_multicast_list(struct net_device *dev) |
| 10505 | { |
| 10506 | |
| 10507 | } |
| 10508 | |
| 10509 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) |
| 10510 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10511 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10512 | struct sockaddr *addr = p; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 10513 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10514 | if (!is_valid_ether_addr(addr->sa_data)) |
| 10515 | return -EADDRNOTAVAIL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10516 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10517 | priv->config |= CFG_CUSTOM_MAC; |
| 10518 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 10519 | printk(KERN_INFO "%s: Setting MAC to %pM\n", |
| 10520 | priv->net_dev->name, priv->mac_addr); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10521 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10522 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10523 | return 0; |
| 10524 | } |
| 10525 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10526 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10527 | struct ethtool_drvinfo *info) |
| 10528 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10529 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10530 | char vers[64]; |
| 10531 | char date[32]; |
| 10532 | u32 len; |
| 10533 | |
| 10534 | strcpy(info->driver, DRV_NAME); |
| 10535 | strcpy(info->version, DRV_VERSION); |
| 10536 | |
| 10537 | len = sizeof(vers); |
| 10538 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); |
| 10539 | len = sizeof(date); |
| 10540 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); |
| 10541 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10542 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10543 | vers, date); |
| 10544 | strcpy(info->bus_info, pci_name(p->pci_dev)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10545 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10546 | } |
| 10547 | |
| 10548 | static u32 ipw_ethtool_get_link(struct net_device *dev) |
| 10549 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10550 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10551 | return (priv->status & STATUS_ASSOCIATED) != 0; |
| 10552 | } |
| 10553 | |
| 10554 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) |
| 10555 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10556 | return IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10557 | } |
| 10558 | |
| 10559 | static int ipw_ethtool_get_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10560 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10561 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10562 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10563 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10564 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10565 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10566 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10567 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10568 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10569 | return 0; |
| 10570 | } |
| 10571 | |
| 10572 | static int ipw_ethtool_set_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10573 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10574 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10575 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10576 | int i; |
| 10577 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10578 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10579 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10580 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10581 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
Adrian Bunk | 71e585f | 2006-03-11 04:42:58 +0100 | [diff] [blame] | 10582 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
| 10583 | ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10584 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10585 | return 0; |
| 10586 | } |
| 10587 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 10588 | static const struct ethtool_ops ipw_ethtool_ops = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10589 | .get_link = ipw_ethtool_get_link, |
| 10590 | .get_drvinfo = ipw_ethtool_get_drvinfo, |
| 10591 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, |
| 10592 | .get_eeprom = ipw_ethtool_get_eeprom, |
| 10593 | .set_eeprom = ipw_ethtool_set_eeprom, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10594 | }; |
| 10595 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 10596 | static irqreturn_t ipw_isr(int irq, void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10597 | { |
| 10598 | struct ipw_priv *priv = data; |
| 10599 | u32 inta, inta_mask; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10600 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10601 | if (!priv) |
| 10602 | return IRQ_NONE; |
| 10603 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10604 | spin_lock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10605 | |
| 10606 | if (!(priv->status & STATUS_INT_ENABLED)) { |
Zhu Yi | d00d012 | 2007-07-12 16:09:40 +0800 | [diff] [blame] | 10607 | /* IRQ is disabled */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10608 | goto none; |
| 10609 | } |
| 10610 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10611 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 10612 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10613 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10614 | if (inta == 0xFFFFFFFF) { |
| 10615 | /* Hardware disappeared */ |
| 10616 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); |
| 10617 | goto none; |
| 10618 | } |
| 10619 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10620 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10621 | /* Shared interrupt */ |
| 10622 | goto none; |
| 10623 | } |
| 10624 | |
| 10625 | /* tell the device to stop sending interrupts */ |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10626 | __ipw_disable_interrupts(priv); |
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 | /* ack current interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10629 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
| 10630 | ipw_write32(priv, IPW_INTA_RW, inta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10631 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10632 | /* Cache INTA value for our tasklet */ |
| 10633 | priv->isr_inta = inta; |
| 10634 | |
| 10635 | tasklet_schedule(&priv->irq_tasklet); |
| 10636 | |
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 | |
| 10639 | return IRQ_HANDLED; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10640 | none: |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10641 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10642 | return IRQ_NONE; |
| 10643 | } |
| 10644 | |
| 10645 | static void ipw_rf_kill(void *adapter) |
| 10646 | { |
| 10647 | struct ipw_priv *priv = adapter; |
| 10648 | unsigned long flags; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10649 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10650 | spin_lock_irqsave(&priv->lock, flags); |
| 10651 | |
| 10652 | if (rf_kill_active(priv)) { |
| 10653 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); |
| 10654 | if (priv->workqueue) |
| 10655 | queue_delayed_work(priv->workqueue, |
| 10656 | &priv->rf_kill, 2 * HZ); |
| 10657 | goto exit_unlock; |
| 10658 | } |
| 10659 | |
| 10660 | /* RF Kill is now disabled, so bring the device back up */ |
| 10661 | |
| 10662 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 10663 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " |
| 10664 | "device\n"); |
| 10665 | |
| 10666 | /* we can not do an adapter restart while inside an irq lock */ |
| 10667 | queue_work(priv->workqueue, &priv->adapter_restart); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10668 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10669 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
| 10670 | "enabled\n"); |
| 10671 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10672 | exit_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10673 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10674 | } |
| 10675 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10676 | static void ipw_bg_rf_kill(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10677 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10678 | struct ipw_priv *priv = |
| 10679 | container_of(work, struct ipw_priv, rf_kill.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10680 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10681 | ipw_rf_kill(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10682 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10683 | } |
| 10684 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10685 | static void ipw_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10686 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10687 | priv->last_seq_num = -1; |
| 10688 | priv->last_frag_num = -1; |
| 10689 | priv->last_packet_time = 0; |
| 10690 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10691 | netif_carrier_on(priv->net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10692 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10693 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10694 | cancel_delayed_work(&priv->request_direct_scan); |
| 10695 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10696 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10697 | ipw_reset_stats(priv); |
| 10698 | /* Ensure the rate is updated immediately */ |
| 10699 | priv->last_rate = ipw_get_current_rate(priv); |
| 10700 | ipw_gather_stats(priv); |
| 10701 | ipw_led_link_up(priv); |
| 10702 | notify_wx_assoc_event(priv); |
| 10703 | |
| 10704 | if (priv->config & CFG_BACKGROUND_SCAN) |
| 10705 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); |
| 10706 | } |
| 10707 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10708 | static void ipw_bg_link_up(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10709 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10710 | struct ipw_priv *priv = |
| 10711 | container_of(work, struct ipw_priv, link_up); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10712 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10713 | ipw_link_up(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10714 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10715 | } |
| 10716 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10717 | static void ipw_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10718 | { |
| 10719 | ipw_led_link_down(priv); |
| 10720 | netif_carrier_off(priv->net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10721 | notify_wx_assoc_event(priv); |
| 10722 | |
| 10723 | /* Cancel any queued work ... */ |
| 10724 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10725 | cancel_delayed_work(&priv->request_direct_scan); |
| 10726 | cancel_delayed_work(&priv->request_passive_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10727 | cancel_delayed_work(&priv->adhoc_check); |
| 10728 | cancel_delayed_work(&priv->gather_stats); |
| 10729 | |
| 10730 | ipw_reset_stats(priv); |
| 10731 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10732 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
| 10733 | /* Queue up another scan... */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10734 | queue_delayed_work(priv->workqueue, &priv->request_scan, 0); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10735 | } else |
| 10736 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10737 | } |
| 10738 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10739 | static void ipw_bg_link_down(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10740 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10741 | struct ipw_priv *priv = |
| 10742 | container_of(work, struct ipw_priv, link_down); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10743 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10744 | ipw_link_down(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10745 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10746 | } |
| 10747 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 10748 | static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10749 | { |
| 10750 | int ret = 0; |
| 10751 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10752 | priv->workqueue = create_workqueue(DRV_NAME); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10753 | init_waitqueue_head(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10754 | init_waitqueue_head(&priv->wait_state); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10755 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10756 | INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check); |
| 10757 | INIT_WORK(&priv->associate, ipw_bg_associate); |
| 10758 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate); |
| 10759 | INIT_WORK(&priv->system_config, ipw_system_config); |
| 10760 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish); |
| 10761 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart); |
| 10762 | INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill); |
| 10763 | INIT_WORK(&priv->up, ipw_bg_up); |
| 10764 | INIT_WORK(&priv->down, ipw_bg_down); |
| 10765 | INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10766 | INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan); |
| 10767 | INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10768 | INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10769 | INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats); |
| 10770 | INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan); |
| 10771 | INIT_WORK(&priv->roam, ipw_bg_roam); |
| 10772 | INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check); |
| 10773 | INIT_WORK(&priv->link_up, ipw_bg_link_up); |
| 10774 | INIT_WORK(&priv->link_down, ipw_bg_link_down); |
| 10775 | INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on); |
| 10776 | INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off); |
| 10777 | INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off); |
| 10778 | INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10779 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10780 | #ifdef CONFIG_IPW2200_QOS |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10781 | INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10782 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10783 | |
| 10784 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 10785 | ipw_irq_tasklet, (unsigned long)priv); |
| 10786 | |
| 10787 | return ret; |
| 10788 | } |
| 10789 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10790 | static void shim__set_security(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10791 | struct libipw_security *sec) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10792 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10793 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10794 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10795 | for (i = 0; i < 4; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10796 | if (sec->flags & (1 << i)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10797 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10798 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10799 | if (sec->key_sizes[i] == 0) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10800 | priv->ieee->sec.flags &= ~(1 << i); |
| 10801 | else { |
| 10802 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10803 | sec->key_sizes[i]); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10804 | priv->ieee->sec.flags |= (1 << i); |
| 10805 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10806 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10807 | } else if (sec->level != SEC_LEVEL_1) |
| 10808 | priv->ieee->sec.flags &= ~(1 << i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10809 | } |
| 10810 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10811 | if (sec->flags & SEC_ACTIVE_KEY) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10812 | if (sec->active_key <= 3) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10813 | priv->ieee->sec.active_key = sec->active_key; |
| 10814 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10815 | } else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10816 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10817 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10818 | } else |
| 10819 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10820 | |
| 10821 | if ((sec->flags & SEC_AUTH_MODE) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10822 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
| 10823 | priv->ieee->sec.auth_mode = sec->auth_mode; |
| 10824 | priv->ieee->sec.flags |= SEC_AUTH_MODE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10825 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
| 10826 | priv->capability |= CAP_SHARED_KEY; |
| 10827 | else |
| 10828 | priv->capability &= ~CAP_SHARED_KEY; |
| 10829 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10830 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10831 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10832 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
| 10833 | priv->ieee->sec.flags |= SEC_ENABLED; |
| 10834 | priv->ieee->sec.enabled = sec->enabled; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10835 | priv->status |= STATUS_SECURITY_UPDATED; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10836 | if (sec->enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10837 | priv->capability |= CAP_PRIVACY_ON; |
| 10838 | else |
| 10839 | priv->capability &= ~CAP_PRIVACY_ON; |
| 10840 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10841 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10842 | if (sec->flags & SEC_ENCRYPT) |
| 10843 | priv->ieee->sec.encrypt = sec->encrypt; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10844 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10845 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
| 10846 | priv->ieee->sec.level = sec->level; |
| 10847 | priv->ieee->sec.flags |= SEC_LEVEL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10848 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10849 | } |
| 10850 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 10851 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
| 10852 | ipw_set_hwcrypto_keys(priv); |
| 10853 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10854 | /* To match current functionality of ipw2100 (which works well w/ |
| 10855 | * various supplicants, we don't force a disassociate if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10856 | * privacy capability changes ... */ |
| 10857 | #if 0 |
| 10858 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10859 | (((priv->assoc_request.capability & |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 10860 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10861 | (!(priv->assoc_request.capability & |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 10862 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10863 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
| 10864 | "change.\n"); |
| 10865 | ipw_disassociate(priv); |
| 10866 | } |
| 10867 | #endif |
| 10868 | } |
| 10869 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10870 | static int init_supported_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10871 | struct ipw_supported_rates *rates) |
| 10872 | { |
| 10873 | /* TODO: Mask out rates based on priv->rates_mask */ |
| 10874 | |
| 10875 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10876 | /* configure supported rates */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10877 | switch (priv->ieee->freq_band) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10878 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10879 | rates->ieee_mode = IPW_A_MODE; |
| 10880 | rates->purpose = IPW_RATE_CAPABILITIES; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10881 | ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10882 | LIBIPW_OFDM_DEFAULT_RATES_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10883 | break; |
| 10884 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10885 | default: /* Mixed or 2.4Ghz */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10886 | rates->ieee_mode = IPW_G_MODE; |
| 10887 | rates->purpose = IPW_RATE_CAPABILITIES; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10888 | ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10889 | LIBIPW_CCK_DEFAULT_RATES_MASK); |
| 10890 | if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) { |
| 10891 | ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10892 | LIBIPW_OFDM_DEFAULT_RATES_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10893 | } |
| 10894 | break; |
| 10895 | } |
| 10896 | |
| 10897 | return 0; |
| 10898 | } |
| 10899 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10900 | static int ipw_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10901 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10902 | /* This is only called from ipw_up, which resets/reloads the firmware |
| 10903 | so, we don't need to first disable the card before we configure |
| 10904 | it */ |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 10905 | if (ipw_set_tx_power(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10906 | goto error; |
| 10907 | |
| 10908 | /* initialize adapter address */ |
| 10909 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) |
| 10910 | goto error; |
| 10911 | |
| 10912 | /* set basic system config settings */ |
| 10913 | init_sys_config(&priv->sys_config); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10914 | |
| 10915 | /* Support Bluetooth if we have BT h/w on board, and user wants to. |
| 10916 | * Does not support BT priority yet (don't abort or defer our Tx) */ |
| 10917 | if (bt_coexist) { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10918 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10919 | |
| 10920 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) |
| 10921 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10922 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10923 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
| 10924 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10925 | |= CFG_BT_COEXISTENCE_OOB; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10926 | } |
| 10927 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10928 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10929 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 10930 | priv->sys_config.accept_all_data_frames = 1; |
| 10931 | priv->sys_config.accept_non_directed_frames = 1; |
| 10932 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 10933 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 10934 | } |
| 10935 | #endif |
| 10936 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10937 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 10938 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 10939 | else |
| 10940 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 10941 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10942 | if (ipw_send_system_config(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10943 | goto error; |
| 10944 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10945 | init_supported_rates(priv, &priv->rates); |
| 10946 | if (ipw_send_supported_rates(priv, &priv->rates)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10947 | goto error; |
| 10948 | |
| 10949 | /* Set request-to-send threshold */ |
| 10950 | if (priv->rts_threshold) { |
| 10951 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) |
| 10952 | goto error; |
| 10953 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10954 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10955 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
| 10956 | ipw_qos_activate(priv, NULL); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10957 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10958 | |
| 10959 | if (ipw_set_random_seed(priv)) |
| 10960 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10961 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10962 | /* final state transition to the RUN state */ |
| 10963 | if (ipw_send_host_complete(priv)) |
| 10964 | goto error; |
| 10965 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10966 | priv->status |= STATUS_INIT; |
| 10967 | |
| 10968 | ipw_led_init(priv); |
| 10969 | ipw_led_radio_on(priv); |
| 10970 | priv->notif_missed_beacons = 0; |
| 10971 | |
| 10972 | /* Set hardware WEP key if it is configured. */ |
| 10973 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 10974 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 10975 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 10976 | ipw_set_hwcrypto_keys(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10977 | |
| 10978 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10979 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10980 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10981 | return -EIO; |
| 10982 | } |
| 10983 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10984 | /* |
| 10985 | * NOTE: |
| 10986 | * |
| 10987 | * These tables have been tested in conjunction with the |
| 10988 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. |
| 10989 | * |
| 10990 | * Altering this values, using it on other hardware, or in geographies |
| 10991 | * not intended for resale of the above mentioned Intel adapters has |
| 10992 | * not been tested. |
| 10993 | * |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 10994 | * Remember to update the table in README.ipw2200 when changing this |
| 10995 | * table. |
| 10996 | * |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10997 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10998 | static const struct libipw_geo ipw_geos[] = { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10999 | { /* Restricted */ |
| 11000 | "---", |
| 11001 | .bg_channels = 11, |
| 11002 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11003 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11004 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11005 | {2457, 10}, {2462, 11}}, |
| 11006 | }, |
| 11007 | |
| 11008 | { /* Custom US/Canada */ |
| 11009 | "ZZF", |
| 11010 | .bg_channels = 11, |
| 11011 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11012 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11013 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11014 | {2457, 10}, {2462, 11}}, |
| 11015 | .a_channels = 8, |
| 11016 | .a = {{5180, 36}, |
| 11017 | {5200, 40}, |
| 11018 | {5220, 44}, |
| 11019 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11020 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11021 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11022 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11023 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11024 | }, |
| 11025 | |
| 11026 | { /* Rest of World */ |
| 11027 | "ZZD", |
| 11028 | .bg_channels = 13, |
| 11029 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11030 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11031 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11032 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11033 | {2472, 13}}, |
| 11034 | }, |
| 11035 | |
| 11036 | { /* Custom USA & Europe & High */ |
| 11037 | "ZZA", |
| 11038 | .bg_channels = 11, |
| 11039 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11040 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11041 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11042 | {2457, 10}, {2462, 11}}, |
| 11043 | .a_channels = 13, |
| 11044 | .a = {{5180, 36}, |
| 11045 | {5200, 40}, |
| 11046 | {5220, 44}, |
| 11047 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11048 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11049 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11050 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11051 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11052 | {5745, 149}, |
| 11053 | {5765, 153}, |
| 11054 | {5785, 157}, |
| 11055 | {5805, 161}, |
| 11056 | {5825, 165}}, |
| 11057 | }, |
| 11058 | |
| 11059 | { /* Custom NA & Europe */ |
| 11060 | "ZZB", |
| 11061 | .bg_channels = 11, |
| 11062 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11063 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11064 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11065 | {2457, 10}, {2462, 11}}, |
| 11066 | .a_channels = 13, |
| 11067 | .a = {{5180, 36}, |
| 11068 | {5200, 40}, |
| 11069 | {5220, 44}, |
| 11070 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11071 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11072 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11073 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11074 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11075 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11076 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11077 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11078 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11079 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11080 | }, |
| 11081 | |
| 11082 | { /* Custom Japan */ |
| 11083 | "ZZC", |
| 11084 | .bg_channels = 11, |
| 11085 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11086 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11087 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11088 | {2457, 10}, {2462, 11}}, |
| 11089 | .a_channels = 4, |
| 11090 | .a = {{5170, 34}, {5190, 38}, |
| 11091 | {5210, 42}, {5230, 46}}, |
| 11092 | }, |
| 11093 | |
| 11094 | { /* Custom */ |
| 11095 | "ZZM", |
| 11096 | .bg_channels = 11, |
| 11097 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11098 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11099 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11100 | {2457, 10}, {2462, 11}}, |
| 11101 | }, |
| 11102 | |
| 11103 | { /* Europe */ |
| 11104 | "ZZE", |
| 11105 | .bg_channels = 13, |
| 11106 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11107 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11108 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11109 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11110 | {2472, 13}}, |
| 11111 | .a_channels = 19, |
| 11112 | .a = {{5180, 36}, |
| 11113 | {5200, 40}, |
| 11114 | {5220, 44}, |
| 11115 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11116 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11117 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11118 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11119 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11120 | {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, |
| 11121 | {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, |
| 11122 | {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, |
| 11123 | {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, |
| 11124 | {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, |
| 11125 | {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, |
| 11126 | {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, |
| 11127 | {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, |
| 11128 | {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, |
| 11129 | {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, |
| 11130 | {5700, 140, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11131 | }, |
| 11132 | |
| 11133 | { /* Custom Japan */ |
| 11134 | "ZZJ", |
| 11135 | .bg_channels = 14, |
| 11136 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11137 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11138 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11139 | {2457, 10}, {2462, 11}, {2467, 12}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11140 | {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11141 | .a_channels = 4, |
| 11142 | .a = {{5170, 34}, {5190, 38}, |
| 11143 | {5210, 42}, {5230, 46}}, |
| 11144 | }, |
| 11145 | |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11146 | { /* Rest of World */ |
| 11147 | "ZZR", |
| 11148 | .bg_channels = 14, |
| 11149 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11150 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11151 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11152 | {2457, 10}, {2462, 11}, {2467, 12}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11153 | {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY | |
| 11154 | LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11155 | }, |
| 11156 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11157 | { /* High Band */ |
| 11158 | "ZZH", |
| 11159 | .bg_channels = 13, |
| 11160 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11161 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11162 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11163 | {2457, 10}, {2462, 11}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11164 | {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, |
| 11165 | {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11166 | .a_channels = 4, |
| 11167 | .a = {{5745, 149}, {5765, 153}, |
| 11168 | {5785, 157}, {5805, 161}}, |
| 11169 | }, |
| 11170 | |
| 11171 | { /* Custom Europe */ |
| 11172 | "ZZG", |
| 11173 | .bg_channels = 13, |
| 11174 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11175 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11176 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11177 | {2457, 10}, {2462, 11}, |
| 11178 | {2467, 12}, {2472, 13}}, |
| 11179 | .a_channels = 4, |
| 11180 | .a = {{5180, 36}, {5200, 40}, |
| 11181 | {5220, 44}, {5240, 48}}, |
| 11182 | }, |
| 11183 | |
| 11184 | { /* Europe */ |
| 11185 | "ZZK", |
| 11186 | .bg_channels = 13, |
| 11187 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11188 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11189 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11190 | {2457, 10}, {2462, 11}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11191 | {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, |
| 11192 | {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11193 | .a_channels = 24, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11194 | .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, |
| 11195 | {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, |
| 11196 | {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, |
| 11197 | {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, |
| 11198 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11199 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11200 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11201 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11202 | {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, |
| 11203 | {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, |
| 11204 | {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, |
| 11205 | {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, |
| 11206 | {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, |
| 11207 | {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, |
| 11208 | {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, |
| 11209 | {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, |
| 11210 | {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, |
| 11211 | {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, |
| 11212 | {5700, 140, LIBIPW_CH_PASSIVE_ONLY}, |
| 11213 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11214 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11215 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11216 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11217 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11218 | }, |
| 11219 | |
| 11220 | { /* Europe */ |
| 11221 | "ZZL", |
| 11222 | .bg_channels = 11, |
| 11223 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11224 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11225 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11226 | {2457, 10}, {2462, 11}}, |
| 11227 | .a_channels = 13, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11228 | .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, |
| 11229 | {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, |
| 11230 | {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, |
| 11231 | {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, |
| 11232 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11233 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11234 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11235 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11236 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11237 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11238 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11239 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11240 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11241 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11242 | }; |
| 11243 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11244 | #define MAX_HW_RESTARTS 5 |
| 11245 | static int ipw_up(struct ipw_priv *priv) |
| 11246 | { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11247 | int rc, i, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11248 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11249 | /* Age scan list entries found before suspend */ |
| 11250 | if (priv->suspend_time) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11251 | libipw_networks_age(priv->ieee, priv->suspend_time); |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11252 | priv->suspend_time = 0; |
| 11253 | } |
| 11254 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11255 | if (priv->status & STATUS_EXIT_PENDING) |
| 11256 | return -EIO; |
| 11257 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11258 | if (cmdlog && !priv->cmdlog) { |
Yan Burman | e6e3f12 | 2006-12-02 13:38:14 +0200 | [diff] [blame] | 11259 | priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog), |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11260 | GFP_KERNEL); |
| 11261 | if (priv->cmdlog == NULL) { |
| 11262 | IPW_ERROR("Error allocating %d command log entries.\n", |
| 11263 | cmdlog); |
Zhu Yi | d0b526b | 2006-04-13 17:19:50 +0800 | [diff] [blame] | 11264 | return -ENOMEM; |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11265 | } else { |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11266 | priv->cmdlog_len = cmdlog; |
| 11267 | } |
| 11268 | } |
| 11269 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11270 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11271 | /* Load the microcode, firmware, and eeprom. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11272 | * Also start the clocks. */ |
| 11273 | rc = ipw_load(priv); |
| 11274 | if (rc) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 11275 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11276 | return rc; |
| 11277 | } |
| 11278 | |
| 11279 | ipw_init_ordinals(priv); |
| 11280 | if (!(priv->config & CFG_CUSTOM_MAC)) |
| 11281 | eeprom_parse_mac(priv, priv->mac_addr); |
| 11282 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
John W. Linville | 5e5eab5 | 2009-10-06 16:45:14 -0400 | [diff] [blame] | 11283 | memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11284 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11285 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
| 11286 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], |
| 11287 | ipw_geos[j].name, 3)) |
| 11288 | break; |
| 11289 | } |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11290 | if (j == ARRAY_SIZE(ipw_geos)) { |
| 11291 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", |
| 11292 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], |
| 11293 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], |
| 11294 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11295 | j = 0; |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11296 | } |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11297 | if (libipw_set_geo(priv->ieee, &ipw_geos[j])) { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11298 | IPW_WARNING("Could not set geography."); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11299 | return 0; |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11300 | } |
| 11301 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11302 | if (priv->status & STATUS_RF_KILL_SW) { |
| 11303 | IPW_WARNING("Radio disabled by module parameter.\n"); |
| 11304 | return 0; |
| 11305 | } else if (rf_kill_active(priv)) { |
| 11306 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" |
| 11307 | "Kill switch must be turned off for " |
| 11308 | "wireless networking to work.\n"); |
| 11309 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
| 11310 | 2 * HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11311 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11312 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11313 | |
| 11314 | rc = ipw_config(priv); |
| 11315 | if (!rc) { |
| 11316 | IPW_DEBUG_INFO("Configured device on count %i\n", i); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11317 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 11318 | /* If configure to try and auto-associate, kick |
| 11319 | * off a scan. */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11320 | queue_delayed_work(priv->workqueue, |
| 11321 | &priv->request_scan, 0); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11322 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11323 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11324 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11325 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11326 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11327 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
| 11328 | i, MAX_HW_RESTARTS); |
| 11329 | |
| 11330 | /* We had an error bringing up the hardware, so take it |
| 11331 | * all the way back down so we can try again */ |
| 11332 | ipw_down(priv); |
| 11333 | } |
| 11334 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11335 | /* tried to restart and config the device for as long as our |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11336 | * patience could withstand */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11337 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11338 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11339 | return -EIO; |
| 11340 | } |
| 11341 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11342 | static void ipw_bg_up(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11343 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11344 | struct ipw_priv *priv = |
| 11345 | container_of(work, struct ipw_priv, up); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11346 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11347 | ipw_up(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11348 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11349 | } |
| 11350 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11351 | static void ipw_deinit(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11352 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11353 | int i; |
| 11354 | |
| 11355 | if (priv->status & STATUS_SCANNING) { |
| 11356 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); |
| 11357 | ipw_abort_scan(priv); |
| 11358 | } |
| 11359 | |
| 11360 | if (priv->status & STATUS_ASSOCIATED) { |
| 11361 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); |
| 11362 | ipw_disassociate(priv); |
| 11363 | } |
| 11364 | |
| 11365 | ipw_led_shutdown(priv); |
| 11366 | |
| 11367 | /* Wait up to 1s for status to change to not scanning and not |
| 11368 | * associated (disassociation can take a while for a ful 802.11 |
| 11369 | * exchange */ |
| 11370 | for (i = 1000; i && (priv->status & |
| 11371 | (STATUS_DISASSOCIATING | |
| 11372 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) |
| 11373 | udelay(10); |
| 11374 | |
| 11375 | if (priv->status & (STATUS_DISASSOCIATING | |
| 11376 | STATUS_ASSOCIATED | STATUS_SCANNING)) |
| 11377 | IPW_DEBUG_INFO("Still associated or scanning...\n"); |
| 11378 | else |
| 11379 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); |
| 11380 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11381 | /* Attempt to disable the card */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11382 | ipw_send_card_disable(priv, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11383 | |
| 11384 | priv->status &= ~STATUS_INIT; |
| 11385 | } |
| 11386 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11387 | static void ipw_down(struct ipw_priv *priv) |
| 11388 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11389 | int exit_pending = priv->status & STATUS_EXIT_PENDING; |
| 11390 | |
| 11391 | priv->status |= STATUS_EXIT_PENDING; |
| 11392 | |
| 11393 | if (ipw_is_init(priv)) |
| 11394 | ipw_deinit(priv); |
| 11395 | |
| 11396 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 11397 | * exiting the module */ |
| 11398 | if (!exit_pending) |
| 11399 | priv->status &= ~STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11400 | |
| 11401 | /* tell the device to stop sending interrupts */ |
| 11402 | ipw_disable_interrupts(priv); |
| 11403 | |
| 11404 | /* Clear all bits but the RF Kill */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11405 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11406 | netif_carrier_off(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11407 | |
| 11408 | ipw_stop_nic(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11409 | |
| 11410 | ipw_led_radio_off(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11411 | } |
| 11412 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11413 | static void ipw_bg_down(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11414 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11415 | struct ipw_priv *priv = |
| 11416 | container_of(work, struct ipw_priv, down); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11417 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11418 | ipw_down(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11419 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11420 | } |
| 11421 | |
| 11422 | /* Called by register_netdev() */ |
| 11423 | static int ipw_net_init(struct net_device *dev) |
| 11424 | { |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11425 | int i, rc = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11426 | struct ipw_priv *priv = libipw_priv(dev); |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11427 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
| 11428 | struct wireless_dev *wdev = &priv->ieee->wdev; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11429 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11430 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11431 | if (ipw_up(priv)) { |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11432 | rc = -EIO; |
| 11433 | goto out; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11434 | } |
| 11435 | |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11436 | memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN); |
| 11437 | |
| 11438 | /* fill-out priv->ieee->bg_band */ |
| 11439 | if (geo->bg_channels) { |
| 11440 | struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band; |
| 11441 | |
| 11442 | bg_band->band = IEEE80211_BAND_2GHZ; |
| 11443 | bg_band->n_channels = geo->bg_channels; |
| 11444 | bg_band->channels = |
| 11445 | kzalloc(geo->bg_channels * |
| 11446 | sizeof(struct ieee80211_channel), GFP_KERNEL); |
| 11447 | /* translate geo->bg to bg_band.channels */ |
| 11448 | for (i = 0; i < geo->bg_channels; i++) { |
| 11449 | bg_band->channels[i].band = IEEE80211_BAND_2GHZ; |
| 11450 | bg_band->channels[i].center_freq = geo->bg[i].freq; |
| 11451 | bg_band->channels[i].hw_value = geo->bg[i].channel; |
| 11452 | bg_band->channels[i].max_power = geo->bg[i].max_power; |
| 11453 | if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) |
| 11454 | bg_band->channels[i].flags |= |
| 11455 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 11456 | if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS) |
| 11457 | bg_band->channels[i].flags |= |
| 11458 | IEEE80211_CHAN_NO_IBSS; |
| 11459 | if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT) |
| 11460 | bg_band->channels[i].flags |= |
| 11461 | IEEE80211_CHAN_RADAR; |
| 11462 | /* No equivalent for LIBIPW_CH_80211H_RULES, |
| 11463 | LIBIPW_CH_UNIFORM_SPREADING, or |
| 11464 | LIBIPW_CH_B_ONLY... */ |
| 11465 | } |
| 11466 | /* point at bitrate info */ |
| 11467 | bg_band->bitrates = ipw2200_bg_rates; |
| 11468 | bg_band->n_bitrates = ipw2200_num_bg_rates; |
| 11469 | |
| 11470 | wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band; |
| 11471 | } |
| 11472 | |
| 11473 | /* fill-out priv->ieee->a_band */ |
| 11474 | if (geo->a_channels) { |
| 11475 | struct ieee80211_supported_band *a_band = &priv->ieee->a_band; |
| 11476 | |
| 11477 | a_band->band = IEEE80211_BAND_5GHZ; |
| 11478 | a_band->n_channels = geo->a_channels; |
| 11479 | a_band->channels = |
| 11480 | kzalloc(geo->a_channels * |
| 11481 | sizeof(struct ieee80211_channel), GFP_KERNEL); |
| 11482 | /* translate geo->bg to a_band.channels */ |
| 11483 | for (i = 0; i < geo->a_channels; i++) { |
| 11484 | a_band->channels[i].band = IEEE80211_BAND_2GHZ; |
| 11485 | a_band->channels[i].center_freq = geo->a[i].freq; |
| 11486 | a_band->channels[i].hw_value = geo->a[i].channel; |
| 11487 | a_band->channels[i].max_power = geo->a[i].max_power; |
| 11488 | if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) |
| 11489 | a_band->channels[i].flags |= |
| 11490 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 11491 | if (geo->a[i].flags & LIBIPW_CH_NO_IBSS) |
| 11492 | a_band->channels[i].flags |= |
| 11493 | IEEE80211_CHAN_NO_IBSS; |
| 11494 | if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT) |
| 11495 | a_band->channels[i].flags |= |
| 11496 | IEEE80211_CHAN_RADAR; |
| 11497 | /* No equivalent for LIBIPW_CH_80211H_RULES, |
| 11498 | LIBIPW_CH_UNIFORM_SPREADING, or |
| 11499 | LIBIPW_CH_B_ONLY... */ |
| 11500 | } |
| 11501 | /* point at bitrate info */ |
| 11502 | a_band->bitrates = ipw2200_a_rates; |
| 11503 | a_band->n_bitrates = ipw2200_num_a_rates; |
| 11504 | |
| 11505 | wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band; |
| 11506 | } |
| 11507 | |
| 11508 | set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev); |
| 11509 | |
| 11510 | /* With that information in place, we can now register the wiphy... */ |
| 11511 | if (wiphy_register(wdev->wiphy)) { |
| 11512 | rc = -EIO; |
| 11513 | goto out; |
| 11514 | } |
| 11515 | |
| 11516 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11517 | mutex_unlock(&priv->mutex); |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11518 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11519 | } |
| 11520 | |
| 11521 | /* PCI driver stuff */ |
| 11522 | static struct pci_device_id card_ids[] = { |
| 11523 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
| 11524 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, |
| 11525 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, |
| 11526 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, |
| 11527 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, |
| 11528 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, |
| 11529 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, |
| 11530 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, |
| 11531 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, |
| 11532 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, |
| 11533 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, |
| 11534 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, |
| 11535 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, |
| 11536 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, |
| 11537 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, |
| 11538 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, |
| 11539 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, |
Joe Perches | 8ab0ea7 | 2009-06-24 22:13:27 -0700 | [diff] [blame] | 11540 | {PCI_VDEVICE(INTEL, 0x104f), 0}, |
| 11541 | {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */ |
| 11542 | {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */ |
| 11543 | {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */ |
| 11544 | {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11545 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11546 | /* required last entry */ |
| 11547 | {0,} |
| 11548 | }; |
| 11549 | |
| 11550 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 11551 | |
| 11552 | static struct attribute *ipw_sysfs_entries[] = { |
| 11553 | &dev_attr_rf_kill.attr, |
| 11554 | &dev_attr_direct_dword.attr, |
| 11555 | &dev_attr_indirect_byte.attr, |
| 11556 | &dev_attr_indirect_dword.attr, |
| 11557 | &dev_attr_mem_gpio_reg.attr, |
| 11558 | &dev_attr_command_event_reg.attr, |
| 11559 | &dev_attr_nic_type.attr, |
| 11560 | &dev_attr_status.attr, |
| 11561 | &dev_attr_cfg.attr, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 11562 | &dev_attr_error.attr, |
| 11563 | &dev_attr_event_log.attr, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11564 | &dev_attr_cmd_log.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11565 | &dev_attr_eeprom_delay.attr, |
| 11566 | &dev_attr_ucode_version.attr, |
| 11567 | &dev_attr_rtc.attr, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11568 | &dev_attr_scan_age.attr, |
| 11569 | &dev_attr_led.attr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11570 | &dev_attr_speed_scan.attr, |
| 11571 | &dev_attr_net_stats.attr, |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 11572 | &dev_attr_channels.attr, |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11573 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11574 | &dev_attr_rtap_iface.attr, |
| 11575 | &dev_attr_rtap_filter.attr, |
| 11576 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11577 | NULL |
| 11578 | }; |
| 11579 | |
| 11580 | static struct attribute_group ipw_attribute_group = { |
| 11581 | .name = NULL, /* put in device directory */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11582 | .attrs = ipw_sysfs_entries, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11583 | }; |
| 11584 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11585 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11586 | static int ipw_prom_open(struct net_device *dev) |
| 11587 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11588 | struct ipw_prom_priv *prom_priv = libipw_priv(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11589 | struct ipw_priv *priv = prom_priv->priv; |
| 11590 | |
| 11591 | IPW_DEBUG_INFO("prom dev->open\n"); |
| 11592 | netif_carrier_off(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11593 | |
| 11594 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11595 | priv->sys_config.accept_all_data_frames = 1; |
| 11596 | priv->sys_config.accept_non_directed_frames = 1; |
| 11597 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 11598 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 11599 | |
| 11600 | ipw_send_system_config(priv); |
| 11601 | } |
| 11602 | |
| 11603 | return 0; |
| 11604 | } |
| 11605 | |
| 11606 | static int ipw_prom_stop(struct net_device *dev) |
| 11607 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11608 | struct ipw_prom_priv *prom_priv = libipw_priv(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11609 | struct ipw_priv *priv = prom_priv->priv; |
| 11610 | |
| 11611 | IPW_DEBUG_INFO("prom dev->stop\n"); |
| 11612 | |
| 11613 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11614 | priv->sys_config.accept_all_data_frames = 0; |
| 11615 | priv->sys_config.accept_non_directed_frames = 0; |
| 11616 | priv->sys_config.accept_all_mgmt_bcpr = 0; |
| 11617 | priv->sys_config.accept_all_mgmt_frames = 0; |
| 11618 | |
| 11619 | ipw_send_system_config(priv); |
| 11620 | } |
| 11621 | |
| 11622 | return 0; |
| 11623 | } |
| 11624 | |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 11625 | static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb, |
| 11626 | struct net_device *dev) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11627 | { |
| 11628 | IPW_DEBUG_INFO("prom dev->xmit\n"); |
Patrick McHardy | 4153e77 | 2009-06-12 04:08:02 +0000 | [diff] [blame] | 11629 | dev_kfree_skb(skb); |
| 11630 | return NETDEV_TX_OK; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11631 | } |
| 11632 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11633 | static const struct net_device_ops ipw_prom_netdev_ops = { |
| 11634 | .ndo_open = ipw_prom_open, |
| 11635 | .ndo_stop = ipw_prom_stop, |
| 11636 | .ndo_start_xmit = ipw_prom_hard_start_xmit, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11637 | .ndo_change_mtu = libipw_change_mtu, |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11638 | .ndo_set_mac_address = eth_mac_addr, |
| 11639 | .ndo_validate_addr = eth_validate_addr, |
| 11640 | }; |
| 11641 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11642 | static int ipw_prom_alloc(struct ipw_priv *priv) |
| 11643 | { |
| 11644 | int rc = 0; |
| 11645 | |
| 11646 | if (priv->prom_net_dev) |
| 11647 | return -EPERM; |
| 11648 | |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11649 | priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv), 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11650 | if (priv->prom_net_dev == NULL) |
| 11651 | return -ENOMEM; |
| 11652 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11653 | priv->prom_priv = libipw_priv(priv->prom_net_dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11654 | priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev); |
| 11655 | priv->prom_priv->priv = priv; |
| 11656 | |
| 11657 | strcpy(priv->prom_net_dev->name, "rtap%d"); |
Daniel Drake | 3f2eeac | 2008-04-02 20:33:54 +0100 | [diff] [blame] | 11658 | memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11659 | |
| 11660 | priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11661 | priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11662 | |
| 11663 | priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR; |
Masakazu Mokuno | 229ce3a | 2008-05-14 14:16:50 +0900 | [diff] [blame] | 11664 | SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11665 | |
| 11666 | rc = register_netdev(priv->prom_net_dev); |
| 11667 | if (rc) { |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11668 | free_ieee80211(priv->prom_net_dev, 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11669 | priv->prom_net_dev = NULL; |
| 11670 | return rc; |
| 11671 | } |
| 11672 | |
| 11673 | return 0; |
| 11674 | } |
| 11675 | |
| 11676 | static void ipw_prom_free(struct ipw_priv *priv) |
| 11677 | { |
| 11678 | if (!priv->prom_net_dev) |
| 11679 | return; |
| 11680 | |
| 11681 | unregister_netdev(priv->prom_net_dev); |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11682 | free_ieee80211(priv->prom_net_dev, 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11683 | |
| 11684 | priv->prom_net_dev = NULL; |
| 11685 | } |
| 11686 | |
| 11687 | #endif |
| 11688 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11689 | static const struct net_device_ops ipw_netdev_ops = { |
| 11690 | .ndo_init = ipw_net_init, |
| 11691 | .ndo_open = ipw_net_open, |
| 11692 | .ndo_stop = ipw_net_stop, |
| 11693 | .ndo_set_multicast_list = ipw_net_set_multicast_list, |
| 11694 | .ndo_set_mac_address = ipw_net_set_mac_address, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11695 | .ndo_start_xmit = libipw_xmit, |
| 11696 | .ndo_change_mtu = libipw_change_mtu, |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11697 | .ndo_validate_addr = eth_validate_addr, |
| 11698 | }; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11699 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 11700 | static int __devinit ipw_pci_probe(struct pci_dev *pdev, |
| 11701 | const struct pci_device_id *ent) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11702 | { |
| 11703 | int err = 0; |
| 11704 | struct net_device *net_dev; |
| 11705 | void __iomem *base; |
| 11706 | u32 length, val; |
| 11707 | struct ipw_priv *priv; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11708 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11709 | |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11710 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv), 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11711 | if (net_dev == NULL) { |
| 11712 | err = -ENOMEM; |
| 11713 | goto out; |
| 11714 | } |
| 11715 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11716 | priv = libipw_priv(net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11717 | priv->ieee = netdev_priv(net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11718 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11719 | priv->net_dev = net_dev; |
| 11720 | priv->pci_dev = pdev; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11721 | ipw_debug_level = debug; |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 11722 | spin_lock_init(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11723 | spin_lock_init(&priv->lock); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11724 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
| 11725 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11726 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11727 | mutex_init(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11728 | if (pci_enable_device(pdev)) { |
| 11729 | err = -ENODEV; |
| 11730 | goto out_free_ieee80211; |
| 11731 | } |
| 11732 | |
| 11733 | pci_set_master(pdev); |
| 11734 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 11735 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11736 | if (!err) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 11737 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11738 | if (err) { |
| 11739 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 11740 | goto out_pci_disable_device; |
| 11741 | } |
| 11742 | |
| 11743 | pci_set_drvdata(pdev, priv); |
| 11744 | |
| 11745 | err = pci_request_regions(pdev, DRV_NAME); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11746 | if (err) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11747 | goto out_pci_disable_device; |
| 11748 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11749 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11750 | * PCI Tx retries from interfering with C3 CPU state */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11751 | pci_read_config_dword(pdev, 0x40, &val); |
| 11752 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11753 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11754 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11755 | length = pci_resource_len(pdev, 0); |
| 11756 | priv->hw_len = length; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11757 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 11758 | base = pci_ioremap_bar(pdev, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11759 | if (!base) { |
| 11760 | err = -ENODEV; |
| 11761 | goto out_pci_release_regions; |
| 11762 | } |
| 11763 | |
| 11764 | priv->hw_base = base; |
| 11765 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); |
| 11766 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); |
| 11767 | |
| 11768 | err = ipw_setup_deferred_work(priv); |
| 11769 | if (err) { |
| 11770 | IPW_ERROR("Unable to setup deferred work\n"); |
| 11771 | goto out_iounmap; |
| 11772 | } |
| 11773 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11774 | ipw_sw_reset(priv, 1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11775 | |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 11776 | err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11777 | if (err) { |
| 11778 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 11779 | goto out_destroy_workqueue; |
| 11780 | } |
| 11781 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11782 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
| 11783 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11784 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11785 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11786 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
| 11787 | priv->ieee->set_security = shim__set_security; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 11788 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11789 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11790 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 11791 | priv->ieee->is_qos_active = ipw_is_qos_active; |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 11792 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
| 11793 | priv->ieee->handle_beacon = ipw_handle_probe_response; |
| 11794 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11795 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11796 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11797 | priv->ieee->perfect_rssi = -20; |
| 11798 | priv->ieee->worst_rssi = -85; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11799 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11800 | net_dev->netdev_ops = &ipw_netdev_ops; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11801 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11802 | net_dev->wireless_data = &priv->wireless_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11803 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
| 11804 | net_dev->ethtool_ops = &ipw_ethtool_ops; |
| 11805 | net_dev->irq = pdev->irq; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11806 | net_dev->base_addr = (unsigned long)priv->hw_base; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11807 | net_dev->mem_start = pci_resource_start(pdev, 0); |
| 11808 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; |
| 11809 | |
| 11810 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11811 | if (err) { |
| 11812 | IPW_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11813 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11814 | goto out_release_irq; |
| 11815 | } |
| 11816 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11817 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11818 | err = register_netdev(net_dev); |
| 11819 | if (err) { |
| 11820 | IPW_ERROR("failed to register network device\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11821 | goto out_remove_sysfs; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11822 | } |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11823 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11824 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11825 | if (rtap_iface) { |
| 11826 | err = ipw_prom_alloc(priv); |
| 11827 | if (err) { |
| 11828 | IPW_ERROR("Failed to register promiscuous network " |
| 11829 | "device (error %d).\n", err); |
| 11830 | unregister_netdev(priv->net_dev); |
| 11831 | goto out_remove_sysfs; |
| 11832 | } |
| 11833 | } |
| 11834 | #endif |
| 11835 | |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11836 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " |
| 11837 | "channels, %d 802.11a channels)\n", |
| 11838 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, |
| 11839 | priv->ieee->geo.a_channels); |
| 11840 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11841 | return 0; |
| 11842 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11843 | out_remove_sysfs: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11844 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11845 | out_release_irq: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11846 | free_irq(pdev->irq, priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11847 | out_destroy_workqueue: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11848 | destroy_workqueue(priv->workqueue); |
| 11849 | priv->workqueue = NULL; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11850 | out_iounmap: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11851 | iounmap(priv->hw_base); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11852 | out_pci_release_regions: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11853 | pci_release_regions(pdev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11854 | out_pci_disable_device: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11855 | pci_disable_device(pdev); |
| 11856 | pci_set_drvdata(pdev, NULL); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11857 | out_free_ieee80211: |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11858 | free_ieee80211(priv->net_dev, 0); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11859 | out: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11860 | return err; |
| 11861 | } |
| 11862 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 11863 | static void __devexit ipw_pci_remove(struct pci_dev *pdev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11864 | { |
| 11865 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11866 | struct list_head *p, *q; |
| 11867 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11868 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11869 | if (!priv) |
| 11870 | return; |
| 11871 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11872 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11873 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11874 | priv->status |= STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11875 | ipw_down(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11876 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11877 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11878 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11879 | |
| 11880 | unregister_netdev(priv->net_dev); |
| 11881 | |
| 11882 | if (priv->rxq) { |
| 11883 | ipw_rx_queue_free(priv, priv->rxq); |
| 11884 | priv->rxq = NULL; |
| 11885 | } |
| 11886 | ipw_tx_queue_free(priv); |
| 11887 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11888 | if (priv->cmdlog) { |
| 11889 | kfree(priv->cmdlog); |
| 11890 | priv->cmdlog = NULL; |
| 11891 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11892 | /* ipw_down will ensure that there is no more pending work |
| 11893 | * in the workqueue's, so we can safely remove them now. */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11894 | cancel_delayed_work(&priv->adhoc_check); |
| 11895 | cancel_delayed_work(&priv->gather_stats); |
| 11896 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 11897 | cancel_delayed_work(&priv->request_direct_scan); |
| 11898 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 11899 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11900 | cancel_delayed_work(&priv->rf_kill); |
| 11901 | cancel_delayed_work(&priv->scan_check); |
| 11902 | destroy_workqueue(priv->workqueue); |
| 11903 | priv->workqueue = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11904 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11905 | /* Free MAC hash list for ADHOC */ |
| 11906 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { |
| 11907 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11908 | list_del(p); |
Zhu Yi | 489f445 | 2006-01-24 16:37:41 +0800 | [diff] [blame] | 11909 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11910 | } |
| 11911 | } |
| 11912 | |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 11913 | kfree(priv->error); |
| 11914 | priv->error = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11915 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11916 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11917 | ipw_prom_free(priv); |
| 11918 | #endif |
| 11919 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11920 | free_irq(pdev->irq, priv); |
| 11921 | iounmap(priv->hw_base); |
| 11922 | pci_release_regions(pdev); |
| 11923 | pci_disable_device(pdev); |
| 11924 | pci_set_drvdata(pdev, NULL); |
John W. Linville | b8ecd98 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11925 | free_ieee80211(priv->net_dev, 0); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11926 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11927 | } |
| 11928 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11929 | #ifdef CONFIG_PM |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11930 | 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] | 11931 | { |
| 11932 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11933 | struct net_device *dev = priv->net_dev; |
| 11934 | |
| 11935 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); |
| 11936 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11937 | /* Take down the device; powers it off, etc. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11938 | ipw_down(priv); |
| 11939 | |
| 11940 | /* Remove the PRESENT state of the device */ |
| 11941 | netif_device_detach(dev); |
| 11942 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11943 | pci_save_state(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11944 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11945 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11946 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11947 | priv->suspend_at = get_seconds(); |
| 11948 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11949 | return 0; |
| 11950 | } |
| 11951 | |
| 11952 | static int ipw_pci_resume(struct pci_dev *pdev) |
| 11953 | { |
| 11954 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11955 | struct net_device *dev = priv->net_dev; |
John W. Linville | 02e0e5e | 2006-11-07 20:53:48 -0500 | [diff] [blame] | 11956 | int err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11957 | u32 val; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11958 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11959 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
| 11960 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11961 | pci_set_power_state(pdev, PCI_D0); |
John W. Linville | 02e0e5e | 2006-11-07 20:53:48 -0500 | [diff] [blame] | 11962 | err = pci_enable_device(pdev); |
| 11963 | if (err) { |
| 11964 | printk(KERN_ERR "%s: pci_enable_device failed on resume\n", |
| 11965 | dev->name); |
| 11966 | return err; |
| 11967 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11968 | pci_restore_state(pdev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11969 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11970 | /* |
| 11971 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 11972 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 11973 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 11974 | * here since it only restores the first 64 bytes pci config header. |
| 11975 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11976 | pci_read_config_dword(pdev, 0x40, &val); |
| 11977 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11978 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 11979 | |
| 11980 | /* Set the device back into the PRESENT state; this will also wake |
| 11981 | * the queue of needed */ |
| 11982 | netif_device_attach(dev); |
| 11983 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11984 | priv->suspend_time = get_seconds() - priv->suspend_at; |
| 11985 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11986 | /* Bring the device back up */ |
| 11987 | queue_work(priv->workqueue, &priv->up); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11988 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11989 | return 0; |
| 11990 | } |
| 11991 | #endif |
| 11992 | |
Zhu Yi | c8c22c9 | 2006-08-21 11:38:39 +0800 | [diff] [blame] | 11993 | static void ipw_pci_shutdown(struct pci_dev *pdev) |
| 11994 | { |
| 11995 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11996 | |
| 11997 | /* Take down the device; powers it off, etc. */ |
| 11998 | ipw_down(priv); |
| 11999 | |
| 12000 | pci_disable_device(pdev); |
| 12001 | } |
| 12002 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12003 | /* driver initialization stuff */ |
| 12004 | static struct pci_driver ipw_driver = { |
| 12005 | .name = DRV_NAME, |
| 12006 | .id_table = card_ids, |
| 12007 | .probe = ipw_pci_probe, |
| 12008 | .remove = __devexit_p(ipw_pci_remove), |
| 12009 | #ifdef CONFIG_PM |
| 12010 | .suspend = ipw_pci_suspend, |
| 12011 | .resume = ipw_pci_resume, |
| 12012 | #endif |
Zhu Yi | c8c22c9 | 2006-08-21 11:38:39 +0800 | [diff] [blame] | 12013 | .shutdown = ipw_pci_shutdown, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12014 | }; |
| 12015 | |
| 12016 | static int __init ipw_init(void) |
| 12017 | { |
| 12018 | int ret; |
| 12019 | |
| 12020 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 12021 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 12022 | |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 12023 | ret = pci_register_driver(&ipw_driver); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12024 | if (ret) { |
| 12025 | IPW_ERROR("Unable to initialize PCI module\n"); |
| 12026 | return ret; |
| 12027 | } |
| 12028 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 12029 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12030 | if (ret) { |
| 12031 | IPW_ERROR("Unable to create driver sysfs file\n"); |
| 12032 | pci_unregister_driver(&ipw_driver); |
| 12033 | return ret; |
| 12034 | } |
| 12035 | |
| 12036 | return ret; |
| 12037 | } |
| 12038 | |
| 12039 | static void __exit ipw_exit(void) |
| 12040 | { |
| 12041 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); |
| 12042 | pci_unregister_driver(&ipw_driver); |
| 12043 | } |
| 12044 | |
| 12045 | module_param(disable, int, 0444); |
| 12046 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 12047 | |
| 12048 | module_param(associate, int, 0444); |
Tim Gardner | 5c7f9b7 | 2008-10-14 10:38:03 -0600 | [diff] [blame] | 12049 | MODULE_PARM_DESC(associate, "auto associate when scanning (default off)"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12050 | |
| 12051 | module_param(auto_create, int, 0444); |
| 12052 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); |
| 12053 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12054 | module_param_named(led, led_support, int, 0444); |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 12055 | 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] | 12056 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12057 | module_param(debug, int, 0444); |
| 12058 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 12059 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12060 | module_param_named(channel, default_channel, int, 0444); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 12061 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12062 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 12063 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 12064 | module_param(rtap_iface, int, 0444); |
| 12065 | MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)"); |
| 12066 | #endif |
| 12067 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 12068 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12069 | module_param(qos_enable, int, 0444); |
| 12070 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12071 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12072 | module_param(qos_burst_enable, int, 0444); |
| 12073 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); |
| 12074 | |
| 12075 | module_param(qos_no_ack_mask, int, 0444); |
| 12076 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); |
| 12077 | |
| 12078 | module_param(burst_duration_CCK, int, 0444); |
| 12079 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); |
| 12080 | |
| 12081 | module_param(burst_duration_OFDM, int, 0444); |
| 12082 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 12083 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12084 | |
| 12085 | #ifdef CONFIG_IPW2200_MONITOR |
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,2=Monitor)"); |
| 12088 | #else |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12089 | module_param_named(mode, network_mode, int, 0444); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12090 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
| 12091 | #endif |
| 12092 | |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 12093 | module_param(bt_coexist, int, 0444); |
| 12094 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); |
| 12095 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12096 | module_param(hwcrypto, int, 0444); |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 12097 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12098 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 12099 | module_param(cmdlog, int, 0444); |
| 12100 | MODULE_PARM_DESC(cmdlog, |
| 12101 | "allocate a ring buffer for logging firmware commands"); |
| 12102 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 12103 | module_param(roaming, int, 0444); |
| 12104 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); |
| 12105 | |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 12106 | module_param(antenna, int, 0444); |
| 12107 | MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)"); |
| 12108 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12109 | module_exit(ipw_exit); |
| 12110 | module_init(ipw_init); |