James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2 | |
Zhu Yi | 171e7b2 | 2006-02-15 07:17:56 +0800 | [diff] [blame] | 3 | Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4 | |
| 5 | 802.11 status code portion of this file from ethereal-0.10.6: |
| 6 | Copyright 2000, Axis Communications AB |
| 7 | Ethereal - Network traffic analyzer |
| 8 | By Gerald Combs <gerald@ethereal.com> |
| 9 | Copyright 1998 Gerald Combs |
| 10 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11 | This program is free software; you can redistribute it and/or modify it |
| 12 | under the terms of version 2 of the GNU General Public License as |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 13 | published by the Free Software Foundation. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 14 | |
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 18 | more details. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 19 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 20 | You should have received a copy of the GNU General Public License along with |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 21 | this program; if not, write to the Free Software Foundation, Inc., 59 |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 22 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 23 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 24 | The full GNU General Public License is included in this distribution in the |
| 25 | file called LICENSE. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 26 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 27 | Contact Information: |
Reinette Chatre | c1eb2c8 | 2009-08-21 13:34:26 -0700 | [diff] [blame] | 28 | Intel Linux Wireless <ilw@linux.intel.com> |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 29 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | |
| 31 | ******************************************************************************/ |
| 32 | |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 33 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 35 | #include "ipw2200.h" |
| 36 | |
Zhu Yi | ae4af61 | 2006-04-13 17:20:34 +0800 | [diff] [blame] | 37 | |
| 38 | #ifndef KBUILD_EXTMOD |
| 39 | #define VK "k" |
| 40 | #else |
| 41 | #define VK |
| 42 | #endif |
| 43 | |
| 44 | #ifdef CONFIG_IPW2200_DEBUG |
| 45 | #define VD "d" |
| 46 | #else |
| 47 | #define VD |
| 48 | #endif |
| 49 | |
| 50 | #ifdef CONFIG_IPW2200_MONITOR |
| 51 | #define VM "m" |
| 52 | #else |
| 53 | #define VM |
| 54 | #endif |
| 55 | |
| 56 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 57 | #define VP "p" |
| 58 | #else |
| 59 | #define VP |
| 60 | #endif |
| 61 | |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 62 | #ifdef CONFIG_IPW2200_RADIOTAP |
Zhu Yi | ae4af61 | 2006-04-13 17:20:34 +0800 | [diff] [blame] | 63 | #define VR "r" |
| 64 | #else |
| 65 | #define VR |
| 66 | #endif |
| 67 | |
| 68 | #ifdef CONFIG_IPW2200_QOS |
| 69 | #define VQ "q" |
| 70 | #else |
| 71 | #define VQ |
| 72 | #endif |
| 73 | |
Zhu Yi | ee2c4ad | 2007-07-12 16:09:47 +0800 | [diff] [blame] | 74 | #define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 75 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" |
Zhu Yi | 171e7b2 | 2006-02-15 07:17:56 +0800 | [diff] [blame] | 76 | #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation" |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 77 | #define DRV_VERSION IPW2200_VERSION |
| 78 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 79 | #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1) |
| 80 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 81 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 82 | MODULE_VERSION(DRV_VERSION); |
| 83 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 84 | MODULE_LICENSE("GPL"); |
Ben Hutchings | 873395a | 2009-11-07 21:59:10 +0000 | [diff] [blame] | 85 | MODULE_FIRMWARE("ipw2200-ibss.fw"); |
| 86 | #ifdef CONFIG_IPW2200_MONITOR |
| 87 | MODULE_FIRMWARE("ipw2200-sniffer.fw"); |
| 88 | #endif |
| 89 | MODULE_FIRMWARE("ipw2200-bss.fw"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 90 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 91 | static int cmdlog = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 92 | static int debug = 0; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 93 | static int default_channel = 0; |
| 94 | static int network_mode = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 95 | |
| 96 | static u32 ipw_debug_level; |
Tim Gardner | 5c7f9b7 | 2008-10-14 10:38:03 -0600 | [diff] [blame] | 97 | static int associate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 98 | static int auto_create = 1; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 99 | static int led_support = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 100 | static int disable = 0; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 101 | static int bt_coexist = 0; |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 102 | static int hwcrypto = 0; |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 103 | static int roaming = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 104 | static const char ipw_modes[] = { |
| 105 | 'a', 'b', 'g', '?' |
| 106 | }; |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 107 | static int antenna = CFG_SYS_ANTENNA_BOTH; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 108 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 109 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 110 | static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */ |
| 111 | #endif |
| 112 | |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 113 | static struct ieee80211_rate ipw2200_rates[] = { |
| 114 | { .bitrate = 10 }, |
| 115 | { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 116 | { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 117 | { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 118 | { .bitrate = 60 }, |
| 119 | { .bitrate = 90 }, |
| 120 | { .bitrate = 120 }, |
| 121 | { .bitrate = 180 }, |
| 122 | { .bitrate = 240 }, |
| 123 | { .bitrate = 360 }, |
| 124 | { .bitrate = 480 }, |
| 125 | { .bitrate = 540 } |
| 126 | }; |
| 127 | |
| 128 | #define ipw2200_a_rates (ipw2200_rates + 4) |
| 129 | #define ipw2200_num_a_rates 8 |
| 130 | #define ipw2200_bg_rates (ipw2200_rates + 0) |
| 131 | #define ipw2200_num_bg_rates 12 |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 132 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 133 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 134 | static int qos_enable = 0; |
| 135 | static int qos_burst_enable = 0; |
| 136 | static int qos_no_ack_mask = 0; |
| 137 | static int burst_duration_CCK = 0; |
| 138 | static int burst_duration_OFDM = 0; |
| 139 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 140 | static struct libipw_qos_parameters def_qos_parameters_OFDM = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 141 | {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, |
| 142 | QOS_TX3_CW_MIN_OFDM}, |
| 143 | {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, |
| 144 | QOS_TX3_CW_MAX_OFDM}, |
| 145 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 146 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 147 | {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, |
| 148 | QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} |
| 149 | }; |
| 150 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 151 | static struct libipw_qos_parameters def_qos_parameters_CCK = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 152 | {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, |
| 153 | QOS_TX3_CW_MIN_CCK}, |
| 154 | {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, |
| 155 | QOS_TX3_CW_MAX_CCK}, |
| 156 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 157 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 158 | {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, |
| 159 | QOS_TX3_TXOP_LIMIT_CCK} |
| 160 | }; |
| 161 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 162 | static struct libipw_qos_parameters def_parameters_OFDM = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 163 | {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, |
| 164 | DEF_TX3_CW_MIN_OFDM}, |
| 165 | {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, |
| 166 | DEF_TX3_CW_MAX_OFDM}, |
| 167 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 168 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 169 | {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, |
| 170 | DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} |
| 171 | }; |
| 172 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 173 | static struct libipw_qos_parameters def_parameters_CCK = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 174 | {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, |
| 175 | DEF_TX3_CW_MIN_CCK}, |
| 176 | {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, |
| 177 | DEF_TX3_CW_MAX_CCK}, |
| 178 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 179 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 180 | {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, |
| 181 | DEF_TX3_TXOP_LIMIT_CCK} |
| 182 | }; |
| 183 | |
| 184 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; |
| 185 | |
| 186 | static int from_priority_to_tx_queue[] = { |
| 187 | IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, |
| 188 | IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 |
| 189 | }; |
| 190 | |
| 191 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); |
| 192 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 193 | 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] | 194 | *qos_param); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 195 | 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] | 196 | *qos_param); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 197 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 198 | |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 199 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 200 | static void ipw_remove_current_network(struct ipw_priv *priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 201 | static void ipw_rx(struct ipw_priv *priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 202 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 203 | struct clx2_tx_queue *txq, int qindex); |
| 204 | static int ipw_queue_reset(struct ipw_priv *priv); |
| 205 | |
| 206 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 207 | int len, int sync); |
| 208 | |
| 209 | static void ipw_tx_queue_free(struct ipw_priv *); |
| 210 | |
| 211 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); |
| 212 | static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); |
| 213 | static void ipw_rx_queue_replenish(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 214 | static int ipw_up(struct ipw_priv *); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 215 | static void ipw_bg_up(struct work_struct *work); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 216 | static void ipw_down(struct ipw_priv *); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 217 | static void ipw_bg_down(struct work_struct *work); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 218 | static int ipw_config(struct ipw_priv *); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 219 | static int init_supported_rates(struct ipw_priv *priv, |
| 220 | struct ipw_supported_rates *prates); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 221 | static void ipw_set_hwcrypto_keys(struct ipw_priv *); |
| 222 | static void ipw_send_wep_keys(struct ipw_priv *, int); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 223 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 224 | static int snprint_line(char *buf, size_t count, |
| 225 | const u8 * data, u32 len, u32 ofs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 226 | { |
| 227 | int out, i, j, l; |
| 228 | char c; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 229 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 230 | out = snprintf(buf, count, "%08X", ofs); |
| 231 | |
| 232 | for (l = 0, i = 0; i < 2; i++) { |
| 233 | out += snprintf(buf + out, count - out, " "); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 234 | for (j = 0; j < 8 && l < len; j++, l++) |
| 235 | out += snprintf(buf + out, count - out, "%02X ", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 236 | data[(i * 8 + j)]); |
| 237 | for (; j < 8; j++) |
| 238 | out += snprintf(buf + out, count - out, " "); |
| 239 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 240 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 241 | out += snprintf(buf + out, count - out, " "); |
| 242 | for (l = 0, i = 0; i < 2; i++) { |
| 243 | out += snprintf(buf + out, count - out, " "); |
| 244 | for (j = 0; j < 8 && l < len; j++, l++) { |
| 245 | c = data[(i * 8 + j)]; |
| 246 | if (!isascii(c) || !isprint(c)) |
| 247 | c = '.'; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 248 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 249 | out += snprintf(buf + out, count - out, "%c", c); |
| 250 | } |
| 251 | |
| 252 | for (; j < 8; j++) |
| 253 | out += snprintf(buf + out, count - out, " "); |
| 254 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 255 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 256 | return out; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 257 | } |
| 258 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 259 | static void printk_buf(int level, const u8 * data, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 260 | { |
| 261 | char line[81]; |
| 262 | u32 ofs = 0; |
| 263 | if (!(ipw_debug_level & level)) |
| 264 | return; |
| 265 | |
| 266 | while (len) { |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 267 | snprint_line(line, sizeof(line), &data[ofs], |
| 268 | min(len, 16U), ofs); |
| 269 | printk(KERN_DEBUG "%s\n", line); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 270 | ofs += 16; |
| 271 | len -= min(len, 16U); |
| 272 | } |
| 273 | } |
| 274 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 275 | static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len) |
| 276 | { |
| 277 | size_t out = size; |
| 278 | u32 ofs = 0; |
| 279 | int total = 0; |
| 280 | |
| 281 | while (size && len) { |
| 282 | out = snprint_line(output, size, &data[ofs], |
| 283 | min_t(size_t, len, 16U), ofs); |
| 284 | |
| 285 | ofs += 16; |
| 286 | output += out; |
| 287 | size -= out; |
| 288 | len -= min_t(size_t, len, 16U); |
| 289 | total += out; |
| 290 | } |
| 291 | return total; |
| 292 | } |
| 293 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 294 | /* 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] | 295 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); |
| 296 | #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) |
| 297 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 298 | /* 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] | 299 | static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); |
| 300 | #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) |
| 301 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 302 | /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 303 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); |
| 304 | static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) |
| 305 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 306 | IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, |
| 307 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 308 | _ipw_write_reg8(a, b, c); |
| 309 | } |
| 310 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 311 | /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 312 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); |
| 313 | static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) |
| 314 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 315 | IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, |
| 316 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 317 | _ipw_write_reg16(a, b, c); |
| 318 | } |
| 319 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 320 | /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 321 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); |
| 322 | static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) |
| 323 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 324 | IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, |
| 325 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 326 | _ipw_write_reg32(a, b, c); |
| 327 | } |
| 328 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 329 | /* 8-bit direct write (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 330 | static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs, |
| 331 | u8 val) |
| 332 | { |
| 333 | writeb(val, ipw->hw_base + ofs); |
| 334 | } |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 335 | |
| 336 | /* 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] | 337 | #define ipw_write8(ipw, ofs, val) do { \ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 338 | IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \ |
| 339 | __LINE__, (u32)(ofs), (u32)(val)); \ |
| 340 | _ipw_write8(ipw, ofs, val); \ |
| 341 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 342 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 343 | /* 16-bit direct write (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 344 | static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs, |
| 345 | u16 val) |
| 346 | { |
| 347 | writew(val, ipw->hw_base + ofs); |
| 348 | } |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 349 | |
| 350 | /* 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] | 351 | #define ipw_write16(ipw, ofs, val) do { \ |
| 352 | IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \ |
| 353 | __LINE__, (u32)(ofs), (u32)(val)); \ |
| 354 | _ipw_write16(ipw, ofs, val); \ |
| 355 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 356 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 357 | /* 32-bit direct write (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 358 | static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs, |
| 359 | u32 val) |
| 360 | { |
| 361 | writel(val, ipw->hw_base + ofs); |
| 362 | } |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 363 | |
| 364 | /* 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] | 365 | #define ipw_write32(ipw, ofs, val) do { \ |
| 366 | IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \ |
| 367 | __LINE__, (u32)(ofs), (u32)(val)); \ |
| 368 | _ipw_write32(ipw, ofs, val); \ |
| 369 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 370 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 371 | /* 8-bit direct read (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 372 | static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 373 | { |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 374 | return readb(ipw->hw_base + ofs); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 375 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 376 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 377 | /* 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] | 378 | #define ipw_read8(ipw, ofs) ({ \ |
| 379 | IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \ |
| 380 | (u32)(ofs)); \ |
| 381 | _ipw_read8(ipw, ofs); \ |
| 382 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 383 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 384 | /* 16-bit direct read (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 385 | static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 386 | { |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 387 | return readw(ipw->hw_base + ofs); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 388 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 389 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 390 | /* 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] | 391 | #define ipw_read16(ipw, ofs) ({ \ |
| 392 | IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \ |
| 393 | (u32)(ofs)); \ |
| 394 | _ipw_read16(ipw, ofs); \ |
| 395 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 396 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 397 | /* 32-bit direct read (low 4K) */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 398 | static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 399 | { |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 400 | return readl(ipw->hw_base + ofs); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 401 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 402 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 403 | /* 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] | 404 | #define ipw_read32(ipw, ofs) ({ \ |
| 405 | IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \ |
| 406 | (u32)(ofs)); \ |
| 407 | _ipw_read32(ipw, ofs); \ |
| 408 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 409 | |
| 410 | static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 411 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 412 | #define ipw_read_indirect(a, b, c, d) ({ \ |
| 413 | IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \ |
| 414 | __LINE__, (u32)(b), (u32)(d)); \ |
| 415 | _ipw_read_indirect(a, b, c, d); \ |
| 416 | }) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 417 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 418 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 419 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, |
| 420 | int num); |
Jiri Slaby | 1788bcd | 2009-02-12 22:29:40 +0100 | [diff] [blame] | 421 | #define ipw_write_indirect(a, b, c, d) do { \ |
| 422 | IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \ |
| 423 | __LINE__, (u32)(b), (u32)(d)); \ |
| 424 | _ipw_write_indirect(a, b, c, d); \ |
| 425 | } while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 426 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 427 | /* 32-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 428 | 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] | 429 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 430 | 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] | 431 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 432 | _ipw_write32(priv, IPW_INDIRECT_DATA, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 433 | } |
| 434 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 435 | /* 8-bit indirect write (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 436 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) |
| 437 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 438 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 439 | u32 dif_len = reg - aligned_addr; |
| 440 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 441 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 442 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 443 | _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 444 | } |
| 445 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 446 | /* 16-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 447 | 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] | 448 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 449 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 450 | u32 dif_len = (reg - aligned_addr) & (~0x1ul); |
| 451 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 452 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 453 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 454 | _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 455 | } |
| 456 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 457 | /* 8-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 458 | static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) |
| 459 | { |
| 460 | u32 word; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 461 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 462 | IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 463 | word = _ipw_read32(priv, IPW_INDIRECT_DATA); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 464 | return (word >> ((reg & 0x3) * 8)) & 0xff; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 465 | } |
| 466 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 467 | /* 32-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 468 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) |
| 469 | { |
| 470 | u32 value; |
| 471 | |
| 472 | IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); |
| 473 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 474 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 475 | value = _ipw_read32(priv, IPW_INDIRECT_DATA); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 476 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); |
| 477 | return value; |
| 478 | } |
| 479 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 480 | /* General purpose, no alignment requirement, iterative (multi-byte) read, */ |
| 481 | /* for area above 1st 4K of SRAM/reg space */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 482 | static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
| 483 | int num) |
| 484 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 485 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 486 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 487 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 488 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 489 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
| 490 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 491 | if (num <= 0) { |
| 492 | return; |
| 493 | } |
| 494 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 495 | /* Read the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 496 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 497 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 498 | /* Start reading at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 499 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 500 | *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 501 | aligned_addr += 4; |
| 502 | } |
| 503 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 504 | /* Read all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 505 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 506 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 507 | *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 508 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 509 | /* Read the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 510 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 511 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 512 | for (i = 0; num > 0; i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 513 | *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 514 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 515 | } |
| 516 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 517 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 518 | /* for area above 1st 4K of SRAM/reg space */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 519 | 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] | 520 | int num) |
| 521 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 522 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 523 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 524 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 525 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 526 | 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] | 527 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 528 | if (num <= 0) { |
| 529 | return; |
| 530 | } |
| 531 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 532 | /* Write the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 533 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 534 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 535 | /* Start writing at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 536 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 537 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 538 | aligned_addr += 4; |
| 539 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 540 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 541 | /* Write all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 542 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 543 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 544 | _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 545 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 546 | /* Write the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 547 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 548 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 549 | for (i = 0; num > 0; i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 550 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 551 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 552 | } |
| 553 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 554 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 555 | /* for 1st 4K of SRAM/regs space */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 556 | 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] | 557 | int num) |
| 558 | { |
| 559 | memcpy_toio((priv->hw_base + addr), buf, num); |
| 560 | } |
| 561 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 562 | /* Set bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 563 | static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 564 | { |
| 565 | ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); |
| 566 | } |
| 567 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 568 | /* Clear bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 569 | static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 570 | { |
| 571 | ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); |
| 572 | } |
| 573 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 574 | static inline void __ipw_enable_interrupts(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 575 | { |
| 576 | if (priv->status & STATUS_INT_ENABLED) |
| 577 | return; |
| 578 | priv->status |= STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 579 | ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 580 | } |
| 581 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 582 | static inline void __ipw_disable_interrupts(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 583 | { |
| 584 | if (!(priv->status & STATUS_INT_ENABLED)) |
| 585 | return; |
| 586 | priv->status &= ~STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 587 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 588 | } |
| 589 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 590 | static inline void ipw_enable_interrupts(struct ipw_priv *priv) |
| 591 | { |
| 592 | unsigned long flags; |
| 593 | |
| 594 | spin_lock_irqsave(&priv->irq_lock, flags); |
| 595 | __ipw_enable_interrupts(priv); |
| 596 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 597 | } |
| 598 | |
| 599 | static inline void ipw_disable_interrupts(struct ipw_priv *priv) |
| 600 | { |
| 601 | unsigned long flags; |
| 602 | |
| 603 | spin_lock_irqsave(&priv->irq_lock, flags); |
| 604 | __ipw_disable_interrupts(priv); |
| 605 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 606 | } |
| 607 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 608 | static char *ipw_error_desc(u32 val) |
| 609 | { |
| 610 | switch (val) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 611 | case IPW_FW_ERROR_OK: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 612 | return "ERROR_OK"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 613 | case IPW_FW_ERROR_FAIL: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 614 | return "ERROR_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 615 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 616 | return "MEMORY_UNDERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 617 | case IPW_FW_ERROR_MEMORY_OVERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 618 | return "MEMORY_OVERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 619 | case IPW_FW_ERROR_BAD_PARAM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 620 | return "BAD_PARAM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 621 | case IPW_FW_ERROR_BAD_CHECKSUM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 622 | return "BAD_CHECKSUM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 623 | case IPW_FW_ERROR_NMI_INTERRUPT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 624 | return "NMI_INTERRUPT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 625 | case IPW_FW_ERROR_BAD_DATABASE: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 626 | return "BAD_DATABASE"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 627 | case IPW_FW_ERROR_ALLOC_FAIL: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 628 | return "ALLOC_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 629 | case IPW_FW_ERROR_DMA_UNDERRUN: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 630 | return "DMA_UNDERRUN"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 631 | case IPW_FW_ERROR_DMA_STATUS: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 632 | return "DMA_STATUS"; |
| 633 | case IPW_FW_ERROR_DINO_ERROR: |
| 634 | return "DINO_ERROR"; |
| 635 | case IPW_FW_ERROR_EEPROM_ERROR: |
| 636 | return "EEPROM_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 637 | case IPW_FW_ERROR_SYSASSERT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 638 | return "SYSASSERT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 639 | case IPW_FW_ERROR_FATAL_ERROR: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 640 | return "FATAL_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 641 | default: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 642 | return "UNKNOWN_ERROR"; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 646 | static void ipw_dump_error_log(struct ipw_priv *priv, |
| 647 | struct ipw_fw_error *error) |
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 | u32 i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 650 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 651 | if (!error) { |
| 652 | IPW_ERROR("Error allocating and capturing error log. " |
| 653 | "Nothing to dump.\n"); |
| 654 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 655 | } |
| 656 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 657 | IPW_ERROR("Start IPW Error Log Dump:\n"); |
| 658 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", |
| 659 | error->status, error->config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 660 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 661 | for (i = 0; i < error->elem_len; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 662 | 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] | 663 | ipw_error_desc(error->elem[i].desc), |
| 664 | error->elem[i].time, |
| 665 | error->elem[i].blink1, |
| 666 | error->elem[i].blink2, |
| 667 | error->elem[i].link1, |
| 668 | error->elem[i].link2, error->elem[i].data); |
| 669 | for (i = 0; i < error->log_len; i++) |
| 670 | IPW_ERROR("%i\t0x%08x\t%i\n", |
| 671 | error->log[i].time, |
James Ketrenos | 286568a | 2005-08-30 10:34:25 -0500 | [diff] [blame] | 672 | error->log[i].data, error->log[i].event); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 673 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 674 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 675 | static inline int ipw_is_init(struct ipw_priv *priv) |
| 676 | { |
| 677 | return (priv->status & STATUS_INIT) ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 678 | } |
| 679 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 680 | 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] | 681 | { |
| 682 | u32 addr, field_info, field_len, field_count, total_len; |
| 683 | |
| 684 | IPW_DEBUG_ORD("ordinal = %i\n", ord); |
| 685 | |
| 686 | if (!priv || !val || !len) { |
| 687 | IPW_DEBUG_ORD("Invalid argument\n"); |
| 688 | return -EINVAL; |
| 689 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 690 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 691 | /* verify device ordinal tables have been initialized */ |
| 692 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { |
| 693 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); |
| 694 | return -EINVAL; |
| 695 | } |
| 696 | |
| 697 | switch (IPW_ORD_TABLE_ID_MASK & ord) { |
| 698 | case IPW_ORD_TABLE_0_MASK: |
| 699 | /* |
| 700 | * TABLE 0: Direct access to a table of 32 bit values |
| 701 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 702 | * This is a very simple table with the data directly |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 703 | * read from the table |
| 704 | */ |
| 705 | |
| 706 | /* remove the table id from the ordinal */ |
| 707 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 708 | |
| 709 | /* boundary check */ |
| 710 | if (ord > priv->table0_len) { |
| 711 | IPW_DEBUG_ORD("ordinal value (%i) longer then " |
| 712 | "max (%i)\n", ord, priv->table0_len); |
| 713 | return -EINVAL; |
| 714 | } |
| 715 | |
| 716 | /* verify we have enough room to store the value */ |
| 717 | if (*len < sizeof(u32)) { |
| 718 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 719 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 720 | return -EINVAL; |
| 721 | } |
| 722 | |
| 723 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 724 | ord, priv->table0_addr + (ord << 2)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 725 | |
| 726 | *len = sizeof(u32); |
| 727 | ord <<= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 728 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 729 | break; |
| 730 | |
| 731 | case IPW_ORD_TABLE_1_MASK: |
| 732 | /* |
| 733 | * TABLE 1: Indirect access to a table of 32 bit values |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 734 | * |
| 735 | * This is a fairly large table of u32 values each |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 736 | * representing starting addr for the data (which is |
| 737 | * also a u32) |
| 738 | */ |
| 739 | |
| 740 | /* remove the table id from the ordinal */ |
| 741 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 742 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 743 | /* boundary check */ |
| 744 | if (ord > priv->table1_len) { |
| 745 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 746 | return -EINVAL; |
| 747 | } |
| 748 | |
| 749 | /* verify we have enough room to store the value */ |
| 750 | if (*len < sizeof(u32)) { |
| 751 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 752 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 753 | return -EINVAL; |
| 754 | } |
| 755 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 756 | *((u32 *) val) = |
| 757 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 758 | *len = sizeof(u32); |
| 759 | break; |
| 760 | |
| 761 | case IPW_ORD_TABLE_2_MASK: |
| 762 | /* |
| 763 | * TABLE 2: Indirect access to a table of variable sized values |
| 764 | * |
| 765 | * This table consist of six values, each containing |
| 766 | * - dword containing the starting offset of the data |
| 767 | * - dword containing the lengh in the first 16bits |
| 768 | * and the count in the second 16bits |
| 769 | */ |
| 770 | |
| 771 | /* remove the table id from the ordinal */ |
| 772 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 773 | |
| 774 | /* boundary check */ |
| 775 | if (ord > priv->table2_len) { |
| 776 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 777 | return -EINVAL; |
| 778 | } |
| 779 | |
| 780 | /* get the address of statistic */ |
| 781 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 782 | |
| 783 | /* get the second DW of statistics ; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 784 | * two 16-bit words - first is length, second is count */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 785 | field_info = |
| 786 | ipw_read_reg32(priv, |
| 787 | priv->table2_addr + (ord << 3) + |
| 788 | sizeof(u32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 789 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 790 | /* get each entry length */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 791 | field_len = *((u16 *) & field_info); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 792 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 793 | /* get number of entries */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 794 | field_count = *(((u16 *) & field_info) + 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 795 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 796 | /* abort if not enough memory */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 797 | total_len = field_len * field_count; |
| 798 | if (total_len > *len) { |
| 799 | *len = total_len; |
| 800 | return -EINVAL; |
| 801 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 802 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 803 | *len = total_len; |
| 804 | if (!total_len) |
| 805 | return 0; |
| 806 | |
| 807 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 808 | "field_info = 0x%08x\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 809 | addr, total_len, field_info); |
| 810 | ipw_read_indirect(priv, addr, val, total_len); |
| 811 | break; |
| 812 | |
| 813 | default: |
| 814 | IPW_DEBUG_ORD("Invalid ordinal!\n"); |
| 815 | return -EINVAL; |
| 816 | |
| 817 | } |
| 818 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | static void ipw_init_ordinals(struct ipw_priv *priv) |
| 823 | { |
| 824 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 825 | priv->table0_len = ipw_read32(priv, priv->table0_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 826 | |
| 827 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", |
| 828 | priv->table0_addr, priv->table0_len); |
| 829 | |
| 830 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); |
| 831 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); |
| 832 | |
| 833 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", |
| 834 | priv->table1_addr, priv->table1_len); |
| 835 | |
| 836 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); |
| 837 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 838 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 839 | |
| 840 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", |
| 841 | priv->table2_addr, priv->table2_len); |
| 842 | |
| 843 | } |
| 844 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 845 | static u32 ipw_register_toggle(u32 reg) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 846 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 847 | reg &= ~IPW_START_STANDBY; |
| 848 | if (reg & IPW_GATE_ODMA) |
| 849 | reg &= ~IPW_GATE_ODMA; |
| 850 | if (reg & IPW_GATE_IDMA) |
| 851 | reg &= ~IPW_GATE_IDMA; |
| 852 | if (reg & IPW_GATE_ADMA) |
| 853 | reg &= ~IPW_GATE_ADMA; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 854 | return reg; |
| 855 | } |
| 856 | |
| 857 | /* |
| 858 | * LED behavior: |
| 859 | * - On radio ON, turn on any LEDs that require to be on during start |
| 860 | * - On initialization, start unassociated blink |
| 861 | * - On association, disable unassociated blink |
| 862 | * - On disassociation, start unassociated blink |
| 863 | * - On radio OFF, turn off any LEDs started during radio on |
| 864 | * |
| 865 | */ |
Zhu Yi | ede6111 | 2006-01-24 16:37:10 +0800 | [diff] [blame] | 866 | #define LD_TIME_LINK_ON msecs_to_jiffies(300) |
| 867 | #define LD_TIME_LINK_OFF msecs_to_jiffies(2700) |
| 868 | #define LD_TIME_ACT_ON msecs_to_jiffies(250) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 869 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 870 | static void ipw_led_link_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 871 | { |
| 872 | unsigned long flags; |
| 873 | u32 led; |
| 874 | |
| 875 | /* If configured to not use LEDs, or nic_type is 1, |
| 876 | * then we don't toggle a LINK led */ |
| 877 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 878 | return; |
| 879 | |
| 880 | spin_lock_irqsave(&priv->lock, flags); |
| 881 | |
| 882 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 883 | !(priv->status & STATUS_LED_LINK_ON)) { |
| 884 | IPW_DEBUG_LED("Link LED On\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 885 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 886 | led |= priv->led_association_on; |
| 887 | |
| 888 | led = ipw_register_toggle(led); |
| 889 | |
| 890 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 891 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 892 | |
| 893 | priv->status |= STATUS_LED_LINK_ON; |
| 894 | |
| 895 | /* If we aren't associated, schedule turning the LED off */ |
| 896 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 897 | queue_delayed_work(priv->workqueue, |
| 898 | &priv->led_link_off, |
| 899 | LD_TIME_LINK_ON); |
| 900 | } |
| 901 | |
| 902 | spin_unlock_irqrestore(&priv->lock, flags); |
| 903 | } |
| 904 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 905 | static void ipw_bg_led_link_on(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 906 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 907 | struct ipw_priv *priv = |
| 908 | container_of(work, struct ipw_priv, led_link_on.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 909 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 910 | ipw_led_link_on(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 911 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 912 | } |
| 913 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 914 | static void ipw_led_link_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 915 | { |
| 916 | unsigned long flags; |
| 917 | u32 led; |
| 918 | |
| 919 | /* If configured not to use LEDs, or nic type is 1, |
| 920 | * then we don't goggle the LINK led. */ |
| 921 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 922 | return; |
| 923 | |
| 924 | spin_lock_irqsave(&priv->lock, flags); |
| 925 | |
| 926 | if (priv->status & STATUS_LED_LINK_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 927 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 928 | led &= priv->led_association_off; |
| 929 | led = ipw_register_toggle(led); |
| 930 | |
| 931 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 932 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 933 | |
| 934 | IPW_DEBUG_LED("Link LED Off\n"); |
| 935 | |
| 936 | priv->status &= ~STATUS_LED_LINK_ON; |
| 937 | |
| 938 | /* If we aren't associated and the radio is on, schedule |
| 939 | * turning the LED on (blink while unassociated) */ |
| 940 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 941 | !(priv->status & STATUS_ASSOCIATED)) |
| 942 | queue_delayed_work(priv->workqueue, &priv->led_link_on, |
| 943 | LD_TIME_LINK_OFF); |
| 944 | |
| 945 | } |
| 946 | |
| 947 | spin_unlock_irqrestore(&priv->lock, flags); |
| 948 | } |
| 949 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 950 | static void ipw_bg_led_link_off(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 951 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 952 | struct ipw_priv *priv = |
| 953 | container_of(work, struct ipw_priv, led_link_off.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 954 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 955 | ipw_led_link_off(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 956 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 957 | } |
| 958 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 959 | static void __ipw_led_activity_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 960 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 961 | u32 led; |
| 962 | |
| 963 | if (priv->config & CFG_NO_LED) |
| 964 | return; |
| 965 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 966 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 967 | return; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 968 | |
| 969 | if (!(priv->status & STATUS_LED_ACT_ON)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 970 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 971 | led |= priv->led_activity_on; |
| 972 | |
| 973 | led = ipw_register_toggle(led); |
| 974 | |
| 975 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 976 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 977 | |
| 978 | IPW_DEBUG_LED("Activity LED On\n"); |
| 979 | |
| 980 | priv->status |= STATUS_LED_ACT_ON; |
| 981 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 982 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 983 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 984 | LD_TIME_ACT_ON); |
| 985 | } else { |
| 986 | /* Reschedule LED off for full time period */ |
| 987 | cancel_delayed_work(&priv->led_act_off); |
| 988 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 989 | LD_TIME_ACT_ON); |
| 990 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 991 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 992 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 993 | #if 0 |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 994 | void ipw_led_activity_on(struct ipw_priv *priv) |
| 995 | { |
| 996 | unsigned long flags; |
| 997 | spin_lock_irqsave(&priv->lock, flags); |
| 998 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 999 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1000 | } |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1001 | #endif /* 0 */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1002 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1003 | static void ipw_led_activity_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1004 | { |
| 1005 | unsigned long flags; |
| 1006 | u32 led; |
| 1007 | |
| 1008 | if (priv->config & CFG_NO_LED) |
| 1009 | return; |
| 1010 | |
| 1011 | spin_lock_irqsave(&priv->lock, flags); |
| 1012 | |
| 1013 | if (priv->status & STATUS_LED_ACT_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1014 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1015 | led &= priv->led_activity_off; |
| 1016 | |
| 1017 | led = ipw_register_toggle(led); |
| 1018 | |
| 1019 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1020 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1021 | |
| 1022 | IPW_DEBUG_LED("Activity LED Off\n"); |
| 1023 | |
| 1024 | priv->status &= ~STATUS_LED_ACT_ON; |
| 1025 | } |
| 1026 | |
| 1027 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1028 | } |
| 1029 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1030 | static void ipw_bg_led_activity_off(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1031 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1032 | struct ipw_priv *priv = |
| 1033 | container_of(work, struct ipw_priv, led_act_off.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 1034 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1035 | ipw_led_activity_off(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 1036 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1037 | } |
| 1038 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1039 | static void ipw_led_band_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1040 | { |
| 1041 | unsigned long flags; |
| 1042 | u32 led; |
| 1043 | |
| 1044 | /* Only nic type 1 supports mode LEDs */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1045 | if (priv->config & CFG_NO_LED || |
| 1046 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1047 | return; |
| 1048 | |
| 1049 | spin_lock_irqsave(&priv->lock, flags); |
| 1050 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1051 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1052 | if (priv->assoc_network->mode == IEEE_A) { |
| 1053 | led |= priv->led_ofdm_on; |
| 1054 | led &= priv->led_association_off; |
| 1055 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); |
| 1056 | } else if (priv->assoc_network->mode == IEEE_G) { |
| 1057 | led |= priv->led_ofdm_on; |
| 1058 | led |= priv->led_association_on; |
| 1059 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); |
| 1060 | } else { |
| 1061 | led &= priv->led_ofdm_off; |
| 1062 | led |= priv->led_association_on; |
| 1063 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); |
| 1064 | } |
| 1065 | |
| 1066 | led = ipw_register_toggle(led); |
| 1067 | |
| 1068 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1069 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1070 | |
| 1071 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1072 | } |
| 1073 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1074 | static void ipw_led_band_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1075 | { |
| 1076 | unsigned long flags; |
| 1077 | u32 led; |
| 1078 | |
| 1079 | /* Only nic type 1 supports mode LEDs */ |
| 1080 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) |
| 1081 | return; |
| 1082 | |
| 1083 | spin_lock_irqsave(&priv->lock, flags); |
| 1084 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1085 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1086 | led &= priv->led_ofdm_off; |
| 1087 | led &= priv->led_association_off; |
| 1088 | |
| 1089 | led = ipw_register_toggle(led); |
| 1090 | |
| 1091 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1092 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1093 | |
| 1094 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1095 | } |
| 1096 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1097 | static void ipw_led_radio_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1098 | { |
| 1099 | ipw_led_link_on(priv); |
| 1100 | } |
| 1101 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1102 | static void ipw_led_radio_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1103 | { |
| 1104 | ipw_led_activity_off(priv); |
| 1105 | ipw_led_link_off(priv); |
| 1106 | } |
| 1107 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1108 | static void ipw_led_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1109 | { |
| 1110 | /* Set the Link Led on for all nic types */ |
| 1111 | ipw_led_link_on(priv); |
| 1112 | } |
| 1113 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1114 | static void ipw_led_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1115 | { |
| 1116 | ipw_led_activity_off(priv); |
| 1117 | ipw_led_link_off(priv); |
| 1118 | |
| 1119 | if (priv->status & STATUS_RF_KILL_MASK) |
| 1120 | ipw_led_radio_off(priv); |
| 1121 | } |
| 1122 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1123 | static void ipw_led_init(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1124 | { |
| 1125 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; |
| 1126 | |
| 1127 | /* Set the default PINs for the link and activity leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1128 | priv->led_activity_on = IPW_ACTIVITY_LED; |
| 1129 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1130 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1131 | priv->led_association_on = IPW_ASSOCIATED_LED; |
| 1132 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1133 | |
| 1134 | /* Set the default PINs for the OFDM leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1135 | priv->led_ofdm_on = IPW_OFDM_LED; |
| 1136 | priv->led_ofdm_off = ~(IPW_OFDM_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1137 | |
| 1138 | switch (priv->nic_type) { |
| 1139 | case EEPROM_NIC_TYPE_1: |
| 1140 | /* In this NIC type, the LEDs are reversed.... */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1141 | priv->led_activity_on = IPW_ASSOCIATED_LED; |
| 1142 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); |
| 1143 | priv->led_association_on = IPW_ACTIVITY_LED; |
| 1144 | priv->led_association_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1145 | |
| 1146 | if (!(priv->config & CFG_NO_LED)) |
| 1147 | ipw_led_band_on(priv); |
| 1148 | |
| 1149 | /* And we don't blink link LEDs for this nic, so |
| 1150 | * just return here */ |
| 1151 | return; |
| 1152 | |
| 1153 | case EEPROM_NIC_TYPE_3: |
| 1154 | case EEPROM_NIC_TYPE_2: |
| 1155 | case EEPROM_NIC_TYPE_4: |
| 1156 | case EEPROM_NIC_TYPE_0: |
| 1157 | break; |
| 1158 | |
| 1159 | default: |
| 1160 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", |
| 1161 | priv->nic_type); |
| 1162 | priv->nic_type = EEPROM_NIC_TYPE_0; |
| 1163 | break; |
| 1164 | } |
| 1165 | |
| 1166 | if (!(priv->config & CFG_NO_LED)) { |
| 1167 | if (priv->status & STATUS_ASSOCIATED) |
| 1168 | ipw_led_link_on(priv); |
| 1169 | else |
| 1170 | ipw_led_link_off(priv); |
| 1171 | } |
| 1172 | } |
| 1173 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1174 | static void ipw_led_shutdown(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1175 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1176 | ipw_led_activity_off(priv); |
| 1177 | ipw_led_link_off(priv); |
| 1178 | ipw_led_band_off(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1179 | cancel_delayed_work(&priv->led_link_on); |
| 1180 | cancel_delayed_work(&priv->led_link_off); |
| 1181 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1182 | } |
| 1183 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1184 | /* |
| 1185 | * The following adds a new attribute to the sysfs representation |
| 1186 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) |
| 1187 | * used for controling the debug level. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1188 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1189 | * See the level definitions in ipw for details. |
| 1190 | */ |
| 1191 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 1192 | { |
| 1193 | return sprintf(buf, "0x%08X\n", ipw_debug_level); |
| 1194 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1195 | |
| 1196 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, |
| 1197 | size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1198 | { |
| 1199 | char *p = (char *)buf; |
| 1200 | u32 val; |
| 1201 | |
| 1202 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1203 | p++; |
| 1204 | if (p[0] == 'x' || p[0] == 'X') |
| 1205 | p++; |
| 1206 | val = simple_strtoul(p, &p, 16); |
| 1207 | } else |
| 1208 | val = simple_strtoul(p, &p, 10); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1209 | if (p == buf) |
| 1210 | printk(KERN_INFO DRV_NAME |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1211 | ": %s is not in hex or decimal form.\n", buf); |
| 1212 | else |
| 1213 | ipw_debug_level = val; |
| 1214 | |
| 1215 | return strnlen(buf, count); |
| 1216 | } |
| 1217 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1218 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1219 | show_debug_level, store_debug_level); |
| 1220 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1221 | static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) |
| 1222 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 1223 | /* length = 1st dword in log */ |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1224 | return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); |
| 1225 | } |
| 1226 | |
| 1227 | static void ipw_capture_event_log(struct ipw_priv *priv, |
| 1228 | u32 log_len, struct ipw_event *log) |
| 1229 | { |
| 1230 | u32 base; |
| 1231 | |
| 1232 | if (log_len) { |
| 1233 | base = ipw_read32(priv, IPW_EVENT_LOG); |
| 1234 | ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), |
| 1235 | (u8 *) log, sizeof(*log) * log_len); |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) |
| 1240 | { |
| 1241 | struct ipw_fw_error *error; |
| 1242 | u32 log_len = ipw_get_event_log_len(priv); |
| 1243 | u32 base = ipw_read32(priv, IPW_ERROR_LOG); |
| 1244 | u32 elem_len = ipw_read_reg32(priv, base); |
| 1245 | |
| 1246 | error = kmalloc(sizeof(*error) + |
| 1247 | sizeof(*error->elem) * elem_len + |
| 1248 | sizeof(*error->log) * log_len, GFP_ATOMIC); |
| 1249 | if (!error) { |
| 1250 | IPW_ERROR("Memory allocation for firmware error log " |
| 1251 | "failed.\n"); |
| 1252 | return NULL; |
| 1253 | } |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1254 | error->jiffies = jiffies; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1255 | error->status = priv->status; |
| 1256 | error->config = priv->config; |
| 1257 | error->elem_len = elem_len; |
| 1258 | error->log_len = log_len; |
| 1259 | error->elem = (struct ipw_error_elem *)error->payload; |
Zhu Yi | 3b26b11 | 2005-11-17 13:58:30 +0800 | [diff] [blame] | 1260 | error->log = (struct ipw_event *)(error->elem + elem_len); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1261 | |
| 1262 | ipw_capture_event_log(priv, log_len, error->log); |
| 1263 | |
| 1264 | if (elem_len) |
| 1265 | ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, |
| 1266 | sizeof(*error->elem) * elem_len); |
| 1267 | |
| 1268 | return error; |
| 1269 | } |
| 1270 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1271 | static ssize_t show_event_log(struct device *d, |
| 1272 | struct device_attribute *attr, char *buf) |
| 1273 | { |
| 1274 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1275 | u32 log_len = ipw_get_event_log_len(priv); |
Reinette Chatre | 412e9e7 | 2007-12-18 22:01:02 -0800 | [diff] [blame] | 1276 | u32 log_size; |
| 1277 | struct ipw_event *log; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1278 | u32 len = 0, i; |
| 1279 | |
Reinette Chatre | 412e9e7 | 2007-12-18 22:01:02 -0800 | [diff] [blame] | 1280 | /* not using min() because of its strict type checking */ |
| 1281 | log_size = PAGE_SIZE / sizeof(*log) > log_len ? |
| 1282 | sizeof(*log) * log_len : PAGE_SIZE; |
| 1283 | log = kzalloc(log_size, GFP_KERNEL); |
| 1284 | if (!log) { |
| 1285 | IPW_ERROR("Unable to allocate memory for log\n"); |
| 1286 | return 0; |
| 1287 | } |
| 1288 | log_len = log_size / sizeof(*log); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1289 | ipw_capture_event_log(priv, log_len, log); |
| 1290 | |
| 1291 | len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); |
| 1292 | for (i = 0; i < log_len; i++) |
| 1293 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1294 | "\n%08X%08X%08X", |
| 1295 | log[i].time, log[i].event, log[i].data); |
| 1296 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
Reinette Chatre | 412e9e7 | 2007-12-18 22:01:02 -0800 | [diff] [blame] | 1297 | kfree(log); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1298 | return len; |
| 1299 | } |
| 1300 | |
| 1301 | static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL); |
| 1302 | |
| 1303 | static ssize_t show_error(struct device *d, |
| 1304 | struct device_attribute *attr, char *buf) |
| 1305 | { |
| 1306 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1307 | u32 len = 0, i; |
| 1308 | if (!priv->error) |
| 1309 | return 0; |
| 1310 | len += snprintf(buf + len, PAGE_SIZE - len, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1311 | "%08lX%08X%08X%08X", |
| 1312 | priv->error->jiffies, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1313 | priv->error->status, |
| 1314 | priv->error->config, priv->error->elem_len); |
| 1315 | for (i = 0; i < priv->error->elem_len; i++) |
| 1316 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1317 | "\n%08X%08X%08X%08X%08X%08X%08X", |
| 1318 | priv->error->elem[i].time, |
| 1319 | priv->error->elem[i].desc, |
| 1320 | priv->error->elem[i].blink1, |
| 1321 | priv->error->elem[i].blink2, |
| 1322 | priv->error->elem[i].link1, |
| 1323 | priv->error->elem[i].link2, |
| 1324 | priv->error->elem[i].data); |
| 1325 | |
| 1326 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1327 | "\n%08X", priv->error->log_len); |
| 1328 | for (i = 0; i < priv->error->log_len; i++) |
| 1329 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1330 | "\n%08X%08X%08X", |
| 1331 | priv->error->log[i].time, |
| 1332 | priv->error->log[i].event, |
| 1333 | priv->error->log[i].data); |
| 1334 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1335 | return len; |
| 1336 | } |
| 1337 | |
| 1338 | static ssize_t clear_error(struct device *d, |
| 1339 | struct device_attribute *attr, |
| 1340 | const char *buf, size_t count) |
| 1341 | { |
| 1342 | struct ipw_priv *priv = dev_get_drvdata(d); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 1343 | |
| 1344 | kfree(priv->error); |
| 1345 | priv->error = NULL; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1346 | return count; |
| 1347 | } |
| 1348 | |
| 1349 | static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error); |
| 1350 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1351 | static ssize_t show_cmd_log(struct device *d, |
| 1352 | struct device_attribute *attr, char *buf) |
| 1353 | { |
| 1354 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1355 | u32 len = 0, i; |
| 1356 | if (!priv->cmdlog) |
| 1357 | return 0; |
| 1358 | for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; |
| 1359 | (i != priv->cmdlog_pos) && (PAGE_SIZE - len); |
| 1360 | i = (i + 1) % priv->cmdlog_len) { |
| 1361 | len += |
| 1362 | snprintf(buf + len, PAGE_SIZE - len, |
| 1363 | "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, |
| 1364 | priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, |
| 1365 | priv->cmdlog[i].cmd.len); |
| 1366 | len += |
| 1367 | snprintk_buf(buf + len, PAGE_SIZE - len, |
| 1368 | (u8 *) priv->cmdlog[i].cmd.param, |
| 1369 | priv->cmdlog[i].cmd.len); |
| 1370 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1371 | } |
| 1372 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1373 | return len; |
| 1374 | } |
| 1375 | |
| 1376 | static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL); |
| 1377 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 1378 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 1379 | static void ipw_prom_free(struct ipw_priv *priv); |
| 1380 | static int ipw_prom_alloc(struct ipw_priv *priv); |
| 1381 | static ssize_t store_rtap_iface(struct device *d, |
| 1382 | struct device_attribute *attr, |
| 1383 | const char *buf, size_t count) |
| 1384 | { |
| 1385 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1386 | int rc = 0; |
| 1387 | |
| 1388 | if (count < 1) |
| 1389 | return -EINVAL; |
| 1390 | |
| 1391 | switch (buf[0]) { |
| 1392 | case '0': |
| 1393 | if (!rtap_iface) |
| 1394 | return count; |
| 1395 | |
| 1396 | if (netif_running(priv->prom_net_dev)) { |
| 1397 | IPW_WARNING("Interface is up. Cannot unregister.\n"); |
| 1398 | return count; |
| 1399 | } |
| 1400 | |
| 1401 | ipw_prom_free(priv); |
| 1402 | rtap_iface = 0; |
| 1403 | break; |
| 1404 | |
| 1405 | case '1': |
| 1406 | if (rtap_iface) |
| 1407 | return count; |
| 1408 | |
| 1409 | rc = ipw_prom_alloc(priv); |
| 1410 | if (!rc) |
| 1411 | rtap_iface = 1; |
| 1412 | break; |
| 1413 | |
| 1414 | default: |
| 1415 | return -EINVAL; |
| 1416 | } |
| 1417 | |
| 1418 | if (rc) { |
| 1419 | IPW_ERROR("Failed to register promiscuous network " |
| 1420 | "device (error %d).\n", rc); |
| 1421 | } |
| 1422 | |
| 1423 | return count; |
| 1424 | } |
| 1425 | |
| 1426 | static ssize_t show_rtap_iface(struct device *d, |
| 1427 | struct device_attribute *attr, |
| 1428 | char *buf) |
| 1429 | { |
| 1430 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1431 | if (rtap_iface) |
| 1432 | return sprintf(buf, "%s", priv->prom_net_dev->name); |
| 1433 | else { |
| 1434 | buf[0] = '-'; |
| 1435 | buf[1] = '1'; |
| 1436 | buf[2] = '\0'; |
| 1437 | return 3; |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface, |
| 1442 | store_rtap_iface); |
| 1443 | |
| 1444 | static ssize_t store_rtap_filter(struct device *d, |
| 1445 | struct device_attribute *attr, |
| 1446 | const char *buf, size_t count) |
| 1447 | { |
| 1448 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1449 | |
| 1450 | if (!priv->prom_priv) { |
| 1451 | IPW_ERROR("Attempting to set filter without " |
| 1452 | "rtap_iface enabled.\n"); |
| 1453 | return -EPERM; |
| 1454 | } |
| 1455 | |
| 1456 | priv->prom_priv->filter = simple_strtol(buf, NULL, 0); |
| 1457 | |
| 1458 | IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n", |
| 1459 | BIT_ARG16(priv->prom_priv->filter)); |
| 1460 | |
| 1461 | return count; |
| 1462 | } |
| 1463 | |
| 1464 | static ssize_t show_rtap_filter(struct device *d, |
| 1465 | struct device_attribute *attr, |
| 1466 | char *buf) |
| 1467 | { |
| 1468 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1469 | return sprintf(buf, "0x%04X", |
| 1470 | priv->prom_priv ? priv->prom_priv->filter : 0); |
| 1471 | } |
| 1472 | |
| 1473 | static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter, |
| 1474 | store_rtap_filter); |
| 1475 | #endif |
| 1476 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1477 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
| 1478 | char *buf) |
| 1479 | { |
| 1480 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1481 | return sprintf(buf, "%d\n", priv->ieee->scan_age); |
| 1482 | } |
| 1483 | |
| 1484 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, |
| 1485 | const char *buf, size_t count) |
| 1486 | { |
| 1487 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1488 | struct net_device *dev = priv->net_dev; |
| 1489 | char buffer[] = "00000000"; |
| 1490 | unsigned long len = |
| 1491 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; |
| 1492 | unsigned long val; |
| 1493 | char *p = buffer; |
| 1494 | |
| 1495 | IPW_DEBUG_INFO("enter\n"); |
| 1496 | |
| 1497 | strncpy(buffer, buf, len); |
| 1498 | buffer[len] = 0; |
| 1499 | |
| 1500 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1501 | p++; |
| 1502 | if (p[0] == 'x' || p[0] == 'X') |
| 1503 | p++; |
| 1504 | val = simple_strtoul(p, &p, 16); |
| 1505 | } else |
| 1506 | val = simple_strtoul(p, &p, 10); |
| 1507 | if (p == buffer) { |
| 1508 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); |
| 1509 | } else { |
| 1510 | priv->ieee->scan_age = val; |
| 1511 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); |
| 1512 | } |
| 1513 | |
| 1514 | IPW_DEBUG_INFO("exit\n"); |
| 1515 | return len; |
| 1516 | } |
| 1517 | |
| 1518 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); |
| 1519 | |
| 1520 | static ssize_t show_led(struct device *d, struct device_attribute *attr, |
| 1521 | char *buf) |
| 1522 | { |
| 1523 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1524 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); |
| 1525 | } |
| 1526 | |
| 1527 | static ssize_t store_led(struct device *d, struct device_attribute *attr, |
| 1528 | const char *buf, size_t count) |
| 1529 | { |
| 1530 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1531 | |
| 1532 | IPW_DEBUG_INFO("enter\n"); |
| 1533 | |
| 1534 | if (count == 0) |
| 1535 | return 0; |
| 1536 | |
| 1537 | if (*buf == 0) { |
| 1538 | IPW_DEBUG_LED("Disabling LED control.\n"); |
| 1539 | priv->config |= CFG_NO_LED; |
| 1540 | ipw_led_shutdown(priv); |
| 1541 | } else { |
| 1542 | IPW_DEBUG_LED("Enabling LED control.\n"); |
| 1543 | priv->config &= ~CFG_NO_LED; |
| 1544 | ipw_led_init(priv); |
| 1545 | } |
| 1546 | |
| 1547 | IPW_DEBUG_INFO("exit\n"); |
| 1548 | return count; |
| 1549 | } |
| 1550 | |
| 1551 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); |
| 1552 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1553 | static ssize_t show_status(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1554 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1555 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1556 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1557 | return sprintf(buf, "0x%08x\n", (int)p->status); |
| 1558 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1559 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1560 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 1561 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1562 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
| 1563 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1564 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1565 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1566 | return sprintf(buf, "0x%08x\n", (int)p->config); |
| 1567 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1568 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1569 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); |
| 1570 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1571 | static ssize_t show_nic_type(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1572 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1573 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1574 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1575 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1576 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1577 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1578 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); |
| 1579 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1580 | static ssize_t show_ucode_version(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1581 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1582 | { |
| 1583 | u32 len = sizeof(u32), tmp = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1584 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1585 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1586 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1587 | return 0; |
| 1588 | |
| 1589 | return sprintf(buf, "0x%08x\n", tmp); |
| 1590 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1591 | |
| 1592 | 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] | 1593 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1594 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, |
| 1595 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1596 | { |
| 1597 | u32 len = sizeof(u32), tmp = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1598 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1599 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1600 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1601 | return 0; |
| 1602 | |
| 1603 | return sprintf(buf, "0x%08x\n", tmp); |
| 1604 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1605 | |
| 1606 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1607 | |
| 1608 | /* |
| 1609 | * Add a device attribute to view/control the delay between eeprom |
| 1610 | * operations. |
| 1611 | */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1612 | static ssize_t show_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1613 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1614 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1615 | struct ipw_priv *p = dev_get_drvdata(d); |
| 1616 | int n = p->eeprom_delay; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1617 | return sprintf(buf, "%i\n", n); |
| 1618 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1619 | static ssize_t store_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1620 | struct device_attribute *attr, |
| 1621 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1622 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1623 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1624 | sscanf(buf, "%i", &p->eeprom_delay); |
| 1625 | return strnlen(buf, count); |
| 1626 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1627 | |
| 1628 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, |
| 1629 | show_eeprom_delay, store_eeprom_delay); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1630 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1631 | static ssize_t show_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1632 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1633 | { |
| 1634 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1635 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1636 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1637 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1638 | return sprintf(buf, "0x%08x\n", reg); |
| 1639 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1640 | static ssize_t store_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1641 | struct device_attribute *attr, |
| 1642 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1643 | { |
| 1644 | u32 reg; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1645 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1646 | |
| 1647 | sscanf(buf, "%x", ®); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1648 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1649 | return strnlen(buf, count); |
| 1650 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1651 | |
| 1652 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, |
| 1653 | show_command_event_reg, store_command_event_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1654 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1655 | static ssize_t show_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1656 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1657 | { |
| 1658 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1659 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1660 | |
| 1661 | reg = ipw_read_reg32(p, 0x301100); |
| 1662 | return sprintf(buf, "0x%08x\n", reg); |
| 1663 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1664 | static ssize_t store_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1665 | struct device_attribute *attr, |
| 1666 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1667 | { |
| 1668 | u32 reg; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1669 | struct ipw_priv *p = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1670 | |
| 1671 | sscanf(buf, "%x", ®); |
| 1672 | ipw_write_reg32(p, 0x301100, reg); |
| 1673 | return strnlen(buf, count); |
| 1674 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1675 | |
| 1676 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, |
| 1677 | show_mem_gpio_reg, store_mem_gpio_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1678 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1679 | static ssize_t show_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1680 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1681 | { |
| 1682 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1683 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1684 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1685 | if (priv->status & STATUS_INDIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1686 | reg = ipw_read_reg32(priv, priv->indirect_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1687 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1688 | reg = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1689 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1690 | return sprintf(buf, "0x%08x\n", reg); |
| 1691 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1692 | static ssize_t store_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1693 | struct device_attribute *attr, |
| 1694 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1695 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1696 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1697 | |
| 1698 | sscanf(buf, "%x", &priv->indirect_dword); |
| 1699 | priv->status |= STATUS_INDIRECT_DWORD; |
| 1700 | return strnlen(buf, count); |
| 1701 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1702 | |
| 1703 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, |
| 1704 | show_indirect_dword, store_indirect_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1705 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1706 | static ssize_t show_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1707 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1708 | { |
| 1709 | u8 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1710 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1711 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1712 | if (priv->status & STATUS_INDIRECT_BYTE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1713 | reg = ipw_read_reg8(priv, priv->indirect_byte); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1714 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1715 | reg = 0; |
| 1716 | |
| 1717 | return sprintf(buf, "0x%02x\n", reg); |
| 1718 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1719 | static ssize_t store_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1720 | struct device_attribute *attr, |
| 1721 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1722 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1723 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1724 | |
| 1725 | sscanf(buf, "%x", &priv->indirect_byte); |
| 1726 | priv->status |= STATUS_INDIRECT_BYTE; |
| 1727 | return strnlen(buf, count); |
| 1728 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1729 | |
| 1730 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1731 | show_indirect_byte, store_indirect_byte); |
| 1732 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1733 | static ssize_t show_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1734 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1735 | { |
| 1736 | u32 reg = 0; |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1737 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1738 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1739 | if (priv->status & STATUS_DIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1740 | reg = ipw_read32(priv, priv->direct_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1741 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1742 | reg = 0; |
| 1743 | |
| 1744 | return sprintf(buf, "0x%08x\n", reg); |
| 1745 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1746 | static ssize_t store_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1747 | struct device_attribute *attr, |
| 1748 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1749 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1750 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1751 | |
| 1752 | sscanf(buf, "%x", &priv->direct_dword); |
| 1753 | priv->status |= STATUS_DIRECT_DWORD; |
| 1754 | return strnlen(buf, count); |
| 1755 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1756 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1757 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, |
| 1758 | show_direct_dword, store_direct_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1759 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1760 | static int rf_kill_active(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1761 | { |
Matthew Garrett | 25f94ae | 2009-11-11 14:36:31 -0500 | [diff] [blame] | 1762 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1763 | priv->status |= STATUS_RF_KILL_HW; |
Matthew Garrett | 25f94ae | 2009-11-11 14:36:31 -0500 | [diff] [blame] | 1764 | wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true); |
| 1765 | } else { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1766 | priv->status &= ~STATUS_RF_KILL_HW; |
Matthew Garrett | 25f94ae | 2009-11-11 14:36:31 -0500 | [diff] [blame] | 1767 | wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false); |
| 1768 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1769 | |
| 1770 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; |
| 1771 | } |
| 1772 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1773 | 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] | 1774 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1775 | { |
| 1776 | /* 0 - RF kill not enabled |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1777 | 1 - SW based RF kill active (sysfs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1778 | 2 - HW based RF kill active |
| 1779 | 3 - Both HW and SW baed RF kill active */ |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1780 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1781 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1782 | (rf_kill_active(priv) ? 0x2 : 0x0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1783 | return sprintf(buf, "%i\n", val); |
| 1784 | } |
| 1785 | |
| 1786 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) |
| 1787 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1788 | if ((disable_radio ? 1 : 0) == |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1789 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1790 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1791 | |
| 1792 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", |
| 1793 | disable_radio ? "OFF" : "ON"); |
| 1794 | |
| 1795 | if (disable_radio) { |
| 1796 | priv->status |= STATUS_RF_KILL_SW; |
| 1797 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 1798 | if (priv->workqueue) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1799 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 1800 | cancel_delayed_work(&priv->request_direct_scan); |
| 1801 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 1802 | cancel_delayed_work(&priv->scan_event); |
| 1803 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1804 | queue_work(priv->workqueue, &priv->down); |
| 1805 | } else { |
| 1806 | priv->status &= ~STATUS_RF_KILL_SW; |
| 1807 | if (rf_kill_active(priv)) { |
| 1808 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1809 | "disabled by HW switch\n"); |
| 1810 | /* Make sure the RF_KILL check timer is running */ |
| 1811 | cancel_delayed_work(&priv->rf_kill); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1812 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 1813 | round_jiffies_relative(2 * HZ)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1814 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1815 | queue_work(priv->workqueue, &priv->up); |
| 1816 | } |
| 1817 | |
| 1818 | return 1; |
| 1819 | } |
| 1820 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1821 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
| 1822 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1823 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1824 | struct ipw_priv *priv = dev_get_drvdata(d); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1825 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1826 | ipw_radio_kill_sw(priv, buf[0] == '1'); |
| 1827 | |
| 1828 | return count; |
| 1829 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1830 | |
| 1831 | 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] | 1832 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1833 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, |
| 1834 | char *buf) |
| 1835 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1836 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1837 | int pos = 0, len = 0; |
| 1838 | if (priv->config & CFG_SPEED_SCAN) { |
| 1839 | while (priv->speed_scan[pos] != 0) |
| 1840 | len += sprintf(&buf[len], "%d ", |
| 1841 | priv->speed_scan[pos++]); |
| 1842 | return len + sprintf(&buf[len], "\n"); |
| 1843 | } |
| 1844 | |
| 1845 | return sprintf(buf, "0\n"); |
| 1846 | } |
| 1847 | |
| 1848 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, |
| 1849 | const char *buf, size_t count) |
| 1850 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1851 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1852 | int channel, pos = 0; |
| 1853 | const char *p = buf; |
| 1854 | |
| 1855 | /* list of space separated channels to scan, optionally ending with 0 */ |
| 1856 | while ((channel = simple_strtol(p, NULL, 0))) { |
| 1857 | if (pos == MAX_SPEED_SCAN - 1) { |
| 1858 | priv->speed_scan[pos] = 0; |
| 1859 | break; |
| 1860 | } |
| 1861 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1862 | if (libipw_is_valid_channel(priv->ieee, channel)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1863 | priv->speed_scan[pos++] = channel; |
| 1864 | else |
| 1865 | IPW_WARNING("Skipping invalid channel request: %d\n", |
| 1866 | channel); |
| 1867 | p = strchr(p, ' '); |
| 1868 | if (!p) |
| 1869 | break; |
| 1870 | while (*p == ' ' || *p == '\t') |
| 1871 | p++; |
| 1872 | } |
| 1873 | |
| 1874 | if (pos == 0) |
| 1875 | priv->config &= ~CFG_SPEED_SCAN; |
| 1876 | else { |
| 1877 | priv->speed_scan_pos = 0; |
| 1878 | priv->config |= CFG_SPEED_SCAN; |
| 1879 | } |
| 1880 | |
| 1881 | return count; |
| 1882 | } |
| 1883 | |
| 1884 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, |
| 1885 | store_speed_scan); |
| 1886 | |
| 1887 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, |
| 1888 | char *buf) |
| 1889 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1890 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1891 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); |
| 1892 | } |
| 1893 | |
| 1894 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, |
| 1895 | const char *buf, size_t count) |
| 1896 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 1897 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1898 | if (buf[0] == '1') |
| 1899 | priv->config |= CFG_NET_STATS; |
| 1900 | else |
| 1901 | priv->config &= ~CFG_NET_STATS; |
| 1902 | |
| 1903 | return count; |
| 1904 | } |
| 1905 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1906 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, |
| 1907 | show_net_stats, store_net_stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1908 | |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1909 | static ssize_t show_channels(struct device *d, |
| 1910 | struct device_attribute *attr, |
| 1911 | char *buf) |
| 1912 | { |
| 1913 | struct ipw_priv *priv = dev_get_drvdata(d); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1914 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1915 | int len = 0, i; |
| 1916 | |
| 1917 | len = sprintf(&buf[len], |
| 1918 | "Displaying %d channels in 2.4Ghz band " |
| 1919 | "(802.11bg):\n", geo->bg_channels); |
| 1920 | |
| 1921 | for (i = 0; i < geo->bg_channels; i++) { |
| 1922 | len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n", |
| 1923 | geo->bg[i].channel, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1924 | geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1925 | " (radar spectrum)" : "", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1926 | ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) || |
| 1927 | (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)) |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1928 | ? "" : ", IBSS", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1929 | geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1930 | "passive only" : "active/passive", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1931 | geo->bg[i].flags & LIBIPW_CH_B_ONLY ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1932 | "B" : "B/G"); |
| 1933 | } |
| 1934 | |
| 1935 | len += sprintf(&buf[len], |
| 1936 | "Displaying %d channels in 5.2Ghz band " |
| 1937 | "(802.11a):\n", geo->a_channels); |
| 1938 | for (i = 0; i < geo->a_channels; i++) { |
| 1939 | len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n", |
| 1940 | geo->a[i].channel, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1941 | geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1942 | " (radar spectrum)" : "", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1943 | ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) || |
| 1944 | (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)) |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1945 | ? "" : ", IBSS", |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 1946 | geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ? |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 1947 | "passive only" : "active/passive"); |
| 1948 | } |
| 1949 | |
| 1950 | return len; |
| 1951 | } |
| 1952 | |
| 1953 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 1954 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1955 | static void notify_wx_assoc_event(struct ipw_priv *priv) |
| 1956 | { |
| 1957 | union iwreq_data wrqu; |
| 1958 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1959 | if (priv->status & STATUS_ASSOCIATED) |
| 1960 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); |
| 1961 | else |
| 1962 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 1963 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); |
| 1964 | } |
| 1965 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1966 | static void ipw_irq_tasklet(struct ipw_priv *priv) |
| 1967 | { |
| 1968 | u32 inta, inta_mask, handled = 0; |
| 1969 | unsigned long flags; |
| 1970 | int rc = 0; |
| 1971 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1972 | spin_lock_irqsave(&priv->irq_lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1973 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1974 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 1975 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
| 1976 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1977 | |
| 1978 | /* Add any cached INTA values that need to be handled */ |
| 1979 | inta |= priv->isr_inta; |
| 1980 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1981 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 1982 | |
| 1983 | spin_lock_irqsave(&priv->lock, flags); |
| 1984 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1985 | /* handle all the justifications for the interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1986 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1987 | ipw_rx(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1988 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1989 | } |
| 1990 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1991 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1992 | IPW_DEBUG_HC("Command completed.\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1993 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1994 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1995 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1996 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1997 | } |
| 1998 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1999 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2000 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2001 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2002 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2003 | } |
| 2004 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2005 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2006 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2007 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2008 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2009 | } |
| 2010 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2011 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2012 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2013 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2014 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2015 | } |
| 2016 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2017 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2018 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2019 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2020 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
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_STATUS_CHANGE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2024 | IPW_WARNING("STATUS_CHANGE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2025 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
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_BEACON_PERIOD_EXPIRED) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2029 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2030 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
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_SLAVE_MODE_HOST_CMD_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2034 | IPW_WARNING("HOST_CMD_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2035 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_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_INITIALIZATION_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2039 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2040 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_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_FW_CARD_DISABLE_PHY_OFF_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2044 | IPW_WARNING("PHY_OFF_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2045 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2046 | } |
| 2047 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2048 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2049 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
| 2050 | priv->status |= STATUS_RF_KILL_HW; |
Matthew Garrett | 25f94ae | 2009-11-11 14:36:31 -0500 | [diff] [blame] | 2051 | wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2052 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 2053 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2054 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 2055 | cancel_delayed_work(&priv->request_direct_scan); |
| 2056 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 2057 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2058 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2059 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2060 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2061 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2062 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2063 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2064 | IPW_WARNING("Firmware error detected. Restarting.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2065 | if (priv->error) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2066 | IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2067 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
| 2068 | struct ipw_fw_error *error = |
| 2069 | ipw_alloc_error_log(priv); |
| 2070 | ipw_dump_error_log(priv, error); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 2071 | kfree(error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2072 | } |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2073 | } else { |
| 2074 | priv->error = ipw_alloc_error_log(priv); |
| 2075 | if (priv->error) |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2076 | IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2077 | else |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2078 | IPW_DEBUG_FW("Error allocating sysfs 'error' " |
| 2079 | "log.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2080 | if (ipw_debug_level & IPW_DL_FW_ERRORS) |
| 2081 | ipw_dump_error_log(priv, priv->error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2082 | } |
| 2083 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2084 | /* XXX: If hardware encryption is for WPA/WPA2, |
| 2085 | * we have to notify the supplicant. */ |
| 2086 | if (priv->ieee->sec.encrypt) { |
| 2087 | priv->status &= ~STATUS_ASSOCIATED; |
| 2088 | notify_wx_assoc_event(priv); |
| 2089 | } |
| 2090 | |
| 2091 | /* Keep the restart process from trying to send host |
| 2092 | * commands by clearing the INIT status bit */ |
| 2093 | priv->status &= ~STATUS_INIT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2094 | |
| 2095 | /* Cancel currently queued command. */ |
| 2096 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2097 | wake_up_interruptible(&priv->wait_command_queue); |
| 2098 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2099 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2100 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2101 | } |
| 2102 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2103 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2104 | IPW_ERROR("Parity error\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2105 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | if (handled != inta) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2109 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2110 | } |
| 2111 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 2112 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2113 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2114 | /* enable all interrupts */ |
| 2115 | ipw_enable_interrupts(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2116 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2117 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2118 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
| 2119 | static char *get_cmd_string(u8 cmd) |
| 2120 | { |
| 2121 | switch (cmd) { |
| 2122 | IPW_CMD(HOST_COMPLETE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2123 | IPW_CMD(POWER_DOWN); |
| 2124 | IPW_CMD(SYSTEM_CONFIG); |
| 2125 | IPW_CMD(MULTICAST_ADDRESS); |
| 2126 | IPW_CMD(SSID); |
| 2127 | IPW_CMD(ADAPTER_ADDRESS); |
| 2128 | IPW_CMD(PORT_TYPE); |
| 2129 | IPW_CMD(RTS_THRESHOLD); |
| 2130 | IPW_CMD(FRAG_THRESHOLD); |
| 2131 | IPW_CMD(POWER_MODE); |
| 2132 | IPW_CMD(WEP_KEY); |
| 2133 | IPW_CMD(TGI_TX_KEY); |
| 2134 | IPW_CMD(SCAN_REQUEST); |
| 2135 | IPW_CMD(SCAN_REQUEST_EXT); |
| 2136 | IPW_CMD(ASSOCIATE); |
| 2137 | IPW_CMD(SUPPORTED_RATES); |
| 2138 | IPW_CMD(SCAN_ABORT); |
| 2139 | IPW_CMD(TX_FLUSH); |
| 2140 | IPW_CMD(QOS_PARAMETERS); |
| 2141 | IPW_CMD(DINO_CONFIG); |
| 2142 | IPW_CMD(RSN_CAPABILITIES); |
| 2143 | IPW_CMD(RX_KEY); |
| 2144 | IPW_CMD(CARD_DISABLE); |
| 2145 | IPW_CMD(SEED_NUMBER); |
| 2146 | IPW_CMD(TX_POWER); |
| 2147 | IPW_CMD(COUNTRY_INFO); |
| 2148 | IPW_CMD(AIRONET_INFO); |
| 2149 | IPW_CMD(AP_TX_POWER); |
| 2150 | IPW_CMD(CCKM_INFO); |
| 2151 | IPW_CMD(CCX_VER_INFO); |
| 2152 | IPW_CMD(SET_CALIBRATION); |
| 2153 | IPW_CMD(SENSITIVITY_CALIB); |
| 2154 | IPW_CMD(RETRY_LIMIT); |
| 2155 | IPW_CMD(IPW_PRE_POWER_DOWN); |
| 2156 | IPW_CMD(VAP_BEACON_TEMPLATE); |
| 2157 | IPW_CMD(VAP_DTIM_PERIOD); |
| 2158 | IPW_CMD(EXT_SUPPORTED_RATES); |
| 2159 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); |
| 2160 | IPW_CMD(VAP_QUIET_INTERVALS); |
| 2161 | IPW_CMD(VAP_CHANNEL_SWITCH); |
| 2162 | IPW_CMD(VAP_MANDATORY_CHANNELS); |
| 2163 | IPW_CMD(VAP_CELL_PWR_LIMIT); |
| 2164 | IPW_CMD(VAP_CF_PARAM_SET); |
| 2165 | IPW_CMD(VAP_SET_BEACONING_STATE); |
| 2166 | IPW_CMD(MEASUREMENT); |
| 2167 | IPW_CMD(POWER_CAPABILITY); |
| 2168 | IPW_CMD(SUPPORTED_CHANNELS); |
| 2169 | IPW_CMD(TPC_REPORT); |
| 2170 | IPW_CMD(WME_INFO); |
| 2171 | IPW_CMD(PRODUCTION_COMMAND); |
| 2172 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2173 | return "UNKNOWN"; |
| 2174 | } |
| 2175 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2176 | |
| 2177 | #define HOST_COMPLETE_TIMEOUT HZ |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2178 | |
| 2179 | 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] | 2180 | { |
| 2181 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2182 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2183 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2184 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2185 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2186 | IPW_ERROR("Failed to send %s: Already sending a command.\n", |
| 2187 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2188 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2189 | return -EAGAIN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | priv->status |= STATUS_HCMD_ACTIVE; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2193 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2194 | if (priv->cmdlog) { |
| 2195 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; |
| 2196 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; |
| 2197 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; |
| 2198 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, |
| 2199 | cmd->len); |
| 2200 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; |
| 2201 | } |
| 2202 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2203 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
| 2204 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, |
| 2205 | priv->status); |
Zhu Yi | f516dbc | 2006-01-24 16:36:44 +0800 | [diff] [blame] | 2206 | |
| 2207 | #ifndef DEBUG_CMD_WEP_KEY |
| 2208 | if (cmd->cmd == IPW_CMD_WEP_KEY) |
| 2209 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); |
| 2210 | else |
| 2211 | #endif |
| 2212 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); |
| 2213 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2214 | 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] | 2215 | if (rc) { |
| 2216 | priv->status &= ~STATUS_HCMD_ACTIVE; |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2217 | IPW_ERROR("Failed to send %s: Reason %d\n", |
| 2218 | get_cmd_string(cmd->cmd), rc); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2219 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2220 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2221 | } |
| 2222 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2223 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2224 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 2225 | !(priv-> |
| 2226 | status & STATUS_HCMD_ACTIVE), |
| 2227 | HOST_COMPLETE_TIMEOUT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2228 | if (rc == 0) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2229 | spin_lock_irqsave(&priv->lock, flags); |
| 2230 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2231 | IPW_ERROR("Failed to send %s: Command timed out.\n", |
| 2232 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2233 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2234 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2235 | rc = -EIO; |
| 2236 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2237 | } |
| 2238 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 2239 | } else |
| 2240 | rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2241 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2242 | if (priv->status & STATUS_RF_KILL_HW) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2243 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", |
| 2244 | get_cmd_string(cmd->cmd)); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2245 | rc = -EIO; |
| 2246 | goto exit; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2247 | } |
| 2248 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2249 | exit: |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2250 | if (priv->cmdlog) { |
| 2251 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; |
| 2252 | priv->cmdlog_pos %= priv->cmdlog_len; |
| 2253 | } |
| 2254 | return rc; |
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 | static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2258 | { |
| 2259 | struct host_cmd cmd = { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2260 | .cmd = command, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2261 | }; |
| 2262 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2263 | return __ipw_send_cmd(priv, &cmd); |
| 2264 | } |
| 2265 | |
| 2266 | static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, |
| 2267 | void *data) |
| 2268 | { |
| 2269 | struct host_cmd cmd = { |
| 2270 | .cmd = command, |
| 2271 | .len = len, |
| 2272 | .param = data, |
| 2273 | }; |
| 2274 | |
| 2275 | return __ipw_send_cmd(priv, &cmd); |
| 2276 | } |
| 2277 | |
| 2278 | static int ipw_send_host_complete(struct ipw_priv *priv) |
| 2279 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2280 | if (!priv) { |
| 2281 | IPW_ERROR("Invalid args\n"); |
| 2282 | return -1; |
| 2283 | } |
| 2284 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2285 | return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2286 | } |
| 2287 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2288 | static int ipw_send_system_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2289 | { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2290 | return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, |
| 2291 | sizeof(priv->sys_config), |
| 2292 | &priv->sys_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2293 | } |
| 2294 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2295 | 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] | 2296 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2297 | if (!priv || !ssid) { |
| 2298 | IPW_ERROR("Invalid args\n"); |
| 2299 | return -1; |
| 2300 | } |
| 2301 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2302 | 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] | 2303 | ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2304 | } |
| 2305 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2306 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2307 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2308 | if (!priv || !mac) { |
| 2309 | IPW_ERROR("Invalid args\n"); |
| 2310 | return -1; |
| 2311 | } |
| 2312 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2313 | IPW_DEBUG_INFO("%s: Setting MAC to %pM\n", |
| 2314 | priv->net_dev->name, mac); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2315 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2316 | 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] | 2317 | } |
| 2318 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2319 | /* |
| 2320 | * NOTE: This must be executed from our workqueue as it results in udelay |
| 2321 | * being called which may corrupt the keyboard if executed on default |
| 2322 | * workqueue |
| 2323 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2324 | static void ipw_adapter_restart(void *adapter) |
| 2325 | { |
| 2326 | struct ipw_priv *priv = adapter; |
| 2327 | |
| 2328 | if (priv->status & STATUS_RF_KILL_MASK) |
| 2329 | return; |
| 2330 | |
| 2331 | ipw_down(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2332 | |
| 2333 | if (priv->assoc_network && |
| 2334 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) |
| 2335 | ipw_remove_current_network(priv); |
| 2336 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2337 | if (ipw_up(priv)) { |
| 2338 | IPW_ERROR("Failed to up device\n"); |
| 2339 | return; |
| 2340 | } |
| 2341 | } |
| 2342 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2343 | static void ipw_bg_adapter_restart(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2344 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2345 | struct ipw_priv *priv = |
| 2346 | container_of(work, struct ipw_priv, adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2347 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2348 | ipw_adapter_restart(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2349 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2350 | } |
| 2351 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2352 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
| 2353 | |
| 2354 | static void ipw_scan_check(void *data) |
| 2355 | { |
| 2356 | struct ipw_priv *priv = data; |
| 2357 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
| 2358 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2359 | "adapter after (%dms).\n", |
| 2360 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2361 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2362 | } |
| 2363 | } |
| 2364 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2365 | static void ipw_bg_scan_check(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2366 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2367 | struct ipw_priv *priv = |
| 2368 | container_of(work, struct ipw_priv, scan_check.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2369 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2370 | ipw_scan_check(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2371 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2372 | } |
| 2373 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2374 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
| 2375 | struct ipw_scan_request_ext *request) |
| 2376 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2377 | return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2378 | sizeof(*request), request); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | static int ipw_send_scan_abort(struct ipw_priv *priv) |
| 2382 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2383 | if (!priv) { |
| 2384 | IPW_ERROR("Invalid args\n"); |
| 2385 | return -1; |
| 2386 | } |
| 2387 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2388 | return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) |
| 2392 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2393 | struct ipw_sensitivity_calib calib = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2394 | .beacon_rssi_raw = cpu_to_le16(sens), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2395 | }; |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2396 | |
| 2397 | return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2398 | &calib); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | static int ipw_send_associate(struct ipw_priv *priv, |
| 2402 | struct ipw_associate *associate) |
| 2403 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2404 | if (!priv || !associate) { |
| 2405 | IPW_ERROR("Invalid args\n"); |
| 2406 | return -1; |
| 2407 | } |
| 2408 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 2409 | return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate), |
| 2410 | associate); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | static int ipw_send_supported_rates(struct ipw_priv *priv, |
| 2414 | struct ipw_supported_rates *rates) |
| 2415 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2416 | if (!priv || !rates) { |
| 2417 | IPW_ERROR("Invalid args\n"); |
| 2418 | return -1; |
| 2419 | } |
| 2420 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2421 | return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2422 | rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | static int ipw_set_random_seed(struct ipw_priv *priv) |
| 2426 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2427 | u32 val; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2428 | |
| 2429 | if (!priv) { |
| 2430 | IPW_ERROR("Invalid args\n"); |
| 2431 | return -1; |
| 2432 | } |
| 2433 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2434 | get_random_bytes(&val, sizeof(val)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2435 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2436 | 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] | 2437 | } |
| 2438 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2439 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
| 2440 | { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2441 | __le32 v = cpu_to_le32(phy_off); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2442 | if (!priv) { |
| 2443 | IPW_ERROR("Invalid args\n"); |
| 2444 | return -1; |
| 2445 | } |
| 2446 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2447 | 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] | 2448 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2449 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2450 | 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] | 2451 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2452 | if (!priv || !power) { |
| 2453 | IPW_ERROR("Invalid args\n"); |
| 2454 | return -1; |
| 2455 | } |
| 2456 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2457 | 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] | 2458 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2459 | |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2460 | static int ipw_set_tx_power(struct ipw_priv *priv) |
| 2461 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2462 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2463 | struct ipw_tx_power tx_power; |
| 2464 | s8 max_power; |
| 2465 | int i; |
| 2466 | |
| 2467 | memset(&tx_power, 0, sizeof(tx_power)); |
| 2468 | |
| 2469 | /* configure device for 'G' band */ |
| 2470 | tx_power.ieee_mode = IPW_G_MODE; |
| 2471 | tx_power.num_channels = geo->bg_channels; |
| 2472 | for (i = 0; i < geo->bg_channels; i++) { |
| 2473 | max_power = geo->bg[i].max_power; |
| 2474 | tx_power.channels_tx_power[i].channel_number = |
| 2475 | geo->bg[i].channel; |
| 2476 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2477 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2478 | } |
| 2479 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2480 | return -EIO; |
| 2481 | |
| 2482 | /* configure device to also handle 'B' band */ |
| 2483 | tx_power.ieee_mode = IPW_B_MODE; |
| 2484 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2485 | return -EIO; |
| 2486 | |
| 2487 | /* configure device to also handle 'A' band */ |
| 2488 | if (priv->ieee->abg_true) { |
| 2489 | tx_power.ieee_mode = IPW_A_MODE; |
| 2490 | tx_power.num_channels = geo->a_channels; |
| 2491 | for (i = 0; i < tx_power.num_channels; i++) { |
| 2492 | max_power = geo->a[i].max_power; |
| 2493 | tx_power.channels_tx_power[i].channel_number = |
| 2494 | geo->a[i].channel; |
| 2495 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2496 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2497 | } |
| 2498 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2499 | return -EIO; |
| 2500 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2501 | return 0; |
| 2502 | } |
| 2503 | |
| 2504 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) |
| 2505 | { |
| 2506 | struct ipw_rts_threshold rts_threshold = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2507 | .rts_threshold = cpu_to_le16(rts), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2508 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2509 | |
| 2510 | if (!priv) { |
| 2511 | IPW_ERROR("Invalid args\n"); |
| 2512 | return -1; |
| 2513 | } |
| 2514 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2515 | return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, |
| 2516 | sizeof(rts_threshold), &rts_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) |
| 2520 | { |
| 2521 | struct ipw_frag_threshold frag_threshold = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2522 | .frag_threshold = cpu_to_le16(frag), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2523 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2524 | |
| 2525 | if (!priv) { |
| 2526 | IPW_ERROR("Invalid args\n"); |
| 2527 | return -1; |
| 2528 | } |
| 2529 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2530 | return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, |
| 2531 | sizeof(frag_threshold), &frag_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) |
| 2535 | { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2536 | __le32 param; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2537 | |
| 2538 | if (!priv) { |
| 2539 | IPW_ERROR("Invalid args\n"); |
| 2540 | return -1; |
| 2541 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2542 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2543 | /* If on battery, set to 3, if AC set to CAM, else user |
| 2544 | * level */ |
| 2545 | switch (mode) { |
| 2546 | case IPW_POWER_BATTERY: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2547 | param = cpu_to_le32(IPW_POWER_INDEX_3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2548 | break; |
| 2549 | case IPW_POWER_AC: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2550 | param = cpu_to_le32(IPW_POWER_MODE_CAM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2551 | break; |
| 2552 | default: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2553 | param = cpu_to_le32(mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2554 | break; |
| 2555 | } |
| 2556 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2557 | return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2558 | ¶m); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2559 | } |
| 2560 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2561 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
| 2562 | { |
| 2563 | struct ipw_retry_limit retry_limit = { |
| 2564 | .short_retry_limit = slimit, |
| 2565 | .long_retry_limit = llimit |
| 2566 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2567 | |
| 2568 | if (!priv) { |
| 2569 | IPW_ERROR("Invalid args\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2570 | return -1; |
| 2571 | } |
| 2572 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2573 | 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] | 2574 | &retry_limit); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | /* |
| 2578 | * The IPW device contains a Microwire compatible EEPROM that stores |
| 2579 | * various data like the MAC address. Usually the firmware has exclusive |
| 2580 | * access to the eeprom, but during device initialization (before the |
| 2581 | * device driver has sent the HostComplete command to the firmware) the |
| 2582 | * device driver has read access to the EEPROM by way of indirect addressing |
| 2583 | * through a couple of memory mapped registers. |
| 2584 | * |
| 2585 | * The following is a simplified implementation for pulling data out of the |
| 2586 | * the eeprom, along with some helper functions to find information in |
| 2587 | * the per device private data's copy of the eeprom. |
| 2588 | * |
| 2589 | * NOTE: To better understand how these functions work (i.e what is a chip |
| 2590 | * select and why do have to keep driving the eeprom clock?), read |
| 2591 | * just about any data sheet for a Microwire compatible EEPROM. |
| 2592 | */ |
| 2593 | |
| 2594 | /* write a 32 bit value into the indirect accessor register */ |
| 2595 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) |
| 2596 | { |
| 2597 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2598 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2599 | /* the eeprom requires some time to complete the operation */ |
| 2600 | udelay(p->eeprom_delay); |
| 2601 | |
| 2602 | return; |
| 2603 | } |
| 2604 | |
| 2605 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2606 | static void eeprom_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2607 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2608 | eeprom_write_reg(priv, 0); |
| 2609 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2610 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2611 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2615 | static void eeprom_disable_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2616 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2617 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2618 | eeprom_write_reg(priv, 0); |
| 2619 | eeprom_write_reg(priv, EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | /* push a single bit down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2623 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2624 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2625 | int d = (bit ? EEPROM_BIT_DI : 0); |
| 2626 | eeprom_write_reg(p, EEPROM_BIT_CS | d); |
| 2627 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | /* push an opcode followed by an address down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2631 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2632 | { |
| 2633 | int i; |
| 2634 | |
| 2635 | eeprom_cs(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2636 | eeprom_write_bit(priv, 1); |
| 2637 | eeprom_write_bit(priv, op & 2); |
| 2638 | eeprom_write_bit(priv, op & 1); |
| 2639 | for (i = 7; i >= 0; i--) { |
| 2640 | eeprom_write_bit(priv, addr & (1 << i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2641 | } |
| 2642 | } |
| 2643 | |
| 2644 | /* pull 16 bits off the eeprom, one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2645 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2646 | { |
| 2647 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2648 | u16 r = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2649 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2650 | /* Send READ Opcode */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2651 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2652 | |
| 2653 | /* Send dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2654 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2655 | |
| 2656 | /* Read the byte off the eeprom one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2657 | for (i = 0; i < 16; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2658 | u32 data = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2659 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2660 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2661 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); |
| 2662 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2663 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2664 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2665 | /* Send another dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2666 | eeprom_write_reg(priv, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2667 | eeprom_disable_cs(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2668 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2669 | return r; |
| 2670 | } |
| 2671 | |
| 2672 | /* helper function for pulling the mac address out of the private */ |
| 2673 | /* data's copy of the eeprom data */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2674 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2675 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2676 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | /* |
| 2680 | * Either the device driver (i.e. the host) or the firmware can |
| 2681 | * load eeprom data into the designated region in SRAM. If neither |
| 2682 | * happens then the FW will shutdown with a fatal error. |
| 2683 | * |
| 2684 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE |
| 2685 | * bit needs region of shared SRAM needs to be non-zero. |
| 2686 | */ |
| 2687 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) |
| 2688 | { |
| 2689 | int i; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2690 | __le16 *eeprom = (__le16 *) priv->eeprom; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2691 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2692 | IPW_DEBUG_TRACE(">>\n"); |
| 2693 | |
| 2694 | /* read entire contents of eeprom into private buffer */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2695 | for (i = 0; i < 128; i++) |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2696 | eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2697 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2698 | /* |
| 2699 | If the data looks correct, then copy it to our private |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2700 | copy. Otherwise let the firmware know to perform the operation |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2701 | on its own. |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2702 | */ |
Alexey Dobriyan | 386093e | 2006-02-01 03:04:57 -0800 | [diff] [blame] | 2703 | if (priv->eeprom[EEPROM_VERSION] != 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2704 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
| 2705 | |
| 2706 | /* write the eeprom data to sram */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2707 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2708 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2709 | |
| 2710 | /* Do not load eeprom data on fatal error or suspend */ |
| 2711 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 2712 | } else { |
| 2713 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); |
| 2714 | |
| 2715 | /* Load eeprom data on fatal error or suspend */ |
| 2716 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); |
| 2717 | } |
| 2718 | |
| 2719 | IPW_DEBUG_TRACE("<<\n"); |
| 2720 | } |
| 2721 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2722 | 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] | 2723 | { |
| 2724 | count >>= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2725 | if (!count) |
| 2726 | return; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2727 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2728 | while (count--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2729 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) |
| 2733 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2734 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2735 | CB_NUMBER_OF_ELEMENTS_SMALL * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2736 | sizeof(struct command_block)); |
| 2737 | } |
| 2738 | |
| 2739 | static int ipw_fw_dma_enable(struct ipw_priv *priv) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2740 | { /* start dma engine but no transfers yet */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2741 | |
| 2742 | IPW_DEBUG_FW(">> : \n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2743 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2744 | /* Start the dma */ |
| 2745 | ipw_fw_dma_reset_command_blocks(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2746 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2747 | /* Write CB base address */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2748 | 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] | 2749 | |
| 2750 | IPW_DEBUG_FW("<< : \n"); |
| 2751 | return 0; |
| 2752 | } |
| 2753 | |
| 2754 | static void ipw_fw_dma_abort(struct ipw_priv *priv) |
| 2755 | { |
| 2756 | u32 control = 0; |
| 2757 | |
| 2758 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2759 | |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 2760 | /* set the Stop and Abort bit */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2761 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2762 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2763 | priv->sram_desc.last_cb_index = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2764 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2765 | IPW_DEBUG_FW("<< \n"); |
| 2766 | } |
| 2767 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2768 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
| 2769 | struct command_block *cb) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2770 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2771 | u32 address = |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2772 | IPW_SHARED_SRAM_DMA_CONTROL + |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2773 | (sizeof(struct command_block) * index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2774 | IPW_DEBUG_FW(">> :\n"); |
| 2775 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2776 | ipw_write_indirect(priv, address, (u8 *) cb, |
| 2777 | (int)sizeof(struct command_block)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2778 | |
| 2779 | IPW_DEBUG_FW("<< :\n"); |
| 2780 | return 0; |
| 2781 | |
| 2782 | } |
| 2783 | |
| 2784 | static int ipw_fw_dma_kick(struct ipw_priv *priv) |
| 2785 | { |
| 2786 | u32 control = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2787 | u32 index = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2788 | |
| 2789 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2790 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2791 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2792 | ipw_fw_dma_write_command_block(priv, index, |
| 2793 | &priv->sram_desc.cb_list[index]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2794 | |
| 2795 | /* Enable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2796 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 2797 | IPW_RESET_REG_MASTER_DISABLED | |
| 2798 | IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2799 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2800 | /* Set the Start bit. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2801 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2802 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2803 | |
| 2804 | IPW_DEBUG_FW("<< :\n"); |
| 2805 | return 0; |
| 2806 | } |
| 2807 | |
| 2808 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) |
| 2809 | { |
| 2810 | u32 address; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2811 | u32 register_value = 0; |
| 2812 | u32 cb_fields_address = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2813 | |
| 2814 | IPW_DEBUG_FW(">> :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2815 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2816 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2817 | |
| 2818 | /* Read the DMA Controlor register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2819 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
| 2820 | 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] | 2821 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2822 | /* Print the CB values */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2823 | cb_fields_address = address; |
| 2824 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2825 | 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] | 2826 | |
| 2827 | cb_fields_address += sizeof(u32); |
| 2828 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2829 | 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] | 2830 | |
| 2831 | cb_fields_address += sizeof(u32); |
| 2832 | register_value = ipw_read_reg32(priv, cb_fields_address); |
| 2833 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", |
| 2834 | register_value); |
| 2835 | |
| 2836 | cb_fields_address += sizeof(u32); |
| 2837 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2838 | 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] | 2839 | |
| 2840 | IPW_DEBUG_FW(">> :\n"); |
| 2841 | } |
| 2842 | |
| 2843 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) |
| 2844 | { |
| 2845 | u32 current_cb_address = 0; |
| 2846 | u32 current_cb_index = 0; |
| 2847 | |
| 2848 | IPW_DEBUG_FW("<< :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2849 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2850 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2851 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2852 | sizeof(struct command_block); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2853 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2854 | 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] | 2855 | current_cb_index, current_cb_address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2856 | |
| 2857 | IPW_DEBUG_FW(">> :\n"); |
| 2858 | return current_cb_index; |
| 2859 | |
| 2860 | } |
| 2861 | |
| 2862 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, |
| 2863 | u32 src_address, |
| 2864 | u32 dest_address, |
| 2865 | u32 length, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2866 | int interrupt_enabled, int is_last) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2867 | { |
| 2868 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2869 | 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] | 2870 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
| 2871 | CB_DEST_SIZE_LONG; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2872 | struct command_block *cb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2873 | u32 last_cb_element = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2874 | |
| 2875 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", |
| 2876 | src_address, dest_address, length); |
| 2877 | |
| 2878 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) |
| 2879 | return -1; |
| 2880 | |
| 2881 | last_cb_element = priv->sram_desc.last_cb_index; |
| 2882 | cb = &priv->sram_desc.cb_list[last_cb_element]; |
| 2883 | priv->sram_desc.last_cb_index++; |
| 2884 | |
| 2885 | /* Calculate the new CB control word */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2886 | if (interrupt_enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2887 | control |= CB_INT_ENABLED; |
| 2888 | |
| 2889 | if (is_last) |
| 2890 | control |= CB_LAST_VALID; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2891 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2892 | control |= length; |
| 2893 | |
| 2894 | /* Calculate the CB Element's checksum value */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2895 | cb->status = control ^ src_address ^ dest_address; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2896 | |
| 2897 | /* Copy the Source and Destination addresses */ |
| 2898 | cb->dest_addr = dest_address; |
| 2899 | cb->source_addr = src_address; |
| 2900 | |
| 2901 | /* Copy the Control Word last */ |
| 2902 | cb->control = control; |
| 2903 | |
| 2904 | return 0; |
| 2905 | } |
| 2906 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2907 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address, |
| 2908 | int nr, u32 dest_address, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2909 | { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2910 | int ret, i; |
| 2911 | u32 size; |
| 2912 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2913 | IPW_DEBUG_FW(">> \n"); |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2914 | IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n", |
| 2915 | nr, dest_address, len); |
| 2916 | |
| 2917 | for (i = 0; i < nr; i++) { |
| 2918 | size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH); |
| 2919 | ret = ipw_fw_dma_add_command_block(priv, src_address[i], |
| 2920 | dest_address + |
| 2921 | i * CB_MAX_LENGTH, size, |
| 2922 | 0, 0); |
| 2923 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2924 | IPW_DEBUG_FW_INFO(": Failed\n"); |
| 2925 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2926 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2927 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2928 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2929 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2930 | IPW_DEBUG_FW("<< \n"); |
| 2931 | return 0; |
| 2932 | } |
| 2933 | |
| 2934 | static int ipw_fw_dma_wait(struct ipw_priv *priv) |
| 2935 | { |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2936 | u32 current_index = 0, previous_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2937 | u32 watchdog = 0; |
| 2938 | |
| 2939 | IPW_DEBUG_FW(">> : \n"); |
| 2940 | |
| 2941 | current_index = ipw_fw_dma_command_block_index(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2942 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2943 | (int)priv->sram_desc.last_cb_index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2944 | |
| 2945 | while (current_index < priv->sram_desc.last_cb_index) { |
| 2946 | udelay(50); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2947 | previous_index = current_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2948 | current_index = ipw_fw_dma_command_block_index(priv); |
| 2949 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2950 | if (previous_index < current_index) { |
| 2951 | watchdog = 0; |
| 2952 | continue; |
| 2953 | } |
| 2954 | if (++watchdog > 400) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2955 | IPW_DEBUG_FW_INFO("Timeout\n"); |
| 2956 | ipw_fw_dma_dump_command_block(priv); |
| 2957 | ipw_fw_dma_abort(priv); |
| 2958 | return -1; |
| 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | ipw_fw_dma_abort(priv); |
| 2963 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2964 | /*Disable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2965 | ipw_set_bit(priv, IPW_RESET_REG, |
| 2966 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2967 | |
| 2968 | IPW_DEBUG_FW("<< dmaWaitSync \n"); |
| 2969 | return 0; |
| 2970 | } |
| 2971 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2972 | static void ipw_remove_current_network(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2973 | { |
| 2974 | struct list_head *element, *safe; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2975 | struct libipw_network *network = NULL; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2976 | unsigned long flags; |
| 2977 | |
| 2978 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2979 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2980 | network = list_entry(element, struct libipw_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2981 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 2982 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2983 | list_add_tail(&network->list, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2984 | &priv->ieee->network_free_list); |
| 2985 | } |
| 2986 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2987 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | /** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2991 | * Check that card is still alive. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2992 | * Reads debug register from domain0. |
| 2993 | * If card is present, pre-defined value should |
| 2994 | * be found there. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2995 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2996 | * @param priv |
| 2997 | * @return 1 if card is present, 0 otherwise |
| 2998 | */ |
| 2999 | static inline int ipw_alive(struct ipw_priv *priv) |
| 3000 | { |
| 3001 | return ipw_read32(priv, 0x90) == 0xd55555d5; |
| 3002 | } |
| 3003 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3004 | /* timeout in msec, attempted in 10-msec quanta */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3005 | 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] | 3006 | int timeout) |
| 3007 | { |
| 3008 | int i = 0; |
| 3009 | |
| 3010 | do { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3011 | if ((ipw_read32(priv, addr) & mask) == mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3012 | return i; |
| 3013 | mdelay(10); |
| 3014 | i += 10; |
| 3015 | } while (i < timeout); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3016 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3017 | return -ETIME; |
| 3018 | } |
| 3019 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3020 | /* These functions load the firmware and micro code for the operation of |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3021 | * the ipw hardware. It assumes the buffer has all the bits for the |
| 3022 | * image and the caller is handling the memory allocation and clean up. |
| 3023 | */ |
| 3024 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3025 | static int ipw_stop_master(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3026 | { |
| 3027 | int rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3028 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3029 | IPW_DEBUG_TRACE(">> \n"); |
| 3030 | /* stop master. typical delay - 0 */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3031 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3032 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3033 | /* timeout is in msec, polled in 10-msec quanta */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3034 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3035 | IPW_RESET_REG_MASTER_DISABLED, 100); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3036 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3037 | IPW_ERROR("wait for stop master failed after 100ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3038 | return -1; |
| 3039 | } |
| 3040 | |
| 3041 | IPW_DEBUG_INFO("stop master %dms\n", rc); |
| 3042 | |
| 3043 | return rc; |
| 3044 | } |
| 3045 | |
| 3046 | static void ipw_arc_release(struct ipw_priv *priv) |
| 3047 | { |
| 3048 | IPW_DEBUG_TRACE(">> \n"); |
| 3049 | mdelay(5); |
| 3050 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3051 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3052 | |
| 3053 | /* no one knows timing, for safety add some delay */ |
| 3054 | mdelay(5); |
| 3055 | } |
| 3056 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3057 | struct fw_chunk { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3058 | __le32 address; |
| 3059 | __le32 length; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3060 | }; |
| 3061 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3062 | 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] | 3063 | { |
| 3064 | int rc = 0, i, addr; |
| 3065 | u8 cr = 0; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3066 | __le16 *image; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3067 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3068 | image = (__le16 *) data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3069 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3070 | IPW_DEBUG_TRACE(">> \n"); |
| 3071 | |
| 3072 | rc = ipw_stop_master(priv); |
| 3073 | |
| 3074 | if (rc < 0) |
| 3075 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3076 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3077 | for (addr = IPW_SHARED_LOWER_BOUND; |
| 3078 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3079 | ipw_write32(priv, addr, 0); |
| 3080 | } |
| 3081 | |
| 3082 | /* no ucode (yet) */ |
| 3083 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); |
| 3084 | /* destroy DMA queues */ |
| 3085 | /* reset sequence */ |
| 3086 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3087 | 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] | 3088 | ipw_arc_release(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3089 | 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] | 3090 | mdelay(1); |
| 3091 | |
| 3092 | /* reset PHY */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3093 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3094 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3095 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3096 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3097 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3098 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3099 | /* enable ucode store */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 3100 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
| 3101 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3102 | mdelay(1); |
| 3103 | |
| 3104 | /* write ucode */ |
| 3105 | /** |
| 3106 | * @bug |
| 3107 | * Do NOT set indirect address register once and then |
| 3108 | * store data to indirect data register in the loop. |
| 3109 | * It seems very reasonable, but in this case DINO do not |
| 3110 | * accept ucode. It is essential to set address each time. |
| 3111 | */ |
| 3112 | /* load new ipw uCode */ |
| 3113 | for (i = 0; i < len / 2; i++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3114 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3115 | le16_to_cpu(image[i])); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3116 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3117 | /* enable DINO */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3118 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
| 3119 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3120 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3121 | /* this is where the igx / win driver deveates from the VAP driver. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3122 | |
| 3123 | /* wait for alive response */ |
| 3124 | for (i = 0; i < 100; i++) { |
| 3125 | /* poll for incoming data */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3126 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3127 | if (cr & DINO_RXFIFO_DATA) |
| 3128 | break; |
| 3129 | mdelay(1); |
| 3130 | } |
| 3131 | |
| 3132 | if (cr & DINO_RXFIFO_DATA) { |
| 3133 | /* alive_command_responce size is NOT multiple of 4 */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3134 | __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3135 | |
| 3136 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3137 | response_buffer[i] = |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3138 | cpu_to_le32(ipw_read_reg32(priv, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3139 | IPW_BASEBAND_RX_FIFO_READ)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3140 | memcpy(&priv->dino_alive, response_buffer, |
| 3141 | sizeof(priv->dino_alive)); |
| 3142 | if (priv->dino_alive.alive_command == 1 |
| 3143 | && priv->dino_alive.ucode_valid == 1) { |
| 3144 | rc = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3145 | IPW_DEBUG_INFO |
| 3146 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " |
| 3147 | "of %02d/%02d/%02d %02d:%02d\n", |
| 3148 | priv->dino_alive.software_revision, |
| 3149 | priv->dino_alive.software_revision, |
| 3150 | priv->dino_alive.device_identifier, |
| 3151 | priv->dino_alive.device_identifier, |
| 3152 | priv->dino_alive.time_stamp[0], |
| 3153 | priv->dino_alive.time_stamp[1], |
| 3154 | priv->dino_alive.time_stamp[2], |
| 3155 | priv->dino_alive.time_stamp[3], |
| 3156 | priv->dino_alive.time_stamp[4]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3157 | } else { |
| 3158 | IPW_DEBUG_INFO("Microcode is not alive\n"); |
| 3159 | rc = -EINVAL; |
| 3160 | } |
| 3161 | } else { |
| 3162 | IPW_DEBUG_INFO("No alive response from DINO\n"); |
| 3163 | rc = -ETIME; |
| 3164 | } |
| 3165 | |
| 3166 | /* disable DINO, otherwise for some reason |
| 3167 | firmware have problem getting alive resp. */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3168 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3169 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3170 | return rc; |
| 3171 | } |
| 3172 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3173 | 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] | 3174 | { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3175 | int ret = -1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3176 | int offset = 0; |
| 3177 | struct fw_chunk *chunk; |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3178 | int total_nr = 0; |
| 3179 | int i; |
| 3180 | struct pci_pool *pool; |
Zhu Yi | 4109316 | 2010-03-09 16:05:31 +0800 | [diff] [blame] | 3181 | void **virts; |
| 3182 | dma_addr_t *phys; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3183 | |
| 3184 | IPW_DEBUG_TRACE("<< : \n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3185 | |
Zhu Yi | 4109316 | 2010-03-09 16:05:31 +0800 | [diff] [blame] | 3186 | virts = kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL, |
| 3187 | GFP_KERNEL); |
| 3188 | if (!virts) |
| 3189 | return -ENOMEM; |
| 3190 | |
| 3191 | phys = kmalloc(sizeof(dma_addr_t) * CB_NUMBER_OF_ELEMENTS_SMALL, |
| 3192 | GFP_KERNEL); |
| 3193 | if (!phys) { |
| 3194 | kfree(virts); |
| 3195 | return -ENOMEM; |
| 3196 | } |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3197 | pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0); |
| 3198 | if (!pool) { |
| 3199 | IPW_ERROR("pci_pool_create failed\n"); |
Zhu Yi | 4109316 | 2010-03-09 16:05:31 +0800 | [diff] [blame] | 3200 | kfree(phys); |
| 3201 | kfree(virts); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3202 | return -ENOMEM; |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3203 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3204 | |
| 3205 | /* Start the Dma */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3206 | ret = ipw_fw_dma_enable(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3207 | |
Alexander Beregalov | 0ee904c | 2009-04-11 14:50:23 +0000 | [diff] [blame] | 3208 | /* the DMA is already ready this would be a bug. */ |
| 3209 | BUG_ON(priv->sram_desc.last_cb_index > 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3210 | |
| 3211 | do { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3212 | u32 chunk_len; |
| 3213 | u8 *start; |
| 3214 | int size; |
| 3215 | int nr = 0; |
| 3216 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3217 | chunk = (struct fw_chunk *)(data + offset); |
| 3218 | offset += sizeof(struct fw_chunk); |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3219 | chunk_len = le32_to_cpu(chunk->length); |
| 3220 | start = data + offset; |
| 3221 | |
| 3222 | nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH; |
| 3223 | for (i = 0; i < nr; i++) { |
| 3224 | virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL, |
| 3225 | &phys[total_nr]); |
| 3226 | if (!virts[total_nr]) { |
| 3227 | ret = -ENOMEM; |
| 3228 | goto out; |
| 3229 | } |
| 3230 | size = min_t(u32, chunk_len - i * CB_MAX_LENGTH, |
| 3231 | CB_MAX_LENGTH); |
| 3232 | memcpy(virts[total_nr], start, size); |
| 3233 | start += size; |
| 3234 | total_nr++; |
| 3235 | /* We don't support fw chunk larger than 64*8K */ |
| 3236 | BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL); |
| 3237 | } |
| 3238 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3239 | /* build DMA packet and queue up for sending */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3240 | /* dma to chunk->address, the chunk->length bytes from data + |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3241 | * offeset*/ |
| 3242 | /* Dma loading */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3243 | ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr], |
| 3244 | nr, le32_to_cpu(chunk->address), |
| 3245 | chunk_len); |
| 3246 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3247 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
| 3248 | goto out; |
| 3249 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3250 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3251 | offset += chunk_len; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3252 | } while (offset < len); |
| 3253 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3254 | /* Run the DMA and wait for the answer */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3255 | ret = ipw_fw_dma_kick(priv); |
| 3256 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3257 | IPW_ERROR("dmaKick Failed\n"); |
| 3258 | goto out; |
| 3259 | } |
| 3260 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3261 | ret = ipw_fw_dma_wait(priv); |
| 3262 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3263 | IPW_ERROR("dmaWaitSync Failed\n"); |
| 3264 | goto out; |
| 3265 | } |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3266 | out: |
| 3267 | for (i = 0; i < total_nr; i++) |
| 3268 | pci_pool_free(pool, virts[i], phys[i]); |
| 3269 | |
| 3270 | pci_pool_destroy(pool); |
Zhu Yi | 4109316 | 2010-03-09 16:05:31 +0800 | [diff] [blame] | 3271 | kfree(phys); |
| 3272 | kfree(virts); |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3273 | |
| 3274 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | /* stop nic */ |
| 3278 | static int ipw_stop_nic(struct ipw_priv *priv) |
| 3279 | { |
| 3280 | int rc = 0; |
| 3281 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3282 | /* stop */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3283 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3284 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3285 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3286 | IPW_RESET_REG_MASTER_DISABLED, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3287 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3288 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3289 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3290 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3291 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3292 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3293 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3294 | return rc; |
| 3295 | } |
| 3296 | |
| 3297 | static void ipw_start_nic(struct ipw_priv *priv) |
| 3298 | { |
| 3299 | IPW_DEBUG_TRACE(">>\n"); |
| 3300 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3301 | /* prvHwStartNic release ARC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3302 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 3303 | IPW_RESET_REG_MASTER_DISABLED | |
| 3304 | IPW_RESET_REG_STOP_MASTER | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3305 | CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3306 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3307 | /* enable power management */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3308 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
| 3309 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3310 | |
| 3311 | IPW_DEBUG_TRACE("<<\n"); |
| 3312 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3313 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3314 | static int ipw_init_nic(struct ipw_priv *priv) |
| 3315 | { |
| 3316 | int rc; |
| 3317 | |
| 3318 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3319 | /* reset */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3320 | /*prvHwInitNic */ |
| 3321 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3322 | 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] | 3323 | |
| 3324 | /* low-level PLL activation */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3325 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
| 3326 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3327 | |
| 3328 | /* wait for clock stabilization */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3329 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
| 3330 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3331 | if (rc < 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3332 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
| 3333 | |
| 3334 | /* assert SW reset */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3335 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3336 | |
| 3337 | udelay(10); |
| 3338 | |
| 3339 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3340 | 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] | 3341 | |
| 3342 | IPW_DEBUG_TRACE(">>\n"); |
| 3343 | return 0; |
| 3344 | } |
| 3345 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3346 | /* Call this function from process context, it will sleep in request_firmware. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3347 | * Probe is an ok place to call this from. |
| 3348 | */ |
| 3349 | static int ipw_reset_nic(struct ipw_priv *priv) |
| 3350 | { |
| 3351 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3352 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3353 | |
| 3354 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3355 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3356 | rc = ipw_init_nic(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3357 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3358 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3359 | /* Clear the 'host command active' bit... */ |
| 3360 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 3361 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3362 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 3363 | wake_up_interruptible(&priv->wait_state); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3364 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3365 | |
| 3366 | IPW_DEBUG_TRACE("<<\n"); |
| 3367 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3368 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3369 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3370 | |
| 3371 | struct ipw_fw { |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3372 | __le32 ver; |
| 3373 | __le32 boot_size; |
| 3374 | __le32 ucode_size; |
| 3375 | __le32 fw_size; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3376 | u8 data[0]; |
| 3377 | }; |
| 3378 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3379 | static int ipw_get_fw(struct ipw_priv *priv, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3380 | const struct firmware **raw, const char *name) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3381 | { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3382 | struct ipw_fw *fw; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3383 | int rc; |
| 3384 | |
| 3385 | /* ask firmware_class module to get the boot firmware off disk */ |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3386 | rc = request_firmware(raw, name, &priv->pci_dev->dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3387 | if (rc < 0) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3388 | IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3389 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3390 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3391 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3392 | if ((*raw)->size < sizeof(*fw)) { |
| 3393 | IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3394 | return -EINVAL; |
| 3395 | } |
| 3396 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3397 | fw = (void *)(*raw)->data; |
| 3398 | |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3399 | if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) + |
| 3400 | le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3401 | IPW_ERROR("%s is too small or corrupt (%zd)\n", |
| 3402 | name, (*raw)->size); |
| 3403 | return -EINVAL; |
| 3404 | } |
| 3405 | |
| 3406 | 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] | 3407 | name, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3408 | le32_to_cpu(fw->ver) >> 16, |
| 3409 | le32_to_cpu(fw->ver) & 0xff, |
| 3410 | (*raw)->size - sizeof(*fw)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3411 | return 0; |
| 3412 | } |
| 3413 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3414 | #define IPW_RX_BUF_SIZE (3000) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3415 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3416 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3417 | struct ipw_rx_queue *rxq) |
| 3418 | { |
| 3419 | unsigned long flags; |
| 3420 | int i; |
| 3421 | |
| 3422 | spin_lock_irqsave(&rxq->lock, flags); |
| 3423 | |
| 3424 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3425 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3426 | |
| 3427 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3428 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3429 | /* In the reset function, these buffers may have been allocated |
| 3430 | * to an SKB, so we need to unmap and free potential storage */ |
| 3431 | if (rxq->pool[i].skb != NULL) { |
| 3432 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3433 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3434 | dev_kfree_skb(rxq->pool[i].skb); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3435 | rxq->pool[i].skb = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3436 | } |
| 3437 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3438 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3439 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3440 | /* Set us so that we have processed and used all buffers, but have |
| 3441 | * not restocked the Rx queue with fresh buffers */ |
| 3442 | rxq->read = rxq->write = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3443 | rxq->free_count = 0; |
| 3444 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3445 | } |
| 3446 | |
| 3447 | #ifdef CONFIG_PM |
| 3448 | static int fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3449 | static const struct firmware *raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3450 | |
| 3451 | static void free_firmware(void) |
| 3452 | { |
| 3453 | if (fw_loaded) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3454 | release_firmware(raw); |
| 3455 | raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3456 | fw_loaded = 0; |
| 3457 | } |
| 3458 | } |
| 3459 | #else |
| 3460 | #define free_firmware() do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3461 | #endif |
| 3462 | |
| 3463 | static int ipw_load(struct ipw_priv *priv) |
| 3464 | { |
| 3465 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3466 | const struct firmware *raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3467 | #endif |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3468 | struct ipw_fw *fw; |
| 3469 | u8 *boot_img, *ucode_img, *fw_img; |
| 3470 | u8 *name = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3471 | int rc = 0, retries = 3; |
| 3472 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3473 | switch (priv->ieee->iw_mode) { |
| 3474 | case IW_MODE_ADHOC: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3475 | name = "ipw2200-ibss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3476 | break; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3477 | #ifdef CONFIG_IPW2200_MONITOR |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3478 | case IW_MODE_MONITOR: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3479 | name = "ipw2200-sniffer.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3480 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3481 | #endif |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3482 | case IW_MODE_INFRA: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3483 | name = "ipw2200-bss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3484 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3485 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3486 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3487 | if (!name) { |
| 3488 | rc = -EINVAL; |
| 3489 | goto error; |
| 3490 | } |
| 3491 | |
| 3492 | #ifdef CONFIG_PM |
| 3493 | if (!fw_loaded) { |
| 3494 | #endif |
| 3495 | rc = ipw_get_fw(priv, &raw, name); |
| 3496 | if (rc < 0) |
| 3497 | goto error; |
| 3498 | #ifdef CONFIG_PM |
| 3499 | } |
| 3500 | #endif |
| 3501 | |
| 3502 | fw = (void *)raw->data; |
| 3503 | boot_img = &fw->data[0]; |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3504 | ucode_img = &fw->data[le32_to_cpu(fw->boot_size)]; |
| 3505 | fw_img = &fw->data[le32_to_cpu(fw->boot_size) + |
| 3506 | le32_to_cpu(fw->ucode_size)]; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3507 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3508 | if (rc < 0) |
| 3509 | goto error; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3510 | |
| 3511 | if (!priv->rxq) |
| 3512 | priv->rxq = ipw_rx_queue_alloc(priv); |
| 3513 | else |
| 3514 | ipw_rx_queue_reset(priv, priv->rxq); |
| 3515 | if (!priv->rxq) { |
| 3516 | IPW_ERROR("Unable to initialize Rx queue\n"); |
| 3517 | goto error; |
| 3518 | } |
| 3519 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3520 | retry: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3521 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3522 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3523 | priv->status &= ~STATUS_INT_ENABLED; |
| 3524 | |
| 3525 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3526 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3527 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3528 | ipw_stop_nic(priv); |
| 3529 | |
| 3530 | rc = ipw_reset_nic(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3531 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3532 | IPW_ERROR("Unable to reset NIC\n"); |
| 3533 | goto error; |
| 3534 | } |
| 3535 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3536 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
| 3537 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3538 | |
| 3539 | /* DMA the initial boot firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3540 | 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] | 3541 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3542 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3543 | goto error; |
| 3544 | } |
| 3545 | |
| 3546 | /* kick start the device */ |
| 3547 | ipw_start_nic(priv); |
| 3548 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3549 | /* wait for the device to finish its initial startup sequence */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3550 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3551 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3552 | if (rc < 0) { |
| 3553 | IPW_ERROR("device failed to boot initial fw image\n"); |
| 3554 | goto error; |
| 3555 | } |
| 3556 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); |
| 3557 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3558 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3559 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3560 | |
| 3561 | /* DMA the ucode into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3562 | 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] | 3563 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3564 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3565 | goto error; |
| 3566 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3567 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3568 | /* stop nic */ |
| 3569 | ipw_stop_nic(priv); |
| 3570 | |
| 3571 | /* DMA bss firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3572 | 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] | 3573 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3574 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3575 | goto error; |
| 3576 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3577 | #ifdef CONFIG_PM |
| 3578 | fw_loaded = 1; |
| 3579 | #endif |
| 3580 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3581 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 3582 | |
| 3583 | rc = ipw_queue_reset(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3584 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3585 | IPW_ERROR("Unable to initialize queues\n"); |
| 3586 | goto error; |
| 3587 | } |
| 3588 | |
| 3589 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3590 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3591 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3592 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3593 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3594 | /* kick start the device */ |
| 3595 | ipw_start_nic(priv); |
| 3596 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3597 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3598 | if (retries > 0) { |
| 3599 | IPW_WARNING("Parity error. Retrying init.\n"); |
| 3600 | retries--; |
| 3601 | goto retry; |
| 3602 | } |
| 3603 | |
| 3604 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); |
| 3605 | rc = -EIO; |
| 3606 | goto error; |
| 3607 | } |
| 3608 | |
| 3609 | /* wait for the device */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3610 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3611 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3612 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3613 | IPW_ERROR("device failed to start within 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3614 | goto error; |
| 3615 | } |
| 3616 | IPW_DEBUG_INFO("device response after %dms\n", rc); |
| 3617 | |
| 3618 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3619 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3620 | |
| 3621 | /* read eeprom data and initialize the eeprom region of sram */ |
| 3622 | priv->eeprom_delay = 1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3623 | ipw_eeprom_init_sram(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3624 | |
| 3625 | /* enable interrupts */ |
| 3626 | ipw_enable_interrupts(priv); |
| 3627 | |
| 3628 | /* Ensure our queue has valid packets */ |
| 3629 | ipw_rx_queue_replenish(priv); |
| 3630 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3631 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3632 | |
| 3633 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3634 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3635 | |
| 3636 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3637 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3638 | #endif |
| 3639 | return 0; |
| 3640 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3641 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3642 | if (priv->rxq) { |
| 3643 | ipw_rx_queue_free(priv, priv->rxq); |
| 3644 | priv->rxq = NULL; |
| 3645 | } |
| 3646 | ipw_tx_queue_free(priv); |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3647 | if (raw) |
| 3648 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3649 | #ifdef CONFIG_PM |
| 3650 | fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3651 | raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3652 | #endif |
| 3653 | |
| 3654 | return rc; |
| 3655 | } |
| 3656 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3657 | /** |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3658 | * DMA services |
| 3659 | * |
| 3660 | * Theory of operation |
| 3661 | * |
| 3662 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 3663 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 3664 | * |
| 3665 | * 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] | 3666 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 3667 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3668 | * Tx queue resumed. |
| 3669 | * |
| 3670 | * The IPW operates with six queues, one receive queue in the device's |
| 3671 | * sram, one transmit queue for sending commands to the device firmware, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3672 | * and four transmit queues for data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3673 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3674 | * The four transmit queues allow for performing quality of service (qos) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3675 | * transmissions as per the 802.11 protocol. Currently Linux does not |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3676 | * provide a mechanism to the user for utilizing prioritized queues, so |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3677 | * we only utilize the first data transmit queue (queue1). |
| 3678 | */ |
| 3679 | |
| 3680 | /** |
| 3681 | * Driver allocates buffers of this size for Rx |
| 3682 | */ |
| 3683 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 3684 | /** |
| 3685 | * ipw_rx_queue_space - Return number of free slots available in queue. |
| 3686 | */ |
| 3687 | static int ipw_rx_queue_space(const struct ipw_rx_queue *q) |
| 3688 | { |
| 3689 | int s = q->read - q->write; |
| 3690 | if (s <= 0) |
| 3691 | s += RX_QUEUE_SIZE; |
| 3692 | /* keep some buffer to not confuse full and empty queue */ |
| 3693 | s -= 2; |
| 3694 | if (s < 0) |
| 3695 | s = 0; |
| 3696 | return s; |
| 3697 | } |
| 3698 | |
| 3699 | static inline int ipw_tx_queue_space(const struct clx2_queue *q) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3700 | { |
| 3701 | int s = q->last_used - q->first_empty; |
| 3702 | if (s <= 0) |
| 3703 | s += q->n_bd; |
| 3704 | s -= 2; /* keep some reserve to not confuse empty and full situations */ |
| 3705 | if (s < 0) |
| 3706 | s = 0; |
| 3707 | return s; |
| 3708 | } |
| 3709 | |
| 3710 | static inline int ipw_queue_inc_wrap(int index, int n_bd) |
| 3711 | { |
| 3712 | return (++index == n_bd) ? 0 : index; |
| 3713 | } |
| 3714 | |
| 3715 | /** |
| 3716 | * Initialize common DMA queue structure |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3717 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3718 | * @param q queue to init |
| 3719 | * @param count Number of BD's to allocate. Should be power of 2 |
| 3720 | * @param read_register Address for 'read' register |
| 3721 | * (not offset within BAR, full address) |
| 3722 | * @param write_register Address for 'write' register |
| 3723 | * (not offset within BAR, full address) |
| 3724 | * @param base_register Address for 'base' register |
| 3725 | * (not offset within BAR, full address) |
| 3726 | * @param size Address for 'size' register |
| 3727 | * (not offset within BAR, full address) |
| 3728 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3729 | 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] | 3730 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3731 | { |
| 3732 | q->n_bd = count; |
| 3733 | |
| 3734 | q->low_mark = q->n_bd / 4; |
| 3735 | if (q->low_mark < 4) |
| 3736 | q->low_mark = 4; |
| 3737 | |
| 3738 | q->high_mark = q->n_bd / 8; |
| 3739 | if (q->high_mark < 2) |
| 3740 | q->high_mark = 2; |
| 3741 | |
| 3742 | q->first_empty = q->last_used = 0; |
| 3743 | q->reg_r = read; |
| 3744 | q->reg_w = write; |
| 3745 | |
| 3746 | ipw_write32(priv, base, q->dma_addr); |
| 3747 | ipw_write32(priv, size, count); |
| 3748 | ipw_write32(priv, read, 0); |
| 3749 | ipw_write32(priv, write, 0); |
| 3750 | |
| 3751 | _ipw_read32(priv, 0x90); |
| 3752 | } |
| 3753 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3754 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3755 | struct clx2_tx_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3756 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3757 | { |
| 3758 | struct pci_dev *dev = priv->pci_dev; |
| 3759 | |
| 3760 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); |
| 3761 | if (!q->txb) { |
| 3762 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); |
| 3763 | return -ENOMEM; |
| 3764 | } |
| 3765 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3766 | q->bd = |
| 3767 | 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] | 3768 | if (!q->bd) { |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3769 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3770 | sizeof(q->bd[0]) * count); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3771 | kfree(q->txb); |
| 3772 | q->txb = NULL; |
| 3773 | return -ENOMEM; |
| 3774 | } |
| 3775 | |
| 3776 | ipw_queue_init(priv, &q->q, count, read, write, base, size); |
| 3777 | return 0; |
| 3778 | } |
| 3779 | |
| 3780 | /** |
| 3781 | * Free one TFD, those at index [txq->q.last_used]. |
| 3782 | * Do NOT advance any indexes |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3783 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3784 | * @param dev |
| 3785 | * @param txq |
| 3786 | */ |
| 3787 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, |
| 3788 | struct clx2_tx_queue *txq) |
| 3789 | { |
| 3790 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; |
| 3791 | struct pci_dev *dev = priv->pci_dev; |
| 3792 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3793 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3794 | /* classify bd */ |
| 3795 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) |
| 3796 | /* nothing to cleanup after for host commands */ |
| 3797 | return; |
| 3798 | |
| 3799 | /* sanity check */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3800 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
| 3801 | IPW_ERROR("Too many chunks: %i\n", |
| 3802 | le32_to_cpu(bd->u.data.num_chunks)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3803 | /** @todo issue fatal error, it is quite serious situation */ |
| 3804 | return; |
| 3805 | } |
| 3806 | |
| 3807 | /* unmap chunks if any */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3808 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
| 3809 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), |
| 3810 | le16_to_cpu(bd->u.data.chunk_len[i]), |
| 3811 | PCI_DMA_TODEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3812 | if (txq->txb[txq->q.last_used]) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 3813 | libipw_txb_free(txq->txb[txq->q.last_used]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3814 | txq->txb[txq->q.last_used] = NULL; |
| 3815 | } |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | /** |
| 3820 | * Deallocate DMA queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3821 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3822 | * Empty queue by removing and destroying all BD's. |
| 3823 | * Free all buffers. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3824 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3825 | * @param dev |
| 3826 | * @param q |
| 3827 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3828 | 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] | 3829 | { |
| 3830 | struct clx2_queue *q = &txq->q; |
| 3831 | struct pci_dev *dev = priv->pci_dev; |
| 3832 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3833 | if (q->n_bd == 0) |
| 3834 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3835 | |
| 3836 | /* first, empty all BD's */ |
| 3837 | for (; q->first_empty != q->last_used; |
| 3838 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3839 | ipw_queue_tx_free_tfd(priv, txq); |
| 3840 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3841 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3842 | /* free buffers belonging to queue itself */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3843 | 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] | 3844 | q->dma_addr); |
| 3845 | kfree(txq->txb); |
| 3846 | |
| 3847 | /* 0 fill whole structure */ |
| 3848 | memset(txq, 0, sizeof(*txq)); |
| 3849 | } |
| 3850 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3851 | /** |
| 3852 | * Destroy all DMA queues and structures |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3853 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3854 | * @param priv |
| 3855 | */ |
| 3856 | static void ipw_tx_queue_free(struct ipw_priv *priv) |
| 3857 | { |
| 3858 | /* Tx CMD queue */ |
| 3859 | ipw_queue_tx_free(priv, &priv->txq_cmd); |
| 3860 | |
| 3861 | /* Tx queues */ |
| 3862 | ipw_queue_tx_free(priv, &priv->txq[0]); |
| 3863 | ipw_queue_tx_free(priv, &priv->txq[1]); |
| 3864 | ipw_queue_tx_free(priv, &priv->txq[2]); |
| 3865 | ipw_queue_tx_free(priv, &priv->txq[3]); |
| 3866 | } |
| 3867 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3868 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3869 | { |
| 3870 | /* First 3 bytes are manufacturer */ |
| 3871 | bssid[0] = priv->mac_addr[0]; |
| 3872 | bssid[1] = priv->mac_addr[1]; |
| 3873 | bssid[2] = priv->mac_addr[2]; |
| 3874 | |
| 3875 | /* Last bytes are random */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3876 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3877 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3878 | bssid[0] &= 0xfe; /* clear multicast bit */ |
| 3879 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3880 | } |
| 3881 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3882 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3883 | { |
| 3884 | struct ipw_station_entry entry; |
| 3885 | int i; |
| 3886 | |
| 3887 | for (i = 0; i < priv->num_stations; i++) { |
| 3888 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { |
| 3889 | /* Another node is active in network */ |
| 3890 | priv->missed_adhoc_beacons = 0; |
| 3891 | if (!(priv->config & CFG_STATIC_CHANNEL)) |
| 3892 | /* when other nodes drop out, we drop out */ |
| 3893 | priv->config &= ~CFG_ADHOC_PERSIST; |
| 3894 | |
| 3895 | return i; |
| 3896 | } |
| 3897 | } |
| 3898 | |
| 3899 | if (i == MAX_STATIONS) |
| 3900 | return IPW_INVALID_STATION; |
| 3901 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3902 | IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3903 | |
| 3904 | entry.reserved = 0; |
| 3905 | entry.support_mode = 0; |
| 3906 | memcpy(entry.mac_addr, bssid, ETH_ALEN); |
| 3907 | memcpy(priv->stations[i], bssid, ETH_ALEN); |
| 3908 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3909 | &entry, sizeof(entry)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3910 | priv->num_stations++; |
| 3911 | |
| 3912 | return i; |
| 3913 | } |
| 3914 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3915 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3916 | { |
| 3917 | int i; |
| 3918 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3919 | for (i = 0; i < priv->num_stations; i++) |
| 3920 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3921 | return i; |
| 3922 | |
| 3923 | return IPW_INVALID_STATION; |
| 3924 | } |
| 3925 | |
| 3926 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) |
| 3927 | { |
| 3928 | int err; |
| 3929 | |
Hong Liu | 7b99659 | 2005-08-25 17:36:13 +0800 | [diff] [blame] | 3930 | if (priv->status & STATUS_ASSOCIATING) { |
| 3931 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); |
| 3932 | queue_work(priv->workqueue, &priv->disassociate); |
| 3933 | return; |
| 3934 | } |
| 3935 | |
| 3936 | if (!(priv->status & STATUS_ASSOCIATED)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3937 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
| 3938 | return; |
| 3939 | } |
| 3940 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3941 | IPW_DEBUG_ASSOC("Disassocation attempt from %pM " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3942 | "on channel %d.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3943 | priv->assoc_request.bssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3944 | priv->assoc_request.channel); |
| 3945 | |
| 3946 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); |
| 3947 | priv->status |= STATUS_DISASSOCIATING; |
| 3948 | |
| 3949 | if (quiet) |
| 3950 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; |
| 3951 | else |
| 3952 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 3953 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3954 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 3955 | if (err) { |
| 3956 | IPW_DEBUG_HC("Attempt to send [dis]associate command " |
| 3957 | "failed.\n"); |
| 3958 | return; |
| 3959 | } |
| 3960 | |
| 3961 | } |
| 3962 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3963 | static int ipw_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3964 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3965 | struct ipw_priv *priv = data; |
| 3966 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) |
| 3967 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3968 | ipw_send_disassociate(data, 0); |
Zhu Yi | b8ddafd | 2008-11-27 13:42:20 +0800 | [diff] [blame] | 3969 | netif_carrier_off(priv->net_dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3970 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3971 | } |
| 3972 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3973 | static void ipw_bg_disassociate(struct work_struct *work) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3974 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3975 | struct ipw_priv *priv = |
| 3976 | container_of(work, struct ipw_priv, disassociate); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3977 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3978 | ipw_disassociate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3979 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3980 | } |
| 3981 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3982 | static void ipw_system_config(struct work_struct *work) |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 3983 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3984 | struct ipw_priv *priv = |
| 3985 | container_of(work, struct ipw_priv, system_config); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 3986 | |
| 3987 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 3988 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 3989 | priv->sys_config.accept_all_data_frames = 1; |
| 3990 | priv->sys_config.accept_non_directed_frames = 1; |
| 3991 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 3992 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 3993 | } |
| 3994 | #endif |
| 3995 | |
| 3996 | ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3997 | } |
| 3998 | |
| 3999 | struct ipw_status_code { |
| 4000 | u16 status; |
| 4001 | const char *reason; |
| 4002 | }; |
| 4003 | |
| 4004 | static const struct ipw_status_code ipw_status_codes[] = { |
| 4005 | {0x00, "Successful"}, |
| 4006 | {0x01, "Unspecified failure"}, |
| 4007 | {0x0A, "Cannot support all requested capabilities in the " |
| 4008 | "Capability information field"}, |
| 4009 | {0x0B, "Reassociation denied due to inability to confirm that " |
| 4010 | "association exists"}, |
| 4011 | {0x0C, "Association denied due to reason outside the scope of this " |
| 4012 | "standard"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4013 | {0x0D, |
| 4014 | "Responding station does not support the specified authentication " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4015 | "algorithm"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4016 | {0x0E, |
| 4017 | "Received an Authentication frame with authentication sequence " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4018 | "transaction sequence number out of expected sequence"}, |
| 4019 | {0x0F, "Authentication rejected because of challenge failure"}, |
| 4020 | {0x10, "Authentication rejected due to timeout waiting for next " |
| 4021 | "frame in sequence"}, |
| 4022 | {0x11, "Association denied because AP is unable to handle additional " |
| 4023 | "associated stations"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4024 | {0x12, |
| 4025 | "Association denied due to requesting station not supporting all " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4026 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4027 | {0x13, |
| 4028 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4029 | "short preamble operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4030 | {0x14, |
| 4031 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4032 | "PBCC encoding"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4033 | {0x15, |
| 4034 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4035 | "channel agility"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4036 | {0x19, |
| 4037 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4038 | "short slot operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4039 | {0x1A, |
| 4040 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4041 | "DSSS-OFDM operation"}, |
| 4042 | {0x28, "Invalid Information Element"}, |
| 4043 | {0x29, "Group Cipher is not valid"}, |
| 4044 | {0x2A, "Pairwise Cipher is not valid"}, |
| 4045 | {0x2B, "AKMP is not valid"}, |
| 4046 | {0x2C, "Unsupported RSN IE version"}, |
| 4047 | {0x2D, "Invalid RSN IE Capabilities"}, |
| 4048 | {0x2E, "Cipher suite is rejected per security policy"}, |
| 4049 | }; |
| 4050 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4051 | static const char *ipw_get_status_code(u16 status) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4052 | { |
| 4053 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4054 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4055 | if (ipw_status_codes[i].status == (status & 0xff)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4056 | return ipw_status_codes[i].reason; |
| 4057 | return "Unknown status value."; |
| 4058 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4059 | |
| 4060 | static void inline average_init(struct average *avg) |
| 4061 | { |
| 4062 | memset(avg, 0, sizeof(*avg)); |
| 4063 | } |
| 4064 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4065 | #define DEPTH_RSSI 8 |
| 4066 | #define DEPTH_NOISE 16 |
| 4067 | static s16 exponential_average(s16 prev_avg, s16 val, u8 depth) |
| 4068 | { |
| 4069 | return ((depth-1)*prev_avg + val)/depth; |
| 4070 | } |
| 4071 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4072 | static void average_add(struct average *avg, s16 val) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4073 | { |
| 4074 | avg->sum -= avg->entries[avg->pos]; |
| 4075 | avg->sum += val; |
| 4076 | avg->entries[avg->pos++] = val; |
| 4077 | if (unlikely(avg->pos == AVG_ENTRIES)) { |
| 4078 | avg->init = 1; |
| 4079 | avg->pos = 0; |
| 4080 | } |
| 4081 | } |
| 4082 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4083 | static s16 average_value(struct average *avg) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4084 | { |
| 4085 | if (!unlikely(avg->init)) { |
| 4086 | if (avg->pos) |
| 4087 | return avg->sum / avg->pos; |
| 4088 | return 0; |
| 4089 | } |
| 4090 | |
| 4091 | return avg->sum / AVG_ENTRIES; |
| 4092 | } |
| 4093 | |
| 4094 | static void ipw_reset_stats(struct ipw_priv *priv) |
| 4095 | { |
| 4096 | u32 len = sizeof(u32); |
| 4097 | |
| 4098 | priv->quality = 0; |
| 4099 | |
| 4100 | average_init(&priv->average_missed_beacons); |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4101 | priv->exp_avg_rssi = -60; |
| 4102 | priv->exp_avg_noise = -85 + 0x100; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4103 | |
| 4104 | priv->last_rate = 0; |
| 4105 | priv->last_missed_beacons = 0; |
| 4106 | priv->last_rx_packets = 0; |
| 4107 | priv->last_tx_packets = 0; |
| 4108 | priv->last_tx_failures = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4109 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4110 | /* Firmware managed, reset only when NIC is restarted, so we have to |
| 4111 | * normalize on the current value */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4112 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4113 | &priv->last_rx_err, &len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4114 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4115 | &priv->last_tx_failures, &len); |
| 4116 | |
| 4117 | /* Driver managed, reset with each association */ |
| 4118 | priv->missed_adhoc_beacons = 0; |
| 4119 | priv->missed_beacons = 0; |
| 4120 | priv->tx_packets = 0; |
| 4121 | priv->rx_packets = 0; |
| 4122 | |
| 4123 | } |
| 4124 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4125 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4126 | { |
| 4127 | u32 i = 0x80000000; |
| 4128 | u32 mask = priv->rates_mask; |
| 4129 | /* If currently associated in B mode, restrict the maximum |
| 4130 | * rate match to B rates */ |
| 4131 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4132 | mask &= LIBIPW_CCK_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4133 | |
| 4134 | /* TODO: Verify that the rate is supported by the current rates |
| 4135 | * list. */ |
| 4136 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4137 | while (i && !(mask & i)) |
| 4138 | i >>= 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4139 | switch (i) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4140 | case LIBIPW_CCK_RATE_1MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4141 | return 1000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4142 | case LIBIPW_CCK_RATE_2MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4143 | return 2000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4144 | case LIBIPW_CCK_RATE_5MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4145 | return 5500000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4146 | case LIBIPW_OFDM_RATE_6MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4147 | return 6000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4148 | case LIBIPW_OFDM_RATE_9MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4149 | return 9000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4150 | case LIBIPW_CCK_RATE_11MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4151 | return 11000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4152 | case LIBIPW_OFDM_RATE_12MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4153 | return 12000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4154 | case LIBIPW_OFDM_RATE_18MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4155 | return 18000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4156 | case LIBIPW_OFDM_RATE_24MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4157 | return 24000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4158 | case LIBIPW_OFDM_RATE_36MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4159 | return 36000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4160 | case LIBIPW_OFDM_RATE_48MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4161 | return 48000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4162 | case LIBIPW_OFDM_RATE_54MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4163 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4164 | } |
| 4165 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4166 | if (priv->ieee->mode == IEEE_B) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4167 | return 11000000; |
| 4168 | else |
| 4169 | return 54000000; |
| 4170 | } |
| 4171 | |
| 4172 | static u32 ipw_get_current_rate(struct ipw_priv *priv) |
| 4173 | { |
| 4174 | u32 rate, len = sizeof(rate); |
| 4175 | int err; |
| 4176 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4177 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4178 | return 0; |
| 4179 | |
| 4180 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4181 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4182 | &len); |
| 4183 | if (err) { |
| 4184 | IPW_DEBUG_INFO("failed querying ordinals.\n"); |
| 4185 | return 0; |
| 4186 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4187 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4188 | return ipw_get_max_rate(priv); |
| 4189 | |
| 4190 | switch (rate) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4191 | case IPW_TX_RATE_1MB: |
| 4192 | return 1000000; |
| 4193 | case IPW_TX_RATE_2MB: |
| 4194 | return 2000000; |
| 4195 | case IPW_TX_RATE_5MB: |
| 4196 | return 5500000; |
| 4197 | case IPW_TX_RATE_6MB: |
| 4198 | return 6000000; |
| 4199 | case IPW_TX_RATE_9MB: |
| 4200 | return 9000000; |
| 4201 | case IPW_TX_RATE_11MB: |
| 4202 | return 11000000; |
| 4203 | case IPW_TX_RATE_12MB: |
| 4204 | return 12000000; |
| 4205 | case IPW_TX_RATE_18MB: |
| 4206 | return 18000000; |
| 4207 | case IPW_TX_RATE_24MB: |
| 4208 | return 24000000; |
| 4209 | case IPW_TX_RATE_36MB: |
| 4210 | return 36000000; |
| 4211 | case IPW_TX_RATE_48MB: |
| 4212 | return 48000000; |
| 4213 | case IPW_TX_RATE_54MB: |
| 4214 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | return 0; |
| 4218 | } |
| 4219 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4220 | #define IPW_STATS_INTERVAL (2 * HZ) |
| 4221 | static void ipw_gather_stats(struct ipw_priv *priv) |
| 4222 | { |
| 4223 | u32 rx_err, rx_err_delta, rx_packets_delta; |
| 4224 | u32 tx_failures, tx_failures_delta, tx_packets_delta; |
| 4225 | u32 missed_beacons_percent, missed_beacons_delta; |
| 4226 | u32 quality = 0; |
| 4227 | u32 len = sizeof(u32); |
| 4228 | s16 rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4229 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4230 | rate_quality; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4231 | u32 max_rate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4232 | |
| 4233 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 4234 | priv->quality = 0; |
| 4235 | return; |
| 4236 | } |
| 4237 | |
| 4238 | /* Update the statistics */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4239 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4240 | &priv->missed_beacons, &len); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4241 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4242 | priv->last_missed_beacons = priv->missed_beacons; |
| 4243 | if (priv->assoc_request.beacon_interval) { |
| 4244 | missed_beacons_percent = missed_beacons_delta * |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4245 | (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4246 | (IPW_STATS_INTERVAL * 10); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4247 | } else { |
| 4248 | missed_beacons_percent = 0; |
| 4249 | } |
| 4250 | average_add(&priv->average_missed_beacons, missed_beacons_percent); |
| 4251 | |
| 4252 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); |
| 4253 | rx_err_delta = rx_err - priv->last_rx_err; |
| 4254 | priv->last_rx_err = rx_err; |
| 4255 | |
| 4256 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); |
| 4257 | tx_failures_delta = tx_failures - priv->last_tx_failures; |
| 4258 | priv->last_tx_failures = tx_failures; |
| 4259 | |
| 4260 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; |
| 4261 | priv->last_rx_packets = priv->rx_packets; |
| 4262 | |
| 4263 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; |
| 4264 | priv->last_tx_packets = priv->tx_packets; |
| 4265 | |
| 4266 | /* Calculate quality based on the following: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4267 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4268 | * Missed beacon: 100% = 0, 0% = 70% missed |
| 4269 | * Rate: 60% = 1Mbs, 100% = Max |
| 4270 | * Rx and Tx errors represent a straight % of total Rx/Tx |
| 4271 | * RSSI: 100% = > -50, 0% = < -80 |
| 4272 | * Rx errors: 100% = 0, 0% = 50% missed |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4273 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4274 | * The lowest computed quality is used. |
| 4275 | * |
| 4276 | */ |
| 4277 | #define BEACON_THRESHOLD 5 |
| 4278 | beacon_quality = 100 - missed_beacons_percent; |
| 4279 | if (beacon_quality < BEACON_THRESHOLD) |
| 4280 | beacon_quality = 0; |
| 4281 | else |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4282 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4283 | (100 - BEACON_THRESHOLD); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4284 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4285 | beacon_quality, missed_beacons_percent); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4286 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4287 | priv->last_rate = ipw_get_current_rate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4288 | max_rate = ipw_get_max_rate(priv); |
| 4289 | rate_quality = priv->last_rate * 40 / max_rate + 60; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4290 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
| 4291 | rate_quality, priv->last_rate / 1000000); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4292 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4293 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4294 | rx_quality = 100 - (rx_err_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4295 | (rx_packets_delta + rx_err_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4296 | else |
| 4297 | rx_quality = 100; |
| 4298 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", |
| 4299 | rx_quality, rx_err_delta, rx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4300 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4301 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4302 | tx_quality = 100 - (tx_failures_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4303 | (tx_packets_delta + tx_failures_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4304 | else |
| 4305 | tx_quality = 100; |
| 4306 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", |
| 4307 | tx_quality, tx_failures_delta, tx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4308 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4309 | rssi = priv->exp_avg_rssi; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4310 | signal_quality = |
| 4311 | (100 * |
| 4312 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4313 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - |
| 4314 | (priv->ieee->perfect_rssi - rssi) * |
| 4315 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + |
| 4316 | 62 * (priv->ieee->perfect_rssi - rssi))) / |
| 4317 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4318 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); |
| 4319 | if (signal_quality > 100) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4320 | signal_quality = 100; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4321 | else if (signal_quality < 1) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4322 | signal_quality = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4323 | |
Zhu Yi | 61fb9ed | 2006-04-13 17:19:55 +0800 | [diff] [blame] | 4324 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4325 | signal_quality, rssi); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4326 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 4327 | quality = min(rx_quality, signal_quality); |
| 4328 | quality = min(tx_quality, quality); |
| 4329 | quality = min(rate_quality, quality); |
| 4330 | quality = min(beacon_quality, quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4331 | if (quality == beacon_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4332 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
| 4333 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4334 | if (quality == rate_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4335 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
| 4336 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4337 | if (quality == tx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4338 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
| 4339 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4340 | if (quality == rx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4341 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
| 4342 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4343 | if (quality == signal_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4344 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
| 4345 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4346 | |
| 4347 | priv->quality = quality; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4348 | |
| 4349 | queue_delayed_work(priv->workqueue, &priv->gather_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4350 | IPW_STATS_INTERVAL); |
| 4351 | } |
| 4352 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4353 | static void ipw_bg_gather_stats(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4354 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4355 | struct ipw_priv *priv = |
| 4356 | container_of(work, struct ipw_priv, gather_stats.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4357 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4358 | ipw_gather_stats(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4359 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4360 | } |
| 4361 | |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4362 | /* Missed beacon behavior: |
| 4363 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. |
| 4364 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. |
| 4365 | * Above disassociate threshold, give up and stop scanning. |
| 4366 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4367 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4368 | int missed_count) |
| 4369 | { |
| 4370 | priv->notif_missed_beacons = missed_count; |
| 4371 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4372 | if (missed_count > priv->disassociate_threshold && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4373 | priv->status & STATUS_ASSOCIATED) { |
| 4374 | /* If associated and we've hit the missed |
| 4375 | * beacon threshold, disassociate, turn |
| 4376 | * off roaming, and abort any active scans */ |
| 4377 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4378 | IPW_DL_STATE | IPW_DL_ASSOC, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4379 | "Missed beacon: %d - disassociate\n", missed_count); |
| 4380 | priv->status &= ~STATUS_ROAMING; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4381 | if (priv->status & STATUS_SCANNING) { |
| 4382 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 4383 | IPW_DL_STATE, |
| 4384 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4385 | queue_work(priv->workqueue, &priv->abort_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4386 | } |
| 4387 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4388 | queue_work(priv->workqueue, &priv->disassociate); |
| 4389 | return; |
| 4390 | } |
| 4391 | |
| 4392 | if (priv->status & STATUS_ROAMING) { |
| 4393 | /* If we are currently roaming, then just |
| 4394 | * print a debug statement... */ |
| 4395 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4396 | "Missed beacon: %d - roam in progress\n", |
| 4397 | missed_count); |
| 4398 | return; |
| 4399 | } |
| 4400 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 4401 | if (roaming && |
| 4402 | (missed_count > priv->roaming_threshold && |
| 4403 | missed_count <= priv->disassociate_threshold)) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4404 | /* If we are not already roaming, set the ROAM |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4405 | * bit in the status and kick off a scan. |
| 4406 | * This can happen several times before we reach |
| 4407 | * disassociate_threshold. */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4408 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4409 | "Missed beacon: %d - initiate " |
| 4410 | "roaming\n", missed_count); |
| 4411 | if (!(priv->status & STATUS_ROAMING)) { |
| 4412 | priv->status |= STATUS_ROAMING; |
| 4413 | if (!(priv->status & STATUS_SCANNING)) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4414 | queue_delayed_work(priv->workqueue, |
| 4415 | &priv->request_scan, 0); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4416 | } |
| 4417 | return; |
| 4418 | } |
| 4419 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 4420 | if (priv->status & STATUS_SCANNING && |
| 4421 | missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4422 | /* Stop scan to keep fw from getting |
| 4423 | * stuck (only if we aren't roaming -- |
| 4424 | * otherwise we'll never scan more than 2 or 3 |
| 4425 | * channels..) */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4426 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
| 4427 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4428 | queue_work(priv->workqueue, &priv->abort_scan); |
| 4429 | } |
| 4430 | |
| 4431 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4432 | } |
| 4433 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4434 | static void ipw_scan_event(struct work_struct *work) |
| 4435 | { |
| 4436 | union iwreq_data wrqu; |
| 4437 | |
| 4438 | struct ipw_priv *priv = |
| 4439 | container_of(work, struct ipw_priv, scan_event.work); |
| 4440 | |
| 4441 | wrqu.data.length = 0; |
| 4442 | wrqu.data.flags = 0; |
| 4443 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); |
| 4444 | } |
| 4445 | |
| 4446 | static void handle_scan_event(struct ipw_priv *priv) |
| 4447 | { |
| 4448 | /* Only userspace-requested scan completion events go out immediately */ |
| 4449 | if (!priv->user_requested_scan) { |
| 4450 | if (!delayed_work_pending(&priv->scan_event)) |
| 4451 | queue_delayed_work(priv->workqueue, &priv->scan_event, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 4452 | round_jiffies_relative(msecs_to_jiffies(4000))); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4453 | } else { |
| 4454 | union iwreq_data wrqu; |
| 4455 | |
| 4456 | priv->user_requested_scan = 0; |
| 4457 | cancel_delayed_work(&priv->scan_event); |
| 4458 | |
| 4459 | wrqu.data.length = 0; |
| 4460 | wrqu.data.flags = 0; |
| 4461 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); |
| 4462 | } |
| 4463 | } |
| 4464 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4465 | /** |
| 4466 | * Handle host notification packet. |
| 4467 | * Called from interrupt routine |
| 4468 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4469 | static void ipw_rx_notification(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4470 | struct ipw_rx_notification *notif) |
| 4471 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4472 | DECLARE_SSID_BUF(ssid); |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4473 | u16 size = le16_to_cpu(notif->size); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4474 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4475 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4476 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4477 | switch (notif->subtype) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4478 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
| 4479 | struct notif_association *assoc = ¬if->u.assoc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4480 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4481 | switch (assoc->state) { |
| 4482 | case CMAS_ASSOCIATED:{ |
| 4483 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4484 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4485 | "associated: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4486 | print_ssid(ssid, priv->essid, |
| 4487 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4488 | priv->bssid); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4489 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4490 | switch (priv->ieee->iw_mode) { |
| 4491 | case IW_MODE_INFRA: |
| 4492 | memcpy(priv->ieee->bssid, |
| 4493 | priv->bssid, ETH_ALEN); |
| 4494 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4495 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4496 | case IW_MODE_ADHOC: |
| 4497 | memcpy(priv->ieee->bssid, |
| 4498 | priv->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4499 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4500 | /* clear out the station table */ |
| 4501 | priv->num_stations = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4502 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4503 | IPW_DEBUG_ASSOC |
| 4504 | ("queueing adhoc check\n"); |
| 4505 | queue_delayed_work(priv-> |
| 4506 | workqueue, |
| 4507 | &priv-> |
| 4508 | adhoc_check, |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4509 | le16_to_cpu(priv-> |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4510 | assoc_request. |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4511 | beacon_interval)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4512 | break; |
| 4513 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4514 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4515 | priv->status &= ~STATUS_ASSOCIATING; |
| 4516 | priv->status |= STATUS_ASSOCIATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 4517 | queue_work(priv->workqueue, |
| 4518 | &priv->system_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4519 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 4520 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4521 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 4522 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control)) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4523 | if ((priv->status & STATUS_AUTH) && |
| 4524 | (IPW_GET_PACKET_STYPE(¬if->u.raw) |
| 4525 | == IEEE80211_STYPE_ASSOC_RESP)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4526 | if ((sizeof |
| 4527 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4528 | libipw_assoc_response) |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4529 | <= size) |
| 4530 | && (size <= 2314)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4531 | struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4532 | libipw_rx_stats |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4533 | stats = { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4534 | .len = size - 1, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4535 | }; |
| 4536 | |
| 4537 | IPW_DEBUG_QOS |
| 4538 | ("QoS Associate " |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4539 | "size %d\n", size); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4540 | libipw_rx_mgt(priv-> |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4541 | ieee, |
| 4542 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4543 | libipw_hdr_4addr |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4544 | *) |
| 4545 | ¬if->u.raw, &stats); |
| 4546 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4547 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4548 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4549 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4550 | schedule_work(&priv->link_up); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4551 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4552 | break; |
| 4553 | } |
| 4554 | |
| 4555 | case CMAS_AUTHENTICATED:{ |
| 4556 | if (priv-> |
| 4557 | status & (STATUS_ASSOCIATED | |
| 4558 | STATUS_AUTH)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4559 | struct notif_authenticate *auth |
| 4560 | = ¬if->u.auth; |
| 4561 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4562 | IPW_DL_STATE | |
| 4563 | IPW_DL_ASSOC, |
| 4564 | "deauthenticated: '%s' " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4565 | "%pM" |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4566 | ": (0x%04X) - %s \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4567 | print_ssid(ssid, |
| 4568 | priv-> |
| 4569 | essid, |
| 4570 | priv-> |
| 4571 | essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4572 | priv->bssid, |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4573 | le16_to_cpu(auth->status), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4574 | ipw_get_status_code |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4575 | (le16_to_cpu |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4576 | (auth->status))); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4577 | |
| 4578 | priv->status &= |
| 4579 | ~(STATUS_ASSOCIATING | |
| 4580 | STATUS_AUTH | |
| 4581 | STATUS_ASSOCIATED); |
| 4582 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4583 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4584 | break; |
| 4585 | } |
| 4586 | |
| 4587 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4588 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4589 | "authenticated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4590 | print_ssid(ssid, priv->essid, |
| 4591 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4592 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4593 | break; |
| 4594 | } |
| 4595 | |
| 4596 | case CMAS_INIT:{ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4597 | if (priv->status & STATUS_AUTH) { |
| 4598 | struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4599 | libipw_assoc_response |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4600 | *resp; |
| 4601 | resp = |
| 4602 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4603 | libipw_assoc_response |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4604 | *)¬if->u.raw; |
| 4605 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4606 | IPW_DL_STATE | |
| 4607 | IPW_DL_ASSOC, |
| 4608 | "association failed (0x%04X): %s\n", |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4609 | le16_to_cpu(resp->status), |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4610 | ipw_get_status_code |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4611 | (le16_to_cpu |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4612 | (resp->status))); |
| 4613 | } |
| 4614 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4615 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4616 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4617 | "disassociated: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4618 | print_ssid(ssid, priv->essid, |
| 4619 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4620 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4621 | |
| 4622 | priv->status &= |
| 4623 | ~(STATUS_DISASSOCIATING | |
| 4624 | STATUS_ASSOCIATING | |
| 4625 | STATUS_ASSOCIATED | STATUS_AUTH); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4626 | if (priv->assoc_network |
| 4627 | && (priv->assoc_network-> |
| 4628 | capability & |
| 4629 | WLAN_CAPABILITY_IBSS)) |
| 4630 | ipw_remove_current_network |
| 4631 | (priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4632 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4633 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4634 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4635 | break; |
| 4636 | } |
| 4637 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4638 | case CMAS_RX_ASSOC_RESP: |
| 4639 | break; |
| 4640 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4641 | default: |
| 4642 | IPW_ERROR("assoc: unknown (%d)\n", |
| 4643 | assoc->state); |
| 4644 | break; |
| 4645 | } |
| 4646 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4647 | break; |
| 4648 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4649 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4650 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
| 4651 | struct notif_authenticate *auth = ¬if->u.auth; |
| 4652 | switch (auth->state) { |
| 4653 | case CMAS_AUTHENTICATED: |
| 4654 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4655 | "authenticated: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4656 | print_ssid(ssid, priv->essid, |
| 4657 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4658 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4659 | priv->status |= STATUS_AUTH; |
| 4660 | break; |
| 4661 | |
| 4662 | case CMAS_INIT: |
| 4663 | if (priv->status & STATUS_AUTH) { |
| 4664 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4665 | IPW_DL_ASSOC, |
| 4666 | "authentication failed (0x%04X): %s\n", |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4667 | le16_to_cpu(auth->status), |
| 4668 | ipw_get_status_code(le16_to_cpu |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4669 | (auth-> |
| 4670 | status))); |
| 4671 | } |
| 4672 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4673 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4674 | "deauthenticated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4675 | print_ssid(ssid, priv->essid, |
| 4676 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4677 | priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4678 | |
| 4679 | priv->status &= ~(STATUS_ASSOCIATING | |
| 4680 | STATUS_AUTH | |
| 4681 | STATUS_ASSOCIATED); |
| 4682 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4683 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4684 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4685 | |
| 4686 | case CMAS_TX_AUTH_SEQ_1: |
| 4687 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4688 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); |
| 4689 | break; |
| 4690 | case CMAS_RX_AUTH_SEQ_2: |
| 4691 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4692 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); |
| 4693 | break; |
| 4694 | case CMAS_AUTH_SEQ_1_PASS: |
| 4695 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4696 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); |
| 4697 | break; |
| 4698 | case CMAS_AUTH_SEQ_1_FAIL: |
| 4699 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4700 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); |
| 4701 | break; |
| 4702 | case CMAS_TX_AUTH_SEQ_3: |
| 4703 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4704 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); |
| 4705 | break; |
| 4706 | case CMAS_RX_AUTH_SEQ_4: |
| 4707 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4708 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); |
| 4709 | break; |
| 4710 | case CMAS_AUTH_SEQ_2_PASS: |
| 4711 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4712 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); |
| 4713 | break; |
| 4714 | case CMAS_AUTH_SEQ_2_FAIL: |
| 4715 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4716 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); |
| 4717 | break; |
| 4718 | case CMAS_TX_ASSOC: |
| 4719 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4720 | IPW_DL_ASSOC, "TX_ASSOC\n"); |
| 4721 | break; |
| 4722 | case CMAS_RX_ASSOC_RESP: |
| 4723 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4724 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4725 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4726 | break; |
| 4727 | case CMAS_ASSOCIATED: |
| 4728 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4729 | IPW_DL_ASSOC, "ASSOCIATED\n"); |
| 4730 | break; |
| 4731 | default: |
| 4732 | IPW_DEBUG_NOTIF("auth: failure - %d\n", |
| 4733 | auth->state); |
| 4734 | break; |
| 4735 | } |
| 4736 | break; |
| 4737 | } |
| 4738 | |
| 4739 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
| 4740 | struct notif_channel_result *x = |
| 4741 | ¬if->u.channel_result; |
| 4742 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4743 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4744 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
| 4745 | x->channel_num); |
| 4746 | } else { |
| 4747 | IPW_DEBUG_SCAN("Scan result of wrong size %d " |
| 4748 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4749 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4750 | } |
| 4751 | break; |
| 4752 | } |
| 4753 | |
| 4754 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
| 4755 | struct notif_scan_complete *x = ¬if->u.scan_complete; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4756 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4757 | IPW_DEBUG_SCAN |
| 4758 | ("Scan completed: type %d, %d channels, " |
| 4759 | "%d status\n", x->scan_type, |
| 4760 | x->num_channels, x->status); |
| 4761 | } else { |
| 4762 | IPW_ERROR("Scan completed of wrong size %d " |
| 4763 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4764 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4765 | } |
| 4766 | |
| 4767 | priv->status &= |
| 4768 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 4769 | |
James Ketrenos | a0e04ab | 2005-08-25 00:49:43 -0500 | [diff] [blame] | 4770 | wake_up_interruptible(&priv->wait_state); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4771 | cancel_delayed_work(&priv->scan_check); |
| 4772 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4773 | if (priv->status & STATUS_EXIT_PENDING) |
| 4774 | break; |
| 4775 | |
| 4776 | priv->ieee->scans++; |
| 4777 | |
| 4778 | #ifdef CONFIG_IPW2200_MONITOR |
| 4779 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4780 | priv->status |= STATUS_SCAN_FORCED; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4781 | queue_delayed_work(priv->workqueue, |
| 4782 | &priv->request_scan, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4783 | break; |
| 4784 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4785 | priv->status &= ~STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4786 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 4787 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 4788 | /* Do queued direct scans first */ |
| 4789 | if (priv->status & STATUS_DIRECT_SCAN_PENDING) { |
| 4790 | queue_delayed_work(priv->workqueue, |
| 4791 | &priv->request_direct_scan, 0); |
| 4792 | } |
| 4793 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4794 | if (!(priv->status & (STATUS_ASSOCIATED | |
| 4795 | STATUS_ASSOCIATING | |
| 4796 | STATUS_ROAMING | |
| 4797 | STATUS_DISASSOCIATING))) |
| 4798 | queue_work(priv->workqueue, &priv->associate); |
| 4799 | else if (priv->status & STATUS_ROAMING) { |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4800 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4801 | /* If a scan completed and we are in roam mode, then |
| 4802 | * the scan that completed was the one requested as a |
| 4803 | * result of entering roam... so, schedule the |
| 4804 | * roam work */ |
| 4805 | queue_work(priv->workqueue, |
| 4806 | &priv->roam); |
| 4807 | else |
| 4808 | /* Don't schedule if we aborted the scan */ |
| 4809 | priv->status &= ~STATUS_ROAMING; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4810 | } else if (priv->status & STATUS_SCAN_PENDING) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4811 | queue_delayed_work(priv->workqueue, |
| 4812 | &priv->request_scan, 0); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4813 | else if (priv->config & CFG_BACKGROUND_SCAN |
| 4814 | && priv->status & STATUS_ASSOCIATED) |
| 4815 | queue_delayed_work(priv->workqueue, |
Stephen Hemminger | 1c9d5e4 | 2007-06-22 21:34:06 -0700 | [diff] [blame] | 4816 | &priv->request_scan, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 4817 | round_jiffies_relative(HZ)); |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 4818 | |
| 4819 | /* Send an empty event to user space. |
| 4820 | * We don't send the received data on the event because |
| 4821 | * it would require us to do complex transcoding, and |
| 4822 | * we want to minimise the work done in the irq handler |
| 4823 | * Use a request to extract the data. |
| 4824 | * Also, we generate this even for any scan, regardless |
| 4825 | * on how the scan was initiated. User space can just |
| 4826 | * sync on periodic scan to get fresh data... |
| 4827 | * Jean II */ |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4828 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4829 | handle_scan_event(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4830 | break; |
| 4831 | } |
| 4832 | |
| 4833 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
| 4834 | struct notif_frag_length *x = ¬if->u.frag_len; |
| 4835 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4836 | if (size == sizeof(*x)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4837 | IPW_ERROR("Frag length: %d\n", |
| 4838 | le16_to_cpu(x->frag_length)); |
| 4839 | else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4840 | IPW_ERROR("Frag length of wrong size %d " |
| 4841 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4842 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4843 | break; |
| 4844 | } |
| 4845 | |
| 4846 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
| 4847 | struct notif_link_deterioration *x = |
| 4848 | ¬if->u.link_deterioration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4849 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4850 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4851 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Cahill, Ben M | 1297715 | 2006-03-08 02:58:02 +0800 | [diff] [blame] | 4852 | "link deterioration: type %d, cnt %d\n", |
| 4853 | x->silence_notification_type, |
| 4854 | x->silence_count); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4855 | memcpy(&priv->last_link_deterioration, x, |
| 4856 | sizeof(*x)); |
| 4857 | } else { |
| 4858 | IPW_ERROR("Link Deterioration of wrong size %d " |
| 4859 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4860 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4861 | } |
| 4862 | break; |
| 4863 | } |
| 4864 | |
| 4865 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
| 4866 | IPW_ERROR("Dino config\n"); |
| 4867 | if (priv->hcmd |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4868 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4869 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4870 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4871 | break; |
| 4872 | } |
| 4873 | |
| 4874 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
| 4875 | struct notif_beacon_state *x = ¬if->u.beacon_state; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4876 | if (size != sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4877 | IPW_ERROR |
| 4878 | ("Beacon state of wrong size %d (should " |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4879 | "be %zd)\n", size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4880 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4881 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4882 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4883 | if (le32_to_cpu(x->state) == |
| 4884 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) |
| 4885 | ipw_handle_missed_beacon(priv, |
| 4886 | le32_to_cpu(x-> |
| 4887 | number)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4888 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4889 | break; |
| 4890 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4891 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4892 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
| 4893 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4894 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4895 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
| 4896 | "0x%02x station %d\n", |
| 4897 | x->key_state, x->security_type, |
| 4898 | x->station_index); |
| 4899 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4900 | } |
| 4901 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4902 | IPW_ERROR |
| 4903 | ("TGi Tx Key of wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4904 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4905 | break; |
| 4906 | } |
| 4907 | |
| 4908 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
| 4909 | struct notif_calibration *x = ¬if->u.calibration; |
| 4910 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4911 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4912 | memcpy(&priv->calib, x, sizeof(*x)); |
| 4913 | IPW_DEBUG_INFO("TODO: Calibration\n"); |
| 4914 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4915 | } |
| 4916 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4917 | IPW_ERROR |
| 4918 | ("Calibration of wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4919 | size, sizeof(*x)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4920 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4921 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4922 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4923 | case HOST_NOTIFICATION_NOISE_STATS:{ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4924 | if (size == sizeof(u32)) { |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4925 | priv->exp_avg_noise = |
| 4926 | exponential_average(priv->exp_avg_noise, |
| 4927 | (u8) (le32_to_cpu(notif->u.noise.value) & 0xff), |
| 4928 | DEPTH_NOISE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4929 | break; |
| 4930 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4931 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4932 | IPW_ERROR |
| 4933 | ("Noise stat is wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4934 | size, sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4935 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4936 | } |
| 4937 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4938 | default: |
Zhu Yi | 1dd31b6 | 2006-02-20 18:28:09 -0800 | [diff] [blame] | 4939 | IPW_DEBUG_NOTIF("Unknown notification: " |
| 4940 | "subtype=%d,flags=0x%2x,size=%d\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4941 | notif->subtype, notif->flags, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4942 | } |
| 4943 | } |
| 4944 | |
| 4945 | /** |
| 4946 | * Destroys all DMA structures and initialise them again |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4947 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4948 | * @param priv |
| 4949 | * @return error code |
| 4950 | */ |
| 4951 | static int ipw_queue_reset(struct ipw_priv *priv) |
| 4952 | { |
| 4953 | int rc = 0; |
| 4954 | /** @todo customize queue sizes */ |
| 4955 | int nTx = 64, nTxCmd = 8; |
| 4956 | ipw_tx_queue_free(priv); |
| 4957 | /* Tx CMD queue */ |
| 4958 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4959 | IPW_TX_CMD_QUEUE_READ_INDEX, |
| 4960 | IPW_TX_CMD_QUEUE_WRITE_INDEX, |
| 4961 | IPW_TX_CMD_QUEUE_BD_BASE, |
| 4962 | IPW_TX_CMD_QUEUE_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4963 | if (rc) { |
| 4964 | IPW_ERROR("Tx Cmd queue init failed\n"); |
| 4965 | goto error; |
| 4966 | } |
| 4967 | /* Tx queue(s) */ |
| 4968 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4969 | IPW_TX_QUEUE_0_READ_INDEX, |
| 4970 | IPW_TX_QUEUE_0_WRITE_INDEX, |
| 4971 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4972 | if (rc) { |
| 4973 | IPW_ERROR("Tx 0 queue init failed\n"); |
| 4974 | goto error; |
| 4975 | } |
| 4976 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4977 | IPW_TX_QUEUE_1_READ_INDEX, |
| 4978 | IPW_TX_QUEUE_1_WRITE_INDEX, |
| 4979 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4980 | if (rc) { |
| 4981 | IPW_ERROR("Tx 1 queue init failed\n"); |
| 4982 | goto error; |
| 4983 | } |
| 4984 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4985 | IPW_TX_QUEUE_2_READ_INDEX, |
| 4986 | IPW_TX_QUEUE_2_WRITE_INDEX, |
| 4987 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4988 | if (rc) { |
| 4989 | IPW_ERROR("Tx 2 queue init failed\n"); |
| 4990 | goto error; |
| 4991 | } |
| 4992 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4993 | IPW_TX_QUEUE_3_READ_INDEX, |
| 4994 | IPW_TX_QUEUE_3_WRITE_INDEX, |
| 4995 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4996 | if (rc) { |
| 4997 | IPW_ERROR("Tx 3 queue init failed\n"); |
| 4998 | goto error; |
| 4999 | } |
| 5000 | /* statistics */ |
| 5001 | priv->rx_bufs_min = 0; |
| 5002 | priv->rx_pend_max = 0; |
| 5003 | return rc; |
| 5004 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5005 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5006 | ipw_tx_queue_free(priv); |
| 5007 | return rc; |
| 5008 | } |
| 5009 | |
| 5010 | /** |
| 5011 | * Reclaim Tx queue entries no more used by NIC. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5012 | * |
Stefano Brivio | 8ff9d21 | 2008-01-12 23:12:26 +0100 | [diff] [blame] | 5013 | * When FW advances 'R' index, all entries between old and |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5014 | * new 'R' index need to be reclaimed. As result, some free space |
| 5015 | * forms. If there is enough free space (> low mark), wake Tx queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5016 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5017 | * @note Need to protect against garbage in 'R' index |
| 5018 | * @param priv |
| 5019 | * @param txq |
| 5020 | * @param qindex |
| 5021 | * @return Number of used entries remains in the queue |
| 5022 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5023 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5024 | struct clx2_tx_queue *txq, int qindex) |
| 5025 | { |
| 5026 | u32 hw_tail; |
| 5027 | int used; |
| 5028 | struct clx2_queue *q = &txq->q; |
| 5029 | |
| 5030 | hw_tail = ipw_read32(priv, q->reg_r); |
| 5031 | if (hw_tail >= q->n_bd) { |
| 5032 | IPW_ERROR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5033 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
| 5034 | hw_tail, q->n_bd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5035 | goto done; |
| 5036 | } |
| 5037 | for (; q->last_used != hw_tail; |
| 5038 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 5039 | ipw_queue_tx_free_tfd(priv, txq); |
| 5040 | priv->tx_packets++; |
| 5041 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5042 | done: |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5043 | if ((ipw_tx_queue_space(q) > q->low_mark) && |
David S. Miller | 521c4d9 | 2008-07-22 18:32:47 -0700 | [diff] [blame] | 5044 | (qindex >= 0)) |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 5045 | netif_wake_queue(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5046 | used = q->first_empty - q->last_used; |
| 5047 | if (used < 0) |
| 5048 | used += q->n_bd; |
| 5049 | |
| 5050 | return used; |
| 5051 | } |
| 5052 | |
| 5053 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 5054 | int len, int sync) |
| 5055 | { |
| 5056 | struct clx2_tx_queue *txq = &priv->txq_cmd; |
| 5057 | struct clx2_queue *q = &txq->q; |
| 5058 | struct tfd_frame *tfd; |
| 5059 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5060 | if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5061 | IPW_ERROR("No space for Tx\n"); |
| 5062 | return -EBUSY; |
| 5063 | } |
| 5064 | |
| 5065 | tfd = &txq->bd[q->first_empty]; |
| 5066 | txq->txb[q->first_empty] = NULL; |
| 5067 | |
| 5068 | memset(tfd, 0, sizeof(*tfd)); |
| 5069 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; |
| 5070 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 5071 | priv->hcmd_seq++; |
| 5072 | tfd->u.cmd.index = hcmd; |
| 5073 | tfd->u.cmd.length = len; |
| 5074 | memcpy(tfd->u.cmd.payload, buf, len); |
| 5075 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 5076 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 5077 | _ipw_read32(priv, 0x90); |
| 5078 | |
| 5079 | return 0; |
| 5080 | } |
| 5081 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5082 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5083 | * Rx theory of operation |
| 5084 | * |
| 5085 | * The host allocates 32 DMA target addresses and passes the host address |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5086 | * 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] | 5087 | * 0 to 31 |
| 5088 | * |
| 5089 | * Rx Queue Indexes |
| 5090 | * The host/firmware share two index registers for managing the Rx buffers. |
| 5091 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5092 | * The READ index maps to the first position that the firmware may be writing |
| 5093 | * to -- the driver can read up to (but not including) this position and get |
| 5094 | * good data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5095 | * The READ index is managed by the firmware once the card is enabled. |
| 5096 | * |
| 5097 | * The WRITE index maps to the last position the driver has read from -- the |
| 5098 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 5099 | * |
| 5100 | * 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] | 5101 | * WRITE = READ. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5102 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5103 | * 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] | 5104 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 5105 | * |
| 5106 | * When the firmware places a packet in a buffer it will advance the READ index |
| 5107 | * and fire the RX interrupt. The driver can then query the READ index and |
| 5108 | * process as many packets as possible, moving the WRITE index forward as it |
| 5109 | * resets the Rx queue buffers with new memory. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5110 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5111 | * The management in the driver is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5112 | * + 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] | 5113 | * 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] | 5114 | * to replensish the ipw->rxq->rx_free. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5115 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
| 5116 | * ipw->rxq is replenished and the READ INDEX is updated (updating the |
| 5117 | * 'processed' and 'read' driver indexes as well) |
| 5118 | * + A received packet is processed and handed to the kernel network stack, |
| 5119 | * detached from the ipw->rxq. The driver 'processed' index is updated. |
| 5120 | * + 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] | 5121 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
| 5122 | * 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] | 5123 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 5124 | * |
| 5125 | * |
| 5126 | * Driver sequence: |
| 5127 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5128 | * ipw_rx_queue_alloc() Allocates rx_free |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5129 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
| 5130 | * ipw_rx_queue_restock |
| 5131 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 5132 | * queue, updates firmware pointers, and updates |
| 5133 | * the WRITE index. If insufficient rx_free buffers |
| 5134 | * are available, schedules ipw_rx_queue_replenish |
| 5135 | * |
| 5136 | * -- enable interrupts -- |
| 5137 | * 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] | 5138 | * READ INDEX, detaching the SKB from the pool. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5139 | * Moves the packet buffer from queue to rx_used. |
| 5140 | * Calls ipw_rx_queue_restock to refill any empty |
| 5141 | * slots. |
| 5142 | * ... |
| 5143 | * |
| 5144 | */ |
| 5145 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5146 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5147 | * If there are slots in the RX queue that need to be restocked, |
| 5148 | * and we have free pre-allocated buffers, fill the ranks as much |
| 5149 | * as we can pulling from rx_free. |
| 5150 | * |
| 5151 | * This moves the 'write' index forward to catch up with 'processed', and |
| 5152 | * also updates the memory address in the firmware to reference the new |
| 5153 | * target buffer. |
| 5154 | */ |
| 5155 | static void ipw_rx_queue_restock(struct ipw_priv *priv) |
| 5156 | { |
| 5157 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5158 | struct list_head *element; |
| 5159 | struct ipw_rx_mem_buffer *rxb; |
| 5160 | unsigned long flags; |
| 5161 | int write; |
| 5162 | |
| 5163 | spin_lock_irqsave(&rxq->lock, flags); |
| 5164 | write = rxq->write; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5165 | while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5166 | element = rxq->rx_free.next; |
| 5167 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
| 5168 | list_del(element); |
| 5169 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5170 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5171 | rxb->dma_addr); |
| 5172 | rxq->queue[rxq->write] = rxb; |
| 5173 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; |
| 5174 | rxq->free_count--; |
| 5175 | } |
| 5176 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5177 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5178 | /* If the pre-allocated buffer pool is dropping low, schedule to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5179 | * refill it */ |
| 5180 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 5181 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 5182 | |
| 5183 | /* 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] | 5184 | if (write != rxq->write) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5185 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5186 | } |
| 5187 | |
| 5188 | /* |
| 5189 | * 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] | 5190 | * Also restock the Rx queue via ipw_rx_queue_restock. |
| 5191 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5192 | * This is called as a scheduled work item (except for during intialization) |
| 5193 | */ |
| 5194 | static void ipw_rx_queue_replenish(void *data) |
| 5195 | { |
| 5196 | struct ipw_priv *priv = data; |
| 5197 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5198 | struct list_head *element; |
| 5199 | struct ipw_rx_mem_buffer *rxb; |
| 5200 | unsigned long flags; |
| 5201 | |
| 5202 | spin_lock_irqsave(&rxq->lock, flags); |
| 5203 | while (!list_empty(&rxq->rx_used)) { |
| 5204 | element = rxq->rx_used.next; |
| 5205 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5206 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5207 | if (!rxb->skb) { |
| 5208 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", |
| 5209 | priv->net_dev->name); |
| 5210 | /* We don't reschedule replenish work here -- we will |
| 5211 | * call the restock method and if it still needs |
| 5212 | * more buffers it will schedule replenish */ |
| 5213 | break; |
| 5214 | } |
| 5215 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5216 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5217 | rxb->dma_addr = |
| 5218 | pci_map_single(priv->pci_dev, rxb->skb->data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5219 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5220 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5221 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 5222 | rxq->free_count++; |
| 5223 | } |
| 5224 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5225 | |
| 5226 | ipw_rx_queue_restock(priv); |
| 5227 | } |
| 5228 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5229 | static void ipw_bg_rx_queue_replenish(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5230 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5231 | struct ipw_priv *priv = |
| 5232 | container_of(work, struct ipw_priv, rx_replenish); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5233 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5234 | ipw_rx_queue_replenish(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5235 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5236 | } |
| 5237 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5238 | /* 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] | 5239 | * 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] | 5240 | * 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] | 5241 | * non NULL it is unmapped and freed |
| 5242 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5243 | 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] | 5244 | { |
| 5245 | int i; |
| 5246 | |
| 5247 | if (!rxq) |
| 5248 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5249 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5250 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 5251 | if (rxq->pool[i].skb != NULL) { |
| 5252 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5253 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5254 | dev_kfree_skb(rxq->pool[i].skb); |
| 5255 | } |
| 5256 | } |
| 5257 | |
| 5258 | kfree(rxq); |
| 5259 | } |
| 5260 | |
| 5261 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) |
| 5262 | { |
| 5263 | struct ipw_rx_queue *rxq; |
| 5264 | int i; |
| 5265 | |
Takis | c75f474 | 2005-12-01 01:41:45 -0800 | [diff] [blame] | 5266 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
Panagiotis Issaris | ad18b0e | 2005-09-05 04:14:10 +0200 | [diff] [blame] | 5267 | if (unlikely(!rxq)) { |
| 5268 | IPW_ERROR("memory allocation failed\n"); |
| 5269 | return NULL; |
| 5270 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5271 | spin_lock_init(&rxq->lock); |
| 5272 | INIT_LIST_HEAD(&rxq->rx_free); |
| 5273 | INIT_LIST_HEAD(&rxq->rx_used); |
| 5274 | |
| 5275 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5276 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5277 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 5278 | |
| 5279 | /* Set us so that we have processed and used all buffers, but have |
| 5280 | * not restocked the Rx queue with fresh buffers */ |
| 5281 | rxq->read = rxq->write = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5282 | rxq->free_count = 0; |
| 5283 | |
| 5284 | return rxq; |
| 5285 | } |
| 5286 | |
| 5287 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) |
| 5288 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5289 | rate &= ~LIBIPW_BASIC_RATE_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5290 | if (ieee_mode == IEEE_A) { |
| 5291 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5292 | case LIBIPW_OFDM_RATE_6MB: |
| 5293 | return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5294 | 1 : 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5295 | case LIBIPW_OFDM_RATE_9MB: |
| 5296 | return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5297 | 1 : 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5298 | case LIBIPW_OFDM_RATE_12MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5299 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5300 | rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; |
| 5301 | case LIBIPW_OFDM_RATE_18MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5302 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5303 | rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; |
| 5304 | case LIBIPW_OFDM_RATE_24MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5305 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5306 | rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; |
| 5307 | case LIBIPW_OFDM_RATE_36MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5308 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5309 | rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; |
| 5310 | case LIBIPW_OFDM_RATE_48MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5311 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5312 | rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; |
| 5313 | case LIBIPW_OFDM_RATE_54MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5314 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5315 | rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5316 | default: |
| 5317 | return 0; |
| 5318 | } |
| 5319 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5320 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5321 | /* B and G mixed */ |
| 5322 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5323 | case LIBIPW_CCK_RATE_1MB: |
| 5324 | return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0; |
| 5325 | case LIBIPW_CCK_RATE_2MB: |
| 5326 | return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0; |
| 5327 | case LIBIPW_CCK_RATE_5MB: |
| 5328 | return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0; |
| 5329 | case LIBIPW_CCK_RATE_11MB: |
| 5330 | return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | /* If we are limited to B modulations, bail at this point */ |
| 5334 | if (ieee_mode == IEEE_B) |
| 5335 | return 0; |
| 5336 | |
| 5337 | /* G */ |
| 5338 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5339 | case LIBIPW_OFDM_RATE_6MB: |
| 5340 | return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0; |
| 5341 | case LIBIPW_OFDM_RATE_9MB: |
| 5342 | return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0; |
| 5343 | case LIBIPW_OFDM_RATE_12MB: |
| 5344 | return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; |
| 5345 | case LIBIPW_OFDM_RATE_18MB: |
| 5346 | return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; |
| 5347 | case LIBIPW_OFDM_RATE_24MB: |
| 5348 | return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; |
| 5349 | case LIBIPW_OFDM_RATE_36MB: |
| 5350 | return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; |
| 5351 | case LIBIPW_OFDM_RATE_48MB: |
| 5352 | return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; |
| 5353 | case LIBIPW_OFDM_RATE_54MB: |
| 5354 | return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | return 0; |
| 5358 | } |
| 5359 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5360 | static int ipw_compatible_rates(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5361 | const struct libipw_network *network, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5362 | struct ipw_supported_rates *rates) |
| 5363 | { |
| 5364 | int num_rates, i; |
| 5365 | |
| 5366 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5367 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5368 | rates->num_rates = 0; |
| 5369 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5370 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5371 | network->rates[i])) { |
| 5372 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5373 | if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5374 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5375 | "rate %02X\n", |
| 5376 | network->rates[i]); |
| 5377 | rates->supported_rates[rates->num_rates++] = |
| 5378 | network->rates[i]; |
| 5379 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5380 | } |
| 5381 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5382 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5383 | network->rates[i], priv->rates_mask); |
| 5384 | continue; |
| 5385 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5386 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5387 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
| 5388 | } |
| 5389 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5390 | num_rates = min(network->rates_ex_len, |
| 5391 | (u8) (IPW_MAX_RATES - num_rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5392 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5393 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5394 | network->rates_ex[i])) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5395 | if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5396 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5397 | "rate %02X\n", |
| 5398 | network->rates_ex[i]); |
| 5399 | rates->supported_rates[rates->num_rates++] = |
| 5400 | network->rates[i]; |
| 5401 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5402 | } |
| 5403 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5404 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5405 | network->rates_ex[i], priv->rates_mask); |
| 5406 | continue; |
| 5407 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5408 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5409 | rates->supported_rates[rates->num_rates++] = |
| 5410 | network->rates_ex[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5411 | } |
| 5412 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5413 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5414 | } |
| 5415 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5416 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5417 | const struct ipw_supported_rates *src) |
| 5418 | { |
| 5419 | u8 i; |
| 5420 | for (i = 0; i < src->num_rates; i++) |
| 5421 | dest->supported_rates[i] = src->supported_rates[i]; |
| 5422 | dest->num_rates = src->num_rates; |
| 5423 | } |
| 5424 | |
| 5425 | /* TODO: Look at sniffed packets in the air to determine if the basic rate |
| 5426 | * mask should ever be used -- right now all callers to add the scan rates are |
| 5427 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ |
| 5428 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5429 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5430 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5431 | u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? |
| 5432 | LIBIPW_BASIC_RATE_MASK : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5433 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5434 | if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5435 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5436 | LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5437 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5438 | if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5439 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5440 | LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5441 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5442 | if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5443 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5444 | LIBIPW_CCK_RATE_5MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5445 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5446 | if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5447 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5448 | LIBIPW_CCK_RATE_11MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5452 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5453 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5454 | u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? |
| 5455 | LIBIPW_BASIC_RATE_MASK : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5456 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5457 | if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5458 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5459 | LIBIPW_OFDM_RATE_6MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5460 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5461 | if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5462 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5463 | LIBIPW_OFDM_RATE_9MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5464 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5465 | if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5466 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5467 | LIBIPW_OFDM_RATE_12MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5468 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5469 | if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5470 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5471 | LIBIPW_OFDM_RATE_18MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5472 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5473 | if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5474 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5475 | LIBIPW_OFDM_RATE_24MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5476 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5477 | if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5478 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5479 | LIBIPW_OFDM_RATE_36MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5480 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5481 | if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5482 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5483 | LIBIPW_OFDM_RATE_48MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5484 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5485 | if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5486 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5487 | LIBIPW_OFDM_RATE_54MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5488 | } |
| 5489 | |
| 5490 | struct ipw_network_match { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5491 | struct libipw_network *network; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5492 | struct ipw_supported_rates rates; |
| 5493 | }; |
| 5494 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5495 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
| 5496 | struct ipw_network_match *match, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5497 | struct libipw_network *network, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5498 | int roaming) |
| 5499 | { |
| 5500 | struct ipw_supported_rates rates; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5501 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5502 | |
| 5503 | /* Verify that this network's capability is compatible with the |
| 5504 | * current mode (AdHoc or Infrastructure) */ |
| 5505 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5506 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5507 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5508 | "capability mismatch.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5509 | print_ssid(ssid, network->ssid, |
| 5510 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5511 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5512 | return 0; |
| 5513 | } |
| 5514 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5515 | if (unlikely(roaming)) { |
| 5516 | /* If we are roaming, then ensure check if this is a valid |
| 5517 | * network to try and roam to */ |
| 5518 | if ((network->ssid_len != match->network->ssid_len) || |
| 5519 | memcmp(network->ssid, match->network->ssid, |
| 5520 | network->ssid_len)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5521 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5522 | "because of non-network ESSID.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5523 | print_ssid(ssid, network->ssid, |
| 5524 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5525 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5526 | return 0; |
| 5527 | } |
| 5528 | } else { |
| 5529 | /* If an ESSID has been configured then compare the broadcast |
| 5530 | * ESSID to ours */ |
| 5531 | if ((priv->config & CFG_STATIC_ESSID) && |
| 5532 | ((network->ssid_len != priv->essid_len) || |
| 5533 | memcmp(network->ssid, priv->essid, |
| 5534 | min(network->ssid_len, priv->essid_len)))) { |
| 5535 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5536 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5537 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5538 | print_ssid(ssid, network->ssid, |
| 5539 | network->ssid_len), |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5540 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5541 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5542 | "because of ESSID mismatch: '%s'.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5543 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5544 | print_ssid(ssid, priv->essid, |
| 5545 | priv->essid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5546 | return 0; |
| 5547 | } |
| 5548 | } |
| 5549 | |
| 5550 | /* If the old network rate is better than this one, don't bother |
| 5551 | * testing everything else. */ |
| 5552 | |
| 5553 | if (network->time_stamp[0] < match->network->time_stamp[0]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5554 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5555 | "current network.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5556 | print_ssid(ssid, match->network->ssid, |
| 5557 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5558 | return 0; |
| 5559 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5560 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5561 | "current network.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5562 | print_ssid(ssid, match->network->ssid, |
| 5563 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5564 | return 0; |
| 5565 | } |
| 5566 | |
| 5567 | /* Now go through and see if the requested network is valid... */ |
| 5568 | if (priv->ieee->scan_age != 0 && |
| 5569 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5570 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5571 | "because of age: %ums.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5572 | print_ssid(ssid, network->ssid, |
| 5573 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5574 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5575 | jiffies_to_msecs(jiffies - |
| 5576 | network->last_scanned)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5577 | return 0; |
| 5578 | } |
| 5579 | |
| 5580 | if ((priv->config & CFG_STATIC_CHANNEL) && |
| 5581 | (network->channel != priv->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5582 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5583 | "because of channel mismatch: %d != %d.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5584 | print_ssid(ssid, network->ssid, |
| 5585 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5586 | network->bssid, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5587 | network->channel, priv->channel); |
| 5588 | return 0; |
| 5589 | } |
| 5590 | |
| 5591 | /* Verify privacy compatability */ |
| 5592 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
| 5593 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5594 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5595 | "because of privacy mismatch: %s != %s.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5596 | print_ssid(ssid, network->ssid, |
| 5597 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5598 | network->bssid, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5599 | priv-> |
| 5600 | capability & CAP_PRIVACY_ON ? "on" : "off", |
| 5601 | network-> |
| 5602 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : |
| 5603 | "off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5604 | return 0; |
| 5605 | } |
| 5606 | |
| 5607 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5608 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
| 5609 | "because of the same BSSID match: %pM" |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5610 | ".\n", print_ssid(ssid, network->ssid, |
| 5611 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5612 | network->bssid, |
| 5613 | priv->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5614 | return 0; |
| 5615 | } |
| 5616 | |
| 5617 | /* Filter out any incompatible freq / mode combinations */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5618 | if (!libipw_is_valid_mode(priv->ieee, network->mode)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5619 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5620 | "because of invalid frequency/mode " |
| 5621 | "combination.\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 | /* Ensure that the rates supported by the driver are compatible with |
| 5629 | * this AP, including verification of basic rates (mandatory) */ |
| 5630 | if (!ipw_compatible_rates(priv, network, &rates)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5631 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5632 | "because configured rate mask excludes " |
| 5633 | "AP mandatory rate.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5634 | print_ssid(ssid, network->ssid, |
| 5635 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5636 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5637 | return 0; |
| 5638 | } |
| 5639 | |
| 5640 | if (rates.num_rates == 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5641 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5642 | "because of no compatible rates.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5643 | print_ssid(ssid, network->ssid, |
| 5644 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5645 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5646 | return 0; |
| 5647 | } |
| 5648 | |
| 5649 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5650 | * want to put too much policy logic here; intelligent scan selection |
| 5651 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5652 | |
| 5653 | /* Set up 'new' AP to this network */ |
| 5654 | ipw_copy_rates(&match->rates, &rates); |
| 5655 | match->network = network; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5656 | IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5657 | print_ssid(ssid, network->ssid, network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5658 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5659 | |
| 5660 | return 1; |
| 5661 | } |
| 5662 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5663 | static void ipw_merge_adhoc_network(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5664 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5665 | DECLARE_SSID_BUF(ssid); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5666 | struct ipw_priv *priv = |
| 5667 | container_of(work, struct ipw_priv, merge_networks); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5668 | struct libipw_network *network = NULL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5669 | struct ipw_network_match match = { |
| 5670 | .network = priv->assoc_network |
| 5671 | }; |
| 5672 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5673 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5674 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5675 | /* First pass through ROAM process -- look for a better |
| 5676 | * network */ |
| 5677 | unsigned long flags; |
| 5678 | |
| 5679 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 5680 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 5681 | if (network != priv->assoc_network) |
| 5682 | ipw_find_adhoc_network(priv, &match, network, |
| 5683 | 1); |
| 5684 | } |
| 5685 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 5686 | |
| 5687 | if (match.network == priv->assoc_network) { |
| 5688 | IPW_DEBUG_MERGE("No better ADHOC in this network to " |
| 5689 | "merge to.\n"); |
| 5690 | return; |
| 5691 | } |
| 5692 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5693 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5694 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
| 5695 | IPW_DEBUG_MERGE("remove network %s\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5696 | print_ssid(ssid, priv->essid, |
| 5697 | priv->essid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5698 | ipw_remove_current_network(priv); |
| 5699 | } |
| 5700 | |
| 5701 | ipw_disassociate(priv); |
| 5702 | priv->assoc_network = match.network; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5703 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5704 | return; |
| 5705 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5706 | } |
| 5707 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5708 | static int ipw_best_network(struct ipw_priv *priv, |
| 5709 | struct ipw_network_match *match, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5710 | struct libipw_network *network, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5711 | { |
| 5712 | struct ipw_supported_rates rates; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5713 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5714 | |
| 5715 | /* Verify that this network's capability is compatible with the |
| 5716 | * current mode (AdHoc or Infrastructure) */ |
| 5717 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && |
Jouni Malinen | 2474385 | 2005-08-14 20:59:59 -0700 | [diff] [blame] | 5718 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5719 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5720 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5721 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5722 | "capability mismatch.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5723 | print_ssid(ssid, network->ssid, |
| 5724 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5725 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5726 | return 0; |
| 5727 | } |
| 5728 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5729 | if (unlikely(roaming)) { |
| 5730 | /* If we are roaming, then ensure check if this is a valid |
| 5731 | * network to try and roam to */ |
| 5732 | if ((network->ssid_len != match->network->ssid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5733 | memcmp(network->ssid, match->network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5734 | network->ssid_len)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5735 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5736 | "because of non-network ESSID.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5737 | print_ssid(ssid, network->ssid, |
| 5738 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5739 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5740 | return 0; |
| 5741 | } |
| 5742 | } else { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5743 | /* If an ESSID has been configured then compare the broadcast |
| 5744 | * ESSID to ours */ |
| 5745 | if ((priv->config & CFG_STATIC_ESSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5746 | ((network->ssid_len != priv->essid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5747 | memcmp(network->ssid, priv->essid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5748 | min(network->ssid_len, priv->essid_len)))) { |
| 5749 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5750 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5751 | print_ssid(ssid, network->ssid, |
| 5752 | network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5753 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5754 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5755 | "because of ESSID mismatch: '%s'.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5756 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5757 | print_ssid(ssid, priv->essid, |
| 5758 | priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5759 | return 0; |
| 5760 | } |
| 5761 | } |
| 5762 | |
| 5763 | /* If the old network rate is better than this one, don't bother |
| 5764 | * testing everything else. */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5765 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5766 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5767 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5768 | print_ssid(ssid, network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5769 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5770 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because " |
| 5771 | "'%s (%pM)' has a stronger signal.\n", |
| 5772 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5773 | print_ssid(ssid, match->network->ssid, |
| 5774 | match->network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5775 | match->network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5776 | return 0; |
| 5777 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5778 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5779 | /* If this network has already had an association attempt within the |
| 5780 | * last 3 seconds, do not try and associate again... */ |
| 5781 | if (network->last_associate && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5782 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5783 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5784 | "because of storming (%ums since last " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5785 | "assoc attempt).\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5786 | print_ssid(ssid, network->ssid, |
| 5787 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5788 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5789 | jiffies_to_msecs(jiffies - |
| 5790 | network->last_associate)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5791 | return 0; |
| 5792 | } |
| 5793 | |
| 5794 | /* Now go through and see if the requested network is valid... */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5795 | if (priv->ieee->scan_age != 0 && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5796 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5797 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5798 | "because of age: %ums.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5799 | print_ssid(ssid, network->ssid, |
| 5800 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5801 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5802 | jiffies_to_msecs(jiffies - |
| 5803 | network->last_scanned)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5804 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5805 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5806 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5807 | if ((priv->config & CFG_STATIC_CHANNEL) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5808 | (network->channel != priv->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5809 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5810 | "because of channel mismatch: %d != %d.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5811 | print_ssid(ssid, network->ssid, |
| 5812 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5813 | network->bssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5814 | network->channel, priv->channel); |
| 5815 | return 0; |
| 5816 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5817 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5818 | /* Verify privacy compatability */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5819 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5820 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5821 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5822 | "because of privacy mismatch: %s != %s.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5823 | print_ssid(ssid, network->ssid, |
| 5824 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5825 | network->bssid, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5826 | priv->capability & CAP_PRIVACY_ON ? "on" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5827 | "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5828 | network->capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5829 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
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 | |
| 5833 | if ((priv->config & CFG_STATIC_BSSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5834 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5835 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
| 5836 | "because of BSSID mismatch: %pM.\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, priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5840 | return 0; |
| 5841 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5842 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5843 | /* Filter out any incompatible freq / mode combinations */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5844 | if (!libipw_is_valid_mode(priv->ieee, network->mode)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5845 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5846 | "because of invalid frequency/mode " |
| 5847 | "combination.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5848 | print_ssid(ssid, network->ssid, |
| 5849 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5850 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5851 | return 0; |
| 5852 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5853 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5854 | /* Filter out invalid channel in current GEO */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5855 | if (!libipw_is_valid_channel(priv->ieee, network->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5856 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5857 | "because of invalid channel in current GEO\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); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5861 | return 0; |
| 5862 | } |
| 5863 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5864 | /* Ensure that the rates supported by the driver are compatible with |
| 5865 | * this AP, including verification of basic rates (mandatory) */ |
| 5866 | if (!ipw_compatible_rates(priv, network, &rates)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5867 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5868 | "because configured rate mask excludes " |
| 5869 | "AP mandatory rate.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5870 | print_ssid(ssid, network->ssid, |
| 5871 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5872 | network->bssid); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5873 | return 0; |
| 5874 | } |
| 5875 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5876 | if (rates.num_rates == 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5877 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5878 | "because of no compatible rates.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5879 | print_ssid(ssid, network->ssid, |
| 5880 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5881 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5882 | return 0; |
| 5883 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5884 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5885 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5886 | * want to put too much policy logic here; intelligent scan selection |
| 5887 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5888 | |
| 5889 | /* Set up 'new' AP to this network */ |
| 5890 | ipw_copy_rates(&match->rates, &rates); |
| 5891 | match->network = network; |
| 5892 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5893 | IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5894 | print_ssid(ssid, network->ssid, network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5895 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5896 | |
| 5897 | return 1; |
| 5898 | } |
| 5899 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5900 | static void ipw_adhoc_create(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5901 | struct libipw_network *network) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5902 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5903 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5904 | int i; |
| 5905 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5906 | /* |
| 5907 | * For the purposes of scanning, we can set our wireless mode |
| 5908 | * to trigger scans across combinations of bands, but when it |
| 5909 | * comes to creating a new ad-hoc network, we have tell the FW |
| 5910 | * exactly which band to use. |
| 5911 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5912 | * We also have the possibility of an invalid channel for the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5913 | * chossen band. Attempting to create a new ad-hoc network |
| 5914 | * with an invalid channel for wireless mode will trigger a |
| 5915 | * FW fatal error. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5916 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5917 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5918 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 5919 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5920 | network->mode = IEEE_A; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5921 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5922 | BUG_ON(i == -1); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5923 | if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5924 | IPW_WARNING("Overriding invalid channel\n"); |
| 5925 | priv->channel = geo->a[0].channel; |
| 5926 | } |
| 5927 | break; |
| 5928 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5929 | case LIBIPW_24GHZ_BAND: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5930 | if (priv->ieee->mode & IEEE_G) |
| 5931 | network->mode = IEEE_G; |
| 5932 | else |
| 5933 | network->mode = IEEE_B; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5934 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5935 | BUG_ON(i == -1); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5936 | if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5937 | IPW_WARNING("Overriding invalid channel\n"); |
| 5938 | priv->channel = geo->bg[0].channel; |
| 5939 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5940 | break; |
| 5941 | |
| 5942 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5943 | IPW_WARNING("Overriding invalid channel\n"); |
| 5944 | if (priv->ieee->mode & IEEE_A) { |
| 5945 | network->mode = IEEE_A; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5946 | priv->channel = geo->a[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5947 | } else if (priv->ieee->mode & IEEE_G) { |
| 5948 | network->mode = IEEE_G; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5949 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5950 | } else { |
| 5951 | network->mode = IEEE_B; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5952 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5953 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5954 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5955 | } |
| 5956 | |
| 5957 | network->channel = priv->channel; |
| 5958 | priv->config |= CFG_ADHOC_PERSIST; |
| 5959 | ipw_create_bssid(priv, network->bssid); |
| 5960 | network->ssid_len = priv->essid_len; |
| 5961 | memcpy(network->ssid, priv->essid, priv->essid_len); |
| 5962 | memset(&network->stats, 0, sizeof(network->stats)); |
| 5963 | network->capability = WLAN_CAPABILITY_IBSS; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5964 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
| 5965 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5966 | if (priv->capability & CAP_PRIVACY_ON) |
| 5967 | network->capability |= WLAN_CAPABILITY_PRIVACY; |
| 5968 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5969 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5970 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5971 | memcpy(network->rates_ex, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5972 | &priv->rates.supported_rates[network->rates_len], |
| 5973 | network->rates_ex_len); |
| 5974 | network->last_scanned = 0; |
| 5975 | network->flags = 0; |
| 5976 | network->last_associate = 0; |
| 5977 | network->time_stamp[0] = 0; |
| 5978 | network->time_stamp[1] = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5979 | network->beacon_interval = 100; /* Default */ |
| 5980 | network->listen_interval = 10; /* Default */ |
| 5981 | network->atim_window = 0; /* Default */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5982 | network->wpa_ie_len = 0; |
| 5983 | network->rsn_ie_len = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5984 | } |
| 5985 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5986 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
| 5987 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5988 | struct ipw_tgi_tx_key key; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5989 | |
| 5990 | if (!(priv->ieee->sec.flags & (1 << index))) |
| 5991 | return; |
| 5992 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5993 | key.key_id = index; |
| 5994 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); |
| 5995 | key.security_type = type; |
| 5996 | key.station_index = 0; /* always 0 for BSS */ |
| 5997 | key.flags = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5998 | /* 0 for new key; previous value of counter (after fatal error) */ |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 5999 | key.tx_counter[0] = cpu_to_le32(0); |
| 6000 | key.tx_counter[1] = cpu_to_le32(0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6001 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6002 | 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] | 6003 | } |
| 6004 | |
| 6005 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6006 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6007 | struct ipw_wep_key key; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6008 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6009 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6010 | key.cmd_id = DINO_CMD_WEP_KEY; |
| 6011 | key.seq_num = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6012 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6013 | /* Note: AES keys cannot be set for multiple times. |
| 6014 | * Only set it at the first time. */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6015 | for (i = 0; i < 4; i++) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6016 | key.key_index = i | type; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6017 | if (!(priv->ieee->sec.flags & (1 << i))) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6018 | key.key_size = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6019 | continue; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6020 | } |
| 6021 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6022 | key.key_size = priv->ieee->sec.key_sizes[i]; |
| 6023 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6024 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6025 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6026 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6027 | } |
| 6028 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6029 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
| 6030 | { |
| 6031 | if (priv->ieee->host_encrypt) |
| 6032 | return; |
| 6033 | |
| 6034 | switch (level) { |
| 6035 | case SEC_LEVEL_3: |
| 6036 | priv->sys_config.disable_unicast_decryption = 0; |
| 6037 | priv->ieee->host_decrypt = 0; |
| 6038 | break; |
| 6039 | case SEC_LEVEL_2: |
| 6040 | priv->sys_config.disable_unicast_decryption = 1; |
| 6041 | priv->ieee->host_decrypt = 1; |
| 6042 | break; |
| 6043 | case SEC_LEVEL_1: |
| 6044 | priv->sys_config.disable_unicast_decryption = 0; |
| 6045 | priv->ieee->host_decrypt = 0; |
| 6046 | break; |
| 6047 | case SEC_LEVEL_0: |
| 6048 | priv->sys_config.disable_unicast_decryption = 1; |
| 6049 | break; |
| 6050 | default: |
| 6051 | break; |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) |
| 6056 | { |
| 6057 | if (priv->ieee->host_encrypt) |
| 6058 | return; |
| 6059 | |
| 6060 | switch (level) { |
| 6061 | case SEC_LEVEL_3: |
| 6062 | priv->sys_config.disable_multicast_decryption = 0; |
| 6063 | break; |
| 6064 | case SEC_LEVEL_2: |
| 6065 | priv->sys_config.disable_multicast_decryption = 1; |
| 6066 | break; |
| 6067 | case SEC_LEVEL_1: |
| 6068 | priv->sys_config.disable_multicast_decryption = 0; |
| 6069 | break; |
| 6070 | case SEC_LEVEL_0: |
| 6071 | priv->sys_config.disable_multicast_decryption = 1; |
| 6072 | break; |
| 6073 | default: |
| 6074 | break; |
| 6075 | } |
| 6076 | } |
| 6077 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6078 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
| 6079 | { |
| 6080 | switch (priv->ieee->sec.level) { |
| 6081 | case SEC_LEVEL_3: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 6082 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 6083 | ipw_send_tgi_tx_key(priv, |
| 6084 | DCT_FLAG_EXT_SECURITY_CCM, |
| 6085 | priv->ieee->sec.active_key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6086 | |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6087 | if (!priv->ieee->host_mc_decrypt) |
| 6088 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6089 | break; |
| 6090 | case SEC_LEVEL_2: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 6091 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 6092 | ipw_send_tgi_tx_key(priv, |
| 6093 | DCT_FLAG_EXT_SECURITY_TKIP, |
| 6094 | priv->ieee->sec.active_key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6095 | break; |
| 6096 | case SEC_LEVEL_1: |
| 6097 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Hong Liu | 29cb843 | 2005-09-12 10:43:33 -0500 | [diff] [blame] | 6098 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
| 6099 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6100 | break; |
| 6101 | case SEC_LEVEL_0: |
| 6102 | default: |
| 6103 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6104 | } |
| 6105 | } |
| 6106 | |
| 6107 | static void ipw_adhoc_check(void *data) |
| 6108 | { |
| 6109 | struct ipw_priv *priv = data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6110 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6111 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6112 | !(priv->config & CFG_ADHOC_PERSIST)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6113 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 6114 | IPW_DL_STATE | IPW_DL_ASSOC, |
| 6115 | "Missed beacon: %d - disassociate\n", |
| 6116 | priv->missed_adhoc_beacons); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6117 | ipw_remove_current_network(priv); |
| 6118 | ipw_disassociate(priv); |
| 6119 | return; |
| 6120 | } |
| 6121 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6122 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 6123 | le16_to_cpu(priv->assoc_request.beacon_interval)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6124 | } |
| 6125 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6126 | static void ipw_bg_adhoc_check(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6127 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6128 | struct ipw_priv *priv = |
| 6129 | container_of(work, struct ipw_priv, adhoc_check.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6130 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6131 | ipw_adhoc_check(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6132 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6133 | } |
| 6134 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6135 | static void ipw_debug_config(struct ipw_priv *priv) |
| 6136 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6137 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6138 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
| 6139 | "[CFG 0x%08X]\n", priv->config); |
| 6140 | if (priv->config & CFG_STATIC_CHANNEL) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6141 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6142 | else |
| 6143 | IPW_DEBUG_INFO("Channel unlocked.\n"); |
| 6144 | if (priv->config & CFG_STATIC_ESSID) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6145 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6146 | print_ssid(ssid, priv->essid, priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6147 | else |
| 6148 | IPW_DEBUG_INFO("ESSID unlocked.\n"); |
| 6149 | if (priv->config & CFG_STATIC_BSSID) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6150 | IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6151 | else |
| 6152 | IPW_DEBUG_INFO("BSSID unlocked.\n"); |
| 6153 | if (priv->capability & CAP_PRIVACY_ON) |
| 6154 | IPW_DEBUG_INFO("PRIVACY on\n"); |
| 6155 | else |
| 6156 | IPW_DEBUG_INFO("PRIVACY off\n"); |
| 6157 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); |
| 6158 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6159 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 6160 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6161 | { |
| 6162 | /* TODO: Verify that this works... */ |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6163 | struct ipw_fixed_rate fr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6164 | u32 reg; |
| 6165 | u16 mask = 0; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6166 | u16 new_tx_rates = priv->rates_mask; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6167 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6168 | /* Identify 'current FW band' and match it with the fixed |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6169 | * Tx rates */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6170 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6171 | switch (priv->ieee->freq_band) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6172 | case LIBIPW_52GHZ_BAND: /* A only */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6173 | /* IEEE_A */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6174 | if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6175 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6176 | IPW_DEBUG_WX |
| 6177 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6178 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6179 | break; |
| 6180 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6181 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6182 | new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6183 | break; |
| 6184 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6185 | default: /* 2.4Ghz or Mixed */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6186 | /* IEEE_B */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6187 | if (mode == IEEE_B) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6188 | if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6189 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6190 | IPW_DEBUG_WX |
| 6191 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6192 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6193 | } |
| 6194 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6195 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6196 | |
| 6197 | /* IEEE_G */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6198 | if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK | |
| 6199 | LIBIPW_OFDM_RATES_MASK)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6200 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6201 | IPW_DEBUG_WX |
| 6202 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6203 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6204 | break; |
| 6205 | } |
| 6206 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6207 | if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) { |
| 6208 | mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1); |
| 6209 | new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6210 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6211 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6212 | if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) { |
| 6213 | mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1); |
| 6214 | new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6215 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6216 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6217 | if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) { |
| 6218 | mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1); |
| 6219 | new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6220 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6221 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6222 | new_tx_rates |= mask; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6223 | break; |
| 6224 | } |
| 6225 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6226 | fr.tx_rates = cpu_to_le16(new_tx_rates); |
| 6227 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6228 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6229 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6230 | } |
| 6231 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6232 | static void ipw_abort_scan(struct ipw_priv *priv) |
| 6233 | { |
| 6234 | int err; |
| 6235 | |
| 6236 | if (priv->status & STATUS_SCAN_ABORTING) { |
| 6237 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); |
| 6238 | return; |
| 6239 | } |
| 6240 | priv->status |= STATUS_SCAN_ABORTING; |
| 6241 | |
| 6242 | err = ipw_send_scan_abort(priv); |
| 6243 | if (err) |
| 6244 | IPW_DEBUG_HC("Request to abort scan failed.\n"); |
| 6245 | } |
| 6246 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6247 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
| 6248 | struct ipw_scan_request_ext *scan, |
| 6249 | int scan_type) |
| 6250 | { |
| 6251 | int channel_index = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6252 | const struct libipw_geo *geo; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6253 | int i; |
| 6254 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6255 | geo = libipw_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6256 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6257 | if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6258 | int start = channel_index; |
| 6259 | for (i = 0; i < geo->a_channels; i++) { |
| 6260 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6261 | geo->a[i].channel == priv->channel) |
| 6262 | continue; |
| 6263 | channel_index++; |
| 6264 | scan->channels_list[channel_index] = geo->a[i].channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6265 | ipw_set_scan_type(scan, channel_index, |
| 6266 | geo->a[i]. |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6267 | flags & LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6268 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : |
| 6269 | scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6270 | } |
| 6271 | |
| 6272 | if (start != channel_index) { |
| 6273 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | |
| 6274 | (channel_index - start); |
| 6275 | channel_index++; |
| 6276 | } |
| 6277 | } |
| 6278 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6279 | if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6280 | int start = channel_index; |
| 6281 | if (priv->config & CFG_SPEED_SCAN) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6282 | int index; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6283 | u8 channels[LIBIPW_24GHZ_CHANNELS] = { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6284 | /* nop out the list */ |
| 6285 | [0] = 0 |
| 6286 | }; |
| 6287 | |
| 6288 | u8 channel; |
Zhu Yi | 7dd2459 | 2009-07-27 10:10:20 +0800 | [diff] [blame] | 6289 | while (channel_index < IPW_SCAN_CHANNELS - 1) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6290 | channel = |
| 6291 | priv->speed_scan[priv->speed_scan_pos]; |
| 6292 | if (channel == 0) { |
| 6293 | priv->speed_scan_pos = 0; |
| 6294 | channel = priv->speed_scan[0]; |
| 6295 | } |
| 6296 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6297 | channel == priv->channel) { |
| 6298 | priv->speed_scan_pos++; |
| 6299 | continue; |
| 6300 | } |
| 6301 | |
| 6302 | /* If this channel has already been |
| 6303 | * added in scan, break from loop |
| 6304 | * and this will be the first channel |
| 6305 | * in the next scan. |
| 6306 | */ |
| 6307 | if (channels[channel - 1] != 0) |
| 6308 | break; |
| 6309 | |
| 6310 | channels[channel - 1] = 1; |
| 6311 | priv->speed_scan_pos++; |
| 6312 | channel_index++; |
| 6313 | scan->channels_list[channel_index] = channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6314 | index = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6315 | libipw_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6316 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6317 | geo->bg[index]. |
| 6318 | flags & |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6319 | LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6320 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6321 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6322 | } |
| 6323 | } else { |
| 6324 | for (i = 0; i < geo->bg_channels; i++) { |
| 6325 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6326 | geo->bg[i].channel == priv->channel) |
| 6327 | continue; |
| 6328 | channel_index++; |
| 6329 | scan->channels_list[channel_index] = |
| 6330 | geo->bg[i].channel; |
| 6331 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6332 | geo->bg[i]. |
| 6333 | flags & |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6334 | LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6335 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6336 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | if (start != channel_index) { |
| 6341 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | |
| 6342 | (channel_index - start); |
| 6343 | } |
| 6344 | } |
| 6345 | } |
| 6346 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6347 | static int ipw_passive_dwell_time(struct ipw_priv *priv) |
| 6348 | { |
| 6349 | /* staying on passive channels longer than the DTIM interval during a |
| 6350 | * scan, while associated, causes the firmware to cancel the scan |
| 6351 | * without notification. Hence, don't stay on passive channels longer |
| 6352 | * than the beacon interval. |
| 6353 | */ |
| 6354 | if (priv->status & STATUS_ASSOCIATED |
| 6355 | && priv->assoc_network->beacon_interval > 10) |
| 6356 | return priv->assoc_network->beacon_interval - 10; |
| 6357 | else |
| 6358 | return 120; |
| 6359 | } |
| 6360 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6361 | 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] | 6362 | { |
| 6363 | struct ipw_scan_request_ext scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6364 | int err = 0, scan_type; |
| 6365 | |
| 6366 | if (!(priv->status & STATUS_INIT) || |
| 6367 | (priv->status & STATUS_EXIT_PENDING)) |
| 6368 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6369 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6370 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6371 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6372 | if (direct && (priv->direct_scan_ssid_len == 0)) { |
| 6373 | IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n"); |
| 6374 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; |
| 6375 | goto done; |
| 6376 | } |
| 6377 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6378 | if (priv->status & STATUS_SCANNING) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6379 | IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n"); |
| 6380 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6381 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6382 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6383 | } |
| 6384 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6385 | if (!(priv->status & STATUS_SCAN_FORCED) && |
| 6386 | priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6387 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6388 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6389 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6390 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6391 | } |
| 6392 | |
| 6393 | if (priv->status & STATUS_RF_KILL_MASK) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6394 | IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n"); |
| 6395 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6396 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6397 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | memset(&scan, 0, sizeof(scan)); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6401 | scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee)); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6402 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6403 | if (type == IW_SCAN_TYPE_PASSIVE) { |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6404 | IPW_DEBUG_WX("use passive scanning\n"); |
| 6405 | scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN; |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6406 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6407 | cpu_to_le16(ipw_passive_dwell_time(priv)); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6408 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 6409 | goto send_request; |
| 6410 | } |
| 6411 | |
| 6412 | /* Use active scan by default. */ |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6413 | if (priv->config & CFG_SPEED_SCAN) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6414 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6415 | cpu_to_le16(30); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6416 | else |
| 6417 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6418 | cpu_to_le16(20); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6419 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6420 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6421 | cpu_to_le16(20); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6422 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6423 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
| 6424 | cpu_to_le16(ipw_passive_dwell_time(priv)); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6425 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6426 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6427 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6428 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6429 | u8 channel; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6430 | u8 band = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6431 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6432 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 6433 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6434 | band = (u8) (IPW_A_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6435 | channel = priv->channel; |
| 6436 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6437 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6438 | case LIBIPW_24GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6439 | band = (u8) (IPW_B_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6440 | channel = priv->channel; |
| 6441 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6442 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6443 | default: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6444 | band = (u8) (IPW_B_MODE << 6) | 1; |
| 6445 | channel = 9; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6446 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6447 | } |
| 6448 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6449 | scan.channels_list[0] = band; |
| 6450 | scan.channels_list[1] = channel; |
| 6451 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6452 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6453 | /* NOTE: The card will sit on this channel for this time |
| 6454 | * period. Scan aborts are timing sensitive and frequently |
| 6455 | * result in firmware restarts. As such, it is best to |
| 6456 | * set a small dwell_time here and just keep re-issuing |
| 6457 | * scans. Otherwise fast channel hopping will not actually |
| 6458 | * hop channels. |
| 6459 | * |
| 6460 | * TODO: Move SPEED SCAN support to all modes and bands */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6461 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6462 | cpu_to_le16(2000); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6463 | } else { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6464 | #endif /* CONFIG_IPW2200_MONITOR */ |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6465 | /* Honor direct scans first, otherwise if we are roaming make |
| 6466 | * this a direct scan for the current network. Finally, |
| 6467 | * ensure that every other scan is a fast channel hop scan */ |
| 6468 | if (direct) { |
| 6469 | err = ipw_send_ssid(priv, priv->direct_scan_ssid, |
| 6470 | priv->direct_scan_ssid_len); |
| 6471 | if (err) { |
| 6472 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6473 | "failed\n"); |
| 6474 | goto done; |
| 6475 | } |
| 6476 | |
| 6477 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
| 6478 | } else if ((priv->status & STATUS_ROAMING) |
| 6479 | || (!(priv->status & STATUS_ASSOCIATED) |
| 6480 | && (priv->config & CFG_STATIC_ESSID) |
| 6481 | && (le32_to_cpu(scan.full_scan_index) % 2))) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6482 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 6483 | if (err) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6484 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6485 | "failed.\n"); |
| 6486 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6490 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6491 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6492 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6493 | ipw_add_scan_channels(priv, &scan, scan_type); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6494 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6495 | } |
| 6496 | #endif |
| 6497 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6498 | send_request: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6499 | err = ipw_send_scan_request_ext(priv, &scan); |
| 6500 | if (err) { |
| 6501 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6502 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6503 | } |
| 6504 | |
| 6505 | priv->status |= STATUS_SCANNING; |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6506 | if (direct) { |
| 6507 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; |
| 6508 | priv->direct_scan_ssid_len = 0; |
| 6509 | } else |
| 6510 | priv->status &= ~STATUS_SCAN_PENDING; |
| 6511 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6512 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6513 | IPW_SCAN_CHECK_WATCHDOG); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6514 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6515 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6516 | return err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6517 | } |
| 6518 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6519 | static void ipw_request_passive_scan(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6520 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6521 | struct ipw_priv *priv = |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6522 | container_of(work, struct ipw_priv, request_passive_scan.work); |
| 6523 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6524 | } |
| 6525 | |
| 6526 | static void ipw_request_scan(struct work_struct *work) |
| 6527 | { |
| 6528 | struct ipw_priv *priv = |
| 6529 | container_of(work, struct ipw_priv, request_scan.work); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6530 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0); |
| 6531 | } |
| 6532 | |
| 6533 | static void ipw_request_direct_scan(struct work_struct *work) |
| 6534 | { |
| 6535 | struct ipw_priv *priv = |
| 6536 | container_of(work, struct ipw_priv, request_direct_scan.work); |
| 6537 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | static void ipw_bg_abort_scan(struct work_struct *work) |
| 6541 | { |
| 6542 | struct ipw_priv *priv = |
| 6543 | container_of(work, struct ipw_priv, abort_scan); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6544 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6545 | ipw_abort_scan(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6546 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6547 | } |
| 6548 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6549 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
| 6550 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6551 | /* This is called when wpa_supplicant loads and closes the driver |
| 6552 | * interface. */ |
Hong Liu | cdd1fa1 | 2005-08-31 18:14:27 +0800 | [diff] [blame] | 6553 | priv->ieee->wpa_enabled = value; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6554 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6555 | } |
| 6556 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6557 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
| 6558 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6559 | struct libipw_device *ieee = priv->ieee; |
| 6560 | struct libipw_security sec = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6561 | .flags = SEC_AUTH_MODE, |
| 6562 | }; |
| 6563 | int ret = 0; |
| 6564 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6565 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6566 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
| 6567 | ieee->open_wep = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6568 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6569 | sec.auth_mode = WLAN_AUTH_OPEN; |
| 6570 | ieee->open_wep = 1; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 6571 | } else if (value & IW_AUTH_ALG_LEAP) { |
| 6572 | sec.auth_mode = WLAN_AUTH_LEAP; |
| 6573 | ieee->open_wep = 1; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6574 | } else |
| 6575 | return -EINVAL; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6576 | |
| 6577 | if (ieee->set_security) |
| 6578 | ieee->set_security(ieee->dev, &sec); |
| 6579 | else |
| 6580 | ret = -EOPNOTSUPP; |
| 6581 | |
| 6582 | return ret; |
| 6583 | } |
| 6584 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 6585 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
| 6586 | int wpa_ie_len) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6587 | { |
| 6588 | /* make sure WPA is enabled */ |
| 6589 | ipw_wpa_enable(priv, 1); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6590 | } |
| 6591 | |
| 6592 | static int ipw_set_rsn_capa(struct ipw_priv *priv, |
| 6593 | char *capabilities, int length) |
| 6594 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6595 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
| 6596 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6597 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 6598 | capabilities); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6599 | } |
| 6600 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6601 | /* |
| 6602 | * WE-18 support |
| 6603 | */ |
| 6604 | |
| 6605 | /* SIOCSIWGENIE */ |
| 6606 | static int ipw_wx_set_genie(struct net_device *dev, |
| 6607 | struct iw_request_info *info, |
| 6608 | union iwreq_data *wrqu, char *extra) |
| 6609 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6610 | struct ipw_priv *priv = libipw_priv(dev); |
| 6611 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6612 | u8 *buf; |
| 6613 | int err = 0; |
| 6614 | |
| 6615 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
| 6616 | (wrqu->data.length && extra == NULL)) |
| 6617 | return -EINVAL; |
| 6618 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6619 | if (wrqu->data.length) { |
| 6620 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 6621 | if (buf == NULL) { |
| 6622 | err = -ENOMEM; |
| 6623 | goto out; |
| 6624 | } |
| 6625 | |
| 6626 | memcpy(buf, extra, wrqu->data.length); |
| 6627 | kfree(ieee->wpa_ie); |
| 6628 | ieee->wpa_ie = buf; |
| 6629 | ieee->wpa_ie_len = wrqu->data.length; |
| 6630 | } else { |
| 6631 | kfree(ieee->wpa_ie); |
| 6632 | ieee->wpa_ie = NULL; |
| 6633 | ieee->wpa_ie_len = 0; |
| 6634 | } |
| 6635 | |
| 6636 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6637 | out: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6638 | return err; |
| 6639 | } |
| 6640 | |
| 6641 | /* SIOCGIWGENIE */ |
| 6642 | static int ipw_wx_get_genie(struct net_device *dev, |
| 6643 | struct iw_request_info *info, |
| 6644 | union iwreq_data *wrqu, char *extra) |
| 6645 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6646 | struct ipw_priv *priv = libipw_priv(dev); |
| 6647 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6648 | int err = 0; |
| 6649 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6650 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
| 6651 | wrqu->data.length = 0; |
| 6652 | goto out; |
| 6653 | } |
| 6654 | |
| 6655 | if (wrqu->data.length < ieee->wpa_ie_len) { |
| 6656 | err = -E2BIG; |
| 6657 | goto out; |
| 6658 | } |
| 6659 | |
| 6660 | wrqu->data.length = ieee->wpa_ie_len; |
| 6661 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6662 | |
| 6663 | out: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6664 | return err; |
| 6665 | } |
| 6666 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6667 | static int wext_cipher2level(int cipher) |
| 6668 | { |
| 6669 | switch (cipher) { |
| 6670 | case IW_AUTH_CIPHER_NONE: |
| 6671 | return SEC_LEVEL_0; |
| 6672 | case IW_AUTH_CIPHER_WEP40: |
| 6673 | case IW_AUTH_CIPHER_WEP104: |
| 6674 | return SEC_LEVEL_1; |
| 6675 | case IW_AUTH_CIPHER_TKIP: |
| 6676 | return SEC_LEVEL_2; |
| 6677 | case IW_AUTH_CIPHER_CCMP: |
| 6678 | return SEC_LEVEL_3; |
| 6679 | default: |
| 6680 | return -1; |
| 6681 | } |
| 6682 | } |
| 6683 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6684 | /* SIOCSIWAUTH */ |
| 6685 | static int ipw_wx_set_auth(struct net_device *dev, |
| 6686 | struct iw_request_info *info, |
| 6687 | union iwreq_data *wrqu, char *extra) |
| 6688 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6689 | struct ipw_priv *priv = libipw_priv(dev); |
| 6690 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6691 | struct iw_param *param = &wrqu->param; |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6692 | struct lib80211_crypt_data *crypt; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6693 | unsigned long flags; |
| 6694 | int ret = 0; |
| 6695 | |
| 6696 | switch (param->flags & IW_AUTH_INDEX) { |
| 6697 | case IW_AUTH_WPA_VERSION: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6698 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6699 | case IW_AUTH_CIPHER_PAIRWISE: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6700 | ipw_set_hw_decrypt_unicast(priv, |
| 6701 | wext_cipher2level(param->value)); |
| 6702 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6703 | case IW_AUTH_CIPHER_GROUP: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6704 | ipw_set_hw_decrypt_multicast(priv, |
| 6705 | wext_cipher2level(param->value)); |
| 6706 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6707 | case IW_AUTH_KEY_MGMT: |
| 6708 | /* |
| 6709 | * ipw2200 does not use these parameters |
| 6710 | */ |
| 6711 | break; |
| 6712 | |
| 6713 | case IW_AUTH_TKIP_COUNTERMEASURES: |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6714 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6715 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6716 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6717 | |
| 6718 | flags = crypt->ops->get_flags(crypt->priv); |
| 6719 | |
| 6720 | if (param->value) |
| 6721 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6722 | else |
| 6723 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6724 | |
| 6725 | crypt->ops->set_flags(flags, crypt->priv); |
| 6726 | |
| 6727 | break; |
| 6728 | |
| 6729 | case IW_AUTH_DROP_UNENCRYPTED:{ |
| 6730 | /* HACK: |
| 6731 | * |
| 6732 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6733 | * is loaded and unloaded, regardless of if WPA is being |
| 6734 | * used. No other calls are made which can be used to |
| 6735 | * determine if encryption will be used or not prior to |
| 6736 | * association being expected. If encryption is not being |
| 6737 | * used, drop_unencrypted is set to false, else true -- we |
| 6738 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6739 | * be set. |
| 6740 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6741 | struct libipw_security sec = { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6742 | .flags = SEC_ENABLED, |
| 6743 | .enabled = param->value, |
| 6744 | }; |
| 6745 | priv->ieee->drop_unencrypted = param->value; |
| 6746 | /* We only change SEC_LEVEL for open mode. Others |
| 6747 | * are set by ipw_wpa_set_encryption. |
| 6748 | */ |
| 6749 | if (!param->value) { |
| 6750 | sec.flags |= SEC_LEVEL; |
| 6751 | sec.level = SEC_LEVEL_0; |
| 6752 | } else { |
| 6753 | sec.flags |= SEC_LEVEL; |
| 6754 | sec.level = SEC_LEVEL_1; |
| 6755 | } |
| 6756 | if (priv->ieee->set_security) |
| 6757 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6758 | break; |
| 6759 | } |
| 6760 | |
| 6761 | case IW_AUTH_80211_AUTH_ALG: |
| 6762 | ret = ipw_wpa_set_auth_algs(priv, param->value); |
| 6763 | break; |
| 6764 | |
| 6765 | case IW_AUTH_WPA_ENABLED: |
| 6766 | ret = ipw_wpa_enable(priv, param->value); |
Zhu Yi | e3c5a64 | 2006-04-13 17:21:13 +0800 | [diff] [blame] | 6767 | ipw_disassociate(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6768 | break; |
| 6769 | |
| 6770 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6771 | ieee->ieee802_1x = param->value; |
| 6772 | break; |
| 6773 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6774 | case IW_AUTH_PRIVACY_INVOKED: |
| 6775 | ieee->privacy_invoked = param->value; |
| 6776 | break; |
| 6777 | |
| 6778 | default: |
| 6779 | return -EOPNOTSUPP; |
| 6780 | } |
| 6781 | return ret; |
| 6782 | } |
| 6783 | |
| 6784 | /* SIOCGIWAUTH */ |
| 6785 | static int ipw_wx_get_auth(struct net_device *dev, |
| 6786 | struct iw_request_info *info, |
| 6787 | union iwreq_data *wrqu, char *extra) |
| 6788 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6789 | struct ipw_priv *priv = libipw_priv(dev); |
| 6790 | struct libipw_device *ieee = priv->ieee; |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6791 | struct lib80211_crypt_data *crypt; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6792 | struct iw_param *param = &wrqu->param; |
| 6793 | int ret = 0; |
| 6794 | |
| 6795 | switch (param->flags & IW_AUTH_INDEX) { |
| 6796 | case IW_AUTH_WPA_VERSION: |
| 6797 | case IW_AUTH_CIPHER_PAIRWISE: |
| 6798 | case IW_AUTH_CIPHER_GROUP: |
| 6799 | case IW_AUTH_KEY_MGMT: |
| 6800 | /* |
| 6801 | * wpa_supplicant will control these internally |
| 6802 | */ |
| 6803 | ret = -EOPNOTSUPP; |
| 6804 | break; |
| 6805 | |
| 6806 | case IW_AUTH_TKIP_COUNTERMEASURES: |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6807 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6808 | if (!crypt || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6809 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6810 | |
| 6811 | param->value = (crypt->ops->get_flags(crypt->priv) & |
| 6812 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; |
| 6813 | |
| 6814 | break; |
| 6815 | |
| 6816 | case IW_AUTH_DROP_UNENCRYPTED: |
| 6817 | param->value = ieee->drop_unencrypted; |
| 6818 | break; |
| 6819 | |
| 6820 | case IW_AUTH_80211_AUTH_ALG: |
| 6821 | param->value = ieee->sec.auth_mode; |
| 6822 | break; |
| 6823 | |
| 6824 | case IW_AUTH_WPA_ENABLED: |
| 6825 | param->value = ieee->wpa_enabled; |
| 6826 | break; |
| 6827 | |
| 6828 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6829 | param->value = ieee->ieee802_1x; |
| 6830 | break; |
| 6831 | |
| 6832 | case IW_AUTH_ROAMING_CONTROL: |
| 6833 | case IW_AUTH_PRIVACY_INVOKED: |
| 6834 | param->value = ieee->privacy_invoked; |
| 6835 | break; |
| 6836 | |
| 6837 | default: |
| 6838 | return -EOPNOTSUPP; |
| 6839 | } |
| 6840 | return 0; |
| 6841 | } |
| 6842 | |
| 6843 | /* SIOCSIWENCODEEXT */ |
| 6844 | static int ipw_wx_set_encodeext(struct net_device *dev, |
| 6845 | struct iw_request_info *info, |
| 6846 | union iwreq_data *wrqu, char *extra) |
| 6847 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6848 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6849 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 6850 | |
| 6851 | if (hwcrypto) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6852 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6853 | /* IPW HW can't build TKIP MIC, |
| 6854 | host decryption still needed */ |
| 6855 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) |
| 6856 | priv->ieee->host_mc_decrypt = 1; |
| 6857 | else { |
| 6858 | priv->ieee->host_encrypt = 0; |
| 6859 | priv->ieee->host_encrypt_msdu = 1; |
| 6860 | priv->ieee->host_decrypt = 1; |
| 6861 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6862 | } else { |
| 6863 | priv->ieee->host_encrypt = 0; |
| 6864 | priv->ieee->host_encrypt_msdu = 0; |
| 6865 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6866 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6867 | } |
| 6868 | } |
| 6869 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6870 | return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6871 | } |
| 6872 | |
| 6873 | /* SIOCGIWENCODEEXT */ |
| 6874 | static int ipw_wx_get_encodeext(struct net_device *dev, |
| 6875 | struct iw_request_info *info, |
| 6876 | union iwreq_data *wrqu, char *extra) |
| 6877 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6878 | struct ipw_priv *priv = libipw_priv(dev); |
| 6879 | return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6880 | } |
| 6881 | |
| 6882 | /* SIOCSIWMLME */ |
| 6883 | static int ipw_wx_set_mlme(struct net_device *dev, |
| 6884 | struct iw_request_info *info, |
| 6885 | union iwreq_data *wrqu, char *extra) |
| 6886 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6887 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6888 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 6889 | __le16 reason; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6890 | |
| 6891 | reason = cpu_to_le16(mlme->reason_code); |
| 6892 | |
| 6893 | switch (mlme->cmd) { |
| 6894 | case IW_MLME_DEAUTH: |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 6895 | /* silently ignore */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6896 | break; |
| 6897 | |
| 6898 | case IW_MLME_DISASSOC: |
| 6899 | ipw_disassociate(priv); |
| 6900 | break; |
| 6901 | |
| 6902 | default: |
| 6903 | return -EOPNOTSUPP; |
| 6904 | } |
| 6905 | return 0; |
| 6906 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6907 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 6908 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6909 | |
| 6910 | /* QoS */ |
| 6911 | /* |
| 6912 | * get the modulation type of the current network or |
| 6913 | * the card current mode |
| 6914 | */ |
Adrian Bunk | 53d0bcf | 2006-03-04 13:14:31 +0100 | [diff] [blame] | 6915 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6916 | { |
| 6917 | u8 mode = 0; |
| 6918 | |
| 6919 | if (priv->status & STATUS_ASSOCIATED) { |
| 6920 | unsigned long flags; |
| 6921 | |
| 6922 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6923 | mode = priv->assoc_network->mode; |
| 6924 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6925 | } else { |
| 6926 | mode = priv->ieee->mode; |
| 6927 | } |
| 6928 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); |
| 6929 | return mode; |
| 6930 | } |
| 6931 | |
| 6932 | /* |
| 6933 | * Handle management frame beacon and probe response |
| 6934 | */ |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6935 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
| 6936 | int active_network, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6937 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6938 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6939 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6940 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6941 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6942 | network->qos_data.active = network->qos_data.supported; |
| 6943 | |
| 6944 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6945 | if (active_network && |
| 6946 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6947 | network->qos_data.active = network->qos_data.supported; |
| 6948 | |
| 6949 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 6950 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 6951 | (network->qos_data.old_param_count != |
| 6952 | network->qos_data.param_count)) { |
| 6953 | network->qos_data.old_param_count = |
| 6954 | network->qos_data.param_count; |
| 6955 | schedule_work(&priv->qos_activate); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6956 | IPW_DEBUG_QOS("QoS parameters change call " |
| 6957 | "qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6958 | } |
| 6959 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6960 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
| 6961 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6962 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6963 | else |
| 6964 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6965 | &def_parameters_OFDM, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6966 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6967 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
| 6968 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); |
| 6969 | schedule_work(&priv->qos_activate); |
| 6970 | } |
| 6971 | |
| 6972 | network->qos_data.active = 0; |
| 6973 | network->qos_data.supported = 0; |
| 6974 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6975 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6976 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { |
| 6977 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) |
John W. Linville | c5d3dce | 2008-09-30 17:17:26 -0400 | [diff] [blame] | 6978 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6979 | if ((network->ssid_len == |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6980 | priv->assoc_network->ssid_len) && |
| 6981 | !memcmp(network->ssid, |
| 6982 | priv->assoc_network->ssid, |
| 6983 | network->ssid_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6984 | queue_work(priv->workqueue, |
| 6985 | &priv->merge_networks); |
| 6986 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6987 | } |
| 6988 | |
| 6989 | return 0; |
| 6990 | } |
| 6991 | |
| 6992 | /* |
| 6993 | * This function set up the firmware to support QoS. It sends |
| 6994 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO |
| 6995 | */ |
| 6996 | static int ipw_qos_activate(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6997 | struct libipw_qos_data *qos_network_data) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6998 | { |
| 6999 | int err; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7000 | struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS]; |
| 7001 | struct libipw_qos_parameters *active_one = NULL; |
| 7002 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7003 | u32 burst_duration; |
| 7004 | int i; |
| 7005 | u8 type; |
| 7006 | |
| 7007 | type = ipw_qos_current_mode(priv); |
| 7008 | |
| 7009 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); |
| 7010 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); |
| 7011 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); |
| 7012 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); |
| 7013 | |
| 7014 | if (qos_network_data == NULL) { |
| 7015 | if (type == IEEE_B) { |
| 7016 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); |
| 7017 | active_one = &def_parameters_CCK; |
| 7018 | } else |
| 7019 | active_one = &def_parameters_OFDM; |
| 7020 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7021 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7022 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 7023 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7024 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 7025 | cpu_to_le16(burst_duration); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7026 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7027 | if (type == IEEE_B) { |
| 7028 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", |
| 7029 | type); |
| 7030 | if (priv->qos_data.qos_enable == 0) |
| 7031 | active_one = &def_parameters_CCK; |
| 7032 | else |
| 7033 | active_one = priv->qos_data.def_qos_parm_CCK; |
| 7034 | } else { |
| 7035 | if (priv->qos_data.qos_enable == 0) |
| 7036 | active_one = &def_parameters_OFDM; |
| 7037 | else |
| 7038 | active_one = priv->qos_data.def_qos_parm_OFDM; |
| 7039 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7040 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7041 | } else { |
| 7042 | unsigned long flags; |
| 7043 | int active; |
| 7044 | |
| 7045 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7046 | active_one = &(qos_network_data->parameters); |
| 7047 | qos_network_data->old_param_count = |
| 7048 | qos_network_data->param_count; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7049 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7050 | active = qos_network_data->supported; |
| 7051 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7052 | |
| 7053 | if (active == 0) { |
| 7054 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 7055 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
| 7056 | qos_parameters[QOS_PARAM_SET_ACTIVE]. |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 7057 | tx_op_limit[i] = cpu_to_le16(burst_duration); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7058 | } |
| 7059 | } |
| 7060 | |
| 7061 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7062 | err = ipw_send_qos_params_command(priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7063 | (struct libipw_qos_parameters *) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7064 | &(qos_parameters[0])); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7065 | if (err) |
| 7066 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); |
| 7067 | |
| 7068 | return err; |
| 7069 | } |
| 7070 | |
| 7071 | /* |
| 7072 | * send IPW_CMD_WME_INFO to the firmware |
| 7073 | */ |
| 7074 | static int ipw_qos_set_info_element(struct ipw_priv *priv) |
| 7075 | { |
| 7076 | int ret = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7077 | struct libipw_qos_information_element qos_info; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7078 | |
| 7079 | if (priv == NULL) |
| 7080 | return -1; |
| 7081 | |
| 7082 | qos_info.elementID = QOS_ELEMENT_ID; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7083 | qos_info.length = sizeof(struct libipw_qos_information_element) - 2; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7084 | |
| 7085 | qos_info.version = QOS_VERSION_1; |
| 7086 | qos_info.ac_info = 0; |
| 7087 | |
| 7088 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); |
| 7089 | qos_info.qui_type = QOS_OUI_TYPE; |
| 7090 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; |
| 7091 | |
| 7092 | ret = ipw_send_qos_info_command(priv, &qos_info); |
| 7093 | if (ret != 0) { |
| 7094 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); |
| 7095 | } |
| 7096 | return ret; |
| 7097 | } |
| 7098 | |
| 7099 | /* |
| 7100 | * Set the QoS parameter with the association request structure |
| 7101 | */ |
| 7102 | static int ipw_qos_association(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7103 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7104 | { |
| 7105 | int err = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7106 | struct libipw_qos_data *qos_data = NULL; |
| 7107 | struct libipw_qos_data ibss_data = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7108 | .supported = 1, |
| 7109 | .active = 1, |
| 7110 | }; |
| 7111 | |
| 7112 | switch (priv->ieee->iw_mode) { |
| 7113 | case IW_MODE_ADHOC: |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 7114 | BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7115 | |
| 7116 | qos_data = &ibss_data; |
| 7117 | break; |
| 7118 | |
| 7119 | case IW_MODE_INFRA: |
| 7120 | qos_data = &network->qos_data; |
| 7121 | break; |
| 7122 | |
| 7123 | default: |
| 7124 | BUG(); |
| 7125 | break; |
| 7126 | } |
| 7127 | |
| 7128 | err = ipw_qos_activate(priv, qos_data); |
| 7129 | if (err) { |
| 7130 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; |
| 7131 | return err; |
| 7132 | } |
| 7133 | |
| 7134 | if (priv->qos_data.qos_enable && qos_data->supported) { |
| 7135 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); |
| 7136 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; |
| 7137 | return ipw_qos_set_info_element(priv); |
| 7138 | } |
| 7139 | |
| 7140 | return 0; |
| 7141 | } |
| 7142 | |
| 7143 | /* |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 7144 | * handling the beaconing responses. if we get different QoS setting |
| 7145 | * off the network from the associated setting, adjust the QoS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7146 | * setting |
| 7147 | */ |
| 7148 | static int ipw_qos_association_resp(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7149 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7150 | { |
| 7151 | int ret = 0; |
| 7152 | unsigned long flags; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7153 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7154 | int set_qos_param = 0; |
| 7155 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7156 | if ((priv == NULL) || (network == NULL) || |
| 7157 | (priv->assoc_network == NULL)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7158 | return ret; |
| 7159 | |
| 7160 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7161 | return ret; |
| 7162 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7163 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7164 | return ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7165 | |
| 7166 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7167 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7168 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7169 | sizeof(struct libipw_qos_data)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7170 | priv->assoc_network->qos_data.active = 1; |
| 7171 | if ((network->qos_data.old_param_count != |
| 7172 | network->qos_data.param_count)) { |
| 7173 | set_qos_param = 1; |
| 7174 | network->qos_data.old_param_count = |
| 7175 | network->qos_data.param_count; |
| 7176 | } |
| 7177 | |
| 7178 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7179 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
| 7180 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7181 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7182 | else |
| 7183 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7184 | &def_parameters_OFDM, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7185 | priv->assoc_network->qos_data.active = 0; |
| 7186 | priv->assoc_network->qos_data.supported = 0; |
| 7187 | set_qos_param = 1; |
| 7188 | } |
| 7189 | |
| 7190 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7191 | |
| 7192 | if (set_qos_param == 1) |
| 7193 | schedule_work(&priv->qos_activate); |
| 7194 | |
| 7195 | return ret; |
| 7196 | } |
| 7197 | |
| 7198 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) |
| 7199 | { |
| 7200 | u32 ret = 0; |
| 7201 | |
| 7202 | if ((priv == NULL)) |
| 7203 | return 0; |
| 7204 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7205 | if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7206 | ret = priv->qos_data.burst_duration_CCK; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7207 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7208 | ret = priv->qos_data.burst_duration_OFDM; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7209 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7210 | return ret; |
| 7211 | } |
| 7212 | |
| 7213 | /* |
| 7214 | * Initialize the setting of QoS global |
| 7215 | */ |
| 7216 | static void ipw_qos_init(struct ipw_priv *priv, int enable, |
| 7217 | int burst_enable, u32 burst_duration_CCK, |
| 7218 | u32 burst_duration_OFDM) |
| 7219 | { |
| 7220 | priv->qos_data.qos_enable = enable; |
| 7221 | |
| 7222 | if (priv->qos_data.qos_enable) { |
| 7223 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; |
| 7224 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; |
| 7225 | IPW_DEBUG_QOS("QoS is enabled\n"); |
| 7226 | } else { |
| 7227 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; |
| 7228 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; |
| 7229 | IPW_DEBUG_QOS("QoS is not enabled\n"); |
| 7230 | } |
| 7231 | |
| 7232 | priv->qos_data.burst_enable = burst_enable; |
| 7233 | |
| 7234 | if (burst_enable) { |
| 7235 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; |
| 7236 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; |
| 7237 | } else { |
| 7238 | priv->qos_data.burst_duration_CCK = 0; |
| 7239 | priv->qos_data.burst_duration_OFDM = 0; |
| 7240 | } |
| 7241 | } |
| 7242 | |
| 7243 | /* |
| 7244 | * map the packet priority to the right TX Queue |
| 7245 | */ |
| 7246 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) |
| 7247 | { |
| 7248 | if (priority > 7 || !priv->qos_data.qos_enable) |
| 7249 | priority = 0; |
| 7250 | |
| 7251 | return from_priority_to_tx_queue[priority] - 1; |
| 7252 | } |
| 7253 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7254 | static int ipw_is_qos_active(struct net_device *dev, |
| 7255 | struct sk_buff *skb) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7256 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7257 | struct ipw_priv *priv = libipw_priv(dev); |
| 7258 | struct libipw_qos_data *qos_data = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7259 | int active, supported; |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7260 | u8 *daddr = skb->data + ETH_ALEN; |
| 7261 | int unicast = !is_multicast_ether_addr(daddr); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7262 | |
| 7263 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7264 | return 0; |
| 7265 | |
| 7266 | qos_data = &priv->assoc_network->qos_data; |
| 7267 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7268 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7269 | if (unicast == 0) |
| 7270 | qos_data->active = 0; |
| 7271 | else |
| 7272 | qos_data->active = qos_data->supported; |
| 7273 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7274 | active = qos_data->active; |
| 7275 | supported = qos_data->supported; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7276 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
| 7277 | "unicast %d\n", |
| 7278 | priv->qos_data.qos_enable, active, supported, unicast); |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7279 | if (active && priv->qos_data.qos_enable) |
| 7280 | return 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7281 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7282 | return 0; |
| 7283 | |
| 7284 | } |
| 7285 | /* |
| 7286 | * add QoS parameter to the TX command |
| 7287 | */ |
| 7288 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, |
| 7289 | u16 priority, |
| 7290 | struct tfd_data *tfd) |
| 7291 | { |
| 7292 | int tx_queue_id = 0; |
| 7293 | |
| 7294 | |
| 7295 | tx_queue_id = from_priority_to_tx_queue[priority] - 1; |
| 7296 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; |
| 7297 | |
| 7298 | if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) { |
| 7299 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 7300 | 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] | 7301 | } |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7302 | return 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7303 | } |
| 7304 | |
| 7305 | /* |
| 7306 | * background support to run QoS activate functionality |
| 7307 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7308 | static void ipw_bg_qos_activate(struct work_struct *work) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7309 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7310 | struct ipw_priv *priv = |
| 7311 | container_of(work, struct ipw_priv, qos_activate); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7312 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7313 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7314 | |
| 7315 | if (priv->status & STATUS_ASSOCIATED) |
| 7316 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); |
| 7317 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7318 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7319 | } |
| 7320 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7321 | static int ipw_handle_probe_response(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7322 | struct libipw_probe_response *resp, |
| 7323 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7324 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7325 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7326 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7327 | (network == priv->assoc_network)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7328 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7329 | ipw_qos_handle_probe_response(priv, active_network, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7330 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7331 | return 0; |
| 7332 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7333 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7334 | static int ipw_handle_beacon(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7335 | struct libipw_beacon *resp, |
| 7336 | struct libipw_network *network) |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7337 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7338 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7339 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7340 | (network == priv->assoc_network)); |
| 7341 | |
| 7342 | ipw_qos_handle_probe_response(priv, active_network, network); |
| 7343 | |
| 7344 | return 0; |
| 7345 | } |
| 7346 | |
| 7347 | static int ipw_handle_assoc_response(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7348 | struct libipw_assoc_response *resp, |
| 7349 | struct libipw_network *network) |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7350 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7351 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7352 | ipw_qos_association_resp(priv, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7353 | return 0; |
| 7354 | } |
| 7355 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7356 | 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] | 7357 | *qos_param) |
| 7358 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7359 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
| 7360 | sizeof(*qos_param) * 3, qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7361 | } |
| 7362 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7363 | 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] | 7364 | *qos_param) |
| 7365 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7366 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
| 7367 | qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7368 | } |
| 7369 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7370 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7371 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7372 | static int ipw_associate_network(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7373 | struct libipw_network *network, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7374 | struct ipw_supported_rates *rates, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7375 | { |
| 7376 | int err; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7377 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7378 | |
| 7379 | if (priv->config & CFG_FIXED_RATE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7380 | ipw_set_fixed_rate(priv, network->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7381 | |
| 7382 | if (!(priv->config & CFG_STATIC_ESSID)) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7383 | priv->essid_len = min(network->ssid_len, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7384 | (u8) IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7385 | memcpy(priv->essid, network->ssid, priv->essid_len); |
| 7386 | } |
| 7387 | |
| 7388 | network->last_associate = jiffies; |
| 7389 | |
| 7390 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); |
| 7391 | priv->assoc_request.channel = network->channel; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7392 | priv->assoc_request.auth_key = 0; |
| 7393 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7394 | if ((priv->capability & CAP_PRIVACY_ON) && |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7395 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7396 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7397 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
| 7398 | |
Zhu Yi | 1ba61e0 | 2006-02-15 13:00:55 +0800 | [diff] [blame] | 7399 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7400 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7401 | |
| 7402 | } else if ((priv->capability & CAP_PRIVACY_ON) && |
| 7403 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) |
| 7404 | priv->assoc_request.auth_type = AUTH_LEAP; |
| 7405 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7406 | priv->assoc_request.auth_type = AUTH_OPEN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7407 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7408 | if (priv->ieee->wpa_ie_len) { |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7409 | priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7410 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
| 7411 | priv->ieee->wpa_ie_len); |
| 7412 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7413 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7414 | /* |
| 7415 | * It is valid for our ieee device to support multiple modes, but |
| 7416 | * 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] | 7417 | * just one mode. |
| 7418 | */ |
| 7419 | if (network->mode & priv->ieee->mode & IEEE_A) |
| 7420 | priv->assoc_request.ieee_mode = IPW_A_MODE; |
| 7421 | else if (network->mode & priv->ieee->mode & IEEE_G) |
| 7422 | priv->assoc_request.ieee_mode = IPW_G_MODE; |
| 7423 | else if (network->mode & priv->ieee->mode & IEEE_B) |
| 7424 | priv->assoc_request.ieee_mode = IPW_B_MODE; |
| 7425 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7426 | priv->assoc_request.capability = cpu_to_le16(network->capability); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7427 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7428 | && !(priv->config & CFG_PREAMBLE_LONG)) { |
| 7429 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; |
| 7430 | } else { |
| 7431 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; |
| 7432 | |
| 7433 | /* Clear the short preamble if we won't be supporting it */ |
| 7434 | priv->assoc_request.capability &= |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7435 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7436 | } |
| 7437 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7438 | /* Clear capability bits that aren't used in Ad Hoc */ |
| 7439 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7440 | priv->assoc_request.capability &= |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7441 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7442 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7443 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7444 | "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] | 7445 | roaming ? "Rea" : "A", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7446 | print_ssid(ssid, priv->essid, priv->essid_len), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7447 | network->channel, |
| 7448 | ipw_modes[priv->assoc_request.ieee_mode], |
| 7449 | rates->num_rates, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7450 | (priv->assoc_request.preamble_length == |
| 7451 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", |
| 7452 | network->capability & |
| 7453 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7454 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7455 | priv->capability & CAP_PRIVACY_ON ? |
| 7456 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7457 | "(open)") : "", |
| 7458 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7459 | priv->capability & CAP_PRIVACY_ON ? |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7460 | '1' + priv->ieee->sec.active_key : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7461 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7462 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7463 | priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7464 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7465 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7466 | priv->assoc_request.assoc_type = HC_IBSS_START; |
| 7467 | priv->assoc_request.assoc_tsf_msw = 0; |
| 7468 | priv->assoc_request.assoc_tsf_lsw = 0; |
| 7469 | } else { |
| 7470 | if (unlikely(roaming)) |
| 7471 | priv->assoc_request.assoc_type = HC_REASSOCIATE; |
| 7472 | else |
| 7473 | priv->assoc_request.assoc_type = HC_ASSOCIATE; |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7474 | priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]); |
| 7475 | 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] | 7476 | } |
| 7477 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7478 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7479 | |
| 7480 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7481 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7482 | priv->assoc_request.atim_window = cpu_to_le16(network->atim_window); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7483 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7484 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7485 | priv->assoc_request.atim_window = 0; |
| 7486 | } |
| 7487 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7488 | priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7489 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7490 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 7491 | if (err) { |
| 7492 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); |
| 7493 | return err; |
| 7494 | } |
| 7495 | |
| 7496 | rates->ieee_mode = priv->assoc_request.ieee_mode; |
| 7497 | rates->purpose = IPW_RATE_CONNECT; |
| 7498 | ipw_send_supported_rates(priv, rates); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7499 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7500 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
| 7501 | priv->sys_config.dot11g_auto_detection = 1; |
| 7502 | else |
| 7503 | priv->sys_config.dot11g_auto_detection = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7504 | |
| 7505 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7506 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 7507 | else |
| 7508 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 7509 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7510 | err = ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7511 | if (err) { |
| 7512 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); |
| 7513 | return err; |
| 7514 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7515 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7516 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7517 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7518 | if (err) { |
| 7519 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7520 | return err; |
| 7521 | } |
| 7522 | |
| 7523 | /* |
| 7524 | * If preemption is enabled, it is possible for the association |
| 7525 | * to complete before we return from ipw_send_associate. Therefore |
| 7526 | * we have to be sure and update our priviate data first. |
| 7527 | */ |
| 7528 | priv->channel = network->channel; |
| 7529 | memcpy(priv->bssid, network->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7530 | priv->status |= STATUS_ASSOCIATING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7531 | priv->status &= ~STATUS_SECURITY_UPDATED; |
| 7532 | |
| 7533 | priv->assoc_network = network; |
| 7534 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7535 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7536 | ipw_qos_association(priv, network); |
| 7537 | #endif |
| 7538 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7539 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 7540 | if (err) { |
| 7541 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7542 | return err; |
| 7543 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7544 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7545 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM \n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7546 | print_ssid(ssid, priv->essid, priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7547 | priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7548 | |
| 7549 | return 0; |
| 7550 | } |
| 7551 | |
| 7552 | static void ipw_roam(void *data) |
| 7553 | { |
| 7554 | struct ipw_priv *priv = data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7555 | struct libipw_network *network = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7556 | struct ipw_network_match match = { |
| 7557 | .network = priv->assoc_network |
| 7558 | }; |
| 7559 | |
| 7560 | /* The roaming process is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7561 | * |
| 7562 | * 1. Missed beacon threshold triggers the roaming process by |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7563 | * setting the status ROAM bit and requesting a scan. |
| 7564 | * 2. When the scan completes, it schedules the ROAM work |
| 7565 | * 3. The ROAM work looks at all of the known networks for one that |
| 7566 | * is a better network than the currently associated. If none |
| 7567 | * found, the ROAM process is over (ROAM bit cleared) |
| 7568 | * 4. If a better network is found, a disassociation request is |
| 7569 | * sent. |
| 7570 | * 5. When the disassociation completes, the roam work is again |
| 7571 | * scheduled. The second time through, the driver is no longer |
| 7572 | * associated, and the newly selected network is sent an |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7573 | * association request. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7574 | * 6. At this point ,the roaming process is complete and the ROAM |
| 7575 | * status bit is cleared. |
| 7576 | */ |
| 7577 | |
| 7578 | /* If we are no longer associated, and the roaming bit is no longer |
| 7579 | * set, then we are not actively roaming, so just return */ |
| 7580 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) |
| 7581 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7582 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7583 | if (priv->status & STATUS_ASSOCIATED) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7584 | /* First pass through ROAM process -- look for a better |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7585 | * network */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7586 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7587 | u8 rssi = priv->assoc_network->stats.rssi; |
| 7588 | priv->assoc_network->stats.rssi = -128; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7589 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7590 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 7591 | if (network != priv->assoc_network) |
| 7592 | ipw_best_network(priv, &match, network, 1); |
| 7593 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7594 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7595 | priv->assoc_network->stats.rssi = rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7596 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7597 | if (match.network == priv->assoc_network) { |
| 7598 | IPW_DEBUG_ASSOC("No better APs in this network to " |
| 7599 | "roam to.\n"); |
| 7600 | priv->status &= ~STATUS_ROAMING; |
| 7601 | ipw_debug_config(priv); |
| 7602 | return; |
| 7603 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7604 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7605 | ipw_send_disassociate(priv, 1); |
| 7606 | priv->assoc_network = match.network; |
| 7607 | |
| 7608 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7609 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7610 | |
| 7611 | /* Second pass through ROAM process -- request association */ |
| 7612 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); |
| 7613 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); |
| 7614 | priv->status &= ~STATUS_ROAMING; |
| 7615 | } |
| 7616 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7617 | static void ipw_bg_roam(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7618 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7619 | struct ipw_priv *priv = |
| 7620 | container_of(work, struct ipw_priv, roam); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7621 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7622 | ipw_roam(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7623 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7624 | } |
| 7625 | |
| 7626 | static int ipw_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7627 | { |
| 7628 | struct ipw_priv *priv = data; |
| 7629 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7630 | struct libipw_network *network = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7631 | struct ipw_network_match match = { |
| 7632 | .network = NULL |
| 7633 | }; |
| 7634 | struct ipw_supported_rates *rates; |
| 7635 | struct list_head *element; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7636 | unsigned long flags; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7637 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7638 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7639 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 7640 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); |
| 7641 | return 0; |
| 7642 | } |
| 7643 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7644 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7645 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
| 7646 | "progress)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7647 | return 0; |
| 7648 | } |
| 7649 | |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 7650 | if (priv->status & STATUS_DISASSOCIATING) { |
| 7651 | IPW_DEBUG_ASSOC("Not attempting association (in " |
| 7652 | "disassociating)\n "); |
| 7653 | queue_work(priv->workqueue, &priv->associate); |
| 7654 | return 0; |
| 7655 | } |
| 7656 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7657 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7658 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
| 7659 | "initialized)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7660 | return 0; |
| 7661 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7662 | |
| 7663 | if (!(priv->config & CFG_ASSOCIATE) && |
Alexey Fisher | 3e4127f | 2008-11-06 09:51:16 +0100 | [diff] [blame] | 7664 | !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7665 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7666 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7667 | } |
| 7668 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7669 | /* Protect our use of the network_list */ |
| 7670 | spin_lock_irqsave(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7671 | list_for_each_entry(network, &priv->ieee->network_list, list) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7672 | ipw_best_network(priv, &match, network, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7673 | |
| 7674 | network = match.network; |
| 7675 | rates = &match.rates; |
| 7676 | |
| 7677 | if (network == NULL && |
| 7678 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7679 | priv->config & CFG_ADHOC_CREATE && |
| 7680 | priv->config & CFG_STATIC_ESSID && |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7681 | priv->config & CFG_STATIC_CHANNEL) { |
| 7682 | /* Use oldest network if the free list is empty */ |
| 7683 | if (list_empty(&priv->ieee->network_free_list)) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7684 | struct libipw_network *oldest = NULL; |
| 7685 | struct libipw_network *target; |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7686 | |
| 7687 | list_for_each_entry(target, &priv->ieee->network_list, list) { |
| 7688 | if ((oldest == NULL) || |
| 7689 | (target->last_scanned < oldest->last_scanned)) |
| 7690 | oldest = target; |
| 7691 | } |
| 7692 | |
| 7693 | /* If there are no more slots, expire the oldest */ |
| 7694 | list_del(&oldest->list); |
| 7695 | target = oldest; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7696 | IPW_DEBUG_ASSOC("Expired '%s' (%pM) from " |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7697 | "network list.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7698 | print_ssid(ssid, target->ssid, |
| 7699 | target->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7700 | target->bssid); |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7701 | list_add_tail(&target->list, |
| 7702 | &priv->ieee->network_free_list); |
| 7703 | } |
| 7704 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7705 | element = priv->ieee->network_free_list.next; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7706 | network = list_entry(element, struct libipw_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7707 | ipw_adhoc_create(priv, network); |
| 7708 | rates = &priv->rates; |
| 7709 | list_del(element); |
| 7710 | list_add_tail(&network->list, &priv->ieee->network_list); |
| 7711 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7712 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7713 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7714 | /* If we reached the end of the list, then we don't have any valid |
| 7715 | * matching APs */ |
| 7716 | if (!network) { |
| 7717 | ipw_debug_config(priv); |
| 7718 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7719 | if (!(priv->status & STATUS_SCANNING)) { |
| 7720 | if (!(priv->config & CFG_SPEED_SCAN)) |
| 7721 | queue_delayed_work(priv->workqueue, |
| 7722 | &priv->request_scan, |
| 7723 | SCAN_INTERVAL); |
| 7724 | else |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7725 | queue_delayed_work(priv->workqueue, |
| 7726 | &priv->request_scan, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7727 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7728 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7729 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7730 | } |
| 7731 | |
| 7732 | ipw_associate_network(priv, network, rates, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7733 | |
| 7734 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7735 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7736 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7737 | static void ipw_bg_associate(struct work_struct *work) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7738 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7739 | struct ipw_priv *priv = |
| 7740 | container_of(work, struct ipw_priv, associate); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7741 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7742 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7743 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7744 | } |
| 7745 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7746 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
| 7747 | struct sk_buff *skb) |
| 7748 | { |
| 7749 | struct ieee80211_hdr *hdr; |
| 7750 | u16 fc; |
| 7751 | |
| 7752 | hdr = (struct ieee80211_hdr *)skb->data; |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 7753 | fc = le16_to_cpu(hdr->frame_control); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7754 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 7755 | return; |
| 7756 | |
| 7757 | fc &= ~IEEE80211_FCTL_PROTECTED; |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 7758 | hdr->frame_control = cpu_to_le16(fc); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7759 | switch (priv->ieee->sec.level) { |
| 7760 | case SEC_LEVEL_3: |
| 7761 | /* Remove CCMP HDR */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7762 | memmove(skb->data + LIBIPW_3ADDR_LEN, |
| 7763 | skb->data + LIBIPW_3ADDR_LEN + 8, |
| 7764 | skb->len - LIBIPW_3ADDR_LEN - 8); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7765 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7766 | break; |
| 7767 | case SEC_LEVEL_2: |
| 7768 | break; |
| 7769 | case SEC_LEVEL_1: |
| 7770 | /* Remove IV */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7771 | memmove(skb->data + LIBIPW_3ADDR_LEN, |
| 7772 | skb->data + LIBIPW_3ADDR_LEN + 4, |
| 7773 | skb->len - LIBIPW_3ADDR_LEN - 4); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7774 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7775 | break; |
| 7776 | case SEC_LEVEL_0: |
| 7777 | break; |
| 7778 | default: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7779 | printk(KERN_ERR "Unknown security level %d\n", |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7780 | priv->ieee->sec.level); |
| 7781 | break; |
| 7782 | } |
| 7783 | } |
| 7784 | |
| 7785 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
| 7786 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7787 | struct libipw_rx_stats *stats) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7788 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7789 | struct net_device *dev = priv->net_dev; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7790 | struct libipw_hdr_4addr *hdr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7791 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7792 | |
| 7793 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7794 | dev->trans_start = jiffies; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7795 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7796 | /* We only process data packets if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7797 | * interface is open */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7798 | 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] | 7799 | skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7800 | dev->stats.rx_errors++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7801 | priv->wstats.discard.misc++; |
| 7802 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7803 | return; |
| 7804 | } else if (unlikely(!netif_running(priv->net_dev))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7805 | dev->stats.rx_dropped++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7806 | priv->wstats.discard.misc++; |
| 7807 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7808 | return; |
| 7809 | } |
| 7810 | |
| 7811 | /* Advance skb->data to the start of the actual payload */ |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 7812 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7813 | |
| 7814 | /* Set the size of the skb to the size of the frame */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7815 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7816 | |
| 7817 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7818 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7819 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7820 | hdr = (struct libipw_hdr_4addr *)rxb->skb->data; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7821 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7822 | (is_multicast_ether_addr(hdr->addr1) ? |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7823 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7824 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
| 7825 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7826 | if (!libipw_rx(priv->ieee, rxb->skb, stats)) |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7827 | dev->stats.rx_errors++; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7828 | else { /* libipw_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7829 | rxb->skb = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7830 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7831 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7832 | } |
| 7833 | |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 7834 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7835 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, |
| 7836 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7837 | struct libipw_rx_stats *stats) |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7838 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7839 | struct net_device *dev = priv->net_dev; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7840 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7841 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7842 | |
| 7843 | /* initial pull of some data */ |
| 7844 | u16 received_channel = frame->received_channel; |
| 7845 | u8 antennaAndPhy = frame->antennaAndPhy; |
| 7846 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ |
| 7847 | u16 pktrate = frame->rate; |
| 7848 | |
| 7849 | /* Magic struct that slots into the radiotap header -- no reason |
| 7850 | * to build this manually element by element, we can write it much |
| 7851 | * more efficiently than we can parse it. ORDER MATTERS HERE */ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7852 | struct ipw_rt_hdr *ipw_rt; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7853 | |
| 7854 | short len = le16_to_cpu(pkt->u.frame.length); |
| 7855 | |
| 7856 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7857 | dev->trans_start = jiffies; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7858 | |
| 7859 | /* We only process data packets if the |
| 7860 | * interface is open */ |
| 7861 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
| 7862 | skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7863 | dev->stats.rx_errors++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7864 | priv->wstats.discard.misc++; |
| 7865 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7866 | return; |
| 7867 | } else if (unlikely(!netif_running(priv->net_dev))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7868 | dev->stats.rx_dropped++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7869 | priv->wstats.discard.misc++; |
| 7870 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7871 | return; |
| 7872 | } |
| 7873 | |
| 7874 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7875 | * that now */ |
| 7876 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7877 | /* FIXME: Should alloc bigger skb instead */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7878 | dev->stats.rx_dropped++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7879 | priv->wstats.discard.misc++; |
| 7880 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7881 | return; |
| 7882 | } |
| 7883 | |
| 7884 | /* copy the frame itself */ |
| 7885 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), |
| 7886 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); |
| 7887 | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7888 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; |
| 7889 | |
| 7890 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7891 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 7892 | 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] | 7893 | |
| 7894 | /* Big bitfield of all the fields we provide in radiotap */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 7895 | ipw_rt->rt_hdr.it_present = cpu_to_le32( |
| 7896 | (1 << IEEE80211_RADIOTAP_TSFT) | |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 7897 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7898 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7899 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7900 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7901 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7902 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7903 | |
| 7904 | /* Zero the flags, we'll add to them as we go */ |
| 7905 | ipw_rt->rt_flags = 0; |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 7906 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | |
| 7907 | frame->parent_tsf[2] << 16 | |
| 7908 | frame->parent_tsf[1] << 8 | |
| 7909 | frame->parent_tsf[0]); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7910 | |
| 7911 | /* Convert signal to DBM */ |
| 7912 | ipw_rt->rt_dbmsignal = antsignal; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 7913 | ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7914 | |
| 7915 | /* Convert the channel data and set the flags */ |
| 7916 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); |
| 7917 | if (received_channel > 14) { /* 802.11a */ |
| 7918 | ipw_rt->rt_chbitmask = |
| 7919 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7920 | } else if (antennaAndPhy & 32) { /* 802.11b */ |
| 7921 | ipw_rt->rt_chbitmask = |
| 7922 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7923 | } else { /* 802.11g */ |
| 7924 | ipw_rt->rt_chbitmask = |
Al Viro | 472caf8 | 2007-12-27 01:50:54 -0500 | [diff] [blame] | 7925 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7926 | } |
| 7927 | |
| 7928 | /* set the rate in multiples of 500k/s */ |
| 7929 | switch (pktrate) { |
| 7930 | case IPW_TX_RATE_1MB: |
| 7931 | ipw_rt->rt_rate = 2; |
| 7932 | break; |
| 7933 | case IPW_TX_RATE_2MB: |
| 7934 | ipw_rt->rt_rate = 4; |
| 7935 | break; |
| 7936 | case IPW_TX_RATE_5MB: |
| 7937 | ipw_rt->rt_rate = 10; |
| 7938 | break; |
| 7939 | case IPW_TX_RATE_6MB: |
| 7940 | ipw_rt->rt_rate = 12; |
| 7941 | break; |
| 7942 | case IPW_TX_RATE_9MB: |
| 7943 | ipw_rt->rt_rate = 18; |
| 7944 | break; |
| 7945 | case IPW_TX_RATE_11MB: |
| 7946 | ipw_rt->rt_rate = 22; |
| 7947 | break; |
| 7948 | case IPW_TX_RATE_12MB: |
| 7949 | ipw_rt->rt_rate = 24; |
| 7950 | break; |
| 7951 | case IPW_TX_RATE_18MB: |
| 7952 | ipw_rt->rt_rate = 36; |
| 7953 | break; |
| 7954 | case IPW_TX_RATE_24MB: |
| 7955 | ipw_rt->rt_rate = 48; |
| 7956 | break; |
| 7957 | case IPW_TX_RATE_36MB: |
| 7958 | ipw_rt->rt_rate = 72; |
| 7959 | break; |
| 7960 | case IPW_TX_RATE_48MB: |
| 7961 | ipw_rt->rt_rate = 96; |
| 7962 | break; |
| 7963 | case IPW_TX_RATE_54MB: |
| 7964 | ipw_rt->rt_rate = 108; |
| 7965 | break; |
| 7966 | default: |
| 7967 | ipw_rt->rt_rate = 0; |
| 7968 | break; |
| 7969 | } |
| 7970 | |
| 7971 | /* antenna number */ |
| 7972 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ |
| 7973 | |
| 7974 | /* set the preamble flag if we have it */ |
| 7975 | if ((antennaAndPhy & 64)) |
| 7976 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7977 | |
| 7978 | /* Set the size of the skb to the size of the frame */ |
| 7979 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7980 | |
| 7981 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7982 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7983 | if (!libipw_rx(priv->ieee, rxb->skb, stats)) |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7984 | dev->stats.rx_errors++; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7985 | else { /* libipw_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7986 | rxb->skb = NULL; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7987 | /* no LED during capture */ |
| 7988 | } |
| 7989 | } |
| 7990 | #endif |
| 7991 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7992 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7993 | #define libipw_is_probe_response(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7994 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \ |
| 7995 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP ) |
| 7996 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7997 | #define libipw_is_management(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7998 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 7999 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8000 | #define libipw_is_control(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8001 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) |
| 8002 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8003 | #define libipw_is_data(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8004 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) |
| 8005 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8006 | #define libipw_is_assoc_request(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8007 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ) |
| 8008 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8009 | #define libipw_is_reassoc_request(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8010 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
| 8011 | |
| 8012 | static void ipw_handle_promiscuous_rx(struct ipw_priv *priv, |
| 8013 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8014 | struct libipw_rx_stats *stats) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8015 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8016 | struct net_device *dev = priv->prom_net_dev; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8017 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 8018 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 8019 | struct ipw_rt_hdr *ipw_rt; |
| 8020 | |
| 8021 | /* First cache any information we need before we overwrite |
| 8022 | * the information provided in the skb from the hardware */ |
| 8023 | struct ieee80211_hdr *hdr; |
| 8024 | u16 channel = frame->received_channel; |
| 8025 | u8 phy_flags = frame->antennaAndPhy; |
| 8026 | s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8027 | s8 noise = (s8) le16_to_cpu(frame->noise); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8028 | u8 rate = frame->rate; |
| 8029 | short len = le16_to_cpu(pkt->u.frame.length); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8030 | struct sk_buff *skb; |
| 8031 | int hdr_only = 0; |
| 8032 | u16 filter = priv->prom_priv->filter; |
| 8033 | |
| 8034 | /* If the filter is set to not include Rx frames then return */ |
| 8035 | if (filter & IPW_PROM_NO_RX) |
| 8036 | return; |
| 8037 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8038 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8039 | dev->trans_start = jiffies; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8040 | |
| 8041 | if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8042 | dev->stats.rx_errors++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8043 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 8044 | return; |
| 8045 | } |
| 8046 | |
| 8047 | /* We only process data packets if the interface is open */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8048 | if (unlikely(!netif_running(dev))) { |
| 8049 | dev->stats.rx_dropped++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8050 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 8051 | return; |
| 8052 | } |
| 8053 | |
| 8054 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 8055 | * that now */ |
| 8056 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 8057 | /* FIXME: Should alloc bigger skb instead */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8058 | dev->stats.rx_dropped++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8059 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 8060 | return; |
| 8061 | } |
| 8062 | |
| 8063 | hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8064 | if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8065 | if (filter & IPW_PROM_NO_MGMT) |
| 8066 | return; |
| 8067 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 8068 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8069 | } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8070 | if (filter & IPW_PROM_NO_CTL) |
| 8071 | return; |
| 8072 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 8073 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8074 | } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8075 | if (filter & IPW_PROM_NO_DATA) |
| 8076 | return; |
| 8077 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 8078 | hdr_only = 1; |
| 8079 | } |
| 8080 | |
| 8081 | /* Copy the SKB since this is for the promiscuous side */ |
| 8082 | skb = skb_copy(rxb->skb, GFP_ATOMIC); |
| 8083 | if (skb == NULL) { |
| 8084 | IPW_ERROR("skb_clone failed for promiscuous copy.\n"); |
| 8085 | return; |
| 8086 | } |
| 8087 | |
| 8088 | /* copy the frame data to write after where the radiotap header goes */ |
| 8089 | ipw_rt = (void *)skb->data; |
| 8090 | |
| 8091 | if (hdr_only) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8092 | len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8093 | |
| 8094 | memcpy(ipw_rt->payload, hdr, len); |
| 8095 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8096 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 8097 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8098 | 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] | 8099 | |
| 8100 | /* Set the size of the skb to the size of the frame */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8101 | skb_put(skb, sizeof(*ipw_rt) + len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8102 | |
| 8103 | /* Big bitfield of all the fields we provide in radiotap */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8104 | ipw_rt->rt_hdr.it_present = cpu_to_le32( |
| 8105 | (1 << IEEE80211_RADIOTAP_TSFT) | |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 8106 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8107 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 8108 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 8109 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 8110 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 8111 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 8112 | |
| 8113 | /* Zero the flags, we'll add to them as we go */ |
| 8114 | ipw_rt->rt_flags = 0; |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 8115 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | |
| 8116 | frame->parent_tsf[2] << 16 | |
| 8117 | frame->parent_tsf[1] << 8 | |
| 8118 | frame->parent_tsf[0]); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8119 | |
| 8120 | /* Convert to DBM */ |
| 8121 | ipw_rt->rt_dbmsignal = signal; |
| 8122 | ipw_rt->rt_dbmnoise = noise; |
| 8123 | |
| 8124 | /* Convert the channel data and set the flags */ |
| 8125 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel)); |
| 8126 | if (channel > 14) { /* 802.11a */ |
| 8127 | ipw_rt->rt_chbitmask = |
| 8128 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 8129 | } else if (phy_flags & (1 << 5)) { /* 802.11b */ |
| 8130 | ipw_rt->rt_chbitmask = |
| 8131 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 8132 | } else { /* 802.11g */ |
| 8133 | ipw_rt->rt_chbitmask = |
Al Viro | 472caf8 | 2007-12-27 01:50:54 -0500 | [diff] [blame] | 8134 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8135 | } |
| 8136 | |
| 8137 | /* set the rate in multiples of 500k/s */ |
| 8138 | switch (rate) { |
| 8139 | case IPW_TX_RATE_1MB: |
| 8140 | ipw_rt->rt_rate = 2; |
| 8141 | break; |
| 8142 | case IPW_TX_RATE_2MB: |
| 8143 | ipw_rt->rt_rate = 4; |
| 8144 | break; |
| 8145 | case IPW_TX_RATE_5MB: |
| 8146 | ipw_rt->rt_rate = 10; |
| 8147 | break; |
| 8148 | case IPW_TX_RATE_6MB: |
| 8149 | ipw_rt->rt_rate = 12; |
| 8150 | break; |
| 8151 | case IPW_TX_RATE_9MB: |
| 8152 | ipw_rt->rt_rate = 18; |
| 8153 | break; |
| 8154 | case IPW_TX_RATE_11MB: |
| 8155 | ipw_rt->rt_rate = 22; |
| 8156 | break; |
| 8157 | case IPW_TX_RATE_12MB: |
| 8158 | ipw_rt->rt_rate = 24; |
| 8159 | break; |
| 8160 | case IPW_TX_RATE_18MB: |
| 8161 | ipw_rt->rt_rate = 36; |
| 8162 | break; |
| 8163 | case IPW_TX_RATE_24MB: |
| 8164 | ipw_rt->rt_rate = 48; |
| 8165 | break; |
| 8166 | case IPW_TX_RATE_36MB: |
| 8167 | ipw_rt->rt_rate = 72; |
| 8168 | break; |
| 8169 | case IPW_TX_RATE_48MB: |
| 8170 | ipw_rt->rt_rate = 96; |
| 8171 | break; |
| 8172 | case IPW_TX_RATE_54MB: |
| 8173 | ipw_rt->rt_rate = 108; |
| 8174 | break; |
| 8175 | default: |
| 8176 | ipw_rt->rt_rate = 0; |
| 8177 | break; |
| 8178 | } |
| 8179 | |
| 8180 | /* antenna number */ |
| 8181 | ipw_rt->rt_antenna = (phy_flags & 3); |
| 8182 | |
| 8183 | /* set the preamble flag if we have it */ |
| 8184 | if (phy_flags & (1 << 6)) |
| 8185 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 8186 | |
| 8187 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len); |
| 8188 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8189 | if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8190 | dev->stats.rx_errors++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8191 | dev_kfree_skb_any(skb); |
| 8192 | } |
| 8193 | } |
| 8194 | #endif |
| 8195 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 8196 | static int is_network_packet(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8197 | struct libipw_hdr_4addr *header) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8198 | { |
| 8199 | /* Filter incoming packets to determine if they are targetted toward |
| 8200 | * this network, discarding packets coming from ourselves */ |
| 8201 | switch (priv->ieee->iw_mode) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8202 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8203 | /* packets from our adapter are dropped (echo) */ |
| 8204 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) |
| 8205 | return 0; |
| 8206 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8207 | /* {broad,multi}cast packets to our BSSID go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 8208 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8209 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8210 | |
| 8211 | /* packets to our adapter go through */ |
| 8212 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 8213 | ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8214 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8215 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8216 | /* packets from our adapter are dropped (echo) */ |
| 8217 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) |
| 8218 | return 0; |
| 8219 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8220 | /* {broad,multi}cast packets to our BSS go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 8221 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8222 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
| 8223 | |
| 8224 | /* packets to our adapter go through */ |
| 8225 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 8226 | ETH_ALEN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8227 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8228 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8229 | return 1; |
| 8230 | } |
| 8231 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8232 | #define IPW_PACKET_RETRY_TIME HZ |
| 8233 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 8234 | static int is_duplicate_packet(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8235 | struct libipw_hdr_4addr *header) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8236 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8237 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 8238 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 8239 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 8240 | u16 *last_seq, *last_frag; |
| 8241 | unsigned long *last_time; |
| 8242 | |
| 8243 | switch (priv->ieee->iw_mode) { |
| 8244 | case IW_MODE_ADHOC: |
| 8245 | { |
| 8246 | struct list_head *p; |
| 8247 | struct ipw_ibss_seq *entry = NULL; |
| 8248 | u8 *mac = header->addr2; |
| 8249 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; |
| 8250 | |
| 8251 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 8252 | entry = |
| 8253 | list_entry(p, struct ipw_ibss_seq, list); |
| 8254 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 8255 | break; |
| 8256 | } |
| 8257 | if (p == &priv->ibss_mac_hash[index]) { |
| 8258 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 8259 | if (!entry) { |
| 8260 | IPW_ERROR |
| 8261 | ("Cannot malloc new mac entry\n"); |
| 8262 | return 0; |
| 8263 | } |
| 8264 | memcpy(entry->mac, mac, ETH_ALEN); |
| 8265 | entry->seq_num = seq; |
| 8266 | entry->frag_num = frag; |
| 8267 | entry->packet_time = jiffies; |
| 8268 | list_add(&entry->list, |
| 8269 | &priv->ibss_mac_hash[index]); |
| 8270 | return 0; |
| 8271 | } |
| 8272 | last_seq = &entry->seq_num; |
| 8273 | last_frag = &entry->frag_num; |
| 8274 | last_time = &entry->packet_time; |
| 8275 | break; |
| 8276 | } |
| 8277 | case IW_MODE_INFRA: |
| 8278 | last_seq = &priv->last_seq_num; |
| 8279 | last_frag = &priv->last_frag_num; |
| 8280 | last_time = &priv->last_packet_time; |
| 8281 | break; |
| 8282 | default: |
| 8283 | return 0; |
| 8284 | } |
| 8285 | if ((*last_seq == seq) && |
| 8286 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { |
| 8287 | if (*last_frag == frag) |
| 8288 | goto drop; |
| 8289 | if (*last_frag + 1 != frag) |
| 8290 | /* out-of-order fragment */ |
| 8291 | goto drop; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8292 | } else |
| 8293 | *last_seq = seq; |
| 8294 | |
Zhu Yi | f57ce7c | 2005-07-13 12:22:15 -0500 | [diff] [blame] | 8295 | *last_frag = frag; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8296 | *last_time = jiffies; |
| 8297 | return 0; |
| 8298 | |
| 8299 | drop: |
Zhu Yi | 87b016c | 2005-08-05 17:17:35 +0800 | [diff] [blame] | 8300 | /* Comment this line now since we observed the card receives |
| 8301 | * duplicate packets but the FCTL_RETRY bit is not set in the |
| 8302 | * IBSS mode with fragmentation enabled. |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 8303 | BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8304 | return 1; |
| 8305 | } |
| 8306 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8307 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
| 8308 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8309 | struct libipw_rx_stats *stats) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8310 | { |
| 8311 | struct sk_buff *skb = rxb->skb; |
| 8312 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8313 | struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8314 | (skb->data + IPW_RX_FRAME_SIZE); |
| 8315 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8316 | libipw_rx_mgt(priv->ieee, header, stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8317 | |
| 8318 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 8319 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8320 | IEEE80211_STYPE_PROBE_RESP) || |
| 8321 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8322 | IEEE80211_STYPE_BEACON))) { |
| 8323 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) |
| 8324 | ipw_add_station(priv, header->addr2); |
| 8325 | } |
| 8326 | |
| 8327 | if (priv->config & CFG_NET_STATS) { |
| 8328 | IPW_DEBUG_HC("sending stat packet\n"); |
| 8329 | |
| 8330 | /* Set the size of the skb to the size of the full |
| 8331 | * ipw header and 802.11 frame */ |
| 8332 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + |
| 8333 | IPW_RX_FRAME_SIZE); |
| 8334 | |
| 8335 | /* Advance past the ipw packet header to the 802.11 frame */ |
| 8336 | skb_pull(skb, IPW_RX_FRAME_SIZE); |
| 8337 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8338 | /* Push the libipw_rx_stats before the 802.11 frame */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8339 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
| 8340 | |
| 8341 | skb->dev = priv->ieee->dev; |
| 8342 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8343 | /* Point raw at the libipw_stats */ |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 8344 | skb_reset_mac_header(skb); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8345 | |
| 8346 | skb->pkt_type = PACKET_OTHERHOST; |
Harvey Harrison | c1b4aa3 | 2009-01-29 13:26:44 -0800 | [diff] [blame] | 8347 | skb->protocol = cpu_to_be16(ETH_P_80211_STATS); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8348 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
| 8349 | netif_rx(skb); |
| 8350 | rxb->skb = NULL; |
| 8351 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8352 | } |
| 8353 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8354 | /* |
| 8355 | * Main entry function for recieving a packet with 80211 headers. This |
| 8356 | * should be called when ever the FW has notified us that there is a new |
| 8357 | * skb in the recieve queue. |
| 8358 | */ |
| 8359 | static void ipw_rx(struct ipw_priv *priv) |
| 8360 | { |
| 8361 | struct ipw_rx_mem_buffer *rxb; |
| 8362 | struct ipw_rx_packet *pkt; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8363 | struct libipw_hdr_4addr *header; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8364 | u32 r, w, i; |
| 8365 | u8 network_packet; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8366 | u8 fill_rx = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8367 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8368 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
| 8369 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8370 | i = priv->rxq->read; |
| 8371 | |
| 8372 | if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2)) |
| 8373 | fill_rx = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8374 | |
| 8375 | while (i != r) { |
| 8376 | rxb = priv->rxq->queue[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8377 | if (unlikely(rxb == NULL)) { |
| 8378 | printk(KERN_CRIT "Queue not allocated!\n"); |
| 8379 | break; |
| 8380 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8381 | priv->rxq->queue[i] = NULL; |
| 8382 | |
| 8383 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8384 | IPW_RX_BUF_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8385 | PCI_DMA_FROMDEVICE); |
| 8386 | |
| 8387 | pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 8388 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", |
| 8389 | pkt->header.message_type, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8390 | pkt->header.rx_seq_num, pkt->header.control_bits); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8391 | |
| 8392 | switch (pkt->header.message_type) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8393 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8394 | struct libipw_rx_stats stats = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 8395 | .rssi = pkt->u.frame.rssi_dbm - |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8396 | IPW_RSSI_TO_DBM, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8397 | .signal = |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8398 | pkt->u.frame.rssi_dbm - |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8399 | IPW_RSSI_TO_DBM + 0x100, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8400 | .noise = |
| 8401 | le16_to_cpu(pkt->u.frame.noise), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8402 | .rate = pkt->u.frame.rate, |
| 8403 | .mac_time = jiffies, |
| 8404 | .received_channel = |
| 8405 | pkt->u.frame.received_channel, |
| 8406 | .freq = |
| 8407 | (pkt->u.frame. |
| 8408 | control & (1 << 0)) ? |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8409 | LIBIPW_24GHZ_BAND : |
| 8410 | LIBIPW_52GHZ_BAND, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8411 | .len = le16_to_cpu(pkt->u.frame.length), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8412 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8413 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8414 | if (stats.rssi != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8415 | stats.mask |= LIBIPW_STATMASK_RSSI; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8416 | if (stats.signal != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8417 | stats.mask |= LIBIPW_STATMASK_SIGNAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8418 | if (stats.noise != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8419 | stats.mask |= LIBIPW_STATMASK_NOISE; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8420 | if (stats.rate != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8421 | stats.mask |= LIBIPW_STATMASK_RATE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8422 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8423 | priv->rx_packets++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8424 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8425 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 8426 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) |
| 8427 | ipw_handle_promiscuous_rx(priv, rxb, &stats); |
| 8428 | #endif |
| 8429 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8430 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8431 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8432 | #ifdef CONFIG_IPW2200_RADIOTAP |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8433 | |
| 8434 | ipw_handle_data_packet_monitor(priv, |
| 8435 | rxb, |
| 8436 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8437 | #else |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8438 | ipw_handle_data_packet(priv, rxb, |
| 8439 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8440 | #endif |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8441 | break; |
| 8442 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8443 | #endif |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8444 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8445 | header = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8446 | (struct libipw_hdr_4addr *)(rxb->skb-> |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 8447 | data + |
| 8448 | IPW_RX_FRAME_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8449 | /* TODO: Check Ad-Hoc dest/source and make sure |
| 8450 | * that we are actually parsing these packets |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8451 | * correctly -- we should probably use the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8452 | * frame control of the packet and disregard |
| 8453 | * the current iw_mode */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8454 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8455 | network_packet = |
| 8456 | is_network_packet(priv, header); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8457 | if (network_packet && priv->assoc_network) { |
| 8458 | priv->assoc_network->stats.rssi = |
| 8459 | stats.rssi; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 8460 | priv->exp_avg_rssi = |
| 8461 | exponential_average(priv->exp_avg_rssi, |
| 8462 | stats.rssi, DEPTH_RSSI); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8463 | } |
| 8464 | |
| 8465 | IPW_DEBUG_RX("Frame: len=%u\n", |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8466 | le16_to_cpu(pkt->u.frame.length)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8467 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8468 | if (le16_to_cpu(pkt->u.frame.length) < |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8469 | libipw_get_hdrlen(le16_to_cpu( |
Zhu Yi | 9d0be03 | 2006-02-15 06:18:19 +0800 | [diff] [blame] | 8470 | header->frame_ctl))) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8471 | IPW_DEBUG_DROP |
| 8472 | ("Received packet is too small. " |
| 8473 | "Dropping.\n"); |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8474 | priv->net_dev->stats.rx_errors++; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8475 | priv->wstats.discard.misc++; |
| 8476 | break; |
| 8477 | } |
| 8478 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8479 | switch (WLAN_FC_GET_TYPE |
| 8480 | (le16_to_cpu(header->frame_ctl))) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8481 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8482 | case IEEE80211_FTYPE_MGMT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8483 | ipw_handle_mgmt_packet(priv, rxb, |
| 8484 | &stats); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8485 | break; |
| 8486 | |
| 8487 | case IEEE80211_FTYPE_CTL: |
| 8488 | break; |
| 8489 | |
| 8490 | case IEEE80211_FTYPE_DATA: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8491 | if (unlikely(!network_packet || |
| 8492 | is_duplicate_packet(priv, |
| 8493 | header))) |
| 8494 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8495 | IPW_DEBUG_DROP("Dropping: " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 8496 | "%pM, " |
| 8497 | "%pM, " |
| 8498 | "%pM\n", |
| 8499 | header->addr1, |
| 8500 | header->addr2, |
| 8501 | header->addr3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8502 | break; |
| 8503 | } |
| 8504 | |
| 8505 | ipw_handle_data_packet(priv, rxb, |
| 8506 | &stats); |
| 8507 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8508 | break; |
| 8509 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8510 | break; |
| 8511 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8512 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8513 | case RX_HOST_NOTIFICATION_TYPE:{ |
| 8514 | IPW_DEBUG_RX |
| 8515 | ("Notification: subtype=%02X flags=%02X size=%d\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8516 | pkt->u.notification.subtype, |
| 8517 | pkt->u.notification.flags, |
Zhu Yi | 720eeb4 | 2006-12-05 14:41:40 +0800 | [diff] [blame] | 8518 | le16_to_cpu(pkt->u.notification.size)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8519 | ipw_rx_notification(priv, &pkt->u.notification); |
| 8520 | break; |
| 8521 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8522 | |
| 8523 | default: |
| 8524 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", |
| 8525 | pkt->header.message_type); |
| 8526 | break; |
| 8527 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8528 | |
| 8529 | /* For now we just don't re-use anything. We can tweak this |
| 8530 | * later to try and re-use notification packets and SKBs that |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8531 | * fail to Rx correctly */ |
| 8532 | if (rxb->skb != NULL) { |
| 8533 | dev_kfree_skb_any(rxb->skb); |
| 8534 | rxb->skb = NULL; |
| 8535 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8536 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8537 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8538 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8539 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8540 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8541 | i = (i + 1) % RX_QUEUE_SIZE; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8542 | |
| 8543 | /* If there are a lot of unsued frames, restock the Rx queue |
| 8544 | * so the ucode won't assert */ |
| 8545 | if (fill_rx) { |
| 8546 | priv->rxq->read = i; |
| 8547 | ipw_rx_queue_replenish(priv); |
| 8548 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8549 | } |
| 8550 | |
| 8551 | /* Backtrack one entry */ |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8552 | priv->rxq->read = i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8553 | ipw_rx_queue_restock(priv); |
| 8554 | } |
| 8555 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8556 | #define DEFAULT_RTS_THRESHOLD 2304U |
| 8557 | #define MIN_RTS_THRESHOLD 1U |
| 8558 | #define MAX_RTS_THRESHOLD 2304U |
| 8559 | #define DEFAULT_BEACON_INTERVAL 100U |
| 8560 | #define DEFAULT_SHORT_RETRY_LIMIT 7U |
| 8561 | #define DEFAULT_LONG_RETRY_LIMIT 4U |
| 8562 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8563 | /** |
| 8564 | * ipw_sw_reset |
| 8565 | * @option: options to control different reset behaviour |
| 8566 | * 0 = reset everything except the 'disable' module_param |
| 8567 | * 1 = reset everything and print out driver info (for probe only) |
| 8568 | * 2 = reset everything |
| 8569 | */ |
| 8570 | static int ipw_sw_reset(struct ipw_priv *priv, int option) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8571 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8572 | int band, modulation; |
| 8573 | int old_mode = priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8574 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8575 | /* Initialize module parameter values here */ |
| 8576 | priv->config = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8577 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8578 | /* We default to disabling the LED code as right now it causes |
| 8579 | * too many systems to lock up... */ |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8580 | if (!led_support) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8581 | priv->config |= CFG_NO_LED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8582 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8583 | if (associate) |
| 8584 | priv->config |= CFG_ASSOCIATE; |
| 8585 | else |
| 8586 | IPW_DEBUG_INFO("Auto associate disabled.\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8587 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8588 | if (auto_create) |
| 8589 | priv->config |= CFG_ADHOC_CREATE; |
| 8590 | else |
| 8591 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); |
| 8592 | |
Zhu Yi | 17ed081 | 2006-01-24 16:36:31 +0800 | [diff] [blame] | 8593 | priv->config &= ~CFG_STATIC_ESSID; |
| 8594 | priv->essid_len = 0; |
| 8595 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 8596 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8597 | if (disable && option) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8598 | priv->status |= STATUS_RF_KILL_SW; |
| 8599 | IPW_DEBUG_INFO("Radio disabled.\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8600 | } |
| 8601 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8602 | if (default_channel != 0) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8603 | priv->config |= CFG_STATIC_CHANNEL; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8604 | priv->channel = default_channel; |
| 8605 | IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8606 | /* TODO: Validate that provided channel is in range */ |
| 8607 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8608 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8609 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
| 8610 | burst_duration_CCK, burst_duration_OFDM); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8611 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8612 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8613 | switch (network_mode) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8614 | case 1: |
| 8615 | priv->ieee->iw_mode = IW_MODE_ADHOC; |
| 8616 | priv->net_dev->type = ARPHRD_ETHER; |
| 8617 | |
| 8618 | break; |
| 8619 | #ifdef CONFIG_IPW2200_MONITOR |
| 8620 | case 2: |
| 8621 | priv->ieee->iw_mode = IW_MODE_MONITOR; |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8622 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8623 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8624 | #else |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8625 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8626 | #endif |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8627 | break; |
| 8628 | #endif |
| 8629 | default: |
| 8630 | case 0: |
| 8631 | priv->net_dev->type = ARPHRD_ETHER; |
| 8632 | priv->ieee->iw_mode = IW_MODE_INFRA; |
| 8633 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8634 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8635 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8636 | if (hwcrypto) { |
| 8637 | priv->ieee->host_encrypt = 0; |
| 8638 | priv->ieee->host_encrypt_msdu = 0; |
| 8639 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 8640 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8641 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8642 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8643 | |
Zhu Yi | e402c93 | 2005-08-05 17:20:40 +0800 | [diff] [blame] | 8644 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
| 8645 | priv->ieee->host_open_frag = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8646 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8647 | if ((priv->pci_dev->device == 0x4223) || |
| 8648 | (priv->pci_dev->device == 0x4224)) { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8649 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8650 | printk(KERN_INFO DRV_NAME |
| 8651 | ": Detected Intel PRO/Wireless 2915ABG Network " |
| 8652 | "Connection\n"); |
| 8653 | priv->ieee->abg_true = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8654 | band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND; |
| 8655 | modulation = LIBIPW_OFDM_MODULATION | |
| 8656 | LIBIPW_CCK_MODULATION; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8657 | priv->adapter = IPW_2915ABG; |
| 8658 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8659 | } else { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8660 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8661 | printk(KERN_INFO DRV_NAME |
| 8662 | ": Detected Intel PRO/Wireless 2200BG Network " |
| 8663 | "Connection\n"); |
| 8664 | |
| 8665 | priv->ieee->abg_true = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8666 | band = LIBIPW_24GHZ_BAND; |
| 8667 | modulation = LIBIPW_OFDM_MODULATION | |
| 8668 | LIBIPW_CCK_MODULATION; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8669 | priv->adapter = IPW_2200BG; |
| 8670 | priv->ieee->mode = IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8671 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8672 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8673 | priv->ieee->freq_band = band; |
| 8674 | priv->ieee->modulation = modulation; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8675 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8676 | priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8677 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8678 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8679 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8680 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8681 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8682 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; |
| 8683 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8684 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8685 | /* If power management is turned on, default to AC mode */ |
| 8686 | priv->power_mode = IPW_POWER_AC; |
| 8687 | priv->tx_power = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8688 | |
Zhu Yi | 0ece35b | 2005-08-05 17:26:51 +0800 | [diff] [blame] | 8689 | return old_mode == priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8690 | } |
| 8691 | |
| 8692 | /* |
| 8693 | * This file defines the Wireless Extension handlers. It does not |
| 8694 | * define any methods of hardware manipulation and relies on the |
| 8695 | * functions defined in ipw_main to provide the HW interaction. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8696 | * |
| 8697 | * The exception to this is the use of the ipw_get_ordinal() |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8698 | * function used to poll the hardware vs. making unecessary calls. |
| 8699 | * |
| 8700 | */ |
| 8701 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8702 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
| 8703 | { |
| 8704 | if (channel == 0) { |
| 8705 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); |
| 8706 | priv->config &= ~CFG_STATIC_CHANNEL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8707 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8708 | "parameters.\n"); |
| 8709 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8710 | return 0; |
| 8711 | } |
| 8712 | |
| 8713 | priv->config |= CFG_STATIC_CHANNEL; |
| 8714 | |
| 8715 | if (priv->channel == channel) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8716 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
| 8717 | channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8718 | return 0; |
| 8719 | } |
| 8720 | |
| 8721 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); |
| 8722 | priv->channel = channel; |
| 8723 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8724 | #ifdef CONFIG_IPW2200_MONITOR |
| 8725 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8726 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8727 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8728 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8729 | "channel change.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8730 | ipw_abort_scan(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8731 | } |
| 8732 | |
| 8733 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) |
| 8734 | udelay(10); |
| 8735 | |
| 8736 | if (priv->status & STATUS_SCANNING) |
| 8737 | IPW_DEBUG_SCAN("Still scanning...\n"); |
| 8738 | else |
| 8739 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", |
| 8740 | 1000 - i); |
| 8741 | |
| 8742 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8743 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8744 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 8745 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8746 | /* Network configuration changed -- force [re]association */ |
| 8747 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); |
| 8748 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8749 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8750 | |
| 8751 | return 0; |
| 8752 | } |
| 8753 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8754 | static int ipw_wx_set_freq(struct net_device *dev, |
| 8755 | struct iw_request_info *info, |
| 8756 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8757 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8758 | struct ipw_priv *priv = libipw_priv(dev); |
| 8759 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8760 | struct iw_freq *fwrq = &wrqu->freq; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8761 | int ret = 0, i; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8762 | u8 channel, flags; |
| 8763 | int band; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8764 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8765 | if (fwrq->m == 0) { |
| 8766 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8767 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8768 | ret = ipw_set_channel(priv, 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8769 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8770 | return ret; |
| 8771 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8772 | /* if setting by freq convert to channel */ |
| 8773 | if (fwrq->e == 1) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8774 | channel = libipw_freq_to_channel(priv->ieee, fwrq->m); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8775 | if (channel == 0) |
| 8776 | return -EINVAL; |
| 8777 | } else |
| 8778 | channel = fwrq->m; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8779 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8780 | if (!(band = libipw_is_valid_channel(priv->ieee, channel))) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8781 | return -EINVAL; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8782 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8783 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8784 | i = libipw_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8785 | if (i == -1) |
| 8786 | return -EINVAL; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8787 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8788 | flags = (band == LIBIPW_24GHZ_BAND) ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8789 | geo->bg[i].flags : geo->a[i].flags; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8790 | if (flags & LIBIPW_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8791 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
| 8792 | return -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8793 | } |
| 8794 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8795 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8796 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8797 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8798 | ret = ipw_set_channel(priv, channel); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8799 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8800 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8801 | } |
| 8802 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8803 | static int ipw_wx_get_freq(struct net_device *dev, |
| 8804 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8805 | union iwreq_data *wrqu, char *extra) |
| 8806 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8807 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8808 | |
| 8809 | wrqu->freq.e = 0; |
| 8810 | |
| 8811 | /* If we are associated, trying to associate, or have a statically |
| 8812 | * configured CHANNEL then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8813 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8814 | if (priv->config & CFG_STATIC_CHANNEL || |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8815 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) { |
| 8816 | int i; |
| 8817 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8818 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8819 | BUG_ON(i == -1); |
| 8820 | wrqu->freq.e = 1; |
| 8821 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8822 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 8823 | case LIBIPW_52GHZ_BAND: |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8824 | wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000; |
| 8825 | break; |
| 8826 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8827 | case LIBIPW_24GHZ_BAND: |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8828 | wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000; |
| 8829 | break; |
| 8830 | |
| 8831 | default: |
| 8832 | BUG(); |
| 8833 | } |
| 8834 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8835 | wrqu->freq.m = 0; |
| 8836 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8837 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8838 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
| 8839 | return 0; |
| 8840 | } |
| 8841 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8842 | static int ipw_wx_set_mode(struct net_device *dev, |
| 8843 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8844 | union iwreq_data *wrqu, char *extra) |
| 8845 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8846 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8847 | int err = 0; |
| 8848 | |
| 8849 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); |
| 8850 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8851 | switch (wrqu->mode) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8852 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8853 | case IW_MODE_MONITOR: |
| 8854 | #endif |
| 8855 | case IW_MODE_ADHOC: |
| 8856 | case IW_MODE_INFRA: |
| 8857 | break; |
| 8858 | case IW_MODE_AUTO: |
| 8859 | wrqu->mode = IW_MODE_INFRA; |
| 8860 | break; |
| 8861 | default: |
| 8862 | return -EINVAL; |
| 8863 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8864 | if (wrqu->mode == priv->ieee->iw_mode) |
| 8865 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8866 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8867 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8868 | |
| 8869 | ipw_sw_reset(priv, 0); |
| 8870 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8871 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8872 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8873 | priv->net_dev->type = ARPHRD_ETHER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8874 | |
| 8875 | if (wrqu->mode == IW_MODE_MONITOR) |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8876 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8877 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8878 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8879 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8880 | #endif |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8881 | #endif /* CONFIG_IPW2200_MONITOR */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8882 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8883 | /* Free the existing firmware and reset the fw_loaded |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 8884 | * flag so ipw_load() will bring in the new firmware */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8885 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8886 | |
| 8887 | priv->ieee->iw_mode = wrqu->mode; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8888 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8889 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8890 | mutex_unlock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8891 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8892 | } |
| 8893 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8894 | static int ipw_wx_get_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8895 | struct iw_request_info *info, |
| 8896 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8897 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8898 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8899 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8900 | wrqu->mode = priv->ieee->iw_mode; |
| 8901 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8902 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8903 | return 0; |
| 8904 | } |
| 8905 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8906 | /* Values are in microsecond */ |
| 8907 | static const s32 timeout_duration[] = { |
| 8908 | 350000, |
| 8909 | 250000, |
| 8910 | 75000, |
| 8911 | 37000, |
| 8912 | 25000, |
| 8913 | }; |
| 8914 | |
| 8915 | static const s32 period_duration[] = { |
| 8916 | 400000, |
| 8917 | 700000, |
| 8918 | 1000000, |
| 8919 | 1000000, |
| 8920 | 1000000 |
| 8921 | }; |
| 8922 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8923 | static int ipw_wx_get_range(struct net_device *dev, |
| 8924 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8925 | union iwreq_data *wrqu, char *extra) |
| 8926 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8927 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8928 | struct iw_range *range = (struct iw_range *)extra; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8929 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8930 | int i = 0, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8931 | |
| 8932 | wrqu->data.length = sizeof(*range); |
| 8933 | memset(range, 0, sizeof(*range)); |
| 8934 | |
| 8935 | /* 54Mbs == ~27 Mb/s real (802.11g) */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8936 | range->throughput = 27 * 1000 * 1000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8937 | |
| 8938 | range->max_qual.qual = 100; |
| 8939 | /* TODO: Find real max RSSI and stick here */ |
| 8940 | range->max_qual.level = 0; |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8941 | range->max_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8942 | range->max_qual.updated = 7; /* Updated all three */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8943 | |
| 8944 | range->avg_qual.qual = 70; |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8945 | /* TODO: Find real 'good' to 'bad' threshold value for RSSI */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8946 | range->avg_qual.level = 0; /* FIXME to real average level */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8947 | range->avg_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8948 | range->avg_qual.updated = 7; /* Updated all three */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8949 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8950 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8951 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8952 | for (i = 0; i < range->num_bitrates; i++) |
| 8953 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8954 | 500000; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8955 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8956 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
| 8957 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 8958 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 8959 | |
| 8960 | range->encoding_size[0] = 5; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8961 | range->encoding_size[1] = 13; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8962 | range->num_encoding_sizes = 2; |
| 8963 | range->max_encoding_tokens = WEP_KEYS; |
| 8964 | |
| 8965 | /* Set the Wireless Extension versions */ |
| 8966 | range->we_version_compiled = WIRELESS_EXT; |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8967 | range->we_version_source = 18; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8968 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8969 | i = 0; |
| 8970 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8971 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8972 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8973 | (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY)) |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8974 | continue; |
| 8975 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8976 | range->freq[i].i = geo->bg[j].channel; |
| 8977 | range->freq[i].m = geo->bg[j].freq * 100000; |
| 8978 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8979 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8980 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8981 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8982 | |
| 8983 | if (priv->ieee->mode & IEEE_A) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8984 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8985 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8986 | (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY)) |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8987 | continue; |
| 8988 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8989 | range->freq[i].i = geo->a[j].channel; |
| 8990 | range->freq[i].m = geo->a[j].freq * 100000; |
| 8991 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8992 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8993 | } |
| 8994 | } |
| 8995 | |
| 8996 | range->num_channels = i; |
| 8997 | range->num_frequency = i; |
| 8998 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8999 | mutex_unlock(&priv->mutex); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 9000 | |
| 9001 | /* Event capability (kernel + driver) */ |
| 9002 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 9003 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 9004 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | |
| 9005 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 9006 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9007 | |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 9008 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 9009 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 9010 | |
Dan Williams | 374fdfb | 2007-12-12 10:25:07 -0500 | [diff] [blame] | 9011 | range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE; |
| 9012 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9013 | IPW_DEBUG_WX("GET Range\n"); |
| 9014 | return 0; |
| 9015 | } |
| 9016 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9017 | static int ipw_wx_set_wap(struct net_device *dev, |
| 9018 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9019 | union iwreq_data *wrqu, char *extra) |
| 9020 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9021 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9022 | |
| 9023 | static const unsigned char any[] = { |
| 9024 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 9025 | }; |
| 9026 | static const unsigned char off[] = { |
| 9027 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 9028 | }; |
| 9029 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9030 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9031 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9032 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9033 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
| 9034 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 9035 | /* we disable mandatory BSSID association */ |
| 9036 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); |
| 9037 | priv->config &= ~CFG_STATIC_BSSID; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9038 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 9039 | "parameters.\n"); |
| 9040 | ipw_associate(priv); |
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 | |
| 9045 | priv->config |= CFG_STATIC_BSSID; |
| 9046 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 9047 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9048 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9049 | return 0; |
| 9050 | } |
| 9051 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 9052 | IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n", |
| 9053 | wrqu->ap_addr.sa_data); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9054 | |
| 9055 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); |
| 9056 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9057 | /* Network configuration changed -- force [re]association */ |
| 9058 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); |
| 9059 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9060 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9061 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9062 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9063 | return 0; |
| 9064 | } |
| 9065 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9066 | static int ipw_wx_get_wap(struct net_device *dev, |
| 9067 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9068 | union iwreq_data *wrqu, char *extra) |
| 9069 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9070 | struct ipw_priv *priv = libipw_priv(dev); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 9071 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9072 | /* If we are associated, trying to associate, or have a statically |
| 9073 | * configured BSSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9074 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9075 | if (priv->config & CFG_STATIC_BSSID || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9076 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 9077 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9078 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9079 | } else |
| 9080 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 9081 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 9082 | IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", |
| 9083 | wrqu->ap_addr.sa_data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9084 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9085 | return 0; |
| 9086 | } |
| 9087 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9088 | static int ipw_wx_set_essid(struct net_device *dev, |
| 9089 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9090 | union iwreq_data *wrqu, char *extra) |
| 9091 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9092 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 9093 | int length; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9094 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9095 | |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 9096 | mutex_lock(&priv->mutex); |
| 9097 | |
| 9098 | if (!wrqu->essid.flags) |
| 9099 | { |
| 9100 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); |
| 9101 | ipw_disassociate(priv); |
| 9102 | priv->config &= ~CFG_STATIC_ESSID; |
| 9103 | ipw_associate(priv); |
| 9104 | mutex_unlock(&priv->mutex); |
| 9105 | return 0; |
| 9106 | } |
| 9107 | |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9108 | length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9109 | |
| 9110 | priv->config |= CFG_STATIC_ESSID; |
| 9111 | |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9112 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length) |
| 9113 | && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9114 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9115 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9116 | return 0; |
| 9117 | } |
| 9118 | |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9119 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", |
| 9120 | print_ssid(ssid, extra, length), length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9121 | |
| 9122 | priv->essid_len = length; |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9123 | memcpy(priv->essid, extra, priv->essid_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9124 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9125 | /* Network configuration changed -- force [re]association */ |
| 9126 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); |
| 9127 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9128 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9129 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9130 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9131 | return 0; |
| 9132 | } |
| 9133 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9134 | static int ipw_wx_get_essid(struct net_device *dev, |
| 9135 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9136 | union iwreq_data *wrqu, char *extra) |
| 9137 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9138 | struct ipw_priv *priv = libipw_priv(dev); |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9139 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9140 | |
| 9141 | /* If we are associated, trying to associate, or have a statically |
| 9142 | * configured ESSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9143 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9144 | if (priv->config & CFG_STATIC_ESSID || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9145 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 9146 | IPW_DEBUG_WX("Getting essid: '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9147 | print_ssid(ssid, priv->essid, priv->essid_len)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9148 | memcpy(extra, priv->essid, priv->essid_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9149 | wrqu->essid.length = priv->essid_len; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9150 | wrqu->essid.flags = 1; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9151 | } else { |
| 9152 | IPW_DEBUG_WX("Getting essid: ANY\n"); |
| 9153 | wrqu->essid.length = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9154 | wrqu->essid.flags = 0; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9155 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9156 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9157 | return 0; |
| 9158 | } |
| 9159 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9160 | static int ipw_wx_set_nick(struct net_device *dev, |
| 9161 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9162 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9163 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9164 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9165 | |
| 9166 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); |
| 9167 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) |
| 9168 | return -E2BIG; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9169 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9170 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9171 | memset(priv->nick, 0, sizeof(priv->nick)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9172 | memcpy(priv->nick, extra, wrqu->data.length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9173 | IPW_DEBUG_TRACE("<<\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9174 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9175 | return 0; |
| 9176 | |
| 9177 | } |
| 9178 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9179 | static int ipw_wx_get_nick(struct net_device *dev, |
| 9180 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9181 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9182 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9183 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9184 | IPW_DEBUG_WX("Getting nick\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9185 | mutex_lock(&priv->mutex); |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9186 | wrqu->data.length = strlen(priv->nick); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9187 | memcpy(extra, priv->nick, wrqu->data.length); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9188 | wrqu->data.flags = 1; /* active */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9189 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9190 | return 0; |
| 9191 | } |
| 9192 | |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9193 | static int ipw_wx_set_sens(struct net_device *dev, |
| 9194 | struct iw_request_info *info, |
| 9195 | union iwreq_data *wrqu, char *extra) |
| 9196 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9197 | struct ipw_priv *priv = libipw_priv(dev); |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9198 | int err = 0; |
| 9199 | |
| 9200 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); |
| 9201 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); |
| 9202 | mutex_lock(&priv->mutex); |
| 9203 | |
| 9204 | if (wrqu->sens.fixed == 0) |
| 9205 | { |
| 9206 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
| 9207 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 9208 | goto out; |
| 9209 | } |
| 9210 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || |
| 9211 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { |
| 9212 | err = -EINVAL; |
| 9213 | goto out; |
| 9214 | } |
| 9215 | |
| 9216 | priv->roaming_threshold = wrqu->sens.value; |
| 9217 | priv->disassociate_threshold = 3*wrqu->sens.value; |
| 9218 | out: |
| 9219 | mutex_unlock(&priv->mutex); |
| 9220 | return err; |
| 9221 | } |
| 9222 | |
| 9223 | static int ipw_wx_get_sens(struct net_device *dev, |
| 9224 | struct iw_request_info *info, |
| 9225 | union iwreq_data *wrqu, char *extra) |
| 9226 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9227 | struct ipw_priv *priv = libipw_priv(dev); |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9228 | mutex_lock(&priv->mutex); |
| 9229 | wrqu->sens.fixed = 1; |
| 9230 | wrqu->sens.value = priv->roaming_threshold; |
| 9231 | mutex_unlock(&priv->mutex); |
| 9232 | |
| 9233 | IPW_DEBUG_WX("GET roaming threshold -> %s %d \n", |
| 9234 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
| 9235 | |
| 9236 | return 0; |
| 9237 | } |
| 9238 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9239 | static int ipw_wx_set_rate(struct net_device *dev, |
| 9240 | struct iw_request_info *info, |
| 9241 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9242 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9243 | /* TODO: We should use semaphores or locks for access to priv */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9244 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9245 | u32 target_rate = wrqu->bitrate.value; |
| 9246 | u32 fixed, mask; |
| 9247 | |
| 9248 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ |
| 9249 | /* value = X, fixed = 1 means only rate X */ |
| 9250 | /* value = X, fixed = 0 means all rates lower equal X */ |
| 9251 | |
| 9252 | if (target_rate == -1) { |
| 9253 | fixed = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9254 | mask = LIBIPW_DEFAULT_RATES_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9255 | /* Now we should reassociate */ |
| 9256 | goto apply; |
| 9257 | } |
| 9258 | |
| 9259 | mask = 0; |
| 9260 | fixed = wrqu->bitrate.fixed; |
| 9261 | |
| 9262 | if (target_rate == 1000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9263 | mask |= LIBIPW_CCK_RATE_1MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9264 | if (target_rate == 1000000) |
| 9265 | goto apply; |
| 9266 | |
| 9267 | if (target_rate == 2000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9268 | mask |= LIBIPW_CCK_RATE_2MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9269 | if (target_rate == 2000000) |
| 9270 | goto apply; |
| 9271 | |
| 9272 | if (target_rate == 5500000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9273 | mask |= LIBIPW_CCK_RATE_5MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9274 | if (target_rate == 5500000) |
| 9275 | goto apply; |
| 9276 | |
| 9277 | if (target_rate == 6000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9278 | mask |= LIBIPW_OFDM_RATE_6MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9279 | if (target_rate == 6000000) |
| 9280 | goto apply; |
| 9281 | |
| 9282 | if (target_rate == 9000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9283 | mask |= LIBIPW_OFDM_RATE_9MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9284 | if (target_rate == 9000000) |
| 9285 | goto apply; |
| 9286 | |
| 9287 | if (target_rate == 11000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9288 | mask |= LIBIPW_CCK_RATE_11MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9289 | if (target_rate == 11000000) |
| 9290 | goto apply; |
| 9291 | |
| 9292 | if (target_rate == 12000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9293 | mask |= LIBIPW_OFDM_RATE_12MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9294 | if (target_rate == 12000000) |
| 9295 | goto apply; |
| 9296 | |
| 9297 | if (target_rate == 18000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9298 | mask |= LIBIPW_OFDM_RATE_18MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9299 | if (target_rate == 18000000) |
| 9300 | goto apply; |
| 9301 | |
| 9302 | if (target_rate == 24000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9303 | mask |= LIBIPW_OFDM_RATE_24MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9304 | if (target_rate == 24000000) |
| 9305 | goto apply; |
| 9306 | |
| 9307 | if (target_rate == 36000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9308 | mask |= LIBIPW_OFDM_RATE_36MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9309 | if (target_rate == 36000000) |
| 9310 | goto apply; |
| 9311 | |
| 9312 | if (target_rate == 48000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9313 | mask |= LIBIPW_OFDM_RATE_48MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9314 | if (target_rate == 48000000) |
| 9315 | goto apply; |
| 9316 | |
| 9317 | if (target_rate == 54000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9318 | mask |= LIBIPW_OFDM_RATE_54MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9319 | if (target_rate == 54000000) |
| 9320 | goto apply; |
| 9321 | |
| 9322 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); |
| 9323 | return -EINVAL; |
| 9324 | |
| 9325 | apply: |
| 9326 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", |
| 9327 | mask, fixed ? "fixed" : "sub-rates"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9328 | mutex_lock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9329 | if (mask == LIBIPW_DEFAULT_RATES_MASK) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9330 | priv->config &= ~CFG_FIXED_RATE; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9331 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
| 9332 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9333 | priv->config |= CFG_FIXED_RATE; |
| 9334 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9335 | if (priv->rates_mask == mask) { |
| 9336 | IPW_DEBUG_WX("Mask set to current mask.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9337 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9338 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9339 | } |
| 9340 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9341 | priv->rates_mask = mask; |
| 9342 | |
| 9343 | /* Network configuration changed -- force [re]association */ |
| 9344 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); |
| 9345 | if (!ipw_disassociate(priv)) |
| 9346 | ipw_associate(priv); |
| 9347 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9348 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9349 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9350 | } |
| 9351 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9352 | static int ipw_wx_get_rate(struct net_device *dev, |
| 9353 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9354 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9355 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9356 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9357 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9358 | wrqu->bitrate.value = priv->last_rate; |
Zhu Yi | 455936c | 2006-04-13 17:20:05 +0800 | [diff] [blame] | 9359 | wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9360 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9361 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
| 9362 | return 0; |
| 9363 | } |
| 9364 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9365 | static int ipw_wx_set_rts(struct net_device *dev, |
| 9366 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9367 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9368 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9369 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9370 | mutex_lock(&priv->mutex); |
Zhu Yi | ea8862d | 2007-01-11 17:32:54 +0800 | [diff] [blame] | 9371 | if (wrqu->rts.disabled || !wrqu->rts.fixed) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9372 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 9373 | else { |
| 9374 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9375 | wrqu->rts.value > MAX_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 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9378 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9379 | priv->rts_threshold = wrqu->rts.value; |
| 9380 | } |
| 9381 | |
| 9382 | ipw_send_rts_threshold(priv, priv->rts_threshold); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9383 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9384 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
| 9385 | return 0; |
| 9386 | } |
| 9387 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9388 | static int ipw_wx_get_rts(struct net_device *dev, |
| 9389 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9390 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9391 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9392 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9393 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9394 | wrqu->rts.value = priv->rts_threshold; |
| 9395 | wrqu->rts.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9396 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9397 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9398 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
| 9399 | return 0; |
| 9400 | } |
| 9401 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9402 | static int ipw_wx_set_txpow(struct net_device *dev, |
| 9403 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9404 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9405 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9406 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9407 | int err = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9408 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9409 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9410 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9411 | err = -EINPROGRESS; |
| 9412 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9413 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9414 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9415 | if (!wrqu->power.fixed) |
| 9416 | wrqu->power.value = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9417 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9418 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9419 | err = -EINVAL; |
| 9420 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9421 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9422 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9423 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9424 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9425 | err = -EINVAL; |
| 9426 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9427 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9428 | |
| 9429 | priv->tx_power = wrqu->power.value; |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9430 | err = ipw_set_tx_power(priv); |
| 9431 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9432 | mutex_unlock(&priv->mutex); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9433 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9434 | } |
| 9435 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9436 | static int ipw_wx_get_txpow(struct net_device *dev, |
| 9437 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9438 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9439 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9440 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9441 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9442 | wrqu->power.value = priv->tx_power; |
| 9443 | wrqu->power.fixed = 1; |
| 9444 | wrqu->power.flags = IW_TXPOW_DBM; |
| 9445 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9446 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9447 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9448 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
Zhu Yi | 22501c8 | 2005-08-11 10:49:17 +0800 | [diff] [blame] | 9449 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9450 | |
| 9451 | return 0; |
| 9452 | } |
| 9453 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9454 | static int ipw_wx_set_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9455 | struct iw_request_info *info, |
| 9456 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9457 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9458 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9459 | mutex_lock(&priv->mutex); |
Zhu Yi | ea8862d | 2007-01-11 17:32:54 +0800 | [diff] [blame] | 9460 | if (wrqu->frag.disabled || !wrqu->frag.fixed) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9461 | priv->ieee->fts = DEFAULT_FTS; |
| 9462 | else { |
| 9463 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9464 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9465 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9466 | return -EINVAL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9467 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9468 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9469 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
| 9470 | } |
| 9471 | |
| 9472 | ipw_send_frag_threshold(priv, wrqu->frag.value); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9473 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9474 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
| 9475 | return 0; |
| 9476 | } |
| 9477 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9478 | static int ipw_wx_get_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9479 | struct iw_request_info *info, |
| 9480 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9481 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9482 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9483 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9484 | wrqu->frag.value = priv->ieee->fts; |
| 9485 | wrqu->frag.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9486 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9487 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9488 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
| 9489 | |
| 9490 | return 0; |
| 9491 | } |
| 9492 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9493 | static int ipw_wx_set_retry(struct net_device *dev, |
| 9494 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9495 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9496 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9497 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9498 | |
| 9499 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) |
| 9500 | return -EINVAL; |
| 9501 | |
| 9502 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) |
| 9503 | return 0; |
| 9504 | |
Zhu Yi | d5f7ac2 | 2006-08-21 11:38:17 +0800 | [diff] [blame] | 9505 | if (wrqu->retry.value < 0 || wrqu->retry.value >= 255) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9506 | return -EINVAL; |
| 9507 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9508 | mutex_lock(&priv->mutex); |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9509 | if (wrqu->retry.flags & IW_RETRY_SHORT) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9510 | priv->short_retry_limit = (u8) wrqu->retry.value; |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9511 | else if (wrqu->retry.flags & IW_RETRY_LONG) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9512 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9513 | else { |
| 9514 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 9515 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9516 | } |
| 9517 | |
| 9518 | ipw_send_retry_limit(priv, priv->short_retry_limit, |
| 9519 | priv->long_retry_limit); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9520 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9521 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
| 9522 | priv->short_retry_limit, priv->long_retry_limit); |
| 9523 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9524 | } |
| 9525 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9526 | static int ipw_wx_get_retry(struct net_device *dev, |
| 9527 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9528 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9529 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9530 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9531 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9532 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9533 | wrqu->retry.disabled = 0; |
| 9534 | |
| 9535 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9536 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9537 | return -EINVAL; |
| 9538 | } |
| 9539 | |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9540 | if (wrqu->retry.flags & IW_RETRY_LONG) { |
| 9541 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9542 | wrqu->retry.value = priv->long_retry_limit; |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9543 | } else if (wrqu->retry.flags & IW_RETRY_SHORT) { |
| 9544 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9545 | wrqu->retry.value = priv->short_retry_limit; |
| 9546 | } else { |
| 9547 | wrqu->retry.flags = IW_RETRY_LIMIT; |
| 9548 | wrqu->retry.value = priv->short_retry_limit; |
| 9549 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9550 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9551 | |
| 9552 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); |
| 9553 | |
| 9554 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9555 | } |
| 9556 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9557 | static int ipw_wx_set_scan(struct net_device *dev, |
| 9558 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9559 | union iwreq_data *wrqu, char *extra) |
| 9560 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9561 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9562 | struct iw_scan_req *req = (struct iw_scan_req *)extra; |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9563 | struct delayed_work *work = NULL; |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9564 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9565 | mutex_lock(&priv->mutex); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9566 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9567 | priv->user_requested_scan = 1; |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9568 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9569 | if (wrqu->data.length == sizeof(struct iw_scan_req)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9570 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9571 | int len = min((int)req->essid_len, |
| 9572 | (int)sizeof(priv->direct_scan_ssid)); |
| 9573 | memcpy(priv->direct_scan_ssid, req->essid, len); |
| 9574 | priv->direct_scan_ssid_len = len; |
| 9575 | work = &priv->request_direct_scan; |
| 9576 | } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { |
| 9577 | work = &priv->request_passive_scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9578 | } |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9579 | } else { |
| 9580 | /* Normal active broadcast scan */ |
| 9581 | work = &priv->request_scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9582 | } |
James Ketrenos | 8935f39 | 2005-10-05 15:59:08 -0500 | [diff] [blame] | 9583 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9584 | mutex_unlock(&priv->mutex); |
| 9585 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9586 | IPW_DEBUG_WX("Start scan\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9587 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9588 | queue_delayed_work(priv->workqueue, work, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9589 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9590 | return 0; |
| 9591 | } |
| 9592 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9593 | static int ipw_wx_get_scan(struct net_device *dev, |
| 9594 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9595 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9596 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9597 | struct ipw_priv *priv = libipw_priv(dev); |
| 9598 | return libipw_wx_get_scan(priv->ieee, info, wrqu, extra); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9599 | } |
| 9600 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9601 | static int ipw_wx_set_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9602 | struct iw_request_info *info, |
| 9603 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9604 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9605 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9606 | int ret; |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9607 | u32 cap = priv->capability; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9608 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9609 | mutex_lock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9610 | ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9611 | |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9612 | /* In IBSS mode, we need to notify the firmware to update |
| 9613 | * the beacon info after we changed the capability. */ |
| 9614 | if (cap != priv->capability && |
| 9615 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 9616 | priv->status & STATUS_ASSOCIATED) |
| 9617 | ipw_disassociate(priv); |
| 9618 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9619 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9620 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9621 | } |
| 9622 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9623 | static int ipw_wx_get_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9624 | struct iw_request_info *info, |
| 9625 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9626 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9627 | struct ipw_priv *priv = libipw_priv(dev); |
| 9628 | return libipw_wx_get_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9629 | } |
| 9630 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9631 | static int ipw_wx_set_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9632 | struct iw_request_info *info, |
| 9633 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9634 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9635 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9636 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9637 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9638 | if (wrqu->power.disabled) { |
| 9639 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); |
| 9640 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); |
| 9641 | if (err) { |
| 9642 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9643 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9644 | return err; |
| 9645 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9646 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9647 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9648 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9649 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9650 | |
| 9651 | switch (wrqu->power.flags & IW_POWER_MODE) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9652 | case IW_POWER_ON: /* If not specified */ |
| 9653 | case IW_POWER_MODE: /* If set all mask */ |
Jean Delvare | c03983a | 2007-10-19 23:22:55 +0200 | [diff] [blame] | 9654 | case IW_POWER_ALL_R: /* If explicitly state all */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9655 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9656 | default: /* Otherwise we don't support it */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9657 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
| 9658 | wrqu->power.flags); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9659 | mutex_unlock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9660 | return -EOPNOTSUPP; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9661 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9662 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9663 | /* If the user hasn't specified a power management mode yet, default |
| 9664 | * to BATTERY */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9665 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9666 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9667 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9668 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9669 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9670 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
| 9671 | if (err) { |
| 9672 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9673 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9674 | return err; |
| 9675 | } |
| 9676 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9677 | 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] | 9678 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9679 | return 0; |
| 9680 | } |
| 9681 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9682 | static int ipw_wx_get_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9683 | struct iw_request_info *info, |
| 9684 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9685 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9686 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9687 | mutex_lock(&priv->mutex); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9688 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9689 | wrqu->power.disabled = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9690 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9691 | wrqu->power.disabled = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9692 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9693 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9694 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9695 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9696 | return 0; |
| 9697 | } |
| 9698 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9699 | static int ipw_wx_set_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9700 | struct iw_request_info *info, |
| 9701 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9702 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9703 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9704 | int mode = *(int *)extra; |
| 9705 | int err; |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9706 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9707 | mutex_lock(&priv->mutex); |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9708 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9709 | mode = IPW_POWER_AC; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9710 | |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9711 | if (IPW_POWER_LEVEL(priv->power_mode) != mode) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9712 | err = ipw_send_power_mode(priv, mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9713 | if (err) { |
| 9714 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9715 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9716 | return err; |
| 9717 | } |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9718 | priv->power_mode = IPW_POWER_ENABLED | mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9719 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9720 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9721 | return 0; |
| 9722 | } |
| 9723 | |
| 9724 | #define MAX_WX_STRING 80 |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9725 | static int ipw_wx_get_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9726 | struct iw_request_info *info, |
| 9727 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9728 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9729 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9730 | int level = IPW_POWER_LEVEL(priv->power_mode); |
| 9731 | char *p = extra; |
| 9732 | |
| 9733 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); |
| 9734 | |
| 9735 | switch (level) { |
| 9736 | case IPW_POWER_AC: |
| 9737 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); |
| 9738 | break; |
| 9739 | case IPW_POWER_BATTERY: |
| 9740 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); |
| 9741 | break; |
| 9742 | default: |
| 9743 | p += snprintf(p, MAX_WX_STRING - (p - extra), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9744 | "(Timeout %dms, Period %dms)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9745 | timeout_duration[level - 1] / 1000, |
| 9746 | period_duration[level - 1] / 1000); |
| 9747 | } |
| 9748 | |
| 9749 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9750 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9751 | |
| 9752 | wrqu->data.length = p - extra + 1; |
| 9753 | |
| 9754 | return 0; |
| 9755 | } |
| 9756 | |
| 9757 | static int ipw_wx_set_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9758 | struct iw_request_info *info, |
| 9759 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9760 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9761 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9762 | int mode = *(int *)extra; |
| 9763 | u8 band = 0, modulation = 0; |
| 9764 | |
| 9765 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9766 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9767 | return -EINVAL; |
| 9768 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9769 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9770 | if (priv->adapter == IPW_2915ABG) { |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9771 | priv->ieee->abg_true = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9772 | if (mode & IEEE_A) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9773 | band |= LIBIPW_52GHZ_BAND; |
| 9774 | modulation |= LIBIPW_OFDM_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9775 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9776 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9777 | } else { |
| 9778 | if (mode & IEEE_A) { |
| 9779 | IPW_WARNING("Attempt to set 2200BG into " |
| 9780 | "802.11a mode\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9781 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9782 | return -EINVAL; |
| 9783 | } |
| 9784 | |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9785 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9786 | } |
| 9787 | |
| 9788 | if (mode & IEEE_B) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9789 | band |= LIBIPW_24GHZ_BAND; |
| 9790 | modulation |= LIBIPW_CCK_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9791 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9792 | priv->ieee->abg_true = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9793 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9794 | if (mode & IEEE_G) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9795 | band |= LIBIPW_24GHZ_BAND; |
| 9796 | modulation |= LIBIPW_OFDM_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9797 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9798 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9799 | |
| 9800 | priv->ieee->mode = mode; |
| 9801 | priv->ieee->freq_band = band; |
| 9802 | priv->ieee->modulation = modulation; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9803 | init_supported_rates(priv, &priv->rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9804 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9805 | /* Network configuration changed -- force [re]association */ |
| 9806 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); |
| 9807 | if (!ipw_disassociate(priv)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9808 | ipw_send_supported_rates(priv, &priv->rates); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9809 | ipw_associate(priv); |
| 9810 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9811 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9812 | /* Update the band LEDs */ |
| 9813 | ipw_led_band_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9814 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9815 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9816 | mode & IEEE_A ? 'a' : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9817 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9818 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9819 | return 0; |
| 9820 | } |
| 9821 | |
| 9822 | static int ipw_wx_get_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9823 | struct iw_request_info *info, |
| 9824 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9825 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9826 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9827 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9828 | switch (priv->ieee->mode) { |
| 9829 | case IEEE_A: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9830 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
| 9831 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9832 | case IEEE_B: |
| 9833 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); |
| 9834 | break; |
| 9835 | case IEEE_A | IEEE_B: |
| 9836 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); |
| 9837 | break; |
| 9838 | case IEEE_G: |
| 9839 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); |
| 9840 | break; |
| 9841 | case IEEE_A | IEEE_G: |
| 9842 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); |
| 9843 | break; |
| 9844 | case IEEE_B | IEEE_G: |
| 9845 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); |
| 9846 | break; |
| 9847 | case IEEE_A | IEEE_B | IEEE_G: |
| 9848 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); |
| 9849 | break; |
| 9850 | default: |
| 9851 | strncpy(extra, "unknown", MAX_WX_STRING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9852 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9853 | } |
| 9854 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9855 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
| 9856 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9857 | wrqu->data.length = strlen(extra) + 1; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9858 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9859 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9860 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9861 | } |
| 9862 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9863 | static int ipw_wx_set_preamble(struct net_device *dev, |
| 9864 | struct iw_request_info *info, |
| 9865 | union iwreq_data *wrqu, char *extra) |
| 9866 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9867 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9868 | int mode = *(int *)extra; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9869 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9870 | /* Switching from SHORT -> LONG requires a disassociation */ |
| 9871 | if (mode == 1) { |
| 9872 | if (!(priv->config & CFG_PREAMBLE_LONG)) { |
| 9873 | priv->config |= CFG_PREAMBLE_LONG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9874 | |
| 9875 | /* Network configuration changed -- force [re]association */ |
| 9876 | IPW_DEBUG_ASSOC |
| 9877 | ("[re]association triggered due to preamble change.\n"); |
| 9878 | if (!ipw_disassociate(priv)) |
| 9879 | ipw_associate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9880 | } |
| 9881 | goto done; |
| 9882 | } |
| 9883 | |
| 9884 | if (mode == 0) { |
| 9885 | priv->config &= ~CFG_PREAMBLE_LONG; |
| 9886 | goto done; |
| 9887 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9888 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9889 | return -EINVAL; |
| 9890 | |
| 9891 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9892 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9893 | return 0; |
| 9894 | } |
| 9895 | |
| 9896 | static int ipw_wx_get_preamble(struct net_device *dev, |
| 9897 | struct iw_request_info *info, |
| 9898 | union iwreq_data *wrqu, char *extra) |
| 9899 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9900 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9901 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9902 | if (priv->config & CFG_PREAMBLE_LONG) |
| 9903 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); |
| 9904 | else |
| 9905 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9906 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9907 | return 0; |
| 9908 | } |
| 9909 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9910 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9911 | static int ipw_wx_set_monitor(struct net_device *dev, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9912 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9913 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9914 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9915 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9916 | int *parms = (int *)extra; |
| 9917 | int enable = (parms[0] > 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9918 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9919 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9920 | if (enable) { |
| 9921 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 9922 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9923 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 9924 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9925 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9926 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9927 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9928 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9929 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9930 | ipw_set_channel(priv, parms[1]); |
| 9931 | } else { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9932 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9933 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9934 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9935 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9936 | priv->net_dev->type = ARPHRD_ETHER; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9937 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9938 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9939 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9940 | return 0; |
| 9941 | } |
| 9942 | |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 9943 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9944 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9945 | static int ipw_wx_reset(struct net_device *dev, |
| 9946 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9947 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9948 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9949 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9950 | IPW_DEBUG_WX("RESET\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9951 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9952 | return 0; |
| 9953 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9954 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9955 | static int ipw_wx_sw_reset(struct net_device *dev, |
| 9956 | struct iw_request_info *info, |
| 9957 | union iwreq_data *wrqu, char *extra) |
| 9958 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9959 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9960 | union iwreq_data wrqu_sec = { |
| 9961 | .encoding = { |
| 9962 | .flags = IW_ENCODE_DISABLED, |
| 9963 | }, |
| 9964 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9965 | int ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9966 | |
| 9967 | IPW_DEBUG_WX("SW_RESET\n"); |
| 9968 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9969 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9970 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 9971 | ret = ipw_sw_reset(priv, 2); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9972 | if (!ret) { |
| 9973 | free_firmware(); |
| 9974 | ipw_adapter_restart(priv); |
| 9975 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9976 | |
| 9977 | /* The SW reset bit might have been toggled on by the 'disable' |
| 9978 | * module parameter, so take appropriate action */ |
| 9979 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); |
| 9980 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9981 | mutex_unlock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9982 | libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9983 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9984 | |
| 9985 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 9986 | /* Configuration likely changed -- force [re]association */ |
| 9987 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " |
| 9988 | "reset.\n"); |
| 9989 | if (!ipw_disassociate(priv)) |
| 9990 | ipw_associate(priv); |
| 9991 | } |
| 9992 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9993 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9994 | |
| 9995 | return 0; |
| 9996 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9997 | |
| 9998 | /* Rebase the WE IOCTLs to zero for the handler array */ |
| 9999 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10000 | static iw_handler ipw_wx_handlers[] = { |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 10001 | IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10002 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, |
| 10003 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, |
| 10004 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, |
| 10005 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 10006 | IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens, |
| 10007 | IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10008 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
| 10009 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, |
| 10010 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, |
| 10011 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, |
| 10012 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, |
| 10013 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, |
| 10014 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, |
| 10015 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, |
| 10016 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, |
| 10017 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, |
| 10018 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, |
| 10019 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, |
| 10020 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, |
| 10021 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, |
| 10022 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, |
| 10023 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, |
| 10024 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, |
| 10025 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, |
| 10026 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, |
| 10027 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, |
| 10028 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, |
| 10029 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, |
| 10030 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10031 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
| 10032 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, |
| 10033 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, |
| 10034 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10035 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
| 10036 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, |
| 10037 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, |
| 10038 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, |
| 10039 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, |
| 10040 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, |
| 10041 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10042 | }; |
| 10043 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10044 | enum { |
| 10045 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, |
| 10046 | IPW_PRIV_GET_POWER, |
| 10047 | IPW_PRIV_SET_MODE, |
| 10048 | IPW_PRIV_GET_MODE, |
| 10049 | IPW_PRIV_SET_PREAMBLE, |
| 10050 | IPW_PRIV_GET_PREAMBLE, |
| 10051 | IPW_PRIV_RESET, |
| 10052 | IPW_PRIV_SW_RESET, |
| 10053 | #ifdef CONFIG_IPW2200_MONITOR |
| 10054 | IPW_PRIV_SET_MONITOR, |
| 10055 | #endif |
| 10056 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10057 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10058 | static struct iw_priv_args ipw_priv_args[] = { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10059 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10060 | .cmd = IPW_PRIV_SET_POWER, |
| 10061 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10062 | .name = "set_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10063 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10064 | .cmd = IPW_PRIV_GET_POWER, |
| 10065 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 10066 | .name = "get_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10067 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10068 | .cmd = IPW_PRIV_SET_MODE, |
| 10069 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10070 | .name = "set_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10071 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10072 | .cmd = IPW_PRIV_GET_MODE, |
| 10073 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 10074 | .name = "get_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10075 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10076 | .cmd = IPW_PRIV_SET_PREAMBLE, |
| 10077 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10078 | .name = "set_preamble"}, |
| 10079 | { |
| 10080 | .cmd = IPW_PRIV_GET_PREAMBLE, |
| 10081 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, |
| 10082 | .name = "get_preamble"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10083 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10084 | IPW_PRIV_RESET, |
| 10085 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10086 | { |
| 10087 | IPW_PRIV_SW_RESET, |
| 10088 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, |
| 10089 | #ifdef CONFIG_IPW2200_MONITOR |
| 10090 | { |
| 10091 | IPW_PRIV_SET_MONITOR, |
| 10092 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, |
| 10093 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10094 | }; |
| 10095 | |
| 10096 | static iw_handler ipw_priv_handler[] = { |
| 10097 | ipw_wx_set_powermode, |
| 10098 | ipw_wx_get_powermode, |
| 10099 | ipw_wx_set_wireless_mode, |
| 10100 | ipw_wx_get_wireless_mode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10101 | ipw_wx_set_preamble, |
| 10102 | ipw_wx_get_preamble, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10103 | ipw_wx_reset, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10104 | ipw_wx_sw_reset, |
| 10105 | #ifdef CONFIG_IPW2200_MONITOR |
| 10106 | ipw_wx_set_monitor, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10107 | #endif |
| 10108 | }; |
| 10109 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10110 | static struct iw_handler_def ipw_wx_handler_def = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10111 | .standard = ipw_wx_handlers, |
| 10112 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), |
| 10113 | .num_private = ARRAY_SIZE(ipw_priv_handler), |
| 10114 | .num_private_args = ARRAY_SIZE(ipw_priv_args), |
| 10115 | .private = ipw_priv_handler, |
| 10116 | .private_args = ipw_priv_args, |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 10117 | .get_wireless_stats = ipw_get_wireless_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10118 | }; |
| 10119 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10120 | /* |
| 10121 | * Get wireless statistics. |
| 10122 | * Called by /proc/net/wireless |
| 10123 | * Also called by SIOCGIWSTATS |
| 10124 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10125 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10126 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10127 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10128 | struct iw_statistics *wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10129 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10130 | wstats = &priv->wstats; |
| 10131 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10132 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10133 | * netdev->get_wireless_stats seems to be called before fw is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10134 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
| 10135 | * and associated; if not associcated, the values are all meaningless |
| 10136 | * anyway, so set them all to NULL and INVALID */ |
| 10137 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 10138 | wstats->miss.beacon = 0; |
| 10139 | wstats->discard.retries = 0; |
| 10140 | wstats->qual.qual = 0; |
| 10141 | wstats->qual.level = 0; |
| 10142 | wstats->qual.noise = 0; |
| 10143 | wstats->qual.updated = 7; |
| 10144 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10145 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10146 | return wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10147 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10148 | |
| 10149 | wstats->qual.qual = priv->quality; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 10150 | wstats->qual.level = priv->exp_avg_rssi; |
| 10151 | wstats->qual.noise = priv->exp_avg_noise; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10152 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 10153 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10154 | |
| 10155 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); |
| 10156 | wstats->discard.retries = priv->last_tx_failures; |
| 10157 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10158 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10159 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
| 10160 | goto fail_get_ordinal; |
| 10161 | wstats->discard.retries += tx_retry; */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10162 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10163 | return wstats; |
| 10164 | } |
| 10165 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10166 | /* net device stuff */ |
| 10167 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 10168 | static void init_sys_config(struct ipw_sys_config *sys_config) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10169 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10170 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10171 | sys_config->bt_coexistence = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10172 | sys_config->answer_broadcast_ssid_probe = 0; |
| 10173 | sys_config->accept_all_data_frames = 0; |
| 10174 | sys_config->accept_non_directed_frames = 1; |
| 10175 | sys_config->exclude_unicast_unencrypted = 0; |
| 10176 | sys_config->disable_unicast_decryption = 1; |
| 10177 | sys_config->exclude_multicast_unencrypted = 0; |
| 10178 | sys_config->disable_multicast_decryption = 1; |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 10179 | if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B) |
| 10180 | antenna = CFG_SYS_ANTENNA_BOTH; |
| 10181 | sys_config->antenna_diversity = antenna; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10182 | 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] | 10183 | sys_config->dot11g_auto_detection = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10184 | sys_config->enable_cts_to_self = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10185 | sys_config->bt_coexist_collision_thr = 0; |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 10186 | 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] | 10187 | sys_config->silence_threshold = 0x1e; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10188 | } |
| 10189 | |
| 10190 | static int ipw_net_open(struct net_device *dev) |
| 10191 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10192 | IPW_DEBUG_INFO("dev->open\n"); |
David S. Miller | 521c4d9 | 2008-07-22 18:32:47 -0700 | [diff] [blame] | 10193 | netif_start_queue(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10194 | return 0; |
| 10195 | } |
| 10196 | |
| 10197 | static int ipw_net_stop(struct net_device *dev) |
| 10198 | { |
| 10199 | IPW_DEBUG_INFO("dev->close\n"); |
| 10200 | netif_stop_queue(dev); |
| 10201 | return 0; |
| 10202 | } |
| 10203 | |
| 10204 | /* |
| 10205 | todo: |
| 10206 | |
| 10207 | 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] | 10208 | we need to heavily modify the libipw_skb_to_txb. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10209 | */ |
| 10210 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10211 | 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] | 10212 | int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10213 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10214 | struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10215 | txb->fragments[0]->data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10216 | int i = 0; |
| 10217 | struct tfd_frame *tfd; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10218 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10219 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10220 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10221 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10222 | struct clx2_tx_queue *txq = &priv->txq[0]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10223 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10224 | struct clx2_queue *q = &txq->q; |
| 10225 | u8 id, hdr_len, unicast; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10226 | int fc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10227 | |
Zhu Yi | b8ddafd | 2008-11-27 13:42:20 +0800 | [diff] [blame] | 10228 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 10229 | goto drop; |
| 10230 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10231 | hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10232 | switch (priv->ieee->iw_mode) { |
| 10233 | case IW_MODE_ADHOC: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10234 | unicast = !is_multicast_ether_addr(hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10235 | id = ipw_find_station(priv, hdr->addr1); |
| 10236 | if (id == IPW_INVALID_STATION) { |
| 10237 | id = ipw_add_station(priv, hdr->addr1); |
| 10238 | if (id == IPW_INVALID_STATION) { |
| 10239 | IPW_WARNING("Attempt to send data to " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 10240 | "invalid cell: %pM\n", |
| 10241 | hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10242 | goto drop; |
| 10243 | } |
| 10244 | } |
| 10245 | break; |
| 10246 | |
| 10247 | case IW_MODE_INFRA: |
| 10248 | default: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10249 | unicast = !is_multicast_ether_addr(hdr->addr3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10250 | id = 0; |
| 10251 | break; |
| 10252 | } |
| 10253 | |
| 10254 | tfd = &txq->bd[q->first_empty]; |
| 10255 | txq->txb[q->first_empty] = txb; |
| 10256 | memset(tfd, 0, sizeof(*tfd)); |
| 10257 | tfd->u.data.station_number = id; |
| 10258 | |
| 10259 | tfd->control_flags.message_type = TX_FRAME_TYPE; |
| 10260 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 10261 | |
| 10262 | tfd->u.data.cmd_id = DINO_CMD_TX; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10263 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10264 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10265 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10266 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10267 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10268 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10269 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10270 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
| 10271 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10272 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10273 | fc = le16_to_cpu(hdr->frame_ctl); |
| 10274 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10275 | |
| 10276 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); |
| 10277 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10278 | if (likely(unicast)) |
| 10279 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10280 | |
| 10281 | if (txb->encrypted && !priv->ieee->host_encrypt) { |
| 10282 | switch (priv->ieee->sec.level) { |
| 10283 | case SEC_LEVEL_3: |
| 10284 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10285 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10286 | /* XXX: ACK flag must be set for CCMP even if it |
| 10287 | * is a multicast/broadcast packet, because CCMP |
| 10288 | * group communication encrypted by GTK is |
| 10289 | * actually done by the AP. */ |
| 10290 | if (!unicast) |
| 10291 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10292 | |
| 10293 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10294 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; |
| 10295 | tfd->u.data.key_index = 0; |
| 10296 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10297 | break; |
| 10298 | case SEC_LEVEL_2: |
| 10299 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10300 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10301 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10302 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; |
| 10303 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10304 | break; |
| 10305 | case SEC_LEVEL_1: |
| 10306 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10307 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 10308 | tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx; |
| 10309 | if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <= |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10310 | 40) |
| 10311 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; |
| 10312 | else |
| 10313 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; |
| 10314 | break; |
| 10315 | case SEC_LEVEL_0: |
| 10316 | break; |
| 10317 | default: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10318 | printk(KERN_ERR "Unknown security level %d\n", |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10319 | priv->ieee->sec.level); |
| 10320 | break; |
| 10321 | } |
| 10322 | } else |
| 10323 | /* No hardware encryption */ |
| 10324 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; |
| 10325 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10326 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 10327 | if (fc & IEEE80211_STYPE_QOS_DATA) |
| 10328 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data)); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10329 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10330 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10331 | /* payload */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10332 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
| 10333 | txb->nr_frags)); |
| 10334 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", |
| 10335 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); |
| 10336 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { |
| 10337 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", |
| 10338 | i, le32_to_cpu(tfd->u.data.num_chunks), |
| 10339 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10340 | 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] | 10341 | i, tfd->u.data.num_chunks, |
| 10342 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10343 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10344 | txb->fragments[i]->len - hdr_len); |
| 10345 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10346 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10347 | cpu_to_le32(pci_map_single |
| 10348 | (priv->pci_dev, |
| 10349 | txb->fragments[i]->data + hdr_len, |
| 10350 | txb->fragments[i]->len - hdr_len, |
| 10351 | PCI_DMA_TODEVICE)); |
| 10352 | tfd->u.data.chunk_len[i] = |
| 10353 | cpu_to_le16(txb->fragments[i]->len - hdr_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10354 | } |
| 10355 | |
| 10356 | if (i != txb->nr_frags) { |
| 10357 | struct sk_buff *skb; |
| 10358 | u16 remaining_bytes = 0; |
| 10359 | int j; |
| 10360 | |
| 10361 | for (j = i; j < txb->nr_frags; j++) |
| 10362 | remaining_bytes += txb->fragments[j]->len - hdr_len; |
| 10363 | |
| 10364 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", |
| 10365 | remaining_bytes); |
| 10366 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); |
| 10367 | if (skb != NULL) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10368 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10369 | for (j = i; j < txb->nr_frags; j++) { |
| 10370 | int size = txb->fragments[j]->len - hdr_len; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10371 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10372 | printk(KERN_INFO "Adding frag %d %d...\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10373 | j, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10374 | memcpy(skb_put(skb, size), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10375 | txb->fragments[j]->data + hdr_len, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10376 | } |
| 10377 | dev_kfree_skb_any(txb->fragments[i]); |
| 10378 | txb->fragments[i] = skb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10379 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10380 | cpu_to_le32(pci_map_single |
| 10381 | (priv->pci_dev, skb->data, |
Al Viro | 4958730 | 2007-12-27 01:57:47 -0500 | [diff] [blame] | 10382 | remaining_bytes, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10383 | PCI_DMA_TODEVICE)); |
| 10384 | |
Marcin Slusarz | 5c05863 | 2008-02-13 00:06:12 +0100 | [diff] [blame] | 10385 | le32_add_cpu(&tfd->u.data.num_chunks, 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10386 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10387 | } |
| 10388 | |
| 10389 | /* kick DMA */ |
| 10390 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 10391 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 10392 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 10393 | if (ipw_tx_queue_space(q) < q->high_mark) |
James Ketrenos | f697014 | 2006-02-14 09:10:51 +0800 | [diff] [blame] | 10394 | netif_stop_queue(priv->net_dev); |
| 10395 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10396 | return NETDEV_TX_OK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10397 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10398 | drop: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10399 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10400 | libipw_txb_free(txb); |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10401 | return NETDEV_TX_OK; |
| 10402 | } |
| 10403 | |
| 10404 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) |
| 10405 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10406 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10407 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10408 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10409 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10410 | #else |
| 10411 | struct clx2_tx_queue *txq = &priv->txq[0]; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10412 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10413 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 10414 | if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark) |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10415 | return 1; |
| 10416 | |
| 10417 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10418 | } |
| 10419 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10420 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10421 | static void ipw_handle_promiscuous_tx(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10422 | struct libipw_txb *txb) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10423 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10424 | struct libipw_rx_stats dummystats; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10425 | struct ieee80211_hdr *hdr; |
| 10426 | u8 n; |
| 10427 | u16 filter = priv->prom_priv->filter; |
| 10428 | int hdr_only = 0; |
| 10429 | |
| 10430 | if (filter & IPW_PROM_NO_TX) |
| 10431 | return; |
| 10432 | |
| 10433 | memset(&dummystats, 0, sizeof(dummystats)); |
| 10434 | |
| 10435 | /* Filtering of fragment chains is done agains the first fragment */ |
| 10436 | hdr = (void *)txb->fragments[0]->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10437 | if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10438 | if (filter & IPW_PROM_NO_MGMT) |
| 10439 | return; |
| 10440 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 10441 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10442 | } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10443 | if (filter & IPW_PROM_NO_CTL) |
| 10444 | return; |
| 10445 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 10446 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10447 | } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10448 | if (filter & IPW_PROM_NO_DATA) |
| 10449 | return; |
| 10450 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 10451 | hdr_only = 1; |
| 10452 | } |
| 10453 | |
| 10454 | for(n=0; n<txb->nr_frags; ++n) { |
| 10455 | struct sk_buff *src = txb->fragments[n]; |
| 10456 | struct sk_buff *dst; |
| 10457 | struct ieee80211_radiotap_header *rt_hdr; |
| 10458 | int len; |
| 10459 | |
| 10460 | if (hdr_only) { |
| 10461 | hdr = (void *)src->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10462 | len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10463 | } else |
| 10464 | len = src->len; |
| 10465 | |
Johannes Berg | 007e5dd | 2008-11-27 23:13:38 +0100 | [diff] [blame] | 10466 | dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC); |
| 10467 | if (!dst) |
| 10468 | continue; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10469 | |
| 10470 | rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr)); |
| 10471 | |
| 10472 | rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION; |
| 10473 | rt_hdr->it_pad = 0; |
| 10474 | rt_hdr->it_present = 0; /* after all, it's just an idea */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 10475 | rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10476 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10477 | *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16( |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10478 | ieee80211chan2mhz(priv->channel)); |
| 10479 | if (priv->channel > 14) /* 802.11a */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10480 | *(__le16*)skb_put(dst, sizeof(u16)) = |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10481 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10482 | IEEE80211_CHAN_5GHZ); |
| 10483 | else if (priv->ieee->mode == IEEE_B) /* 802.11b */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10484 | *(__le16*)skb_put(dst, sizeof(u16)) = |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10485 | cpu_to_le16(IEEE80211_CHAN_CCK | |
| 10486 | IEEE80211_CHAN_2GHZ); |
| 10487 | else /* 802.11g */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10488 | *(__le16*)skb_put(dst, sizeof(u16)) = |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10489 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10490 | IEEE80211_CHAN_2GHZ); |
| 10491 | |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 10492 | rt_hdr->it_len = cpu_to_le16(dst->len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10493 | |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 10494 | skb_copy_from_linear_data(src, skb_put(dst, len), len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10495 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10496 | if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats)) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10497 | dev_kfree_skb_any(dst); |
| 10498 | } |
| 10499 | } |
| 10500 | #endif |
| 10501 | |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 10502 | static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb, |
| 10503 | struct net_device *dev, int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10504 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10505 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10506 | unsigned long flags; |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 10507 | netdev_tx_t ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10508 | |
| 10509 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10510 | spin_lock_irqsave(&priv->lock, flags); |
| 10511 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10512 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10513 | if (rtap_iface && netif_running(priv->prom_net_dev)) |
| 10514 | ipw_handle_promiscuous_tx(priv, txb); |
| 10515 | #endif |
| 10516 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10517 | ret = ipw_tx_skb(priv, txb, pri); |
| 10518 | if (ret == NETDEV_TX_OK) |
| 10519 | __ipw_led_activity_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10520 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10521 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10522 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10523 | } |
| 10524 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10525 | static void ipw_net_set_multicast_list(struct net_device *dev) |
| 10526 | { |
| 10527 | |
| 10528 | } |
| 10529 | |
| 10530 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) |
| 10531 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10532 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10533 | struct sockaddr *addr = p; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 10534 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10535 | if (!is_valid_ether_addr(addr->sa_data)) |
| 10536 | return -EADDRNOTAVAIL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10537 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10538 | priv->config |= CFG_CUSTOM_MAC; |
| 10539 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 10540 | printk(KERN_INFO "%s: Setting MAC to %pM\n", |
| 10541 | priv->net_dev->name, priv->mac_addr); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10542 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10543 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10544 | return 0; |
| 10545 | } |
| 10546 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10547 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10548 | struct ethtool_drvinfo *info) |
| 10549 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10550 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10551 | char vers[64]; |
| 10552 | char date[32]; |
| 10553 | u32 len; |
| 10554 | |
| 10555 | strcpy(info->driver, DRV_NAME); |
| 10556 | strcpy(info->version, DRV_VERSION); |
| 10557 | |
| 10558 | len = sizeof(vers); |
| 10559 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); |
| 10560 | len = sizeof(date); |
| 10561 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); |
| 10562 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10563 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10564 | vers, date); |
| 10565 | strcpy(info->bus_info, pci_name(p->pci_dev)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10566 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10567 | } |
| 10568 | |
| 10569 | static u32 ipw_ethtool_get_link(struct net_device *dev) |
| 10570 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10571 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10572 | return (priv->status & STATUS_ASSOCIATED) != 0; |
| 10573 | } |
| 10574 | |
| 10575 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) |
| 10576 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10577 | return IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10578 | } |
| 10579 | |
| 10580 | static int ipw_ethtool_get_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10581 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10582 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10583 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10584 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10585 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10586 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10587 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10588 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10589 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10590 | return 0; |
| 10591 | } |
| 10592 | |
| 10593 | static int ipw_ethtool_set_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10594 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10595 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10596 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10597 | int i; |
| 10598 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10599 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10600 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10601 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10602 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
Adrian Bunk | 71e585f | 2006-03-11 04:42:58 +0100 | [diff] [blame] | 10603 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
| 10604 | ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10605 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10606 | return 0; |
| 10607 | } |
| 10608 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 10609 | static const struct ethtool_ops ipw_ethtool_ops = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10610 | .get_link = ipw_ethtool_get_link, |
| 10611 | .get_drvinfo = ipw_ethtool_get_drvinfo, |
| 10612 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, |
| 10613 | .get_eeprom = ipw_ethtool_get_eeprom, |
| 10614 | .set_eeprom = ipw_ethtool_set_eeprom, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10615 | }; |
| 10616 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 10617 | static irqreturn_t ipw_isr(int irq, void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10618 | { |
| 10619 | struct ipw_priv *priv = data; |
| 10620 | u32 inta, inta_mask; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10621 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10622 | if (!priv) |
| 10623 | return IRQ_NONE; |
| 10624 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10625 | spin_lock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10626 | |
| 10627 | if (!(priv->status & STATUS_INT_ENABLED)) { |
Zhu Yi | d00d012 | 2007-07-12 16:09:40 +0800 | [diff] [blame] | 10628 | /* IRQ is disabled */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10629 | goto none; |
| 10630 | } |
| 10631 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10632 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 10633 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10634 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10635 | if (inta == 0xFFFFFFFF) { |
| 10636 | /* Hardware disappeared */ |
| 10637 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); |
| 10638 | goto none; |
| 10639 | } |
| 10640 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10641 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10642 | /* Shared interrupt */ |
| 10643 | goto none; |
| 10644 | } |
| 10645 | |
| 10646 | /* tell the device to stop sending interrupts */ |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10647 | __ipw_disable_interrupts(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10648 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10649 | /* ack current interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10650 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
| 10651 | ipw_write32(priv, IPW_INTA_RW, inta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10652 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10653 | /* Cache INTA value for our tasklet */ |
| 10654 | priv->isr_inta = inta; |
| 10655 | |
| 10656 | tasklet_schedule(&priv->irq_tasklet); |
| 10657 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10658 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10659 | |
| 10660 | return IRQ_HANDLED; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10661 | none: |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10662 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10663 | return IRQ_NONE; |
| 10664 | } |
| 10665 | |
| 10666 | static void ipw_rf_kill(void *adapter) |
| 10667 | { |
| 10668 | struct ipw_priv *priv = adapter; |
| 10669 | unsigned long flags; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10670 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10671 | spin_lock_irqsave(&priv->lock, flags); |
| 10672 | |
| 10673 | if (rf_kill_active(priv)) { |
| 10674 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); |
| 10675 | if (priv->workqueue) |
| 10676 | queue_delayed_work(priv->workqueue, |
| 10677 | &priv->rf_kill, 2 * HZ); |
| 10678 | goto exit_unlock; |
| 10679 | } |
| 10680 | |
| 10681 | /* RF Kill is now disabled, so bring the device back up */ |
| 10682 | |
| 10683 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 10684 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " |
| 10685 | "device\n"); |
| 10686 | |
| 10687 | /* we can not do an adapter restart while inside an irq lock */ |
| 10688 | queue_work(priv->workqueue, &priv->adapter_restart); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10689 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10690 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
| 10691 | "enabled\n"); |
| 10692 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10693 | exit_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10694 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10695 | } |
| 10696 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10697 | static void ipw_bg_rf_kill(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10698 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10699 | struct ipw_priv *priv = |
| 10700 | container_of(work, struct ipw_priv, rf_kill.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10701 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10702 | ipw_rf_kill(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10703 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10704 | } |
| 10705 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10706 | static void ipw_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10707 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10708 | priv->last_seq_num = -1; |
| 10709 | priv->last_frag_num = -1; |
| 10710 | priv->last_packet_time = 0; |
| 10711 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10712 | netif_carrier_on(priv->net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10713 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10714 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10715 | cancel_delayed_work(&priv->request_direct_scan); |
| 10716 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10717 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10718 | ipw_reset_stats(priv); |
| 10719 | /* Ensure the rate is updated immediately */ |
| 10720 | priv->last_rate = ipw_get_current_rate(priv); |
| 10721 | ipw_gather_stats(priv); |
| 10722 | ipw_led_link_up(priv); |
| 10723 | notify_wx_assoc_event(priv); |
| 10724 | |
| 10725 | if (priv->config & CFG_BACKGROUND_SCAN) |
| 10726 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); |
| 10727 | } |
| 10728 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10729 | static void ipw_bg_link_up(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10730 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10731 | struct ipw_priv *priv = |
| 10732 | container_of(work, struct ipw_priv, link_up); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10733 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10734 | ipw_link_up(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10735 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10736 | } |
| 10737 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10738 | static void ipw_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10739 | { |
| 10740 | ipw_led_link_down(priv); |
| 10741 | netif_carrier_off(priv->net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10742 | notify_wx_assoc_event(priv); |
| 10743 | |
| 10744 | /* Cancel any queued work ... */ |
| 10745 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10746 | cancel_delayed_work(&priv->request_direct_scan); |
| 10747 | cancel_delayed_work(&priv->request_passive_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10748 | cancel_delayed_work(&priv->adhoc_check); |
| 10749 | cancel_delayed_work(&priv->gather_stats); |
| 10750 | |
| 10751 | ipw_reset_stats(priv); |
| 10752 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10753 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
| 10754 | /* Queue up another scan... */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10755 | queue_delayed_work(priv->workqueue, &priv->request_scan, 0); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10756 | } else |
| 10757 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10758 | } |
| 10759 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10760 | static void ipw_bg_link_down(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10761 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10762 | struct ipw_priv *priv = |
| 10763 | container_of(work, struct ipw_priv, link_down); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10764 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10765 | ipw_link_down(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10766 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10767 | } |
| 10768 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 10769 | static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10770 | { |
| 10771 | int ret = 0; |
| 10772 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10773 | priv->workqueue = create_workqueue(DRV_NAME); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10774 | init_waitqueue_head(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10775 | init_waitqueue_head(&priv->wait_state); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10776 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10777 | INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check); |
| 10778 | INIT_WORK(&priv->associate, ipw_bg_associate); |
| 10779 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate); |
| 10780 | INIT_WORK(&priv->system_config, ipw_system_config); |
| 10781 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish); |
| 10782 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart); |
| 10783 | INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill); |
| 10784 | INIT_WORK(&priv->up, ipw_bg_up); |
| 10785 | INIT_WORK(&priv->down, ipw_bg_down); |
| 10786 | INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10787 | INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan); |
| 10788 | INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10789 | INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10790 | INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats); |
| 10791 | INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan); |
| 10792 | INIT_WORK(&priv->roam, ipw_bg_roam); |
| 10793 | INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check); |
| 10794 | INIT_WORK(&priv->link_up, ipw_bg_link_up); |
| 10795 | INIT_WORK(&priv->link_down, ipw_bg_link_down); |
| 10796 | INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on); |
| 10797 | INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off); |
| 10798 | INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off); |
| 10799 | INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10800 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10801 | #ifdef CONFIG_IPW2200_QOS |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10802 | INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10803 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10804 | |
| 10805 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 10806 | ipw_irq_tasklet, (unsigned long)priv); |
| 10807 | |
| 10808 | return ret; |
| 10809 | } |
| 10810 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10811 | static void shim__set_security(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10812 | struct libipw_security *sec) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10813 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10814 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10815 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10816 | for (i = 0; i < 4; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10817 | if (sec->flags & (1 << i)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10818 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10819 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10820 | if (sec->key_sizes[i] == 0) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10821 | priv->ieee->sec.flags &= ~(1 << i); |
| 10822 | else { |
| 10823 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10824 | sec->key_sizes[i]); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10825 | priv->ieee->sec.flags |= (1 << i); |
| 10826 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10827 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10828 | } else if (sec->level != SEC_LEVEL_1) |
| 10829 | priv->ieee->sec.flags &= ~(1 << i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10830 | } |
| 10831 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10832 | if (sec->flags & SEC_ACTIVE_KEY) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10833 | if (sec->active_key <= 3) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10834 | priv->ieee->sec.active_key = sec->active_key; |
| 10835 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10836 | } else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10837 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10838 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10839 | } else |
| 10840 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10841 | |
| 10842 | if ((sec->flags & SEC_AUTH_MODE) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10843 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
| 10844 | priv->ieee->sec.auth_mode = sec->auth_mode; |
| 10845 | priv->ieee->sec.flags |= SEC_AUTH_MODE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10846 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
| 10847 | priv->capability |= CAP_SHARED_KEY; |
| 10848 | else |
| 10849 | priv->capability &= ~CAP_SHARED_KEY; |
| 10850 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10851 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10852 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10853 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
| 10854 | priv->ieee->sec.flags |= SEC_ENABLED; |
| 10855 | priv->ieee->sec.enabled = sec->enabled; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10856 | priv->status |= STATUS_SECURITY_UPDATED; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10857 | if (sec->enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10858 | priv->capability |= CAP_PRIVACY_ON; |
| 10859 | else |
| 10860 | priv->capability &= ~CAP_PRIVACY_ON; |
| 10861 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10862 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10863 | if (sec->flags & SEC_ENCRYPT) |
| 10864 | priv->ieee->sec.encrypt = sec->encrypt; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10865 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10866 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
| 10867 | priv->ieee->sec.level = sec->level; |
| 10868 | priv->ieee->sec.flags |= SEC_LEVEL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10869 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10870 | } |
| 10871 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 10872 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
| 10873 | ipw_set_hwcrypto_keys(priv); |
| 10874 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10875 | /* To match current functionality of ipw2100 (which works well w/ |
| 10876 | * various supplicants, we don't force a disassociate if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10877 | * privacy capability changes ... */ |
| 10878 | #if 0 |
| 10879 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10880 | (((priv->assoc_request.capability & |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 10881 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10882 | (!(priv->assoc_request.capability & |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 10883 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10884 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
| 10885 | "change.\n"); |
| 10886 | ipw_disassociate(priv); |
| 10887 | } |
| 10888 | #endif |
| 10889 | } |
| 10890 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10891 | static int init_supported_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10892 | struct ipw_supported_rates *rates) |
| 10893 | { |
| 10894 | /* TODO: Mask out rates based on priv->rates_mask */ |
| 10895 | |
| 10896 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10897 | /* configure supported rates */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10898 | switch (priv->ieee->freq_band) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10899 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10900 | rates->ieee_mode = IPW_A_MODE; |
| 10901 | rates->purpose = IPW_RATE_CAPABILITIES; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10902 | ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10903 | LIBIPW_OFDM_DEFAULT_RATES_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10904 | break; |
| 10905 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10906 | default: /* Mixed or 2.4Ghz */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10907 | rates->ieee_mode = IPW_G_MODE; |
| 10908 | rates->purpose = IPW_RATE_CAPABILITIES; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10909 | ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10910 | LIBIPW_CCK_DEFAULT_RATES_MASK); |
| 10911 | if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) { |
| 10912 | ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10913 | LIBIPW_OFDM_DEFAULT_RATES_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10914 | } |
| 10915 | break; |
| 10916 | } |
| 10917 | |
| 10918 | return 0; |
| 10919 | } |
| 10920 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10921 | static int ipw_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10922 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10923 | /* This is only called from ipw_up, which resets/reloads the firmware |
| 10924 | so, we don't need to first disable the card before we configure |
| 10925 | it */ |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 10926 | if (ipw_set_tx_power(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10927 | goto error; |
| 10928 | |
| 10929 | /* initialize adapter address */ |
| 10930 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) |
| 10931 | goto error; |
| 10932 | |
| 10933 | /* set basic system config settings */ |
| 10934 | init_sys_config(&priv->sys_config); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10935 | |
| 10936 | /* Support Bluetooth if we have BT h/w on board, and user wants to. |
| 10937 | * Does not support BT priority yet (don't abort or defer our Tx) */ |
| 10938 | if (bt_coexist) { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10939 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10940 | |
| 10941 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) |
| 10942 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10943 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10944 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
| 10945 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10946 | |= CFG_BT_COEXISTENCE_OOB; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10947 | } |
| 10948 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10949 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10950 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 10951 | priv->sys_config.accept_all_data_frames = 1; |
| 10952 | priv->sys_config.accept_non_directed_frames = 1; |
| 10953 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 10954 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 10955 | } |
| 10956 | #endif |
| 10957 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10958 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 10959 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 10960 | else |
| 10961 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 10962 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10963 | if (ipw_send_system_config(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10964 | goto error; |
| 10965 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10966 | init_supported_rates(priv, &priv->rates); |
| 10967 | if (ipw_send_supported_rates(priv, &priv->rates)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10968 | goto error; |
| 10969 | |
| 10970 | /* Set request-to-send threshold */ |
| 10971 | if (priv->rts_threshold) { |
| 10972 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) |
| 10973 | goto error; |
| 10974 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10975 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10976 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
| 10977 | ipw_qos_activate(priv, NULL); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10978 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10979 | |
| 10980 | if (ipw_set_random_seed(priv)) |
| 10981 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10982 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10983 | /* final state transition to the RUN state */ |
| 10984 | if (ipw_send_host_complete(priv)) |
| 10985 | goto error; |
| 10986 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10987 | priv->status |= STATUS_INIT; |
| 10988 | |
| 10989 | ipw_led_init(priv); |
| 10990 | ipw_led_radio_on(priv); |
| 10991 | priv->notif_missed_beacons = 0; |
| 10992 | |
| 10993 | /* Set hardware WEP key if it is configured. */ |
| 10994 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 10995 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 10996 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 10997 | ipw_set_hwcrypto_keys(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10998 | |
| 10999 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11000 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11001 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11002 | return -EIO; |
| 11003 | } |
| 11004 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11005 | /* |
| 11006 | * NOTE: |
| 11007 | * |
| 11008 | * These tables have been tested in conjunction with the |
| 11009 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. |
| 11010 | * |
| 11011 | * Altering this values, using it on other hardware, or in geographies |
| 11012 | * not intended for resale of the above mentioned Intel adapters has |
| 11013 | * not been tested. |
| 11014 | * |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11015 | * Remember to update the table in README.ipw2200 when changing this |
| 11016 | * table. |
| 11017 | * |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11018 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11019 | static const struct libipw_geo ipw_geos[] = { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11020 | { /* Restricted */ |
| 11021 | "---", |
| 11022 | .bg_channels = 11, |
| 11023 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11024 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11025 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11026 | {2457, 10}, {2462, 11}}, |
| 11027 | }, |
| 11028 | |
| 11029 | { /* Custom US/Canada */ |
| 11030 | "ZZF", |
| 11031 | .bg_channels = 11, |
| 11032 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11033 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11034 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11035 | {2457, 10}, {2462, 11}}, |
| 11036 | .a_channels = 8, |
| 11037 | .a = {{5180, 36}, |
| 11038 | {5200, 40}, |
| 11039 | {5220, 44}, |
| 11040 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11041 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11042 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11043 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11044 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11045 | }, |
| 11046 | |
| 11047 | { /* Rest of World */ |
| 11048 | "ZZD", |
| 11049 | .bg_channels = 13, |
| 11050 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11051 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11052 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11053 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11054 | {2472, 13}}, |
| 11055 | }, |
| 11056 | |
| 11057 | { /* Custom USA & Europe & High */ |
| 11058 | "ZZA", |
| 11059 | .bg_channels = 11, |
| 11060 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11061 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11062 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11063 | {2457, 10}, {2462, 11}}, |
| 11064 | .a_channels = 13, |
| 11065 | .a = {{5180, 36}, |
| 11066 | {5200, 40}, |
| 11067 | {5220, 44}, |
| 11068 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11069 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11070 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11071 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11072 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11073 | {5745, 149}, |
| 11074 | {5765, 153}, |
| 11075 | {5785, 157}, |
| 11076 | {5805, 161}, |
| 11077 | {5825, 165}}, |
| 11078 | }, |
| 11079 | |
| 11080 | { /* Custom NA & Europe */ |
| 11081 | "ZZB", |
| 11082 | .bg_channels = 11, |
| 11083 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11084 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11085 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11086 | {2457, 10}, {2462, 11}}, |
| 11087 | .a_channels = 13, |
| 11088 | .a = {{5180, 36}, |
| 11089 | {5200, 40}, |
| 11090 | {5220, 44}, |
| 11091 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11092 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11093 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11094 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11095 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11096 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11097 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11098 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11099 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11100 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11101 | }, |
| 11102 | |
| 11103 | { /* Custom Japan */ |
| 11104 | "ZZC", |
| 11105 | .bg_channels = 11, |
| 11106 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11107 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11108 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11109 | {2457, 10}, {2462, 11}}, |
| 11110 | .a_channels = 4, |
| 11111 | .a = {{5170, 34}, {5190, 38}, |
| 11112 | {5210, 42}, {5230, 46}}, |
| 11113 | }, |
| 11114 | |
| 11115 | { /* Custom */ |
| 11116 | "ZZM", |
| 11117 | .bg_channels = 11, |
| 11118 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11119 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11120 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11121 | {2457, 10}, {2462, 11}}, |
| 11122 | }, |
| 11123 | |
| 11124 | { /* Europe */ |
| 11125 | "ZZE", |
| 11126 | .bg_channels = 13, |
| 11127 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11128 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11129 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11130 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11131 | {2472, 13}}, |
| 11132 | .a_channels = 19, |
| 11133 | .a = {{5180, 36}, |
| 11134 | {5200, 40}, |
| 11135 | {5220, 44}, |
| 11136 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11137 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11138 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11139 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11140 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11141 | {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, |
| 11142 | {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, |
| 11143 | {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, |
| 11144 | {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, |
| 11145 | {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, |
| 11146 | {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, |
| 11147 | {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, |
| 11148 | {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, |
| 11149 | {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, |
| 11150 | {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, |
| 11151 | {5700, 140, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11152 | }, |
| 11153 | |
| 11154 | { /* Custom Japan */ |
| 11155 | "ZZJ", |
| 11156 | .bg_channels = 14, |
| 11157 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11158 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11159 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11160 | {2457, 10}, {2462, 11}, {2467, 12}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11161 | {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11162 | .a_channels = 4, |
| 11163 | .a = {{5170, 34}, {5190, 38}, |
| 11164 | {5210, 42}, {5230, 46}}, |
| 11165 | }, |
| 11166 | |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11167 | { /* Rest of World */ |
| 11168 | "ZZR", |
| 11169 | .bg_channels = 14, |
| 11170 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11171 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11172 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11173 | {2457, 10}, {2462, 11}, {2467, 12}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11174 | {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY | |
| 11175 | LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11176 | }, |
| 11177 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11178 | { /* High Band */ |
| 11179 | "ZZH", |
| 11180 | .bg_channels = 13, |
| 11181 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11182 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11183 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11184 | {2457, 10}, {2462, 11}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11185 | {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, |
| 11186 | {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11187 | .a_channels = 4, |
| 11188 | .a = {{5745, 149}, {5765, 153}, |
| 11189 | {5785, 157}, {5805, 161}}, |
| 11190 | }, |
| 11191 | |
| 11192 | { /* Custom Europe */ |
| 11193 | "ZZG", |
| 11194 | .bg_channels = 13, |
| 11195 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11196 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11197 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11198 | {2457, 10}, {2462, 11}, |
| 11199 | {2467, 12}, {2472, 13}}, |
| 11200 | .a_channels = 4, |
| 11201 | .a = {{5180, 36}, {5200, 40}, |
| 11202 | {5220, 44}, {5240, 48}}, |
| 11203 | }, |
| 11204 | |
| 11205 | { /* Europe */ |
| 11206 | "ZZK", |
| 11207 | .bg_channels = 13, |
| 11208 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11209 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11210 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11211 | {2457, 10}, {2462, 11}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11212 | {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, |
| 11213 | {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11214 | .a_channels = 24, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11215 | .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, |
| 11216 | {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, |
| 11217 | {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, |
| 11218 | {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, |
| 11219 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11220 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11221 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11222 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11223 | {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, |
| 11224 | {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, |
| 11225 | {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, |
| 11226 | {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, |
| 11227 | {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, |
| 11228 | {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, |
| 11229 | {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, |
| 11230 | {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, |
| 11231 | {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, |
| 11232 | {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, |
| 11233 | {5700, 140, LIBIPW_CH_PASSIVE_ONLY}, |
| 11234 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11235 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11236 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11237 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11238 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11239 | }, |
| 11240 | |
| 11241 | { /* Europe */ |
| 11242 | "ZZL", |
| 11243 | .bg_channels = 11, |
| 11244 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11245 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11246 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11247 | {2457, 10}, {2462, 11}}, |
| 11248 | .a_channels = 13, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11249 | .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, |
| 11250 | {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, |
| 11251 | {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, |
| 11252 | {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, |
| 11253 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11254 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11255 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11256 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11257 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11258 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11259 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11260 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11261 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11262 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11263 | }; |
| 11264 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11265 | #define MAX_HW_RESTARTS 5 |
| 11266 | static int ipw_up(struct ipw_priv *priv) |
| 11267 | { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11268 | int rc, i, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11269 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11270 | /* Age scan list entries found before suspend */ |
| 11271 | if (priv->suspend_time) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11272 | libipw_networks_age(priv->ieee, priv->suspend_time); |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11273 | priv->suspend_time = 0; |
| 11274 | } |
| 11275 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11276 | if (priv->status & STATUS_EXIT_PENDING) |
| 11277 | return -EIO; |
| 11278 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11279 | if (cmdlog && !priv->cmdlog) { |
Yan Burman | e6e3f12 | 2006-12-02 13:38:14 +0200 | [diff] [blame] | 11280 | priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog), |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11281 | GFP_KERNEL); |
| 11282 | if (priv->cmdlog == NULL) { |
| 11283 | IPW_ERROR("Error allocating %d command log entries.\n", |
| 11284 | cmdlog); |
Zhu Yi | d0b526b | 2006-04-13 17:19:50 +0800 | [diff] [blame] | 11285 | return -ENOMEM; |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11286 | } else { |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11287 | priv->cmdlog_len = cmdlog; |
| 11288 | } |
| 11289 | } |
| 11290 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11291 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11292 | /* Load the microcode, firmware, and eeprom. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11293 | * Also start the clocks. */ |
| 11294 | rc = ipw_load(priv); |
| 11295 | if (rc) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 11296 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11297 | return rc; |
| 11298 | } |
| 11299 | |
| 11300 | ipw_init_ordinals(priv); |
| 11301 | if (!(priv->config & CFG_CUSTOM_MAC)) |
| 11302 | eeprom_parse_mac(priv, priv->mac_addr); |
| 11303 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
John W. Linville | 5e5eab5 | 2009-10-06 16:45:14 -0400 | [diff] [blame] | 11304 | memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11305 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11306 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
| 11307 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], |
| 11308 | ipw_geos[j].name, 3)) |
| 11309 | break; |
| 11310 | } |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11311 | if (j == ARRAY_SIZE(ipw_geos)) { |
| 11312 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", |
| 11313 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], |
| 11314 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], |
| 11315 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11316 | j = 0; |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11317 | } |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11318 | if (libipw_set_geo(priv->ieee, &ipw_geos[j])) { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11319 | IPW_WARNING("Could not set geography."); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11320 | return 0; |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11321 | } |
| 11322 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11323 | if (priv->status & STATUS_RF_KILL_SW) { |
| 11324 | IPW_WARNING("Radio disabled by module parameter.\n"); |
| 11325 | return 0; |
| 11326 | } else if (rf_kill_active(priv)) { |
| 11327 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" |
| 11328 | "Kill switch must be turned off for " |
| 11329 | "wireless networking to work.\n"); |
| 11330 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
| 11331 | 2 * HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11332 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11333 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11334 | |
| 11335 | rc = ipw_config(priv); |
| 11336 | if (!rc) { |
| 11337 | IPW_DEBUG_INFO("Configured device on count %i\n", i); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11338 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 11339 | /* If configure to try and auto-associate, kick |
| 11340 | * off a scan. */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11341 | queue_delayed_work(priv->workqueue, |
| 11342 | &priv->request_scan, 0); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11343 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11344 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11345 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11346 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11347 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11348 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
| 11349 | i, MAX_HW_RESTARTS); |
| 11350 | |
| 11351 | /* We had an error bringing up the hardware, so take it |
| 11352 | * all the way back down so we can try again */ |
| 11353 | ipw_down(priv); |
| 11354 | } |
| 11355 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11356 | /* tried to restart and config the device for as long as our |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11357 | * patience could withstand */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11358 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11359 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11360 | return -EIO; |
| 11361 | } |
| 11362 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11363 | static void ipw_bg_up(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11364 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11365 | struct ipw_priv *priv = |
| 11366 | container_of(work, struct ipw_priv, up); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11367 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11368 | ipw_up(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11369 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11370 | } |
| 11371 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11372 | static void ipw_deinit(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11373 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11374 | int i; |
| 11375 | |
| 11376 | if (priv->status & STATUS_SCANNING) { |
| 11377 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); |
| 11378 | ipw_abort_scan(priv); |
| 11379 | } |
| 11380 | |
| 11381 | if (priv->status & STATUS_ASSOCIATED) { |
| 11382 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); |
| 11383 | ipw_disassociate(priv); |
| 11384 | } |
| 11385 | |
| 11386 | ipw_led_shutdown(priv); |
| 11387 | |
| 11388 | /* Wait up to 1s for status to change to not scanning and not |
| 11389 | * associated (disassociation can take a while for a ful 802.11 |
| 11390 | * exchange */ |
| 11391 | for (i = 1000; i && (priv->status & |
| 11392 | (STATUS_DISASSOCIATING | |
| 11393 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) |
| 11394 | udelay(10); |
| 11395 | |
| 11396 | if (priv->status & (STATUS_DISASSOCIATING | |
| 11397 | STATUS_ASSOCIATED | STATUS_SCANNING)) |
| 11398 | IPW_DEBUG_INFO("Still associated or scanning...\n"); |
| 11399 | else |
| 11400 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); |
| 11401 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11402 | /* Attempt to disable the card */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11403 | ipw_send_card_disable(priv, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11404 | |
| 11405 | priv->status &= ~STATUS_INIT; |
| 11406 | } |
| 11407 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11408 | static void ipw_down(struct ipw_priv *priv) |
| 11409 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11410 | int exit_pending = priv->status & STATUS_EXIT_PENDING; |
| 11411 | |
| 11412 | priv->status |= STATUS_EXIT_PENDING; |
| 11413 | |
| 11414 | if (ipw_is_init(priv)) |
| 11415 | ipw_deinit(priv); |
| 11416 | |
| 11417 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 11418 | * exiting the module */ |
| 11419 | if (!exit_pending) |
| 11420 | priv->status &= ~STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11421 | |
| 11422 | /* tell the device to stop sending interrupts */ |
| 11423 | ipw_disable_interrupts(priv); |
| 11424 | |
| 11425 | /* Clear all bits but the RF Kill */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11426 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11427 | netif_carrier_off(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11428 | |
| 11429 | ipw_stop_nic(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11430 | |
| 11431 | ipw_led_radio_off(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11432 | } |
| 11433 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11434 | static void ipw_bg_down(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11435 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11436 | struct ipw_priv *priv = |
| 11437 | container_of(work, struct ipw_priv, down); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11438 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11439 | ipw_down(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11440 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11441 | } |
| 11442 | |
| 11443 | /* Called by register_netdev() */ |
| 11444 | static int ipw_net_init(struct net_device *dev) |
| 11445 | { |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11446 | int i, rc = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11447 | struct ipw_priv *priv = libipw_priv(dev); |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11448 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
| 11449 | struct wireless_dev *wdev = &priv->ieee->wdev; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11450 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11451 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11452 | if (ipw_up(priv)) { |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11453 | rc = -EIO; |
| 11454 | goto out; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11455 | } |
| 11456 | |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11457 | memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN); |
| 11458 | |
| 11459 | /* fill-out priv->ieee->bg_band */ |
| 11460 | if (geo->bg_channels) { |
| 11461 | struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band; |
| 11462 | |
| 11463 | bg_band->band = IEEE80211_BAND_2GHZ; |
| 11464 | bg_band->n_channels = geo->bg_channels; |
| 11465 | bg_band->channels = |
| 11466 | kzalloc(geo->bg_channels * |
| 11467 | sizeof(struct ieee80211_channel), GFP_KERNEL); |
| 11468 | /* translate geo->bg to bg_band.channels */ |
| 11469 | for (i = 0; i < geo->bg_channels; i++) { |
| 11470 | bg_band->channels[i].band = IEEE80211_BAND_2GHZ; |
| 11471 | bg_band->channels[i].center_freq = geo->bg[i].freq; |
| 11472 | bg_band->channels[i].hw_value = geo->bg[i].channel; |
| 11473 | bg_band->channels[i].max_power = geo->bg[i].max_power; |
| 11474 | if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) |
| 11475 | bg_band->channels[i].flags |= |
| 11476 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 11477 | if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS) |
| 11478 | bg_band->channels[i].flags |= |
| 11479 | IEEE80211_CHAN_NO_IBSS; |
| 11480 | if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT) |
| 11481 | bg_band->channels[i].flags |= |
| 11482 | IEEE80211_CHAN_RADAR; |
| 11483 | /* No equivalent for LIBIPW_CH_80211H_RULES, |
| 11484 | LIBIPW_CH_UNIFORM_SPREADING, or |
| 11485 | LIBIPW_CH_B_ONLY... */ |
| 11486 | } |
| 11487 | /* point at bitrate info */ |
| 11488 | bg_band->bitrates = ipw2200_bg_rates; |
| 11489 | bg_band->n_bitrates = ipw2200_num_bg_rates; |
| 11490 | |
| 11491 | wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band; |
| 11492 | } |
| 11493 | |
| 11494 | /* fill-out priv->ieee->a_band */ |
| 11495 | if (geo->a_channels) { |
| 11496 | struct ieee80211_supported_band *a_band = &priv->ieee->a_band; |
| 11497 | |
| 11498 | a_band->band = IEEE80211_BAND_5GHZ; |
| 11499 | a_band->n_channels = geo->a_channels; |
| 11500 | a_band->channels = |
| 11501 | kzalloc(geo->a_channels * |
| 11502 | sizeof(struct ieee80211_channel), GFP_KERNEL); |
| 11503 | /* translate geo->bg to a_band.channels */ |
| 11504 | for (i = 0; i < geo->a_channels; i++) { |
| 11505 | a_band->channels[i].band = IEEE80211_BAND_2GHZ; |
| 11506 | a_band->channels[i].center_freq = geo->a[i].freq; |
| 11507 | a_band->channels[i].hw_value = geo->a[i].channel; |
| 11508 | a_band->channels[i].max_power = geo->a[i].max_power; |
| 11509 | if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) |
| 11510 | a_band->channels[i].flags |= |
| 11511 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 11512 | if (geo->a[i].flags & LIBIPW_CH_NO_IBSS) |
| 11513 | a_band->channels[i].flags |= |
| 11514 | IEEE80211_CHAN_NO_IBSS; |
| 11515 | if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT) |
| 11516 | a_band->channels[i].flags |= |
| 11517 | IEEE80211_CHAN_RADAR; |
| 11518 | /* No equivalent for LIBIPW_CH_80211H_RULES, |
| 11519 | LIBIPW_CH_UNIFORM_SPREADING, or |
| 11520 | LIBIPW_CH_B_ONLY... */ |
| 11521 | } |
| 11522 | /* point at bitrate info */ |
| 11523 | a_band->bitrates = ipw2200_a_rates; |
| 11524 | a_band->n_bitrates = ipw2200_num_a_rates; |
| 11525 | |
| 11526 | wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band; |
| 11527 | } |
| 11528 | |
| 11529 | set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev); |
| 11530 | |
| 11531 | /* With that information in place, we can now register the wiphy... */ |
| 11532 | if (wiphy_register(wdev->wiphy)) { |
| 11533 | rc = -EIO; |
| 11534 | goto out; |
| 11535 | } |
| 11536 | |
| 11537 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11538 | mutex_unlock(&priv->mutex); |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11539 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11540 | } |
| 11541 | |
| 11542 | /* PCI driver stuff */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 11543 | static DEFINE_PCI_DEVICE_TABLE(card_ids) = { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11544 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
| 11545 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, |
| 11546 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, |
| 11547 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, |
| 11548 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, |
| 11549 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, |
| 11550 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, |
| 11551 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, |
| 11552 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, |
| 11553 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, |
| 11554 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, |
| 11555 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, |
| 11556 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, |
| 11557 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, |
| 11558 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, |
| 11559 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, |
| 11560 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, |
Joe Perches | 8ab0ea7 | 2009-06-24 22:13:27 -0700 | [diff] [blame] | 11561 | {PCI_VDEVICE(INTEL, 0x104f), 0}, |
| 11562 | {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */ |
| 11563 | {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */ |
| 11564 | {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */ |
| 11565 | {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11566 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11567 | /* required last entry */ |
| 11568 | {0,} |
| 11569 | }; |
| 11570 | |
| 11571 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 11572 | |
| 11573 | static struct attribute *ipw_sysfs_entries[] = { |
| 11574 | &dev_attr_rf_kill.attr, |
| 11575 | &dev_attr_direct_dword.attr, |
| 11576 | &dev_attr_indirect_byte.attr, |
| 11577 | &dev_attr_indirect_dword.attr, |
| 11578 | &dev_attr_mem_gpio_reg.attr, |
| 11579 | &dev_attr_command_event_reg.attr, |
| 11580 | &dev_attr_nic_type.attr, |
| 11581 | &dev_attr_status.attr, |
| 11582 | &dev_attr_cfg.attr, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 11583 | &dev_attr_error.attr, |
| 11584 | &dev_attr_event_log.attr, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11585 | &dev_attr_cmd_log.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11586 | &dev_attr_eeprom_delay.attr, |
| 11587 | &dev_attr_ucode_version.attr, |
| 11588 | &dev_attr_rtc.attr, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11589 | &dev_attr_scan_age.attr, |
| 11590 | &dev_attr_led.attr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11591 | &dev_attr_speed_scan.attr, |
| 11592 | &dev_attr_net_stats.attr, |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 11593 | &dev_attr_channels.attr, |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11594 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11595 | &dev_attr_rtap_iface.attr, |
| 11596 | &dev_attr_rtap_filter.attr, |
| 11597 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11598 | NULL |
| 11599 | }; |
| 11600 | |
| 11601 | static struct attribute_group ipw_attribute_group = { |
| 11602 | .name = NULL, /* put in device directory */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11603 | .attrs = ipw_sysfs_entries, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11604 | }; |
| 11605 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11606 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11607 | static int ipw_prom_open(struct net_device *dev) |
| 11608 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11609 | struct ipw_prom_priv *prom_priv = libipw_priv(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11610 | struct ipw_priv *priv = prom_priv->priv; |
| 11611 | |
| 11612 | IPW_DEBUG_INFO("prom dev->open\n"); |
| 11613 | netif_carrier_off(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11614 | |
| 11615 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11616 | priv->sys_config.accept_all_data_frames = 1; |
| 11617 | priv->sys_config.accept_non_directed_frames = 1; |
| 11618 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 11619 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 11620 | |
| 11621 | ipw_send_system_config(priv); |
| 11622 | } |
| 11623 | |
| 11624 | return 0; |
| 11625 | } |
| 11626 | |
| 11627 | static int ipw_prom_stop(struct net_device *dev) |
| 11628 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11629 | struct ipw_prom_priv *prom_priv = libipw_priv(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11630 | struct ipw_priv *priv = prom_priv->priv; |
| 11631 | |
| 11632 | IPW_DEBUG_INFO("prom dev->stop\n"); |
| 11633 | |
| 11634 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11635 | priv->sys_config.accept_all_data_frames = 0; |
| 11636 | priv->sys_config.accept_non_directed_frames = 0; |
| 11637 | priv->sys_config.accept_all_mgmt_bcpr = 0; |
| 11638 | priv->sys_config.accept_all_mgmt_frames = 0; |
| 11639 | |
| 11640 | ipw_send_system_config(priv); |
| 11641 | } |
| 11642 | |
| 11643 | return 0; |
| 11644 | } |
| 11645 | |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 11646 | static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb, |
| 11647 | struct net_device *dev) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11648 | { |
| 11649 | IPW_DEBUG_INFO("prom dev->xmit\n"); |
Patrick McHardy | 4153e77 | 2009-06-12 04:08:02 +0000 | [diff] [blame] | 11650 | dev_kfree_skb(skb); |
| 11651 | return NETDEV_TX_OK; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11652 | } |
| 11653 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11654 | static const struct net_device_ops ipw_prom_netdev_ops = { |
| 11655 | .ndo_open = ipw_prom_open, |
| 11656 | .ndo_stop = ipw_prom_stop, |
| 11657 | .ndo_start_xmit = ipw_prom_hard_start_xmit, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11658 | .ndo_change_mtu = libipw_change_mtu, |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11659 | .ndo_set_mac_address = eth_mac_addr, |
| 11660 | .ndo_validate_addr = eth_validate_addr, |
| 11661 | }; |
| 11662 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11663 | static int ipw_prom_alloc(struct ipw_priv *priv) |
| 11664 | { |
| 11665 | int rc = 0; |
| 11666 | |
| 11667 | if (priv->prom_net_dev) |
| 11668 | return -EPERM; |
| 11669 | |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11670 | priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv), 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11671 | if (priv->prom_net_dev == NULL) |
| 11672 | return -ENOMEM; |
| 11673 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11674 | priv->prom_priv = libipw_priv(priv->prom_net_dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11675 | priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev); |
| 11676 | priv->prom_priv->priv = priv; |
| 11677 | |
| 11678 | strcpy(priv->prom_net_dev->name, "rtap%d"); |
Daniel Drake | 3f2eeac | 2008-04-02 20:33:54 +0100 | [diff] [blame] | 11679 | memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11680 | |
| 11681 | priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11682 | priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11683 | |
| 11684 | priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR; |
Masakazu Mokuno | 229ce3a | 2008-05-14 14:16:50 +0900 | [diff] [blame] | 11685 | SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11686 | |
| 11687 | rc = register_netdev(priv->prom_net_dev); |
| 11688 | if (rc) { |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11689 | free_ieee80211(priv->prom_net_dev, 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11690 | priv->prom_net_dev = NULL; |
| 11691 | return rc; |
| 11692 | } |
| 11693 | |
| 11694 | return 0; |
| 11695 | } |
| 11696 | |
| 11697 | static void ipw_prom_free(struct ipw_priv *priv) |
| 11698 | { |
| 11699 | if (!priv->prom_net_dev) |
| 11700 | return; |
| 11701 | |
| 11702 | unregister_netdev(priv->prom_net_dev); |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11703 | free_ieee80211(priv->prom_net_dev, 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11704 | |
| 11705 | priv->prom_net_dev = NULL; |
| 11706 | } |
| 11707 | |
| 11708 | #endif |
| 11709 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11710 | static const struct net_device_ops ipw_netdev_ops = { |
| 11711 | .ndo_init = ipw_net_init, |
| 11712 | .ndo_open = ipw_net_open, |
| 11713 | .ndo_stop = ipw_net_stop, |
| 11714 | .ndo_set_multicast_list = ipw_net_set_multicast_list, |
| 11715 | .ndo_set_mac_address = ipw_net_set_mac_address, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11716 | .ndo_start_xmit = libipw_xmit, |
| 11717 | .ndo_change_mtu = libipw_change_mtu, |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11718 | .ndo_validate_addr = eth_validate_addr, |
| 11719 | }; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11720 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 11721 | static int __devinit ipw_pci_probe(struct pci_dev *pdev, |
| 11722 | const struct pci_device_id *ent) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11723 | { |
| 11724 | int err = 0; |
| 11725 | struct net_device *net_dev; |
| 11726 | void __iomem *base; |
| 11727 | u32 length, val; |
| 11728 | struct ipw_priv *priv; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11729 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11730 | |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11731 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv), 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11732 | if (net_dev == NULL) { |
| 11733 | err = -ENOMEM; |
| 11734 | goto out; |
| 11735 | } |
| 11736 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11737 | priv = libipw_priv(net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11738 | priv->ieee = netdev_priv(net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11739 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11740 | priv->net_dev = net_dev; |
| 11741 | priv->pci_dev = pdev; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11742 | ipw_debug_level = debug; |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 11743 | spin_lock_init(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11744 | spin_lock_init(&priv->lock); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11745 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
| 11746 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11747 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11748 | mutex_init(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11749 | if (pci_enable_device(pdev)) { |
| 11750 | err = -ENODEV; |
| 11751 | goto out_free_ieee80211; |
| 11752 | } |
| 11753 | |
| 11754 | pci_set_master(pdev); |
| 11755 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 11756 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11757 | if (!err) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 11758 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11759 | if (err) { |
| 11760 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 11761 | goto out_pci_disable_device; |
| 11762 | } |
| 11763 | |
| 11764 | pci_set_drvdata(pdev, priv); |
| 11765 | |
| 11766 | err = pci_request_regions(pdev, DRV_NAME); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11767 | if (err) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11768 | goto out_pci_disable_device; |
| 11769 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11770 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11771 | * PCI Tx retries from interfering with C3 CPU state */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11772 | pci_read_config_dword(pdev, 0x40, &val); |
| 11773 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11774 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11775 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11776 | length = pci_resource_len(pdev, 0); |
| 11777 | priv->hw_len = length; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11778 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 11779 | base = pci_ioremap_bar(pdev, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11780 | if (!base) { |
| 11781 | err = -ENODEV; |
| 11782 | goto out_pci_release_regions; |
| 11783 | } |
| 11784 | |
| 11785 | priv->hw_base = base; |
| 11786 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); |
| 11787 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); |
| 11788 | |
| 11789 | err = ipw_setup_deferred_work(priv); |
| 11790 | if (err) { |
| 11791 | IPW_ERROR("Unable to setup deferred work\n"); |
| 11792 | goto out_iounmap; |
| 11793 | } |
| 11794 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11795 | ipw_sw_reset(priv, 1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11796 | |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 11797 | err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11798 | if (err) { |
| 11799 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 11800 | goto out_destroy_workqueue; |
| 11801 | } |
| 11802 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11803 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
| 11804 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11805 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11806 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11807 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
| 11808 | priv->ieee->set_security = shim__set_security; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 11809 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11810 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11811 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 11812 | priv->ieee->is_qos_active = ipw_is_qos_active; |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 11813 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
| 11814 | priv->ieee->handle_beacon = ipw_handle_probe_response; |
| 11815 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11816 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11817 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11818 | priv->ieee->perfect_rssi = -20; |
| 11819 | priv->ieee->worst_rssi = -85; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11820 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11821 | net_dev->netdev_ops = &ipw_netdev_ops; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11822 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11823 | net_dev->wireless_data = &priv->wireless_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11824 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
| 11825 | net_dev->ethtool_ops = &ipw_ethtool_ops; |
| 11826 | net_dev->irq = pdev->irq; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11827 | net_dev->base_addr = (unsigned long)priv->hw_base; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11828 | net_dev->mem_start = pci_resource_start(pdev, 0); |
| 11829 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; |
| 11830 | |
| 11831 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11832 | if (err) { |
| 11833 | IPW_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11834 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11835 | goto out_release_irq; |
| 11836 | } |
| 11837 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11838 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11839 | err = register_netdev(net_dev); |
| 11840 | if (err) { |
| 11841 | IPW_ERROR("failed to register network device\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11842 | goto out_remove_sysfs; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11843 | } |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11844 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11845 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11846 | if (rtap_iface) { |
| 11847 | err = ipw_prom_alloc(priv); |
| 11848 | if (err) { |
| 11849 | IPW_ERROR("Failed to register promiscuous network " |
| 11850 | "device (error %d).\n", err); |
| 11851 | unregister_netdev(priv->net_dev); |
| 11852 | goto out_remove_sysfs; |
| 11853 | } |
| 11854 | } |
| 11855 | #endif |
| 11856 | |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11857 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " |
| 11858 | "channels, %d 802.11a channels)\n", |
| 11859 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, |
| 11860 | priv->ieee->geo.a_channels); |
| 11861 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11862 | return 0; |
| 11863 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11864 | out_remove_sysfs: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11865 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11866 | out_release_irq: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11867 | free_irq(pdev->irq, priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11868 | out_destroy_workqueue: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11869 | destroy_workqueue(priv->workqueue); |
| 11870 | priv->workqueue = NULL; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11871 | out_iounmap: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11872 | iounmap(priv->hw_base); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11873 | out_pci_release_regions: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11874 | pci_release_regions(pdev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11875 | out_pci_disable_device: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11876 | pci_disable_device(pdev); |
| 11877 | pci_set_drvdata(pdev, NULL); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11878 | out_free_ieee80211: |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11879 | free_ieee80211(priv->net_dev, 0); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11880 | out: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11881 | return err; |
| 11882 | } |
| 11883 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 11884 | static void __devexit ipw_pci_remove(struct pci_dev *pdev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11885 | { |
| 11886 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11887 | struct list_head *p, *q; |
| 11888 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11889 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11890 | if (!priv) |
| 11891 | return; |
| 11892 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11893 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11894 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11895 | priv->status |= STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11896 | ipw_down(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11897 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11898 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11899 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11900 | |
| 11901 | unregister_netdev(priv->net_dev); |
| 11902 | |
| 11903 | if (priv->rxq) { |
| 11904 | ipw_rx_queue_free(priv, priv->rxq); |
| 11905 | priv->rxq = NULL; |
| 11906 | } |
| 11907 | ipw_tx_queue_free(priv); |
| 11908 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11909 | if (priv->cmdlog) { |
| 11910 | kfree(priv->cmdlog); |
| 11911 | priv->cmdlog = NULL; |
| 11912 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11913 | /* ipw_down will ensure that there is no more pending work |
| 11914 | * in the workqueue's, so we can safely remove them now. */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11915 | cancel_delayed_work(&priv->adhoc_check); |
| 11916 | cancel_delayed_work(&priv->gather_stats); |
| 11917 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 11918 | cancel_delayed_work(&priv->request_direct_scan); |
| 11919 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 11920 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11921 | cancel_delayed_work(&priv->rf_kill); |
| 11922 | cancel_delayed_work(&priv->scan_check); |
| 11923 | destroy_workqueue(priv->workqueue); |
| 11924 | priv->workqueue = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11925 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11926 | /* Free MAC hash list for ADHOC */ |
| 11927 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { |
| 11928 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11929 | list_del(p); |
Zhu Yi | 489f445 | 2006-01-24 16:37:41 +0800 | [diff] [blame] | 11930 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11931 | } |
| 11932 | } |
| 11933 | |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 11934 | kfree(priv->error); |
| 11935 | priv->error = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11936 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11937 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11938 | ipw_prom_free(priv); |
| 11939 | #endif |
| 11940 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11941 | free_irq(pdev->irq, priv); |
| 11942 | iounmap(priv->hw_base); |
| 11943 | pci_release_regions(pdev); |
| 11944 | pci_disable_device(pdev); |
| 11945 | pci_set_drvdata(pdev, NULL); |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11946 | /* wiphy_unregister needs to be here, before free_ieee80211 */ |
| 11947 | wiphy_unregister(priv->ieee->wdev.wiphy); |
| 11948 | kfree(priv->ieee->a_band.channels); |
| 11949 | kfree(priv->ieee->bg_band.channels); |
| 11950 | free_ieee80211(priv->net_dev, 0); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11951 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11952 | } |
| 11953 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11954 | #ifdef CONFIG_PM |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11955 | 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] | 11956 | { |
| 11957 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11958 | struct net_device *dev = priv->net_dev; |
| 11959 | |
| 11960 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); |
| 11961 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11962 | /* Take down the device; powers it off, etc. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11963 | ipw_down(priv); |
| 11964 | |
| 11965 | /* Remove the PRESENT state of the device */ |
| 11966 | netif_device_detach(dev); |
| 11967 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11968 | pci_save_state(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11969 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11970 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11971 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11972 | priv->suspend_at = get_seconds(); |
| 11973 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11974 | return 0; |
| 11975 | } |
| 11976 | |
| 11977 | static int ipw_pci_resume(struct pci_dev *pdev) |
| 11978 | { |
| 11979 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11980 | struct net_device *dev = priv->net_dev; |
John W. Linville | 02e0e5e | 2006-11-07 20:53:48 -0500 | [diff] [blame] | 11981 | int err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11982 | u32 val; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11983 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11984 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
| 11985 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11986 | pci_set_power_state(pdev, PCI_D0); |
John W. Linville | 02e0e5e | 2006-11-07 20:53:48 -0500 | [diff] [blame] | 11987 | err = pci_enable_device(pdev); |
| 11988 | if (err) { |
| 11989 | printk(KERN_ERR "%s: pci_enable_device failed on resume\n", |
| 11990 | dev->name); |
| 11991 | return err; |
| 11992 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11993 | pci_restore_state(pdev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11994 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11995 | /* |
| 11996 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 11997 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 11998 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 11999 | * here since it only restores the first 64 bytes pci config header. |
| 12000 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 12001 | pci_read_config_dword(pdev, 0x40, &val); |
| 12002 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12003 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 12004 | |
| 12005 | /* Set the device back into the PRESENT state; this will also wake |
| 12006 | * the queue of needed */ |
| 12007 | netif_device_attach(dev); |
| 12008 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 12009 | priv->suspend_time = get_seconds() - priv->suspend_at; |
| 12010 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12011 | /* Bring the device back up */ |
| 12012 | queue_work(priv->workqueue, &priv->up); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 12013 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12014 | return 0; |
| 12015 | } |
| 12016 | #endif |
| 12017 | |
Zhu Yi | c8c22c9 | 2006-08-21 11:38:39 +0800 | [diff] [blame] | 12018 | static void ipw_pci_shutdown(struct pci_dev *pdev) |
| 12019 | { |
| 12020 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 12021 | |
| 12022 | /* Take down the device; powers it off, etc. */ |
| 12023 | ipw_down(priv); |
| 12024 | |
| 12025 | pci_disable_device(pdev); |
| 12026 | } |
| 12027 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12028 | /* driver initialization stuff */ |
| 12029 | static struct pci_driver ipw_driver = { |
| 12030 | .name = DRV_NAME, |
| 12031 | .id_table = card_ids, |
| 12032 | .probe = ipw_pci_probe, |
| 12033 | .remove = __devexit_p(ipw_pci_remove), |
| 12034 | #ifdef CONFIG_PM |
| 12035 | .suspend = ipw_pci_suspend, |
| 12036 | .resume = ipw_pci_resume, |
| 12037 | #endif |
Zhu Yi | c8c22c9 | 2006-08-21 11:38:39 +0800 | [diff] [blame] | 12038 | .shutdown = ipw_pci_shutdown, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12039 | }; |
| 12040 | |
| 12041 | static int __init ipw_init(void) |
| 12042 | { |
| 12043 | int ret; |
| 12044 | |
| 12045 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 12046 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 12047 | |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 12048 | ret = pci_register_driver(&ipw_driver); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12049 | if (ret) { |
| 12050 | IPW_ERROR("Unable to initialize PCI module\n"); |
| 12051 | return ret; |
| 12052 | } |
| 12053 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 12054 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12055 | if (ret) { |
| 12056 | IPW_ERROR("Unable to create driver sysfs file\n"); |
| 12057 | pci_unregister_driver(&ipw_driver); |
| 12058 | return ret; |
| 12059 | } |
| 12060 | |
| 12061 | return ret; |
| 12062 | } |
| 12063 | |
| 12064 | static void __exit ipw_exit(void) |
| 12065 | { |
| 12066 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); |
| 12067 | pci_unregister_driver(&ipw_driver); |
| 12068 | } |
| 12069 | |
| 12070 | module_param(disable, int, 0444); |
| 12071 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 12072 | |
| 12073 | module_param(associate, int, 0444); |
Tim Gardner | 5c7f9b7 | 2008-10-14 10:38:03 -0600 | [diff] [blame] | 12074 | MODULE_PARM_DESC(associate, "auto associate when scanning (default off)"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12075 | |
| 12076 | module_param(auto_create, int, 0444); |
| 12077 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); |
| 12078 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12079 | module_param_named(led, led_support, int, 0444); |
Niels de Vos | 61a2d07 | 2008-07-31 00:07:23 -0700 | [diff] [blame] | 12080 | 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] | 12081 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12082 | module_param(debug, int, 0444); |
| 12083 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 12084 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12085 | module_param_named(channel, default_channel, int, 0444); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 12086 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12087 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 12088 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 12089 | module_param(rtap_iface, int, 0444); |
| 12090 | MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)"); |
| 12091 | #endif |
| 12092 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 12093 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12094 | module_param(qos_enable, int, 0444); |
| 12095 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12096 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12097 | module_param(qos_burst_enable, int, 0444); |
| 12098 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); |
| 12099 | |
| 12100 | module_param(qos_no_ack_mask, int, 0444); |
| 12101 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); |
| 12102 | |
| 12103 | module_param(burst_duration_CCK, int, 0444); |
| 12104 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); |
| 12105 | |
| 12106 | module_param(burst_duration_OFDM, int, 0444); |
| 12107 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 12108 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12109 | |
| 12110 | #ifdef CONFIG_IPW2200_MONITOR |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12111 | module_param_named(mode, network_mode, int, 0444); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12112 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); |
| 12113 | #else |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12114 | module_param_named(mode, network_mode, int, 0444); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12115 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
| 12116 | #endif |
| 12117 | |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 12118 | module_param(bt_coexist, int, 0444); |
| 12119 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); |
| 12120 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12121 | module_param(hwcrypto, int, 0444); |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 12122 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12123 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 12124 | module_param(cmdlog, int, 0444); |
| 12125 | MODULE_PARM_DESC(cmdlog, |
| 12126 | "allocate a ring buffer for logging firmware commands"); |
| 12127 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 12128 | module_param(roaming, int, 0444); |
| 12129 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); |
| 12130 | |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 12131 | module_param(antenna, int, 0444); |
| 12132 | MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)"); |
| 12133 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12134 | module_exit(ipw_exit); |
| 12135 | module_init(ipw_init); |