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; |
ubuntu@tjworld.net | c086aba | 2009-03-23 20:29:28 +0000 | [diff] [blame] | 99 | static int led_support = 1; |
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); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [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); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 476 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x\n", reg, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 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); |
Indan Zupancic | 3c4a8cc | 2011-01-08 12:17:27 +0100 | [diff] [blame] | 1976 | |
| 1977 | if (inta == 0xFFFFFFFF) { |
| 1978 | /* Hardware disappeared */ |
| 1979 | IPW_WARNING("TASKLET INTA == 0xFFFFFFFF\n"); |
| 1980 | /* Only handle the cached INTA values */ |
| 1981 | inta = 0; |
| 1982 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1983 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1984 | |
| 1985 | /* Add any cached INTA values that need to be handled */ |
| 1986 | inta |= priv->isr_inta; |
| 1987 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 1988 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
| 1989 | |
| 1990 | spin_lock_irqsave(&priv->lock, flags); |
| 1991 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1992 | /* handle all the justifications for the interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1993 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1994 | ipw_rx(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1995 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1996 | } |
| 1997 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1998 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1999 | IPW_DEBUG_HC("Command completed.\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2000 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2001 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2002 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2003 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2004 | } |
| 2005 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2006 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2007 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2008 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2009 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2010 | } |
| 2011 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2012 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2013 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2014 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2015 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2016 | } |
| 2017 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2018 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2019 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2020 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2021 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2022 | } |
| 2023 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2024 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2025 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2026 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2027 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2028 | } |
| 2029 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2030 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2031 | IPW_WARNING("STATUS_CHANGE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2032 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2033 | } |
| 2034 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2035 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2036 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2037 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2038 | } |
| 2039 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2040 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2041 | IPW_WARNING("HOST_CMD_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2042 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2043 | } |
| 2044 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2045 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2046 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2047 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2048 | } |
| 2049 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2050 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2051 | IPW_WARNING("PHY_OFF_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2052 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2053 | } |
| 2054 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2055 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2056 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
| 2057 | priv->status |= STATUS_RF_KILL_HW; |
Matthew Garrett | 25f94ae | 2009-11-11 14:36:31 -0500 | [diff] [blame] | 2058 | wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2059 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 2060 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2061 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 2062 | cancel_delayed_work(&priv->request_direct_scan); |
| 2063 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 2064 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2065 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2066 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2067 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2068 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2069 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2070 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2071 | IPW_WARNING("Firmware error detected. Restarting.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2072 | if (priv->error) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2073 | IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2074 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
| 2075 | struct ipw_fw_error *error = |
| 2076 | ipw_alloc_error_log(priv); |
| 2077 | ipw_dump_error_log(priv, error); |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 2078 | kfree(error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2079 | } |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2080 | } else { |
| 2081 | priv->error = ipw_alloc_error_log(priv); |
| 2082 | if (priv->error) |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2083 | IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2084 | else |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 2085 | IPW_DEBUG_FW("Error allocating sysfs 'error' " |
| 2086 | "log.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2087 | if (ipw_debug_level & IPW_DL_FW_ERRORS) |
| 2088 | ipw_dump_error_log(priv, priv->error); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 2089 | } |
| 2090 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2091 | /* XXX: If hardware encryption is for WPA/WPA2, |
| 2092 | * we have to notify the supplicant. */ |
| 2093 | if (priv->ieee->sec.encrypt) { |
| 2094 | priv->status &= ~STATUS_ASSOCIATED; |
| 2095 | notify_wx_assoc_event(priv); |
| 2096 | } |
| 2097 | |
| 2098 | /* Keep the restart process from trying to send host |
| 2099 | * commands by clearing the INIT status bit */ |
| 2100 | priv->status &= ~STATUS_INIT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2101 | |
| 2102 | /* Cancel currently queued command. */ |
| 2103 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2104 | wake_up_interruptible(&priv->wait_command_queue); |
| 2105 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2106 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2107 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2108 | } |
| 2109 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2110 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2111 | IPW_ERROR("Parity error\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2112 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | if (handled != inta) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2116 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2117 | } |
| 2118 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 2119 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2120 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2121 | /* enable all interrupts */ |
| 2122 | ipw_enable_interrupts(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2123 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2124 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2125 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
| 2126 | static char *get_cmd_string(u8 cmd) |
| 2127 | { |
| 2128 | switch (cmd) { |
| 2129 | IPW_CMD(HOST_COMPLETE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2130 | IPW_CMD(POWER_DOWN); |
| 2131 | IPW_CMD(SYSTEM_CONFIG); |
| 2132 | IPW_CMD(MULTICAST_ADDRESS); |
| 2133 | IPW_CMD(SSID); |
| 2134 | IPW_CMD(ADAPTER_ADDRESS); |
| 2135 | IPW_CMD(PORT_TYPE); |
| 2136 | IPW_CMD(RTS_THRESHOLD); |
| 2137 | IPW_CMD(FRAG_THRESHOLD); |
| 2138 | IPW_CMD(POWER_MODE); |
| 2139 | IPW_CMD(WEP_KEY); |
| 2140 | IPW_CMD(TGI_TX_KEY); |
| 2141 | IPW_CMD(SCAN_REQUEST); |
| 2142 | IPW_CMD(SCAN_REQUEST_EXT); |
| 2143 | IPW_CMD(ASSOCIATE); |
| 2144 | IPW_CMD(SUPPORTED_RATES); |
| 2145 | IPW_CMD(SCAN_ABORT); |
| 2146 | IPW_CMD(TX_FLUSH); |
| 2147 | IPW_CMD(QOS_PARAMETERS); |
| 2148 | IPW_CMD(DINO_CONFIG); |
| 2149 | IPW_CMD(RSN_CAPABILITIES); |
| 2150 | IPW_CMD(RX_KEY); |
| 2151 | IPW_CMD(CARD_DISABLE); |
| 2152 | IPW_CMD(SEED_NUMBER); |
| 2153 | IPW_CMD(TX_POWER); |
| 2154 | IPW_CMD(COUNTRY_INFO); |
| 2155 | IPW_CMD(AIRONET_INFO); |
| 2156 | IPW_CMD(AP_TX_POWER); |
| 2157 | IPW_CMD(CCKM_INFO); |
| 2158 | IPW_CMD(CCX_VER_INFO); |
| 2159 | IPW_CMD(SET_CALIBRATION); |
| 2160 | IPW_CMD(SENSITIVITY_CALIB); |
| 2161 | IPW_CMD(RETRY_LIMIT); |
| 2162 | IPW_CMD(IPW_PRE_POWER_DOWN); |
| 2163 | IPW_CMD(VAP_BEACON_TEMPLATE); |
| 2164 | IPW_CMD(VAP_DTIM_PERIOD); |
| 2165 | IPW_CMD(EXT_SUPPORTED_RATES); |
| 2166 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); |
| 2167 | IPW_CMD(VAP_QUIET_INTERVALS); |
| 2168 | IPW_CMD(VAP_CHANNEL_SWITCH); |
| 2169 | IPW_CMD(VAP_MANDATORY_CHANNELS); |
| 2170 | IPW_CMD(VAP_CELL_PWR_LIMIT); |
| 2171 | IPW_CMD(VAP_CF_PARAM_SET); |
| 2172 | IPW_CMD(VAP_SET_BEACONING_STATE); |
| 2173 | IPW_CMD(MEASUREMENT); |
| 2174 | IPW_CMD(POWER_CAPABILITY); |
| 2175 | IPW_CMD(SUPPORTED_CHANNELS); |
| 2176 | IPW_CMD(TPC_REPORT); |
| 2177 | IPW_CMD(WME_INFO); |
| 2178 | IPW_CMD(PRODUCTION_COMMAND); |
| 2179 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2180 | return "UNKNOWN"; |
| 2181 | } |
| 2182 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2183 | |
| 2184 | #define HOST_COMPLETE_TIMEOUT HZ |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2185 | |
| 2186 | 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] | 2187 | { |
| 2188 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2189 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2190 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2191 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2192 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2193 | IPW_ERROR("Failed to send %s: Already sending a command.\n", |
| 2194 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2195 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2196 | return -EAGAIN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | priv->status |= STATUS_HCMD_ACTIVE; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2200 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2201 | if (priv->cmdlog) { |
| 2202 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; |
| 2203 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; |
| 2204 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; |
| 2205 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, |
| 2206 | cmd->len); |
| 2207 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; |
| 2208 | } |
| 2209 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2210 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
| 2211 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, |
| 2212 | priv->status); |
Zhu Yi | f516dbc | 2006-01-24 16:36:44 +0800 | [diff] [blame] | 2213 | |
| 2214 | #ifndef DEBUG_CMD_WEP_KEY |
| 2215 | if (cmd->cmd == IPW_CMD_WEP_KEY) |
| 2216 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); |
| 2217 | else |
| 2218 | #endif |
| 2219 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); |
| 2220 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2221 | 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] | 2222 | if (rc) { |
| 2223 | priv->status &= ~STATUS_HCMD_ACTIVE; |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2224 | IPW_ERROR("Failed to send %s: Reason %d\n", |
| 2225 | get_cmd_string(cmd->cmd), rc); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2226 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2227 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2228 | } |
| 2229 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2230 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2231 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 2232 | !(priv-> |
| 2233 | status & STATUS_HCMD_ACTIVE), |
| 2234 | HOST_COMPLETE_TIMEOUT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2235 | if (rc == 0) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2236 | spin_lock_irqsave(&priv->lock, flags); |
| 2237 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2238 | IPW_ERROR("Failed to send %s: Command timed out.\n", |
| 2239 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2240 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 2241 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2242 | rc = -EIO; |
| 2243 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2244 | } |
| 2245 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 2246 | } else |
| 2247 | rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2248 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2249 | if (priv->status & STATUS_RF_KILL_HW) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2250 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", |
| 2251 | get_cmd_string(cmd->cmd)); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2252 | rc = -EIO; |
| 2253 | goto exit; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2254 | } |
| 2255 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2256 | exit: |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2257 | if (priv->cmdlog) { |
| 2258 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; |
| 2259 | priv->cmdlog_pos %= priv->cmdlog_len; |
| 2260 | } |
| 2261 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2262 | } |
| 2263 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2264 | static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2265 | { |
| 2266 | struct host_cmd cmd = { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2267 | .cmd = command, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2268 | }; |
| 2269 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2270 | return __ipw_send_cmd(priv, &cmd); |
| 2271 | } |
| 2272 | |
| 2273 | static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, |
| 2274 | void *data) |
| 2275 | { |
| 2276 | struct host_cmd cmd = { |
| 2277 | .cmd = command, |
| 2278 | .len = len, |
| 2279 | .param = data, |
| 2280 | }; |
| 2281 | |
| 2282 | return __ipw_send_cmd(priv, &cmd); |
| 2283 | } |
| 2284 | |
| 2285 | static int ipw_send_host_complete(struct ipw_priv *priv) |
| 2286 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2287 | if (!priv) { |
| 2288 | IPW_ERROR("Invalid args\n"); |
| 2289 | return -1; |
| 2290 | } |
| 2291 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2292 | return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2293 | } |
| 2294 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2295 | static int ipw_send_system_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2296 | { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 2297 | return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, |
| 2298 | sizeof(priv->sys_config), |
| 2299 | &priv->sys_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2300 | } |
| 2301 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2302 | 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] | 2303 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2304 | if (!priv || !ssid) { |
| 2305 | IPW_ERROR("Invalid args\n"); |
| 2306 | return -1; |
| 2307 | } |
| 2308 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2309 | 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] | 2310 | ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2311 | } |
| 2312 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2313 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2314 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2315 | if (!priv || !mac) { |
| 2316 | IPW_ERROR("Invalid args\n"); |
| 2317 | return -1; |
| 2318 | } |
| 2319 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2320 | IPW_DEBUG_INFO("%s: Setting MAC to %pM\n", |
| 2321 | priv->net_dev->name, mac); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2322 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2323 | 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] | 2324 | } |
| 2325 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2326 | /* |
| 2327 | * NOTE: This must be executed from our workqueue as it results in udelay |
| 2328 | * being called which may corrupt the keyboard if executed on default |
| 2329 | * workqueue |
| 2330 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2331 | static void ipw_adapter_restart(void *adapter) |
| 2332 | { |
| 2333 | struct ipw_priv *priv = adapter; |
| 2334 | |
| 2335 | if (priv->status & STATUS_RF_KILL_MASK) |
| 2336 | return; |
| 2337 | |
| 2338 | ipw_down(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2339 | |
| 2340 | if (priv->assoc_network && |
| 2341 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) |
| 2342 | ipw_remove_current_network(priv); |
| 2343 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2344 | if (ipw_up(priv)) { |
| 2345 | IPW_ERROR("Failed to up device\n"); |
| 2346 | return; |
| 2347 | } |
| 2348 | } |
| 2349 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2350 | static void ipw_bg_adapter_restart(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2351 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2352 | struct ipw_priv *priv = |
| 2353 | container_of(work, struct ipw_priv, adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2354 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2355 | ipw_adapter_restart(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2356 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2357 | } |
| 2358 | |
Zhu Yi | e65054b | 2010-03-30 09:36:16 +0800 | [diff] [blame] | 2359 | static void ipw_abort_scan(struct ipw_priv *priv); |
| 2360 | |
| 2361 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2362 | |
| 2363 | static void ipw_scan_check(void *data) |
| 2364 | { |
| 2365 | struct ipw_priv *priv = data; |
Zhu Yi | e65054b | 2010-03-30 09:36:16 +0800 | [diff] [blame] | 2366 | |
| 2367 | if (priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2368 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2369 | "adapter after (%dms).\n", |
| 2370 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2371 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | e65054b | 2010-03-30 09:36:16 +0800 | [diff] [blame] | 2372 | } else if (priv->status & STATUS_SCANNING) { |
| 2373 | IPW_DEBUG_SCAN("Scan completion watchdog aborting scan " |
| 2374 | "after (%dms).\n", |
| 2375 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); |
| 2376 | ipw_abort_scan(priv); |
| 2377 | queue_delayed_work(priv->workqueue, &priv->scan_check, HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2378 | } |
| 2379 | } |
| 2380 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2381 | static void ipw_bg_scan_check(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2382 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2383 | struct ipw_priv *priv = |
| 2384 | container_of(work, struct ipw_priv, scan_check.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2385 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2386 | ipw_scan_check(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2387 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2388 | } |
| 2389 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2390 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
| 2391 | struct ipw_scan_request_ext *request) |
| 2392 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2393 | return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2394 | sizeof(*request), request); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | static int ipw_send_scan_abort(struct ipw_priv *priv) |
| 2398 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2399 | if (!priv) { |
| 2400 | IPW_ERROR("Invalid args\n"); |
| 2401 | return -1; |
| 2402 | } |
| 2403 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2404 | return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) |
| 2408 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2409 | struct ipw_sensitivity_calib calib = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2410 | .beacon_rssi_raw = cpu_to_le16(sens), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2411 | }; |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2412 | |
| 2413 | return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2414 | &calib); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | static int ipw_send_associate(struct ipw_priv *priv, |
| 2418 | struct ipw_associate *associate) |
| 2419 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2420 | if (!priv || !associate) { |
| 2421 | IPW_ERROR("Invalid args\n"); |
| 2422 | return -1; |
| 2423 | } |
| 2424 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 2425 | return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate), |
| 2426 | associate); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | static int ipw_send_supported_rates(struct ipw_priv *priv, |
| 2430 | struct ipw_supported_rates *rates) |
| 2431 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2432 | if (!priv || !rates) { |
| 2433 | IPW_ERROR("Invalid args\n"); |
| 2434 | return -1; |
| 2435 | } |
| 2436 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2437 | return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2438 | rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | static int ipw_set_random_seed(struct ipw_priv *priv) |
| 2442 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2443 | u32 val; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2444 | |
| 2445 | if (!priv) { |
| 2446 | IPW_ERROR("Invalid args\n"); |
| 2447 | return -1; |
| 2448 | } |
| 2449 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2450 | get_random_bytes(&val, sizeof(val)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2451 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2452 | 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] | 2453 | } |
| 2454 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2455 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
| 2456 | { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2457 | __le32 v = cpu_to_le32(phy_off); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2458 | if (!priv) { |
| 2459 | IPW_ERROR("Invalid args\n"); |
| 2460 | return -1; |
| 2461 | } |
| 2462 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2463 | 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] | 2464 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2465 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2466 | 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] | 2467 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2468 | if (!priv || !power) { |
| 2469 | IPW_ERROR("Invalid args\n"); |
| 2470 | return -1; |
| 2471 | } |
| 2472 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2473 | 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] | 2474 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2475 | |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2476 | static int ipw_set_tx_power(struct ipw_priv *priv) |
| 2477 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2478 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2479 | struct ipw_tx_power tx_power; |
| 2480 | s8 max_power; |
| 2481 | int i; |
| 2482 | |
| 2483 | memset(&tx_power, 0, sizeof(tx_power)); |
| 2484 | |
| 2485 | /* configure device for 'G' band */ |
| 2486 | tx_power.ieee_mode = IPW_G_MODE; |
| 2487 | tx_power.num_channels = geo->bg_channels; |
| 2488 | for (i = 0; i < geo->bg_channels; i++) { |
| 2489 | max_power = geo->bg[i].max_power; |
| 2490 | tx_power.channels_tx_power[i].channel_number = |
| 2491 | geo->bg[i].channel; |
| 2492 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2493 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2494 | } |
| 2495 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2496 | return -EIO; |
| 2497 | |
| 2498 | /* configure device to also handle 'B' band */ |
| 2499 | tx_power.ieee_mode = IPW_B_MODE; |
| 2500 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2501 | return -EIO; |
| 2502 | |
| 2503 | /* configure device to also handle 'A' band */ |
| 2504 | if (priv->ieee->abg_true) { |
| 2505 | tx_power.ieee_mode = IPW_A_MODE; |
| 2506 | tx_power.num_channels = geo->a_channels; |
| 2507 | for (i = 0; i < tx_power.num_channels; i++) { |
| 2508 | max_power = geo->a[i].max_power; |
| 2509 | tx_power.channels_tx_power[i].channel_number = |
| 2510 | geo->a[i].channel; |
| 2511 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2512 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2513 | } |
| 2514 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2515 | return -EIO; |
| 2516 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2517 | return 0; |
| 2518 | } |
| 2519 | |
| 2520 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) |
| 2521 | { |
| 2522 | struct ipw_rts_threshold rts_threshold = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2523 | .rts_threshold = cpu_to_le16(rts), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2524 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2525 | |
| 2526 | if (!priv) { |
| 2527 | IPW_ERROR("Invalid args\n"); |
| 2528 | return -1; |
| 2529 | } |
| 2530 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2531 | return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, |
| 2532 | sizeof(rts_threshold), &rts_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) |
| 2536 | { |
| 2537 | struct ipw_frag_threshold frag_threshold = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 2538 | .frag_threshold = cpu_to_le16(frag), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2539 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2540 | |
| 2541 | if (!priv) { |
| 2542 | IPW_ERROR("Invalid args\n"); |
| 2543 | return -1; |
| 2544 | } |
| 2545 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2546 | return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, |
| 2547 | sizeof(frag_threshold), &frag_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) |
| 2551 | { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2552 | __le32 param; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2553 | |
| 2554 | if (!priv) { |
| 2555 | IPW_ERROR("Invalid args\n"); |
| 2556 | return -1; |
| 2557 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2558 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2559 | /* If on battery, set to 3, if AC set to CAM, else user |
| 2560 | * level */ |
| 2561 | switch (mode) { |
| 2562 | case IPW_POWER_BATTERY: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2563 | param = cpu_to_le32(IPW_POWER_INDEX_3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2564 | break; |
| 2565 | case IPW_POWER_AC: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2566 | param = cpu_to_le32(IPW_POWER_MODE_CAM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2567 | break; |
| 2568 | default: |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2569 | param = cpu_to_le32(mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2570 | break; |
| 2571 | } |
| 2572 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2573 | return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2574 | ¶m); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2575 | } |
| 2576 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2577 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
| 2578 | { |
| 2579 | struct ipw_retry_limit retry_limit = { |
| 2580 | .short_retry_limit = slimit, |
| 2581 | .long_retry_limit = llimit |
| 2582 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2583 | |
| 2584 | if (!priv) { |
| 2585 | IPW_ERROR("Invalid args\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2586 | return -1; |
| 2587 | } |
| 2588 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2589 | 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] | 2590 | &retry_limit); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | /* |
| 2594 | * The IPW device contains a Microwire compatible EEPROM that stores |
| 2595 | * various data like the MAC address. Usually the firmware has exclusive |
| 2596 | * access to the eeprom, but during device initialization (before the |
| 2597 | * device driver has sent the HostComplete command to the firmware) the |
| 2598 | * device driver has read access to the EEPROM by way of indirect addressing |
| 2599 | * through a couple of memory mapped registers. |
| 2600 | * |
| 2601 | * The following is a simplified implementation for pulling data out of the |
| 2602 | * the eeprom, along with some helper functions to find information in |
| 2603 | * the per device private data's copy of the eeprom. |
| 2604 | * |
| 2605 | * NOTE: To better understand how these functions work (i.e what is a chip |
| 2606 | * select and why do have to keep driving the eeprom clock?), read |
| 2607 | * just about any data sheet for a Microwire compatible EEPROM. |
| 2608 | */ |
| 2609 | |
| 2610 | /* write a 32 bit value into the indirect accessor register */ |
| 2611 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) |
| 2612 | { |
| 2613 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2614 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2615 | /* the eeprom requires some time to complete the operation */ |
| 2616 | udelay(p->eeprom_delay); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2620 | static void eeprom_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2621 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2622 | eeprom_write_reg(priv, 0); |
| 2623 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2624 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2625 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2629 | static void eeprom_disable_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2630 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2631 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2632 | eeprom_write_reg(priv, 0); |
| 2633 | eeprom_write_reg(priv, EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | /* push a single bit down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2637 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2638 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2639 | int d = (bit ? EEPROM_BIT_DI : 0); |
| 2640 | eeprom_write_reg(p, EEPROM_BIT_CS | d); |
| 2641 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | /* push an opcode followed by an address down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2645 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2646 | { |
| 2647 | int i; |
| 2648 | |
| 2649 | eeprom_cs(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2650 | eeprom_write_bit(priv, 1); |
| 2651 | eeprom_write_bit(priv, op & 2); |
| 2652 | eeprom_write_bit(priv, op & 1); |
| 2653 | for (i = 7; i >= 0; i--) { |
| 2654 | eeprom_write_bit(priv, addr & (1 << i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | /* pull 16 bits off the eeprom, one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2659 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2660 | { |
| 2661 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2662 | u16 r = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2663 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2664 | /* Send READ Opcode */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2665 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2666 | |
| 2667 | /* Send dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2668 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2669 | |
| 2670 | /* Read the byte off the eeprom one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2671 | for (i = 0; i < 16; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2672 | u32 data = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2673 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2674 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2675 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); |
| 2676 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2677 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2678 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2679 | /* Send another dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2680 | eeprom_write_reg(priv, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2681 | eeprom_disable_cs(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2682 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2683 | return r; |
| 2684 | } |
| 2685 | |
| 2686 | /* helper function for pulling the mac address out of the private */ |
| 2687 | /* data's copy of the eeprom data */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2688 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2689 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2690 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | /* |
| 2694 | * Either the device driver (i.e. the host) or the firmware can |
| 2695 | * load eeprom data into the designated region in SRAM. If neither |
| 2696 | * happens then the FW will shutdown with a fatal error. |
| 2697 | * |
| 2698 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE |
| 2699 | * bit needs region of shared SRAM needs to be non-zero. |
| 2700 | */ |
| 2701 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) |
| 2702 | { |
| 2703 | int i; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2704 | __le16 *eeprom = (__le16 *) priv->eeprom; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2705 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2706 | IPW_DEBUG_TRACE(">>\n"); |
| 2707 | |
| 2708 | /* read entire contents of eeprom into private buffer */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2709 | for (i = 0; i < 128; i++) |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 2710 | eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2711 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2712 | /* |
| 2713 | If the data looks correct, then copy it to our private |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2714 | copy. Otherwise let the firmware know to perform the operation |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2715 | on its own. |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2716 | */ |
Alexey Dobriyan | 386093e | 2006-02-01 03:04:57 -0800 | [diff] [blame] | 2717 | if (priv->eeprom[EEPROM_VERSION] != 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2718 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
| 2719 | |
| 2720 | /* write the eeprom data to sram */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2721 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2722 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2723 | |
| 2724 | /* Do not load eeprom data on fatal error or suspend */ |
| 2725 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 2726 | } else { |
| 2727 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); |
| 2728 | |
| 2729 | /* Load eeprom data on fatal error or suspend */ |
| 2730 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); |
| 2731 | } |
| 2732 | |
| 2733 | IPW_DEBUG_TRACE("<<\n"); |
| 2734 | } |
| 2735 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2736 | 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] | 2737 | { |
| 2738 | count >>= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2739 | if (!count) |
| 2740 | return; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2741 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2742 | while (count--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2743 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) |
| 2747 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2748 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2749 | CB_NUMBER_OF_ELEMENTS_SMALL * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2750 | sizeof(struct command_block)); |
| 2751 | } |
| 2752 | |
| 2753 | static int ipw_fw_dma_enable(struct ipw_priv *priv) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2754 | { /* start dma engine but no transfers yet */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2755 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2756 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2757 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2758 | /* Start the dma */ |
| 2759 | ipw_fw_dma_reset_command_blocks(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2760 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2761 | /* Write CB base address */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2762 | 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] | 2763 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2764 | IPW_DEBUG_FW("<< :\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2765 | return 0; |
| 2766 | } |
| 2767 | |
| 2768 | static void ipw_fw_dma_abort(struct ipw_priv *priv) |
| 2769 | { |
| 2770 | u32 control = 0; |
| 2771 | |
| 2772 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2773 | |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 2774 | /* set the Stop and Abort bit */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2775 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2776 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2777 | priv->sram_desc.last_cb_index = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2778 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2779 | IPW_DEBUG_FW("<<\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2780 | } |
| 2781 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2782 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
| 2783 | struct command_block *cb) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2784 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2785 | u32 address = |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2786 | IPW_SHARED_SRAM_DMA_CONTROL + |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2787 | (sizeof(struct command_block) * index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2788 | IPW_DEBUG_FW(">> :\n"); |
| 2789 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2790 | ipw_write_indirect(priv, address, (u8 *) cb, |
| 2791 | (int)sizeof(struct command_block)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2792 | |
| 2793 | IPW_DEBUG_FW("<< :\n"); |
| 2794 | return 0; |
| 2795 | |
| 2796 | } |
| 2797 | |
| 2798 | static int ipw_fw_dma_kick(struct ipw_priv *priv) |
| 2799 | { |
| 2800 | u32 control = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2801 | u32 index = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2802 | |
| 2803 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2804 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2805 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2806 | ipw_fw_dma_write_command_block(priv, index, |
| 2807 | &priv->sram_desc.cb_list[index]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2808 | |
| 2809 | /* Enable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2810 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 2811 | IPW_RESET_REG_MASTER_DISABLED | |
| 2812 | IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2813 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2814 | /* Set the Start bit. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2815 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2816 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2817 | |
| 2818 | IPW_DEBUG_FW("<< :\n"); |
| 2819 | return 0; |
| 2820 | } |
| 2821 | |
| 2822 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) |
| 2823 | { |
| 2824 | u32 address; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2825 | u32 register_value = 0; |
| 2826 | u32 cb_fields_address = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2827 | |
| 2828 | IPW_DEBUG_FW(">> :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2829 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2830 | IPW_DEBUG_FW_INFO("Current CB is 0x%x\n", address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2831 | |
| 2832 | /* Read the DMA Controlor register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2833 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2834 | 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] | 2835 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2836 | /* Print the CB values */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2837 | cb_fields_address = address; |
| 2838 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2839 | IPW_DEBUG_FW_INFO("Current CB Control Field is 0x%x\n", register_value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2840 | |
| 2841 | cb_fields_address += sizeof(u32); |
| 2842 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2843 | 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] | 2844 | |
| 2845 | cb_fields_address += sizeof(u32); |
| 2846 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2847 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2848 | register_value); |
| 2849 | |
| 2850 | cb_fields_address += sizeof(u32); |
| 2851 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2852 | 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] | 2853 | |
| 2854 | IPW_DEBUG_FW(">> :\n"); |
| 2855 | } |
| 2856 | |
| 2857 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) |
| 2858 | { |
| 2859 | u32 current_cb_address = 0; |
| 2860 | u32 current_cb_index = 0; |
| 2861 | |
| 2862 | IPW_DEBUG_FW("<< :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2863 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2864 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2865 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2866 | sizeof(struct command_block); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2867 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2868 | 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] | 2869 | current_cb_index, current_cb_address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2870 | |
| 2871 | IPW_DEBUG_FW(">> :\n"); |
| 2872 | return current_cb_index; |
| 2873 | |
| 2874 | } |
| 2875 | |
| 2876 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, |
| 2877 | u32 src_address, |
| 2878 | u32 dest_address, |
| 2879 | u32 length, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2880 | int interrupt_enabled, int is_last) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2881 | { |
| 2882 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2883 | 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] | 2884 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
| 2885 | CB_DEST_SIZE_LONG; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2886 | struct command_block *cb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2887 | u32 last_cb_element = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2888 | |
| 2889 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", |
| 2890 | src_address, dest_address, length); |
| 2891 | |
| 2892 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) |
| 2893 | return -1; |
| 2894 | |
| 2895 | last_cb_element = priv->sram_desc.last_cb_index; |
| 2896 | cb = &priv->sram_desc.cb_list[last_cb_element]; |
| 2897 | priv->sram_desc.last_cb_index++; |
| 2898 | |
| 2899 | /* Calculate the new CB control word */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2900 | if (interrupt_enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2901 | control |= CB_INT_ENABLED; |
| 2902 | |
| 2903 | if (is_last) |
| 2904 | control |= CB_LAST_VALID; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2905 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2906 | control |= length; |
| 2907 | |
| 2908 | /* Calculate the CB Element's checksum value */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2909 | cb->status = control ^ src_address ^ dest_address; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2910 | |
| 2911 | /* Copy the Source and Destination addresses */ |
| 2912 | cb->dest_addr = dest_address; |
| 2913 | cb->source_addr = src_address; |
| 2914 | |
| 2915 | /* Copy the Control Word last */ |
| 2916 | cb->control = control; |
| 2917 | |
| 2918 | return 0; |
| 2919 | } |
| 2920 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2921 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address, |
| 2922 | int nr, u32 dest_address, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2923 | { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2924 | int ret, i; |
| 2925 | u32 size; |
| 2926 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2927 | IPW_DEBUG_FW(">>\n"); |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 2928 | IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n", |
| 2929 | nr, dest_address, len); |
| 2930 | |
| 2931 | for (i = 0; i < nr; i++) { |
| 2932 | size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH); |
| 2933 | ret = ipw_fw_dma_add_command_block(priv, src_address[i], |
| 2934 | dest_address + |
| 2935 | i * CB_MAX_LENGTH, size, |
| 2936 | 0, 0); |
| 2937 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2938 | IPW_DEBUG_FW_INFO(": Failed\n"); |
| 2939 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2940 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2941 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2942 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2943 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2944 | IPW_DEBUG_FW("<<\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2945 | return 0; |
| 2946 | } |
| 2947 | |
| 2948 | static int ipw_fw_dma_wait(struct ipw_priv *priv) |
| 2949 | { |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2950 | u32 current_index = 0, previous_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2951 | u32 watchdog = 0; |
| 2952 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2953 | IPW_DEBUG_FW(">> :\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2954 | |
| 2955 | current_index = ipw_fw_dma_command_block_index(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2956 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2957 | (int)priv->sram_desc.last_cb_index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2958 | |
| 2959 | while (current_index < priv->sram_desc.last_cb_index) { |
| 2960 | udelay(50); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2961 | previous_index = current_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2962 | current_index = ipw_fw_dma_command_block_index(priv); |
| 2963 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2964 | if (previous_index < current_index) { |
| 2965 | watchdog = 0; |
| 2966 | continue; |
| 2967 | } |
| 2968 | if (++watchdog > 400) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2969 | IPW_DEBUG_FW_INFO("Timeout\n"); |
| 2970 | ipw_fw_dma_dump_command_block(priv); |
| 2971 | ipw_fw_dma_abort(priv); |
| 2972 | return -1; |
| 2973 | } |
| 2974 | } |
| 2975 | |
| 2976 | ipw_fw_dma_abort(priv); |
| 2977 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2978 | /*Disable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2979 | ipw_set_bit(priv, IPW_RESET_REG, |
| 2980 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2981 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 2982 | IPW_DEBUG_FW("<< dmaWaitSync\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2983 | return 0; |
| 2984 | } |
| 2985 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2986 | static void ipw_remove_current_network(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2987 | { |
| 2988 | struct list_head *element, *safe; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2989 | struct libipw_network *network = NULL; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2990 | unsigned long flags; |
| 2991 | |
| 2992 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2993 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 2994 | network = list_entry(element, struct libipw_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2995 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 2996 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2997 | list_add_tail(&network->list, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2998 | &priv->ieee->network_free_list); |
| 2999 | } |
| 3000 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3001 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | /** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3005 | * Check that card is still alive. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3006 | * Reads debug register from domain0. |
| 3007 | * If card is present, pre-defined value should |
| 3008 | * be found there. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3009 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3010 | * @param priv |
| 3011 | * @return 1 if card is present, 0 otherwise |
| 3012 | */ |
| 3013 | static inline int ipw_alive(struct ipw_priv *priv) |
| 3014 | { |
| 3015 | return ipw_read32(priv, 0x90) == 0xd55555d5; |
| 3016 | } |
| 3017 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3018 | /* timeout in msec, attempted in 10-msec quanta */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3019 | 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] | 3020 | int timeout) |
| 3021 | { |
| 3022 | int i = 0; |
| 3023 | |
| 3024 | do { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3025 | if ((ipw_read32(priv, addr) & mask) == mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3026 | return i; |
| 3027 | mdelay(10); |
| 3028 | i += 10; |
| 3029 | } while (i < timeout); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3030 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3031 | return -ETIME; |
| 3032 | } |
| 3033 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3034 | /* These functions load the firmware and micro code for the operation of |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3035 | * the ipw hardware. It assumes the buffer has all the bits for the |
| 3036 | * image and the caller is handling the memory allocation and clean up. |
| 3037 | */ |
| 3038 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3039 | static int ipw_stop_master(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3040 | { |
| 3041 | int rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3042 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 3043 | IPW_DEBUG_TRACE(">>\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3044 | /* stop master. typical delay - 0 */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3045 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3046 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3047 | /* timeout is in msec, polled in 10-msec quanta */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3048 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3049 | IPW_RESET_REG_MASTER_DISABLED, 100); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3050 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3051 | IPW_ERROR("wait for stop master failed after 100ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3052 | return -1; |
| 3053 | } |
| 3054 | |
| 3055 | IPW_DEBUG_INFO("stop master %dms\n", rc); |
| 3056 | |
| 3057 | return rc; |
| 3058 | } |
| 3059 | |
| 3060 | static void ipw_arc_release(struct ipw_priv *priv) |
| 3061 | { |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 3062 | IPW_DEBUG_TRACE(">>\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3063 | mdelay(5); |
| 3064 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3065 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3066 | |
| 3067 | /* no one knows timing, for safety add some delay */ |
| 3068 | mdelay(5); |
| 3069 | } |
| 3070 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3071 | struct fw_chunk { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3072 | __le32 address; |
| 3073 | __le32 length; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3074 | }; |
| 3075 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3076 | 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] | 3077 | { |
| 3078 | int rc = 0, i, addr; |
| 3079 | u8 cr = 0; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3080 | __le16 *image; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3081 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3082 | image = (__le16 *) data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3083 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 3084 | IPW_DEBUG_TRACE(">>\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3085 | |
| 3086 | rc = ipw_stop_master(priv); |
| 3087 | |
| 3088 | if (rc < 0) |
| 3089 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3090 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3091 | for (addr = IPW_SHARED_LOWER_BOUND; |
| 3092 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3093 | ipw_write32(priv, addr, 0); |
| 3094 | } |
| 3095 | |
| 3096 | /* no ucode (yet) */ |
| 3097 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); |
| 3098 | /* destroy DMA queues */ |
| 3099 | /* reset sequence */ |
| 3100 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3101 | 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] | 3102 | ipw_arc_release(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3103 | 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] | 3104 | mdelay(1); |
| 3105 | |
| 3106 | /* reset PHY */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3107 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3108 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3109 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3110 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3111 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3112 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3113 | /* enable ucode store */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 3114 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
| 3115 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3116 | mdelay(1); |
| 3117 | |
| 3118 | /* write ucode */ |
| 3119 | /** |
| 3120 | * @bug |
| 3121 | * Do NOT set indirect address register once and then |
| 3122 | * store data to indirect data register in the loop. |
| 3123 | * It seems very reasonable, but in this case DINO do not |
| 3124 | * accept ucode. It is essential to set address each time. |
| 3125 | */ |
| 3126 | /* load new ipw uCode */ |
| 3127 | for (i = 0; i < len / 2; i++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3128 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3129 | le16_to_cpu(image[i])); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3130 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3131 | /* enable DINO */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3132 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
| 3133 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3134 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3135 | /* this is where the igx / win driver deveates from the VAP driver. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3136 | |
| 3137 | /* wait for alive response */ |
| 3138 | for (i = 0; i < 100; i++) { |
| 3139 | /* poll for incoming data */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3140 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3141 | if (cr & DINO_RXFIFO_DATA) |
| 3142 | break; |
| 3143 | mdelay(1); |
| 3144 | } |
| 3145 | |
| 3146 | if (cr & DINO_RXFIFO_DATA) { |
| 3147 | /* alive_command_responce size is NOT multiple of 4 */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3148 | __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3149 | |
| 3150 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3151 | response_buffer[i] = |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 3152 | cpu_to_le32(ipw_read_reg32(priv, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3153 | IPW_BASEBAND_RX_FIFO_READ)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3154 | memcpy(&priv->dino_alive, response_buffer, |
| 3155 | sizeof(priv->dino_alive)); |
| 3156 | if (priv->dino_alive.alive_command == 1 |
| 3157 | && priv->dino_alive.ucode_valid == 1) { |
| 3158 | rc = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3159 | IPW_DEBUG_INFO |
| 3160 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " |
| 3161 | "of %02d/%02d/%02d %02d:%02d\n", |
| 3162 | priv->dino_alive.software_revision, |
| 3163 | priv->dino_alive.software_revision, |
| 3164 | priv->dino_alive.device_identifier, |
| 3165 | priv->dino_alive.device_identifier, |
| 3166 | priv->dino_alive.time_stamp[0], |
| 3167 | priv->dino_alive.time_stamp[1], |
| 3168 | priv->dino_alive.time_stamp[2], |
| 3169 | priv->dino_alive.time_stamp[3], |
| 3170 | priv->dino_alive.time_stamp[4]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3171 | } else { |
| 3172 | IPW_DEBUG_INFO("Microcode is not alive\n"); |
| 3173 | rc = -EINVAL; |
| 3174 | } |
| 3175 | } else { |
| 3176 | IPW_DEBUG_INFO("No alive response from DINO\n"); |
| 3177 | rc = -ETIME; |
| 3178 | } |
| 3179 | |
| 3180 | /* disable DINO, otherwise for some reason |
| 3181 | firmware have problem getting alive resp. */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3182 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3183 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3184 | return rc; |
| 3185 | } |
| 3186 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3187 | 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] | 3188 | { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3189 | int ret = -1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3190 | int offset = 0; |
| 3191 | struct fw_chunk *chunk; |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3192 | int total_nr = 0; |
| 3193 | int i; |
| 3194 | struct pci_pool *pool; |
Zhu Yi | 4109316 | 2010-03-09 16:05:31 +0800 | [diff] [blame] | 3195 | void **virts; |
| 3196 | dma_addr_t *phys; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3197 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 3198 | IPW_DEBUG_TRACE("<< :\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3199 | |
Zhu Yi | 4109316 | 2010-03-09 16:05:31 +0800 | [diff] [blame] | 3200 | virts = kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL, |
| 3201 | GFP_KERNEL); |
| 3202 | if (!virts) |
| 3203 | return -ENOMEM; |
| 3204 | |
| 3205 | phys = kmalloc(sizeof(dma_addr_t) * CB_NUMBER_OF_ELEMENTS_SMALL, |
| 3206 | GFP_KERNEL); |
| 3207 | if (!phys) { |
| 3208 | kfree(virts); |
| 3209 | return -ENOMEM; |
| 3210 | } |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3211 | pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0); |
| 3212 | if (!pool) { |
| 3213 | IPW_ERROR("pci_pool_create failed\n"); |
Zhu Yi | 4109316 | 2010-03-09 16:05:31 +0800 | [diff] [blame] | 3214 | kfree(phys); |
| 3215 | kfree(virts); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3216 | return -ENOMEM; |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3217 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3218 | |
| 3219 | /* Start the Dma */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3220 | ret = ipw_fw_dma_enable(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3221 | |
Alexander Beregalov | 0ee904c | 2009-04-11 14:50:23 +0000 | [diff] [blame] | 3222 | /* the DMA is already ready this would be a bug. */ |
| 3223 | BUG_ON(priv->sram_desc.last_cb_index > 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3224 | |
| 3225 | do { |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3226 | u32 chunk_len; |
| 3227 | u8 *start; |
| 3228 | int size; |
| 3229 | int nr = 0; |
| 3230 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3231 | chunk = (struct fw_chunk *)(data + offset); |
| 3232 | offset += sizeof(struct fw_chunk); |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3233 | chunk_len = le32_to_cpu(chunk->length); |
| 3234 | start = data + offset; |
| 3235 | |
| 3236 | nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH; |
| 3237 | for (i = 0; i < nr; i++) { |
| 3238 | virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL, |
| 3239 | &phys[total_nr]); |
| 3240 | if (!virts[total_nr]) { |
| 3241 | ret = -ENOMEM; |
| 3242 | goto out; |
| 3243 | } |
| 3244 | size = min_t(u32, chunk_len - i * CB_MAX_LENGTH, |
| 3245 | CB_MAX_LENGTH); |
| 3246 | memcpy(virts[total_nr], start, size); |
| 3247 | start += size; |
| 3248 | total_nr++; |
| 3249 | /* We don't support fw chunk larger than 64*8K */ |
| 3250 | BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL); |
| 3251 | } |
| 3252 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3253 | /* build DMA packet and queue up for sending */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3254 | /* dma to chunk->address, the chunk->length bytes from data + |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3255 | * offeset*/ |
| 3256 | /* Dma loading */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3257 | ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr], |
| 3258 | nr, le32_to_cpu(chunk->address), |
| 3259 | chunk_len); |
| 3260 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3261 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
| 3262 | goto out; |
| 3263 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3264 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3265 | offset += chunk_len; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3266 | } while (offset < len); |
| 3267 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3268 | /* Run the DMA and wait for the answer */ |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3269 | ret = ipw_fw_dma_kick(priv); |
| 3270 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3271 | IPW_ERROR("dmaKick Failed\n"); |
| 3272 | goto out; |
| 3273 | } |
| 3274 | |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3275 | ret = ipw_fw_dma_wait(priv); |
| 3276 | if (ret) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3277 | IPW_ERROR("dmaWaitSync Failed\n"); |
| 3278 | goto out; |
| 3279 | } |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3280 | out: |
| 3281 | for (i = 0; i < total_nr; i++) |
| 3282 | pci_pool_free(pool, virts[i], phys[i]); |
| 3283 | |
| 3284 | pci_pool_destroy(pool); |
Zhu Yi | 4109316 | 2010-03-09 16:05:31 +0800 | [diff] [blame] | 3285 | kfree(phys); |
| 3286 | kfree(virts); |
Zhu Yi | 11ebd1b | 2009-08-28 11:42:31 +0800 | [diff] [blame] | 3287 | |
| 3288 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | /* stop nic */ |
| 3292 | static int ipw_stop_nic(struct ipw_priv *priv) |
| 3293 | { |
| 3294 | int rc = 0; |
| 3295 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3296 | /* stop */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3297 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3298 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3299 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3300 | IPW_RESET_REG_MASTER_DISABLED, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3301 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3302 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3303 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3304 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3305 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3306 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3307 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3308 | return rc; |
| 3309 | } |
| 3310 | |
| 3311 | static void ipw_start_nic(struct ipw_priv *priv) |
| 3312 | { |
| 3313 | IPW_DEBUG_TRACE(">>\n"); |
| 3314 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3315 | /* prvHwStartNic release ARC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3316 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 3317 | IPW_RESET_REG_MASTER_DISABLED | |
| 3318 | IPW_RESET_REG_STOP_MASTER | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3319 | CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3320 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3321 | /* enable power management */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3322 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
| 3323 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3324 | |
| 3325 | IPW_DEBUG_TRACE("<<\n"); |
| 3326 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3327 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3328 | static int ipw_init_nic(struct ipw_priv *priv) |
| 3329 | { |
| 3330 | int rc; |
| 3331 | |
| 3332 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3333 | /* reset */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3334 | /*prvHwInitNic */ |
| 3335 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3336 | 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] | 3337 | |
| 3338 | /* low-level PLL activation */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3339 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
| 3340 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3341 | |
| 3342 | /* wait for clock stabilization */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3343 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
| 3344 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3345 | if (rc < 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3346 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
| 3347 | |
| 3348 | /* assert SW reset */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3349 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3350 | |
| 3351 | udelay(10); |
| 3352 | |
| 3353 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3354 | 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] | 3355 | |
| 3356 | IPW_DEBUG_TRACE(">>\n"); |
| 3357 | return 0; |
| 3358 | } |
| 3359 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3360 | /* Call this function from process context, it will sleep in request_firmware. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3361 | * Probe is an ok place to call this from. |
| 3362 | */ |
| 3363 | static int ipw_reset_nic(struct ipw_priv *priv) |
| 3364 | { |
| 3365 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3366 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3367 | |
| 3368 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3369 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3370 | rc = ipw_init_nic(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3371 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3372 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3373 | /* Clear the 'host command active' bit... */ |
| 3374 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 3375 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3376 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 3377 | wake_up_interruptible(&priv->wait_state); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3378 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3379 | |
| 3380 | IPW_DEBUG_TRACE("<<\n"); |
| 3381 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3382 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3383 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3384 | |
| 3385 | struct ipw_fw { |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3386 | __le32 ver; |
| 3387 | __le32 boot_size; |
| 3388 | __le32 ucode_size; |
| 3389 | __le32 fw_size; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3390 | u8 data[0]; |
| 3391 | }; |
| 3392 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3393 | static int ipw_get_fw(struct ipw_priv *priv, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3394 | const struct firmware **raw, const char *name) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3395 | { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3396 | struct ipw_fw *fw; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3397 | int rc; |
| 3398 | |
| 3399 | /* ask firmware_class module to get the boot firmware off disk */ |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3400 | rc = request_firmware(raw, name, &priv->pci_dev->dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3401 | if (rc < 0) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3402 | IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3403 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3404 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3405 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3406 | if ((*raw)->size < sizeof(*fw)) { |
| 3407 | IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3408 | return -EINVAL; |
| 3409 | } |
| 3410 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3411 | fw = (void *)(*raw)->data; |
| 3412 | |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3413 | if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) + |
| 3414 | le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3415 | IPW_ERROR("%s is too small or corrupt (%zd)\n", |
| 3416 | name, (*raw)->size); |
| 3417 | return -EINVAL; |
| 3418 | } |
| 3419 | |
| 3420 | 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] | 3421 | name, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3422 | le32_to_cpu(fw->ver) >> 16, |
| 3423 | le32_to_cpu(fw->ver) & 0xff, |
| 3424 | (*raw)->size - sizeof(*fw)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3425 | return 0; |
| 3426 | } |
| 3427 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3428 | #define IPW_RX_BUF_SIZE (3000) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3429 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3430 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3431 | struct ipw_rx_queue *rxq) |
| 3432 | { |
| 3433 | unsigned long flags; |
| 3434 | int i; |
| 3435 | |
| 3436 | spin_lock_irqsave(&rxq->lock, flags); |
| 3437 | |
| 3438 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3439 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3440 | |
| 3441 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3442 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3443 | /* In the reset function, these buffers may have been allocated |
| 3444 | * to an SKB, so we need to unmap and free potential storage */ |
| 3445 | if (rxq->pool[i].skb != NULL) { |
| 3446 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3447 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3448 | dev_kfree_skb(rxq->pool[i].skb); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3449 | rxq->pool[i].skb = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3450 | } |
| 3451 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3452 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3453 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3454 | /* Set us so that we have processed and used all buffers, but have |
| 3455 | * not restocked the Rx queue with fresh buffers */ |
| 3456 | rxq->read = rxq->write = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3457 | rxq->free_count = 0; |
| 3458 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3459 | } |
| 3460 | |
| 3461 | #ifdef CONFIG_PM |
| 3462 | static int fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3463 | static const struct firmware *raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3464 | |
| 3465 | static void free_firmware(void) |
| 3466 | { |
| 3467 | if (fw_loaded) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3468 | release_firmware(raw); |
| 3469 | raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3470 | fw_loaded = 0; |
| 3471 | } |
| 3472 | } |
| 3473 | #else |
| 3474 | #define free_firmware() do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3475 | #endif |
| 3476 | |
| 3477 | static int ipw_load(struct ipw_priv *priv) |
| 3478 | { |
| 3479 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3480 | const struct firmware *raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3481 | #endif |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3482 | struct ipw_fw *fw; |
| 3483 | u8 *boot_img, *ucode_img, *fw_img; |
| 3484 | u8 *name = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3485 | int rc = 0, retries = 3; |
| 3486 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3487 | switch (priv->ieee->iw_mode) { |
| 3488 | case IW_MODE_ADHOC: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3489 | name = "ipw2200-ibss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3490 | break; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3491 | #ifdef CONFIG_IPW2200_MONITOR |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3492 | case IW_MODE_MONITOR: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3493 | name = "ipw2200-sniffer.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3494 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3495 | #endif |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3496 | case IW_MODE_INFRA: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3497 | name = "ipw2200-bss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3498 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3499 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3500 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3501 | if (!name) { |
| 3502 | rc = -EINVAL; |
| 3503 | goto error; |
| 3504 | } |
| 3505 | |
| 3506 | #ifdef CONFIG_PM |
| 3507 | if (!fw_loaded) { |
| 3508 | #endif |
| 3509 | rc = ipw_get_fw(priv, &raw, name); |
| 3510 | if (rc < 0) |
| 3511 | goto error; |
| 3512 | #ifdef CONFIG_PM |
| 3513 | } |
| 3514 | #endif |
| 3515 | |
| 3516 | fw = (void *)raw->data; |
| 3517 | boot_img = &fw->data[0]; |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3518 | ucode_img = &fw->data[le32_to_cpu(fw->boot_size)]; |
| 3519 | fw_img = &fw->data[le32_to_cpu(fw->boot_size) + |
| 3520 | le32_to_cpu(fw->ucode_size)]; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3521 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3522 | if (rc < 0) |
| 3523 | goto error; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3524 | |
| 3525 | if (!priv->rxq) |
| 3526 | priv->rxq = ipw_rx_queue_alloc(priv); |
| 3527 | else |
| 3528 | ipw_rx_queue_reset(priv, priv->rxq); |
| 3529 | if (!priv->rxq) { |
| 3530 | IPW_ERROR("Unable to initialize Rx queue\n"); |
| 3531 | goto error; |
| 3532 | } |
| 3533 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3534 | retry: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3535 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3536 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3537 | priv->status &= ~STATUS_INT_ENABLED; |
| 3538 | |
| 3539 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3540 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3541 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3542 | ipw_stop_nic(priv); |
| 3543 | |
| 3544 | rc = ipw_reset_nic(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3545 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3546 | IPW_ERROR("Unable to reset NIC\n"); |
| 3547 | goto error; |
| 3548 | } |
| 3549 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3550 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
| 3551 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3552 | |
| 3553 | /* DMA the initial boot firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3554 | 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] | 3555 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3556 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3557 | goto error; |
| 3558 | } |
| 3559 | |
| 3560 | /* kick start the device */ |
| 3561 | ipw_start_nic(priv); |
| 3562 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3563 | /* wait for the device to finish its initial startup sequence */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3564 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3565 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3566 | if (rc < 0) { |
| 3567 | IPW_ERROR("device failed to boot initial fw image\n"); |
| 3568 | goto error; |
| 3569 | } |
| 3570 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); |
| 3571 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3572 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3573 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3574 | |
| 3575 | /* DMA the ucode into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3576 | 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] | 3577 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3578 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3579 | goto error; |
| 3580 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3581 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3582 | /* stop nic */ |
| 3583 | ipw_stop_nic(priv); |
| 3584 | |
| 3585 | /* DMA bss firmware into the device */ |
Zhu Yi | 0070f8c | 2006-04-13 17:20:12 +0800 | [diff] [blame] | 3586 | 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] | 3587 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3588 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3589 | goto error; |
| 3590 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3591 | #ifdef CONFIG_PM |
| 3592 | fw_loaded = 1; |
| 3593 | #endif |
| 3594 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3595 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 3596 | |
| 3597 | rc = ipw_queue_reset(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3598 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3599 | IPW_ERROR("Unable to initialize queues\n"); |
| 3600 | goto error; |
| 3601 | } |
| 3602 | |
| 3603 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3604 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3605 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3606 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3607 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3608 | /* kick start the device */ |
| 3609 | ipw_start_nic(priv); |
| 3610 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3611 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3612 | if (retries > 0) { |
| 3613 | IPW_WARNING("Parity error. Retrying init.\n"); |
| 3614 | retries--; |
| 3615 | goto retry; |
| 3616 | } |
| 3617 | |
| 3618 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); |
| 3619 | rc = -EIO; |
| 3620 | goto error; |
| 3621 | } |
| 3622 | |
| 3623 | /* wait for the device */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3624 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3625 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3626 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3627 | IPW_ERROR("device failed to start within 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3628 | goto error; |
| 3629 | } |
| 3630 | IPW_DEBUG_INFO("device response after %dms\n", rc); |
| 3631 | |
| 3632 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3633 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3634 | |
| 3635 | /* read eeprom data and initialize the eeprom region of sram */ |
| 3636 | priv->eeprom_delay = 1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3637 | ipw_eeprom_init_sram(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3638 | |
| 3639 | /* enable interrupts */ |
| 3640 | ipw_enable_interrupts(priv); |
| 3641 | |
| 3642 | /* Ensure our queue has valid packets */ |
| 3643 | ipw_rx_queue_replenish(priv); |
| 3644 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3645 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3646 | |
| 3647 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3648 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3649 | |
| 3650 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3651 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3652 | #endif |
| 3653 | return 0; |
| 3654 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3655 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3656 | if (priv->rxq) { |
| 3657 | ipw_rx_queue_free(priv, priv->rxq); |
| 3658 | priv->rxq = NULL; |
| 3659 | } |
| 3660 | ipw_tx_queue_free(priv); |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3661 | if (raw) |
| 3662 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3663 | #ifdef CONFIG_PM |
| 3664 | fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3665 | raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3666 | #endif |
| 3667 | |
| 3668 | return rc; |
| 3669 | } |
| 3670 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3671 | /** |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3672 | * DMA services |
| 3673 | * |
| 3674 | * Theory of operation |
| 3675 | * |
| 3676 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 3677 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 3678 | * |
| 3679 | * 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] | 3680 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 3681 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3682 | * Tx queue resumed. |
| 3683 | * |
| 3684 | * The IPW operates with six queues, one receive queue in the device's |
| 3685 | * sram, one transmit queue for sending commands to the device firmware, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3686 | * and four transmit queues for data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3687 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3688 | * The four transmit queues allow for performing quality of service (qos) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3689 | * transmissions as per the 802.11 protocol. Currently Linux does not |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3690 | * provide a mechanism to the user for utilizing prioritized queues, so |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3691 | * we only utilize the first data transmit queue (queue1). |
| 3692 | */ |
| 3693 | |
| 3694 | /** |
| 3695 | * Driver allocates buffers of this size for Rx |
| 3696 | */ |
| 3697 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 3698 | /** |
| 3699 | * ipw_rx_queue_space - Return number of free slots available in queue. |
| 3700 | */ |
| 3701 | static int ipw_rx_queue_space(const struct ipw_rx_queue *q) |
| 3702 | { |
| 3703 | int s = q->read - q->write; |
| 3704 | if (s <= 0) |
| 3705 | s += RX_QUEUE_SIZE; |
| 3706 | /* keep some buffer to not confuse full and empty queue */ |
| 3707 | s -= 2; |
| 3708 | if (s < 0) |
| 3709 | s = 0; |
| 3710 | return s; |
| 3711 | } |
| 3712 | |
| 3713 | static inline int ipw_tx_queue_space(const struct clx2_queue *q) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3714 | { |
| 3715 | int s = q->last_used - q->first_empty; |
| 3716 | if (s <= 0) |
| 3717 | s += q->n_bd; |
| 3718 | s -= 2; /* keep some reserve to not confuse empty and full situations */ |
| 3719 | if (s < 0) |
| 3720 | s = 0; |
| 3721 | return s; |
| 3722 | } |
| 3723 | |
| 3724 | static inline int ipw_queue_inc_wrap(int index, int n_bd) |
| 3725 | { |
| 3726 | return (++index == n_bd) ? 0 : index; |
| 3727 | } |
| 3728 | |
| 3729 | /** |
| 3730 | * Initialize common DMA queue structure |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3731 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3732 | * @param q queue to init |
| 3733 | * @param count Number of BD's to allocate. Should be power of 2 |
| 3734 | * @param read_register Address for 'read' register |
| 3735 | * (not offset within BAR, full address) |
| 3736 | * @param write_register Address for 'write' register |
| 3737 | * (not offset within BAR, full address) |
| 3738 | * @param base_register Address for 'base' register |
| 3739 | * (not offset within BAR, full address) |
| 3740 | * @param size Address for 'size' register |
| 3741 | * (not offset within BAR, full address) |
| 3742 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3743 | 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] | 3744 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3745 | { |
| 3746 | q->n_bd = count; |
| 3747 | |
| 3748 | q->low_mark = q->n_bd / 4; |
| 3749 | if (q->low_mark < 4) |
| 3750 | q->low_mark = 4; |
| 3751 | |
| 3752 | q->high_mark = q->n_bd / 8; |
| 3753 | if (q->high_mark < 2) |
| 3754 | q->high_mark = 2; |
| 3755 | |
| 3756 | q->first_empty = q->last_used = 0; |
| 3757 | q->reg_r = read; |
| 3758 | q->reg_w = write; |
| 3759 | |
| 3760 | ipw_write32(priv, base, q->dma_addr); |
| 3761 | ipw_write32(priv, size, count); |
| 3762 | ipw_write32(priv, read, 0); |
| 3763 | ipw_write32(priv, write, 0); |
| 3764 | |
| 3765 | _ipw_read32(priv, 0x90); |
| 3766 | } |
| 3767 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3768 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3769 | struct clx2_tx_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3770 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3771 | { |
| 3772 | struct pci_dev *dev = priv->pci_dev; |
| 3773 | |
| 3774 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); |
| 3775 | if (!q->txb) { |
| 3776 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); |
| 3777 | return -ENOMEM; |
| 3778 | } |
| 3779 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3780 | q->bd = |
| 3781 | 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] | 3782 | if (!q->bd) { |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3783 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3784 | sizeof(q->bd[0]) * count); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3785 | kfree(q->txb); |
| 3786 | q->txb = NULL; |
| 3787 | return -ENOMEM; |
| 3788 | } |
| 3789 | |
| 3790 | ipw_queue_init(priv, &q->q, count, read, write, base, size); |
| 3791 | return 0; |
| 3792 | } |
| 3793 | |
| 3794 | /** |
| 3795 | * Free one TFD, those at index [txq->q.last_used]. |
| 3796 | * Do NOT advance any indexes |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3797 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3798 | * @param dev |
| 3799 | * @param txq |
| 3800 | */ |
| 3801 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, |
| 3802 | struct clx2_tx_queue *txq) |
| 3803 | { |
| 3804 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; |
| 3805 | struct pci_dev *dev = priv->pci_dev; |
| 3806 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3807 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3808 | /* classify bd */ |
| 3809 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) |
| 3810 | /* nothing to cleanup after for host commands */ |
| 3811 | return; |
| 3812 | |
| 3813 | /* sanity check */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3814 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
| 3815 | IPW_ERROR("Too many chunks: %i\n", |
| 3816 | le32_to_cpu(bd->u.data.num_chunks)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3817 | /** @todo issue fatal error, it is quite serious situation */ |
| 3818 | return; |
| 3819 | } |
| 3820 | |
| 3821 | /* unmap chunks if any */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3822 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
| 3823 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), |
| 3824 | le16_to_cpu(bd->u.data.chunk_len[i]), |
| 3825 | PCI_DMA_TODEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3826 | if (txq->txb[txq->q.last_used]) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 3827 | libipw_txb_free(txq->txb[txq->q.last_used]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3828 | txq->txb[txq->q.last_used] = NULL; |
| 3829 | } |
| 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | /** |
| 3834 | * Deallocate DMA queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3835 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3836 | * Empty queue by removing and destroying all BD's. |
| 3837 | * Free all buffers. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3838 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3839 | * @param dev |
| 3840 | * @param q |
| 3841 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3842 | 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] | 3843 | { |
| 3844 | struct clx2_queue *q = &txq->q; |
| 3845 | struct pci_dev *dev = priv->pci_dev; |
| 3846 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3847 | if (q->n_bd == 0) |
| 3848 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3849 | |
| 3850 | /* first, empty all BD's */ |
| 3851 | for (; q->first_empty != q->last_used; |
| 3852 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3853 | ipw_queue_tx_free_tfd(priv, txq); |
| 3854 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3855 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3856 | /* free buffers belonging to queue itself */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3857 | 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] | 3858 | q->dma_addr); |
| 3859 | kfree(txq->txb); |
| 3860 | |
| 3861 | /* 0 fill whole structure */ |
| 3862 | memset(txq, 0, sizeof(*txq)); |
| 3863 | } |
| 3864 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3865 | /** |
| 3866 | * Destroy all DMA queues and structures |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3867 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3868 | * @param priv |
| 3869 | */ |
| 3870 | static void ipw_tx_queue_free(struct ipw_priv *priv) |
| 3871 | { |
| 3872 | /* Tx CMD queue */ |
| 3873 | ipw_queue_tx_free(priv, &priv->txq_cmd); |
| 3874 | |
| 3875 | /* Tx queues */ |
| 3876 | ipw_queue_tx_free(priv, &priv->txq[0]); |
| 3877 | ipw_queue_tx_free(priv, &priv->txq[1]); |
| 3878 | ipw_queue_tx_free(priv, &priv->txq[2]); |
| 3879 | ipw_queue_tx_free(priv, &priv->txq[3]); |
| 3880 | } |
| 3881 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3882 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3883 | { |
| 3884 | /* First 3 bytes are manufacturer */ |
| 3885 | bssid[0] = priv->mac_addr[0]; |
| 3886 | bssid[1] = priv->mac_addr[1]; |
| 3887 | bssid[2] = priv->mac_addr[2]; |
| 3888 | |
| 3889 | /* Last bytes are random */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3890 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3891 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3892 | bssid[0] &= 0xfe; /* clear multicast bit */ |
| 3893 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3894 | } |
| 3895 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3896 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3897 | { |
| 3898 | struct ipw_station_entry entry; |
| 3899 | int i; |
| 3900 | |
| 3901 | for (i = 0; i < priv->num_stations; i++) { |
| 3902 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { |
| 3903 | /* Another node is active in network */ |
| 3904 | priv->missed_adhoc_beacons = 0; |
| 3905 | if (!(priv->config & CFG_STATIC_CHANNEL)) |
| 3906 | /* when other nodes drop out, we drop out */ |
| 3907 | priv->config &= ~CFG_ADHOC_PERSIST; |
| 3908 | |
| 3909 | return i; |
| 3910 | } |
| 3911 | } |
| 3912 | |
| 3913 | if (i == MAX_STATIONS) |
| 3914 | return IPW_INVALID_STATION; |
| 3915 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3916 | IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3917 | |
| 3918 | entry.reserved = 0; |
| 3919 | entry.support_mode = 0; |
| 3920 | memcpy(entry.mac_addr, bssid, ETH_ALEN); |
| 3921 | memcpy(priv->stations[i], bssid, ETH_ALEN); |
| 3922 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3923 | &entry, sizeof(entry)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3924 | priv->num_stations++; |
| 3925 | |
| 3926 | return i; |
| 3927 | } |
| 3928 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3929 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3930 | { |
| 3931 | int i; |
| 3932 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3933 | for (i = 0; i < priv->num_stations; i++) |
| 3934 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3935 | return i; |
| 3936 | |
| 3937 | return IPW_INVALID_STATION; |
| 3938 | } |
| 3939 | |
| 3940 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) |
| 3941 | { |
| 3942 | int err; |
| 3943 | |
Hong Liu | 7b99659 | 2005-08-25 17:36:13 +0800 | [diff] [blame] | 3944 | if (priv->status & STATUS_ASSOCIATING) { |
| 3945 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); |
| 3946 | queue_work(priv->workqueue, &priv->disassociate); |
| 3947 | return; |
| 3948 | } |
| 3949 | |
| 3950 | if (!(priv->status & STATUS_ASSOCIATED)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3951 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
| 3952 | return; |
| 3953 | } |
| 3954 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3955 | IPW_DEBUG_ASSOC("Disassocation attempt from %pM " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3956 | "on channel %d.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3957 | priv->assoc_request.bssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3958 | priv->assoc_request.channel); |
| 3959 | |
| 3960 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); |
| 3961 | priv->status |= STATUS_DISASSOCIATING; |
| 3962 | |
| 3963 | if (quiet) |
| 3964 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; |
| 3965 | else |
| 3966 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 3967 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3968 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 3969 | if (err) { |
| 3970 | IPW_DEBUG_HC("Attempt to send [dis]associate command " |
| 3971 | "failed.\n"); |
| 3972 | return; |
| 3973 | } |
| 3974 | |
| 3975 | } |
| 3976 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3977 | static int ipw_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3978 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3979 | struct ipw_priv *priv = data; |
| 3980 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) |
| 3981 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3982 | ipw_send_disassociate(data, 0); |
Zhu Yi | b8ddafd | 2008-11-27 13:42:20 +0800 | [diff] [blame] | 3983 | netif_carrier_off(priv->net_dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3984 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3985 | } |
| 3986 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3987 | static void ipw_bg_disassociate(struct work_struct *work) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3988 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3989 | struct ipw_priv *priv = |
| 3990 | container_of(work, struct ipw_priv, disassociate); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3991 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3992 | ipw_disassociate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3993 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3994 | } |
| 3995 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3996 | static void ipw_system_config(struct work_struct *work) |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 3997 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3998 | struct ipw_priv *priv = |
| 3999 | container_of(work, struct ipw_priv, system_config); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 4000 | |
| 4001 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 4002 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 4003 | priv->sys_config.accept_all_data_frames = 1; |
| 4004 | priv->sys_config.accept_non_directed_frames = 1; |
| 4005 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 4006 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 4007 | } |
| 4008 | #endif |
| 4009 | |
| 4010 | ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4011 | } |
| 4012 | |
| 4013 | struct ipw_status_code { |
| 4014 | u16 status; |
| 4015 | const char *reason; |
| 4016 | }; |
| 4017 | |
| 4018 | static const struct ipw_status_code ipw_status_codes[] = { |
| 4019 | {0x00, "Successful"}, |
| 4020 | {0x01, "Unspecified failure"}, |
| 4021 | {0x0A, "Cannot support all requested capabilities in the " |
| 4022 | "Capability information field"}, |
| 4023 | {0x0B, "Reassociation denied due to inability to confirm that " |
| 4024 | "association exists"}, |
| 4025 | {0x0C, "Association denied due to reason outside the scope of this " |
| 4026 | "standard"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4027 | {0x0D, |
| 4028 | "Responding station does not support the specified authentication " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4029 | "algorithm"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4030 | {0x0E, |
| 4031 | "Received an Authentication frame with authentication sequence " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4032 | "transaction sequence number out of expected sequence"}, |
| 4033 | {0x0F, "Authentication rejected because of challenge failure"}, |
| 4034 | {0x10, "Authentication rejected due to timeout waiting for next " |
| 4035 | "frame in sequence"}, |
| 4036 | {0x11, "Association denied because AP is unable to handle additional " |
| 4037 | "associated stations"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4038 | {0x12, |
| 4039 | "Association denied due to requesting station not supporting all " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4040 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4041 | {0x13, |
| 4042 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4043 | "short preamble operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4044 | {0x14, |
| 4045 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4046 | "PBCC encoding"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4047 | {0x15, |
| 4048 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4049 | "channel agility"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4050 | {0x19, |
| 4051 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4052 | "short slot operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4053 | {0x1A, |
| 4054 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4055 | "DSSS-OFDM operation"}, |
| 4056 | {0x28, "Invalid Information Element"}, |
| 4057 | {0x29, "Group Cipher is not valid"}, |
| 4058 | {0x2A, "Pairwise Cipher is not valid"}, |
| 4059 | {0x2B, "AKMP is not valid"}, |
| 4060 | {0x2C, "Unsupported RSN IE version"}, |
| 4061 | {0x2D, "Invalid RSN IE Capabilities"}, |
| 4062 | {0x2E, "Cipher suite is rejected per security policy"}, |
| 4063 | }; |
| 4064 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4065 | static const char *ipw_get_status_code(u16 status) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4066 | { |
| 4067 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4068 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4069 | if (ipw_status_codes[i].status == (status & 0xff)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4070 | return ipw_status_codes[i].reason; |
| 4071 | return "Unknown status value."; |
| 4072 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4073 | |
| 4074 | static void inline average_init(struct average *avg) |
| 4075 | { |
| 4076 | memset(avg, 0, sizeof(*avg)); |
| 4077 | } |
| 4078 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4079 | #define DEPTH_RSSI 8 |
| 4080 | #define DEPTH_NOISE 16 |
| 4081 | static s16 exponential_average(s16 prev_avg, s16 val, u8 depth) |
| 4082 | { |
| 4083 | return ((depth-1)*prev_avg + val)/depth; |
| 4084 | } |
| 4085 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4086 | static void average_add(struct average *avg, s16 val) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4087 | { |
| 4088 | avg->sum -= avg->entries[avg->pos]; |
| 4089 | avg->sum += val; |
| 4090 | avg->entries[avg->pos++] = val; |
| 4091 | if (unlikely(avg->pos == AVG_ENTRIES)) { |
| 4092 | avg->init = 1; |
| 4093 | avg->pos = 0; |
| 4094 | } |
| 4095 | } |
| 4096 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4097 | static s16 average_value(struct average *avg) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4098 | { |
| 4099 | if (!unlikely(avg->init)) { |
| 4100 | if (avg->pos) |
| 4101 | return avg->sum / avg->pos; |
| 4102 | return 0; |
| 4103 | } |
| 4104 | |
| 4105 | return avg->sum / AVG_ENTRIES; |
| 4106 | } |
| 4107 | |
| 4108 | static void ipw_reset_stats(struct ipw_priv *priv) |
| 4109 | { |
| 4110 | u32 len = sizeof(u32); |
| 4111 | |
| 4112 | priv->quality = 0; |
| 4113 | |
| 4114 | average_init(&priv->average_missed_beacons); |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4115 | priv->exp_avg_rssi = -60; |
| 4116 | priv->exp_avg_noise = -85 + 0x100; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4117 | |
| 4118 | priv->last_rate = 0; |
| 4119 | priv->last_missed_beacons = 0; |
| 4120 | priv->last_rx_packets = 0; |
| 4121 | priv->last_tx_packets = 0; |
| 4122 | priv->last_tx_failures = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4123 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4124 | /* Firmware managed, reset only when NIC is restarted, so we have to |
| 4125 | * normalize on the current value */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4126 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4127 | &priv->last_rx_err, &len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4128 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4129 | &priv->last_tx_failures, &len); |
| 4130 | |
| 4131 | /* Driver managed, reset with each association */ |
| 4132 | priv->missed_adhoc_beacons = 0; |
| 4133 | priv->missed_beacons = 0; |
| 4134 | priv->tx_packets = 0; |
| 4135 | priv->rx_packets = 0; |
| 4136 | |
| 4137 | } |
| 4138 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4139 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4140 | { |
| 4141 | u32 i = 0x80000000; |
| 4142 | u32 mask = priv->rates_mask; |
| 4143 | /* If currently associated in B mode, restrict the maximum |
| 4144 | * rate match to B rates */ |
| 4145 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4146 | mask &= LIBIPW_CCK_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4147 | |
| 4148 | /* TODO: Verify that the rate is supported by the current rates |
| 4149 | * list. */ |
| 4150 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4151 | while (i && !(mask & i)) |
| 4152 | i >>= 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4153 | switch (i) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4154 | case LIBIPW_CCK_RATE_1MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4155 | return 1000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4156 | case LIBIPW_CCK_RATE_2MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4157 | return 2000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4158 | case LIBIPW_CCK_RATE_5MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4159 | return 5500000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4160 | case LIBIPW_OFDM_RATE_6MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4161 | return 6000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4162 | case LIBIPW_OFDM_RATE_9MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4163 | return 9000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4164 | case LIBIPW_CCK_RATE_11MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4165 | return 11000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4166 | case LIBIPW_OFDM_RATE_12MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4167 | return 12000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4168 | case LIBIPW_OFDM_RATE_18MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4169 | return 18000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4170 | case LIBIPW_OFDM_RATE_24MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4171 | return 24000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4172 | case LIBIPW_OFDM_RATE_36MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4173 | return 36000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4174 | case LIBIPW_OFDM_RATE_48MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4175 | return 48000000; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4176 | case LIBIPW_OFDM_RATE_54MB_MASK: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4177 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4178 | } |
| 4179 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4180 | if (priv->ieee->mode == IEEE_B) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4181 | return 11000000; |
| 4182 | else |
| 4183 | return 54000000; |
| 4184 | } |
| 4185 | |
| 4186 | static u32 ipw_get_current_rate(struct ipw_priv *priv) |
| 4187 | { |
| 4188 | u32 rate, len = sizeof(rate); |
| 4189 | int err; |
| 4190 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4191 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4192 | return 0; |
| 4193 | |
| 4194 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4195 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4196 | &len); |
| 4197 | if (err) { |
| 4198 | IPW_DEBUG_INFO("failed querying ordinals.\n"); |
| 4199 | return 0; |
| 4200 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4201 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4202 | return ipw_get_max_rate(priv); |
| 4203 | |
| 4204 | switch (rate) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4205 | case IPW_TX_RATE_1MB: |
| 4206 | return 1000000; |
| 4207 | case IPW_TX_RATE_2MB: |
| 4208 | return 2000000; |
| 4209 | case IPW_TX_RATE_5MB: |
| 4210 | return 5500000; |
| 4211 | case IPW_TX_RATE_6MB: |
| 4212 | return 6000000; |
| 4213 | case IPW_TX_RATE_9MB: |
| 4214 | return 9000000; |
| 4215 | case IPW_TX_RATE_11MB: |
| 4216 | return 11000000; |
| 4217 | case IPW_TX_RATE_12MB: |
| 4218 | return 12000000; |
| 4219 | case IPW_TX_RATE_18MB: |
| 4220 | return 18000000; |
| 4221 | case IPW_TX_RATE_24MB: |
| 4222 | return 24000000; |
| 4223 | case IPW_TX_RATE_36MB: |
| 4224 | return 36000000; |
| 4225 | case IPW_TX_RATE_48MB: |
| 4226 | return 48000000; |
| 4227 | case IPW_TX_RATE_54MB: |
| 4228 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | return 0; |
| 4232 | } |
| 4233 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4234 | #define IPW_STATS_INTERVAL (2 * HZ) |
| 4235 | static void ipw_gather_stats(struct ipw_priv *priv) |
| 4236 | { |
| 4237 | u32 rx_err, rx_err_delta, rx_packets_delta; |
| 4238 | u32 tx_failures, tx_failures_delta, tx_packets_delta; |
| 4239 | u32 missed_beacons_percent, missed_beacons_delta; |
| 4240 | u32 quality = 0; |
| 4241 | u32 len = sizeof(u32); |
| 4242 | s16 rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4243 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4244 | rate_quality; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4245 | u32 max_rate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4246 | |
| 4247 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 4248 | priv->quality = 0; |
| 4249 | return; |
| 4250 | } |
| 4251 | |
| 4252 | /* Update the statistics */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4253 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4254 | &priv->missed_beacons, &len); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4255 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4256 | priv->last_missed_beacons = priv->missed_beacons; |
| 4257 | if (priv->assoc_request.beacon_interval) { |
| 4258 | missed_beacons_percent = missed_beacons_delta * |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4259 | (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4260 | (IPW_STATS_INTERVAL * 10); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4261 | } else { |
| 4262 | missed_beacons_percent = 0; |
| 4263 | } |
| 4264 | average_add(&priv->average_missed_beacons, missed_beacons_percent); |
| 4265 | |
| 4266 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); |
| 4267 | rx_err_delta = rx_err - priv->last_rx_err; |
| 4268 | priv->last_rx_err = rx_err; |
| 4269 | |
| 4270 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); |
| 4271 | tx_failures_delta = tx_failures - priv->last_tx_failures; |
| 4272 | priv->last_tx_failures = tx_failures; |
| 4273 | |
| 4274 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; |
| 4275 | priv->last_rx_packets = priv->rx_packets; |
| 4276 | |
| 4277 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; |
| 4278 | priv->last_tx_packets = priv->tx_packets; |
| 4279 | |
| 4280 | /* Calculate quality based on the following: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4281 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4282 | * Missed beacon: 100% = 0, 0% = 70% missed |
| 4283 | * Rate: 60% = 1Mbs, 100% = Max |
| 4284 | * Rx and Tx errors represent a straight % of total Rx/Tx |
| 4285 | * RSSI: 100% = > -50, 0% = < -80 |
| 4286 | * Rx errors: 100% = 0, 0% = 50% missed |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4287 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4288 | * The lowest computed quality is used. |
| 4289 | * |
| 4290 | */ |
| 4291 | #define BEACON_THRESHOLD 5 |
| 4292 | beacon_quality = 100 - missed_beacons_percent; |
| 4293 | if (beacon_quality < BEACON_THRESHOLD) |
| 4294 | beacon_quality = 0; |
| 4295 | else |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4296 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4297 | (100 - BEACON_THRESHOLD); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4298 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4299 | beacon_quality, missed_beacons_percent); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4300 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4301 | priv->last_rate = ipw_get_current_rate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4302 | max_rate = ipw_get_max_rate(priv); |
| 4303 | rate_quality = priv->last_rate * 40 / max_rate + 60; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4304 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
| 4305 | rate_quality, priv->last_rate / 1000000); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4306 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4307 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4308 | rx_quality = 100 - (rx_err_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4309 | (rx_packets_delta + rx_err_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4310 | else |
| 4311 | rx_quality = 100; |
| 4312 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", |
| 4313 | rx_quality, rx_err_delta, rx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4314 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4315 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4316 | tx_quality = 100 - (tx_failures_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4317 | (tx_packets_delta + tx_failures_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4318 | else |
| 4319 | tx_quality = 100; |
| 4320 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", |
| 4321 | tx_quality, tx_failures_delta, tx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4322 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4323 | rssi = priv->exp_avg_rssi; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4324 | signal_quality = |
| 4325 | (100 * |
| 4326 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4327 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - |
| 4328 | (priv->ieee->perfect_rssi - rssi) * |
| 4329 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + |
| 4330 | 62 * (priv->ieee->perfect_rssi - rssi))) / |
| 4331 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4332 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); |
| 4333 | if (signal_quality > 100) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4334 | signal_quality = 100; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4335 | else if (signal_quality < 1) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4336 | signal_quality = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4337 | |
Zhu Yi | 61fb9ed | 2006-04-13 17:19:55 +0800 | [diff] [blame] | 4338 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4339 | signal_quality, rssi); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4340 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 4341 | quality = min(rx_quality, signal_quality); |
| 4342 | quality = min(tx_quality, quality); |
| 4343 | quality = min(rate_quality, quality); |
| 4344 | quality = min(beacon_quality, quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4345 | if (quality == beacon_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4346 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
| 4347 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4348 | if (quality == rate_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4349 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
| 4350 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4351 | if (quality == tx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4352 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
| 4353 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4354 | if (quality == rx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4355 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
| 4356 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4357 | if (quality == signal_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4358 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
| 4359 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4360 | |
| 4361 | priv->quality = quality; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4362 | |
| 4363 | queue_delayed_work(priv->workqueue, &priv->gather_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4364 | IPW_STATS_INTERVAL); |
| 4365 | } |
| 4366 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4367 | static void ipw_bg_gather_stats(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4368 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4369 | struct ipw_priv *priv = |
| 4370 | container_of(work, struct ipw_priv, gather_stats.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4371 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4372 | ipw_gather_stats(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4373 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4374 | } |
| 4375 | |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4376 | /* Missed beacon behavior: |
| 4377 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. |
| 4378 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. |
| 4379 | * Above disassociate threshold, give up and stop scanning. |
| 4380 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4381 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4382 | int missed_count) |
| 4383 | { |
| 4384 | priv->notif_missed_beacons = missed_count; |
| 4385 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4386 | if (missed_count > priv->disassociate_threshold && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4387 | priv->status & STATUS_ASSOCIATED) { |
| 4388 | /* If associated and we've hit the missed |
| 4389 | * beacon threshold, disassociate, turn |
| 4390 | * off roaming, and abort any active scans */ |
| 4391 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4392 | IPW_DL_STATE | IPW_DL_ASSOC, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4393 | "Missed beacon: %d - disassociate\n", missed_count); |
| 4394 | priv->status &= ~STATUS_ROAMING; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4395 | if (priv->status & STATUS_SCANNING) { |
| 4396 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 4397 | IPW_DL_STATE, |
| 4398 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4399 | queue_work(priv->workqueue, &priv->abort_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4400 | } |
| 4401 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4402 | queue_work(priv->workqueue, &priv->disassociate); |
| 4403 | return; |
| 4404 | } |
| 4405 | |
| 4406 | if (priv->status & STATUS_ROAMING) { |
| 4407 | /* If we are currently roaming, then just |
| 4408 | * print a debug statement... */ |
| 4409 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4410 | "Missed beacon: %d - roam in progress\n", |
| 4411 | missed_count); |
| 4412 | return; |
| 4413 | } |
| 4414 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 4415 | if (roaming && |
| 4416 | (missed_count > priv->roaming_threshold && |
| 4417 | missed_count <= priv->disassociate_threshold)) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4418 | /* If we are not already roaming, set the ROAM |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4419 | * bit in the status and kick off a scan. |
| 4420 | * This can happen several times before we reach |
| 4421 | * disassociate_threshold. */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4422 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4423 | "Missed beacon: %d - initiate " |
| 4424 | "roaming\n", missed_count); |
| 4425 | if (!(priv->status & STATUS_ROAMING)) { |
| 4426 | priv->status |= STATUS_ROAMING; |
| 4427 | if (!(priv->status & STATUS_SCANNING)) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4428 | queue_delayed_work(priv->workqueue, |
| 4429 | &priv->request_scan, 0); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4430 | } |
| 4431 | return; |
| 4432 | } |
| 4433 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 4434 | if (priv->status & STATUS_SCANNING && |
| 4435 | missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4436 | /* Stop scan to keep fw from getting |
| 4437 | * stuck (only if we aren't roaming -- |
| 4438 | * otherwise we'll never scan more than 2 or 3 |
| 4439 | * channels..) */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4440 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
| 4441 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4442 | queue_work(priv->workqueue, &priv->abort_scan); |
| 4443 | } |
| 4444 | |
| 4445 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4446 | } |
| 4447 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4448 | static void ipw_scan_event(struct work_struct *work) |
| 4449 | { |
| 4450 | union iwreq_data wrqu; |
| 4451 | |
| 4452 | struct ipw_priv *priv = |
| 4453 | container_of(work, struct ipw_priv, scan_event.work); |
| 4454 | |
| 4455 | wrqu.data.length = 0; |
| 4456 | wrqu.data.flags = 0; |
| 4457 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); |
| 4458 | } |
| 4459 | |
| 4460 | static void handle_scan_event(struct ipw_priv *priv) |
| 4461 | { |
| 4462 | /* Only userspace-requested scan completion events go out immediately */ |
| 4463 | if (!priv->user_requested_scan) { |
| 4464 | if (!delayed_work_pending(&priv->scan_event)) |
| 4465 | queue_delayed_work(priv->workqueue, &priv->scan_event, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 4466 | round_jiffies_relative(msecs_to_jiffies(4000))); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4467 | } else { |
| 4468 | union iwreq_data wrqu; |
| 4469 | |
| 4470 | priv->user_requested_scan = 0; |
| 4471 | cancel_delayed_work(&priv->scan_event); |
| 4472 | |
| 4473 | wrqu.data.length = 0; |
| 4474 | wrqu.data.flags = 0; |
| 4475 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); |
| 4476 | } |
| 4477 | } |
| 4478 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4479 | /** |
| 4480 | * Handle host notification packet. |
| 4481 | * Called from interrupt routine |
| 4482 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4483 | static void ipw_rx_notification(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4484 | struct ipw_rx_notification *notif) |
| 4485 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4486 | DECLARE_SSID_BUF(ssid); |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4487 | u16 size = le16_to_cpu(notif->size); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4488 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4489 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4490 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4491 | switch (notif->subtype) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4492 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
| 4493 | struct notif_association *assoc = ¬if->u.assoc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4494 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4495 | switch (assoc->state) { |
| 4496 | case CMAS_ASSOCIATED:{ |
| 4497 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4498 | IPW_DL_ASSOC, |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 4499 | "associated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4500 | print_ssid(ssid, priv->essid, |
| 4501 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4502 | priv->bssid); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4503 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4504 | switch (priv->ieee->iw_mode) { |
| 4505 | case IW_MODE_INFRA: |
| 4506 | memcpy(priv->ieee->bssid, |
| 4507 | priv->bssid, ETH_ALEN); |
| 4508 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4509 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4510 | case IW_MODE_ADHOC: |
| 4511 | memcpy(priv->ieee->bssid, |
| 4512 | priv->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4513 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4514 | /* clear out the station table */ |
| 4515 | priv->num_stations = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4516 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4517 | IPW_DEBUG_ASSOC |
| 4518 | ("queueing adhoc check\n"); |
| 4519 | queue_delayed_work(priv-> |
| 4520 | workqueue, |
| 4521 | &priv-> |
| 4522 | adhoc_check, |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4523 | le16_to_cpu(priv-> |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4524 | assoc_request. |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 4525 | beacon_interval)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4526 | break; |
| 4527 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4528 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4529 | priv->status &= ~STATUS_ASSOCIATING; |
| 4530 | priv->status |= STATUS_ASSOCIATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 4531 | queue_work(priv->workqueue, |
| 4532 | &priv->system_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4533 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 4534 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4535 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 4536 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control)) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4537 | if ((priv->status & STATUS_AUTH) && |
| 4538 | (IPW_GET_PACKET_STYPE(¬if->u.raw) |
| 4539 | == IEEE80211_STYPE_ASSOC_RESP)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4540 | if ((sizeof |
| 4541 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4542 | libipw_assoc_response) |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4543 | <= size) |
| 4544 | && (size <= 2314)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4545 | struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4546 | libipw_rx_stats |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4547 | stats = { |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4548 | .len = size - 1, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4549 | }; |
| 4550 | |
| 4551 | IPW_DEBUG_QOS |
| 4552 | ("QoS Associate " |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4553 | "size %d\n", size); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4554 | libipw_rx_mgt(priv-> |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4555 | ieee, |
| 4556 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4557 | libipw_hdr_4addr |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4558 | *) |
| 4559 | ¬if->u.raw, &stats); |
| 4560 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4561 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4562 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4563 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4564 | schedule_work(&priv->link_up); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4565 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4566 | break; |
| 4567 | } |
| 4568 | |
| 4569 | case CMAS_AUTHENTICATED:{ |
| 4570 | if (priv-> |
| 4571 | status & (STATUS_ASSOCIATED | |
| 4572 | STATUS_AUTH)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4573 | struct notif_authenticate *auth |
| 4574 | = ¬if->u.auth; |
| 4575 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4576 | IPW_DL_STATE | |
| 4577 | IPW_DL_ASSOC, |
| 4578 | "deauthenticated: '%s' " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4579 | "%pM" |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 4580 | ": (0x%04X) - %s\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4581 | print_ssid(ssid, |
| 4582 | priv-> |
| 4583 | essid, |
| 4584 | priv-> |
| 4585 | essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4586 | priv->bssid, |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4587 | le16_to_cpu(auth->status), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4588 | ipw_get_status_code |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4589 | (le16_to_cpu |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4590 | (auth->status))); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4591 | |
| 4592 | priv->status &= |
| 4593 | ~(STATUS_ASSOCIATING | |
| 4594 | STATUS_AUTH | |
| 4595 | STATUS_ASSOCIATED); |
| 4596 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4597 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4598 | break; |
| 4599 | } |
| 4600 | |
| 4601 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4602 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4603 | "authenticated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4604 | print_ssid(ssid, priv->essid, |
| 4605 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4606 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4607 | break; |
| 4608 | } |
| 4609 | |
| 4610 | case CMAS_INIT:{ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4611 | if (priv->status & STATUS_AUTH) { |
| 4612 | struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4613 | libipw_assoc_response |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4614 | *resp; |
| 4615 | resp = |
| 4616 | (struct |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 4617 | libipw_assoc_response |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4618 | *)¬if->u.raw; |
| 4619 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4620 | IPW_DL_STATE | |
| 4621 | IPW_DL_ASSOC, |
| 4622 | "association failed (0x%04X): %s\n", |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4623 | le16_to_cpu(resp->status), |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4624 | ipw_get_status_code |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4625 | (le16_to_cpu |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4626 | (resp->status))); |
| 4627 | } |
| 4628 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4629 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4630 | IPW_DL_ASSOC, |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 4631 | "disassociated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4632 | print_ssid(ssid, priv->essid, |
| 4633 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4634 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4635 | |
| 4636 | priv->status &= |
| 4637 | ~(STATUS_DISASSOCIATING | |
| 4638 | STATUS_ASSOCIATING | |
| 4639 | STATUS_ASSOCIATED | STATUS_AUTH); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4640 | if (priv->assoc_network |
| 4641 | && (priv->assoc_network-> |
| 4642 | capability & |
| 4643 | WLAN_CAPABILITY_IBSS)) |
| 4644 | ipw_remove_current_network |
| 4645 | (priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4646 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4647 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4648 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4649 | break; |
| 4650 | } |
| 4651 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4652 | case CMAS_RX_ASSOC_RESP: |
| 4653 | break; |
| 4654 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4655 | default: |
| 4656 | IPW_ERROR("assoc: unknown (%d)\n", |
| 4657 | assoc->state); |
| 4658 | break; |
| 4659 | } |
| 4660 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4661 | break; |
| 4662 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4663 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4664 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
| 4665 | struct notif_authenticate *auth = ¬if->u.auth; |
| 4666 | switch (auth->state) { |
| 4667 | case CMAS_AUTHENTICATED: |
| 4668 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 4669 | "authenticated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4670 | print_ssid(ssid, priv->essid, |
| 4671 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4672 | priv->bssid); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4673 | priv->status |= STATUS_AUTH; |
| 4674 | break; |
| 4675 | |
| 4676 | case CMAS_INIT: |
| 4677 | if (priv->status & STATUS_AUTH) { |
| 4678 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4679 | IPW_DL_ASSOC, |
| 4680 | "authentication failed (0x%04X): %s\n", |
Al Viro | 83f7d57 | 2008-03-16 22:26:44 +0000 | [diff] [blame] | 4681 | le16_to_cpu(auth->status), |
| 4682 | ipw_get_status_code(le16_to_cpu |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4683 | (auth-> |
| 4684 | status))); |
| 4685 | } |
| 4686 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4687 | IPW_DL_ASSOC, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4688 | "deauthenticated: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 4689 | print_ssid(ssid, priv->essid, |
| 4690 | priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4691 | priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4692 | |
| 4693 | priv->status &= ~(STATUS_ASSOCIATING | |
| 4694 | STATUS_AUTH | |
| 4695 | STATUS_ASSOCIATED); |
| 4696 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4697 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4698 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4699 | |
| 4700 | case CMAS_TX_AUTH_SEQ_1: |
| 4701 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4702 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); |
| 4703 | break; |
| 4704 | case CMAS_RX_AUTH_SEQ_2: |
| 4705 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4706 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); |
| 4707 | break; |
| 4708 | case CMAS_AUTH_SEQ_1_PASS: |
| 4709 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4710 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); |
| 4711 | break; |
| 4712 | case CMAS_AUTH_SEQ_1_FAIL: |
| 4713 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4714 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); |
| 4715 | break; |
| 4716 | case CMAS_TX_AUTH_SEQ_3: |
| 4717 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4718 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); |
| 4719 | break; |
| 4720 | case CMAS_RX_AUTH_SEQ_4: |
| 4721 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4722 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); |
| 4723 | break; |
| 4724 | case CMAS_AUTH_SEQ_2_PASS: |
| 4725 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4726 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); |
| 4727 | break; |
| 4728 | case CMAS_AUTH_SEQ_2_FAIL: |
| 4729 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4730 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); |
| 4731 | break; |
| 4732 | case CMAS_TX_ASSOC: |
| 4733 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4734 | IPW_DL_ASSOC, "TX_ASSOC\n"); |
| 4735 | break; |
| 4736 | case CMAS_RX_ASSOC_RESP: |
| 4737 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4738 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4739 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4740 | break; |
| 4741 | case CMAS_ASSOCIATED: |
| 4742 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4743 | IPW_DL_ASSOC, "ASSOCIATED\n"); |
| 4744 | break; |
| 4745 | default: |
| 4746 | IPW_DEBUG_NOTIF("auth: failure - %d\n", |
| 4747 | auth->state); |
| 4748 | break; |
| 4749 | } |
| 4750 | break; |
| 4751 | } |
| 4752 | |
| 4753 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
| 4754 | struct notif_channel_result *x = |
| 4755 | ¬if->u.channel_result; |
| 4756 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4757 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4758 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
| 4759 | x->channel_num); |
| 4760 | } else { |
| 4761 | IPW_DEBUG_SCAN("Scan result of wrong size %d " |
| 4762 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4763 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4764 | } |
| 4765 | break; |
| 4766 | } |
| 4767 | |
| 4768 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
| 4769 | struct notif_scan_complete *x = ¬if->u.scan_complete; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4770 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4771 | IPW_DEBUG_SCAN |
| 4772 | ("Scan completed: type %d, %d channels, " |
| 4773 | "%d status\n", x->scan_type, |
| 4774 | x->num_channels, x->status); |
| 4775 | } else { |
| 4776 | IPW_ERROR("Scan completed of wrong size %d " |
| 4777 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4778 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4779 | } |
| 4780 | |
| 4781 | priv->status &= |
| 4782 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 4783 | |
James Ketrenos | a0e04ab | 2005-08-25 00:49:43 -0500 | [diff] [blame] | 4784 | wake_up_interruptible(&priv->wait_state); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4785 | cancel_delayed_work(&priv->scan_check); |
| 4786 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4787 | if (priv->status & STATUS_EXIT_PENDING) |
| 4788 | break; |
| 4789 | |
| 4790 | priv->ieee->scans++; |
| 4791 | |
| 4792 | #ifdef CONFIG_IPW2200_MONITOR |
| 4793 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4794 | priv->status |= STATUS_SCAN_FORCED; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4795 | queue_delayed_work(priv->workqueue, |
| 4796 | &priv->request_scan, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4797 | break; |
| 4798 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4799 | priv->status &= ~STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4800 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 4801 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 4802 | /* Do queued direct scans first */ |
| 4803 | if (priv->status & STATUS_DIRECT_SCAN_PENDING) { |
| 4804 | queue_delayed_work(priv->workqueue, |
| 4805 | &priv->request_direct_scan, 0); |
| 4806 | } |
| 4807 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4808 | if (!(priv->status & (STATUS_ASSOCIATED | |
| 4809 | STATUS_ASSOCIATING | |
| 4810 | STATUS_ROAMING | |
| 4811 | STATUS_DISASSOCIATING))) |
| 4812 | queue_work(priv->workqueue, &priv->associate); |
| 4813 | else if (priv->status & STATUS_ROAMING) { |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4814 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4815 | /* If a scan completed and we are in roam mode, then |
| 4816 | * the scan that completed was the one requested as a |
| 4817 | * result of entering roam... so, schedule the |
| 4818 | * roam work */ |
| 4819 | queue_work(priv->workqueue, |
| 4820 | &priv->roam); |
| 4821 | else |
| 4822 | /* Don't schedule if we aborted the scan */ |
| 4823 | priv->status &= ~STATUS_ROAMING; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4824 | } else if (priv->status & STATUS_SCAN_PENDING) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4825 | queue_delayed_work(priv->workqueue, |
| 4826 | &priv->request_scan, 0); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4827 | else if (priv->config & CFG_BACKGROUND_SCAN |
| 4828 | && priv->status & STATUS_ASSOCIATED) |
| 4829 | queue_delayed_work(priv->workqueue, |
Stephen Hemminger | 1c9d5e4 | 2007-06-22 21:34:06 -0700 | [diff] [blame] | 4830 | &priv->request_scan, |
Anton Blanchard | be84e3d | 2007-10-15 00:38:01 -0500 | [diff] [blame] | 4831 | round_jiffies_relative(HZ)); |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 4832 | |
| 4833 | /* Send an empty event to user space. |
| 4834 | * We don't send the received data on the event because |
| 4835 | * it would require us to do complex transcoding, and |
| 4836 | * we want to minimise the work done in the irq handler |
| 4837 | * Use a request to extract the data. |
| 4838 | * Also, we generate this even for any scan, regardless |
| 4839 | * on how the scan was initiated. User space can just |
| 4840 | * sync on periodic scan to get fresh data... |
| 4841 | * Jean II */ |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 4842 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4843 | handle_scan_event(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4844 | break; |
| 4845 | } |
| 4846 | |
| 4847 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
| 4848 | struct notif_frag_length *x = ¬if->u.frag_len; |
| 4849 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4850 | if (size == sizeof(*x)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4851 | IPW_ERROR("Frag length: %d\n", |
| 4852 | le16_to_cpu(x->frag_length)); |
| 4853 | else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4854 | IPW_ERROR("Frag length of wrong size %d " |
| 4855 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4856 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4857 | break; |
| 4858 | } |
| 4859 | |
| 4860 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
| 4861 | struct notif_link_deterioration *x = |
| 4862 | ¬if->u.link_deterioration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4863 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4864 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4865 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Cahill, Ben M | 1297715 | 2006-03-08 02:58:02 +0800 | [diff] [blame] | 4866 | "link deterioration: type %d, cnt %d\n", |
| 4867 | x->silence_notification_type, |
| 4868 | x->silence_count); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4869 | memcpy(&priv->last_link_deterioration, x, |
| 4870 | sizeof(*x)); |
| 4871 | } else { |
| 4872 | IPW_ERROR("Link Deterioration of wrong size %d " |
| 4873 | "(should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4874 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4875 | } |
| 4876 | break; |
| 4877 | } |
| 4878 | |
| 4879 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
| 4880 | IPW_ERROR("Dino config\n"); |
| 4881 | if (priv->hcmd |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4882 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4883 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4884 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4885 | break; |
| 4886 | } |
| 4887 | |
| 4888 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
| 4889 | struct notif_beacon_state *x = ¬if->u.beacon_state; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4890 | if (size != sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4891 | IPW_ERROR |
| 4892 | ("Beacon state of wrong size %d (should " |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4893 | "be %zd)\n", size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4894 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4895 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4896 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4897 | if (le32_to_cpu(x->state) == |
| 4898 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) |
| 4899 | ipw_handle_missed_beacon(priv, |
| 4900 | le32_to_cpu(x-> |
| 4901 | number)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4902 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4903 | break; |
| 4904 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4905 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4906 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
| 4907 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4908 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4909 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
| 4910 | "0x%02x station %d\n", |
| 4911 | x->key_state, x->security_type, |
| 4912 | x->station_index); |
| 4913 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4914 | } |
| 4915 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4916 | IPW_ERROR |
| 4917 | ("TGi Tx Key of wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4918 | size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4919 | break; |
| 4920 | } |
| 4921 | |
| 4922 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
| 4923 | struct notif_calibration *x = ¬if->u.calibration; |
| 4924 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4925 | if (size == sizeof(*x)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4926 | memcpy(&priv->calib, x, sizeof(*x)); |
| 4927 | IPW_DEBUG_INFO("TODO: Calibration\n"); |
| 4928 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4929 | } |
| 4930 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4931 | IPW_ERROR |
| 4932 | ("Calibration of wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4933 | size, sizeof(*x)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4934 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4935 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4936 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4937 | case HOST_NOTIFICATION_NOISE_STATS:{ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4938 | if (size == sizeof(u32)) { |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4939 | priv->exp_avg_noise = |
| 4940 | exponential_average(priv->exp_avg_noise, |
| 4941 | (u8) (le32_to_cpu(notif->u.noise.value) & 0xff), |
| 4942 | DEPTH_NOISE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4943 | break; |
| 4944 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4945 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4946 | IPW_ERROR |
| 4947 | ("Noise stat is wrong size %d (should be %zd)\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4948 | size, sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4949 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4950 | } |
| 4951 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4952 | default: |
Zhu Yi | 1dd31b6 | 2006-02-20 18:28:09 -0800 | [diff] [blame] | 4953 | IPW_DEBUG_NOTIF("Unknown notification: " |
| 4954 | "subtype=%d,flags=0x%2x,size=%d\n", |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 4955 | notif->subtype, notif->flags, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4956 | } |
| 4957 | } |
| 4958 | |
| 4959 | /** |
| 4960 | * Destroys all DMA structures and initialise them again |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4961 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4962 | * @param priv |
| 4963 | * @return error code |
| 4964 | */ |
| 4965 | static int ipw_queue_reset(struct ipw_priv *priv) |
| 4966 | { |
| 4967 | int rc = 0; |
| 4968 | /** @todo customize queue sizes */ |
| 4969 | int nTx = 64, nTxCmd = 8; |
| 4970 | ipw_tx_queue_free(priv); |
| 4971 | /* Tx CMD queue */ |
| 4972 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4973 | IPW_TX_CMD_QUEUE_READ_INDEX, |
| 4974 | IPW_TX_CMD_QUEUE_WRITE_INDEX, |
| 4975 | IPW_TX_CMD_QUEUE_BD_BASE, |
| 4976 | IPW_TX_CMD_QUEUE_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4977 | if (rc) { |
| 4978 | IPW_ERROR("Tx Cmd queue init failed\n"); |
| 4979 | goto error; |
| 4980 | } |
| 4981 | /* Tx queue(s) */ |
| 4982 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4983 | IPW_TX_QUEUE_0_READ_INDEX, |
| 4984 | IPW_TX_QUEUE_0_WRITE_INDEX, |
| 4985 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4986 | if (rc) { |
| 4987 | IPW_ERROR("Tx 0 queue init failed\n"); |
| 4988 | goto error; |
| 4989 | } |
| 4990 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4991 | IPW_TX_QUEUE_1_READ_INDEX, |
| 4992 | IPW_TX_QUEUE_1_WRITE_INDEX, |
| 4993 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4994 | if (rc) { |
| 4995 | IPW_ERROR("Tx 1 queue init failed\n"); |
| 4996 | goto error; |
| 4997 | } |
| 4998 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4999 | IPW_TX_QUEUE_2_READ_INDEX, |
| 5000 | IPW_TX_QUEUE_2_WRITE_INDEX, |
| 5001 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5002 | if (rc) { |
| 5003 | IPW_ERROR("Tx 2 queue init failed\n"); |
| 5004 | goto error; |
| 5005 | } |
| 5006 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5007 | IPW_TX_QUEUE_3_READ_INDEX, |
| 5008 | IPW_TX_QUEUE_3_WRITE_INDEX, |
| 5009 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5010 | if (rc) { |
| 5011 | IPW_ERROR("Tx 3 queue init failed\n"); |
| 5012 | goto error; |
| 5013 | } |
| 5014 | /* statistics */ |
| 5015 | priv->rx_bufs_min = 0; |
| 5016 | priv->rx_pend_max = 0; |
| 5017 | return rc; |
| 5018 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5019 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5020 | ipw_tx_queue_free(priv); |
| 5021 | return rc; |
| 5022 | } |
| 5023 | |
| 5024 | /** |
| 5025 | * Reclaim Tx queue entries no more used by NIC. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5026 | * |
Stefano Brivio | 8ff9d21 | 2008-01-12 23:12:26 +0100 | [diff] [blame] | 5027 | * When FW advances 'R' index, all entries between old and |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5028 | * new 'R' index need to be reclaimed. As result, some free space |
| 5029 | * forms. If there is enough free space (> low mark), wake Tx queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5030 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5031 | * @note Need to protect against garbage in 'R' index |
| 5032 | * @param priv |
| 5033 | * @param txq |
| 5034 | * @param qindex |
| 5035 | * @return Number of used entries remains in the queue |
| 5036 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5037 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5038 | struct clx2_tx_queue *txq, int qindex) |
| 5039 | { |
| 5040 | u32 hw_tail; |
| 5041 | int used; |
| 5042 | struct clx2_queue *q = &txq->q; |
| 5043 | |
| 5044 | hw_tail = ipw_read32(priv, q->reg_r); |
| 5045 | if (hw_tail >= q->n_bd) { |
| 5046 | IPW_ERROR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5047 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
| 5048 | hw_tail, q->n_bd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5049 | goto done; |
| 5050 | } |
| 5051 | for (; q->last_used != hw_tail; |
| 5052 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 5053 | ipw_queue_tx_free_tfd(priv, txq); |
| 5054 | priv->tx_packets++; |
| 5055 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5056 | done: |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5057 | if ((ipw_tx_queue_space(q) > q->low_mark) && |
David S. Miller | 521c4d9 | 2008-07-22 18:32:47 -0700 | [diff] [blame] | 5058 | (qindex >= 0)) |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 5059 | netif_wake_queue(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5060 | used = q->first_empty - q->last_used; |
| 5061 | if (used < 0) |
| 5062 | used += q->n_bd; |
| 5063 | |
| 5064 | return used; |
| 5065 | } |
| 5066 | |
| 5067 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 5068 | int len, int sync) |
| 5069 | { |
| 5070 | struct clx2_tx_queue *txq = &priv->txq_cmd; |
| 5071 | struct clx2_queue *q = &txq->q; |
| 5072 | struct tfd_frame *tfd; |
| 5073 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5074 | if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5075 | IPW_ERROR("No space for Tx\n"); |
| 5076 | return -EBUSY; |
| 5077 | } |
| 5078 | |
| 5079 | tfd = &txq->bd[q->first_empty]; |
| 5080 | txq->txb[q->first_empty] = NULL; |
| 5081 | |
| 5082 | memset(tfd, 0, sizeof(*tfd)); |
| 5083 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; |
| 5084 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 5085 | priv->hcmd_seq++; |
| 5086 | tfd->u.cmd.index = hcmd; |
| 5087 | tfd->u.cmd.length = len; |
| 5088 | memcpy(tfd->u.cmd.payload, buf, len); |
| 5089 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 5090 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 5091 | _ipw_read32(priv, 0x90); |
| 5092 | |
| 5093 | return 0; |
| 5094 | } |
| 5095 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5096 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5097 | * Rx theory of operation |
| 5098 | * |
| 5099 | * The host allocates 32 DMA target addresses and passes the host address |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5100 | * 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] | 5101 | * 0 to 31 |
| 5102 | * |
| 5103 | * Rx Queue Indexes |
| 5104 | * The host/firmware share two index registers for managing the Rx buffers. |
| 5105 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5106 | * The READ index maps to the first position that the firmware may be writing |
| 5107 | * to -- the driver can read up to (but not including) this position and get |
| 5108 | * good data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5109 | * The READ index is managed by the firmware once the card is enabled. |
| 5110 | * |
| 5111 | * The WRITE index maps to the last position the driver has read from -- the |
| 5112 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 5113 | * |
| 5114 | * 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] | 5115 | * WRITE = READ. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5116 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5117 | * 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] | 5118 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 5119 | * |
| 5120 | * When the firmware places a packet in a buffer it will advance the READ index |
| 5121 | * and fire the RX interrupt. The driver can then query the READ index and |
| 5122 | * process as many packets as possible, moving the WRITE index forward as it |
| 5123 | * resets the Rx queue buffers with new memory. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5124 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5125 | * The management in the driver is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5126 | * + 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] | 5127 | * 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] | 5128 | * to replensish the ipw->rxq->rx_free. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5129 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
| 5130 | * ipw->rxq is replenished and the READ INDEX is updated (updating the |
| 5131 | * 'processed' and 'read' driver indexes as well) |
| 5132 | * + A received packet is processed and handed to the kernel network stack, |
| 5133 | * detached from the ipw->rxq. The driver 'processed' index is updated. |
| 5134 | * + 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] | 5135 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
| 5136 | * 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] | 5137 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 5138 | * |
| 5139 | * |
| 5140 | * Driver sequence: |
| 5141 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5142 | * ipw_rx_queue_alloc() Allocates rx_free |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5143 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
| 5144 | * ipw_rx_queue_restock |
| 5145 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 5146 | * queue, updates firmware pointers, and updates |
| 5147 | * the WRITE index. If insufficient rx_free buffers |
| 5148 | * are available, schedules ipw_rx_queue_replenish |
| 5149 | * |
| 5150 | * -- enable interrupts -- |
| 5151 | * 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] | 5152 | * READ INDEX, detaching the SKB from the pool. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5153 | * Moves the packet buffer from queue to rx_used. |
| 5154 | * Calls ipw_rx_queue_restock to refill any empty |
| 5155 | * slots. |
| 5156 | * ... |
| 5157 | * |
| 5158 | */ |
| 5159 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5160 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5161 | * If there are slots in the RX queue that need to be restocked, |
| 5162 | * and we have free pre-allocated buffers, fill the ranks as much |
| 5163 | * as we can pulling from rx_free. |
| 5164 | * |
| 5165 | * This moves the 'write' index forward to catch up with 'processed', and |
| 5166 | * also updates the memory address in the firmware to reference the new |
| 5167 | * target buffer. |
| 5168 | */ |
| 5169 | static void ipw_rx_queue_restock(struct ipw_priv *priv) |
| 5170 | { |
| 5171 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5172 | struct list_head *element; |
| 5173 | struct ipw_rx_mem_buffer *rxb; |
| 5174 | unsigned long flags; |
| 5175 | int write; |
| 5176 | |
| 5177 | spin_lock_irqsave(&rxq->lock, flags); |
| 5178 | write = rxq->write; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 5179 | while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5180 | element = rxq->rx_free.next; |
| 5181 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
| 5182 | list_del(element); |
| 5183 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5184 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5185 | rxb->dma_addr); |
| 5186 | rxq->queue[rxq->write] = rxb; |
| 5187 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; |
| 5188 | rxq->free_count--; |
| 5189 | } |
| 5190 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5191 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5192 | /* If the pre-allocated buffer pool is dropping low, schedule to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5193 | * refill it */ |
| 5194 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 5195 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 5196 | |
| 5197 | /* 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] | 5198 | if (write != rxq->write) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5199 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | /* |
| 5203 | * 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] | 5204 | * Also restock the Rx queue via ipw_rx_queue_restock. |
| 5205 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5206 | * This is called as a scheduled work item (except for during intialization) |
| 5207 | */ |
| 5208 | static void ipw_rx_queue_replenish(void *data) |
| 5209 | { |
| 5210 | struct ipw_priv *priv = data; |
| 5211 | struct ipw_rx_queue *rxq = priv->rxq; |
| 5212 | struct list_head *element; |
| 5213 | struct ipw_rx_mem_buffer *rxb; |
| 5214 | unsigned long flags; |
| 5215 | |
| 5216 | spin_lock_irqsave(&rxq->lock, flags); |
| 5217 | while (!list_empty(&rxq->rx_used)) { |
| 5218 | element = rxq->rx_used.next; |
| 5219 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5220 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5221 | if (!rxb->skb) { |
| 5222 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", |
| 5223 | priv->net_dev->name); |
| 5224 | /* We don't reschedule replenish work here -- we will |
| 5225 | * call the restock method and if it still needs |
| 5226 | * more buffers it will schedule replenish */ |
| 5227 | break; |
| 5228 | } |
| 5229 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5230 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5231 | rxb->dma_addr = |
| 5232 | pci_map_single(priv->pci_dev, rxb->skb->data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5233 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5234 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5235 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 5236 | rxq->free_count++; |
| 5237 | } |
| 5238 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 5239 | |
| 5240 | ipw_rx_queue_restock(priv); |
| 5241 | } |
| 5242 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5243 | static void ipw_bg_rx_queue_replenish(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5244 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5245 | struct ipw_priv *priv = |
| 5246 | container_of(work, struct ipw_priv, rx_replenish); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5247 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5248 | ipw_rx_queue_replenish(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5249 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5250 | } |
| 5251 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5252 | /* 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] | 5253 | * 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] | 5254 | * 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] | 5255 | * non NULL it is unmapped and freed |
| 5256 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5257 | 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] | 5258 | { |
| 5259 | int i; |
| 5260 | |
| 5261 | if (!rxq) |
| 5262 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5263 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5264 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 5265 | if (rxq->pool[i].skb != NULL) { |
| 5266 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5267 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5268 | dev_kfree_skb(rxq->pool[i].skb); |
| 5269 | } |
| 5270 | } |
| 5271 | |
| 5272 | kfree(rxq); |
| 5273 | } |
| 5274 | |
| 5275 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) |
| 5276 | { |
| 5277 | struct ipw_rx_queue *rxq; |
| 5278 | int i; |
| 5279 | |
Takis | c75f474 | 2005-12-01 01:41:45 -0800 | [diff] [blame] | 5280 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
Panagiotis Issaris | ad18b0e | 2005-09-05 04:14:10 +0200 | [diff] [blame] | 5281 | if (unlikely(!rxq)) { |
| 5282 | IPW_ERROR("memory allocation failed\n"); |
| 5283 | return NULL; |
| 5284 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5285 | spin_lock_init(&rxq->lock); |
| 5286 | INIT_LIST_HEAD(&rxq->rx_free); |
| 5287 | INIT_LIST_HEAD(&rxq->rx_used); |
| 5288 | |
| 5289 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5290 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5291 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 5292 | |
| 5293 | /* Set us so that we have processed and used all buffers, but have |
| 5294 | * not restocked the Rx queue with fresh buffers */ |
| 5295 | rxq->read = rxq->write = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5296 | rxq->free_count = 0; |
| 5297 | |
| 5298 | return rxq; |
| 5299 | } |
| 5300 | |
| 5301 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) |
| 5302 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5303 | rate &= ~LIBIPW_BASIC_RATE_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5304 | if (ieee_mode == IEEE_A) { |
| 5305 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5306 | case LIBIPW_OFDM_RATE_6MB: |
| 5307 | return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5308 | 1 : 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5309 | case LIBIPW_OFDM_RATE_9MB: |
| 5310 | return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5311 | 1 : 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5312 | case LIBIPW_OFDM_RATE_12MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5313 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5314 | rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; |
| 5315 | case LIBIPW_OFDM_RATE_18MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5316 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5317 | rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; |
| 5318 | case LIBIPW_OFDM_RATE_24MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5319 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5320 | rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; |
| 5321 | case LIBIPW_OFDM_RATE_36MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5322 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5323 | rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; |
| 5324 | case LIBIPW_OFDM_RATE_48MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5325 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5326 | rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; |
| 5327 | case LIBIPW_OFDM_RATE_54MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5328 | return priv-> |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5329 | rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5330 | default: |
| 5331 | return 0; |
| 5332 | } |
| 5333 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5334 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5335 | /* B and G mixed */ |
| 5336 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5337 | case LIBIPW_CCK_RATE_1MB: |
| 5338 | return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0; |
| 5339 | case LIBIPW_CCK_RATE_2MB: |
| 5340 | return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0; |
| 5341 | case LIBIPW_CCK_RATE_5MB: |
| 5342 | return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0; |
| 5343 | case LIBIPW_CCK_RATE_11MB: |
| 5344 | return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | /* If we are limited to B modulations, bail at this point */ |
| 5348 | if (ieee_mode == IEEE_B) |
| 5349 | return 0; |
| 5350 | |
| 5351 | /* G */ |
| 5352 | switch (rate) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5353 | case LIBIPW_OFDM_RATE_6MB: |
| 5354 | return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0; |
| 5355 | case LIBIPW_OFDM_RATE_9MB: |
| 5356 | return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0; |
| 5357 | case LIBIPW_OFDM_RATE_12MB: |
| 5358 | return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; |
| 5359 | case LIBIPW_OFDM_RATE_18MB: |
| 5360 | return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; |
| 5361 | case LIBIPW_OFDM_RATE_24MB: |
| 5362 | return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; |
| 5363 | case LIBIPW_OFDM_RATE_36MB: |
| 5364 | return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; |
| 5365 | case LIBIPW_OFDM_RATE_48MB: |
| 5366 | return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; |
| 5367 | case LIBIPW_OFDM_RATE_54MB: |
| 5368 | return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5369 | } |
| 5370 | |
| 5371 | return 0; |
| 5372 | } |
| 5373 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5374 | static int ipw_compatible_rates(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5375 | const struct libipw_network *network, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5376 | struct ipw_supported_rates *rates) |
| 5377 | { |
| 5378 | int num_rates, i; |
| 5379 | |
| 5380 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5381 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5382 | rates->num_rates = 0; |
| 5383 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5384 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5385 | network->rates[i])) { |
| 5386 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5387 | if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5388 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5389 | "rate %02X\n", |
| 5390 | network->rates[i]); |
| 5391 | rates->supported_rates[rates->num_rates++] = |
| 5392 | network->rates[i]; |
| 5393 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5394 | } |
| 5395 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5396 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5397 | network->rates[i], priv->rates_mask); |
| 5398 | continue; |
| 5399 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5400 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5401 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
| 5402 | } |
| 5403 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5404 | num_rates = min(network->rates_ex_len, |
| 5405 | (u8) (IPW_MAX_RATES - num_rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5406 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5407 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5408 | network->rates_ex[i])) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5409 | if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5410 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5411 | "rate %02X\n", |
| 5412 | network->rates_ex[i]); |
| 5413 | rates->supported_rates[rates->num_rates++] = |
| 5414 | network->rates[i]; |
| 5415 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5416 | } |
| 5417 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5418 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5419 | network->rates_ex[i], priv->rates_mask); |
| 5420 | continue; |
| 5421 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5422 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5423 | rates->supported_rates[rates->num_rates++] = |
| 5424 | network->rates_ex[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5425 | } |
| 5426 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5427 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5428 | } |
| 5429 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5430 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5431 | const struct ipw_supported_rates *src) |
| 5432 | { |
| 5433 | u8 i; |
| 5434 | for (i = 0; i < src->num_rates; i++) |
| 5435 | dest->supported_rates[i] = src->supported_rates[i]; |
| 5436 | dest->num_rates = src->num_rates; |
| 5437 | } |
| 5438 | |
| 5439 | /* TODO: Look at sniffed packets in the air to determine if the basic rate |
| 5440 | * mask should ever be used -- right now all callers to add the scan rates are |
| 5441 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ |
| 5442 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5443 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5444 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5445 | u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? |
| 5446 | LIBIPW_BASIC_RATE_MASK : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5447 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5448 | if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5449 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5450 | LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5451 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5452 | if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5453 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5454 | LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5455 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5456 | if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5457 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5458 | LIBIPW_CCK_RATE_5MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5459 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5460 | if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5461 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5462 | LIBIPW_CCK_RATE_11MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5466 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5467 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5468 | u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? |
| 5469 | LIBIPW_BASIC_RATE_MASK : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5470 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5471 | if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5472 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5473 | LIBIPW_OFDM_RATE_6MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5474 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5475 | if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5476 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5477 | LIBIPW_OFDM_RATE_9MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5478 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5479 | if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5480 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5481 | LIBIPW_OFDM_RATE_12MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5482 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5483 | if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5484 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5485 | LIBIPW_OFDM_RATE_18MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5486 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5487 | if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5488 | rates->supported_rates[rates->num_rates++] = basic_mask | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5489 | LIBIPW_OFDM_RATE_24MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5490 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5491 | if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5492 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5493 | LIBIPW_OFDM_RATE_36MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5494 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5495 | if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5496 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5497 | LIBIPW_OFDM_RATE_48MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5498 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5499 | if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5500 | rates->supported_rates[rates->num_rates++] = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5501 | LIBIPW_OFDM_RATE_54MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | struct ipw_network_match { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5505 | struct libipw_network *network; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5506 | struct ipw_supported_rates rates; |
| 5507 | }; |
| 5508 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5509 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
| 5510 | struct ipw_network_match *match, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5511 | struct libipw_network *network, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5512 | int roaming) |
| 5513 | { |
| 5514 | struct ipw_supported_rates rates; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5515 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5516 | |
| 5517 | /* Verify that this network's capability is compatible with the |
| 5518 | * current mode (AdHoc or Infrastructure) */ |
| 5519 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5520 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5521 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5522 | "capability mismatch.\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 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5529 | if (unlikely(roaming)) { |
| 5530 | /* If we are roaming, then ensure check if this is a valid |
| 5531 | * network to try and roam to */ |
| 5532 | if ((network->ssid_len != match->network->ssid_len) || |
| 5533 | memcmp(network->ssid, match->network->ssid, |
| 5534 | network->ssid_len)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5535 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5536 | "because of non-network ESSID.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5537 | print_ssid(ssid, network->ssid, |
| 5538 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5539 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5540 | return 0; |
| 5541 | } |
| 5542 | } else { |
| 5543 | /* If an ESSID has been configured then compare the broadcast |
| 5544 | * ESSID to ours */ |
| 5545 | if ((priv->config & CFG_STATIC_ESSID) && |
| 5546 | ((network->ssid_len != priv->essid_len) || |
| 5547 | memcmp(network->ssid, priv->essid, |
| 5548 | min(network->ssid_len, priv->essid_len)))) { |
| 5549 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5550 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5551 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5552 | print_ssid(ssid, network->ssid, |
| 5553 | network->ssid_len), |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5554 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5555 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5556 | "because of ESSID mismatch: '%s'.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5557 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5558 | print_ssid(ssid, priv->essid, |
| 5559 | priv->essid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5560 | return 0; |
| 5561 | } |
| 5562 | } |
| 5563 | |
| 5564 | /* If the old network rate is better than this one, don't bother |
| 5565 | * testing everything else. */ |
| 5566 | |
| 5567 | if (network->time_stamp[0] < match->network->time_stamp[0]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5568 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5569 | "current network.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5570 | print_ssid(ssid, match->network->ssid, |
| 5571 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5572 | return 0; |
| 5573 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5574 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5575 | "current network.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5576 | print_ssid(ssid, match->network->ssid, |
| 5577 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5578 | return 0; |
| 5579 | } |
| 5580 | |
| 5581 | /* Now go through and see if the requested network is valid... */ |
| 5582 | if (priv->ieee->scan_age != 0 && |
| 5583 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5584 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5585 | "because of age: %ums.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5586 | print_ssid(ssid, network->ssid, |
| 5587 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5588 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5589 | jiffies_to_msecs(jiffies - |
| 5590 | network->last_scanned)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5591 | return 0; |
| 5592 | } |
| 5593 | |
| 5594 | if ((priv->config & CFG_STATIC_CHANNEL) && |
| 5595 | (network->channel != priv->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5596 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5597 | "because of channel mismatch: %d != %d.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5598 | print_ssid(ssid, network->ssid, |
| 5599 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5600 | network->bssid, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5601 | network->channel, priv->channel); |
| 5602 | return 0; |
| 5603 | } |
| 5604 | |
| 5605 | /* Verify privacy compatability */ |
| 5606 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
| 5607 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5608 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5609 | "because of privacy mismatch: %s != %s.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5610 | print_ssid(ssid, network->ssid, |
| 5611 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5612 | network->bssid, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5613 | priv-> |
| 5614 | capability & CAP_PRIVACY_ON ? "on" : "off", |
| 5615 | network-> |
| 5616 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : |
| 5617 | "off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5618 | return 0; |
| 5619 | } |
| 5620 | |
| 5621 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5622 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
| 5623 | "because of the same BSSID match: %pM" |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5624 | ".\n", print_ssid(ssid, network->ssid, |
| 5625 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5626 | network->bssid, |
| 5627 | priv->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5628 | return 0; |
| 5629 | } |
| 5630 | |
| 5631 | /* Filter out any incompatible freq / mode combinations */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5632 | if (!libipw_is_valid_mode(priv->ieee, network->mode)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5633 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5634 | "because of invalid frequency/mode " |
| 5635 | "combination.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5636 | print_ssid(ssid, network->ssid, |
| 5637 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5638 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5639 | return 0; |
| 5640 | } |
| 5641 | |
| 5642 | /* Ensure that the rates supported by the driver are compatible with |
| 5643 | * this AP, including verification of basic rates (mandatory) */ |
| 5644 | if (!ipw_compatible_rates(priv, network, &rates)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5645 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5646 | "because configured rate mask excludes " |
| 5647 | "AP mandatory rate.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5648 | print_ssid(ssid, network->ssid, |
| 5649 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5650 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5651 | return 0; |
| 5652 | } |
| 5653 | |
| 5654 | if (rates.num_rates == 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5655 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5656 | "because of no compatible rates.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5657 | print_ssid(ssid, network->ssid, |
| 5658 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5659 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5660 | return 0; |
| 5661 | } |
| 5662 | |
| 5663 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5664 | * want to put too much policy logic here; intelligent scan selection |
| 5665 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5666 | |
| 5667 | /* Set up 'new' AP to this network */ |
| 5668 | ipw_copy_rates(&match->rates, &rates); |
| 5669 | match->network = network; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5670 | IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5671 | print_ssid(ssid, network->ssid, network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5672 | network->bssid); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5673 | |
| 5674 | return 1; |
| 5675 | } |
| 5676 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5677 | static void ipw_merge_adhoc_network(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5678 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5679 | DECLARE_SSID_BUF(ssid); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5680 | struct ipw_priv *priv = |
| 5681 | container_of(work, struct ipw_priv, merge_networks); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5682 | struct libipw_network *network = NULL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5683 | struct ipw_network_match match = { |
| 5684 | .network = priv->assoc_network |
| 5685 | }; |
| 5686 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5687 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5688 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5689 | /* First pass through ROAM process -- look for a better |
| 5690 | * network */ |
| 5691 | unsigned long flags; |
| 5692 | |
| 5693 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 5694 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 5695 | if (network != priv->assoc_network) |
| 5696 | ipw_find_adhoc_network(priv, &match, network, |
| 5697 | 1); |
| 5698 | } |
| 5699 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 5700 | |
| 5701 | if (match.network == priv->assoc_network) { |
| 5702 | IPW_DEBUG_MERGE("No better ADHOC in this network to " |
| 5703 | "merge to.\n"); |
| 5704 | return; |
| 5705 | } |
| 5706 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5707 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5708 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
| 5709 | IPW_DEBUG_MERGE("remove network %s\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5710 | print_ssid(ssid, priv->essid, |
| 5711 | priv->essid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5712 | ipw_remove_current_network(priv); |
| 5713 | } |
| 5714 | |
| 5715 | ipw_disassociate(priv); |
| 5716 | priv->assoc_network = match.network; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5717 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5718 | return; |
| 5719 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5720 | } |
| 5721 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5722 | static int ipw_best_network(struct ipw_priv *priv, |
| 5723 | struct ipw_network_match *match, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5724 | struct libipw_network *network, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5725 | { |
| 5726 | struct ipw_supported_rates rates; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5727 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5728 | |
| 5729 | /* Verify that this network's capability is compatible with the |
| 5730 | * current mode (AdHoc or Infrastructure) */ |
| 5731 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && |
Jouni Malinen | 2474385 | 2005-08-14 20:59:59 -0700 | [diff] [blame] | 5732 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5733 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5734 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5735 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5736 | "capability mismatch.\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 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5743 | if (unlikely(roaming)) { |
| 5744 | /* If we are roaming, then ensure check if this is a valid |
| 5745 | * network to try and roam to */ |
| 5746 | if ((network->ssid_len != match->network->ssid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5747 | memcmp(network->ssid, match->network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5748 | network->ssid_len)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5749 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5750 | "because of non-network ESSID.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5751 | print_ssid(ssid, network->ssid, |
| 5752 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5753 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5754 | return 0; |
| 5755 | } |
| 5756 | } else { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5757 | /* If an ESSID has been configured then compare the broadcast |
| 5758 | * ESSID to ours */ |
| 5759 | if ((priv->config & CFG_STATIC_ESSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5760 | ((network->ssid_len != priv->essid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5761 | memcmp(network->ssid, priv->essid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5762 | min(network->ssid_len, priv->essid_len)))) { |
| 5763 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5764 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5765 | print_ssid(ssid, network->ssid, |
| 5766 | network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5767 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5768 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5769 | "because of ESSID mismatch: '%s'.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5770 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5771 | print_ssid(ssid, priv->essid, |
| 5772 | priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5773 | return 0; |
| 5774 | } |
| 5775 | } |
| 5776 | |
| 5777 | /* If the old network rate is better than this one, don't bother |
| 5778 | * testing everything else. */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5779 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5780 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5781 | strncpy(escaped, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5782 | print_ssid(ssid, network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5783 | sizeof(escaped)); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5784 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because " |
| 5785 | "'%s (%pM)' has a stronger signal.\n", |
| 5786 | escaped, network->bssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5787 | print_ssid(ssid, match->network->ssid, |
| 5788 | match->network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5789 | match->network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5790 | return 0; |
| 5791 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5792 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5793 | /* If this network has already had an association attempt within the |
| 5794 | * last 3 seconds, do not try and associate again... */ |
| 5795 | if (network->last_associate && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5796 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
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 storming (%ums since last " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5799 | "assoc attempt).\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5800 | print_ssid(ssid, network->ssid, |
| 5801 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5802 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5803 | jiffies_to_msecs(jiffies - |
| 5804 | network->last_associate)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5805 | return 0; |
| 5806 | } |
| 5807 | |
| 5808 | /* Now go through and see if the requested network is valid... */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5809 | if (priv->ieee->scan_age != 0 && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5810 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5811 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5812 | "because of age: %ums.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5813 | print_ssid(ssid, network->ssid, |
| 5814 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5815 | network->bssid, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5816 | jiffies_to_msecs(jiffies - |
| 5817 | network->last_scanned)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5818 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5819 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5820 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5821 | if ((priv->config & CFG_STATIC_CHANNEL) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5822 | (network->channel != priv->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5823 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5824 | "because of channel mismatch: %d != %d.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5825 | print_ssid(ssid, network->ssid, |
| 5826 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5827 | network->bssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5828 | network->channel, priv->channel); |
| 5829 | return 0; |
| 5830 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5831 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5832 | /* Verify privacy compatability */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5833 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5834 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5835 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5836 | "because of privacy mismatch: %s != %s.\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, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5840 | priv->capability & CAP_PRIVACY_ON ? "on" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5841 | "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5842 | network->capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5843 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5844 | return 0; |
| 5845 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5846 | |
| 5847 | if ((priv->config & CFG_STATIC_BSSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5848 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5849 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
| 5850 | "because of BSSID mismatch: %pM.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5851 | print_ssid(ssid, network->ssid, |
| 5852 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5853 | network->bssid, priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5854 | return 0; |
| 5855 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5856 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5857 | /* Filter out any incompatible freq / mode combinations */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5858 | if (!libipw_is_valid_mode(priv->ieee, network->mode)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5859 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5860 | "because of invalid frequency/mode " |
| 5861 | "combination.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5862 | print_ssid(ssid, network->ssid, |
| 5863 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5864 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5865 | return 0; |
| 5866 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5867 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5868 | /* Filter out invalid channel in current GEO */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5869 | if (!libipw_is_valid_channel(priv->ieee, network->channel)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5870 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5871 | "because of invalid channel in current GEO\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5872 | print_ssid(ssid, network->ssid, |
| 5873 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5874 | network->bssid); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5875 | return 0; |
| 5876 | } |
| 5877 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5878 | /* Ensure that the rates supported by the driver are compatible with |
| 5879 | * this AP, including verification of basic rates (mandatory) */ |
| 5880 | if (!ipw_compatible_rates(priv, network, &rates)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5881 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5882 | "because configured rate mask excludes " |
| 5883 | "AP mandatory rate.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5884 | print_ssid(ssid, network->ssid, |
| 5885 | network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5886 | network->bssid); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5887 | return 0; |
| 5888 | } |
| 5889 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5890 | if (rates.num_rates == 0) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5891 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5892 | "because of no compatible rates.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5893 | print_ssid(ssid, network->ssid, |
| 5894 | 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 | return 0; |
| 5897 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5898 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5899 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5900 | * want to put too much policy logic here; intelligent scan selection |
| 5901 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5902 | |
| 5903 | /* Set up 'new' AP to this network */ |
| 5904 | ipw_copy_rates(&match->rates, &rates); |
| 5905 | match->network = network; |
| 5906 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5907 | IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5908 | print_ssid(ssid, network->ssid, network->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5909 | network->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5910 | |
| 5911 | return 1; |
| 5912 | } |
| 5913 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5914 | static void ipw_adhoc_create(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5915 | struct libipw_network *network) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5916 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5917 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5918 | int i; |
| 5919 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5920 | /* |
| 5921 | * For the purposes of scanning, we can set our wireless mode |
| 5922 | * to trigger scans across combinations of bands, but when it |
| 5923 | * comes to creating a new ad-hoc network, we have tell the FW |
| 5924 | * exactly which band to use. |
| 5925 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5926 | * We also have the possibility of an invalid channel for the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5927 | * chossen band. Attempting to create a new ad-hoc network |
| 5928 | * with an invalid channel for wireless mode will trigger a |
| 5929 | * FW fatal error. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5930 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5931 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5932 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 5933 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5934 | network->mode = IEEE_A; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5935 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5936 | BUG_ON(i == -1); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5937 | if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5938 | IPW_WARNING("Overriding invalid channel\n"); |
| 5939 | priv->channel = geo->a[0].channel; |
| 5940 | } |
| 5941 | break; |
| 5942 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5943 | case LIBIPW_24GHZ_BAND: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5944 | if (priv->ieee->mode & IEEE_G) |
| 5945 | network->mode = IEEE_G; |
| 5946 | else |
| 5947 | network->mode = IEEE_B; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5948 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5949 | BUG_ON(i == -1); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 5950 | if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5951 | IPW_WARNING("Overriding invalid channel\n"); |
| 5952 | priv->channel = geo->bg[0].channel; |
| 5953 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5954 | break; |
| 5955 | |
| 5956 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5957 | IPW_WARNING("Overriding invalid channel\n"); |
| 5958 | if (priv->ieee->mode & IEEE_A) { |
| 5959 | network->mode = IEEE_A; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5960 | priv->channel = geo->a[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5961 | } else if (priv->ieee->mode & IEEE_G) { |
| 5962 | network->mode = IEEE_G; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5963 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5964 | } else { |
| 5965 | network->mode = IEEE_B; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5966 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5967 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5968 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | network->channel = priv->channel; |
| 5972 | priv->config |= CFG_ADHOC_PERSIST; |
| 5973 | ipw_create_bssid(priv, network->bssid); |
| 5974 | network->ssid_len = priv->essid_len; |
| 5975 | memcpy(network->ssid, priv->essid, priv->essid_len); |
| 5976 | memset(&network->stats, 0, sizeof(network->stats)); |
| 5977 | network->capability = WLAN_CAPABILITY_IBSS; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5978 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
| 5979 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5980 | if (priv->capability & CAP_PRIVACY_ON) |
| 5981 | network->capability |= WLAN_CAPABILITY_PRIVACY; |
| 5982 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5983 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5984 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5985 | memcpy(network->rates_ex, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5986 | &priv->rates.supported_rates[network->rates_len], |
| 5987 | network->rates_ex_len); |
| 5988 | network->last_scanned = 0; |
| 5989 | network->flags = 0; |
| 5990 | network->last_associate = 0; |
| 5991 | network->time_stamp[0] = 0; |
| 5992 | network->time_stamp[1] = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5993 | network->beacon_interval = 100; /* Default */ |
| 5994 | network->listen_interval = 10; /* Default */ |
| 5995 | network->atim_window = 0; /* Default */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5996 | network->wpa_ie_len = 0; |
| 5997 | network->rsn_ie_len = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5998 | } |
| 5999 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6000 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
| 6001 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6002 | struct ipw_tgi_tx_key key; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6003 | |
| 6004 | if (!(priv->ieee->sec.flags & (1 << index))) |
| 6005 | return; |
| 6006 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6007 | key.key_id = index; |
| 6008 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); |
| 6009 | key.security_type = type; |
| 6010 | key.station_index = 0; /* always 0 for BSS */ |
| 6011 | key.flags = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6012 | /* 0 for new key; previous value of counter (after fatal error) */ |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 6013 | key.tx_counter[0] = cpu_to_le32(0); |
| 6014 | key.tx_counter[1] = cpu_to_le32(0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6015 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6016 | 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] | 6017 | } |
| 6018 | |
| 6019 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6020 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6021 | struct ipw_wep_key key; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6022 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6023 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6024 | key.cmd_id = DINO_CMD_WEP_KEY; |
| 6025 | key.seq_num = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6026 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6027 | /* Note: AES keys cannot be set for multiple times. |
| 6028 | * Only set it at the first time. */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6029 | for (i = 0; i < 4; i++) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6030 | key.key_index = i | type; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6031 | if (!(priv->ieee->sec.flags & (1 << i))) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6032 | key.key_size = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6033 | continue; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6034 | } |
| 6035 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6036 | key.key_size = priv->ieee->sec.key_sizes[i]; |
| 6037 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6038 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6039 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6040 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6041 | } |
| 6042 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6043 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
| 6044 | { |
| 6045 | if (priv->ieee->host_encrypt) |
| 6046 | return; |
| 6047 | |
| 6048 | switch (level) { |
| 6049 | case SEC_LEVEL_3: |
| 6050 | priv->sys_config.disable_unicast_decryption = 0; |
| 6051 | priv->ieee->host_decrypt = 0; |
| 6052 | break; |
| 6053 | case SEC_LEVEL_2: |
| 6054 | priv->sys_config.disable_unicast_decryption = 1; |
| 6055 | priv->ieee->host_decrypt = 1; |
| 6056 | break; |
| 6057 | case SEC_LEVEL_1: |
| 6058 | priv->sys_config.disable_unicast_decryption = 0; |
| 6059 | priv->ieee->host_decrypt = 0; |
| 6060 | break; |
| 6061 | case SEC_LEVEL_0: |
| 6062 | priv->sys_config.disable_unicast_decryption = 1; |
| 6063 | break; |
| 6064 | default: |
| 6065 | break; |
| 6066 | } |
| 6067 | } |
| 6068 | |
| 6069 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) |
| 6070 | { |
| 6071 | if (priv->ieee->host_encrypt) |
| 6072 | return; |
| 6073 | |
| 6074 | switch (level) { |
| 6075 | case SEC_LEVEL_3: |
| 6076 | priv->sys_config.disable_multicast_decryption = 0; |
| 6077 | break; |
| 6078 | case SEC_LEVEL_2: |
| 6079 | priv->sys_config.disable_multicast_decryption = 1; |
| 6080 | break; |
| 6081 | case SEC_LEVEL_1: |
| 6082 | priv->sys_config.disable_multicast_decryption = 0; |
| 6083 | break; |
| 6084 | case SEC_LEVEL_0: |
| 6085 | priv->sys_config.disable_multicast_decryption = 1; |
| 6086 | break; |
| 6087 | default: |
| 6088 | break; |
| 6089 | } |
| 6090 | } |
| 6091 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6092 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
| 6093 | { |
| 6094 | switch (priv->ieee->sec.level) { |
| 6095 | case SEC_LEVEL_3: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 6096 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 6097 | ipw_send_tgi_tx_key(priv, |
| 6098 | DCT_FLAG_EXT_SECURITY_CCM, |
| 6099 | priv->ieee->sec.active_key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6100 | |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6101 | if (!priv->ieee->host_mc_decrypt) |
| 6102 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6103 | break; |
| 6104 | case SEC_LEVEL_2: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 6105 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 6106 | ipw_send_tgi_tx_key(priv, |
| 6107 | DCT_FLAG_EXT_SECURITY_TKIP, |
| 6108 | priv->ieee->sec.active_key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6109 | break; |
| 6110 | case SEC_LEVEL_1: |
| 6111 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Hong Liu | 29cb843 | 2005-09-12 10:43:33 -0500 | [diff] [blame] | 6112 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
| 6113 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6114 | break; |
| 6115 | case SEC_LEVEL_0: |
| 6116 | default: |
| 6117 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6118 | } |
| 6119 | } |
| 6120 | |
| 6121 | static void ipw_adhoc_check(void *data) |
| 6122 | { |
| 6123 | struct ipw_priv *priv = data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6124 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6125 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6126 | !(priv->config & CFG_ADHOC_PERSIST)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6127 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 6128 | IPW_DL_STATE | IPW_DL_ASSOC, |
| 6129 | "Missed beacon: %d - disassociate\n", |
| 6130 | priv->missed_adhoc_beacons); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6131 | ipw_remove_current_network(priv); |
| 6132 | ipw_disassociate(priv); |
| 6133 | return; |
| 6134 | } |
| 6135 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6136 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 6137 | le16_to_cpu(priv->assoc_request.beacon_interval)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6138 | } |
| 6139 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6140 | static void ipw_bg_adhoc_check(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6141 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6142 | struct ipw_priv *priv = |
| 6143 | container_of(work, struct ipw_priv, adhoc_check.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6144 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6145 | ipw_adhoc_check(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6146 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6147 | } |
| 6148 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6149 | static void ipw_debug_config(struct ipw_priv *priv) |
| 6150 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6151 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6152 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
| 6153 | "[CFG 0x%08X]\n", priv->config); |
| 6154 | if (priv->config & CFG_STATIC_CHANNEL) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6155 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6156 | else |
| 6157 | IPW_DEBUG_INFO("Channel unlocked.\n"); |
| 6158 | if (priv->config & CFG_STATIC_ESSID) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6159 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6160 | print_ssid(ssid, priv->essid, priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6161 | else |
| 6162 | IPW_DEBUG_INFO("ESSID unlocked.\n"); |
| 6163 | if (priv->config & CFG_STATIC_BSSID) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6164 | IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6165 | else |
| 6166 | IPW_DEBUG_INFO("BSSID unlocked.\n"); |
| 6167 | if (priv->capability & CAP_PRIVACY_ON) |
| 6168 | IPW_DEBUG_INFO("PRIVACY on\n"); |
| 6169 | else |
| 6170 | IPW_DEBUG_INFO("PRIVACY off\n"); |
| 6171 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); |
| 6172 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6173 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 6174 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6175 | { |
| 6176 | /* TODO: Verify that this works... */ |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6177 | struct ipw_fixed_rate fr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6178 | u32 reg; |
| 6179 | u16 mask = 0; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6180 | u16 new_tx_rates = priv->rates_mask; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6181 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6182 | /* Identify 'current FW band' and match it with the fixed |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6183 | * Tx rates */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6184 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6185 | switch (priv->ieee->freq_band) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6186 | case LIBIPW_52GHZ_BAND: /* A only */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6187 | /* IEEE_A */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6188 | if (priv->rates_mask & ~LIBIPW_OFDM_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 | break; |
| 6194 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6195 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6196 | new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6197 | break; |
| 6198 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6199 | default: /* 2.4Ghz or Mixed */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6200 | /* IEEE_B */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6201 | if (mode == IEEE_B) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6202 | if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6203 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6204 | IPW_DEBUG_WX |
| 6205 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6206 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6207 | } |
| 6208 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6209 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6210 | |
| 6211 | /* IEEE_G */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6212 | if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK | |
| 6213 | LIBIPW_OFDM_RATES_MASK)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6214 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6215 | IPW_DEBUG_WX |
| 6216 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6217 | new_tx_rates = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6218 | break; |
| 6219 | } |
| 6220 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6221 | if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) { |
| 6222 | mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1); |
| 6223 | new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6224 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6225 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6226 | if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) { |
| 6227 | mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1); |
| 6228 | new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6229 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6230 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6231 | if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) { |
| 6232 | mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1); |
| 6233 | new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6234 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6235 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6236 | new_tx_rates |= mask; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6237 | break; |
| 6238 | } |
| 6239 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 6240 | fr.tx_rates = cpu_to_le16(new_tx_rates); |
| 6241 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6242 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6243 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6244 | } |
| 6245 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6246 | static void ipw_abort_scan(struct ipw_priv *priv) |
| 6247 | { |
| 6248 | int err; |
| 6249 | |
| 6250 | if (priv->status & STATUS_SCAN_ABORTING) { |
| 6251 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); |
| 6252 | return; |
| 6253 | } |
| 6254 | priv->status |= STATUS_SCAN_ABORTING; |
| 6255 | |
| 6256 | err = ipw_send_scan_abort(priv); |
| 6257 | if (err) |
| 6258 | IPW_DEBUG_HC("Request to abort scan failed.\n"); |
| 6259 | } |
| 6260 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6261 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
| 6262 | struct ipw_scan_request_ext *scan, |
| 6263 | int scan_type) |
| 6264 | { |
| 6265 | int channel_index = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6266 | const struct libipw_geo *geo; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6267 | int i; |
| 6268 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6269 | geo = libipw_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6270 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6271 | if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6272 | int start = channel_index; |
| 6273 | for (i = 0; i < geo->a_channels; i++) { |
| 6274 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6275 | geo->a[i].channel == priv->channel) |
| 6276 | continue; |
| 6277 | channel_index++; |
| 6278 | scan->channels_list[channel_index] = geo->a[i].channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6279 | ipw_set_scan_type(scan, channel_index, |
| 6280 | geo->a[i]. |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6281 | flags & LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6282 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : |
| 6283 | scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6284 | } |
| 6285 | |
| 6286 | if (start != channel_index) { |
| 6287 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | |
| 6288 | (channel_index - start); |
| 6289 | channel_index++; |
| 6290 | } |
| 6291 | } |
| 6292 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6293 | if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6294 | int start = channel_index; |
| 6295 | if (priv->config & CFG_SPEED_SCAN) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6296 | int index; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6297 | u8 channels[LIBIPW_24GHZ_CHANNELS] = { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6298 | /* nop out the list */ |
| 6299 | [0] = 0 |
| 6300 | }; |
| 6301 | |
| 6302 | u8 channel; |
Zhu Yi | 7dd2459 | 2009-07-27 10:10:20 +0800 | [diff] [blame] | 6303 | while (channel_index < IPW_SCAN_CHANNELS - 1) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6304 | channel = |
| 6305 | priv->speed_scan[priv->speed_scan_pos]; |
| 6306 | if (channel == 0) { |
| 6307 | priv->speed_scan_pos = 0; |
| 6308 | channel = priv->speed_scan[0]; |
| 6309 | } |
| 6310 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6311 | channel == priv->channel) { |
| 6312 | priv->speed_scan_pos++; |
| 6313 | continue; |
| 6314 | } |
| 6315 | |
| 6316 | /* If this channel has already been |
| 6317 | * added in scan, break from loop |
| 6318 | * and this will be the first channel |
| 6319 | * in the next scan. |
| 6320 | */ |
| 6321 | if (channels[channel - 1] != 0) |
| 6322 | break; |
| 6323 | |
| 6324 | channels[channel - 1] = 1; |
| 6325 | priv->speed_scan_pos++; |
| 6326 | channel_index++; |
| 6327 | scan->channels_list[channel_index] = channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6328 | index = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6329 | libipw_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6330 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6331 | geo->bg[index]. |
| 6332 | flags & |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6333 | LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6334 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6335 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6336 | } |
| 6337 | } else { |
| 6338 | for (i = 0; i < geo->bg_channels; i++) { |
| 6339 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6340 | geo->bg[i].channel == priv->channel) |
| 6341 | continue; |
| 6342 | channel_index++; |
| 6343 | scan->channels_list[channel_index] = |
| 6344 | geo->bg[i].channel; |
| 6345 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6346 | geo->bg[i]. |
| 6347 | flags & |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6348 | LIBIPW_CH_PASSIVE_ONLY ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6349 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6350 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6351 | } |
| 6352 | } |
| 6353 | |
| 6354 | if (start != channel_index) { |
| 6355 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | |
| 6356 | (channel_index - start); |
| 6357 | } |
| 6358 | } |
| 6359 | } |
| 6360 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6361 | static int ipw_passive_dwell_time(struct ipw_priv *priv) |
| 6362 | { |
| 6363 | /* staying on passive channels longer than the DTIM interval during a |
| 6364 | * scan, while associated, causes the firmware to cancel the scan |
| 6365 | * without notification. Hence, don't stay on passive channels longer |
| 6366 | * than the beacon interval. |
| 6367 | */ |
| 6368 | if (priv->status & STATUS_ASSOCIATED |
| 6369 | && priv->assoc_network->beacon_interval > 10) |
| 6370 | return priv->assoc_network->beacon_interval - 10; |
| 6371 | else |
| 6372 | return 120; |
| 6373 | } |
| 6374 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6375 | 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] | 6376 | { |
| 6377 | struct ipw_scan_request_ext scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6378 | int err = 0, scan_type; |
| 6379 | |
| 6380 | if (!(priv->status & STATUS_INIT) || |
| 6381 | (priv->status & STATUS_EXIT_PENDING)) |
| 6382 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6383 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6384 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6385 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6386 | if (direct && (priv->direct_scan_ssid_len == 0)) { |
| 6387 | IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n"); |
| 6388 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; |
| 6389 | goto done; |
| 6390 | } |
| 6391 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6392 | if (priv->status & STATUS_SCANNING) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6393 | IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n"); |
| 6394 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6395 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6396 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6397 | } |
| 6398 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6399 | if (!(priv->status & STATUS_SCAN_FORCED) && |
| 6400 | priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6401 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6402 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6403 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6404 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6405 | } |
| 6406 | |
| 6407 | if (priv->status & STATUS_RF_KILL_MASK) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6408 | IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n"); |
| 6409 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
| 6410 | STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6411 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6412 | } |
| 6413 | |
| 6414 | memset(&scan, 0, sizeof(scan)); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6415 | scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee)); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6416 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6417 | if (type == IW_SCAN_TYPE_PASSIVE) { |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6418 | IPW_DEBUG_WX("use passive scanning\n"); |
| 6419 | scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN; |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6420 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6421 | cpu_to_le16(ipw_passive_dwell_time(priv)); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6422 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 6423 | goto send_request; |
| 6424 | } |
| 6425 | |
| 6426 | /* Use active scan by default. */ |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6427 | if (priv->config & CFG_SPEED_SCAN) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6428 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6429 | cpu_to_le16(30); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6430 | else |
| 6431 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6432 | cpu_to_le16(20); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6433 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6434 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6435 | cpu_to_le16(20); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6436 | |
Helmut Schaa | 14a4dfe | 2008-12-10 13:17:26 +0100 | [diff] [blame] | 6437 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
| 6438 | cpu_to_le16(ipw_passive_dwell_time(priv)); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6439 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6440 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6441 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6442 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6443 | u8 channel; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6444 | u8 band = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6445 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6446 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 6447 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6448 | band = (u8) (IPW_A_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6449 | channel = priv->channel; |
| 6450 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6451 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6452 | case LIBIPW_24GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6453 | band = (u8) (IPW_B_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6454 | channel = priv->channel; |
| 6455 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6456 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6457 | default: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6458 | band = (u8) (IPW_B_MODE << 6) | 1; |
| 6459 | channel = 9; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6460 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6461 | } |
| 6462 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6463 | scan.channels_list[0] = band; |
| 6464 | scan.channels_list[1] = channel; |
| 6465 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6466 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6467 | /* NOTE: The card will sit on this channel for this time |
| 6468 | * period. Scan aborts are timing sensitive and frequently |
| 6469 | * result in firmware restarts. As such, it is best to |
| 6470 | * set a small dwell_time here and just keep re-issuing |
| 6471 | * scans. Otherwise fast channel hopping will not actually |
| 6472 | * hop channels. |
| 6473 | * |
| 6474 | * TODO: Move SPEED SCAN support to all modes and bands */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6475 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6476 | cpu_to_le16(2000); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6477 | } else { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6478 | #endif /* CONFIG_IPW2200_MONITOR */ |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6479 | /* Honor direct scans first, otherwise if we are roaming make |
| 6480 | * this a direct scan for the current network. Finally, |
| 6481 | * ensure that every other scan is a fast channel hop scan */ |
| 6482 | if (direct) { |
| 6483 | err = ipw_send_ssid(priv, priv->direct_scan_ssid, |
| 6484 | priv->direct_scan_ssid_len); |
| 6485 | if (err) { |
| 6486 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6487 | "failed\n"); |
| 6488 | goto done; |
| 6489 | } |
| 6490 | |
| 6491 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
| 6492 | } else if ((priv->status & STATUS_ROAMING) |
| 6493 | || (!(priv->status & STATUS_ASSOCIATED) |
| 6494 | && (priv->config & CFG_STATIC_ESSID) |
| 6495 | && (le32_to_cpu(scan.full_scan_index) % 2))) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6496 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 6497 | if (err) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6498 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6499 | "failed.\n"); |
| 6500 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6501 | } |
| 6502 | |
| 6503 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6504 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6505 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6506 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6507 | ipw_add_scan_channels(priv, &scan, scan_type); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6508 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6509 | } |
| 6510 | #endif |
| 6511 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6512 | send_request: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6513 | err = ipw_send_scan_request_ext(priv, &scan); |
| 6514 | if (err) { |
| 6515 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6516 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6517 | } |
| 6518 | |
| 6519 | priv->status |= STATUS_SCANNING; |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6520 | if (direct) { |
| 6521 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; |
| 6522 | priv->direct_scan_ssid_len = 0; |
| 6523 | } else |
| 6524 | priv->status &= ~STATUS_SCAN_PENDING; |
| 6525 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6526 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6527 | IPW_SCAN_CHECK_WATCHDOG); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 6528 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6529 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6530 | return err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6531 | } |
| 6532 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6533 | static void ipw_request_passive_scan(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6534 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6535 | struct ipw_priv *priv = |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6536 | container_of(work, struct ipw_priv, request_passive_scan.work); |
| 6537 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | static void ipw_request_scan(struct work_struct *work) |
| 6541 | { |
| 6542 | struct ipw_priv *priv = |
| 6543 | container_of(work, struct ipw_priv, request_scan.work); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 6544 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0); |
| 6545 | } |
| 6546 | |
| 6547 | static void ipw_request_direct_scan(struct work_struct *work) |
| 6548 | { |
| 6549 | struct ipw_priv *priv = |
| 6550 | container_of(work, struct ipw_priv, request_direct_scan.work); |
| 6551 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6552 | } |
| 6553 | |
| 6554 | static void ipw_bg_abort_scan(struct work_struct *work) |
| 6555 | { |
| 6556 | struct ipw_priv *priv = |
| 6557 | container_of(work, struct ipw_priv, abort_scan); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6558 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6559 | ipw_abort_scan(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6560 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6561 | } |
| 6562 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6563 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
| 6564 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6565 | /* This is called when wpa_supplicant loads and closes the driver |
| 6566 | * interface. */ |
Hong Liu | cdd1fa1 | 2005-08-31 18:14:27 +0800 | [diff] [blame] | 6567 | priv->ieee->wpa_enabled = value; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6568 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6569 | } |
| 6570 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6571 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
| 6572 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6573 | struct libipw_device *ieee = priv->ieee; |
| 6574 | struct libipw_security sec = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6575 | .flags = SEC_AUTH_MODE, |
| 6576 | }; |
| 6577 | int ret = 0; |
| 6578 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6579 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6580 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
| 6581 | ieee->open_wep = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6582 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6583 | sec.auth_mode = WLAN_AUTH_OPEN; |
| 6584 | ieee->open_wep = 1; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 6585 | } else if (value & IW_AUTH_ALG_LEAP) { |
| 6586 | sec.auth_mode = WLAN_AUTH_LEAP; |
| 6587 | ieee->open_wep = 1; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6588 | } else |
| 6589 | return -EINVAL; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6590 | |
| 6591 | if (ieee->set_security) |
| 6592 | ieee->set_security(ieee->dev, &sec); |
| 6593 | else |
| 6594 | ret = -EOPNOTSUPP; |
| 6595 | |
| 6596 | return ret; |
| 6597 | } |
| 6598 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 6599 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
| 6600 | int wpa_ie_len) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6601 | { |
| 6602 | /* make sure WPA is enabled */ |
| 6603 | ipw_wpa_enable(priv, 1); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | static int ipw_set_rsn_capa(struct ipw_priv *priv, |
| 6607 | char *capabilities, int length) |
| 6608 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6609 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
| 6610 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6611 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 6612 | capabilities); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6613 | } |
| 6614 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6615 | /* |
| 6616 | * WE-18 support |
| 6617 | */ |
| 6618 | |
| 6619 | /* SIOCSIWGENIE */ |
| 6620 | static int ipw_wx_set_genie(struct net_device *dev, |
| 6621 | struct iw_request_info *info, |
| 6622 | union iwreq_data *wrqu, char *extra) |
| 6623 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6624 | struct ipw_priv *priv = libipw_priv(dev); |
| 6625 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6626 | u8 *buf; |
| 6627 | int err = 0; |
| 6628 | |
| 6629 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
| 6630 | (wrqu->data.length && extra == NULL)) |
| 6631 | return -EINVAL; |
| 6632 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6633 | if (wrqu->data.length) { |
Julia Lawall | d3e5033 | 2010-05-15 23:21:01 +0200 | [diff] [blame] | 6634 | buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6635 | if (buf == NULL) { |
| 6636 | err = -ENOMEM; |
| 6637 | goto out; |
| 6638 | } |
| 6639 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6640 | kfree(ieee->wpa_ie); |
| 6641 | ieee->wpa_ie = buf; |
| 6642 | ieee->wpa_ie_len = wrqu->data.length; |
| 6643 | } else { |
| 6644 | kfree(ieee->wpa_ie); |
| 6645 | ieee->wpa_ie = NULL; |
| 6646 | ieee->wpa_ie_len = 0; |
| 6647 | } |
| 6648 | |
| 6649 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6650 | out: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6651 | return err; |
| 6652 | } |
| 6653 | |
| 6654 | /* SIOCGIWGENIE */ |
| 6655 | static int ipw_wx_get_genie(struct net_device *dev, |
| 6656 | struct iw_request_info *info, |
| 6657 | union iwreq_data *wrqu, char *extra) |
| 6658 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6659 | struct ipw_priv *priv = libipw_priv(dev); |
| 6660 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6661 | int err = 0; |
| 6662 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6663 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
| 6664 | wrqu->data.length = 0; |
| 6665 | goto out; |
| 6666 | } |
| 6667 | |
| 6668 | if (wrqu->data.length < ieee->wpa_ie_len) { |
| 6669 | err = -E2BIG; |
| 6670 | goto out; |
| 6671 | } |
| 6672 | |
| 6673 | wrqu->data.length = ieee->wpa_ie_len; |
| 6674 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6675 | |
| 6676 | out: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6677 | return err; |
| 6678 | } |
| 6679 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6680 | static int wext_cipher2level(int cipher) |
| 6681 | { |
| 6682 | switch (cipher) { |
| 6683 | case IW_AUTH_CIPHER_NONE: |
| 6684 | return SEC_LEVEL_0; |
| 6685 | case IW_AUTH_CIPHER_WEP40: |
| 6686 | case IW_AUTH_CIPHER_WEP104: |
| 6687 | return SEC_LEVEL_1; |
| 6688 | case IW_AUTH_CIPHER_TKIP: |
| 6689 | return SEC_LEVEL_2; |
| 6690 | case IW_AUTH_CIPHER_CCMP: |
| 6691 | return SEC_LEVEL_3; |
| 6692 | default: |
| 6693 | return -1; |
| 6694 | } |
| 6695 | } |
| 6696 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6697 | /* SIOCSIWAUTH */ |
| 6698 | static int ipw_wx_set_auth(struct net_device *dev, |
| 6699 | struct iw_request_info *info, |
| 6700 | union iwreq_data *wrqu, char *extra) |
| 6701 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6702 | struct ipw_priv *priv = libipw_priv(dev); |
| 6703 | struct libipw_device *ieee = priv->ieee; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6704 | struct iw_param *param = &wrqu->param; |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6705 | struct lib80211_crypt_data *crypt; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6706 | unsigned long flags; |
| 6707 | int ret = 0; |
| 6708 | |
| 6709 | switch (param->flags & IW_AUTH_INDEX) { |
| 6710 | case IW_AUTH_WPA_VERSION: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6711 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6712 | case IW_AUTH_CIPHER_PAIRWISE: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6713 | ipw_set_hw_decrypt_unicast(priv, |
| 6714 | wext_cipher2level(param->value)); |
| 6715 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6716 | case IW_AUTH_CIPHER_GROUP: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6717 | ipw_set_hw_decrypt_multicast(priv, |
| 6718 | wext_cipher2level(param->value)); |
| 6719 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6720 | case IW_AUTH_KEY_MGMT: |
| 6721 | /* |
| 6722 | * ipw2200 does not use these parameters |
| 6723 | */ |
| 6724 | break; |
| 6725 | |
| 6726 | case IW_AUTH_TKIP_COUNTERMEASURES: |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6727 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6728 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6729 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6730 | |
| 6731 | flags = crypt->ops->get_flags(crypt->priv); |
| 6732 | |
| 6733 | if (param->value) |
| 6734 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6735 | else |
| 6736 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6737 | |
| 6738 | crypt->ops->set_flags(flags, crypt->priv); |
| 6739 | |
| 6740 | break; |
| 6741 | |
| 6742 | case IW_AUTH_DROP_UNENCRYPTED:{ |
| 6743 | /* HACK: |
| 6744 | * |
| 6745 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6746 | * is loaded and unloaded, regardless of if WPA is being |
| 6747 | * used. No other calls are made which can be used to |
| 6748 | * determine if encryption will be used or not prior to |
| 6749 | * association being expected. If encryption is not being |
| 6750 | * used, drop_unencrypted is set to false, else true -- we |
| 6751 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6752 | * be set. |
| 6753 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6754 | struct libipw_security sec = { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6755 | .flags = SEC_ENABLED, |
| 6756 | .enabled = param->value, |
| 6757 | }; |
| 6758 | priv->ieee->drop_unencrypted = param->value; |
| 6759 | /* We only change SEC_LEVEL for open mode. Others |
| 6760 | * are set by ipw_wpa_set_encryption. |
| 6761 | */ |
| 6762 | if (!param->value) { |
| 6763 | sec.flags |= SEC_LEVEL; |
| 6764 | sec.level = SEC_LEVEL_0; |
| 6765 | } else { |
| 6766 | sec.flags |= SEC_LEVEL; |
| 6767 | sec.level = SEC_LEVEL_1; |
| 6768 | } |
| 6769 | if (priv->ieee->set_security) |
| 6770 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6771 | break; |
| 6772 | } |
| 6773 | |
| 6774 | case IW_AUTH_80211_AUTH_ALG: |
| 6775 | ret = ipw_wpa_set_auth_algs(priv, param->value); |
| 6776 | break; |
| 6777 | |
| 6778 | case IW_AUTH_WPA_ENABLED: |
| 6779 | ret = ipw_wpa_enable(priv, param->value); |
Zhu Yi | e3c5a64 | 2006-04-13 17:21:13 +0800 | [diff] [blame] | 6780 | ipw_disassociate(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6781 | break; |
| 6782 | |
| 6783 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6784 | ieee->ieee802_1x = param->value; |
| 6785 | break; |
| 6786 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6787 | case IW_AUTH_PRIVACY_INVOKED: |
| 6788 | ieee->privacy_invoked = param->value; |
| 6789 | break; |
| 6790 | |
| 6791 | default: |
| 6792 | return -EOPNOTSUPP; |
| 6793 | } |
| 6794 | return ret; |
| 6795 | } |
| 6796 | |
| 6797 | /* SIOCGIWAUTH */ |
| 6798 | static int ipw_wx_get_auth(struct net_device *dev, |
| 6799 | struct iw_request_info *info, |
| 6800 | union iwreq_data *wrqu, char *extra) |
| 6801 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6802 | struct ipw_priv *priv = libipw_priv(dev); |
| 6803 | struct libipw_device *ieee = priv->ieee; |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6804 | struct lib80211_crypt_data *crypt; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6805 | struct iw_param *param = &wrqu->param; |
| 6806 | int ret = 0; |
| 6807 | |
| 6808 | switch (param->flags & IW_AUTH_INDEX) { |
| 6809 | case IW_AUTH_WPA_VERSION: |
| 6810 | case IW_AUTH_CIPHER_PAIRWISE: |
| 6811 | case IW_AUTH_CIPHER_GROUP: |
| 6812 | case IW_AUTH_KEY_MGMT: |
| 6813 | /* |
| 6814 | * wpa_supplicant will control these internally |
| 6815 | */ |
| 6816 | ret = -EOPNOTSUPP; |
| 6817 | break; |
| 6818 | |
| 6819 | case IW_AUTH_TKIP_COUNTERMEASURES: |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 6820 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6821 | if (!crypt || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6822 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6823 | |
| 6824 | param->value = (crypt->ops->get_flags(crypt->priv) & |
| 6825 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; |
| 6826 | |
| 6827 | break; |
| 6828 | |
| 6829 | case IW_AUTH_DROP_UNENCRYPTED: |
| 6830 | param->value = ieee->drop_unencrypted; |
| 6831 | break; |
| 6832 | |
| 6833 | case IW_AUTH_80211_AUTH_ALG: |
| 6834 | param->value = ieee->sec.auth_mode; |
| 6835 | break; |
| 6836 | |
| 6837 | case IW_AUTH_WPA_ENABLED: |
| 6838 | param->value = ieee->wpa_enabled; |
| 6839 | break; |
| 6840 | |
| 6841 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6842 | param->value = ieee->ieee802_1x; |
| 6843 | break; |
| 6844 | |
| 6845 | case IW_AUTH_ROAMING_CONTROL: |
| 6846 | case IW_AUTH_PRIVACY_INVOKED: |
| 6847 | param->value = ieee->privacy_invoked; |
| 6848 | break; |
| 6849 | |
| 6850 | default: |
| 6851 | return -EOPNOTSUPP; |
| 6852 | } |
| 6853 | return 0; |
| 6854 | } |
| 6855 | |
| 6856 | /* SIOCSIWENCODEEXT */ |
| 6857 | static int ipw_wx_set_encodeext(struct net_device *dev, |
| 6858 | struct iw_request_info *info, |
| 6859 | union iwreq_data *wrqu, char *extra) |
| 6860 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6861 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6862 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 6863 | |
| 6864 | if (hwcrypto) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6865 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6866 | /* IPW HW can't build TKIP MIC, |
| 6867 | host decryption still needed */ |
| 6868 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) |
| 6869 | priv->ieee->host_mc_decrypt = 1; |
| 6870 | else { |
| 6871 | priv->ieee->host_encrypt = 0; |
| 6872 | priv->ieee->host_encrypt_msdu = 1; |
| 6873 | priv->ieee->host_decrypt = 1; |
| 6874 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6875 | } else { |
| 6876 | priv->ieee->host_encrypt = 0; |
| 6877 | priv->ieee->host_encrypt_msdu = 0; |
| 6878 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6879 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6880 | } |
| 6881 | } |
| 6882 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6883 | return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6884 | } |
| 6885 | |
| 6886 | /* SIOCGIWENCODEEXT */ |
| 6887 | static int ipw_wx_get_encodeext(struct net_device *dev, |
| 6888 | struct iw_request_info *info, |
| 6889 | union iwreq_data *wrqu, char *extra) |
| 6890 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6891 | struct ipw_priv *priv = libipw_priv(dev); |
| 6892 | return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6893 | } |
| 6894 | |
| 6895 | /* SIOCSIWMLME */ |
| 6896 | static int ipw_wx_set_mlme(struct net_device *dev, |
| 6897 | struct iw_request_info *info, |
| 6898 | union iwreq_data *wrqu, char *extra) |
| 6899 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6900 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6901 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 6902 | __le16 reason; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6903 | |
| 6904 | reason = cpu_to_le16(mlme->reason_code); |
| 6905 | |
| 6906 | switch (mlme->cmd) { |
| 6907 | case IW_MLME_DEAUTH: |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 6908 | /* silently ignore */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6909 | break; |
| 6910 | |
| 6911 | case IW_MLME_DISASSOC: |
| 6912 | ipw_disassociate(priv); |
| 6913 | break; |
| 6914 | |
| 6915 | default: |
| 6916 | return -EOPNOTSUPP; |
| 6917 | } |
| 6918 | return 0; |
| 6919 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6920 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 6921 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6922 | |
| 6923 | /* QoS */ |
| 6924 | /* |
| 6925 | * get the modulation type of the current network or |
| 6926 | * the card current mode |
| 6927 | */ |
Adrian Bunk | 53d0bcf | 2006-03-04 13:14:31 +0100 | [diff] [blame] | 6928 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6929 | { |
| 6930 | u8 mode = 0; |
| 6931 | |
| 6932 | if (priv->status & STATUS_ASSOCIATED) { |
| 6933 | unsigned long flags; |
| 6934 | |
| 6935 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6936 | mode = priv->assoc_network->mode; |
| 6937 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6938 | } else { |
| 6939 | mode = priv->ieee->mode; |
| 6940 | } |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 6941 | IPW_DEBUG_QOS("QoS network/card mode %d\n", mode); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6942 | return mode; |
| 6943 | } |
| 6944 | |
| 6945 | /* |
| 6946 | * Handle management frame beacon and probe response |
| 6947 | */ |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6948 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
| 6949 | int active_network, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6950 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6951 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 6952 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6953 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6954 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6955 | network->qos_data.active = network->qos_data.supported; |
| 6956 | |
| 6957 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6958 | if (active_network && |
| 6959 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6960 | network->qos_data.active = network->qos_data.supported; |
| 6961 | |
| 6962 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 6963 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 6964 | (network->qos_data.old_param_count != |
| 6965 | network->qos_data.param_count)) { |
| 6966 | network->qos_data.old_param_count = |
| 6967 | network->qos_data.param_count; |
| 6968 | schedule_work(&priv->qos_activate); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6969 | IPW_DEBUG_QOS("QoS parameters change call " |
| 6970 | "qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6971 | } |
| 6972 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6973 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
| 6974 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6975 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6976 | else |
| 6977 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6978 | &def_parameters_OFDM, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6979 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6980 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 6981 | IPW_DEBUG_QOS("QoS was disabled call qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6982 | schedule_work(&priv->qos_activate); |
| 6983 | } |
| 6984 | |
| 6985 | network->qos_data.active = 0; |
| 6986 | network->qos_data.supported = 0; |
| 6987 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6988 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6989 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { |
| 6990 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) |
John W. Linville | c5d3dce | 2008-09-30 17:17:26 -0400 | [diff] [blame] | 6991 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6992 | if ((network->ssid_len == |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6993 | priv->assoc_network->ssid_len) && |
| 6994 | !memcmp(network->ssid, |
| 6995 | priv->assoc_network->ssid, |
| 6996 | network->ssid_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6997 | queue_work(priv->workqueue, |
| 6998 | &priv->merge_networks); |
| 6999 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7000 | } |
| 7001 | |
| 7002 | return 0; |
| 7003 | } |
| 7004 | |
| 7005 | /* |
| 7006 | * This function set up the firmware to support QoS. It sends |
| 7007 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO |
| 7008 | */ |
| 7009 | static int ipw_qos_activate(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7010 | struct libipw_qos_data *qos_network_data) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7011 | { |
| 7012 | int err; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7013 | struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS]; |
| 7014 | struct libipw_qos_parameters *active_one = NULL; |
| 7015 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7016 | u32 burst_duration; |
| 7017 | int i; |
| 7018 | u8 type; |
| 7019 | |
| 7020 | type = ipw_qos_current_mode(priv); |
| 7021 | |
| 7022 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); |
| 7023 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); |
| 7024 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); |
| 7025 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); |
| 7026 | |
| 7027 | if (qos_network_data == NULL) { |
| 7028 | if (type == IEEE_B) { |
| 7029 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); |
| 7030 | active_one = &def_parameters_CCK; |
| 7031 | } else |
| 7032 | active_one = &def_parameters_OFDM; |
| 7033 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7034 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7035 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 7036 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7037 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 7038 | cpu_to_le16(burst_duration); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7039 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7040 | if (type == IEEE_B) { |
| 7041 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", |
| 7042 | type); |
| 7043 | if (priv->qos_data.qos_enable == 0) |
| 7044 | active_one = &def_parameters_CCK; |
| 7045 | else |
| 7046 | active_one = priv->qos_data.def_qos_parm_CCK; |
| 7047 | } else { |
| 7048 | if (priv->qos_data.qos_enable == 0) |
| 7049 | active_one = &def_parameters_OFDM; |
| 7050 | else |
| 7051 | active_one = priv->qos_data.def_qos_parm_OFDM; |
| 7052 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7053 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7054 | } else { |
| 7055 | unsigned long flags; |
| 7056 | int active; |
| 7057 | |
| 7058 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7059 | active_one = &(qos_network_data->parameters); |
| 7060 | qos_network_data->old_param_count = |
| 7061 | qos_network_data->param_count; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7062 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7063 | active = qos_network_data->supported; |
| 7064 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7065 | |
| 7066 | if (active == 0) { |
| 7067 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 7068 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
| 7069 | qos_parameters[QOS_PARAM_SET_ACTIVE]. |
Al Viro | 8fffc15 | 2007-12-27 01:25:40 -0500 | [diff] [blame] | 7070 | tx_op_limit[i] = cpu_to_le16(burst_duration); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7071 | } |
| 7072 | } |
| 7073 | |
| 7074 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7075 | err = ipw_send_qos_params_command(priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7076 | (struct libipw_qos_parameters *) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7077 | &(qos_parameters[0])); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7078 | if (err) |
| 7079 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); |
| 7080 | |
| 7081 | return err; |
| 7082 | } |
| 7083 | |
| 7084 | /* |
| 7085 | * send IPW_CMD_WME_INFO to the firmware |
| 7086 | */ |
| 7087 | static int ipw_qos_set_info_element(struct ipw_priv *priv) |
| 7088 | { |
| 7089 | int ret = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7090 | struct libipw_qos_information_element qos_info; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7091 | |
| 7092 | if (priv == NULL) |
| 7093 | return -1; |
| 7094 | |
| 7095 | qos_info.elementID = QOS_ELEMENT_ID; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7096 | qos_info.length = sizeof(struct libipw_qos_information_element) - 2; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7097 | |
| 7098 | qos_info.version = QOS_VERSION_1; |
| 7099 | qos_info.ac_info = 0; |
| 7100 | |
| 7101 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); |
| 7102 | qos_info.qui_type = QOS_OUI_TYPE; |
| 7103 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; |
| 7104 | |
| 7105 | ret = ipw_send_qos_info_command(priv, &qos_info); |
| 7106 | if (ret != 0) { |
| 7107 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); |
| 7108 | } |
| 7109 | return ret; |
| 7110 | } |
| 7111 | |
| 7112 | /* |
| 7113 | * Set the QoS parameter with the association request structure |
| 7114 | */ |
| 7115 | static int ipw_qos_association(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7116 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7117 | { |
| 7118 | int err = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7119 | struct libipw_qos_data *qos_data = NULL; |
| 7120 | struct libipw_qos_data ibss_data = { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7121 | .supported = 1, |
| 7122 | .active = 1, |
| 7123 | }; |
| 7124 | |
| 7125 | switch (priv->ieee->iw_mode) { |
| 7126 | case IW_MODE_ADHOC: |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 7127 | BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7128 | |
| 7129 | qos_data = &ibss_data; |
| 7130 | break; |
| 7131 | |
| 7132 | case IW_MODE_INFRA: |
| 7133 | qos_data = &network->qos_data; |
| 7134 | break; |
| 7135 | |
| 7136 | default: |
| 7137 | BUG(); |
| 7138 | break; |
| 7139 | } |
| 7140 | |
| 7141 | err = ipw_qos_activate(priv, qos_data); |
| 7142 | if (err) { |
| 7143 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; |
| 7144 | return err; |
| 7145 | } |
| 7146 | |
| 7147 | if (priv->qos_data.qos_enable && qos_data->supported) { |
| 7148 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); |
| 7149 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; |
| 7150 | return ipw_qos_set_info_element(priv); |
| 7151 | } |
| 7152 | |
| 7153 | return 0; |
| 7154 | } |
| 7155 | |
| 7156 | /* |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 7157 | * handling the beaconing responses. if we get different QoS setting |
| 7158 | * off the network from the associated setting, adjust the QoS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7159 | * setting |
| 7160 | */ |
| 7161 | static int ipw_qos_association_resp(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7162 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7163 | { |
| 7164 | int ret = 0; |
| 7165 | unsigned long flags; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7166 | u32 size = sizeof(struct libipw_qos_parameters); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7167 | int set_qos_param = 0; |
| 7168 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7169 | if ((priv == NULL) || (network == NULL) || |
| 7170 | (priv->assoc_network == NULL)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7171 | return ret; |
| 7172 | |
| 7173 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7174 | return ret; |
| 7175 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7176 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7177 | return ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7178 | |
| 7179 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7180 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7181 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7182 | sizeof(struct libipw_qos_data)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7183 | priv->assoc_network->qos_data.active = 1; |
| 7184 | if ((network->qos_data.old_param_count != |
| 7185 | network->qos_data.param_count)) { |
| 7186 | set_qos_param = 1; |
| 7187 | network->qos_data.old_param_count = |
| 7188 | network->qos_data.param_count; |
| 7189 | } |
| 7190 | |
| 7191 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7192 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
| 7193 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7194 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7195 | else |
| 7196 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7197 | &def_parameters_OFDM, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7198 | priv->assoc_network->qos_data.active = 0; |
| 7199 | priv->assoc_network->qos_data.supported = 0; |
| 7200 | set_qos_param = 1; |
| 7201 | } |
| 7202 | |
| 7203 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7204 | |
| 7205 | if (set_qos_param == 1) |
| 7206 | schedule_work(&priv->qos_activate); |
| 7207 | |
| 7208 | return ret; |
| 7209 | } |
| 7210 | |
| 7211 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) |
| 7212 | { |
| 7213 | u32 ret = 0; |
| 7214 | |
| 7215 | if ((priv == NULL)) |
| 7216 | return 0; |
| 7217 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7218 | if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7219 | ret = priv->qos_data.burst_duration_CCK; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7220 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7221 | ret = priv->qos_data.burst_duration_OFDM; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7222 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7223 | return ret; |
| 7224 | } |
| 7225 | |
| 7226 | /* |
| 7227 | * Initialize the setting of QoS global |
| 7228 | */ |
| 7229 | static void ipw_qos_init(struct ipw_priv *priv, int enable, |
| 7230 | int burst_enable, u32 burst_duration_CCK, |
| 7231 | u32 burst_duration_OFDM) |
| 7232 | { |
| 7233 | priv->qos_data.qos_enable = enable; |
| 7234 | |
| 7235 | if (priv->qos_data.qos_enable) { |
| 7236 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; |
| 7237 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; |
| 7238 | IPW_DEBUG_QOS("QoS is enabled\n"); |
| 7239 | } else { |
| 7240 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; |
| 7241 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; |
| 7242 | IPW_DEBUG_QOS("QoS is not enabled\n"); |
| 7243 | } |
| 7244 | |
| 7245 | priv->qos_data.burst_enable = burst_enable; |
| 7246 | |
| 7247 | if (burst_enable) { |
| 7248 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; |
| 7249 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; |
| 7250 | } else { |
| 7251 | priv->qos_data.burst_duration_CCK = 0; |
| 7252 | priv->qos_data.burst_duration_OFDM = 0; |
| 7253 | } |
| 7254 | } |
| 7255 | |
| 7256 | /* |
| 7257 | * map the packet priority to the right TX Queue |
| 7258 | */ |
| 7259 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) |
| 7260 | { |
| 7261 | if (priority > 7 || !priv->qos_data.qos_enable) |
| 7262 | priority = 0; |
| 7263 | |
| 7264 | return from_priority_to_tx_queue[priority] - 1; |
| 7265 | } |
| 7266 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7267 | static int ipw_is_qos_active(struct net_device *dev, |
| 7268 | struct sk_buff *skb) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7269 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7270 | struct ipw_priv *priv = libipw_priv(dev); |
| 7271 | struct libipw_qos_data *qos_data = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7272 | int active, supported; |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7273 | u8 *daddr = skb->data + ETH_ALEN; |
| 7274 | int unicast = !is_multicast_ether_addr(daddr); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7275 | |
| 7276 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7277 | return 0; |
| 7278 | |
| 7279 | qos_data = &priv->assoc_network->qos_data; |
| 7280 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7281 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7282 | if (unicast == 0) |
| 7283 | qos_data->active = 0; |
| 7284 | else |
| 7285 | qos_data->active = qos_data->supported; |
| 7286 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7287 | active = qos_data->active; |
| 7288 | supported = qos_data->supported; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7289 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
| 7290 | "unicast %d\n", |
| 7291 | priv->qos_data.qos_enable, active, supported, unicast); |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7292 | if (active && priv->qos_data.qos_enable) |
| 7293 | return 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7294 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7295 | return 0; |
| 7296 | |
| 7297 | } |
| 7298 | /* |
| 7299 | * add QoS parameter to the TX command |
| 7300 | */ |
| 7301 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, |
| 7302 | u16 priority, |
| 7303 | struct tfd_data *tfd) |
| 7304 | { |
| 7305 | int tx_queue_id = 0; |
| 7306 | |
| 7307 | |
| 7308 | tx_queue_id = from_priority_to_tx_queue[priority] - 1; |
| 7309 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; |
| 7310 | |
| 7311 | if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) { |
| 7312 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 7313 | 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] | 7314 | } |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 7315 | return 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7316 | } |
| 7317 | |
| 7318 | /* |
| 7319 | * background support to run QoS activate functionality |
| 7320 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7321 | static void ipw_bg_qos_activate(struct work_struct *work) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7322 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7323 | struct ipw_priv *priv = |
| 7324 | container_of(work, struct ipw_priv, qos_activate); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7325 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7326 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7327 | |
| 7328 | if (priv->status & STATUS_ASSOCIATED) |
| 7329 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); |
| 7330 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7331 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7332 | } |
| 7333 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7334 | static int ipw_handle_probe_response(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7335 | struct libipw_probe_response *resp, |
| 7336 | struct libipw_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -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)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7341 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7342 | ipw_qos_handle_probe_response(priv, active_network, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7343 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7344 | return 0; |
| 7345 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7346 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7347 | static int ipw_handle_beacon(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7348 | struct libipw_beacon *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 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7353 | (network == priv->assoc_network)); |
| 7354 | |
| 7355 | ipw_qos_handle_probe_response(priv, active_network, network); |
| 7356 | |
| 7357 | return 0; |
| 7358 | } |
| 7359 | |
| 7360 | static int ipw_handle_assoc_response(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7361 | struct libipw_assoc_response *resp, |
| 7362 | struct libipw_network *network) |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7363 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7364 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7365 | ipw_qos_association_resp(priv, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7366 | return 0; |
| 7367 | } |
| 7368 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7369 | 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] | 7370 | *qos_param) |
| 7371 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7372 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
| 7373 | sizeof(*qos_param) * 3, qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7374 | } |
| 7375 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7376 | 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] | 7377 | *qos_param) |
| 7378 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7379 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
| 7380 | qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7381 | } |
| 7382 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7383 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7384 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7385 | static int ipw_associate_network(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7386 | struct libipw_network *network, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7387 | struct ipw_supported_rates *rates, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7388 | { |
| 7389 | int err; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7390 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7391 | |
| 7392 | if (priv->config & CFG_FIXED_RATE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7393 | ipw_set_fixed_rate(priv, network->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7394 | |
| 7395 | if (!(priv->config & CFG_STATIC_ESSID)) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7396 | priv->essid_len = min(network->ssid_len, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7397 | (u8) IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7398 | memcpy(priv->essid, network->ssid, priv->essid_len); |
| 7399 | } |
| 7400 | |
| 7401 | network->last_associate = jiffies; |
| 7402 | |
| 7403 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); |
| 7404 | priv->assoc_request.channel = network->channel; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7405 | priv->assoc_request.auth_key = 0; |
| 7406 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7407 | if ((priv->capability & CAP_PRIVACY_ON) && |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7408 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7409 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7410 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
| 7411 | |
Zhu Yi | 1ba61e0 | 2006-02-15 13:00:55 +0800 | [diff] [blame] | 7412 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7413 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7414 | |
| 7415 | } else if ((priv->capability & CAP_PRIVACY_ON) && |
| 7416 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) |
| 7417 | priv->assoc_request.auth_type = AUTH_LEAP; |
| 7418 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7419 | priv->assoc_request.auth_type = AUTH_OPEN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7420 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7421 | if (priv->ieee->wpa_ie_len) { |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7422 | priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7423 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
| 7424 | priv->ieee->wpa_ie_len); |
| 7425 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7426 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7427 | /* |
| 7428 | * It is valid for our ieee device to support multiple modes, but |
| 7429 | * 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] | 7430 | * just one mode. |
| 7431 | */ |
| 7432 | if (network->mode & priv->ieee->mode & IEEE_A) |
| 7433 | priv->assoc_request.ieee_mode = IPW_A_MODE; |
| 7434 | else if (network->mode & priv->ieee->mode & IEEE_G) |
| 7435 | priv->assoc_request.ieee_mode = IPW_G_MODE; |
| 7436 | else if (network->mode & priv->ieee->mode & IEEE_B) |
| 7437 | priv->assoc_request.ieee_mode = IPW_B_MODE; |
| 7438 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7439 | priv->assoc_request.capability = cpu_to_le16(network->capability); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7440 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7441 | && !(priv->config & CFG_PREAMBLE_LONG)) { |
| 7442 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; |
| 7443 | } else { |
| 7444 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; |
| 7445 | |
| 7446 | /* Clear the short preamble if we won't be supporting it */ |
| 7447 | priv->assoc_request.capability &= |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7448 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7449 | } |
| 7450 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7451 | /* Clear capability bits that aren't used in Ad Hoc */ |
| 7452 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7453 | priv->assoc_request.capability &= |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7454 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7455 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7456 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7457 | "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] | 7458 | roaming ? "Rea" : "A", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7459 | print_ssid(ssid, priv->essid, priv->essid_len), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7460 | network->channel, |
| 7461 | ipw_modes[priv->assoc_request.ieee_mode], |
| 7462 | rates->num_rates, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7463 | (priv->assoc_request.preamble_length == |
| 7464 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", |
| 7465 | network->capability & |
| 7466 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7467 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7468 | priv->capability & CAP_PRIVACY_ON ? |
| 7469 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7470 | "(open)") : "", |
| 7471 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7472 | priv->capability & CAP_PRIVACY_ON ? |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7473 | '1' + priv->ieee->sec.active_key : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7474 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7475 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7476 | priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7477 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7478 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7479 | priv->assoc_request.assoc_type = HC_IBSS_START; |
| 7480 | priv->assoc_request.assoc_tsf_msw = 0; |
| 7481 | priv->assoc_request.assoc_tsf_lsw = 0; |
| 7482 | } else { |
| 7483 | if (unlikely(roaming)) |
| 7484 | priv->assoc_request.assoc_type = HC_REASSOCIATE; |
| 7485 | else |
| 7486 | priv->assoc_request.assoc_type = HC_ASSOCIATE; |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7487 | priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]); |
| 7488 | 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] | 7489 | } |
| 7490 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7491 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7492 | |
| 7493 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7494 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7495 | priv->assoc_request.atim_window = cpu_to_le16(network->atim_window); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7496 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7497 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7498 | priv->assoc_request.atim_window = 0; |
| 7499 | } |
| 7500 | |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 7501 | priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7502 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7503 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 7504 | if (err) { |
| 7505 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); |
| 7506 | return err; |
| 7507 | } |
| 7508 | |
| 7509 | rates->ieee_mode = priv->assoc_request.ieee_mode; |
| 7510 | rates->purpose = IPW_RATE_CONNECT; |
| 7511 | ipw_send_supported_rates(priv, rates); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7512 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7513 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
| 7514 | priv->sys_config.dot11g_auto_detection = 1; |
| 7515 | else |
| 7516 | priv->sys_config.dot11g_auto_detection = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7517 | |
| 7518 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7519 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 7520 | else |
| 7521 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 7522 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7523 | err = ipw_send_system_config(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7524 | if (err) { |
| 7525 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); |
| 7526 | return err; |
| 7527 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7528 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7529 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7530 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7531 | if (err) { |
| 7532 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7533 | return err; |
| 7534 | } |
| 7535 | |
| 7536 | /* |
| 7537 | * If preemption is enabled, it is possible for the association |
| 7538 | * to complete before we return from ipw_send_associate. Therefore |
| 7539 | * we have to be sure and update our priviate data first. |
| 7540 | */ |
| 7541 | priv->channel = network->channel; |
| 7542 | memcpy(priv->bssid, network->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7543 | priv->status |= STATUS_ASSOCIATING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7544 | priv->status &= ~STATUS_SECURITY_UPDATED; |
| 7545 | |
| 7546 | priv->assoc_network = network; |
| 7547 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 7548 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7549 | ipw_qos_association(priv, network); |
| 7550 | #endif |
| 7551 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7552 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 7553 | if (err) { |
| 7554 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7555 | return err; |
| 7556 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7557 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 7558 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7559 | print_ssid(ssid, priv->essid, priv->essid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7560 | priv->bssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7561 | |
| 7562 | return 0; |
| 7563 | } |
| 7564 | |
| 7565 | static void ipw_roam(void *data) |
| 7566 | { |
| 7567 | struct ipw_priv *priv = data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7568 | struct libipw_network *network = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7569 | struct ipw_network_match match = { |
| 7570 | .network = priv->assoc_network |
| 7571 | }; |
| 7572 | |
| 7573 | /* The roaming process is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7574 | * |
| 7575 | * 1. Missed beacon threshold triggers the roaming process by |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7576 | * setting the status ROAM bit and requesting a scan. |
| 7577 | * 2. When the scan completes, it schedules the ROAM work |
| 7578 | * 3. The ROAM work looks at all of the known networks for one that |
| 7579 | * is a better network than the currently associated. If none |
| 7580 | * found, the ROAM process is over (ROAM bit cleared) |
| 7581 | * 4. If a better network is found, a disassociation request is |
| 7582 | * sent. |
| 7583 | * 5. When the disassociation completes, the roam work is again |
| 7584 | * scheduled. The second time through, the driver is no longer |
| 7585 | * associated, and the newly selected network is sent an |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7586 | * association request. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7587 | * 6. At this point ,the roaming process is complete and the ROAM |
| 7588 | * status bit is cleared. |
| 7589 | */ |
| 7590 | |
| 7591 | /* If we are no longer associated, and the roaming bit is no longer |
| 7592 | * set, then we are not actively roaming, so just return */ |
| 7593 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) |
| 7594 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7595 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7596 | if (priv->status & STATUS_ASSOCIATED) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7597 | /* First pass through ROAM process -- look for a better |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7598 | * network */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7599 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7600 | u8 rssi = priv->assoc_network->stats.rssi; |
| 7601 | priv->assoc_network->stats.rssi = -128; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7602 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7603 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 7604 | if (network != priv->assoc_network) |
| 7605 | ipw_best_network(priv, &match, network, 1); |
| 7606 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7607 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7608 | priv->assoc_network->stats.rssi = rssi; |
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 | if (match.network == priv->assoc_network) { |
| 7611 | IPW_DEBUG_ASSOC("No better APs in this network to " |
| 7612 | "roam to.\n"); |
| 7613 | priv->status &= ~STATUS_ROAMING; |
| 7614 | ipw_debug_config(priv); |
| 7615 | return; |
| 7616 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7617 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7618 | ipw_send_disassociate(priv, 1); |
| 7619 | priv->assoc_network = match.network; |
| 7620 | |
| 7621 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7622 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7623 | |
| 7624 | /* Second pass through ROAM process -- request association */ |
| 7625 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); |
| 7626 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); |
| 7627 | priv->status &= ~STATUS_ROAMING; |
| 7628 | } |
| 7629 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7630 | static void ipw_bg_roam(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7631 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7632 | struct ipw_priv *priv = |
| 7633 | container_of(work, struct ipw_priv, roam); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7634 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7635 | ipw_roam(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7636 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7637 | } |
| 7638 | |
| 7639 | static int ipw_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7640 | { |
| 7641 | struct ipw_priv *priv = data; |
| 7642 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7643 | struct libipw_network *network = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7644 | struct ipw_network_match match = { |
| 7645 | .network = NULL |
| 7646 | }; |
| 7647 | struct ipw_supported_rates *rates; |
| 7648 | struct list_head *element; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7649 | unsigned long flags; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7650 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7651 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7652 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 7653 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); |
| 7654 | return 0; |
| 7655 | } |
| 7656 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7657 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7658 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
| 7659 | "progress)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7660 | return 0; |
| 7661 | } |
| 7662 | |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 7663 | if (priv->status & STATUS_DISASSOCIATING) { |
| 7664 | IPW_DEBUG_ASSOC("Not attempting association (in " |
| 7665 | "disassociating)\n "); |
| 7666 | queue_work(priv->workqueue, &priv->associate); |
| 7667 | return 0; |
| 7668 | } |
| 7669 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7670 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7671 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
| 7672 | "initialized)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7673 | return 0; |
| 7674 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7675 | |
| 7676 | if (!(priv->config & CFG_ASSOCIATE) && |
Alexey Fisher | 3e4127f | 2008-11-06 09:51:16 +0100 | [diff] [blame] | 7677 | !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7678 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7679 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7680 | } |
| 7681 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7682 | /* Protect our use of the network_list */ |
| 7683 | spin_lock_irqsave(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7684 | list_for_each_entry(network, &priv->ieee->network_list, list) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7685 | ipw_best_network(priv, &match, network, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7686 | |
| 7687 | network = match.network; |
| 7688 | rates = &match.rates; |
| 7689 | |
| 7690 | if (network == NULL && |
| 7691 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7692 | priv->config & CFG_ADHOC_CREATE && |
| 7693 | priv->config & CFG_STATIC_ESSID && |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7694 | priv->config & CFG_STATIC_CHANNEL) { |
| 7695 | /* Use oldest network if the free list is empty */ |
| 7696 | if (list_empty(&priv->ieee->network_free_list)) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7697 | struct libipw_network *oldest = NULL; |
| 7698 | struct libipw_network *target; |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7699 | |
| 7700 | list_for_each_entry(target, &priv->ieee->network_list, list) { |
| 7701 | if ((oldest == NULL) || |
| 7702 | (target->last_scanned < oldest->last_scanned)) |
| 7703 | oldest = target; |
| 7704 | } |
| 7705 | |
| 7706 | /* If there are no more slots, expire the oldest */ |
| 7707 | list_del(&oldest->list); |
| 7708 | target = oldest; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7709 | IPW_DEBUG_ASSOC("Expired '%s' (%pM) from " |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7710 | "network list.\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 7711 | print_ssid(ssid, target->ssid, |
| 7712 | target->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7713 | target->bssid); |
Dan Williams | a6d4eae | 2008-05-29 14:38:28 -0400 | [diff] [blame] | 7714 | list_add_tail(&target->list, |
| 7715 | &priv->ieee->network_free_list); |
| 7716 | } |
| 7717 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7718 | element = priv->ieee->network_free_list.next; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7719 | network = list_entry(element, struct libipw_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7720 | ipw_adhoc_create(priv, network); |
| 7721 | rates = &priv->rates; |
| 7722 | list_del(element); |
| 7723 | list_add_tail(&network->list, &priv->ieee->network_list); |
| 7724 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7725 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7726 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7727 | /* If we reached the end of the list, then we don't have any valid |
| 7728 | * matching APs */ |
| 7729 | if (!network) { |
| 7730 | ipw_debug_config(priv); |
| 7731 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7732 | if (!(priv->status & STATUS_SCANNING)) { |
| 7733 | if (!(priv->config & CFG_SPEED_SCAN)) |
| 7734 | queue_delayed_work(priv->workqueue, |
| 7735 | &priv->request_scan, |
| 7736 | SCAN_INTERVAL); |
| 7737 | else |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7738 | queue_delayed_work(priv->workqueue, |
| 7739 | &priv->request_scan, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7740 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7741 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7742 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7743 | } |
| 7744 | |
| 7745 | ipw_associate_network(priv, network, rates, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7746 | |
| 7747 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7748 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7749 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7750 | static void ipw_bg_associate(struct work_struct *work) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7751 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7752 | struct ipw_priv *priv = |
| 7753 | container_of(work, struct ipw_priv, associate); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7754 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7755 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7756 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7757 | } |
| 7758 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7759 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
| 7760 | struct sk_buff *skb) |
| 7761 | { |
| 7762 | struct ieee80211_hdr *hdr; |
| 7763 | u16 fc; |
| 7764 | |
| 7765 | hdr = (struct ieee80211_hdr *)skb->data; |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 7766 | fc = le16_to_cpu(hdr->frame_control); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7767 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 7768 | return; |
| 7769 | |
| 7770 | fc &= ~IEEE80211_FCTL_PROTECTED; |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 7771 | hdr->frame_control = cpu_to_le16(fc); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7772 | switch (priv->ieee->sec.level) { |
| 7773 | case SEC_LEVEL_3: |
| 7774 | /* Remove CCMP HDR */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7775 | memmove(skb->data + LIBIPW_3ADDR_LEN, |
| 7776 | skb->data + LIBIPW_3ADDR_LEN + 8, |
| 7777 | skb->len - LIBIPW_3ADDR_LEN - 8); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7778 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7779 | break; |
| 7780 | case SEC_LEVEL_2: |
| 7781 | break; |
| 7782 | case SEC_LEVEL_1: |
| 7783 | /* Remove IV */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7784 | memmove(skb->data + LIBIPW_3ADDR_LEN, |
| 7785 | skb->data + LIBIPW_3ADDR_LEN + 4, |
| 7786 | skb->len - LIBIPW_3ADDR_LEN - 4); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7787 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7788 | break; |
| 7789 | case SEC_LEVEL_0: |
| 7790 | break; |
| 7791 | default: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7792 | printk(KERN_ERR "Unknown security level %d\n", |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7793 | priv->ieee->sec.level); |
| 7794 | break; |
| 7795 | } |
| 7796 | } |
| 7797 | |
| 7798 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
| 7799 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7800 | struct libipw_rx_stats *stats) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7801 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7802 | struct net_device *dev = priv->net_dev; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7803 | struct libipw_hdr_4addr *hdr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7804 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7805 | |
| 7806 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7807 | dev->trans_start = jiffies; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7808 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7809 | /* We only process data packets if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7810 | * interface is open */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7811 | 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] | 7812 | skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7813 | dev->stats.rx_errors++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7814 | priv->wstats.discard.misc++; |
| 7815 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7816 | return; |
| 7817 | } else if (unlikely(!netif_running(priv->net_dev))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7818 | dev->stats.rx_dropped++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7819 | priv->wstats.discard.misc++; |
| 7820 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7821 | return; |
| 7822 | } |
| 7823 | |
| 7824 | /* Advance skb->data to the start of the actual payload */ |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 7825 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7826 | |
| 7827 | /* Set the size of the skb to the size of the frame */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7828 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7829 | |
| 7830 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7831 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7832 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7833 | hdr = (struct libipw_hdr_4addr *)rxb->skb->data; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7834 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7835 | (is_multicast_ether_addr(hdr->addr1) ? |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7836 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7837 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
| 7838 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7839 | if (!libipw_rx(priv->ieee, rxb->skb, stats)) |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7840 | dev->stats.rx_errors++; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7841 | else { /* libipw_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7842 | rxb->skb = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7843 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7844 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7845 | } |
| 7846 | |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 7847 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7848 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, |
| 7849 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7850 | struct libipw_rx_stats *stats) |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7851 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7852 | struct net_device *dev = priv->net_dev; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7853 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7854 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7855 | |
| 7856 | /* initial pull of some data */ |
| 7857 | u16 received_channel = frame->received_channel; |
| 7858 | u8 antennaAndPhy = frame->antennaAndPhy; |
| 7859 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ |
| 7860 | u16 pktrate = frame->rate; |
| 7861 | |
| 7862 | /* Magic struct that slots into the radiotap header -- no reason |
| 7863 | * to build this manually element by element, we can write it much |
| 7864 | * more efficiently than we can parse it. ORDER MATTERS HERE */ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7865 | struct ipw_rt_hdr *ipw_rt; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7866 | |
| 7867 | short len = le16_to_cpu(pkt->u.frame.length); |
| 7868 | |
| 7869 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7870 | dev->trans_start = jiffies; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7871 | |
| 7872 | /* We only process data packets if the |
| 7873 | * interface is open */ |
| 7874 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
| 7875 | skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7876 | dev->stats.rx_errors++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7877 | priv->wstats.discard.misc++; |
| 7878 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7879 | return; |
| 7880 | } else if (unlikely(!netif_running(priv->net_dev))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7881 | dev->stats.rx_dropped++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7882 | priv->wstats.discard.misc++; |
| 7883 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7884 | return; |
| 7885 | } |
| 7886 | |
| 7887 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7888 | * that now */ |
| 7889 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7890 | /* FIXME: Should alloc bigger skb instead */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7891 | dev->stats.rx_dropped++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7892 | priv->wstats.discard.misc++; |
| 7893 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7894 | return; |
| 7895 | } |
| 7896 | |
| 7897 | /* copy the frame itself */ |
| 7898 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), |
| 7899 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); |
| 7900 | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7901 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; |
| 7902 | |
| 7903 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7904 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 7905 | 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] | 7906 | |
| 7907 | /* Big bitfield of all the fields we provide in radiotap */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 7908 | ipw_rt->rt_hdr.it_present = cpu_to_le32( |
| 7909 | (1 << IEEE80211_RADIOTAP_TSFT) | |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 7910 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7911 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7912 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7913 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 7914 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7915 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7916 | |
| 7917 | /* Zero the flags, we'll add to them as we go */ |
| 7918 | ipw_rt->rt_flags = 0; |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 7919 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | |
| 7920 | frame->parent_tsf[2] << 16 | |
| 7921 | frame->parent_tsf[1] << 8 | |
| 7922 | frame->parent_tsf[0]); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7923 | |
| 7924 | /* Convert signal to DBM */ |
| 7925 | ipw_rt->rt_dbmsignal = antsignal; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 7926 | ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7927 | |
| 7928 | /* Convert the channel data and set the flags */ |
| 7929 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); |
| 7930 | if (received_channel > 14) { /* 802.11a */ |
| 7931 | ipw_rt->rt_chbitmask = |
| 7932 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7933 | } else if (antennaAndPhy & 32) { /* 802.11b */ |
| 7934 | ipw_rt->rt_chbitmask = |
| 7935 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7936 | } else { /* 802.11g */ |
| 7937 | ipw_rt->rt_chbitmask = |
Al Viro | 472caf8 | 2007-12-27 01:50:54 -0500 | [diff] [blame] | 7938 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7939 | } |
| 7940 | |
| 7941 | /* set the rate in multiples of 500k/s */ |
| 7942 | switch (pktrate) { |
| 7943 | case IPW_TX_RATE_1MB: |
| 7944 | ipw_rt->rt_rate = 2; |
| 7945 | break; |
| 7946 | case IPW_TX_RATE_2MB: |
| 7947 | ipw_rt->rt_rate = 4; |
| 7948 | break; |
| 7949 | case IPW_TX_RATE_5MB: |
| 7950 | ipw_rt->rt_rate = 10; |
| 7951 | break; |
| 7952 | case IPW_TX_RATE_6MB: |
| 7953 | ipw_rt->rt_rate = 12; |
| 7954 | break; |
| 7955 | case IPW_TX_RATE_9MB: |
| 7956 | ipw_rt->rt_rate = 18; |
| 7957 | break; |
| 7958 | case IPW_TX_RATE_11MB: |
| 7959 | ipw_rt->rt_rate = 22; |
| 7960 | break; |
| 7961 | case IPW_TX_RATE_12MB: |
| 7962 | ipw_rt->rt_rate = 24; |
| 7963 | break; |
| 7964 | case IPW_TX_RATE_18MB: |
| 7965 | ipw_rt->rt_rate = 36; |
| 7966 | break; |
| 7967 | case IPW_TX_RATE_24MB: |
| 7968 | ipw_rt->rt_rate = 48; |
| 7969 | break; |
| 7970 | case IPW_TX_RATE_36MB: |
| 7971 | ipw_rt->rt_rate = 72; |
| 7972 | break; |
| 7973 | case IPW_TX_RATE_48MB: |
| 7974 | ipw_rt->rt_rate = 96; |
| 7975 | break; |
| 7976 | case IPW_TX_RATE_54MB: |
| 7977 | ipw_rt->rt_rate = 108; |
| 7978 | break; |
| 7979 | default: |
| 7980 | ipw_rt->rt_rate = 0; |
| 7981 | break; |
| 7982 | } |
| 7983 | |
| 7984 | /* antenna number */ |
| 7985 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ |
| 7986 | |
| 7987 | /* set the preamble flag if we have it */ |
| 7988 | if ((antennaAndPhy & 64)) |
| 7989 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7990 | |
| 7991 | /* Set the size of the skb to the size of the frame */ |
| 7992 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7993 | |
| 7994 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7995 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7996 | if (!libipw_rx(priv->ieee, rxb->skb, stats)) |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 7997 | dev->stats.rx_errors++; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 7998 | else { /* libipw_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7999 | rxb->skb = NULL; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8000 | /* no LED during capture */ |
| 8001 | } |
| 8002 | } |
| 8003 | #endif |
| 8004 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8005 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8006 | #define libipw_is_probe_response(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8007 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \ |
| 8008 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP ) |
| 8009 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8010 | #define libipw_is_management(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8011 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 8012 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8013 | #define libipw_is_control(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8014 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) |
| 8015 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8016 | #define libipw_is_data(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8017 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) |
| 8018 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8019 | #define libipw_is_assoc_request(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8020 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ) |
| 8021 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8022 | #define libipw_is_reassoc_request(fc) \ |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8023 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
| 8024 | |
| 8025 | static void ipw_handle_promiscuous_rx(struct ipw_priv *priv, |
| 8026 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8027 | struct libipw_rx_stats *stats) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8028 | { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8029 | struct net_device *dev = priv->prom_net_dev; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8030 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 8031 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 8032 | struct ipw_rt_hdr *ipw_rt; |
| 8033 | |
| 8034 | /* First cache any information we need before we overwrite |
| 8035 | * the information provided in the skb from the hardware */ |
| 8036 | struct ieee80211_hdr *hdr; |
| 8037 | u16 channel = frame->received_channel; |
| 8038 | u8 phy_flags = frame->antennaAndPhy; |
| 8039 | s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8040 | s8 noise = (s8) le16_to_cpu(frame->noise); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8041 | u8 rate = frame->rate; |
| 8042 | short len = le16_to_cpu(pkt->u.frame.length); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8043 | struct sk_buff *skb; |
| 8044 | int hdr_only = 0; |
| 8045 | u16 filter = priv->prom_priv->filter; |
| 8046 | |
| 8047 | /* If the filter is set to not include Rx frames then return */ |
| 8048 | if (filter & IPW_PROM_NO_RX) |
| 8049 | return; |
| 8050 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8051 | /* We received data from the HW, so stop the watchdog */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8052 | dev->trans_start = jiffies; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8053 | |
| 8054 | if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8055 | dev->stats.rx_errors++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8056 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 8057 | return; |
| 8058 | } |
| 8059 | |
| 8060 | /* We only process data packets if the interface is open */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8061 | if (unlikely(!netif_running(dev))) { |
| 8062 | dev->stats.rx_dropped++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8063 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 8064 | return; |
| 8065 | } |
| 8066 | |
| 8067 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 8068 | * that now */ |
| 8069 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 8070 | /* FIXME: Should alloc bigger skb instead */ |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8071 | dev->stats.rx_dropped++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8072 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 8073 | return; |
| 8074 | } |
| 8075 | |
| 8076 | hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8077 | if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8078 | if (filter & IPW_PROM_NO_MGMT) |
| 8079 | return; |
| 8080 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 8081 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8082 | } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8083 | if (filter & IPW_PROM_NO_CTL) |
| 8084 | return; |
| 8085 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 8086 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8087 | } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8088 | if (filter & IPW_PROM_NO_DATA) |
| 8089 | return; |
| 8090 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 8091 | hdr_only = 1; |
| 8092 | } |
| 8093 | |
| 8094 | /* Copy the SKB since this is for the promiscuous side */ |
| 8095 | skb = skb_copy(rxb->skb, GFP_ATOMIC); |
| 8096 | if (skb == NULL) { |
| 8097 | IPW_ERROR("skb_clone failed for promiscuous copy.\n"); |
| 8098 | return; |
| 8099 | } |
| 8100 | |
| 8101 | /* copy the frame data to write after where the radiotap header goes */ |
| 8102 | ipw_rt = (void *)skb->data; |
| 8103 | |
| 8104 | if (hdr_only) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8105 | len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8106 | |
| 8107 | memcpy(ipw_rt->payload, hdr, len); |
| 8108 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8109 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 8110 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8111 | 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] | 8112 | |
| 8113 | /* Set the size of the skb to the size of the frame */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8114 | skb_put(skb, sizeof(*ipw_rt) + len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8115 | |
| 8116 | /* Big bitfield of all the fields we provide in radiotap */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 8117 | ipw_rt->rt_hdr.it_present = cpu_to_le32( |
| 8118 | (1 << IEEE80211_RADIOTAP_TSFT) | |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 8119 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8120 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 8121 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 8122 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 8123 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 8124 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 8125 | |
| 8126 | /* Zero the flags, we'll add to them as we go */ |
| 8127 | ipw_rt->rt_flags = 0; |
Zhu Yi | 4b1f8a9 | 2006-12-05 14:42:14 +0800 | [diff] [blame] | 8128 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | |
| 8129 | frame->parent_tsf[2] << 16 | |
| 8130 | frame->parent_tsf[1] << 8 | |
| 8131 | frame->parent_tsf[0]); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8132 | |
| 8133 | /* Convert to DBM */ |
| 8134 | ipw_rt->rt_dbmsignal = signal; |
| 8135 | ipw_rt->rt_dbmnoise = noise; |
| 8136 | |
| 8137 | /* Convert the channel data and set the flags */ |
| 8138 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel)); |
| 8139 | if (channel > 14) { /* 802.11a */ |
| 8140 | ipw_rt->rt_chbitmask = |
| 8141 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 8142 | } else if (phy_flags & (1 << 5)) { /* 802.11b */ |
| 8143 | ipw_rt->rt_chbitmask = |
| 8144 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 8145 | } else { /* 802.11g */ |
| 8146 | ipw_rt->rt_chbitmask = |
Al Viro | 472caf8 | 2007-12-27 01:50:54 -0500 | [diff] [blame] | 8147 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8148 | } |
| 8149 | |
| 8150 | /* set the rate in multiples of 500k/s */ |
| 8151 | switch (rate) { |
| 8152 | case IPW_TX_RATE_1MB: |
| 8153 | ipw_rt->rt_rate = 2; |
| 8154 | break; |
| 8155 | case IPW_TX_RATE_2MB: |
| 8156 | ipw_rt->rt_rate = 4; |
| 8157 | break; |
| 8158 | case IPW_TX_RATE_5MB: |
| 8159 | ipw_rt->rt_rate = 10; |
| 8160 | break; |
| 8161 | case IPW_TX_RATE_6MB: |
| 8162 | ipw_rt->rt_rate = 12; |
| 8163 | break; |
| 8164 | case IPW_TX_RATE_9MB: |
| 8165 | ipw_rt->rt_rate = 18; |
| 8166 | break; |
| 8167 | case IPW_TX_RATE_11MB: |
| 8168 | ipw_rt->rt_rate = 22; |
| 8169 | break; |
| 8170 | case IPW_TX_RATE_12MB: |
| 8171 | ipw_rt->rt_rate = 24; |
| 8172 | break; |
| 8173 | case IPW_TX_RATE_18MB: |
| 8174 | ipw_rt->rt_rate = 36; |
| 8175 | break; |
| 8176 | case IPW_TX_RATE_24MB: |
| 8177 | ipw_rt->rt_rate = 48; |
| 8178 | break; |
| 8179 | case IPW_TX_RATE_36MB: |
| 8180 | ipw_rt->rt_rate = 72; |
| 8181 | break; |
| 8182 | case IPW_TX_RATE_48MB: |
| 8183 | ipw_rt->rt_rate = 96; |
| 8184 | break; |
| 8185 | case IPW_TX_RATE_54MB: |
| 8186 | ipw_rt->rt_rate = 108; |
| 8187 | break; |
| 8188 | default: |
| 8189 | ipw_rt->rt_rate = 0; |
| 8190 | break; |
| 8191 | } |
| 8192 | |
| 8193 | /* antenna number */ |
| 8194 | ipw_rt->rt_antenna = (phy_flags & 3); |
| 8195 | |
| 8196 | /* set the preamble flag if we have it */ |
| 8197 | if (phy_flags & (1 << 6)) |
| 8198 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 8199 | |
| 8200 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len); |
| 8201 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8202 | if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) { |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8203 | dev->stats.rx_errors++; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8204 | dev_kfree_skb_any(skb); |
| 8205 | } |
| 8206 | } |
| 8207 | #endif |
| 8208 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 8209 | static int is_network_packet(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8210 | struct libipw_hdr_4addr *header) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8211 | { |
| 8212 | /* Filter incoming packets to determine if they are targetted toward |
| 8213 | * this network, discarding packets coming from ourselves */ |
| 8214 | switch (priv->ieee->iw_mode) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8215 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8216 | /* packets from our adapter are dropped (echo) */ |
| 8217 | if (!memcmp(header->addr2, 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 BSSID go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 8221 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8222 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8223 | |
| 8224 | /* packets to our adapter go through */ |
| 8225 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 8226 | ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8227 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8228 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8229 | /* packets from our adapter are dropped (echo) */ |
| 8230 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) |
| 8231 | return 0; |
| 8232 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 8233 | /* {broad,multi}cast packets to our BSS go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 8234 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8235 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
| 8236 | |
| 8237 | /* packets to our adapter go through */ |
| 8238 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 8239 | ETH_ALEN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8240 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8241 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8242 | return 1; |
| 8243 | } |
| 8244 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8245 | #define IPW_PACKET_RETRY_TIME HZ |
| 8246 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 8247 | static int is_duplicate_packet(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8248 | struct libipw_hdr_4addr *header) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8249 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8250 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 8251 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 8252 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 8253 | u16 *last_seq, *last_frag; |
| 8254 | unsigned long *last_time; |
| 8255 | |
| 8256 | switch (priv->ieee->iw_mode) { |
| 8257 | case IW_MODE_ADHOC: |
| 8258 | { |
| 8259 | struct list_head *p; |
| 8260 | struct ipw_ibss_seq *entry = NULL; |
| 8261 | u8 *mac = header->addr2; |
| 8262 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; |
| 8263 | |
| 8264 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 8265 | entry = |
| 8266 | list_entry(p, struct ipw_ibss_seq, list); |
| 8267 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 8268 | break; |
| 8269 | } |
| 8270 | if (p == &priv->ibss_mac_hash[index]) { |
| 8271 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 8272 | if (!entry) { |
| 8273 | IPW_ERROR |
| 8274 | ("Cannot malloc new mac entry\n"); |
| 8275 | return 0; |
| 8276 | } |
| 8277 | memcpy(entry->mac, mac, ETH_ALEN); |
| 8278 | entry->seq_num = seq; |
| 8279 | entry->frag_num = frag; |
| 8280 | entry->packet_time = jiffies; |
| 8281 | list_add(&entry->list, |
| 8282 | &priv->ibss_mac_hash[index]); |
| 8283 | return 0; |
| 8284 | } |
| 8285 | last_seq = &entry->seq_num; |
| 8286 | last_frag = &entry->frag_num; |
| 8287 | last_time = &entry->packet_time; |
| 8288 | break; |
| 8289 | } |
| 8290 | case IW_MODE_INFRA: |
| 8291 | last_seq = &priv->last_seq_num; |
| 8292 | last_frag = &priv->last_frag_num; |
| 8293 | last_time = &priv->last_packet_time; |
| 8294 | break; |
| 8295 | default: |
| 8296 | return 0; |
| 8297 | } |
| 8298 | if ((*last_seq == seq) && |
| 8299 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { |
| 8300 | if (*last_frag == frag) |
| 8301 | goto drop; |
| 8302 | if (*last_frag + 1 != frag) |
| 8303 | /* out-of-order fragment */ |
| 8304 | goto drop; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8305 | } else |
| 8306 | *last_seq = seq; |
| 8307 | |
Zhu Yi | f57ce7c | 2005-07-13 12:22:15 -0500 | [diff] [blame] | 8308 | *last_frag = frag; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8309 | *last_time = jiffies; |
| 8310 | return 0; |
| 8311 | |
| 8312 | drop: |
Zhu Yi | 87b016c | 2005-08-05 17:17:35 +0800 | [diff] [blame] | 8313 | /* Comment this line now since we observed the card receives |
| 8314 | * duplicate packets but the FCTL_RETRY bit is not set in the |
| 8315 | * IBSS mode with fragmentation enabled. |
John W. Linville | 7211801 | 2008-09-30 21:43:03 -0400 | [diff] [blame] | 8316 | BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8317 | return 1; |
| 8318 | } |
| 8319 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8320 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
| 8321 | struct ipw_rx_mem_buffer *rxb, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8322 | struct libipw_rx_stats *stats) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8323 | { |
| 8324 | struct sk_buff *skb = rxb->skb; |
| 8325 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8326 | struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8327 | (skb->data + IPW_RX_FRAME_SIZE); |
| 8328 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8329 | libipw_rx_mgt(priv->ieee, header, stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8330 | |
| 8331 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 8332 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8333 | IEEE80211_STYPE_PROBE_RESP) || |
| 8334 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 8335 | IEEE80211_STYPE_BEACON))) { |
| 8336 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) |
| 8337 | ipw_add_station(priv, header->addr2); |
| 8338 | } |
| 8339 | |
| 8340 | if (priv->config & CFG_NET_STATS) { |
| 8341 | IPW_DEBUG_HC("sending stat packet\n"); |
| 8342 | |
| 8343 | /* Set the size of the skb to the size of the full |
| 8344 | * ipw header and 802.11 frame */ |
| 8345 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + |
| 8346 | IPW_RX_FRAME_SIZE); |
| 8347 | |
| 8348 | /* Advance past the ipw packet header to the 802.11 frame */ |
| 8349 | skb_pull(skb, IPW_RX_FRAME_SIZE); |
| 8350 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8351 | /* Push the libipw_rx_stats before the 802.11 frame */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8352 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
| 8353 | |
| 8354 | skb->dev = priv->ieee->dev; |
| 8355 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8356 | /* Point raw at the libipw_stats */ |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 8357 | skb_reset_mac_header(skb); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8358 | |
| 8359 | skb->pkt_type = PACKET_OTHERHOST; |
Harvey Harrison | c1b4aa3 | 2009-01-29 13:26:44 -0800 | [diff] [blame] | 8360 | skb->protocol = cpu_to_be16(ETH_P_80211_STATS); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8361 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
| 8362 | netif_rx(skb); |
| 8363 | rxb->skb = NULL; |
| 8364 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8365 | } |
| 8366 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8367 | /* |
| 8368 | * Main entry function for recieving a packet with 80211 headers. This |
| 8369 | * should be called when ever the FW has notified us that there is a new |
| 8370 | * skb in the recieve queue. |
| 8371 | */ |
| 8372 | static void ipw_rx(struct ipw_priv *priv) |
| 8373 | { |
| 8374 | struct ipw_rx_mem_buffer *rxb; |
| 8375 | struct ipw_rx_packet *pkt; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8376 | struct libipw_hdr_4addr *header; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8377 | u32 r, w, i; |
| 8378 | u8 network_packet; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8379 | u8 fill_rx = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8380 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8381 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
| 8382 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8383 | i = priv->rxq->read; |
| 8384 | |
| 8385 | if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2)) |
| 8386 | fill_rx = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8387 | |
| 8388 | while (i != r) { |
| 8389 | rxb = priv->rxq->queue[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8390 | if (unlikely(rxb == NULL)) { |
| 8391 | printk(KERN_CRIT "Queue not allocated!\n"); |
| 8392 | break; |
| 8393 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8394 | priv->rxq->queue[i] = NULL; |
| 8395 | |
| 8396 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8397 | IPW_RX_BUF_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8398 | PCI_DMA_FROMDEVICE); |
| 8399 | |
| 8400 | pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 8401 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", |
| 8402 | pkt->header.message_type, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8403 | pkt->header.rx_seq_num, pkt->header.control_bits); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8404 | |
| 8405 | switch (pkt->header.message_type) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8406 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8407 | struct libipw_rx_stats stats = { |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 8408 | .rssi = pkt->u.frame.rssi_dbm - |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8409 | IPW_RSSI_TO_DBM, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8410 | .signal = |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8411 | pkt->u.frame.rssi_dbm - |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8412 | IPW_RSSI_TO_DBM + 0x100, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8413 | .noise = |
| 8414 | le16_to_cpu(pkt->u.frame.noise), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8415 | .rate = pkt->u.frame.rate, |
| 8416 | .mac_time = jiffies, |
| 8417 | .received_channel = |
| 8418 | pkt->u.frame.received_channel, |
| 8419 | .freq = |
| 8420 | (pkt->u.frame. |
| 8421 | control & (1 << 0)) ? |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8422 | LIBIPW_24GHZ_BAND : |
| 8423 | LIBIPW_52GHZ_BAND, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8424 | .len = le16_to_cpu(pkt->u.frame.length), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8425 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8426 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8427 | if (stats.rssi != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8428 | stats.mask |= LIBIPW_STATMASK_RSSI; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8429 | if (stats.signal != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8430 | stats.mask |= LIBIPW_STATMASK_SIGNAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8431 | if (stats.noise != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8432 | stats.mask |= LIBIPW_STATMASK_NOISE; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8433 | if (stats.rate != 0) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8434 | stats.mask |= LIBIPW_STATMASK_RATE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8435 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8436 | priv->rx_packets++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8437 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8438 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 8439 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) |
| 8440 | ipw_handle_promiscuous_rx(priv, rxb, &stats); |
| 8441 | #endif |
| 8442 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8443 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8444 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8445 | #ifdef CONFIG_IPW2200_RADIOTAP |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8446 | |
| 8447 | ipw_handle_data_packet_monitor(priv, |
| 8448 | rxb, |
| 8449 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8450 | #else |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 8451 | ipw_handle_data_packet(priv, rxb, |
| 8452 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8453 | #endif |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8454 | break; |
| 8455 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8456 | #endif |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8457 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8458 | header = |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8459 | (struct libipw_hdr_4addr *)(rxb->skb-> |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 8460 | data + |
| 8461 | IPW_RX_FRAME_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8462 | /* TODO: Check Ad-Hoc dest/source and make sure |
| 8463 | * that we are actually parsing these packets |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8464 | * correctly -- we should probably use the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8465 | * frame control of the packet and disregard |
| 8466 | * the current iw_mode */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8467 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8468 | network_packet = |
| 8469 | is_network_packet(priv, header); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8470 | if (network_packet && priv->assoc_network) { |
| 8471 | priv->assoc_network->stats.rssi = |
| 8472 | stats.rssi; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 8473 | priv->exp_avg_rssi = |
| 8474 | exponential_average(priv->exp_avg_rssi, |
| 8475 | stats.rssi, DEPTH_RSSI); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8476 | } |
| 8477 | |
| 8478 | IPW_DEBUG_RX("Frame: len=%u\n", |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8479 | le16_to_cpu(pkt->u.frame.length)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8480 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8481 | if (le16_to_cpu(pkt->u.frame.length) < |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8482 | libipw_get_hdrlen(le16_to_cpu( |
Zhu Yi | 9d0be03 | 2006-02-15 06:18:19 +0800 | [diff] [blame] | 8483 | header->frame_ctl))) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8484 | IPW_DEBUG_DROP |
| 8485 | ("Received packet is too small. " |
| 8486 | "Dropping.\n"); |
Stephen Hemminger | ce55cba | 2009-03-20 19:36:38 +0000 | [diff] [blame] | 8487 | priv->net_dev->stats.rx_errors++; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8488 | priv->wstats.discard.misc++; |
| 8489 | break; |
| 8490 | } |
| 8491 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8492 | switch (WLAN_FC_GET_TYPE |
| 8493 | (le16_to_cpu(header->frame_ctl))) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8494 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8495 | case IEEE80211_FTYPE_MGMT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8496 | ipw_handle_mgmt_packet(priv, rxb, |
| 8497 | &stats); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8498 | break; |
| 8499 | |
| 8500 | case IEEE80211_FTYPE_CTL: |
| 8501 | break; |
| 8502 | |
| 8503 | case IEEE80211_FTYPE_DATA: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8504 | if (unlikely(!network_packet || |
| 8505 | is_duplicate_packet(priv, |
| 8506 | header))) |
| 8507 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8508 | IPW_DEBUG_DROP("Dropping: " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 8509 | "%pM, " |
| 8510 | "%pM, " |
| 8511 | "%pM\n", |
| 8512 | header->addr1, |
| 8513 | header->addr2, |
| 8514 | header->addr3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8515 | break; |
| 8516 | } |
| 8517 | |
| 8518 | ipw_handle_data_packet(priv, rxb, |
| 8519 | &stats); |
| 8520 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8521 | break; |
| 8522 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8523 | break; |
| 8524 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8525 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8526 | case RX_HOST_NOTIFICATION_TYPE:{ |
| 8527 | IPW_DEBUG_RX |
| 8528 | ("Notification: subtype=%02X flags=%02X size=%d\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8529 | pkt->u.notification.subtype, |
| 8530 | pkt->u.notification.flags, |
Zhu Yi | 720eeb4 | 2006-12-05 14:41:40 +0800 | [diff] [blame] | 8531 | le16_to_cpu(pkt->u.notification.size)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8532 | ipw_rx_notification(priv, &pkt->u.notification); |
| 8533 | break; |
| 8534 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8535 | |
| 8536 | default: |
| 8537 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", |
| 8538 | pkt->header.message_type); |
| 8539 | break; |
| 8540 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8541 | |
| 8542 | /* For now we just don't re-use anything. We can tweak this |
| 8543 | * later to try and re-use notification packets and SKBs that |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8544 | * fail to Rx correctly */ |
| 8545 | if (rxb->skb != NULL) { |
| 8546 | dev_kfree_skb_any(rxb->skb); |
| 8547 | rxb->skb = NULL; |
| 8548 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8549 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8550 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8551 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8552 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8553 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8554 | i = (i + 1) % RX_QUEUE_SIZE; |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8555 | |
| 8556 | /* If there are a lot of unsued frames, restock the Rx queue |
| 8557 | * so the ucode won't assert */ |
| 8558 | if (fill_rx) { |
| 8559 | priv->rxq->read = i; |
| 8560 | ipw_rx_queue_replenish(priv); |
| 8561 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8562 | } |
| 8563 | |
| 8564 | /* Backtrack one entry */ |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 8565 | priv->rxq->read = i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8566 | ipw_rx_queue_restock(priv); |
| 8567 | } |
| 8568 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8569 | #define DEFAULT_RTS_THRESHOLD 2304U |
| 8570 | #define MIN_RTS_THRESHOLD 1U |
| 8571 | #define MAX_RTS_THRESHOLD 2304U |
| 8572 | #define DEFAULT_BEACON_INTERVAL 100U |
| 8573 | #define DEFAULT_SHORT_RETRY_LIMIT 7U |
| 8574 | #define DEFAULT_LONG_RETRY_LIMIT 4U |
| 8575 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8576 | /** |
| 8577 | * ipw_sw_reset |
| 8578 | * @option: options to control different reset behaviour |
| 8579 | * 0 = reset everything except the 'disable' module_param |
| 8580 | * 1 = reset everything and print out driver info (for probe only) |
| 8581 | * 2 = reset everything |
| 8582 | */ |
| 8583 | static int ipw_sw_reset(struct ipw_priv *priv, int option) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8584 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8585 | int band, modulation; |
| 8586 | int old_mode = priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8587 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8588 | /* Initialize module parameter values here */ |
| 8589 | priv->config = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8590 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8591 | /* We default to disabling the LED code as right now it causes |
| 8592 | * too many systems to lock up... */ |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8593 | if (!led_support) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8594 | priv->config |= CFG_NO_LED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8595 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8596 | if (associate) |
| 8597 | priv->config |= CFG_ASSOCIATE; |
| 8598 | else |
| 8599 | IPW_DEBUG_INFO("Auto associate disabled.\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8600 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8601 | if (auto_create) |
| 8602 | priv->config |= CFG_ADHOC_CREATE; |
| 8603 | else |
| 8604 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); |
| 8605 | |
Zhu Yi | 17ed081 | 2006-01-24 16:36:31 +0800 | [diff] [blame] | 8606 | priv->config &= ~CFG_STATIC_ESSID; |
| 8607 | priv->essid_len = 0; |
| 8608 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 8609 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8610 | if (disable && option) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8611 | priv->status |= STATUS_RF_KILL_SW; |
| 8612 | IPW_DEBUG_INFO("Radio disabled.\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8613 | } |
| 8614 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8615 | if (default_channel != 0) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8616 | priv->config |= CFG_STATIC_CHANNEL; |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8617 | priv->channel = default_channel; |
| 8618 | IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8619 | /* TODO: Validate that provided channel is in range */ |
| 8620 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8621 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8622 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
| 8623 | burst_duration_CCK, burst_duration_OFDM); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 8624 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8625 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 8626 | switch (network_mode) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8627 | case 1: |
| 8628 | priv->ieee->iw_mode = IW_MODE_ADHOC; |
| 8629 | priv->net_dev->type = ARPHRD_ETHER; |
| 8630 | |
| 8631 | break; |
| 8632 | #ifdef CONFIG_IPW2200_MONITOR |
| 8633 | case 2: |
| 8634 | priv->ieee->iw_mode = IW_MODE_MONITOR; |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8635 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8636 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8637 | #else |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8638 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8639 | #endif |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8640 | break; |
| 8641 | #endif |
| 8642 | default: |
| 8643 | case 0: |
| 8644 | priv->net_dev->type = ARPHRD_ETHER; |
| 8645 | priv->ieee->iw_mode = IW_MODE_INFRA; |
| 8646 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8647 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8648 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8649 | if (hwcrypto) { |
| 8650 | priv->ieee->host_encrypt = 0; |
| 8651 | priv->ieee->host_encrypt_msdu = 0; |
| 8652 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 8653 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8654 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8655 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8656 | |
Zhu Yi | e402c93 | 2005-08-05 17:20:40 +0800 | [diff] [blame] | 8657 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
| 8658 | priv->ieee->host_open_frag = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8659 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8660 | if ((priv->pci_dev->device == 0x4223) || |
| 8661 | (priv->pci_dev->device == 0x4224)) { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8662 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8663 | printk(KERN_INFO DRV_NAME |
| 8664 | ": Detected Intel PRO/Wireless 2915ABG Network " |
| 8665 | "Connection\n"); |
| 8666 | priv->ieee->abg_true = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8667 | band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND; |
| 8668 | modulation = LIBIPW_OFDM_MODULATION | |
| 8669 | LIBIPW_CCK_MODULATION; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8670 | priv->adapter = IPW_2915ABG; |
| 8671 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8672 | } else { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8673 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8674 | printk(KERN_INFO DRV_NAME |
| 8675 | ": Detected Intel PRO/Wireless 2200BG Network " |
| 8676 | "Connection\n"); |
| 8677 | |
| 8678 | priv->ieee->abg_true = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8679 | band = LIBIPW_24GHZ_BAND; |
| 8680 | modulation = LIBIPW_OFDM_MODULATION | |
| 8681 | LIBIPW_CCK_MODULATION; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8682 | priv->adapter = IPW_2200BG; |
| 8683 | priv->ieee->mode = IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8684 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8685 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8686 | priv->ieee->freq_band = band; |
| 8687 | priv->ieee->modulation = modulation; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8688 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8689 | priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8690 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8691 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8692 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8693 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8694 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8695 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; |
| 8696 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8697 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8698 | /* If power management is turned on, default to AC mode */ |
| 8699 | priv->power_mode = IPW_POWER_AC; |
| 8700 | priv->tx_power = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8701 | |
Zhu Yi | 0ece35b | 2005-08-05 17:26:51 +0800 | [diff] [blame] | 8702 | return old_mode == priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8703 | } |
| 8704 | |
| 8705 | /* |
| 8706 | * This file defines the Wireless Extension handlers. It does not |
| 8707 | * define any methods of hardware manipulation and relies on the |
| 8708 | * functions defined in ipw_main to provide the HW interaction. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8709 | * |
| 8710 | * The exception to this is the use of the ipw_get_ordinal() |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8711 | * function used to poll the hardware vs. making unecessary calls. |
| 8712 | * |
| 8713 | */ |
| 8714 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8715 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
| 8716 | { |
| 8717 | if (channel == 0) { |
| 8718 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); |
| 8719 | priv->config &= ~CFG_STATIC_CHANNEL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8720 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8721 | "parameters.\n"); |
| 8722 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8723 | return 0; |
| 8724 | } |
| 8725 | |
| 8726 | priv->config |= CFG_STATIC_CHANNEL; |
| 8727 | |
| 8728 | if (priv->channel == channel) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8729 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
| 8730 | channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8731 | return 0; |
| 8732 | } |
| 8733 | |
| 8734 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); |
| 8735 | priv->channel = channel; |
| 8736 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8737 | #ifdef CONFIG_IPW2200_MONITOR |
| 8738 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8739 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8740 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8741 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8742 | "channel change.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8743 | ipw_abort_scan(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8744 | } |
| 8745 | |
| 8746 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) |
| 8747 | udelay(10); |
| 8748 | |
| 8749 | if (priv->status & STATUS_SCANNING) |
| 8750 | IPW_DEBUG_SCAN("Still scanning...\n"); |
| 8751 | else |
| 8752 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", |
| 8753 | 1000 - i); |
| 8754 | |
| 8755 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8756 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8757 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 8758 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8759 | /* Network configuration changed -- force [re]association */ |
| 8760 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); |
| 8761 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8762 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8763 | |
| 8764 | return 0; |
| 8765 | } |
| 8766 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8767 | static int ipw_wx_set_freq(struct net_device *dev, |
| 8768 | struct iw_request_info *info, |
| 8769 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8770 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8771 | struct ipw_priv *priv = libipw_priv(dev); |
| 8772 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8773 | struct iw_freq *fwrq = &wrqu->freq; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8774 | int ret = 0, i; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8775 | u8 channel, flags; |
| 8776 | int band; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8777 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8778 | if (fwrq->m == 0) { |
| 8779 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8780 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8781 | ret = ipw_set_channel(priv, 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8782 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8783 | return ret; |
| 8784 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8785 | /* if setting by freq convert to channel */ |
| 8786 | if (fwrq->e == 1) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8787 | channel = libipw_freq_to_channel(priv->ieee, fwrq->m); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8788 | if (channel == 0) |
| 8789 | return -EINVAL; |
| 8790 | } else |
| 8791 | channel = fwrq->m; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8792 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8793 | if (!(band = libipw_is_valid_channel(priv->ieee, channel))) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8794 | return -EINVAL; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8795 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8796 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8797 | i = libipw_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8798 | if (i == -1) |
| 8799 | return -EINVAL; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8800 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8801 | flags = (band == LIBIPW_24GHZ_BAND) ? |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8802 | geo->bg[i].flags : geo->a[i].flags; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8803 | if (flags & LIBIPW_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8804 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
| 8805 | return -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8806 | } |
| 8807 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8808 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 8809 | IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8810 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8811 | ret = ipw_set_channel(priv, channel); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8812 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8813 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8814 | } |
| 8815 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8816 | static int ipw_wx_get_freq(struct net_device *dev, |
| 8817 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8818 | union iwreq_data *wrqu, char *extra) |
| 8819 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8820 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8821 | |
| 8822 | wrqu->freq.e = 0; |
| 8823 | |
| 8824 | /* If we are associated, trying to associate, or have a statically |
| 8825 | * configured CHANNEL then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8826 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8827 | if (priv->config & CFG_STATIC_CHANNEL || |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8828 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) { |
| 8829 | int i; |
| 8830 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8831 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8832 | BUG_ON(i == -1); |
| 8833 | wrqu->freq.e = 1; |
| 8834 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8835 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
| 8836 | case LIBIPW_52GHZ_BAND: |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8837 | wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000; |
| 8838 | break; |
| 8839 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8840 | case LIBIPW_24GHZ_BAND: |
Zhu Yi | c580f67 | 2006-08-21 11:37:01 +0800 | [diff] [blame] | 8841 | wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000; |
| 8842 | break; |
| 8843 | |
| 8844 | default: |
| 8845 | BUG(); |
| 8846 | } |
| 8847 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8848 | wrqu->freq.m = 0; |
| 8849 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8850 | mutex_unlock(&priv->mutex); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 8851 | IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8852 | return 0; |
| 8853 | } |
| 8854 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8855 | static int ipw_wx_set_mode(struct net_device *dev, |
| 8856 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8857 | union iwreq_data *wrqu, char *extra) |
| 8858 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8859 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8860 | int err = 0; |
| 8861 | |
| 8862 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); |
| 8863 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8864 | switch (wrqu->mode) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8865 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8866 | case IW_MODE_MONITOR: |
| 8867 | #endif |
| 8868 | case IW_MODE_ADHOC: |
| 8869 | case IW_MODE_INFRA: |
| 8870 | break; |
| 8871 | case IW_MODE_AUTO: |
| 8872 | wrqu->mode = IW_MODE_INFRA; |
| 8873 | break; |
| 8874 | default: |
| 8875 | return -EINVAL; |
| 8876 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8877 | if (wrqu->mode == priv->ieee->iw_mode) |
| 8878 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8879 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8880 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8881 | |
| 8882 | ipw_sw_reset(priv, 0); |
| 8883 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8884 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8885 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8886 | priv->net_dev->type = ARPHRD_ETHER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8887 | |
| 8888 | if (wrqu->mode == IW_MODE_MONITOR) |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 8889 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8890 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8891 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8892 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8893 | #endif |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8894 | #endif /* CONFIG_IPW2200_MONITOR */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8895 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8896 | /* Free the existing firmware and reset the fw_loaded |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 8897 | * flag so ipw_load() will bring in the new firmware */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8898 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8899 | |
| 8900 | priv->ieee->iw_mode = wrqu->mode; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8901 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8902 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8903 | mutex_unlock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8904 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8905 | } |
| 8906 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8907 | static int ipw_wx_get_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8908 | struct iw_request_info *info, |
| 8909 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8910 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8911 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8912 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8913 | wrqu->mode = priv->ieee->iw_mode; |
| 8914 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8915 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8916 | return 0; |
| 8917 | } |
| 8918 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8919 | /* Values are in microsecond */ |
| 8920 | static const s32 timeout_duration[] = { |
| 8921 | 350000, |
| 8922 | 250000, |
| 8923 | 75000, |
| 8924 | 37000, |
| 8925 | 25000, |
| 8926 | }; |
| 8927 | |
| 8928 | static const s32 period_duration[] = { |
| 8929 | 400000, |
| 8930 | 700000, |
| 8931 | 1000000, |
| 8932 | 1000000, |
| 8933 | 1000000 |
| 8934 | }; |
| 8935 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8936 | static int ipw_wx_get_range(struct net_device *dev, |
| 8937 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8938 | union iwreq_data *wrqu, char *extra) |
| 8939 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8940 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8941 | struct iw_range *range = (struct iw_range *)extra; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8942 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8943 | int i = 0, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8944 | |
| 8945 | wrqu->data.length = sizeof(*range); |
| 8946 | memset(range, 0, sizeof(*range)); |
| 8947 | |
| 8948 | /* 54Mbs == ~27 Mb/s real (802.11g) */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8949 | range->throughput = 27 * 1000 * 1000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8950 | |
| 8951 | range->max_qual.qual = 100; |
| 8952 | /* TODO: Find real max RSSI and stick here */ |
| 8953 | range->max_qual.level = 0; |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8954 | range->max_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8955 | range->max_qual.updated = 7; /* Updated all three */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8956 | |
| 8957 | range->avg_qual.qual = 70; |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8958 | /* TODO: Find real 'good' to 'bad' threshold value for RSSI */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8959 | range->avg_qual.level = 0; /* FIXME to real average level */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8960 | range->avg_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8961 | range->avg_qual.updated = 7; /* Updated all three */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8962 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8963 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8964 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8965 | for (i = 0; i < range->num_bitrates; i++) |
| 8966 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8967 | 500000; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8968 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8969 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
| 8970 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 8971 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 8972 | |
| 8973 | range->encoding_size[0] = 5; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8974 | range->encoding_size[1] = 13; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8975 | range->num_encoding_sizes = 2; |
| 8976 | range->max_encoding_tokens = WEP_KEYS; |
| 8977 | |
| 8978 | /* Set the Wireless Extension versions */ |
| 8979 | range->we_version_compiled = WIRELESS_EXT; |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8980 | range->we_version_source = 18; |
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 | i = 0; |
| 8983 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8984 | for (j = 0; j < geo->bg_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->bg[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->bg[j].channel; |
| 8990 | range->freq[i].m = geo->bg[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 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8994 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8995 | |
| 8996 | if (priv->ieee->mode & IEEE_A) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8997 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8998 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 8999 | (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY)) |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 9000 | continue; |
| 9001 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9002 | range->freq[i].i = geo->a[j].channel; |
| 9003 | range->freq[i].m = geo->a[j].freq * 100000; |
| 9004 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 9005 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9006 | } |
| 9007 | } |
| 9008 | |
| 9009 | range->num_channels = i; |
| 9010 | range->num_frequency = i; |
| 9011 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9012 | mutex_unlock(&priv->mutex); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 9013 | |
| 9014 | /* Event capability (kernel + driver) */ |
| 9015 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 9016 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
Zhu Yi | 07f02e4 | 2006-04-13 17:19:25 +0800 | [diff] [blame] | 9017 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | |
| 9018 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 9019 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9020 | |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 9021 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 9022 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 9023 | |
Dan Williams | 374fdfb | 2007-12-12 10:25:07 -0500 | [diff] [blame] | 9024 | range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE; |
| 9025 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9026 | IPW_DEBUG_WX("GET Range\n"); |
| 9027 | return 0; |
| 9028 | } |
| 9029 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9030 | static int ipw_wx_set_wap(struct net_device *dev, |
| 9031 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9032 | union iwreq_data *wrqu, char *extra) |
| 9033 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9034 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9035 | |
| 9036 | static const unsigned char any[] = { |
| 9037 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 9038 | }; |
| 9039 | static const unsigned char off[] = { |
| 9040 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 9041 | }; |
| 9042 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9043 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9044 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9045 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9046 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
| 9047 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 9048 | /* we disable mandatory BSSID association */ |
| 9049 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); |
| 9050 | priv->config &= ~CFG_STATIC_BSSID; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9051 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 9052 | "parameters.\n"); |
| 9053 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9054 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9055 | return 0; |
| 9056 | } |
| 9057 | |
| 9058 | priv->config |= CFG_STATIC_BSSID; |
| 9059 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 9060 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9061 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9062 | return 0; |
| 9063 | } |
| 9064 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 9065 | IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n", |
| 9066 | wrqu->ap_addr.sa_data); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9067 | |
| 9068 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); |
| 9069 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9070 | /* Network configuration changed -- force [re]association */ |
| 9071 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); |
| 9072 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9073 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9074 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9075 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9076 | return 0; |
| 9077 | } |
| 9078 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9079 | static int ipw_wx_get_wap(struct net_device *dev, |
| 9080 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9081 | union iwreq_data *wrqu, char *extra) |
| 9082 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9083 | struct ipw_priv *priv = libipw_priv(dev); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 9084 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9085 | /* If we are associated, trying to associate, or have a statically |
| 9086 | * configured BSSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9087 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9088 | if (priv->config & CFG_STATIC_BSSID || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9089 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 9090 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9091 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9092 | } else |
| 9093 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 9094 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 9095 | IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", |
| 9096 | wrqu->ap_addr.sa_data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9097 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9098 | return 0; |
| 9099 | } |
| 9100 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9101 | static int ipw_wx_set_essid(struct net_device *dev, |
| 9102 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9103 | union iwreq_data *wrqu, char *extra) |
| 9104 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9105 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 9106 | int length; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9107 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9108 | |
Zhu Yi | ab644b0 | 2006-08-21 11:37:13 +0800 | [diff] [blame] | 9109 | mutex_lock(&priv->mutex); |
| 9110 | |
| 9111 | if (!wrqu->essid.flags) |
| 9112 | { |
| 9113 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); |
| 9114 | ipw_disassociate(priv); |
| 9115 | priv->config &= ~CFG_STATIC_ESSID; |
| 9116 | ipw_associate(priv); |
| 9117 | mutex_unlock(&priv->mutex); |
| 9118 | return 0; |
| 9119 | } |
| 9120 | |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9121 | length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9122 | |
| 9123 | priv->config |= CFG_STATIC_ESSID; |
| 9124 | |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9125 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length) |
| 9126 | && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9127 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9128 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9129 | return 0; |
| 9130 | } |
| 9131 | |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9132 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", |
| 9133 | print_ssid(ssid, extra, length), length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9134 | |
| 9135 | priv->essid_len = length; |
Zhu Yi | a9f0d42 | 2006-08-21 11:37:26 +0800 | [diff] [blame] | 9136 | memcpy(priv->essid, extra, priv->essid_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9137 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9138 | /* Network configuration changed -- force [re]association */ |
| 9139 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); |
| 9140 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9141 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9142 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9143 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9144 | return 0; |
| 9145 | } |
| 9146 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9147 | static int ipw_wx_get_essid(struct net_device *dev, |
| 9148 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9149 | union iwreq_data *wrqu, char *extra) |
| 9150 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9151 | struct ipw_priv *priv = libipw_priv(dev); |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9152 | DECLARE_SSID_BUF(ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9153 | |
| 9154 | /* If we are associated, trying to associate, or have a statically |
| 9155 | * configured ESSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9156 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9157 | if (priv->config & CFG_STATIC_ESSID || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9158 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 9159 | IPW_DEBUG_WX("Getting essid: '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 9160 | print_ssid(ssid, priv->essid, priv->essid_len)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9161 | memcpy(extra, priv->essid, priv->essid_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9162 | wrqu->essid.length = priv->essid_len; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9163 | wrqu->essid.flags = 1; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9164 | } else { |
| 9165 | IPW_DEBUG_WX("Getting essid: ANY\n"); |
| 9166 | wrqu->essid.length = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9167 | wrqu->essid.flags = 0; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9168 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9169 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9170 | return 0; |
| 9171 | } |
| 9172 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9173 | static int ipw_wx_set_nick(struct net_device *dev, |
| 9174 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9175 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9176 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9177 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9178 | |
| 9179 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); |
| 9180 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) |
| 9181 | return -E2BIG; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9182 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9183 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9184 | memset(priv->nick, 0, sizeof(priv->nick)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9185 | memcpy(priv->nick, extra, wrqu->data.length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9186 | IPW_DEBUG_TRACE("<<\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9187 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9188 | return 0; |
| 9189 | |
| 9190 | } |
| 9191 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9192 | static int ipw_wx_get_nick(struct net_device *dev, |
| 9193 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9194 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9195 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9196 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9197 | IPW_DEBUG_WX("Getting nick\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9198 | mutex_lock(&priv->mutex); |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9199 | wrqu->data.length = strlen(priv->nick); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9200 | memcpy(extra, priv->nick, wrqu->data.length); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9201 | wrqu->data.flags = 1; /* active */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9202 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9203 | return 0; |
| 9204 | } |
| 9205 | |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9206 | static int ipw_wx_set_sens(struct net_device *dev, |
| 9207 | struct iw_request_info *info, |
| 9208 | union iwreq_data *wrqu, char *extra) |
| 9209 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9210 | struct ipw_priv *priv = libipw_priv(dev); |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9211 | int err = 0; |
| 9212 | |
| 9213 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); |
| 9214 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); |
| 9215 | mutex_lock(&priv->mutex); |
| 9216 | |
| 9217 | if (wrqu->sens.fixed == 0) |
| 9218 | { |
| 9219 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
| 9220 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 9221 | goto out; |
| 9222 | } |
| 9223 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || |
| 9224 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { |
| 9225 | err = -EINVAL; |
| 9226 | goto out; |
| 9227 | } |
| 9228 | |
| 9229 | priv->roaming_threshold = wrqu->sens.value; |
| 9230 | priv->disassociate_threshold = 3*wrqu->sens.value; |
| 9231 | out: |
| 9232 | mutex_unlock(&priv->mutex); |
| 9233 | return err; |
| 9234 | } |
| 9235 | |
| 9236 | static int ipw_wx_get_sens(struct net_device *dev, |
| 9237 | struct iw_request_info *info, |
| 9238 | union iwreq_data *wrqu, char *extra) |
| 9239 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9240 | struct ipw_priv *priv = libipw_priv(dev); |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9241 | mutex_lock(&priv->mutex); |
| 9242 | wrqu->sens.fixed = 1; |
| 9243 | wrqu->sens.value = priv->roaming_threshold; |
| 9244 | mutex_unlock(&priv->mutex); |
| 9245 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 9246 | IPW_DEBUG_WX("GET roaming threshold -> %s %d\n", |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9247 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
| 9248 | |
| 9249 | return 0; |
| 9250 | } |
| 9251 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9252 | static int ipw_wx_set_rate(struct net_device *dev, |
| 9253 | struct iw_request_info *info, |
| 9254 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9255 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9256 | /* TODO: We should use semaphores or locks for access to priv */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9257 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9258 | u32 target_rate = wrqu->bitrate.value; |
| 9259 | u32 fixed, mask; |
| 9260 | |
| 9261 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ |
| 9262 | /* value = X, fixed = 1 means only rate X */ |
| 9263 | /* value = X, fixed = 0 means all rates lower equal X */ |
| 9264 | |
| 9265 | if (target_rate == -1) { |
| 9266 | fixed = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9267 | mask = LIBIPW_DEFAULT_RATES_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9268 | /* Now we should reassociate */ |
| 9269 | goto apply; |
| 9270 | } |
| 9271 | |
| 9272 | mask = 0; |
| 9273 | fixed = wrqu->bitrate.fixed; |
| 9274 | |
| 9275 | if (target_rate == 1000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9276 | mask |= LIBIPW_CCK_RATE_1MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9277 | if (target_rate == 1000000) |
| 9278 | goto apply; |
| 9279 | |
| 9280 | if (target_rate == 2000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9281 | mask |= LIBIPW_CCK_RATE_2MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9282 | if (target_rate == 2000000) |
| 9283 | goto apply; |
| 9284 | |
| 9285 | if (target_rate == 5500000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9286 | mask |= LIBIPW_CCK_RATE_5MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9287 | if (target_rate == 5500000) |
| 9288 | goto apply; |
| 9289 | |
| 9290 | if (target_rate == 6000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9291 | mask |= LIBIPW_OFDM_RATE_6MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9292 | if (target_rate == 6000000) |
| 9293 | goto apply; |
| 9294 | |
| 9295 | if (target_rate == 9000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9296 | mask |= LIBIPW_OFDM_RATE_9MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9297 | if (target_rate == 9000000) |
| 9298 | goto apply; |
| 9299 | |
| 9300 | if (target_rate == 11000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9301 | mask |= LIBIPW_CCK_RATE_11MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9302 | if (target_rate == 11000000) |
| 9303 | goto apply; |
| 9304 | |
| 9305 | if (target_rate == 12000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9306 | mask |= LIBIPW_OFDM_RATE_12MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9307 | if (target_rate == 12000000) |
| 9308 | goto apply; |
| 9309 | |
| 9310 | if (target_rate == 18000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9311 | mask |= LIBIPW_OFDM_RATE_18MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9312 | if (target_rate == 18000000) |
| 9313 | goto apply; |
| 9314 | |
| 9315 | if (target_rate == 24000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9316 | mask |= LIBIPW_OFDM_RATE_24MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9317 | if (target_rate == 24000000) |
| 9318 | goto apply; |
| 9319 | |
| 9320 | if (target_rate == 36000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9321 | mask |= LIBIPW_OFDM_RATE_36MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9322 | if (target_rate == 36000000) |
| 9323 | goto apply; |
| 9324 | |
| 9325 | if (target_rate == 48000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9326 | mask |= LIBIPW_OFDM_RATE_48MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9327 | if (target_rate == 48000000) |
| 9328 | goto apply; |
| 9329 | |
| 9330 | if (target_rate == 54000000 || !fixed) |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9331 | mask |= LIBIPW_OFDM_RATE_54MB_MASK; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9332 | if (target_rate == 54000000) |
| 9333 | goto apply; |
| 9334 | |
| 9335 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); |
| 9336 | return -EINVAL; |
| 9337 | |
| 9338 | apply: |
| 9339 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", |
| 9340 | mask, fixed ? "fixed" : "sub-rates"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9341 | mutex_lock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9342 | if (mask == LIBIPW_DEFAULT_RATES_MASK) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9343 | priv->config &= ~CFG_FIXED_RATE; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9344 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
| 9345 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9346 | priv->config |= CFG_FIXED_RATE; |
| 9347 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9348 | if (priv->rates_mask == mask) { |
| 9349 | IPW_DEBUG_WX("Mask set to current mask.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9350 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9351 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9352 | } |
| 9353 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9354 | priv->rates_mask = mask; |
| 9355 | |
| 9356 | /* Network configuration changed -- force [re]association */ |
| 9357 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); |
| 9358 | if (!ipw_disassociate(priv)) |
| 9359 | ipw_associate(priv); |
| 9360 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9361 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9362 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9363 | } |
| 9364 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9365 | static int ipw_wx_get_rate(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); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9371 | wrqu->bitrate.value = priv->last_rate; |
Zhu Yi | 455936c | 2006-04-13 17:20:05 +0800 | [diff] [blame] | 9372 | wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9373 | mutex_unlock(&priv->mutex); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 9374 | IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9375 | return 0; |
| 9376 | } |
| 9377 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9378 | static int ipw_wx_set_rts(struct net_device *dev, |
| 9379 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9380 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9381 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9382 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9383 | mutex_lock(&priv->mutex); |
Zhu Yi | ea8862d | 2007-01-11 17:32:54 +0800 | [diff] [blame] | 9384 | if (wrqu->rts.disabled || !wrqu->rts.fixed) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9385 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 9386 | else { |
| 9387 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9388 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9389 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9390 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9391 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9392 | priv->rts_threshold = wrqu->rts.value; |
| 9393 | } |
| 9394 | |
| 9395 | ipw_send_rts_threshold(priv, priv->rts_threshold); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9396 | mutex_unlock(&priv->mutex); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 9397 | IPW_DEBUG_WX("SET RTS Threshold -> %d\n", priv->rts_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9398 | return 0; |
| 9399 | } |
| 9400 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9401 | static int ipw_wx_get_rts(struct net_device *dev, |
| 9402 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9403 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9404 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9405 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9406 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9407 | wrqu->rts.value = priv->rts_threshold; |
| 9408 | wrqu->rts.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9409 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9410 | mutex_unlock(&priv->mutex); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 9411 | IPW_DEBUG_WX("GET RTS Threshold -> %d\n", wrqu->rts.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9412 | return 0; |
| 9413 | } |
| 9414 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9415 | static int ipw_wx_set_txpow(struct net_device *dev, |
| 9416 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9417 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9418 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9419 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9420 | int err = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9421 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9422 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9423 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9424 | err = -EINPROGRESS; |
| 9425 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9426 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9427 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9428 | if (!wrqu->power.fixed) |
| 9429 | wrqu->power.value = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9430 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9431 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9432 | err = -EINVAL; |
| 9433 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9434 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9435 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9436 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9437 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9438 | err = -EINVAL; |
| 9439 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9440 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9441 | |
| 9442 | priv->tx_power = wrqu->power.value; |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9443 | err = ipw_set_tx_power(priv); |
| 9444 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9445 | mutex_unlock(&priv->mutex); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 9446 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9447 | } |
| 9448 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9449 | static int ipw_wx_get_txpow(struct net_device *dev, |
| 9450 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9451 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9452 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9453 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9454 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9455 | wrqu->power.value = priv->tx_power; |
| 9456 | wrqu->power.fixed = 1; |
| 9457 | wrqu->power.flags = IW_TXPOW_DBM; |
| 9458 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9459 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9460 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 9461 | IPW_DEBUG_WX("GET TX Power -> %s %d\n", |
Zhu Yi | 22501c8 | 2005-08-11 10:49:17 +0800 | [diff] [blame] | 9462 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9463 | |
| 9464 | return 0; |
| 9465 | } |
| 9466 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9467 | static int ipw_wx_set_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9468 | struct iw_request_info *info, |
| 9469 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9470 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9471 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9472 | mutex_lock(&priv->mutex); |
Zhu Yi | ea8862d | 2007-01-11 17:32:54 +0800 | [diff] [blame] | 9473 | if (wrqu->frag.disabled || !wrqu->frag.fixed) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9474 | priv->ieee->fts = DEFAULT_FTS; |
| 9475 | else { |
| 9476 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9477 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9478 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9479 | return -EINVAL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9480 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9481 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9482 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
| 9483 | } |
| 9484 | |
| 9485 | ipw_send_frag_threshold(priv, wrqu->frag.value); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9486 | mutex_unlock(&priv->mutex); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 9487 | IPW_DEBUG_WX("SET Frag Threshold -> %d\n", wrqu->frag.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9488 | return 0; |
| 9489 | } |
| 9490 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9491 | static int ipw_wx_get_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9492 | struct iw_request_info *info, |
| 9493 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9494 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9495 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9496 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9497 | wrqu->frag.value = priv->ieee->fts; |
| 9498 | wrqu->frag.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9499 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9500 | mutex_unlock(&priv->mutex); |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 9501 | IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9502 | |
| 9503 | return 0; |
| 9504 | } |
| 9505 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9506 | static int ipw_wx_set_retry(struct net_device *dev, |
| 9507 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9508 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9509 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9510 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9511 | |
| 9512 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) |
| 9513 | return -EINVAL; |
| 9514 | |
| 9515 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) |
| 9516 | return 0; |
| 9517 | |
Zhu Yi | d5f7ac2 | 2006-08-21 11:38:17 +0800 | [diff] [blame] | 9518 | if (wrqu->retry.value < 0 || wrqu->retry.value >= 255) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9519 | return -EINVAL; |
| 9520 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9521 | mutex_lock(&priv->mutex); |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9522 | if (wrqu->retry.flags & IW_RETRY_SHORT) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9523 | priv->short_retry_limit = (u8) wrqu->retry.value; |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9524 | else if (wrqu->retry.flags & IW_RETRY_LONG) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9525 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9526 | else { |
| 9527 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 9528 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9529 | } |
| 9530 | |
| 9531 | ipw_send_retry_limit(priv, priv->short_retry_limit, |
| 9532 | priv->long_retry_limit); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9533 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9534 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
| 9535 | priv->short_retry_limit, priv->long_retry_limit); |
| 9536 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9537 | } |
| 9538 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9539 | static int ipw_wx_get_retry(struct net_device *dev, |
| 9540 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9541 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9542 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9543 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9544 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9545 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9546 | wrqu->retry.disabled = 0; |
| 9547 | |
| 9548 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9549 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9550 | return -EINVAL; |
| 9551 | } |
| 9552 | |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9553 | if (wrqu->retry.flags & IW_RETRY_LONG) { |
| 9554 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9555 | wrqu->retry.value = priv->long_retry_limit; |
Jean Tourrilhes | 919ee6d | 2006-08-29 18:01:40 -0700 | [diff] [blame] | 9556 | } else if (wrqu->retry.flags & IW_RETRY_SHORT) { |
| 9557 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9558 | wrqu->retry.value = priv->short_retry_limit; |
| 9559 | } else { |
| 9560 | wrqu->retry.flags = IW_RETRY_LIMIT; |
| 9561 | wrqu->retry.value = priv->short_retry_limit; |
| 9562 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9563 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9564 | |
Frans Pop | 9fd1ea4 | 2010-03-24 19:46:31 +0100 | [diff] [blame] | 9565 | IPW_DEBUG_WX("GET retry -> %d\n", wrqu->retry.value); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9566 | |
| 9567 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9568 | } |
| 9569 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9570 | static int ipw_wx_set_scan(struct net_device *dev, |
| 9571 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9572 | union iwreq_data *wrqu, char *extra) |
| 9573 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9574 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9575 | struct iw_scan_req *req = (struct iw_scan_req *)extra; |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9576 | struct delayed_work *work = NULL; |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9577 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9578 | mutex_lock(&priv->mutex); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9579 | |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9580 | priv->user_requested_scan = 1; |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 9581 | |
Zhu Yi | 094c4d2 | 2006-08-21 11:39:03 +0800 | [diff] [blame] | 9582 | if (wrqu->data.length == sizeof(struct iw_scan_req)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9583 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9584 | int len = min((int)req->essid_len, |
| 9585 | (int)sizeof(priv->direct_scan_ssid)); |
| 9586 | memcpy(priv->direct_scan_ssid, req->essid, len); |
| 9587 | priv->direct_scan_ssid_len = len; |
| 9588 | work = &priv->request_direct_scan; |
| 9589 | } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { |
| 9590 | work = &priv->request_passive_scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9591 | } |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9592 | } else { |
| 9593 | /* Normal active broadcast scan */ |
| 9594 | work = &priv->request_scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9595 | } |
James Ketrenos | 8935f39 | 2005-10-05 15:59:08 -0500 | [diff] [blame] | 9596 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9597 | mutex_unlock(&priv->mutex); |
| 9598 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9599 | IPW_DEBUG_WX("Start scan\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9600 | |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 9601 | queue_delayed_work(priv->workqueue, work, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9602 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9603 | return 0; |
| 9604 | } |
| 9605 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9606 | static int ipw_wx_get_scan(struct net_device *dev, |
| 9607 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9608 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9609 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9610 | struct ipw_priv *priv = libipw_priv(dev); |
| 9611 | return libipw_wx_get_scan(priv->ieee, info, wrqu, extra); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9612 | } |
| 9613 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9614 | static int ipw_wx_set_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9615 | struct iw_request_info *info, |
| 9616 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9617 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9618 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9619 | int ret; |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9620 | u32 cap = priv->capability; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9621 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9622 | mutex_lock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9623 | ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9624 | |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9625 | /* In IBSS mode, we need to notify the firmware to update |
| 9626 | * the beacon info after we changed the capability. */ |
| 9627 | if (cap != priv->capability && |
| 9628 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 9629 | priv->status & STATUS_ASSOCIATED) |
| 9630 | ipw_disassociate(priv); |
| 9631 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9632 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9633 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9634 | } |
| 9635 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9636 | static int ipw_wx_get_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9637 | struct iw_request_info *info, |
| 9638 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9639 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9640 | struct ipw_priv *priv = libipw_priv(dev); |
| 9641 | return libipw_wx_get_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9642 | } |
| 9643 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9644 | static int ipw_wx_set_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9645 | struct iw_request_info *info, |
| 9646 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9647 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9648 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9649 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9650 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9651 | if (wrqu->power.disabled) { |
| 9652 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); |
| 9653 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); |
| 9654 | if (err) { |
| 9655 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9656 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9657 | return err; |
| 9658 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9659 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9660 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9661 | return 0; |
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 | |
| 9664 | switch (wrqu->power.flags & IW_POWER_MODE) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9665 | case IW_POWER_ON: /* If not specified */ |
| 9666 | case IW_POWER_MODE: /* If set all mask */ |
Jean Delvare | c03983a | 2007-10-19 23:22:55 +0200 | [diff] [blame] | 9667 | case IW_POWER_ALL_R: /* If explicitly state all */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9668 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9669 | default: /* Otherwise we don't support it */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9670 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
| 9671 | wrqu->power.flags); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9672 | mutex_unlock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9673 | return -EOPNOTSUPP; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9674 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9675 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9676 | /* If the user hasn't specified a power management mode yet, default |
| 9677 | * to BATTERY */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9678 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9679 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9680 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9681 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9682 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9683 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
| 9684 | if (err) { |
| 9685 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9686 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9687 | return err; |
| 9688 | } |
| 9689 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9690 | 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] | 9691 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9692 | return 0; |
| 9693 | } |
| 9694 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9695 | static int ipw_wx_get_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9696 | struct iw_request_info *info, |
| 9697 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9698 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9699 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9700 | mutex_lock(&priv->mutex); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9701 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9702 | wrqu->power.disabled = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9703 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9704 | wrqu->power.disabled = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9705 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9706 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9707 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9708 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9709 | return 0; |
| 9710 | } |
| 9711 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9712 | static int ipw_wx_set_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9713 | struct iw_request_info *info, |
| 9714 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9715 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9716 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9717 | int mode = *(int *)extra; |
| 9718 | int err; |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9719 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9720 | mutex_lock(&priv->mutex); |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9721 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9722 | mode = IPW_POWER_AC; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9723 | |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9724 | if (IPW_POWER_LEVEL(priv->power_mode) != mode) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9725 | err = ipw_send_power_mode(priv, mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9726 | if (err) { |
| 9727 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9728 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9729 | return err; |
| 9730 | } |
Zhu Yi | 4e157f0 | 2007-07-12 16:09:32 +0800 | [diff] [blame] | 9731 | priv->power_mode = IPW_POWER_ENABLED | mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9732 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9733 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9734 | return 0; |
| 9735 | } |
| 9736 | |
| 9737 | #define MAX_WX_STRING 80 |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9738 | static int ipw_wx_get_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9739 | struct iw_request_info *info, |
| 9740 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9741 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9742 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9743 | int level = IPW_POWER_LEVEL(priv->power_mode); |
| 9744 | char *p = extra; |
| 9745 | |
| 9746 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); |
| 9747 | |
| 9748 | switch (level) { |
| 9749 | case IPW_POWER_AC: |
| 9750 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); |
| 9751 | break; |
| 9752 | case IPW_POWER_BATTERY: |
| 9753 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); |
| 9754 | break; |
| 9755 | default: |
| 9756 | p += snprintf(p, MAX_WX_STRING - (p - extra), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9757 | "(Timeout %dms, Period %dms)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9758 | timeout_duration[level - 1] / 1000, |
| 9759 | period_duration[level - 1] / 1000); |
| 9760 | } |
| 9761 | |
| 9762 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9763 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9764 | |
| 9765 | wrqu->data.length = p - extra + 1; |
| 9766 | |
| 9767 | return 0; |
| 9768 | } |
| 9769 | |
| 9770 | static int ipw_wx_set_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9771 | struct iw_request_info *info, |
| 9772 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9773 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9774 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9775 | int mode = *(int *)extra; |
| 9776 | u8 band = 0, modulation = 0; |
| 9777 | |
| 9778 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9779 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9780 | return -EINVAL; |
| 9781 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9782 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9783 | if (priv->adapter == IPW_2915ABG) { |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9784 | priv->ieee->abg_true = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9785 | if (mode & IEEE_A) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9786 | band |= LIBIPW_52GHZ_BAND; |
| 9787 | modulation |= LIBIPW_OFDM_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9788 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9789 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9790 | } else { |
| 9791 | if (mode & IEEE_A) { |
| 9792 | IPW_WARNING("Attempt to set 2200BG into " |
| 9793 | "802.11a mode\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9794 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9795 | return -EINVAL; |
| 9796 | } |
| 9797 | |
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 | |
| 9801 | if (mode & IEEE_B) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9802 | band |= LIBIPW_24GHZ_BAND; |
| 9803 | modulation |= LIBIPW_CCK_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9804 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9805 | priv->ieee->abg_true = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9806 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9807 | if (mode & IEEE_G) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9808 | band |= LIBIPW_24GHZ_BAND; |
| 9809 | modulation |= LIBIPW_OFDM_MODULATION; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9810 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9811 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9812 | |
| 9813 | priv->ieee->mode = mode; |
| 9814 | priv->ieee->freq_band = band; |
| 9815 | priv->ieee->modulation = modulation; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9816 | init_supported_rates(priv, &priv->rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9817 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9818 | /* Network configuration changed -- force [re]association */ |
| 9819 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); |
| 9820 | if (!ipw_disassociate(priv)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9821 | ipw_send_supported_rates(priv, &priv->rates); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9822 | ipw_associate(priv); |
| 9823 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9824 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9825 | /* Update the band LEDs */ |
| 9826 | ipw_led_band_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9827 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9828 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9829 | mode & IEEE_A ? 'a' : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9830 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9831 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9832 | return 0; |
| 9833 | } |
| 9834 | |
| 9835 | static int ipw_wx_get_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9836 | struct iw_request_info *info, |
| 9837 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9838 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9839 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9840 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9841 | switch (priv->ieee->mode) { |
| 9842 | case IEEE_A: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9843 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
| 9844 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9845 | case IEEE_B: |
| 9846 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); |
| 9847 | break; |
| 9848 | case IEEE_A | IEEE_B: |
| 9849 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); |
| 9850 | break; |
| 9851 | case IEEE_G: |
| 9852 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); |
| 9853 | break; |
| 9854 | case IEEE_A | IEEE_G: |
| 9855 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); |
| 9856 | break; |
| 9857 | case IEEE_B | IEEE_G: |
| 9858 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); |
| 9859 | break; |
| 9860 | case IEEE_A | IEEE_B | IEEE_G: |
| 9861 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); |
| 9862 | break; |
| 9863 | default: |
| 9864 | strncpy(extra, "unknown", MAX_WX_STRING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9865 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9866 | } |
| 9867 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9868 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
| 9869 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9870 | wrqu->data.length = strlen(extra) + 1; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9871 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9872 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9873 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9874 | } |
| 9875 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9876 | static int ipw_wx_set_preamble(struct net_device *dev, |
| 9877 | struct iw_request_info *info, |
| 9878 | union iwreq_data *wrqu, char *extra) |
| 9879 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9880 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9881 | int mode = *(int *)extra; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9882 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9883 | /* Switching from SHORT -> LONG requires a disassociation */ |
| 9884 | if (mode == 1) { |
| 9885 | if (!(priv->config & CFG_PREAMBLE_LONG)) { |
| 9886 | priv->config |= CFG_PREAMBLE_LONG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9887 | |
| 9888 | /* Network configuration changed -- force [re]association */ |
| 9889 | IPW_DEBUG_ASSOC |
| 9890 | ("[re]association triggered due to preamble change.\n"); |
| 9891 | if (!ipw_disassociate(priv)) |
| 9892 | ipw_associate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9893 | } |
| 9894 | goto done; |
| 9895 | } |
| 9896 | |
| 9897 | if (mode == 0) { |
| 9898 | priv->config &= ~CFG_PREAMBLE_LONG; |
| 9899 | goto done; |
| 9900 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9901 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9902 | return -EINVAL; |
| 9903 | |
| 9904 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9905 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9906 | return 0; |
| 9907 | } |
| 9908 | |
| 9909 | static int ipw_wx_get_preamble(struct net_device *dev, |
| 9910 | struct iw_request_info *info, |
| 9911 | union iwreq_data *wrqu, char *extra) |
| 9912 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9913 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9914 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9915 | if (priv->config & CFG_PREAMBLE_LONG) |
| 9916 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); |
| 9917 | else |
| 9918 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9919 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9920 | return 0; |
| 9921 | } |
| 9922 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9923 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9924 | static int ipw_wx_set_monitor(struct net_device *dev, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9925 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9926 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9927 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9928 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9929 | int *parms = (int *)extra; |
| 9930 | int enable = (parms[0] > 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9931 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9932 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9933 | if (enable) { |
| 9934 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 459d408 | 2006-04-13 17:21:00 +0800 | [diff] [blame] | 9935 | #ifdef CONFIG_IPW2200_RADIOTAP |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9936 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 9937 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9938 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9939 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9940 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9941 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9942 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9943 | ipw_set_channel(priv, parms[1]); |
| 9944 | } else { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9945 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9946 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9947 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9948 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9949 | priv->net_dev->type = ARPHRD_ETHER; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9950 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9951 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9952 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9953 | return 0; |
| 9954 | } |
| 9955 | |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 9956 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9957 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9958 | static int ipw_wx_reset(struct net_device *dev, |
| 9959 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9960 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9961 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9962 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9963 | IPW_DEBUG_WX("RESET\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9964 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9965 | return 0; |
| 9966 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9967 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9968 | static int ipw_wx_sw_reset(struct net_device *dev, |
| 9969 | struct iw_request_info *info, |
| 9970 | union iwreq_data *wrqu, char *extra) |
| 9971 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9972 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9973 | union iwreq_data wrqu_sec = { |
| 9974 | .encoding = { |
| 9975 | .flags = IW_ENCODE_DISABLED, |
| 9976 | }, |
| 9977 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9978 | int ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9979 | |
| 9980 | IPW_DEBUG_WX("SW_RESET\n"); |
| 9981 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9982 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9983 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 9984 | ret = ipw_sw_reset(priv, 2); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9985 | if (!ret) { |
| 9986 | free_firmware(); |
| 9987 | ipw_adapter_restart(priv); |
| 9988 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9989 | |
| 9990 | /* The SW reset bit might have been toggled on by the 'disable' |
| 9991 | * module parameter, so take appropriate action */ |
| 9992 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); |
| 9993 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9994 | mutex_unlock(&priv->mutex); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 9995 | libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9996 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9997 | |
| 9998 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 9999 | /* Configuration likely changed -- force [re]association */ |
| 10000 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " |
| 10001 | "reset.\n"); |
| 10002 | if (!ipw_disassociate(priv)) |
| 10003 | ipw_associate(priv); |
| 10004 | } |
| 10005 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10006 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10007 | |
| 10008 | return 0; |
| 10009 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10010 | |
| 10011 | /* Rebase the WE IOCTLs to zero for the handler array */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10012 | static iw_handler ipw_wx_handlers[] = { |
Joe Perches | 56b632e | 2010-03-18 18:29:38 -0700 | [diff] [blame] | 10013 | IW_HANDLER(SIOCGIWNAME, (iw_handler)cfg80211_wext_giwname), |
| 10014 | IW_HANDLER(SIOCSIWFREQ, ipw_wx_set_freq), |
| 10015 | IW_HANDLER(SIOCGIWFREQ, ipw_wx_get_freq), |
| 10016 | IW_HANDLER(SIOCSIWMODE, ipw_wx_set_mode), |
| 10017 | IW_HANDLER(SIOCGIWMODE, ipw_wx_get_mode), |
| 10018 | IW_HANDLER(SIOCSIWSENS, ipw_wx_set_sens), |
| 10019 | IW_HANDLER(SIOCGIWSENS, ipw_wx_get_sens), |
| 10020 | IW_HANDLER(SIOCGIWRANGE, ipw_wx_get_range), |
| 10021 | IW_HANDLER(SIOCSIWAP, ipw_wx_set_wap), |
| 10022 | IW_HANDLER(SIOCGIWAP, ipw_wx_get_wap), |
| 10023 | IW_HANDLER(SIOCSIWSCAN, ipw_wx_set_scan), |
| 10024 | IW_HANDLER(SIOCGIWSCAN, ipw_wx_get_scan), |
| 10025 | IW_HANDLER(SIOCSIWESSID, ipw_wx_set_essid), |
| 10026 | IW_HANDLER(SIOCGIWESSID, ipw_wx_get_essid), |
| 10027 | IW_HANDLER(SIOCSIWNICKN, ipw_wx_set_nick), |
| 10028 | IW_HANDLER(SIOCGIWNICKN, ipw_wx_get_nick), |
| 10029 | IW_HANDLER(SIOCSIWRATE, ipw_wx_set_rate), |
| 10030 | IW_HANDLER(SIOCGIWRATE, ipw_wx_get_rate), |
| 10031 | IW_HANDLER(SIOCSIWRTS, ipw_wx_set_rts), |
| 10032 | IW_HANDLER(SIOCGIWRTS, ipw_wx_get_rts), |
| 10033 | IW_HANDLER(SIOCSIWFRAG, ipw_wx_set_frag), |
| 10034 | IW_HANDLER(SIOCGIWFRAG, ipw_wx_get_frag), |
| 10035 | IW_HANDLER(SIOCSIWTXPOW, ipw_wx_set_txpow), |
| 10036 | IW_HANDLER(SIOCGIWTXPOW, ipw_wx_get_txpow), |
| 10037 | IW_HANDLER(SIOCSIWRETRY, ipw_wx_set_retry), |
| 10038 | IW_HANDLER(SIOCGIWRETRY, ipw_wx_get_retry), |
| 10039 | IW_HANDLER(SIOCSIWENCODE, ipw_wx_set_encode), |
| 10040 | IW_HANDLER(SIOCGIWENCODE, ipw_wx_get_encode), |
| 10041 | IW_HANDLER(SIOCSIWPOWER, ipw_wx_set_power), |
| 10042 | IW_HANDLER(SIOCGIWPOWER, ipw_wx_get_power), |
| 10043 | IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy), |
| 10044 | IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy), |
| 10045 | IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy), |
| 10046 | IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy), |
| 10047 | IW_HANDLER(SIOCSIWGENIE, ipw_wx_set_genie), |
| 10048 | IW_HANDLER(SIOCGIWGENIE, ipw_wx_get_genie), |
| 10049 | IW_HANDLER(SIOCSIWMLME, ipw_wx_set_mlme), |
| 10050 | IW_HANDLER(SIOCSIWAUTH, ipw_wx_set_auth), |
| 10051 | IW_HANDLER(SIOCGIWAUTH, ipw_wx_get_auth), |
| 10052 | IW_HANDLER(SIOCSIWENCODEEXT, ipw_wx_set_encodeext), |
| 10053 | IW_HANDLER(SIOCGIWENCODEEXT, ipw_wx_get_encodeext), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10054 | }; |
| 10055 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10056 | enum { |
| 10057 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, |
| 10058 | IPW_PRIV_GET_POWER, |
| 10059 | IPW_PRIV_SET_MODE, |
| 10060 | IPW_PRIV_GET_MODE, |
| 10061 | IPW_PRIV_SET_PREAMBLE, |
| 10062 | IPW_PRIV_GET_PREAMBLE, |
| 10063 | IPW_PRIV_RESET, |
| 10064 | IPW_PRIV_SW_RESET, |
| 10065 | #ifdef CONFIG_IPW2200_MONITOR |
| 10066 | IPW_PRIV_SET_MONITOR, |
| 10067 | #endif |
| 10068 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10069 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10070 | static struct iw_priv_args ipw_priv_args[] = { |
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_SET_POWER, |
| 10073 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10074 | .name = "set_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10075 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10076 | .cmd = IPW_PRIV_GET_POWER, |
| 10077 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 10078 | .name = "get_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10079 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10080 | .cmd = IPW_PRIV_SET_MODE, |
| 10081 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10082 | .name = "set_mode"}, |
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 | .cmd = IPW_PRIV_GET_MODE, |
| 10085 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 10086 | .name = "get_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10087 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10088 | .cmd = IPW_PRIV_SET_PREAMBLE, |
| 10089 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 10090 | .name = "set_preamble"}, |
| 10091 | { |
| 10092 | .cmd = IPW_PRIV_GET_PREAMBLE, |
| 10093 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, |
| 10094 | .name = "get_preamble"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10095 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10096 | IPW_PRIV_RESET, |
| 10097 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10098 | { |
| 10099 | IPW_PRIV_SW_RESET, |
| 10100 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, |
| 10101 | #ifdef CONFIG_IPW2200_MONITOR |
| 10102 | { |
| 10103 | IPW_PRIV_SET_MONITOR, |
| 10104 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, |
| 10105 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10106 | }; |
| 10107 | |
| 10108 | static iw_handler ipw_priv_handler[] = { |
| 10109 | ipw_wx_set_powermode, |
| 10110 | ipw_wx_get_powermode, |
| 10111 | ipw_wx_set_wireless_mode, |
| 10112 | ipw_wx_get_wireless_mode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10113 | ipw_wx_set_preamble, |
| 10114 | ipw_wx_get_preamble, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10115 | ipw_wx_reset, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10116 | ipw_wx_sw_reset, |
| 10117 | #ifdef CONFIG_IPW2200_MONITOR |
| 10118 | ipw_wx_set_monitor, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10119 | #endif |
| 10120 | }; |
| 10121 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10122 | static struct iw_handler_def ipw_wx_handler_def = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10123 | .standard = ipw_wx_handlers, |
| 10124 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), |
| 10125 | .num_private = ARRAY_SIZE(ipw_priv_handler), |
| 10126 | .num_private_args = ARRAY_SIZE(ipw_priv_args), |
| 10127 | .private = ipw_priv_handler, |
| 10128 | .private_args = ipw_priv_args, |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 10129 | .get_wireless_stats = ipw_get_wireless_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10130 | }; |
| 10131 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10132 | /* |
| 10133 | * Get wireless statistics. |
| 10134 | * Called by /proc/net/wireless |
| 10135 | * Also called by SIOCGIWSTATS |
| 10136 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10137 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10138 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10139 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10140 | struct iw_statistics *wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10141 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10142 | wstats = &priv->wstats; |
| 10143 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10144 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10145 | * netdev->get_wireless_stats seems to be called before fw is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10146 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
| 10147 | * and associated; if not associcated, the values are all meaningless |
| 10148 | * anyway, so set them all to NULL and INVALID */ |
| 10149 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 10150 | wstats->miss.beacon = 0; |
| 10151 | wstats->discard.retries = 0; |
| 10152 | wstats->qual.qual = 0; |
| 10153 | wstats->qual.level = 0; |
| 10154 | wstats->qual.noise = 0; |
| 10155 | wstats->qual.updated = 7; |
| 10156 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10157 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10158 | return wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10159 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10160 | |
| 10161 | wstats->qual.qual = priv->quality; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 10162 | wstats->qual.level = priv->exp_avg_rssi; |
| 10163 | wstats->qual.noise = priv->exp_avg_noise; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10164 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 10165 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10166 | |
| 10167 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); |
| 10168 | wstats->discard.retries = priv->last_tx_failures; |
| 10169 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10170 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10171 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
| 10172 | goto fail_get_ordinal; |
| 10173 | wstats->discard.retries += tx_retry; */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10174 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10175 | return wstats; |
| 10176 | } |
| 10177 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10178 | /* net device stuff */ |
| 10179 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 10180 | static void init_sys_config(struct ipw_sys_config *sys_config) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10181 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10182 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10183 | sys_config->bt_coexistence = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10184 | sys_config->answer_broadcast_ssid_probe = 0; |
| 10185 | sys_config->accept_all_data_frames = 0; |
| 10186 | sys_config->accept_non_directed_frames = 1; |
| 10187 | sys_config->exclude_unicast_unencrypted = 0; |
| 10188 | sys_config->disable_unicast_decryption = 1; |
| 10189 | sys_config->exclude_multicast_unencrypted = 0; |
| 10190 | sys_config->disable_multicast_decryption = 1; |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 10191 | if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B) |
| 10192 | antenna = CFG_SYS_ANTENNA_BOTH; |
| 10193 | sys_config->antenna_diversity = antenna; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10194 | 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] | 10195 | sys_config->dot11g_auto_detection = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10196 | sys_config->enable_cts_to_self = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10197 | sys_config->bt_coexist_collision_thr = 0; |
Pavel Machek | 67fd6b4 | 2006-07-11 15:34:05 +0200 | [diff] [blame] | 10198 | 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] | 10199 | sys_config->silence_threshold = 0x1e; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10200 | } |
| 10201 | |
| 10202 | static int ipw_net_open(struct net_device *dev) |
| 10203 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10204 | IPW_DEBUG_INFO("dev->open\n"); |
David S. Miller | 521c4d9 | 2008-07-22 18:32:47 -0700 | [diff] [blame] | 10205 | netif_start_queue(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10206 | return 0; |
| 10207 | } |
| 10208 | |
| 10209 | static int ipw_net_stop(struct net_device *dev) |
| 10210 | { |
| 10211 | IPW_DEBUG_INFO("dev->close\n"); |
| 10212 | netif_stop_queue(dev); |
| 10213 | return 0; |
| 10214 | } |
| 10215 | |
| 10216 | /* |
| 10217 | todo: |
| 10218 | |
| 10219 | 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] | 10220 | we need to heavily modify the libipw_skb_to_txb. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10221 | */ |
| 10222 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10223 | 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] | 10224 | int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10225 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10226 | struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10227 | txb->fragments[0]->data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10228 | int i = 0; |
| 10229 | struct tfd_frame *tfd; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10230 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10231 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10232 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10233 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10234 | struct clx2_tx_queue *txq = &priv->txq[0]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10235 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10236 | struct clx2_queue *q = &txq->q; |
| 10237 | u8 id, hdr_len, unicast; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10238 | int fc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10239 | |
Zhu Yi | b8ddafd | 2008-11-27 13:42:20 +0800 | [diff] [blame] | 10240 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 10241 | goto drop; |
| 10242 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10243 | hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10244 | switch (priv->ieee->iw_mode) { |
| 10245 | case IW_MODE_ADHOC: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10246 | unicast = !is_multicast_ether_addr(hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10247 | id = ipw_find_station(priv, hdr->addr1); |
| 10248 | if (id == IPW_INVALID_STATION) { |
| 10249 | id = ipw_add_station(priv, hdr->addr1); |
| 10250 | if (id == IPW_INVALID_STATION) { |
| 10251 | IPW_WARNING("Attempt to send data to " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 10252 | "invalid cell: %pM\n", |
| 10253 | hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10254 | goto drop; |
| 10255 | } |
| 10256 | } |
| 10257 | break; |
| 10258 | |
| 10259 | case IW_MODE_INFRA: |
| 10260 | default: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 10261 | unicast = !is_multicast_ether_addr(hdr->addr3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10262 | id = 0; |
| 10263 | break; |
| 10264 | } |
| 10265 | |
| 10266 | tfd = &txq->bd[q->first_empty]; |
| 10267 | txq->txb[q->first_empty] = txb; |
| 10268 | memset(tfd, 0, sizeof(*tfd)); |
| 10269 | tfd->u.data.station_number = id; |
| 10270 | |
| 10271 | tfd->control_flags.message_type = TX_FRAME_TYPE; |
| 10272 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 10273 | |
| 10274 | tfd->u.data.cmd_id = DINO_CMD_TX; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10275 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10276 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10277 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10278 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10279 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10280 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10281 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10282 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
| 10283 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10284 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10285 | fc = le16_to_cpu(hdr->frame_ctl); |
| 10286 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10287 | |
| 10288 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); |
| 10289 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10290 | if (likely(unicast)) |
| 10291 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10292 | |
| 10293 | if (txb->encrypted && !priv->ieee->host_encrypt) { |
| 10294 | switch (priv->ieee->sec.level) { |
| 10295 | case SEC_LEVEL_3: |
| 10296 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10297 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10298 | /* XXX: ACK flag must be set for CCMP even if it |
| 10299 | * is a multicast/broadcast packet, because CCMP |
| 10300 | * group communication encrypted by GTK is |
| 10301 | * actually done by the AP. */ |
| 10302 | if (!unicast) |
| 10303 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 10304 | |
| 10305 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10306 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; |
| 10307 | tfd->u.data.key_index = 0; |
| 10308 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10309 | break; |
| 10310 | case SEC_LEVEL_2: |
| 10311 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10312 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10313 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 10314 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; |
| 10315 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; |
| 10316 | break; |
| 10317 | case SEC_LEVEL_1: |
| 10318 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
Zhu Yi | 851ca26 | 2006-08-21 11:37:58 +0800 | [diff] [blame] | 10319 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 10320 | tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx; |
| 10321 | if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <= |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10322 | 40) |
| 10323 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; |
| 10324 | else |
| 10325 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; |
| 10326 | break; |
| 10327 | case SEC_LEVEL_0: |
| 10328 | break; |
| 10329 | default: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10330 | printk(KERN_ERR "Unknown security level %d\n", |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10331 | priv->ieee->sec.level); |
| 10332 | break; |
| 10333 | } |
| 10334 | } else |
| 10335 | /* No hardware encryption */ |
| 10336 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; |
| 10337 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10338 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 10339 | if (fc & IEEE80211_STYPE_QOS_DATA) |
| 10340 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data)); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10341 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10342 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10343 | /* payload */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10344 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
| 10345 | txb->nr_frags)); |
| 10346 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", |
| 10347 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); |
| 10348 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { |
| 10349 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", |
| 10350 | i, le32_to_cpu(tfd->u.data.num_chunks), |
| 10351 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10352 | 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] | 10353 | i, tfd->u.data.num_chunks, |
| 10354 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10355 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10356 | txb->fragments[i]->len - hdr_len); |
| 10357 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10358 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10359 | cpu_to_le32(pci_map_single |
| 10360 | (priv->pci_dev, |
| 10361 | txb->fragments[i]->data + hdr_len, |
| 10362 | txb->fragments[i]->len - hdr_len, |
| 10363 | PCI_DMA_TODEVICE)); |
| 10364 | tfd->u.data.chunk_len[i] = |
| 10365 | cpu_to_le16(txb->fragments[i]->len - hdr_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10366 | } |
| 10367 | |
| 10368 | if (i != txb->nr_frags) { |
| 10369 | struct sk_buff *skb; |
| 10370 | u16 remaining_bytes = 0; |
| 10371 | int j; |
| 10372 | |
| 10373 | for (j = i; j < txb->nr_frags; j++) |
| 10374 | remaining_bytes += txb->fragments[j]->len - hdr_len; |
| 10375 | |
| 10376 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", |
| 10377 | remaining_bytes); |
| 10378 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); |
| 10379 | if (skb != NULL) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10380 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10381 | for (j = i; j < txb->nr_frags; j++) { |
| 10382 | int size = txb->fragments[j]->len - hdr_len; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10383 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10384 | printk(KERN_INFO "Adding frag %d %d...\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10385 | j, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10386 | memcpy(skb_put(skb, size), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10387 | txb->fragments[j]->data + hdr_len, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10388 | } |
| 10389 | dev_kfree_skb_any(txb->fragments[i]); |
| 10390 | txb->fragments[i] = skb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10391 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10392 | cpu_to_le32(pci_map_single |
| 10393 | (priv->pci_dev, skb->data, |
Al Viro | 4958730 | 2007-12-27 01:57:47 -0500 | [diff] [blame] | 10394 | remaining_bytes, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10395 | PCI_DMA_TODEVICE)); |
| 10396 | |
Marcin Slusarz | 5c05863 | 2008-02-13 00:06:12 +0100 | [diff] [blame] | 10397 | le32_add_cpu(&tfd->u.data.num_chunks, 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10398 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10399 | } |
| 10400 | |
| 10401 | /* kick DMA */ |
| 10402 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 10403 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 10404 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 10405 | if (ipw_tx_queue_space(q) < q->high_mark) |
James Ketrenos | f697014 | 2006-02-14 09:10:51 +0800 | [diff] [blame] | 10406 | netif_stop_queue(priv->net_dev); |
| 10407 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10408 | return NETDEV_TX_OK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10409 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10410 | drop: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10411 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10412 | libipw_txb_free(txb); |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10413 | return NETDEV_TX_OK; |
| 10414 | } |
| 10415 | |
| 10416 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) |
| 10417 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10418 | struct ipw_priv *priv = libipw_priv(dev); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10419 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10420 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 10421 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 10422 | #else |
| 10423 | struct clx2_tx_queue *txq = &priv->txq[0]; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10424 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10425 | |
Dan Williams | 943dbef | 2008-02-14 17:49:41 -0500 | [diff] [blame] | 10426 | if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark) |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10427 | return 1; |
| 10428 | |
| 10429 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10430 | } |
| 10431 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10432 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10433 | static void ipw_handle_promiscuous_tx(struct ipw_priv *priv, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10434 | struct libipw_txb *txb) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10435 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10436 | struct libipw_rx_stats dummystats; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10437 | struct ieee80211_hdr *hdr; |
| 10438 | u8 n; |
| 10439 | u16 filter = priv->prom_priv->filter; |
| 10440 | int hdr_only = 0; |
| 10441 | |
| 10442 | if (filter & IPW_PROM_NO_TX) |
| 10443 | return; |
| 10444 | |
| 10445 | memset(&dummystats, 0, sizeof(dummystats)); |
| 10446 | |
| 10447 | /* Filtering of fragment chains is done agains the first fragment */ |
| 10448 | hdr = (void *)txb->fragments[0]->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10449 | if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10450 | if (filter & IPW_PROM_NO_MGMT) |
| 10451 | return; |
| 10452 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) |
| 10453 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10454 | } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10455 | if (filter & IPW_PROM_NO_CTL) |
| 10456 | return; |
| 10457 | if (filter & IPW_PROM_CTL_HEADER_ONLY) |
| 10458 | hdr_only = 1; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10459 | } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10460 | if (filter & IPW_PROM_NO_DATA) |
| 10461 | return; |
| 10462 | if (filter & IPW_PROM_DATA_HEADER_ONLY) |
| 10463 | hdr_only = 1; |
| 10464 | } |
| 10465 | |
| 10466 | for(n=0; n<txb->nr_frags; ++n) { |
| 10467 | struct sk_buff *src = txb->fragments[n]; |
| 10468 | struct sk_buff *dst; |
| 10469 | struct ieee80211_radiotap_header *rt_hdr; |
| 10470 | int len; |
| 10471 | |
| 10472 | if (hdr_only) { |
| 10473 | hdr = (void *)src->data; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10474 | len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10475 | } else |
| 10476 | len = src->len; |
| 10477 | |
Johannes Berg | 007e5dd | 2008-11-27 23:13:38 +0100 | [diff] [blame] | 10478 | dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC); |
| 10479 | if (!dst) |
| 10480 | continue; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10481 | |
| 10482 | rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr)); |
| 10483 | |
| 10484 | rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION; |
| 10485 | rt_hdr->it_pad = 0; |
| 10486 | rt_hdr->it_present = 0; /* after all, it's just an idea */ |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 10487 | rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10488 | |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10489 | *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16( |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10490 | ieee80211chan2mhz(priv->channel)); |
| 10491 | if (priv->channel > 14) /* 802.11a */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10492 | *(__le16*)skb_put(dst, sizeof(u16)) = |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10493 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10494 | IEEE80211_CHAN_5GHZ); |
| 10495 | else if (priv->ieee->mode == IEEE_B) /* 802.11b */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10496 | *(__le16*)skb_put(dst, sizeof(u16)) = |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10497 | cpu_to_le16(IEEE80211_CHAN_CCK | |
| 10498 | IEEE80211_CHAN_2GHZ); |
| 10499 | else /* 802.11g */ |
Al Viro | e62e1ee | 2007-12-27 01:36:46 -0500 | [diff] [blame] | 10500 | *(__le16*)skb_put(dst, sizeof(u16)) = |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10501 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 10502 | IEEE80211_CHAN_2GHZ); |
| 10503 | |
Al Viro | 743b84d | 2007-12-27 01:43:16 -0500 | [diff] [blame] | 10504 | rt_hdr->it_len = cpu_to_le16(dst->len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10505 | |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 10506 | skb_copy_from_linear_data(src, skb_put(dst, len), len); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10507 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10508 | if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats)) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10509 | dev_kfree_skb_any(dst); |
| 10510 | } |
| 10511 | } |
| 10512 | #endif |
| 10513 | |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 10514 | static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb, |
| 10515 | struct net_device *dev, int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10516 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10517 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10518 | unsigned long flags; |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 10519 | netdev_tx_t ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10520 | |
| 10521 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10522 | spin_lock_irqsave(&priv->lock, flags); |
| 10523 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10524 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10525 | if (rtap_iface && netif_running(priv->prom_net_dev)) |
| 10526 | ipw_handle_promiscuous_tx(priv, txb); |
| 10527 | #endif |
| 10528 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10529 | ret = ipw_tx_skb(priv, txb, pri); |
| 10530 | if (ret == NETDEV_TX_OK) |
| 10531 | __ipw_led_activity_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10532 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10533 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10534 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10535 | } |
| 10536 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10537 | static void ipw_net_set_multicast_list(struct net_device *dev) |
| 10538 | { |
| 10539 | |
| 10540 | } |
| 10541 | |
| 10542 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) |
| 10543 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10544 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10545 | struct sockaddr *addr = p; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 10546 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10547 | if (!is_valid_ether_addr(addr->sa_data)) |
| 10548 | return -EADDRNOTAVAIL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10549 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10550 | priv->config |= CFG_CUSTOM_MAC; |
| 10551 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 10552 | printk(KERN_INFO "%s: Setting MAC to %pM\n", |
| 10553 | priv->net_dev->name, priv->mac_addr); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10554 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10555 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10556 | return 0; |
| 10557 | } |
| 10558 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10559 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10560 | struct ethtool_drvinfo *info) |
| 10561 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10562 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10563 | char vers[64]; |
| 10564 | char date[32]; |
| 10565 | u32 len; |
| 10566 | |
| 10567 | strcpy(info->driver, DRV_NAME); |
| 10568 | strcpy(info->version, DRV_VERSION); |
| 10569 | |
| 10570 | len = sizeof(vers); |
| 10571 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); |
| 10572 | len = sizeof(date); |
| 10573 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); |
| 10574 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10575 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10576 | vers, date); |
| 10577 | strcpy(info->bus_info, pci_name(p->pci_dev)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10578 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10579 | } |
| 10580 | |
| 10581 | static u32 ipw_ethtool_get_link(struct net_device *dev) |
| 10582 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10583 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10584 | return (priv->status & STATUS_ASSOCIATED) != 0; |
| 10585 | } |
| 10586 | |
| 10587 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) |
| 10588 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10589 | return IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10590 | } |
| 10591 | |
| 10592 | static int ipw_ethtool_get_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10593 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10594 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10595 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10596 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10597 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10598 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10599 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10600 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10601 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10602 | return 0; |
| 10603 | } |
| 10604 | |
| 10605 | static int ipw_ethtool_set_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10606 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10607 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10608 | struct ipw_priv *p = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10609 | int i; |
| 10610 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10611 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10612 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10613 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10614 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
Adrian Bunk | 71e585f | 2006-03-11 04:42:58 +0100 | [diff] [blame] | 10615 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
| 10616 | ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10617 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10618 | return 0; |
| 10619 | } |
| 10620 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 10621 | static const struct ethtool_ops ipw_ethtool_ops = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10622 | .get_link = ipw_ethtool_get_link, |
| 10623 | .get_drvinfo = ipw_ethtool_get_drvinfo, |
| 10624 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, |
| 10625 | .get_eeprom = ipw_ethtool_get_eeprom, |
| 10626 | .set_eeprom = ipw_ethtool_set_eeprom, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10627 | }; |
| 10628 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 10629 | static irqreturn_t ipw_isr(int irq, void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10630 | { |
| 10631 | struct ipw_priv *priv = data; |
| 10632 | u32 inta, inta_mask; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10633 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10634 | if (!priv) |
| 10635 | return IRQ_NONE; |
| 10636 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10637 | spin_lock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10638 | |
| 10639 | if (!(priv->status & STATUS_INT_ENABLED)) { |
Zhu Yi | d00d012 | 2007-07-12 16:09:40 +0800 | [diff] [blame] | 10640 | /* IRQ is disabled */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10641 | goto none; |
| 10642 | } |
| 10643 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10644 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 10645 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10646 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10647 | if (inta == 0xFFFFFFFF) { |
| 10648 | /* Hardware disappeared */ |
| 10649 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); |
| 10650 | goto none; |
| 10651 | } |
| 10652 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10653 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10654 | /* Shared interrupt */ |
| 10655 | goto none; |
| 10656 | } |
| 10657 | |
| 10658 | /* tell the device to stop sending interrupts */ |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10659 | __ipw_disable_interrupts(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10660 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10661 | /* ack current interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10662 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
| 10663 | ipw_write32(priv, IPW_INTA_RW, inta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10664 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10665 | /* Cache INTA value for our tasklet */ |
| 10666 | priv->isr_inta = inta; |
| 10667 | |
| 10668 | tasklet_schedule(&priv->irq_tasklet); |
| 10669 | |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10670 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10671 | |
| 10672 | return IRQ_HANDLED; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10673 | none: |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 10674 | spin_unlock(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10675 | return IRQ_NONE; |
| 10676 | } |
| 10677 | |
| 10678 | static void ipw_rf_kill(void *adapter) |
| 10679 | { |
| 10680 | struct ipw_priv *priv = adapter; |
| 10681 | unsigned long flags; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10682 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10683 | spin_lock_irqsave(&priv->lock, flags); |
| 10684 | |
| 10685 | if (rf_kill_active(priv)) { |
| 10686 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); |
| 10687 | if (priv->workqueue) |
| 10688 | queue_delayed_work(priv->workqueue, |
| 10689 | &priv->rf_kill, 2 * HZ); |
| 10690 | goto exit_unlock; |
| 10691 | } |
| 10692 | |
| 10693 | /* RF Kill is now disabled, so bring the device back up */ |
| 10694 | |
| 10695 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 10696 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " |
| 10697 | "device\n"); |
| 10698 | |
| 10699 | /* we can not do an adapter restart while inside an irq lock */ |
| 10700 | queue_work(priv->workqueue, &priv->adapter_restart); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10701 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10702 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
| 10703 | "enabled\n"); |
| 10704 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10705 | exit_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10706 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10707 | } |
| 10708 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10709 | static void ipw_bg_rf_kill(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10710 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10711 | struct ipw_priv *priv = |
| 10712 | container_of(work, struct ipw_priv, rf_kill.work); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10713 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10714 | ipw_rf_kill(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10715 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10716 | } |
| 10717 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10718 | static void ipw_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10719 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10720 | priv->last_seq_num = -1; |
| 10721 | priv->last_frag_num = -1; |
| 10722 | priv->last_packet_time = 0; |
| 10723 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10724 | netif_carrier_on(priv->net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10725 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10726 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10727 | cancel_delayed_work(&priv->request_direct_scan); |
| 10728 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10729 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10730 | ipw_reset_stats(priv); |
| 10731 | /* Ensure the rate is updated immediately */ |
| 10732 | priv->last_rate = ipw_get_current_rate(priv); |
| 10733 | ipw_gather_stats(priv); |
| 10734 | ipw_led_link_up(priv); |
| 10735 | notify_wx_assoc_event(priv); |
| 10736 | |
| 10737 | if (priv->config & CFG_BACKGROUND_SCAN) |
| 10738 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); |
| 10739 | } |
| 10740 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10741 | static void ipw_bg_link_up(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10742 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10743 | struct ipw_priv *priv = |
| 10744 | container_of(work, struct ipw_priv, link_up); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10745 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10746 | ipw_link_up(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10747 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10748 | } |
| 10749 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10750 | static void ipw_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10751 | { |
| 10752 | ipw_led_link_down(priv); |
| 10753 | netif_carrier_off(priv->net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10754 | notify_wx_assoc_event(priv); |
| 10755 | |
| 10756 | /* Cancel any queued work ... */ |
| 10757 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10758 | cancel_delayed_work(&priv->request_direct_scan); |
| 10759 | cancel_delayed_work(&priv->request_passive_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10760 | cancel_delayed_work(&priv->adhoc_check); |
| 10761 | cancel_delayed_work(&priv->gather_stats); |
| 10762 | |
| 10763 | ipw_reset_stats(priv); |
| 10764 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10765 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
| 10766 | /* Queue up another scan... */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10767 | queue_delayed_work(priv->workqueue, &priv->request_scan, 0); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10768 | } else |
| 10769 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10770 | } |
| 10771 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10772 | static void ipw_bg_link_down(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10773 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10774 | struct ipw_priv *priv = |
| 10775 | container_of(work, struct ipw_priv, link_down); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10776 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10777 | ipw_link_down(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10778 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10779 | } |
| 10780 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 10781 | static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10782 | { |
| 10783 | int ret = 0; |
| 10784 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10785 | priv->workqueue = create_workqueue(DRV_NAME); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10786 | init_waitqueue_head(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10787 | init_waitqueue_head(&priv->wait_state); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10788 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10789 | INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check); |
| 10790 | INIT_WORK(&priv->associate, ipw_bg_associate); |
| 10791 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate); |
| 10792 | INIT_WORK(&priv->system_config, ipw_system_config); |
| 10793 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish); |
| 10794 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart); |
| 10795 | INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill); |
| 10796 | INIT_WORK(&priv->up, ipw_bg_up); |
| 10797 | INIT_WORK(&priv->down, ipw_bg_down); |
| 10798 | INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 10799 | INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan); |
| 10800 | INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 10801 | INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10802 | INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats); |
| 10803 | INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan); |
| 10804 | INIT_WORK(&priv->roam, ipw_bg_roam); |
| 10805 | INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check); |
| 10806 | INIT_WORK(&priv->link_up, ipw_bg_link_up); |
| 10807 | INIT_WORK(&priv->link_down, ipw_bg_link_down); |
| 10808 | INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on); |
| 10809 | INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off); |
| 10810 | INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off); |
| 10811 | INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10812 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10813 | #ifdef CONFIG_IPW2200_QOS |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 10814 | INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10815 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10816 | |
| 10817 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 10818 | ipw_irq_tasklet, (unsigned long)priv); |
| 10819 | |
| 10820 | return ret; |
| 10821 | } |
| 10822 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10823 | static void shim__set_security(struct net_device *dev, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10824 | struct libipw_security *sec) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10825 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10826 | struct ipw_priv *priv = libipw_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10827 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10828 | for (i = 0; i < 4; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10829 | if (sec->flags & (1 << i)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10830 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10831 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10832 | if (sec->key_sizes[i] == 0) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10833 | priv->ieee->sec.flags &= ~(1 << i); |
| 10834 | else { |
| 10835 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10836 | sec->key_sizes[i]); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10837 | priv->ieee->sec.flags |= (1 << i); |
| 10838 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10839 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10840 | } else if (sec->level != SEC_LEVEL_1) |
| 10841 | priv->ieee->sec.flags &= ~(1 << i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10842 | } |
| 10843 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10844 | if (sec->flags & SEC_ACTIVE_KEY) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10845 | if (sec->active_key <= 3) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10846 | priv->ieee->sec.active_key = sec->active_key; |
| 10847 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10848 | } else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10849 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10850 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10851 | } else |
| 10852 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10853 | |
| 10854 | if ((sec->flags & SEC_AUTH_MODE) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10855 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
| 10856 | priv->ieee->sec.auth_mode = sec->auth_mode; |
| 10857 | priv->ieee->sec.flags |= SEC_AUTH_MODE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10858 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
| 10859 | priv->capability |= CAP_SHARED_KEY; |
| 10860 | else |
| 10861 | priv->capability &= ~CAP_SHARED_KEY; |
| 10862 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10863 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10864 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10865 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
| 10866 | priv->ieee->sec.flags |= SEC_ENABLED; |
| 10867 | priv->ieee->sec.enabled = sec->enabled; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10868 | priv->status |= STATUS_SECURITY_UPDATED; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10869 | if (sec->enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10870 | priv->capability |= CAP_PRIVACY_ON; |
| 10871 | else |
| 10872 | priv->capability &= ~CAP_PRIVACY_ON; |
| 10873 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10874 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10875 | if (sec->flags & SEC_ENCRYPT) |
| 10876 | priv->ieee->sec.encrypt = sec->encrypt; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10877 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10878 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
| 10879 | priv->ieee->sec.level = sec->level; |
| 10880 | priv->ieee->sec.flags |= SEC_LEVEL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10881 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10882 | } |
| 10883 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 10884 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
| 10885 | ipw_set_hwcrypto_keys(priv); |
| 10886 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10887 | /* To match current functionality of ipw2100 (which works well w/ |
| 10888 | * various supplicants, we don't force a disassociate if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10889 | * privacy capability changes ... */ |
| 10890 | #if 0 |
| 10891 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10892 | (((priv->assoc_request.capability & |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 10893 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10894 | (!(priv->assoc_request.capability & |
Al Viro | 5b5e807 | 2007-12-27 01:54:06 -0500 | [diff] [blame] | 10895 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10896 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
| 10897 | "change.\n"); |
| 10898 | ipw_disassociate(priv); |
| 10899 | } |
| 10900 | #endif |
| 10901 | } |
| 10902 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10903 | static int init_supported_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10904 | struct ipw_supported_rates *rates) |
| 10905 | { |
| 10906 | /* TODO: Mask out rates based on priv->rates_mask */ |
| 10907 | |
| 10908 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10909 | /* configure supported rates */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10910 | switch (priv->ieee->freq_band) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10911 | case LIBIPW_52GHZ_BAND: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10912 | rates->ieee_mode = IPW_A_MODE; |
| 10913 | rates->purpose = IPW_RATE_CAPABILITIES; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10914 | ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10915 | LIBIPW_OFDM_DEFAULT_RATES_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10916 | break; |
| 10917 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10918 | default: /* Mixed or 2.4Ghz */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10919 | rates->ieee_mode = IPW_G_MODE; |
| 10920 | rates->purpose = IPW_RATE_CAPABILITIES; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 10921 | ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10922 | LIBIPW_CCK_DEFAULT_RATES_MASK); |
| 10923 | if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) { |
| 10924 | ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, |
| 10925 | LIBIPW_OFDM_DEFAULT_RATES_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10926 | } |
| 10927 | break; |
| 10928 | } |
| 10929 | |
| 10930 | return 0; |
| 10931 | } |
| 10932 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10933 | static int ipw_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10934 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10935 | /* This is only called from ipw_up, which resets/reloads the firmware |
| 10936 | so, we don't need to first disable the card before we configure |
| 10937 | it */ |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 10938 | if (ipw_set_tx_power(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10939 | goto error; |
| 10940 | |
| 10941 | /* initialize adapter address */ |
| 10942 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) |
| 10943 | goto error; |
| 10944 | |
| 10945 | /* set basic system config settings */ |
| 10946 | init_sys_config(&priv->sys_config); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10947 | |
| 10948 | /* Support Bluetooth if we have BT h/w on board, and user wants to. |
| 10949 | * Does not support BT priority yet (don't abort or defer our Tx) */ |
| 10950 | if (bt_coexist) { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10951 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10952 | |
| 10953 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) |
| 10954 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10955 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10956 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
| 10957 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10958 | |= CFG_BT_COEXISTENCE_OOB; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10959 | } |
| 10960 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10961 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 10962 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { |
| 10963 | priv->sys_config.accept_all_data_frames = 1; |
| 10964 | priv->sys_config.accept_non_directed_frames = 1; |
| 10965 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 10966 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 10967 | } |
| 10968 | #endif |
| 10969 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10970 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 10971 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 10972 | else |
| 10973 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 10974 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 10975 | if (ipw_send_system_config(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10976 | goto error; |
| 10977 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10978 | init_supported_rates(priv, &priv->rates); |
| 10979 | if (ipw_send_supported_rates(priv, &priv->rates)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10980 | goto error; |
| 10981 | |
| 10982 | /* Set request-to-send threshold */ |
| 10983 | if (priv->rts_threshold) { |
| 10984 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) |
| 10985 | goto error; |
| 10986 | } |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10987 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10988 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
| 10989 | ipw_qos_activate(priv, NULL); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 10990 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10991 | |
| 10992 | if (ipw_set_random_seed(priv)) |
| 10993 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10994 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10995 | /* final state transition to the RUN state */ |
| 10996 | if (ipw_send_host_complete(priv)) |
| 10997 | goto error; |
| 10998 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10999 | priv->status |= STATUS_INIT; |
| 11000 | |
| 11001 | ipw_led_init(priv); |
| 11002 | ipw_led_radio_on(priv); |
| 11003 | priv->notif_missed_beacons = 0; |
| 11004 | |
| 11005 | /* Set hardware WEP key if it is configured. */ |
| 11006 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 11007 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 11008 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 11009 | ipw_set_hwcrypto_keys(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11010 | |
| 11011 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11012 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11013 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11014 | return -EIO; |
| 11015 | } |
| 11016 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11017 | /* |
| 11018 | * NOTE: |
| 11019 | * |
| 11020 | * These tables have been tested in conjunction with the |
| 11021 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. |
| 11022 | * |
| 11023 | * Altering this values, using it on other hardware, or in geographies |
| 11024 | * not intended for resale of the above mentioned Intel adapters has |
| 11025 | * not been tested. |
| 11026 | * |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11027 | * Remember to update the table in README.ipw2200 when changing this |
| 11028 | * table. |
| 11029 | * |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11030 | */ |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11031 | static const struct libipw_geo ipw_geos[] = { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11032 | { /* Restricted */ |
| 11033 | "---", |
| 11034 | .bg_channels = 11, |
| 11035 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11036 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11037 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11038 | {2457, 10}, {2462, 11}}, |
| 11039 | }, |
| 11040 | |
| 11041 | { /* Custom US/Canada */ |
| 11042 | "ZZF", |
| 11043 | .bg_channels = 11, |
| 11044 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11045 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11046 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11047 | {2457, 10}, {2462, 11}}, |
| 11048 | .a_channels = 8, |
| 11049 | .a = {{5180, 36}, |
| 11050 | {5200, 40}, |
| 11051 | {5220, 44}, |
| 11052 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11053 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11054 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11055 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11056 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11057 | }, |
| 11058 | |
| 11059 | { /* Rest of World */ |
| 11060 | "ZZD", |
| 11061 | .bg_channels = 13, |
| 11062 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11063 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11064 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11065 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11066 | {2472, 13}}, |
| 11067 | }, |
| 11068 | |
| 11069 | { /* Custom USA & Europe & High */ |
| 11070 | "ZZA", |
| 11071 | .bg_channels = 11, |
| 11072 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11073 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11074 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11075 | {2457, 10}, {2462, 11}}, |
| 11076 | .a_channels = 13, |
| 11077 | .a = {{5180, 36}, |
| 11078 | {5200, 40}, |
| 11079 | {5220, 44}, |
| 11080 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11081 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11082 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11083 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11084 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11085 | {5745, 149}, |
| 11086 | {5765, 153}, |
| 11087 | {5785, 157}, |
| 11088 | {5805, 161}, |
| 11089 | {5825, 165}}, |
| 11090 | }, |
| 11091 | |
| 11092 | { /* Custom NA & Europe */ |
| 11093 | "ZZB", |
| 11094 | .bg_channels = 11, |
| 11095 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11096 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11097 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11098 | {2457, 10}, {2462, 11}}, |
| 11099 | .a_channels = 13, |
| 11100 | .a = {{5180, 36}, |
| 11101 | {5200, 40}, |
| 11102 | {5220, 44}, |
| 11103 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11104 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11105 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11106 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11107 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11108 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11109 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11110 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11111 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11112 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11113 | }, |
| 11114 | |
| 11115 | { /* Custom Japan */ |
| 11116 | "ZZC", |
| 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 | .a_channels = 4, |
| 11123 | .a = {{5170, 34}, {5190, 38}, |
| 11124 | {5210, 42}, {5230, 46}}, |
| 11125 | }, |
| 11126 | |
| 11127 | { /* Custom */ |
| 11128 | "ZZM", |
| 11129 | .bg_channels = 11, |
| 11130 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11131 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11132 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11133 | {2457, 10}, {2462, 11}}, |
| 11134 | }, |
| 11135 | |
| 11136 | { /* Europe */ |
| 11137 | "ZZE", |
| 11138 | .bg_channels = 13, |
| 11139 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11140 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11141 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11142 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 11143 | {2472, 13}}, |
| 11144 | .a_channels = 19, |
| 11145 | .a = {{5180, 36}, |
| 11146 | {5200, 40}, |
| 11147 | {5220, 44}, |
| 11148 | {5240, 48}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11149 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11150 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11151 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11152 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11153 | {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, |
| 11154 | {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, |
| 11155 | {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, |
| 11156 | {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, |
| 11157 | {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, |
| 11158 | {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, |
| 11159 | {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, |
| 11160 | {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, |
| 11161 | {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, |
| 11162 | {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, |
| 11163 | {5700, 140, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11164 | }, |
| 11165 | |
| 11166 | { /* Custom Japan */ |
| 11167 | "ZZJ", |
| 11168 | .bg_channels = 14, |
| 11169 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11170 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11171 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11172 | {2457, 10}, {2462, 11}, {2467, 12}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11173 | {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11174 | .a_channels = 4, |
| 11175 | .a = {{5170, 34}, {5190, 38}, |
| 11176 | {5210, 42}, {5230, 46}}, |
| 11177 | }, |
| 11178 | |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11179 | { /* Rest of World */ |
| 11180 | "ZZR", |
| 11181 | .bg_channels = 14, |
| 11182 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11183 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11184 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11185 | {2457, 10}, {2462, 11}, {2467, 12}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11186 | {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY | |
| 11187 | LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11188 | }, |
| 11189 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11190 | { /* High Band */ |
| 11191 | "ZZH", |
| 11192 | .bg_channels = 13, |
| 11193 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11194 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11195 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11196 | {2457, 10}, {2462, 11}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11197 | {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, |
| 11198 | {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11199 | .a_channels = 4, |
| 11200 | .a = {{5745, 149}, {5765, 153}, |
| 11201 | {5785, 157}, {5805, 161}}, |
| 11202 | }, |
| 11203 | |
| 11204 | { /* Custom Europe */ |
| 11205 | "ZZG", |
| 11206 | .bg_channels = 13, |
| 11207 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11208 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11209 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11210 | {2457, 10}, {2462, 11}, |
| 11211 | {2467, 12}, {2472, 13}}, |
| 11212 | .a_channels = 4, |
| 11213 | .a = {{5180, 36}, {5200, 40}, |
| 11214 | {5220, 44}, {5240, 48}}, |
| 11215 | }, |
| 11216 | |
| 11217 | { /* Europe */ |
| 11218 | "ZZK", |
| 11219 | .bg_channels = 13, |
| 11220 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11221 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11222 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11223 | {2457, 10}, {2462, 11}, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11224 | {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, |
| 11225 | {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11226 | .a_channels = 24, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11227 | .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, |
| 11228 | {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, |
| 11229 | {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, |
| 11230 | {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, |
| 11231 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11232 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11233 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11234 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11235 | {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, |
| 11236 | {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, |
| 11237 | {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, |
| 11238 | {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, |
| 11239 | {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, |
| 11240 | {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, |
| 11241 | {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, |
| 11242 | {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, |
| 11243 | {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, |
| 11244 | {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, |
| 11245 | {5700, 140, LIBIPW_CH_PASSIVE_ONLY}, |
| 11246 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11247 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11248 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11249 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11250 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11251 | }, |
| 11252 | |
| 11253 | { /* Europe */ |
| 11254 | "ZZL", |
| 11255 | .bg_channels = 11, |
| 11256 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 11257 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 11258 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 11259 | {2457, 10}, {2462, 11}}, |
| 11260 | .a_channels = 13, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11261 | .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, |
| 11262 | {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, |
| 11263 | {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, |
| 11264 | {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, |
| 11265 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
| 11266 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, |
| 11267 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, |
| 11268 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, |
| 11269 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, |
| 11270 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, |
| 11271 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, |
| 11272 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, |
| 11273 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11274 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11275 | }; |
| 11276 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11277 | #define MAX_HW_RESTARTS 5 |
| 11278 | static int ipw_up(struct ipw_priv *priv) |
| 11279 | { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11280 | int rc, i, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11281 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11282 | /* Age scan list entries found before suspend */ |
| 11283 | if (priv->suspend_time) { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11284 | libipw_networks_age(priv->ieee, priv->suspend_time); |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11285 | priv->suspend_time = 0; |
| 11286 | } |
| 11287 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11288 | if (priv->status & STATUS_EXIT_PENDING) |
| 11289 | return -EIO; |
| 11290 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11291 | if (cmdlog && !priv->cmdlog) { |
Yan Burman | e6e3f12 | 2006-12-02 13:38:14 +0200 | [diff] [blame] | 11292 | priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog), |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11293 | GFP_KERNEL); |
| 11294 | if (priv->cmdlog == NULL) { |
| 11295 | IPW_ERROR("Error allocating %d command log entries.\n", |
| 11296 | cmdlog); |
Zhu Yi | d0b526b | 2006-04-13 17:19:50 +0800 | [diff] [blame] | 11297 | return -ENOMEM; |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11298 | } else { |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11299 | priv->cmdlog_len = cmdlog; |
| 11300 | } |
| 11301 | } |
| 11302 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11303 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11304 | /* Load the microcode, firmware, and eeprom. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11305 | * Also start the clocks. */ |
| 11306 | rc = ipw_load(priv); |
| 11307 | if (rc) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 11308 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11309 | return rc; |
| 11310 | } |
| 11311 | |
| 11312 | ipw_init_ordinals(priv); |
| 11313 | if (!(priv->config & CFG_CUSTOM_MAC)) |
| 11314 | eeprom_parse_mac(priv, priv->mac_addr); |
| 11315 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
John W. Linville | 5e5eab5 | 2009-10-06 16:45:14 -0400 | [diff] [blame] | 11316 | memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11317 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11318 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
| 11319 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], |
| 11320 | ipw_geos[j].name, 3)) |
| 11321 | break; |
| 11322 | } |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11323 | if (j == ARRAY_SIZE(ipw_geos)) { |
| 11324 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", |
| 11325 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], |
| 11326 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], |
| 11327 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11328 | j = 0; |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 11329 | } |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11330 | if (libipw_set_geo(priv->ieee, &ipw_geos[j])) { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11331 | IPW_WARNING("Could not set geography."); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11332 | return 0; |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 11333 | } |
| 11334 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11335 | if (priv->status & STATUS_RF_KILL_SW) { |
| 11336 | IPW_WARNING("Radio disabled by module parameter.\n"); |
| 11337 | return 0; |
| 11338 | } else if (rf_kill_active(priv)) { |
| 11339 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" |
| 11340 | "Kill switch must be turned off for " |
| 11341 | "wireless networking to work.\n"); |
| 11342 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
| 11343 | 2 * HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11344 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11345 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11346 | |
| 11347 | rc = ipw_config(priv); |
| 11348 | if (!rc) { |
| 11349 | IPW_DEBUG_INFO("Configured device on count %i\n", i); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11350 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 11351 | /* If configure to try and auto-associate, kick |
| 11352 | * off a scan. */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11353 | queue_delayed_work(priv->workqueue, |
| 11354 | &priv->request_scan, 0); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11355 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11356 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11357 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11358 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11359 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11360 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
| 11361 | i, MAX_HW_RESTARTS); |
| 11362 | |
| 11363 | /* We had an error bringing up the hardware, so take it |
| 11364 | * all the way back down so we can try again */ |
| 11365 | ipw_down(priv); |
| 11366 | } |
| 11367 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11368 | /* tried to restart and config the device for as long as our |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11369 | * patience could withstand */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11370 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11371 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11372 | return -EIO; |
| 11373 | } |
| 11374 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11375 | static void ipw_bg_up(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11376 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11377 | struct ipw_priv *priv = |
| 11378 | container_of(work, struct ipw_priv, up); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11379 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11380 | ipw_up(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11381 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11382 | } |
| 11383 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11384 | static void ipw_deinit(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11385 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11386 | int i; |
| 11387 | |
| 11388 | if (priv->status & STATUS_SCANNING) { |
| 11389 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); |
| 11390 | ipw_abort_scan(priv); |
| 11391 | } |
| 11392 | |
| 11393 | if (priv->status & STATUS_ASSOCIATED) { |
| 11394 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); |
| 11395 | ipw_disassociate(priv); |
| 11396 | } |
| 11397 | |
| 11398 | ipw_led_shutdown(priv); |
| 11399 | |
| 11400 | /* Wait up to 1s for status to change to not scanning and not |
| 11401 | * associated (disassociation can take a while for a ful 802.11 |
| 11402 | * exchange */ |
| 11403 | for (i = 1000; i && (priv->status & |
| 11404 | (STATUS_DISASSOCIATING | |
| 11405 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) |
| 11406 | udelay(10); |
| 11407 | |
| 11408 | if (priv->status & (STATUS_DISASSOCIATING | |
| 11409 | STATUS_ASSOCIATED | STATUS_SCANNING)) |
| 11410 | IPW_DEBUG_INFO("Still associated or scanning...\n"); |
| 11411 | else |
| 11412 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); |
| 11413 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11414 | /* Attempt to disable the card */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11415 | ipw_send_card_disable(priv, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11416 | |
| 11417 | priv->status &= ~STATUS_INIT; |
| 11418 | } |
| 11419 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11420 | static void ipw_down(struct ipw_priv *priv) |
| 11421 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11422 | int exit_pending = priv->status & STATUS_EXIT_PENDING; |
| 11423 | |
| 11424 | priv->status |= STATUS_EXIT_PENDING; |
| 11425 | |
| 11426 | if (ipw_is_init(priv)) |
| 11427 | ipw_deinit(priv); |
| 11428 | |
| 11429 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 11430 | * exiting the module */ |
| 11431 | if (!exit_pending) |
| 11432 | priv->status &= ~STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11433 | |
| 11434 | /* tell the device to stop sending interrupts */ |
| 11435 | ipw_disable_interrupts(priv); |
| 11436 | |
| 11437 | /* Clear all bits but the RF Kill */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11438 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11439 | netif_carrier_off(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11440 | |
| 11441 | ipw_stop_nic(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11442 | |
| 11443 | ipw_led_radio_off(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11444 | } |
| 11445 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11446 | static void ipw_bg_down(struct work_struct *work) |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11447 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11448 | struct ipw_priv *priv = |
| 11449 | container_of(work, struct ipw_priv, down); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11450 | mutex_lock(&priv->mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 11451 | ipw_down(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11452 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11453 | } |
| 11454 | |
| 11455 | /* Called by register_netdev() */ |
| 11456 | static int ipw_net_init(struct net_device *dev) |
| 11457 | { |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11458 | int i, rc = 0; |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11459 | struct ipw_priv *priv = libipw_priv(dev); |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11460 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
| 11461 | struct wireless_dev *wdev = &priv->ieee->wdev; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11462 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11463 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11464 | if (ipw_up(priv)) { |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11465 | rc = -EIO; |
| 11466 | goto out; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11467 | } |
| 11468 | |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11469 | memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN); |
| 11470 | |
| 11471 | /* fill-out priv->ieee->bg_band */ |
| 11472 | if (geo->bg_channels) { |
| 11473 | struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band; |
| 11474 | |
| 11475 | bg_band->band = IEEE80211_BAND_2GHZ; |
| 11476 | bg_band->n_channels = geo->bg_channels; |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 11477 | bg_band->channels = kcalloc(geo->bg_channels, |
| 11478 | sizeof(struct ieee80211_channel), |
| 11479 | GFP_KERNEL); |
Dan Carpenter | 2ee4e27 | 2010-10-04 14:31:46 +0200 | [diff] [blame] | 11480 | if (!bg_band->channels) { |
| 11481 | rc = -ENOMEM; |
| 11482 | goto out; |
| 11483 | } |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11484 | /* translate geo->bg to bg_band.channels */ |
| 11485 | for (i = 0; i < geo->bg_channels; i++) { |
| 11486 | bg_band->channels[i].band = IEEE80211_BAND_2GHZ; |
| 11487 | bg_band->channels[i].center_freq = geo->bg[i].freq; |
| 11488 | bg_band->channels[i].hw_value = geo->bg[i].channel; |
| 11489 | bg_band->channels[i].max_power = geo->bg[i].max_power; |
| 11490 | if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) |
| 11491 | bg_band->channels[i].flags |= |
| 11492 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 11493 | if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS) |
| 11494 | bg_band->channels[i].flags |= |
| 11495 | IEEE80211_CHAN_NO_IBSS; |
| 11496 | if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT) |
| 11497 | bg_band->channels[i].flags |= |
| 11498 | IEEE80211_CHAN_RADAR; |
| 11499 | /* No equivalent for LIBIPW_CH_80211H_RULES, |
| 11500 | LIBIPW_CH_UNIFORM_SPREADING, or |
| 11501 | LIBIPW_CH_B_ONLY... */ |
| 11502 | } |
| 11503 | /* point at bitrate info */ |
| 11504 | bg_band->bitrates = ipw2200_bg_rates; |
| 11505 | bg_band->n_bitrates = ipw2200_num_bg_rates; |
| 11506 | |
| 11507 | wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band; |
| 11508 | } |
| 11509 | |
| 11510 | /* fill-out priv->ieee->a_band */ |
| 11511 | if (geo->a_channels) { |
| 11512 | struct ieee80211_supported_band *a_band = &priv->ieee->a_band; |
| 11513 | |
| 11514 | a_band->band = IEEE80211_BAND_5GHZ; |
| 11515 | a_band->n_channels = geo->a_channels; |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 11516 | a_band->channels = kcalloc(geo->a_channels, |
| 11517 | sizeof(struct ieee80211_channel), |
| 11518 | GFP_KERNEL); |
Dan Carpenter | 2ee4e27 | 2010-10-04 14:31:46 +0200 | [diff] [blame] | 11519 | if (!a_band->channels) { |
| 11520 | rc = -ENOMEM; |
| 11521 | goto out; |
| 11522 | } |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11523 | /* translate geo->bg to a_band.channels */ |
| 11524 | for (i = 0; i < geo->a_channels; i++) { |
| 11525 | a_band->channels[i].band = IEEE80211_BAND_2GHZ; |
| 11526 | a_band->channels[i].center_freq = geo->a[i].freq; |
| 11527 | a_band->channels[i].hw_value = geo->a[i].channel; |
| 11528 | a_band->channels[i].max_power = geo->a[i].max_power; |
| 11529 | if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) |
| 11530 | a_band->channels[i].flags |= |
| 11531 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 11532 | if (geo->a[i].flags & LIBIPW_CH_NO_IBSS) |
| 11533 | a_band->channels[i].flags |= |
| 11534 | IEEE80211_CHAN_NO_IBSS; |
| 11535 | if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT) |
| 11536 | a_band->channels[i].flags |= |
| 11537 | IEEE80211_CHAN_RADAR; |
| 11538 | /* No equivalent for LIBIPW_CH_80211H_RULES, |
| 11539 | LIBIPW_CH_UNIFORM_SPREADING, or |
| 11540 | LIBIPW_CH_B_ONLY... */ |
| 11541 | } |
| 11542 | /* point at bitrate info */ |
| 11543 | a_band->bitrates = ipw2200_a_rates; |
| 11544 | a_band->n_bitrates = ipw2200_num_a_rates; |
| 11545 | |
| 11546 | wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band; |
| 11547 | } |
| 11548 | |
| 11549 | set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev); |
| 11550 | |
| 11551 | /* With that information in place, we can now register the wiphy... */ |
| 11552 | if (wiphy_register(wdev->wiphy)) { |
| 11553 | rc = -EIO; |
| 11554 | goto out; |
| 11555 | } |
| 11556 | |
| 11557 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11558 | mutex_unlock(&priv->mutex); |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11559 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11560 | } |
| 11561 | |
| 11562 | /* PCI driver stuff */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 11563 | static DEFINE_PCI_DEVICE_TABLE(card_ids) = { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11564 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
| 11565 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, |
| 11566 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, |
| 11567 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, |
| 11568 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, |
| 11569 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, |
| 11570 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, |
| 11571 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, |
| 11572 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, |
| 11573 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, |
| 11574 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, |
| 11575 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, |
| 11576 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, |
| 11577 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, |
| 11578 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, |
| 11579 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, |
| 11580 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, |
Joe Perches | 8ab0ea7 | 2009-06-24 22:13:27 -0700 | [diff] [blame] | 11581 | {PCI_VDEVICE(INTEL, 0x104f), 0}, |
| 11582 | {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */ |
| 11583 | {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */ |
| 11584 | {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */ |
| 11585 | {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11586 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11587 | /* required last entry */ |
| 11588 | {0,} |
| 11589 | }; |
| 11590 | |
| 11591 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 11592 | |
| 11593 | static struct attribute *ipw_sysfs_entries[] = { |
| 11594 | &dev_attr_rf_kill.attr, |
| 11595 | &dev_attr_direct_dword.attr, |
| 11596 | &dev_attr_indirect_byte.attr, |
| 11597 | &dev_attr_indirect_dword.attr, |
| 11598 | &dev_attr_mem_gpio_reg.attr, |
| 11599 | &dev_attr_command_event_reg.attr, |
| 11600 | &dev_attr_nic_type.attr, |
| 11601 | &dev_attr_status.attr, |
| 11602 | &dev_attr_cfg.attr, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 11603 | &dev_attr_error.attr, |
| 11604 | &dev_attr_event_log.attr, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11605 | &dev_attr_cmd_log.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11606 | &dev_attr_eeprom_delay.attr, |
| 11607 | &dev_attr_ucode_version.attr, |
| 11608 | &dev_attr_rtc.attr, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11609 | &dev_attr_scan_age.attr, |
| 11610 | &dev_attr_led.attr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11611 | &dev_attr_speed_scan.attr, |
| 11612 | &dev_attr_net_stats.attr, |
Zhu Yi | 375dd24 | 2007-02-14 16:04:24 +0800 | [diff] [blame] | 11613 | &dev_attr_channels.attr, |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11614 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11615 | &dev_attr_rtap_iface.attr, |
| 11616 | &dev_attr_rtap_filter.attr, |
| 11617 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11618 | NULL |
| 11619 | }; |
| 11620 | |
| 11621 | static struct attribute_group ipw_attribute_group = { |
| 11622 | .name = NULL, /* put in device directory */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11623 | .attrs = ipw_sysfs_entries, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11624 | }; |
| 11625 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11626 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11627 | static int ipw_prom_open(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->open\n"); |
| 11633 | netif_carrier_off(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11634 | |
| 11635 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11636 | priv->sys_config.accept_all_data_frames = 1; |
| 11637 | priv->sys_config.accept_non_directed_frames = 1; |
| 11638 | priv->sys_config.accept_all_mgmt_bcpr = 1; |
| 11639 | priv->sys_config.accept_all_mgmt_frames = 1; |
| 11640 | |
| 11641 | ipw_send_system_config(priv); |
| 11642 | } |
| 11643 | |
| 11644 | return 0; |
| 11645 | } |
| 11646 | |
| 11647 | static int ipw_prom_stop(struct net_device *dev) |
| 11648 | { |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11649 | struct ipw_prom_priv *prom_priv = libipw_priv(dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11650 | struct ipw_priv *priv = prom_priv->priv; |
| 11651 | |
| 11652 | IPW_DEBUG_INFO("prom dev->stop\n"); |
| 11653 | |
| 11654 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 11655 | priv->sys_config.accept_all_data_frames = 0; |
| 11656 | priv->sys_config.accept_non_directed_frames = 0; |
| 11657 | priv->sys_config.accept_all_mgmt_bcpr = 0; |
| 11658 | priv->sys_config.accept_all_mgmt_frames = 0; |
| 11659 | |
| 11660 | ipw_send_system_config(priv); |
| 11661 | } |
| 11662 | |
| 11663 | return 0; |
| 11664 | } |
| 11665 | |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 11666 | static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb, |
| 11667 | struct net_device *dev) |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11668 | { |
| 11669 | IPW_DEBUG_INFO("prom dev->xmit\n"); |
Patrick McHardy | 4153e77 | 2009-06-12 04:08:02 +0000 | [diff] [blame] | 11670 | dev_kfree_skb(skb); |
| 11671 | return NETDEV_TX_OK; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11672 | } |
| 11673 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11674 | static const struct net_device_ops ipw_prom_netdev_ops = { |
| 11675 | .ndo_open = ipw_prom_open, |
| 11676 | .ndo_stop = ipw_prom_stop, |
| 11677 | .ndo_start_xmit = ipw_prom_hard_start_xmit, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11678 | .ndo_change_mtu = libipw_change_mtu, |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11679 | .ndo_set_mac_address = eth_mac_addr, |
| 11680 | .ndo_validate_addr = eth_validate_addr, |
| 11681 | }; |
| 11682 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11683 | static int ipw_prom_alloc(struct ipw_priv *priv) |
| 11684 | { |
| 11685 | int rc = 0; |
| 11686 | |
| 11687 | if (priv->prom_net_dev) |
| 11688 | return -EPERM; |
| 11689 | |
Pavel Roskin | 27ae60f | 2010-03-12 00:01:22 -0500 | [diff] [blame] | 11690 | priv->prom_net_dev = alloc_libipw(sizeof(struct ipw_prom_priv), 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11691 | if (priv->prom_net_dev == NULL) |
| 11692 | return -ENOMEM; |
| 11693 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11694 | priv->prom_priv = libipw_priv(priv->prom_net_dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11695 | priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev); |
| 11696 | priv->prom_priv->priv = priv; |
| 11697 | |
| 11698 | strcpy(priv->prom_net_dev->name, "rtap%d"); |
Daniel Drake | 3f2eeac | 2008-04-02 20:33:54 +0100 | [diff] [blame] | 11699 | memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11700 | |
| 11701 | priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11702 | priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11703 | |
| 11704 | priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR; |
Masakazu Mokuno | 229ce3a | 2008-05-14 14:16:50 +0900 | [diff] [blame] | 11705 | SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11706 | |
| 11707 | rc = register_netdev(priv->prom_net_dev); |
| 11708 | if (rc) { |
Pavel Roskin | 27ae60f | 2010-03-12 00:01:22 -0500 | [diff] [blame] | 11709 | free_libipw(priv->prom_net_dev, 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11710 | priv->prom_net_dev = NULL; |
| 11711 | return rc; |
| 11712 | } |
| 11713 | |
| 11714 | return 0; |
| 11715 | } |
| 11716 | |
| 11717 | static void ipw_prom_free(struct ipw_priv *priv) |
| 11718 | { |
| 11719 | if (!priv->prom_net_dev) |
| 11720 | return; |
| 11721 | |
| 11722 | unregister_netdev(priv->prom_net_dev); |
Pavel Roskin | 27ae60f | 2010-03-12 00:01:22 -0500 | [diff] [blame] | 11723 | free_libipw(priv->prom_net_dev, 1); |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11724 | |
| 11725 | priv->prom_net_dev = NULL; |
| 11726 | } |
| 11727 | |
| 11728 | #endif |
| 11729 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11730 | static const struct net_device_ops ipw_netdev_ops = { |
| 11731 | .ndo_init = ipw_net_init, |
| 11732 | .ndo_open = ipw_net_open, |
| 11733 | .ndo_stop = ipw_net_stop, |
| 11734 | .ndo_set_multicast_list = ipw_net_set_multicast_list, |
| 11735 | .ndo_set_mac_address = ipw_net_set_mac_address, |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11736 | .ndo_start_xmit = libipw_xmit, |
| 11737 | .ndo_change_mtu = libipw_change_mtu, |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11738 | .ndo_validate_addr = eth_validate_addr, |
| 11739 | }; |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11740 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 11741 | static int __devinit ipw_pci_probe(struct pci_dev *pdev, |
| 11742 | const struct pci_device_id *ent) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11743 | { |
| 11744 | int err = 0; |
| 11745 | struct net_device *net_dev; |
| 11746 | void __iomem *base; |
| 11747 | u32 length, val; |
| 11748 | struct ipw_priv *priv; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11749 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11750 | |
Pavel Roskin | 27ae60f | 2010-03-12 00:01:22 -0500 | [diff] [blame] | 11751 | net_dev = alloc_libipw(sizeof(struct ipw_priv), 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11752 | if (net_dev == NULL) { |
| 11753 | err = -ENOMEM; |
| 11754 | goto out; |
| 11755 | } |
| 11756 | |
John W. Linville | b0a4e7d | 2009-08-20 14:48:03 -0400 | [diff] [blame] | 11757 | priv = libipw_priv(net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11758 | priv->ieee = netdev_priv(net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11759 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11760 | priv->net_dev = net_dev; |
| 11761 | priv->pci_dev = pdev; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11762 | ipw_debug_level = debug; |
Zhu Yi | 89c318e | 2006-06-08 22:19:49 -0700 | [diff] [blame] | 11763 | spin_lock_init(&priv->irq_lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11764 | spin_lock_init(&priv->lock); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11765 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
| 11766 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11767 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11768 | mutex_init(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11769 | if (pci_enable_device(pdev)) { |
| 11770 | err = -ENODEV; |
Pavel Roskin | 27ae60f | 2010-03-12 00:01:22 -0500 | [diff] [blame] | 11771 | goto out_free_libipw; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11772 | } |
| 11773 | |
| 11774 | pci_set_master(pdev); |
| 11775 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 11776 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11777 | if (!err) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 11778 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11779 | if (err) { |
| 11780 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 11781 | goto out_pci_disable_device; |
| 11782 | } |
| 11783 | |
| 11784 | pci_set_drvdata(pdev, priv); |
| 11785 | |
| 11786 | err = pci_request_regions(pdev, DRV_NAME); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11787 | if (err) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11788 | goto out_pci_disable_device; |
| 11789 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11790 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11791 | * PCI Tx retries from interfering with C3 CPU state */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11792 | pci_read_config_dword(pdev, 0x40, &val); |
| 11793 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11794 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11795 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11796 | length = pci_resource_len(pdev, 0); |
| 11797 | priv->hw_len = length; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11798 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 11799 | base = pci_ioremap_bar(pdev, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11800 | if (!base) { |
| 11801 | err = -ENODEV; |
| 11802 | goto out_pci_release_regions; |
| 11803 | } |
| 11804 | |
| 11805 | priv->hw_base = base; |
| 11806 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); |
| 11807 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); |
| 11808 | |
| 11809 | err = ipw_setup_deferred_work(priv); |
| 11810 | if (err) { |
| 11811 | IPW_ERROR("Unable to setup deferred work\n"); |
| 11812 | goto out_iounmap; |
| 11813 | } |
| 11814 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11815 | ipw_sw_reset(priv, 1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11816 | |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 11817 | err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11818 | if (err) { |
| 11819 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 11820 | goto out_destroy_workqueue; |
| 11821 | } |
| 11822 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11823 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
| 11824 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11825 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11826 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11827 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
| 11828 | priv->ieee->set_security = shim__set_security; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 11829 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11830 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11831 | #ifdef CONFIG_IPW2200_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame] | 11832 | priv->ieee->is_qos_active = ipw_is_qos_active; |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 11833 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
| 11834 | priv->ieee->handle_beacon = ipw_handle_probe_response; |
| 11835 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 11836 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11837 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11838 | priv->ieee->perfect_rssi = -20; |
| 11839 | priv->ieee->worst_rssi = -85; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11840 | |
Stephen Hemminger | 44e9ad0 | 2009-03-20 19:36:41 +0000 | [diff] [blame] | 11841 | net_dev->netdev_ops = &ipw_netdev_ops; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11842 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11843 | net_dev->wireless_data = &priv->wireless_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11844 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
| 11845 | net_dev->ethtool_ops = &ipw_ethtool_ops; |
| 11846 | net_dev->irq = pdev->irq; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11847 | net_dev->base_addr = (unsigned long)priv->hw_base; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11848 | net_dev->mem_start = pci_resource_start(pdev, 0); |
| 11849 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; |
| 11850 | |
| 11851 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11852 | if (err) { |
| 11853 | IPW_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11854 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11855 | goto out_release_irq; |
| 11856 | } |
| 11857 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11858 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11859 | err = register_netdev(net_dev); |
| 11860 | if (err) { |
| 11861 | IPW_ERROR("failed to register network device\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11862 | goto out_remove_sysfs; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11863 | } |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11864 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11865 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11866 | if (rtap_iface) { |
| 11867 | err = ipw_prom_alloc(priv); |
| 11868 | if (err) { |
| 11869 | IPW_ERROR("Failed to register promiscuous network " |
| 11870 | "device (error %d).\n", err); |
| 11871 | unregister_netdev(priv->net_dev); |
| 11872 | goto out_remove_sysfs; |
| 11873 | } |
| 11874 | } |
| 11875 | #endif |
| 11876 | |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11877 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " |
| 11878 | "channels, %d 802.11a channels)\n", |
| 11879 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, |
| 11880 | priv->ieee->geo.a_channels); |
| 11881 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11882 | return 0; |
| 11883 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11884 | out_remove_sysfs: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11885 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11886 | out_release_irq: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11887 | free_irq(pdev->irq, priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11888 | out_destroy_workqueue: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11889 | destroy_workqueue(priv->workqueue); |
| 11890 | priv->workqueue = NULL; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11891 | out_iounmap: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11892 | iounmap(priv->hw_base); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11893 | out_pci_release_regions: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11894 | pci_release_regions(pdev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11895 | out_pci_disable_device: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11896 | pci_disable_device(pdev); |
| 11897 | pci_set_drvdata(pdev, NULL); |
Pavel Roskin | 27ae60f | 2010-03-12 00:01:22 -0500 | [diff] [blame] | 11898 | out_free_libipw: |
| 11899 | free_libipw(priv->net_dev, 0); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11900 | out: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11901 | return err; |
| 11902 | } |
| 11903 | |
Adrian Bunk | 2ef19e6 | 2007-12-11 23:20:22 +0100 | [diff] [blame] | 11904 | static void __devexit ipw_pci_remove(struct pci_dev *pdev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11905 | { |
| 11906 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11907 | struct list_head *p, *q; |
| 11908 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11909 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11910 | if (!priv) |
| 11911 | return; |
| 11912 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11913 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11914 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11915 | priv->status |= STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11916 | ipw_down(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11917 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11918 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11919 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11920 | |
| 11921 | unregister_netdev(priv->net_dev); |
| 11922 | |
| 11923 | if (priv->rxq) { |
| 11924 | ipw_rx_queue_free(priv, priv->rxq); |
| 11925 | priv->rxq = NULL; |
| 11926 | } |
| 11927 | ipw_tx_queue_free(priv); |
| 11928 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11929 | if (priv->cmdlog) { |
| 11930 | kfree(priv->cmdlog); |
| 11931 | priv->cmdlog = NULL; |
| 11932 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11933 | /* ipw_down will ensure that there is no more pending work |
| 11934 | * in the workqueue's, so we can safely remove them now. */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11935 | cancel_delayed_work(&priv->adhoc_check); |
| 11936 | cancel_delayed_work(&priv->gather_stats); |
| 11937 | cancel_delayed_work(&priv->request_scan); |
Dan Williams | ea17730 | 2008-06-02 17:51:23 -0400 | [diff] [blame] | 11938 | cancel_delayed_work(&priv->request_direct_scan); |
| 11939 | cancel_delayed_work(&priv->request_passive_scan); |
Dan Williams | 0b53167 | 2007-10-09 13:55:24 -0400 | [diff] [blame] | 11940 | cancel_delayed_work(&priv->scan_event); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11941 | cancel_delayed_work(&priv->rf_kill); |
| 11942 | cancel_delayed_work(&priv->scan_check); |
| 11943 | destroy_workqueue(priv->workqueue); |
| 11944 | priv->workqueue = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11945 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11946 | /* Free MAC hash list for ADHOC */ |
| 11947 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { |
| 11948 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11949 | list_del(p); |
Zhu Yi | 489f445 | 2006-01-24 16:37:41 +0800 | [diff] [blame] | 11950 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11951 | } |
| 11952 | } |
| 11953 | |
Jesper Juhl | 8f76078 | 2006-06-27 02:55:06 -0700 | [diff] [blame] | 11954 | kfree(priv->error); |
| 11955 | priv->error = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11956 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 11957 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 11958 | ipw_prom_free(priv); |
| 11959 | #endif |
| 11960 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11961 | free_irq(pdev->irq, priv); |
| 11962 | iounmap(priv->hw_base); |
| 11963 | pci_release_regions(pdev); |
| 11964 | pci_disable_device(pdev); |
| 11965 | pci_set_drvdata(pdev, NULL); |
Pavel Roskin | 27ae60f | 2010-03-12 00:01:22 -0500 | [diff] [blame] | 11966 | /* wiphy_unregister needs to be here, before free_libipw */ |
John W. Linville | a3caa99 | 2009-08-25 14:12:25 -0400 | [diff] [blame] | 11967 | wiphy_unregister(priv->ieee->wdev.wiphy); |
| 11968 | kfree(priv->ieee->a_band.channels); |
| 11969 | kfree(priv->ieee->bg_band.channels); |
Pavel Roskin | 27ae60f | 2010-03-12 00:01:22 -0500 | [diff] [blame] | 11970 | free_libipw(priv->net_dev, 0); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11971 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11972 | } |
| 11973 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11974 | #ifdef CONFIG_PM |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11975 | 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] | 11976 | { |
| 11977 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11978 | struct net_device *dev = priv->net_dev; |
| 11979 | |
| 11980 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); |
| 11981 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11982 | /* Take down the device; powers it off, etc. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11983 | ipw_down(priv); |
| 11984 | |
| 11985 | /* Remove the PRESENT state of the device */ |
| 11986 | netif_device_detach(dev); |
| 11987 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11988 | pci_save_state(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11989 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11990 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11991 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 11992 | priv->suspend_at = get_seconds(); |
| 11993 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11994 | return 0; |
| 11995 | } |
| 11996 | |
| 11997 | static int ipw_pci_resume(struct pci_dev *pdev) |
| 11998 | { |
| 11999 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 12000 | struct net_device *dev = priv->net_dev; |
John W. Linville | 02e0e5e | 2006-11-07 20:53:48 -0500 | [diff] [blame] | 12001 | int err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12002 | u32 val; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 12003 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12004 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
| 12005 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 12006 | pci_set_power_state(pdev, PCI_D0); |
John W. Linville | 02e0e5e | 2006-11-07 20:53:48 -0500 | [diff] [blame] | 12007 | err = pci_enable_device(pdev); |
| 12008 | if (err) { |
| 12009 | printk(KERN_ERR "%s: pci_enable_device failed on resume\n", |
| 12010 | dev->name); |
| 12011 | return err; |
| 12012 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12013 | pci_restore_state(pdev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 12014 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12015 | /* |
| 12016 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 12017 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 12018 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 12019 | * here since it only restores the first 64 bytes pci config header. |
| 12020 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 12021 | pci_read_config_dword(pdev, 0x40, &val); |
| 12022 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12023 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 12024 | |
| 12025 | /* Set the device back into the PRESENT state; this will also wake |
| 12026 | * the queue of needed */ |
| 12027 | netif_device_attach(dev); |
| 12028 | |
Dan Williams | c3d72b9 | 2009-02-11 13:26:06 -0500 | [diff] [blame] | 12029 | priv->suspend_time = get_seconds() - priv->suspend_at; |
| 12030 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12031 | /* Bring the device back up */ |
| 12032 | queue_work(priv->workqueue, &priv->up); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 12033 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12034 | return 0; |
| 12035 | } |
| 12036 | #endif |
| 12037 | |
Zhu Yi | c8c22c9 | 2006-08-21 11:38:39 +0800 | [diff] [blame] | 12038 | static void ipw_pci_shutdown(struct pci_dev *pdev) |
| 12039 | { |
| 12040 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 12041 | |
| 12042 | /* Take down the device; powers it off, etc. */ |
| 12043 | ipw_down(priv); |
| 12044 | |
| 12045 | pci_disable_device(pdev); |
| 12046 | } |
| 12047 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12048 | /* driver initialization stuff */ |
| 12049 | static struct pci_driver ipw_driver = { |
| 12050 | .name = DRV_NAME, |
| 12051 | .id_table = card_ids, |
| 12052 | .probe = ipw_pci_probe, |
| 12053 | .remove = __devexit_p(ipw_pci_remove), |
| 12054 | #ifdef CONFIG_PM |
| 12055 | .suspend = ipw_pci_suspend, |
| 12056 | .resume = ipw_pci_resume, |
| 12057 | #endif |
Zhu Yi | c8c22c9 | 2006-08-21 11:38:39 +0800 | [diff] [blame] | 12058 | .shutdown = ipw_pci_shutdown, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12059 | }; |
| 12060 | |
| 12061 | static int __init ipw_init(void) |
| 12062 | { |
| 12063 | int ret; |
| 12064 | |
| 12065 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 12066 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 12067 | |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 12068 | ret = pci_register_driver(&ipw_driver); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12069 | if (ret) { |
| 12070 | IPW_ERROR("Unable to initialize PCI module\n"); |
| 12071 | return ret; |
| 12072 | } |
| 12073 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 12074 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12075 | if (ret) { |
| 12076 | IPW_ERROR("Unable to create driver sysfs file\n"); |
| 12077 | pci_unregister_driver(&ipw_driver); |
| 12078 | return ret; |
| 12079 | } |
| 12080 | |
| 12081 | return ret; |
| 12082 | } |
| 12083 | |
| 12084 | static void __exit ipw_exit(void) |
| 12085 | { |
| 12086 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); |
| 12087 | pci_unregister_driver(&ipw_driver); |
| 12088 | } |
| 12089 | |
| 12090 | module_param(disable, int, 0444); |
| 12091 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 12092 | |
| 12093 | module_param(associate, int, 0444); |
Tim Gardner | 5c7f9b7 | 2008-10-14 10:38:03 -0600 | [diff] [blame] | 12094 | MODULE_PARM_DESC(associate, "auto associate when scanning (default off)"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12095 | |
| 12096 | module_param(auto_create, int, 0444); |
| 12097 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); |
| 12098 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12099 | module_param_named(led, led_support, int, 0444); |
ubuntu@tjworld.net | c086aba | 2009-03-23 20:29:28 +0000 | [diff] [blame] | 12100 | MODULE_PARM_DESC(led, "enable led control on some systems (default 1 on)"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 12101 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12102 | module_param(debug, int, 0444); |
| 12103 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 12104 | |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12105 | module_param_named(channel, default_channel, int, 0444); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 12106 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12107 | |
Zhu Yi | d685b8c | 2006-04-13 17:20:27 +0800 | [diff] [blame] | 12108 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
| 12109 | module_param(rtap_iface, int, 0444); |
| 12110 | MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)"); |
| 12111 | #endif |
| 12112 | |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 12113 | #ifdef CONFIG_IPW2200_QOS |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12114 | module_param(qos_enable, int, 0444); |
| 12115 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12116 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12117 | module_param(qos_burst_enable, int, 0444); |
| 12118 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); |
| 12119 | |
| 12120 | module_param(qos_no_ack_mask, int, 0444); |
| 12121 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); |
| 12122 | |
| 12123 | module_param(burst_duration_CCK, int, 0444); |
| 12124 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); |
| 12125 | |
| 12126 | module_param(burst_duration_OFDM, int, 0444); |
| 12127 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); |
Zhu Yi | e43e3c1 | 2006-04-13 17:20:45 +0800 | [diff] [blame] | 12128 | #endif /* CONFIG_IPW2200_QOS */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12129 | |
| 12130 | #ifdef CONFIG_IPW2200_MONITOR |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12131 | module_param_named(mode, network_mode, int, 0444); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12132 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); |
| 12133 | #else |
Reinette Chatre | 21f8a73 | 2009-08-18 10:25:05 -0700 | [diff] [blame] | 12134 | module_param_named(mode, network_mode, int, 0444); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12135 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
| 12136 | #endif |
| 12137 | |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 12138 | module_param(bt_coexist, int, 0444); |
| 12139 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); |
| 12140 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12141 | module_param(hwcrypto, int, 0444); |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 12142 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 12143 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 12144 | module_param(cmdlog, int, 0444); |
| 12145 | MODULE_PARM_DESC(cmdlog, |
| 12146 | "allocate a ring buffer for logging firmware commands"); |
| 12147 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 12148 | module_param(roaming, int, 0444); |
| 12149 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); |
| 12150 | |
Zhu Yi | d2b83e1 | 2006-04-13 17:19:36 +0800 | [diff] [blame] | 12151 | module_param(antenna, int, 0444); |
| 12152 | MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)"); |
| 12153 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 12154 | module_exit(ipw_exit); |
| 12155 | module_init(ipw_init); |