James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2 | |
Zhu Yi | 171e7b2 | 2006-02-15 07:17:56 +0800 | [diff] [blame] | 3 | Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4 | |
| 5 | 802.11 status code portion of this file from ethereal-0.10.6: |
| 6 | Copyright 2000, Axis Communications AB |
| 7 | Ethereal - Network traffic analyzer |
| 8 | By Gerald Combs <gerald@ethereal.com> |
| 9 | Copyright 1998 Gerald Combs |
| 10 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11 | This program is free software; you can redistribute it and/or modify it |
| 12 | under the terms of version 2 of the GNU General Public License as |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 13 | published by the Free Software Foundation. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 14 | |
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 18 | more details. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 19 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 20 | You should have received a copy of the GNU General Public License along with |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 21 | this program; if not, write to the Free Software Foundation, Inc., 59 |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 22 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 23 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 24 | The full GNU General Public License is included in this distribution in the |
| 25 | file called LICENSE. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 26 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 27 | Contact Information: |
| 28 | James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 29 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | |
| 31 | ******************************************************************************/ |
| 32 | |
| 33 | #include "ipw2200.h" |
Olaf Hering | 733482e | 2005-11-08 21:34:55 -0800 | [diff] [blame] | 34 | #include <linux/version.h> |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 35 | |
Zhu Yi | 7c56789 | 2006-02-24 04:20:48 +0800 | [diff] [blame] | 36 | #define IPW2200_VERSION "git-1.1.1" |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 37 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" |
Zhu Yi | 171e7b2 | 2006-02-15 07:17:56 +0800 | [diff] [blame] | 38 | #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation" |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 39 | #define DRV_VERSION IPW2200_VERSION |
| 40 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 41 | #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1) |
| 42 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 43 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 44 | MODULE_VERSION(DRV_VERSION); |
| 45 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 46 | MODULE_LICENSE("GPL"); |
| 47 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 48 | static int cmdlog = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 49 | static int debug = 0; |
| 50 | static int channel = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 51 | static int mode = 0; |
| 52 | |
| 53 | static u32 ipw_debug_level; |
| 54 | static int associate = 1; |
| 55 | static int auto_create = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 56 | static int led = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 57 | static int disable = 0; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 58 | static int bt_coexist = 0; |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 59 | static int hwcrypto = 0; |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 60 | static int roaming = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 61 | static const char ipw_modes[] = { |
| 62 | 'a', 'b', 'g', '?' |
| 63 | }; |
| 64 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 65 | #ifdef CONFIG_IPW_QOS |
| 66 | static int qos_enable = 0; |
| 67 | static int qos_burst_enable = 0; |
| 68 | static int qos_no_ack_mask = 0; |
| 69 | static int burst_duration_CCK = 0; |
| 70 | static int burst_duration_OFDM = 0; |
| 71 | |
| 72 | static struct ieee80211_qos_parameters def_qos_parameters_OFDM = { |
| 73 | {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, |
| 74 | QOS_TX3_CW_MIN_OFDM}, |
| 75 | {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, |
| 76 | QOS_TX3_CW_MAX_OFDM}, |
| 77 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 78 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 79 | {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, |
| 80 | QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} |
| 81 | }; |
| 82 | |
| 83 | static struct ieee80211_qos_parameters def_qos_parameters_CCK = { |
| 84 | {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, |
| 85 | QOS_TX3_CW_MIN_CCK}, |
| 86 | {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, |
| 87 | QOS_TX3_CW_MAX_CCK}, |
| 88 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 89 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 90 | {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, |
| 91 | QOS_TX3_TXOP_LIMIT_CCK} |
| 92 | }; |
| 93 | |
| 94 | static struct ieee80211_qos_parameters def_parameters_OFDM = { |
| 95 | {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, |
| 96 | DEF_TX3_CW_MIN_OFDM}, |
| 97 | {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, |
| 98 | DEF_TX3_CW_MAX_OFDM}, |
| 99 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 100 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 101 | {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, |
| 102 | DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} |
| 103 | }; |
| 104 | |
| 105 | static struct ieee80211_qos_parameters def_parameters_CCK = { |
| 106 | {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, |
| 107 | DEF_TX3_CW_MIN_CCK}, |
| 108 | {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, |
| 109 | DEF_TX3_CW_MAX_CCK}, |
| 110 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 111 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 112 | {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, |
| 113 | DEF_TX3_TXOP_LIMIT_CCK} |
| 114 | }; |
| 115 | |
| 116 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; |
| 117 | |
| 118 | static int from_priority_to_tx_queue[] = { |
| 119 | IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, |
| 120 | IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 |
| 121 | }; |
| 122 | |
| 123 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); |
| 124 | |
| 125 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
| 126 | *qos_param); |
| 127 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element |
| 128 | *qos_param); |
| 129 | #endif /* CONFIG_IPW_QOS */ |
| 130 | |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 131 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 132 | static void ipw_remove_current_network(struct ipw_priv *priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 133 | static void ipw_rx(struct ipw_priv *priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 134 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 135 | struct clx2_tx_queue *txq, int qindex); |
| 136 | static int ipw_queue_reset(struct ipw_priv *priv); |
| 137 | |
| 138 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 139 | int len, int sync); |
| 140 | |
| 141 | static void ipw_tx_queue_free(struct ipw_priv *); |
| 142 | |
| 143 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); |
| 144 | static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); |
| 145 | static void ipw_rx_queue_replenish(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 146 | static int ipw_up(struct ipw_priv *); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 147 | static void ipw_bg_up(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 148 | static void ipw_down(struct ipw_priv *); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 149 | static void ipw_bg_down(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 150 | static int ipw_config(struct ipw_priv *); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 151 | static int init_supported_rates(struct ipw_priv *priv, |
| 152 | struct ipw_supported_rates *prates); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 153 | static void ipw_set_hwcrypto_keys(struct ipw_priv *); |
| 154 | static void ipw_send_wep_keys(struct ipw_priv *, int); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 155 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 156 | static int snprint_line(char *buf, size_t count, |
| 157 | const u8 * data, u32 len, u32 ofs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 158 | { |
| 159 | int out, i, j, l; |
| 160 | char c; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 161 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 162 | out = snprintf(buf, count, "%08X", ofs); |
| 163 | |
| 164 | for (l = 0, i = 0; i < 2; i++) { |
| 165 | out += snprintf(buf + out, count - out, " "); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 166 | for (j = 0; j < 8 && l < len; j++, l++) |
| 167 | out += snprintf(buf + out, count - out, "%02X ", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 168 | data[(i * 8 + j)]); |
| 169 | for (; j < 8; j++) |
| 170 | out += snprintf(buf + out, count - out, " "); |
| 171 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 172 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 173 | out += snprintf(buf + out, count - out, " "); |
| 174 | for (l = 0, i = 0; i < 2; i++) { |
| 175 | out += snprintf(buf + out, count - out, " "); |
| 176 | for (j = 0; j < 8 && l < len; j++, l++) { |
| 177 | c = data[(i * 8 + j)]; |
| 178 | if (!isascii(c) || !isprint(c)) |
| 179 | c = '.'; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 180 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 181 | out += snprintf(buf + out, count - out, "%c", c); |
| 182 | } |
| 183 | |
| 184 | for (; j < 8; j++) |
| 185 | out += snprintf(buf + out, count - out, " "); |
| 186 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 187 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 188 | return out; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 189 | } |
| 190 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 191 | static void printk_buf(int level, const u8 * data, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 192 | { |
| 193 | char line[81]; |
| 194 | u32 ofs = 0; |
| 195 | if (!(ipw_debug_level & level)) |
| 196 | return; |
| 197 | |
| 198 | while (len) { |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 199 | snprint_line(line, sizeof(line), &data[ofs], |
| 200 | min(len, 16U), ofs); |
| 201 | printk(KERN_DEBUG "%s\n", line); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 202 | ofs += 16; |
| 203 | len -= min(len, 16U); |
| 204 | } |
| 205 | } |
| 206 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 207 | static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len) |
| 208 | { |
| 209 | size_t out = size; |
| 210 | u32 ofs = 0; |
| 211 | int total = 0; |
| 212 | |
| 213 | while (size && len) { |
| 214 | out = snprint_line(output, size, &data[ofs], |
| 215 | min_t(size_t, len, 16U), ofs); |
| 216 | |
| 217 | ofs += 16; |
| 218 | output += out; |
| 219 | size -= out; |
| 220 | len -= min_t(size_t, len, 16U); |
| 221 | total += out; |
| 222 | } |
| 223 | return total; |
| 224 | } |
| 225 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 226 | /* 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] | 227 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); |
| 228 | #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) |
| 229 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 230 | /* 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] | 231 | static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); |
| 232 | #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) |
| 233 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 234 | /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 235 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); |
| 236 | static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) |
| 237 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 238 | IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, |
| 239 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 240 | _ipw_write_reg8(a, b, c); |
| 241 | } |
| 242 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 243 | /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 244 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); |
| 245 | static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) |
| 246 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 247 | IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, |
| 248 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 249 | _ipw_write_reg16(a, b, c); |
| 250 | } |
| 251 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 252 | /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 253 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); |
| 254 | static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) |
| 255 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 256 | IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, |
| 257 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 258 | _ipw_write_reg32(a, b, c); |
| 259 | } |
| 260 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 261 | /* 8-bit direct write (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 262 | #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 263 | |
| 264 | /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 265 | #define ipw_write8(ipw, ofs, val) \ |
| 266 | IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 267 | _ipw_write8(ipw, ofs, val) |
| 268 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 269 | /* 16-bit direct write (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 270 | #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 271 | |
| 272 | /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 273 | #define ipw_write16(ipw, ofs, val) \ |
| 274 | IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 275 | _ipw_write16(ipw, ofs, val) |
| 276 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 277 | /* 32-bit direct write (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 278 | #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 279 | |
| 280 | /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 281 | #define ipw_write32(ipw, ofs, val) \ |
| 282 | IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 283 | _ipw_write32(ipw, ofs, val) |
| 284 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 285 | /* 8-bit direct read (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 286 | #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 287 | |
| 288 | /* 8-bit direct read (low 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 289 | static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 290 | { |
| 291 | IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 292 | return _ipw_read8(ipw, ofs); |
| 293 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 294 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 295 | /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 296 | #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs) |
| 297 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 298 | /* 16-bit direct read (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 299 | #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 300 | |
| 301 | /* 16-bit direct read (low 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 302 | static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 303 | { |
| 304 | IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 305 | return _ipw_read16(ipw, ofs); |
| 306 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 307 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 308 | /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 309 | #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs) |
| 310 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 311 | /* 32-bit direct read (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 312 | #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 313 | |
| 314 | /* 32-bit direct read (low 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 315 | static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 316 | { |
| 317 | IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 318 | return _ipw_read32(ipw, ofs); |
| 319 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 320 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 321 | /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 322 | #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs) |
| 323 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 324 | /* multi-byte read (above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 325 | static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 326 | static inline void __ipw_read_indirect(const char *f, int l, |
| 327 | struct ipw_priv *a, u32 b, u8 * c, int d) |
| 328 | { |
| 329 | IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b), |
| 330 | d); |
| 331 | _ipw_read_indirect(a, b, c, d); |
| 332 | } |
| 333 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 334 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 335 | #define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 336 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 337 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 338 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, |
| 339 | int num); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 340 | #define ipw_write_indirect(a, b, c, d) \ |
| 341 | IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 342 | _ipw_write_indirect(a, b, c, d) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 343 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 344 | /* 32-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 345 | 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] | 346 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 347 | 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] | 348 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 349 | _ipw_write32(priv, IPW_INDIRECT_DATA, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 350 | } |
| 351 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 352 | /* 8-bit indirect write (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 353 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) |
| 354 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 355 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 356 | u32 dif_len = reg - aligned_addr; |
| 357 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 358 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 359 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 360 | _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 361 | } |
| 362 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 363 | /* 16-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 364 | 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] | 365 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 366 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 367 | u32 dif_len = (reg - aligned_addr) & (~0x1ul); |
| 368 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 369 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 370 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 371 | _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 372 | } |
| 373 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 374 | /* 8-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 375 | static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) |
| 376 | { |
| 377 | u32 word; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 378 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 379 | IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 380 | word = _ipw_read32(priv, IPW_INDIRECT_DATA); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 381 | return (word >> ((reg & 0x3) * 8)) & 0xff; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 382 | } |
| 383 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 384 | /* 32-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 385 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) |
| 386 | { |
| 387 | u32 value; |
| 388 | |
| 389 | IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); |
| 390 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 391 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 392 | value = _ipw_read32(priv, IPW_INDIRECT_DATA); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 393 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); |
| 394 | return value; |
| 395 | } |
| 396 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 397 | /* General purpose, no alignment requirement, iterative (multi-byte) read, */ |
| 398 | /* for area above 1st 4K of SRAM/reg space */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 399 | static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
| 400 | int num) |
| 401 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 402 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 403 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 404 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 405 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 406 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
| 407 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 408 | if (num <= 0) { |
| 409 | return; |
| 410 | } |
| 411 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 412 | /* Read the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 413 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 414 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 415 | /* Start reading at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 416 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 417 | *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 418 | aligned_addr += 4; |
| 419 | } |
| 420 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 421 | /* Read all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 422 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 423 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 424 | *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 425 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 426 | /* Read the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 427 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 428 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 429 | for (i = 0; num > 0; i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 430 | *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 431 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 432 | } |
| 433 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 434 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 435 | /* for area above 1st 4K of SRAM/reg space */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 436 | 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] | 437 | int num) |
| 438 | { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 439 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 440 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 441 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 442 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 443 | 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] | 444 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 445 | if (num <= 0) { |
| 446 | return; |
| 447 | } |
| 448 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 449 | /* Write the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 450 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 451 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 452 | /* Start writing at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 453 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 454 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 455 | aligned_addr += 4; |
| 456 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 457 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 458 | /* Write all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 459 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 460 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 461 | _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 462 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 463 | /* Write the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 464 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 465 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 466 | for (i = 0; num > 0; i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 467 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 468 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 469 | } |
| 470 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 471 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 472 | /* for 1st 4K of SRAM/regs space */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 473 | 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] | 474 | int num) |
| 475 | { |
| 476 | memcpy_toio((priv->hw_base + addr), buf, num); |
| 477 | } |
| 478 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 479 | /* Set bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 480 | static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 481 | { |
| 482 | ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); |
| 483 | } |
| 484 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 485 | /* Clear bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 486 | static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 487 | { |
| 488 | ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); |
| 489 | } |
| 490 | |
| 491 | static inline void ipw_enable_interrupts(struct ipw_priv *priv) |
| 492 | { |
| 493 | if (priv->status & STATUS_INT_ENABLED) |
| 494 | return; |
| 495 | priv->status |= STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 496 | ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static inline void ipw_disable_interrupts(struct ipw_priv *priv) |
| 500 | { |
| 501 | if (!(priv->status & STATUS_INT_ENABLED)) |
| 502 | return; |
| 503 | priv->status &= ~STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 504 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 505 | } |
| 506 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 507 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 508 | static char *ipw_error_desc(u32 val) |
| 509 | { |
| 510 | switch (val) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 511 | case IPW_FW_ERROR_OK: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 512 | return "ERROR_OK"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 513 | case IPW_FW_ERROR_FAIL: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 514 | return "ERROR_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 515 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 516 | return "MEMORY_UNDERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 517 | case IPW_FW_ERROR_MEMORY_OVERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 518 | return "MEMORY_OVERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 519 | case IPW_FW_ERROR_BAD_PARAM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 520 | return "BAD_PARAM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 521 | case IPW_FW_ERROR_BAD_CHECKSUM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 522 | return "BAD_CHECKSUM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 523 | case IPW_FW_ERROR_NMI_INTERRUPT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 524 | return "NMI_INTERRUPT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 525 | case IPW_FW_ERROR_BAD_DATABASE: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 526 | return "BAD_DATABASE"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 527 | case IPW_FW_ERROR_ALLOC_FAIL: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 528 | return "ALLOC_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 529 | case IPW_FW_ERROR_DMA_UNDERRUN: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 530 | return "DMA_UNDERRUN"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 531 | case IPW_FW_ERROR_DMA_STATUS: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 532 | return "DMA_STATUS"; |
| 533 | case IPW_FW_ERROR_DINO_ERROR: |
| 534 | return "DINO_ERROR"; |
| 535 | case IPW_FW_ERROR_EEPROM_ERROR: |
| 536 | return "EEPROM_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 537 | case IPW_FW_ERROR_SYSASSERT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 538 | return "SYSASSERT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 539 | case IPW_FW_ERROR_FATAL_ERROR: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 540 | return "FATAL_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 541 | default: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 542 | return "UNKNOWN_ERROR"; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 546 | static void ipw_dump_error_log(struct ipw_priv *priv, |
| 547 | struct ipw_fw_error *error) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 548 | { |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 549 | u32 i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 550 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 551 | if (!error) { |
| 552 | IPW_ERROR("Error allocating and capturing error log. " |
| 553 | "Nothing to dump.\n"); |
| 554 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 555 | } |
| 556 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 557 | IPW_ERROR("Start IPW Error Log Dump:\n"); |
| 558 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", |
| 559 | error->status, error->config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 560 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 561 | for (i = 0; i < error->elem_len; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 562 | 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] | 563 | ipw_error_desc(error->elem[i].desc), |
| 564 | error->elem[i].time, |
| 565 | error->elem[i].blink1, |
| 566 | error->elem[i].blink2, |
| 567 | error->elem[i].link1, |
| 568 | error->elem[i].link2, error->elem[i].data); |
| 569 | for (i = 0; i < error->log_len; i++) |
| 570 | IPW_ERROR("%i\t0x%08x\t%i\n", |
| 571 | error->log[i].time, |
James Ketrenos | 286568a | 2005-08-30 10:34:25 -0500 | [diff] [blame] | 572 | error->log[i].data, error->log[i].event); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 573 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 574 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 575 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 576 | static inline int ipw_is_init(struct ipw_priv *priv) |
| 577 | { |
| 578 | return (priv->status & STATUS_INIT) ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 579 | } |
| 580 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 581 | 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] | 582 | { |
| 583 | u32 addr, field_info, field_len, field_count, total_len; |
| 584 | |
| 585 | IPW_DEBUG_ORD("ordinal = %i\n", ord); |
| 586 | |
| 587 | if (!priv || !val || !len) { |
| 588 | IPW_DEBUG_ORD("Invalid argument\n"); |
| 589 | return -EINVAL; |
| 590 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 591 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 592 | /* verify device ordinal tables have been initialized */ |
| 593 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { |
| 594 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); |
| 595 | return -EINVAL; |
| 596 | } |
| 597 | |
| 598 | switch (IPW_ORD_TABLE_ID_MASK & ord) { |
| 599 | case IPW_ORD_TABLE_0_MASK: |
| 600 | /* |
| 601 | * TABLE 0: Direct access to a table of 32 bit values |
| 602 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 603 | * This is a very simple table with the data directly |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 604 | * read from the table |
| 605 | */ |
| 606 | |
| 607 | /* remove the table id from the ordinal */ |
| 608 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 609 | |
| 610 | /* boundary check */ |
| 611 | if (ord > priv->table0_len) { |
| 612 | IPW_DEBUG_ORD("ordinal value (%i) longer then " |
| 613 | "max (%i)\n", ord, priv->table0_len); |
| 614 | return -EINVAL; |
| 615 | } |
| 616 | |
| 617 | /* verify we have enough room to store the value */ |
| 618 | if (*len < sizeof(u32)) { |
| 619 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 620 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 621 | return -EINVAL; |
| 622 | } |
| 623 | |
| 624 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 625 | ord, priv->table0_addr + (ord << 2)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 626 | |
| 627 | *len = sizeof(u32); |
| 628 | ord <<= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 629 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 630 | break; |
| 631 | |
| 632 | case IPW_ORD_TABLE_1_MASK: |
| 633 | /* |
| 634 | * TABLE 1: Indirect access to a table of 32 bit values |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 635 | * |
| 636 | * This is a fairly large table of u32 values each |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 637 | * representing starting addr for the data (which is |
| 638 | * also a u32) |
| 639 | */ |
| 640 | |
| 641 | /* remove the table id from the ordinal */ |
| 642 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 643 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 644 | /* boundary check */ |
| 645 | if (ord > priv->table1_len) { |
| 646 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 647 | return -EINVAL; |
| 648 | } |
| 649 | |
| 650 | /* verify we have enough room to store the value */ |
| 651 | if (*len < sizeof(u32)) { |
| 652 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 653 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 654 | return -EINVAL; |
| 655 | } |
| 656 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 657 | *((u32 *) val) = |
| 658 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 659 | *len = sizeof(u32); |
| 660 | break; |
| 661 | |
| 662 | case IPW_ORD_TABLE_2_MASK: |
| 663 | /* |
| 664 | * TABLE 2: Indirect access to a table of variable sized values |
| 665 | * |
| 666 | * This table consist of six values, each containing |
| 667 | * - dword containing the starting offset of the data |
| 668 | * - dword containing the lengh in the first 16bits |
| 669 | * and the count in the second 16bits |
| 670 | */ |
| 671 | |
| 672 | /* remove the table id from the ordinal */ |
| 673 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 674 | |
| 675 | /* boundary check */ |
| 676 | if (ord > priv->table2_len) { |
| 677 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 678 | return -EINVAL; |
| 679 | } |
| 680 | |
| 681 | /* get the address of statistic */ |
| 682 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 683 | |
| 684 | /* get the second DW of statistics ; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 685 | * two 16-bit words - first is length, second is count */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 686 | field_info = |
| 687 | ipw_read_reg32(priv, |
| 688 | priv->table2_addr + (ord << 3) + |
| 689 | sizeof(u32)); |
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 | /* get each entry length */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 692 | field_len = *((u16 *) & field_info); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 693 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 694 | /* get number of entries */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 695 | field_count = *(((u16 *) & field_info) + 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 696 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 697 | /* abort if not enought memory */ |
| 698 | total_len = field_len * field_count; |
| 699 | if (total_len > *len) { |
| 700 | *len = total_len; |
| 701 | return -EINVAL; |
| 702 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 703 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 704 | *len = total_len; |
| 705 | if (!total_len) |
| 706 | return 0; |
| 707 | |
| 708 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 709 | "field_info = 0x%08x\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 710 | addr, total_len, field_info); |
| 711 | ipw_read_indirect(priv, addr, val, total_len); |
| 712 | break; |
| 713 | |
| 714 | default: |
| 715 | IPW_DEBUG_ORD("Invalid ordinal!\n"); |
| 716 | return -EINVAL; |
| 717 | |
| 718 | } |
| 719 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | static void ipw_init_ordinals(struct ipw_priv *priv) |
| 724 | { |
| 725 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 726 | priv->table0_len = ipw_read32(priv, priv->table0_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 727 | |
| 728 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", |
| 729 | priv->table0_addr, priv->table0_len); |
| 730 | |
| 731 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); |
| 732 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); |
| 733 | |
| 734 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", |
| 735 | priv->table1_addr, priv->table1_len); |
| 736 | |
| 737 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); |
| 738 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 739 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 740 | |
| 741 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", |
| 742 | priv->table2_addr, priv->table2_len); |
| 743 | |
| 744 | } |
| 745 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 746 | static u32 ipw_register_toggle(u32 reg) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 747 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 748 | reg &= ~IPW_START_STANDBY; |
| 749 | if (reg & IPW_GATE_ODMA) |
| 750 | reg &= ~IPW_GATE_ODMA; |
| 751 | if (reg & IPW_GATE_IDMA) |
| 752 | reg &= ~IPW_GATE_IDMA; |
| 753 | if (reg & IPW_GATE_ADMA) |
| 754 | reg &= ~IPW_GATE_ADMA; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 755 | return reg; |
| 756 | } |
| 757 | |
| 758 | /* |
| 759 | * LED behavior: |
| 760 | * - On radio ON, turn on any LEDs that require to be on during start |
| 761 | * - On initialization, start unassociated blink |
| 762 | * - On association, disable unassociated blink |
| 763 | * - On disassociation, start unassociated blink |
| 764 | * - On radio OFF, turn off any LEDs started during radio on |
| 765 | * |
| 766 | */ |
Zhu Yi | ede6111 | 2006-01-24 16:37:10 +0800 | [diff] [blame] | 767 | #define LD_TIME_LINK_ON msecs_to_jiffies(300) |
| 768 | #define LD_TIME_LINK_OFF msecs_to_jiffies(2700) |
| 769 | #define LD_TIME_ACT_ON msecs_to_jiffies(250) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 770 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 771 | static void ipw_led_link_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 772 | { |
| 773 | unsigned long flags; |
| 774 | u32 led; |
| 775 | |
| 776 | /* If configured to not use LEDs, or nic_type is 1, |
| 777 | * then we don't toggle a LINK led */ |
| 778 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 779 | return; |
| 780 | |
| 781 | spin_lock_irqsave(&priv->lock, flags); |
| 782 | |
| 783 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 784 | !(priv->status & STATUS_LED_LINK_ON)) { |
| 785 | IPW_DEBUG_LED("Link LED On\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 786 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 787 | led |= priv->led_association_on; |
| 788 | |
| 789 | led = ipw_register_toggle(led); |
| 790 | |
| 791 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 792 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 793 | |
| 794 | priv->status |= STATUS_LED_LINK_ON; |
| 795 | |
| 796 | /* If we aren't associated, schedule turning the LED off */ |
| 797 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 798 | queue_delayed_work(priv->workqueue, |
| 799 | &priv->led_link_off, |
| 800 | LD_TIME_LINK_ON); |
| 801 | } |
| 802 | |
| 803 | spin_unlock_irqrestore(&priv->lock, flags); |
| 804 | } |
| 805 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 806 | static void ipw_bg_led_link_on(void *data) |
| 807 | { |
| 808 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 809 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 810 | ipw_led_link_on(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 811 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 812 | } |
| 813 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 814 | static void ipw_led_link_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 815 | { |
| 816 | unsigned long flags; |
| 817 | u32 led; |
| 818 | |
| 819 | /* If configured not to use LEDs, or nic type is 1, |
| 820 | * then we don't goggle the LINK led. */ |
| 821 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 822 | return; |
| 823 | |
| 824 | spin_lock_irqsave(&priv->lock, flags); |
| 825 | |
| 826 | if (priv->status & STATUS_LED_LINK_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 827 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 828 | led &= priv->led_association_off; |
| 829 | led = ipw_register_toggle(led); |
| 830 | |
| 831 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 832 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 833 | |
| 834 | IPW_DEBUG_LED("Link LED Off\n"); |
| 835 | |
| 836 | priv->status &= ~STATUS_LED_LINK_ON; |
| 837 | |
| 838 | /* If we aren't associated and the radio is on, schedule |
| 839 | * turning the LED on (blink while unassociated) */ |
| 840 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 841 | !(priv->status & STATUS_ASSOCIATED)) |
| 842 | queue_delayed_work(priv->workqueue, &priv->led_link_on, |
| 843 | LD_TIME_LINK_OFF); |
| 844 | |
| 845 | } |
| 846 | |
| 847 | spin_unlock_irqrestore(&priv->lock, flags); |
| 848 | } |
| 849 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 850 | static void ipw_bg_led_link_off(void *data) |
| 851 | { |
| 852 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 853 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 854 | ipw_led_link_off(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 855 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 856 | } |
| 857 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 858 | static void __ipw_led_activity_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 859 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 860 | u32 led; |
| 861 | |
| 862 | if (priv->config & CFG_NO_LED) |
| 863 | return; |
| 864 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 865 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 866 | return; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 867 | |
| 868 | if (!(priv->status & STATUS_LED_ACT_ON)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 869 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 870 | led |= priv->led_activity_on; |
| 871 | |
| 872 | led = ipw_register_toggle(led); |
| 873 | |
| 874 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 875 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 876 | |
| 877 | IPW_DEBUG_LED("Activity LED On\n"); |
| 878 | |
| 879 | priv->status |= STATUS_LED_ACT_ON; |
| 880 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 881 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 882 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 883 | LD_TIME_ACT_ON); |
| 884 | } else { |
| 885 | /* Reschedule LED off for full time period */ |
| 886 | cancel_delayed_work(&priv->led_act_off); |
| 887 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 888 | LD_TIME_ACT_ON); |
| 889 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 890 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 891 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 892 | #if 0 |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 893 | void ipw_led_activity_on(struct ipw_priv *priv) |
| 894 | { |
| 895 | unsigned long flags; |
| 896 | spin_lock_irqsave(&priv->lock, flags); |
| 897 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 898 | spin_unlock_irqrestore(&priv->lock, flags); |
| 899 | } |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 900 | #endif /* 0 */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 901 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 902 | static void ipw_led_activity_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 903 | { |
| 904 | unsigned long flags; |
| 905 | u32 led; |
| 906 | |
| 907 | if (priv->config & CFG_NO_LED) |
| 908 | return; |
| 909 | |
| 910 | spin_lock_irqsave(&priv->lock, flags); |
| 911 | |
| 912 | if (priv->status & STATUS_LED_ACT_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 913 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 914 | led &= priv->led_activity_off; |
| 915 | |
| 916 | led = ipw_register_toggle(led); |
| 917 | |
| 918 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 919 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 920 | |
| 921 | IPW_DEBUG_LED("Activity LED Off\n"); |
| 922 | |
| 923 | priv->status &= ~STATUS_LED_ACT_ON; |
| 924 | } |
| 925 | |
| 926 | spin_unlock_irqrestore(&priv->lock, flags); |
| 927 | } |
| 928 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 929 | static void ipw_bg_led_activity_off(void *data) |
| 930 | { |
| 931 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 932 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 933 | ipw_led_activity_off(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 934 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 935 | } |
| 936 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 937 | static void ipw_led_band_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 938 | { |
| 939 | unsigned long flags; |
| 940 | u32 led; |
| 941 | |
| 942 | /* Only nic type 1 supports mode LEDs */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 943 | if (priv->config & CFG_NO_LED || |
| 944 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 945 | return; |
| 946 | |
| 947 | spin_lock_irqsave(&priv->lock, flags); |
| 948 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 949 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 950 | if (priv->assoc_network->mode == IEEE_A) { |
| 951 | led |= priv->led_ofdm_on; |
| 952 | led &= priv->led_association_off; |
| 953 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); |
| 954 | } else if (priv->assoc_network->mode == IEEE_G) { |
| 955 | led |= priv->led_ofdm_on; |
| 956 | led |= priv->led_association_on; |
| 957 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); |
| 958 | } else { |
| 959 | led &= priv->led_ofdm_off; |
| 960 | led |= priv->led_association_on; |
| 961 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); |
| 962 | } |
| 963 | |
| 964 | led = ipw_register_toggle(led); |
| 965 | |
| 966 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 967 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 968 | |
| 969 | spin_unlock_irqrestore(&priv->lock, flags); |
| 970 | } |
| 971 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 972 | static void ipw_led_band_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 973 | { |
| 974 | unsigned long flags; |
| 975 | u32 led; |
| 976 | |
| 977 | /* Only nic type 1 supports mode LEDs */ |
| 978 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) |
| 979 | return; |
| 980 | |
| 981 | spin_lock_irqsave(&priv->lock, flags); |
| 982 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 983 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 984 | led &= priv->led_ofdm_off; |
| 985 | led &= priv->led_association_off; |
| 986 | |
| 987 | led = ipw_register_toggle(led); |
| 988 | |
| 989 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 990 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 991 | |
| 992 | spin_unlock_irqrestore(&priv->lock, flags); |
| 993 | } |
| 994 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 995 | static void ipw_led_radio_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 996 | { |
| 997 | ipw_led_link_on(priv); |
| 998 | } |
| 999 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1000 | static void ipw_led_radio_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1001 | { |
| 1002 | ipw_led_activity_off(priv); |
| 1003 | ipw_led_link_off(priv); |
| 1004 | } |
| 1005 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1006 | static void ipw_led_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1007 | { |
| 1008 | /* Set the Link Led on for all nic types */ |
| 1009 | ipw_led_link_on(priv); |
| 1010 | } |
| 1011 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1012 | static void ipw_led_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1013 | { |
| 1014 | ipw_led_activity_off(priv); |
| 1015 | ipw_led_link_off(priv); |
| 1016 | |
| 1017 | if (priv->status & STATUS_RF_KILL_MASK) |
| 1018 | ipw_led_radio_off(priv); |
| 1019 | } |
| 1020 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1021 | static void ipw_led_init(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1022 | { |
| 1023 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; |
| 1024 | |
| 1025 | /* Set the default PINs for the link and activity leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1026 | priv->led_activity_on = IPW_ACTIVITY_LED; |
| 1027 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1028 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1029 | priv->led_association_on = IPW_ASSOCIATED_LED; |
| 1030 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1031 | |
| 1032 | /* Set the default PINs for the OFDM leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1033 | priv->led_ofdm_on = IPW_OFDM_LED; |
| 1034 | priv->led_ofdm_off = ~(IPW_OFDM_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1035 | |
| 1036 | switch (priv->nic_type) { |
| 1037 | case EEPROM_NIC_TYPE_1: |
| 1038 | /* In this NIC type, the LEDs are reversed.... */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1039 | priv->led_activity_on = IPW_ASSOCIATED_LED; |
| 1040 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); |
| 1041 | priv->led_association_on = IPW_ACTIVITY_LED; |
| 1042 | priv->led_association_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1043 | |
| 1044 | if (!(priv->config & CFG_NO_LED)) |
| 1045 | ipw_led_band_on(priv); |
| 1046 | |
| 1047 | /* And we don't blink link LEDs for this nic, so |
| 1048 | * just return here */ |
| 1049 | return; |
| 1050 | |
| 1051 | case EEPROM_NIC_TYPE_3: |
| 1052 | case EEPROM_NIC_TYPE_2: |
| 1053 | case EEPROM_NIC_TYPE_4: |
| 1054 | case EEPROM_NIC_TYPE_0: |
| 1055 | break; |
| 1056 | |
| 1057 | default: |
| 1058 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", |
| 1059 | priv->nic_type); |
| 1060 | priv->nic_type = EEPROM_NIC_TYPE_0; |
| 1061 | break; |
| 1062 | } |
| 1063 | |
| 1064 | if (!(priv->config & CFG_NO_LED)) { |
| 1065 | if (priv->status & STATUS_ASSOCIATED) |
| 1066 | ipw_led_link_on(priv); |
| 1067 | else |
| 1068 | ipw_led_link_off(priv); |
| 1069 | } |
| 1070 | } |
| 1071 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1072 | static void ipw_led_shutdown(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1073 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1074 | ipw_led_activity_off(priv); |
| 1075 | ipw_led_link_off(priv); |
| 1076 | ipw_led_band_off(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1077 | cancel_delayed_work(&priv->led_link_on); |
| 1078 | cancel_delayed_work(&priv->led_link_off); |
| 1079 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1080 | } |
| 1081 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1082 | /* |
| 1083 | * The following adds a new attribute to the sysfs representation |
| 1084 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) |
| 1085 | * used for controling the debug level. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1086 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1087 | * See the level definitions in ipw for details. |
| 1088 | */ |
| 1089 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 1090 | { |
| 1091 | return sprintf(buf, "0x%08X\n", ipw_debug_level); |
| 1092 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1093 | |
| 1094 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, |
| 1095 | size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1096 | { |
| 1097 | char *p = (char *)buf; |
| 1098 | u32 val; |
| 1099 | |
| 1100 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1101 | p++; |
| 1102 | if (p[0] == 'x' || p[0] == 'X') |
| 1103 | p++; |
| 1104 | val = simple_strtoul(p, &p, 16); |
| 1105 | } else |
| 1106 | val = simple_strtoul(p, &p, 10); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1107 | if (p == buf) |
| 1108 | printk(KERN_INFO DRV_NAME |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1109 | ": %s is not in hex or decimal form.\n", buf); |
| 1110 | else |
| 1111 | ipw_debug_level = val; |
| 1112 | |
| 1113 | return strnlen(buf, count); |
| 1114 | } |
| 1115 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1116 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1117 | show_debug_level, store_debug_level); |
| 1118 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1119 | static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) |
| 1120 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 1121 | /* length = 1st dword in log */ |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1122 | return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); |
| 1123 | } |
| 1124 | |
| 1125 | static void ipw_capture_event_log(struct ipw_priv *priv, |
| 1126 | u32 log_len, struct ipw_event *log) |
| 1127 | { |
| 1128 | u32 base; |
| 1129 | |
| 1130 | if (log_len) { |
| 1131 | base = ipw_read32(priv, IPW_EVENT_LOG); |
| 1132 | ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), |
| 1133 | (u8 *) log, sizeof(*log) * log_len); |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) |
| 1138 | { |
| 1139 | struct ipw_fw_error *error; |
| 1140 | u32 log_len = ipw_get_event_log_len(priv); |
| 1141 | u32 base = ipw_read32(priv, IPW_ERROR_LOG); |
| 1142 | u32 elem_len = ipw_read_reg32(priv, base); |
| 1143 | |
| 1144 | error = kmalloc(sizeof(*error) + |
| 1145 | sizeof(*error->elem) * elem_len + |
| 1146 | sizeof(*error->log) * log_len, GFP_ATOMIC); |
| 1147 | if (!error) { |
| 1148 | IPW_ERROR("Memory allocation for firmware error log " |
| 1149 | "failed.\n"); |
| 1150 | return NULL; |
| 1151 | } |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1152 | error->jiffies = jiffies; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1153 | error->status = priv->status; |
| 1154 | error->config = priv->config; |
| 1155 | error->elem_len = elem_len; |
| 1156 | error->log_len = log_len; |
| 1157 | error->elem = (struct ipw_error_elem *)error->payload; |
Zhu Yi | 3b26b11 | 2005-11-17 13:58:30 +0800 | [diff] [blame] | 1158 | error->log = (struct ipw_event *)(error->elem + elem_len); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1159 | |
| 1160 | ipw_capture_event_log(priv, log_len, error->log); |
| 1161 | |
| 1162 | if (elem_len) |
| 1163 | ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, |
| 1164 | sizeof(*error->elem) * elem_len); |
| 1165 | |
| 1166 | return error; |
| 1167 | } |
| 1168 | |
| 1169 | static void ipw_free_error_log(struct ipw_fw_error *error) |
| 1170 | { |
| 1171 | if (error) |
| 1172 | kfree(error); |
| 1173 | } |
| 1174 | |
| 1175 | static ssize_t show_event_log(struct device *d, |
| 1176 | struct device_attribute *attr, char *buf) |
| 1177 | { |
| 1178 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1179 | u32 log_len = ipw_get_event_log_len(priv); |
| 1180 | struct ipw_event log[log_len]; |
| 1181 | u32 len = 0, i; |
| 1182 | |
| 1183 | ipw_capture_event_log(priv, log_len, log); |
| 1184 | |
| 1185 | len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); |
| 1186 | for (i = 0; i < log_len; i++) |
| 1187 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1188 | "\n%08X%08X%08X", |
| 1189 | log[i].time, log[i].event, log[i].data); |
| 1190 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1191 | return len; |
| 1192 | } |
| 1193 | |
| 1194 | static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL); |
| 1195 | |
| 1196 | static ssize_t show_error(struct device *d, |
| 1197 | struct device_attribute *attr, char *buf) |
| 1198 | { |
| 1199 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1200 | u32 len = 0, i; |
| 1201 | if (!priv->error) |
| 1202 | return 0; |
| 1203 | len += snprintf(buf + len, PAGE_SIZE - len, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1204 | "%08lX%08X%08X%08X", |
| 1205 | priv->error->jiffies, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1206 | priv->error->status, |
| 1207 | priv->error->config, priv->error->elem_len); |
| 1208 | for (i = 0; i < priv->error->elem_len; i++) |
| 1209 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1210 | "\n%08X%08X%08X%08X%08X%08X%08X", |
| 1211 | priv->error->elem[i].time, |
| 1212 | priv->error->elem[i].desc, |
| 1213 | priv->error->elem[i].blink1, |
| 1214 | priv->error->elem[i].blink2, |
| 1215 | priv->error->elem[i].link1, |
| 1216 | priv->error->elem[i].link2, |
| 1217 | priv->error->elem[i].data); |
| 1218 | |
| 1219 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1220 | "\n%08X", priv->error->log_len); |
| 1221 | for (i = 0; i < priv->error->log_len; i++) |
| 1222 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1223 | "\n%08X%08X%08X", |
| 1224 | priv->error->log[i].time, |
| 1225 | priv->error->log[i].event, |
| 1226 | priv->error->log[i].data); |
| 1227 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1228 | return len; |
| 1229 | } |
| 1230 | |
| 1231 | static ssize_t clear_error(struct device *d, |
| 1232 | struct device_attribute *attr, |
| 1233 | const char *buf, size_t count) |
| 1234 | { |
| 1235 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1236 | if (priv->error) { |
| 1237 | ipw_free_error_log(priv->error); |
| 1238 | priv->error = NULL; |
| 1239 | } |
| 1240 | return count; |
| 1241 | } |
| 1242 | |
| 1243 | static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error); |
| 1244 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1245 | static ssize_t show_cmd_log(struct device *d, |
| 1246 | struct device_attribute *attr, char *buf) |
| 1247 | { |
| 1248 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1249 | u32 len = 0, i; |
| 1250 | if (!priv->cmdlog) |
| 1251 | return 0; |
| 1252 | for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; |
| 1253 | (i != priv->cmdlog_pos) && (PAGE_SIZE - len); |
| 1254 | i = (i + 1) % priv->cmdlog_len) { |
| 1255 | len += |
| 1256 | snprintf(buf + len, PAGE_SIZE - len, |
| 1257 | "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, |
| 1258 | priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, |
| 1259 | priv->cmdlog[i].cmd.len); |
| 1260 | len += |
| 1261 | snprintk_buf(buf + len, PAGE_SIZE - len, |
| 1262 | (u8 *) priv->cmdlog[i].cmd.param, |
| 1263 | priv->cmdlog[i].cmd.len); |
| 1264 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1265 | } |
| 1266 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1267 | return len; |
| 1268 | } |
| 1269 | |
| 1270 | static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL); |
| 1271 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1272 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
| 1273 | char *buf) |
| 1274 | { |
| 1275 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1276 | return sprintf(buf, "%d\n", priv->ieee->scan_age); |
| 1277 | } |
| 1278 | |
| 1279 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, |
| 1280 | const char *buf, size_t count) |
| 1281 | { |
| 1282 | struct ipw_priv *priv = dev_get_drvdata(d); |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 1283 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1284 | struct net_device *dev = priv->net_dev; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1285 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1286 | char buffer[] = "00000000"; |
| 1287 | unsigned long len = |
| 1288 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; |
| 1289 | unsigned long val; |
| 1290 | char *p = buffer; |
| 1291 | |
| 1292 | IPW_DEBUG_INFO("enter\n"); |
| 1293 | |
| 1294 | strncpy(buffer, buf, len); |
| 1295 | buffer[len] = 0; |
| 1296 | |
| 1297 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1298 | p++; |
| 1299 | if (p[0] == 'x' || p[0] == 'X') |
| 1300 | p++; |
| 1301 | val = simple_strtoul(p, &p, 16); |
| 1302 | } else |
| 1303 | val = simple_strtoul(p, &p, 10); |
| 1304 | if (p == buffer) { |
| 1305 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); |
| 1306 | } else { |
| 1307 | priv->ieee->scan_age = val; |
| 1308 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); |
| 1309 | } |
| 1310 | |
| 1311 | IPW_DEBUG_INFO("exit\n"); |
| 1312 | return len; |
| 1313 | } |
| 1314 | |
| 1315 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); |
| 1316 | |
| 1317 | static ssize_t show_led(struct device *d, struct device_attribute *attr, |
| 1318 | char *buf) |
| 1319 | { |
| 1320 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1321 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); |
| 1322 | } |
| 1323 | |
| 1324 | static ssize_t store_led(struct device *d, struct device_attribute *attr, |
| 1325 | const char *buf, size_t count) |
| 1326 | { |
| 1327 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1328 | |
| 1329 | IPW_DEBUG_INFO("enter\n"); |
| 1330 | |
| 1331 | if (count == 0) |
| 1332 | return 0; |
| 1333 | |
| 1334 | if (*buf == 0) { |
| 1335 | IPW_DEBUG_LED("Disabling LED control.\n"); |
| 1336 | priv->config |= CFG_NO_LED; |
| 1337 | ipw_led_shutdown(priv); |
| 1338 | } else { |
| 1339 | IPW_DEBUG_LED("Enabling LED control.\n"); |
| 1340 | priv->config &= ~CFG_NO_LED; |
| 1341 | ipw_led_init(priv); |
| 1342 | } |
| 1343 | |
| 1344 | IPW_DEBUG_INFO("exit\n"); |
| 1345 | return count; |
| 1346 | } |
| 1347 | |
| 1348 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); |
| 1349 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1350 | static ssize_t show_status(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1351 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1352 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1353 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1354 | return sprintf(buf, "0x%08x\n", (int)p->status); |
| 1355 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1356 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1357 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 1358 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1359 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
| 1360 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1361 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1362 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1363 | return sprintf(buf, "0x%08x\n", (int)p->config); |
| 1364 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1365 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1366 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); |
| 1367 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1368 | static ssize_t show_nic_type(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1369 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1370 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1371 | struct ipw_priv *priv = d->driver_data; |
| 1372 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1373 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1374 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1375 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); |
| 1376 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1377 | static ssize_t show_ucode_version(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1378 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1379 | { |
| 1380 | u32 len = sizeof(u32), tmp = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1381 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1382 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1383 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1384 | return 0; |
| 1385 | |
| 1386 | return sprintf(buf, "0x%08x\n", tmp); |
| 1387 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1388 | |
| 1389 | 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] | 1390 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1391 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, |
| 1392 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1393 | { |
| 1394 | u32 len = sizeof(u32), tmp = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1395 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1396 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1397 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1398 | return 0; |
| 1399 | |
| 1400 | return sprintf(buf, "0x%08x\n", tmp); |
| 1401 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1402 | |
| 1403 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1404 | |
| 1405 | /* |
| 1406 | * Add a device attribute to view/control the delay between eeprom |
| 1407 | * operations. |
| 1408 | */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1409 | static ssize_t show_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1410 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1411 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1412 | int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1413 | return sprintf(buf, "%i\n", n); |
| 1414 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1415 | static ssize_t store_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1416 | struct device_attribute *attr, |
| 1417 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1418 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1419 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1420 | sscanf(buf, "%i", &p->eeprom_delay); |
| 1421 | return strnlen(buf, count); |
| 1422 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1423 | |
| 1424 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, |
| 1425 | show_eeprom_delay, store_eeprom_delay); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1426 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1427 | static ssize_t show_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1428 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1429 | { |
| 1430 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1431 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1432 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1433 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1434 | return sprintf(buf, "0x%08x\n", reg); |
| 1435 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1436 | static ssize_t store_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1437 | struct device_attribute *attr, |
| 1438 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1439 | { |
| 1440 | u32 reg; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1441 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1442 | |
| 1443 | sscanf(buf, "%x", ®); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1444 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1445 | return strnlen(buf, count); |
| 1446 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1447 | |
| 1448 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, |
| 1449 | show_command_event_reg, store_command_event_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1450 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1451 | static ssize_t show_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1452 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1453 | { |
| 1454 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1455 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1456 | |
| 1457 | reg = ipw_read_reg32(p, 0x301100); |
| 1458 | return sprintf(buf, "0x%08x\n", reg); |
| 1459 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1460 | static ssize_t store_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1461 | struct device_attribute *attr, |
| 1462 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1463 | { |
| 1464 | u32 reg; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1465 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1466 | |
| 1467 | sscanf(buf, "%x", ®); |
| 1468 | ipw_write_reg32(p, 0x301100, reg); |
| 1469 | return strnlen(buf, count); |
| 1470 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1471 | |
| 1472 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, |
| 1473 | show_mem_gpio_reg, store_mem_gpio_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1474 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1475 | static ssize_t show_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1476 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1477 | { |
| 1478 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1479 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1480 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1481 | if (priv->status & STATUS_INDIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1482 | reg = ipw_read_reg32(priv, priv->indirect_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1483 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1484 | reg = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1485 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1486 | return sprintf(buf, "0x%08x\n", reg); |
| 1487 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1488 | static ssize_t store_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1489 | struct device_attribute *attr, |
| 1490 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1491 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1492 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1493 | |
| 1494 | sscanf(buf, "%x", &priv->indirect_dword); |
| 1495 | priv->status |= STATUS_INDIRECT_DWORD; |
| 1496 | return strnlen(buf, count); |
| 1497 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1498 | |
| 1499 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, |
| 1500 | show_indirect_dword, store_indirect_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1501 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1502 | static ssize_t show_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1503 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1504 | { |
| 1505 | u8 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1506 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1507 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1508 | if (priv->status & STATUS_INDIRECT_BYTE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1509 | reg = ipw_read_reg8(priv, priv->indirect_byte); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1510 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1511 | reg = 0; |
| 1512 | |
| 1513 | return sprintf(buf, "0x%02x\n", reg); |
| 1514 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1515 | static ssize_t store_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1516 | struct device_attribute *attr, |
| 1517 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1518 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1519 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1520 | |
| 1521 | sscanf(buf, "%x", &priv->indirect_byte); |
| 1522 | priv->status |= STATUS_INDIRECT_BYTE; |
| 1523 | return strnlen(buf, count); |
| 1524 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1525 | |
| 1526 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1527 | show_indirect_byte, store_indirect_byte); |
| 1528 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1529 | static ssize_t show_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1530 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1531 | { |
| 1532 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1533 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1534 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1535 | if (priv->status & STATUS_DIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1536 | reg = ipw_read32(priv, priv->direct_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1537 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1538 | reg = 0; |
| 1539 | |
| 1540 | return sprintf(buf, "0x%08x\n", reg); |
| 1541 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1542 | static ssize_t store_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1543 | struct device_attribute *attr, |
| 1544 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1545 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1546 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1547 | |
| 1548 | sscanf(buf, "%x", &priv->direct_dword); |
| 1549 | priv->status |= STATUS_DIRECT_DWORD; |
| 1550 | return strnlen(buf, count); |
| 1551 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1552 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1553 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, |
| 1554 | show_direct_dword, store_direct_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1555 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1556 | static int rf_kill_active(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1557 | { |
| 1558 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) |
| 1559 | priv->status |= STATUS_RF_KILL_HW; |
| 1560 | else |
| 1561 | priv->status &= ~STATUS_RF_KILL_HW; |
| 1562 | |
| 1563 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; |
| 1564 | } |
| 1565 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1566 | 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] | 1567 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1568 | { |
| 1569 | /* 0 - RF kill not enabled |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1570 | 1 - SW based RF kill active (sysfs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1571 | 2 - HW based RF kill active |
| 1572 | 3 - Both HW and SW baed RF kill active */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1573 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1574 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1575 | (rf_kill_active(priv) ? 0x2 : 0x0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1576 | return sprintf(buf, "%i\n", val); |
| 1577 | } |
| 1578 | |
| 1579 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) |
| 1580 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1581 | if ((disable_radio ? 1 : 0) == |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1582 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1583 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1584 | |
| 1585 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", |
| 1586 | disable_radio ? "OFF" : "ON"); |
| 1587 | |
| 1588 | if (disable_radio) { |
| 1589 | priv->status |= STATUS_RF_KILL_SW; |
| 1590 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1591 | if (priv->workqueue) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1592 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1593 | queue_work(priv->workqueue, &priv->down); |
| 1594 | } else { |
| 1595 | priv->status &= ~STATUS_RF_KILL_SW; |
| 1596 | if (rf_kill_active(priv)) { |
| 1597 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1598 | "disabled by HW switch\n"); |
| 1599 | /* Make sure the RF_KILL check timer is running */ |
| 1600 | cancel_delayed_work(&priv->rf_kill); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1601 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1602 | 2 * HZ); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1603 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1604 | queue_work(priv->workqueue, &priv->up); |
| 1605 | } |
| 1606 | |
| 1607 | return 1; |
| 1608 | } |
| 1609 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1610 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
| 1611 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1612 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1613 | struct ipw_priv *priv = d->driver_data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1614 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1615 | ipw_radio_kill_sw(priv, buf[0] == '1'); |
| 1616 | |
| 1617 | return count; |
| 1618 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1619 | |
| 1620 | 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] | 1621 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1622 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, |
| 1623 | char *buf) |
| 1624 | { |
| 1625 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1626 | int pos = 0, len = 0; |
| 1627 | if (priv->config & CFG_SPEED_SCAN) { |
| 1628 | while (priv->speed_scan[pos] != 0) |
| 1629 | len += sprintf(&buf[len], "%d ", |
| 1630 | priv->speed_scan[pos++]); |
| 1631 | return len + sprintf(&buf[len], "\n"); |
| 1632 | } |
| 1633 | |
| 1634 | return sprintf(buf, "0\n"); |
| 1635 | } |
| 1636 | |
| 1637 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, |
| 1638 | const char *buf, size_t count) |
| 1639 | { |
| 1640 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1641 | int channel, pos = 0; |
| 1642 | const char *p = buf; |
| 1643 | |
| 1644 | /* list of space separated channels to scan, optionally ending with 0 */ |
| 1645 | while ((channel = simple_strtol(p, NULL, 0))) { |
| 1646 | if (pos == MAX_SPEED_SCAN - 1) { |
| 1647 | priv->speed_scan[pos] = 0; |
| 1648 | break; |
| 1649 | } |
| 1650 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 1651 | if (ieee80211_is_valid_channel(priv->ieee, channel)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1652 | priv->speed_scan[pos++] = channel; |
| 1653 | else |
| 1654 | IPW_WARNING("Skipping invalid channel request: %d\n", |
| 1655 | channel); |
| 1656 | p = strchr(p, ' '); |
| 1657 | if (!p) |
| 1658 | break; |
| 1659 | while (*p == ' ' || *p == '\t') |
| 1660 | p++; |
| 1661 | } |
| 1662 | |
| 1663 | if (pos == 0) |
| 1664 | priv->config &= ~CFG_SPEED_SCAN; |
| 1665 | else { |
| 1666 | priv->speed_scan_pos = 0; |
| 1667 | priv->config |= CFG_SPEED_SCAN; |
| 1668 | } |
| 1669 | |
| 1670 | return count; |
| 1671 | } |
| 1672 | |
| 1673 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, |
| 1674 | store_speed_scan); |
| 1675 | |
| 1676 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, |
| 1677 | char *buf) |
| 1678 | { |
| 1679 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1680 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); |
| 1681 | } |
| 1682 | |
| 1683 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, |
| 1684 | const char *buf, size_t count) |
| 1685 | { |
| 1686 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1687 | if (buf[0] == '1') |
| 1688 | priv->config |= CFG_NET_STATS; |
| 1689 | else |
| 1690 | priv->config &= ~CFG_NET_STATS; |
| 1691 | |
| 1692 | return count; |
| 1693 | } |
| 1694 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1695 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, |
| 1696 | show_net_stats, store_net_stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1697 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1698 | static void notify_wx_assoc_event(struct ipw_priv *priv) |
| 1699 | { |
| 1700 | union iwreq_data wrqu; |
| 1701 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1702 | if (priv->status & STATUS_ASSOCIATED) |
| 1703 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); |
| 1704 | else |
| 1705 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 1706 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); |
| 1707 | } |
| 1708 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1709 | static void ipw_irq_tasklet(struct ipw_priv *priv) |
| 1710 | { |
| 1711 | u32 inta, inta_mask, handled = 0; |
| 1712 | unsigned long flags; |
| 1713 | int rc = 0; |
| 1714 | |
| 1715 | spin_lock_irqsave(&priv->lock, flags); |
| 1716 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1717 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 1718 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
| 1719 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1720 | |
| 1721 | /* Add any cached INTA values that need to be handled */ |
| 1722 | inta |= priv->isr_inta; |
| 1723 | |
| 1724 | /* handle all the justifications for the interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1725 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1726 | ipw_rx(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1727 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1728 | } |
| 1729 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1730 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1731 | IPW_DEBUG_HC("Command completed.\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1732 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1733 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1734 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1735 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1736 | } |
| 1737 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1738 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1739 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1740 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1741 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1742 | } |
| 1743 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1744 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1745 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1746 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1747 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1748 | } |
| 1749 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1750 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1751 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1752 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1753 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1754 | } |
| 1755 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1756 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1757 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1758 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1759 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1760 | } |
| 1761 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1762 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1763 | IPW_WARNING("STATUS_CHANGE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1764 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1765 | } |
| 1766 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1767 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1768 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1769 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1770 | } |
| 1771 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1772 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1773 | IPW_WARNING("HOST_CMD_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1774 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1775 | } |
| 1776 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1777 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1778 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1779 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1780 | } |
| 1781 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1782 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1783 | IPW_WARNING("PHY_OFF_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1784 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1785 | } |
| 1786 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1787 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1788 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
| 1789 | priv->status |= STATUS_RF_KILL_HW; |
| 1790 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1791 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1792 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1793 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1794 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1795 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1796 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1797 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1798 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1799 | IPW_WARNING("Firmware error detected. Restarting.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1800 | if (priv->error) { |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1801 | IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 1802 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1803 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
| 1804 | struct ipw_fw_error *error = |
| 1805 | ipw_alloc_error_log(priv); |
| 1806 | ipw_dump_error_log(priv, error); |
| 1807 | if (error) |
| 1808 | ipw_free_error_log(error); |
| 1809 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1810 | #endif |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1811 | } else { |
| 1812 | priv->error = ipw_alloc_error_log(priv); |
| 1813 | if (priv->error) |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1814 | IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1815 | else |
Zhu Yi | 1d1b09e | 2006-03-02 06:40:59 +0800 | [diff] [blame] | 1816 | IPW_DEBUG_FW("Error allocating sysfs 'error' " |
| 1817 | "log.\n"); |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 1818 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1819 | if (ipw_debug_level & IPW_DL_FW_ERRORS) |
| 1820 | ipw_dump_error_log(priv, priv->error); |
| 1821 | #endif |
| 1822 | } |
| 1823 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1824 | /* XXX: If hardware encryption is for WPA/WPA2, |
| 1825 | * we have to notify the supplicant. */ |
| 1826 | if (priv->ieee->sec.encrypt) { |
| 1827 | priv->status &= ~STATUS_ASSOCIATED; |
| 1828 | notify_wx_assoc_event(priv); |
| 1829 | } |
| 1830 | |
| 1831 | /* Keep the restart process from trying to send host |
| 1832 | * commands by clearing the INIT status bit */ |
| 1833 | priv->status &= ~STATUS_INIT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1834 | |
| 1835 | /* Cancel currently queued command. */ |
| 1836 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1837 | wake_up_interruptible(&priv->wait_command_queue); |
| 1838 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1839 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1840 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1841 | } |
| 1842 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1843 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1844 | IPW_ERROR("Parity error\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1845 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | if (handled != inta) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1849 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | /* enable all interrupts */ |
| 1853 | ipw_enable_interrupts(priv); |
| 1854 | |
| 1855 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1856 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1857 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1858 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
| 1859 | static char *get_cmd_string(u8 cmd) |
| 1860 | { |
| 1861 | switch (cmd) { |
| 1862 | IPW_CMD(HOST_COMPLETE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1863 | IPW_CMD(POWER_DOWN); |
| 1864 | IPW_CMD(SYSTEM_CONFIG); |
| 1865 | IPW_CMD(MULTICAST_ADDRESS); |
| 1866 | IPW_CMD(SSID); |
| 1867 | IPW_CMD(ADAPTER_ADDRESS); |
| 1868 | IPW_CMD(PORT_TYPE); |
| 1869 | IPW_CMD(RTS_THRESHOLD); |
| 1870 | IPW_CMD(FRAG_THRESHOLD); |
| 1871 | IPW_CMD(POWER_MODE); |
| 1872 | IPW_CMD(WEP_KEY); |
| 1873 | IPW_CMD(TGI_TX_KEY); |
| 1874 | IPW_CMD(SCAN_REQUEST); |
| 1875 | IPW_CMD(SCAN_REQUEST_EXT); |
| 1876 | IPW_CMD(ASSOCIATE); |
| 1877 | IPW_CMD(SUPPORTED_RATES); |
| 1878 | IPW_CMD(SCAN_ABORT); |
| 1879 | IPW_CMD(TX_FLUSH); |
| 1880 | IPW_CMD(QOS_PARAMETERS); |
| 1881 | IPW_CMD(DINO_CONFIG); |
| 1882 | IPW_CMD(RSN_CAPABILITIES); |
| 1883 | IPW_CMD(RX_KEY); |
| 1884 | IPW_CMD(CARD_DISABLE); |
| 1885 | IPW_CMD(SEED_NUMBER); |
| 1886 | IPW_CMD(TX_POWER); |
| 1887 | IPW_CMD(COUNTRY_INFO); |
| 1888 | IPW_CMD(AIRONET_INFO); |
| 1889 | IPW_CMD(AP_TX_POWER); |
| 1890 | IPW_CMD(CCKM_INFO); |
| 1891 | IPW_CMD(CCX_VER_INFO); |
| 1892 | IPW_CMD(SET_CALIBRATION); |
| 1893 | IPW_CMD(SENSITIVITY_CALIB); |
| 1894 | IPW_CMD(RETRY_LIMIT); |
| 1895 | IPW_CMD(IPW_PRE_POWER_DOWN); |
| 1896 | IPW_CMD(VAP_BEACON_TEMPLATE); |
| 1897 | IPW_CMD(VAP_DTIM_PERIOD); |
| 1898 | IPW_CMD(EXT_SUPPORTED_RATES); |
| 1899 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); |
| 1900 | IPW_CMD(VAP_QUIET_INTERVALS); |
| 1901 | IPW_CMD(VAP_CHANNEL_SWITCH); |
| 1902 | IPW_CMD(VAP_MANDATORY_CHANNELS); |
| 1903 | IPW_CMD(VAP_CELL_PWR_LIMIT); |
| 1904 | IPW_CMD(VAP_CF_PARAM_SET); |
| 1905 | IPW_CMD(VAP_SET_BEACONING_STATE); |
| 1906 | IPW_CMD(MEASUREMENT); |
| 1907 | IPW_CMD(POWER_CAPABILITY); |
| 1908 | IPW_CMD(SUPPORTED_CHANNELS); |
| 1909 | IPW_CMD(TPC_REPORT); |
| 1910 | IPW_CMD(WME_INFO); |
| 1911 | IPW_CMD(PRODUCTION_COMMAND); |
| 1912 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1913 | return "UNKNOWN"; |
| 1914 | } |
| 1915 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1916 | |
| 1917 | #define HOST_COMPLETE_TIMEOUT HZ |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 1918 | |
| 1919 | 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] | 1920 | { |
| 1921 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1922 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1923 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1924 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1925 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 1926 | IPW_ERROR("Failed to send %s: Already sending a command.\n", |
| 1927 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1928 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 1929 | return -EAGAIN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | priv->status |= STATUS_HCMD_ACTIVE; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1933 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1934 | if (priv->cmdlog) { |
| 1935 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; |
| 1936 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; |
| 1937 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; |
| 1938 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, |
| 1939 | cmd->len); |
| 1940 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; |
| 1941 | } |
| 1942 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1943 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
| 1944 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, |
| 1945 | priv->status); |
Zhu Yi | f516dbc | 2006-01-24 16:36:44 +0800 | [diff] [blame] | 1946 | |
| 1947 | #ifndef DEBUG_CMD_WEP_KEY |
| 1948 | if (cmd->cmd == IPW_CMD_WEP_KEY) |
| 1949 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); |
| 1950 | else |
| 1951 | #endif |
| 1952 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); |
| 1953 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 1954 | 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] | 1955 | if (rc) { |
| 1956 | priv->status &= ~STATUS_HCMD_ACTIVE; |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 1957 | IPW_ERROR("Failed to send %s: Reason %d\n", |
| 1958 | get_cmd_string(cmd->cmd), rc); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1959 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1960 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1961 | } |
| 1962 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1963 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1964 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 1965 | !(priv-> |
| 1966 | status & STATUS_HCMD_ACTIVE), |
| 1967 | HOST_COMPLETE_TIMEOUT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1968 | if (rc == 0) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1969 | spin_lock_irqsave(&priv->lock, flags); |
| 1970 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 1971 | IPW_ERROR("Failed to send %s: Command timed out.\n", |
| 1972 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1973 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1974 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1975 | rc = -EIO; |
| 1976 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1977 | } |
| 1978 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 1979 | } else |
| 1980 | rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1981 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1982 | if (priv->status & STATUS_RF_KILL_HW) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 1983 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", |
| 1984 | get_cmd_string(cmd->cmd)); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1985 | rc = -EIO; |
| 1986 | goto exit; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1987 | } |
| 1988 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 1989 | exit: |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1990 | if (priv->cmdlog) { |
| 1991 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; |
| 1992 | priv->cmdlog_pos %= priv->cmdlog_len; |
| 1993 | } |
| 1994 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1995 | } |
| 1996 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 1997 | static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1998 | { |
| 1999 | struct host_cmd cmd = { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2000 | .cmd = command, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2001 | }; |
| 2002 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2003 | return __ipw_send_cmd(priv, &cmd); |
| 2004 | } |
| 2005 | |
| 2006 | static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, |
| 2007 | void *data) |
| 2008 | { |
| 2009 | struct host_cmd cmd = { |
| 2010 | .cmd = command, |
| 2011 | .len = len, |
| 2012 | .param = data, |
| 2013 | }; |
| 2014 | |
| 2015 | return __ipw_send_cmd(priv, &cmd); |
| 2016 | } |
| 2017 | |
| 2018 | static int ipw_send_host_complete(struct ipw_priv *priv) |
| 2019 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2020 | if (!priv) { |
| 2021 | IPW_ERROR("Invalid args\n"); |
| 2022 | return -1; |
| 2023 | } |
| 2024 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2025 | return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2026 | } |
| 2027 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2028 | static int ipw_send_system_config(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2029 | struct ipw_sys_config *config) |
| 2030 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2031 | if (!priv || !config) { |
| 2032 | IPW_ERROR("Invalid args\n"); |
| 2033 | return -1; |
| 2034 | } |
| 2035 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2036 | return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, sizeof(*config), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2037 | config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2038 | } |
| 2039 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2040 | 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] | 2041 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2042 | if (!priv || !ssid) { |
| 2043 | IPW_ERROR("Invalid args\n"); |
| 2044 | return -1; |
| 2045 | } |
| 2046 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2047 | 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] | 2048 | ssid); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2049 | } |
| 2050 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2051 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2052 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2053 | if (!priv || !mac) { |
| 2054 | IPW_ERROR("Invalid args\n"); |
| 2055 | return -1; |
| 2056 | } |
| 2057 | |
| 2058 | IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n", |
| 2059 | priv->net_dev->name, MAC_ARG(mac)); |
| 2060 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2061 | 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] | 2062 | } |
| 2063 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2064 | /* |
| 2065 | * NOTE: This must be executed from our workqueue as it results in udelay |
| 2066 | * being called which may corrupt the keyboard if executed on default |
| 2067 | * workqueue |
| 2068 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2069 | static void ipw_adapter_restart(void *adapter) |
| 2070 | { |
| 2071 | struct ipw_priv *priv = adapter; |
| 2072 | |
| 2073 | if (priv->status & STATUS_RF_KILL_MASK) |
| 2074 | return; |
| 2075 | |
| 2076 | ipw_down(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2077 | |
| 2078 | if (priv->assoc_network && |
| 2079 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) |
| 2080 | ipw_remove_current_network(priv); |
| 2081 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2082 | if (ipw_up(priv)) { |
| 2083 | IPW_ERROR("Failed to up device\n"); |
| 2084 | return; |
| 2085 | } |
| 2086 | } |
| 2087 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2088 | static void ipw_bg_adapter_restart(void *data) |
| 2089 | { |
| 2090 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2091 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2092 | ipw_adapter_restart(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2093 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2094 | } |
| 2095 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2096 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
| 2097 | |
| 2098 | static void ipw_scan_check(void *data) |
| 2099 | { |
| 2100 | struct ipw_priv *priv = data; |
| 2101 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
| 2102 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2103 | "adapter after (%dms).\n", |
| 2104 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2105 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2106 | } |
| 2107 | } |
| 2108 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2109 | static void ipw_bg_scan_check(void *data) |
| 2110 | { |
| 2111 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2112 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2113 | ipw_scan_check(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 2114 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2115 | } |
| 2116 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2117 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
| 2118 | struct ipw_scan_request_ext *request) |
| 2119 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2120 | return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2121 | sizeof(*request), request); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | static int ipw_send_scan_abort(struct ipw_priv *priv) |
| 2125 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2126 | if (!priv) { |
| 2127 | IPW_ERROR("Invalid args\n"); |
| 2128 | return -1; |
| 2129 | } |
| 2130 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2131 | return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) |
| 2135 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2136 | struct ipw_sensitivity_calib calib = { |
| 2137 | .beacon_rssi_raw = sens, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2138 | }; |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2139 | |
| 2140 | return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2141 | &calib); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | static int ipw_send_associate(struct ipw_priv *priv, |
| 2145 | struct ipw_associate *associate) |
| 2146 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2147 | struct ipw_associate tmp_associate; |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2148 | |
| 2149 | if (!priv || !associate) { |
| 2150 | IPW_ERROR("Invalid args\n"); |
| 2151 | return -1; |
| 2152 | } |
| 2153 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2154 | memcpy(&tmp_associate, associate, sizeof(*associate)); |
| 2155 | tmp_associate.policy_support = |
| 2156 | cpu_to_le16(tmp_associate.policy_support); |
| 2157 | tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw); |
| 2158 | tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw); |
| 2159 | tmp_associate.capability = cpu_to_le16(tmp_associate.capability); |
| 2160 | tmp_associate.listen_interval = |
| 2161 | cpu_to_le16(tmp_associate.listen_interval); |
| 2162 | tmp_associate.beacon_interval = |
| 2163 | cpu_to_le16(tmp_associate.beacon_interval); |
| 2164 | tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window); |
| 2165 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2166 | return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2167 | &tmp_associate); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | static int ipw_send_supported_rates(struct ipw_priv *priv, |
| 2171 | struct ipw_supported_rates *rates) |
| 2172 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2173 | if (!priv || !rates) { |
| 2174 | IPW_ERROR("Invalid args\n"); |
| 2175 | return -1; |
| 2176 | } |
| 2177 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2178 | return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2179 | rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | static int ipw_set_random_seed(struct ipw_priv *priv) |
| 2183 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2184 | u32 val; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2185 | |
| 2186 | if (!priv) { |
| 2187 | IPW_ERROR("Invalid args\n"); |
| 2188 | return -1; |
| 2189 | } |
| 2190 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2191 | get_random_bytes(&val, sizeof(val)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2192 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2193 | 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] | 2194 | } |
| 2195 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2196 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
| 2197 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2198 | if (!priv) { |
| 2199 | IPW_ERROR("Invalid args\n"); |
| 2200 | return -1; |
| 2201 | } |
| 2202 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2203 | return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2204 | &phy_off); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2205 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2206 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2207 | 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] | 2208 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2209 | if (!priv || !power) { |
| 2210 | IPW_ERROR("Invalid args\n"); |
| 2211 | return -1; |
| 2212 | } |
| 2213 | |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2214 | 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] | 2215 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2216 | |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2217 | static int ipw_set_tx_power(struct ipw_priv *priv) |
| 2218 | { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 2219 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2220 | struct ipw_tx_power tx_power; |
| 2221 | s8 max_power; |
| 2222 | int i; |
| 2223 | |
| 2224 | memset(&tx_power, 0, sizeof(tx_power)); |
| 2225 | |
| 2226 | /* configure device for 'G' band */ |
| 2227 | tx_power.ieee_mode = IPW_G_MODE; |
| 2228 | tx_power.num_channels = geo->bg_channels; |
| 2229 | for (i = 0; i < geo->bg_channels; i++) { |
| 2230 | max_power = geo->bg[i].max_power; |
| 2231 | tx_power.channels_tx_power[i].channel_number = |
| 2232 | geo->bg[i].channel; |
| 2233 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2234 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2235 | } |
| 2236 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2237 | return -EIO; |
| 2238 | |
| 2239 | /* configure device to also handle 'B' band */ |
| 2240 | tx_power.ieee_mode = IPW_B_MODE; |
| 2241 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2242 | return -EIO; |
| 2243 | |
| 2244 | /* configure device to also handle 'A' band */ |
| 2245 | if (priv->ieee->abg_true) { |
| 2246 | tx_power.ieee_mode = IPW_A_MODE; |
| 2247 | tx_power.num_channels = geo->a_channels; |
| 2248 | for (i = 0; i < tx_power.num_channels; i++) { |
| 2249 | max_power = geo->a[i].max_power; |
| 2250 | tx_power.channels_tx_power[i].channel_number = |
| 2251 | geo->a[i].channel; |
| 2252 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2253 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2254 | } |
| 2255 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2256 | return -EIO; |
| 2257 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2258 | return 0; |
| 2259 | } |
| 2260 | |
| 2261 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) |
| 2262 | { |
| 2263 | struct ipw_rts_threshold rts_threshold = { |
| 2264 | .rts_threshold = rts, |
| 2265 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2266 | |
| 2267 | if (!priv) { |
| 2268 | IPW_ERROR("Invalid args\n"); |
| 2269 | return -1; |
| 2270 | } |
| 2271 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2272 | return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, |
| 2273 | sizeof(rts_threshold), &rts_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) |
| 2277 | { |
| 2278 | struct ipw_frag_threshold frag_threshold = { |
| 2279 | .frag_threshold = frag, |
| 2280 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2281 | |
| 2282 | if (!priv) { |
| 2283 | IPW_ERROR("Invalid args\n"); |
| 2284 | return -1; |
| 2285 | } |
| 2286 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2287 | return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, |
| 2288 | sizeof(frag_threshold), &frag_threshold); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) |
| 2292 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2293 | u32 param; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2294 | |
| 2295 | if (!priv) { |
| 2296 | IPW_ERROR("Invalid args\n"); |
| 2297 | return -1; |
| 2298 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2299 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2300 | /* If on battery, set to 3, if AC set to CAM, else user |
| 2301 | * level */ |
| 2302 | switch (mode) { |
| 2303 | case IPW_POWER_BATTERY: |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2304 | param = IPW_POWER_INDEX_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2305 | break; |
| 2306 | case IPW_POWER_AC: |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2307 | param = IPW_POWER_MODE_CAM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2308 | break; |
| 2309 | default: |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2310 | param = mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2311 | break; |
| 2312 | } |
| 2313 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2314 | return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 2315 | ¶m); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2316 | } |
| 2317 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2318 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
| 2319 | { |
| 2320 | struct ipw_retry_limit retry_limit = { |
| 2321 | .short_retry_limit = slimit, |
| 2322 | .long_retry_limit = llimit |
| 2323 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2324 | |
| 2325 | if (!priv) { |
| 2326 | IPW_ERROR("Invalid args\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2327 | return -1; |
| 2328 | } |
| 2329 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 2330 | 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] | 2331 | &retry_limit); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | /* |
| 2335 | * The IPW device contains a Microwire compatible EEPROM that stores |
| 2336 | * various data like the MAC address. Usually the firmware has exclusive |
| 2337 | * access to the eeprom, but during device initialization (before the |
| 2338 | * device driver has sent the HostComplete command to the firmware) the |
| 2339 | * device driver has read access to the EEPROM by way of indirect addressing |
| 2340 | * through a couple of memory mapped registers. |
| 2341 | * |
| 2342 | * The following is a simplified implementation for pulling data out of the |
| 2343 | * the eeprom, along with some helper functions to find information in |
| 2344 | * the per device private data's copy of the eeprom. |
| 2345 | * |
| 2346 | * NOTE: To better understand how these functions work (i.e what is a chip |
| 2347 | * select and why do have to keep driving the eeprom clock?), read |
| 2348 | * just about any data sheet for a Microwire compatible EEPROM. |
| 2349 | */ |
| 2350 | |
| 2351 | /* write a 32 bit value into the indirect accessor register */ |
| 2352 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) |
| 2353 | { |
| 2354 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2355 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2356 | /* the eeprom requires some time to complete the operation */ |
| 2357 | udelay(p->eeprom_delay); |
| 2358 | |
| 2359 | return; |
| 2360 | } |
| 2361 | |
| 2362 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2363 | static void eeprom_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2364 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2365 | eeprom_write_reg(priv, 0); |
| 2366 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2367 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2368 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2372 | static void eeprom_disable_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2373 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2374 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2375 | eeprom_write_reg(priv, 0); |
| 2376 | eeprom_write_reg(priv, EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | /* push a single bit down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2380 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2381 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2382 | int d = (bit ? EEPROM_BIT_DI : 0); |
| 2383 | eeprom_write_reg(p, EEPROM_BIT_CS | d); |
| 2384 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | /* push an opcode followed by an address down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2388 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2389 | { |
| 2390 | int i; |
| 2391 | |
| 2392 | eeprom_cs(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2393 | eeprom_write_bit(priv, 1); |
| 2394 | eeprom_write_bit(priv, op & 2); |
| 2395 | eeprom_write_bit(priv, op & 1); |
| 2396 | for (i = 7; i >= 0; i--) { |
| 2397 | eeprom_write_bit(priv, addr & (1 << i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | /* pull 16 bits off the eeprom, one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2402 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2403 | { |
| 2404 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2405 | u16 r = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2406 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2407 | /* Send READ Opcode */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2408 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2409 | |
| 2410 | /* Send dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2411 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2412 | |
| 2413 | /* Read the byte off the eeprom one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2414 | for (i = 0; i < 16; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2415 | u32 data = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2416 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2417 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2418 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); |
| 2419 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2420 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2421 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2422 | /* Send another dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2423 | eeprom_write_reg(priv, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2424 | eeprom_disable_cs(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2425 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2426 | return r; |
| 2427 | } |
| 2428 | |
| 2429 | /* helper function for pulling the mac address out of the private */ |
| 2430 | /* data's copy of the eeprom data */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2431 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2432 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2433 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | /* |
| 2437 | * Either the device driver (i.e. the host) or the firmware can |
| 2438 | * load eeprom data into the designated region in SRAM. If neither |
| 2439 | * happens then the FW will shutdown with a fatal error. |
| 2440 | * |
| 2441 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE |
| 2442 | * bit needs region of shared SRAM needs to be non-zero. |
| 2443 | */ |
| 2444 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) |
| 2445 | { |
| 2446 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2447 | u16 *eeprom = (u16 *) priv->eeprom; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2448 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2449 | IPW_DEBUG_TRACE(">>\n"); |
| 2450 | |
| 2451 | /* read entire contents of eeprom into private buffer */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2452 | for (i = 0; i < 128; i++) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2453 | eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2454 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2455 | /* |
| 2456 | If the data looks correct, then copy it to our private |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2457 | copy. Otherwise let the firmware know to perform the operation |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2458 | on its own. |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2459 | */ |
Alexey Dobriyan | 386093e | 2006-02-01 03:04:57 -0800 | [diff] [blame] | 2460 | if (priv->eeprom[EEPROM_VERSION] != 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2461 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
| 2462 | |
| 2463 | /* write the eeprom data to sram */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2464 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2465 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2466 | |
| 2467 | /* Do not load eeprom data on fatal error or suspend */ |
| 2468 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 2469 | } else { |
| 2470 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); |
| 2471 | |
| 2472 | /* Load eeprom data on fatal error or suspend */ |
| 2473 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); |
| 2474 | } |
| 2475 | |
| 2476 | IPW_DEBUG_TRACE("<<\n"); |
| 2477 | } |
| 2478 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2479 | 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] | 2480 | { |
| 2481 | count >>= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2482 | if (!count) |
| 2483 | return; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2484 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2485 | while (count--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2486 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) |
| 2490 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2491 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2492 | CB_NUMBER_OF_ELEMENTS_SMALL * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2493 | sizeof(struct command_block)); |
| 2494 | } |
| 2495 | |
| 2496 | static int ipw_fw_dma_enable(struct ipw_priv *priv) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2497 | { /* start dma engine but no transfers yet */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2498 | |
| 2499 | IPW_DEBUG_FW(">> : \n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2500 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2501 | /* Start the dma */ |
| 2502 | ipw_fw_dma_reset_command_blocks(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2503 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2504 | /* Write CB base address */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2505 | 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] | 2506 | |
| 2507 | IPW_DEBUG_FW("<< : \n"); |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
| 2511 | static void ipw_fw_dma_abort(struct ipw_priv *priv) |
| 2512 | { |
| 2513 | u32 control = 0; |
| 2514 | |
| 2515 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2516 | |
| 2517 | //set the Stop and Abort bit |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2518 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2519 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2520 | priv->sram_desc.last_cb_index = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2521 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2522 | IPW_DEBUG_FW("<< \n"); |
| 2523 | } |
| 2524 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2525 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
| 2526 | struct command_block *cb) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2527 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2528 | u32 address = |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2529 | IPW_SHARED_SRAM_DMA_CONTROL + |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2530 | (sizeof(struct command_block) * index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2531 | IPW_DEBUG_FW(">> :\n"); |
| 2532 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2533 | ipw_write_indirect(priv, address, (u8 *) cb, |
| 2534 | (int)sizeof(struct command_block)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2535 | |
| 2536 | IPW_DEBUG_FW("<< :\n"); |
| 2537 | return 0; |
| 2538 | |
| 2539 | } |
| 2540 | |
| 2541 | static int ipw_fw_dma_kick(struct ipw_priv *priv) |
| 2542 | { |
| 2543 | u32 control = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2544 | u32 index = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2545 | |
| 2546 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2547 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2548 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2549 | ipw_fw_dma_write_command_block(priv, index, |
| 2550 | &priv->sram_desc.cb_list[index]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2551 | |
| 2552 | /* Enable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2553 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 2554 | IPW_RESET_REG_MASTER_DISABLED | |
| 2555 | IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2556 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2557 | /* Set the Start bit. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2558 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2559 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2560 | |
| 2561 | IPW_DEBUG_FW("<< :\n"); |
| 2562 | return 0; |
| 2563 | } |
| 2564 | |
| 2565 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) |
| 2566 | { |
| 2567 | u32 address; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2568 | u32 register_value = 0; |
| 2569 | u32 cb_fields_address = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2570 | |
| 2571 | IPW_DEBUG_FW(">> :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2572 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2573 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2574 | |
| 2575 | /* Read the DMA Controlor register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2576 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
| 2577 | 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] | 2578 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2579 | /* Print the CB values */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2580 | cb_fields_address = address; |
| 2581 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2582 | IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2583 | |
| 2584 | cb_fields_address += sizeof(u32); |
| 2585 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2586 | 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] | 2587 | |
| 2588 | cb_fields_address += sizeof(u32); |
| 2589 | register_value = ipw_read_reg32(priv, cb_fields_address); |
| 2590 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", |
| 2591 | register_value); |
| 2592 | |
| 2593 | cb_fields_address += sizeof(u32); |
| 2594 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2595 | 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] | 2596 | |
| 2597 | IPW_DEBUG_FW(">> :\n"); |
| 2598 | } |
| 2599 | |
| 2600 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) |
| 2601 | { |
| 2602 | u32 current_cb_address = 0; |
| 2603 | u32 current_cb_index = 0; |
| 2604 | |
| 2605 | IPW_DEBUG_FW("<< :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2606 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2607 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2608 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2609 | sizeof(struct command_block); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2610 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2611 | 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] | 2612 | current_cb_index, current_cb_address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2613 | |
| 2614 | IPW_DEBUG_FW(">> :\n"); |
| 2615 | return current_cb_index; |
| 2616 | |
| 2617 | } |
| 2618 | |
| 2619 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, |
| 2620 | u32 src_address, |
| 2621 | u32 dest_address, |
| 2622 | u32 length, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2623 | int interrupt_enabled, int is_last) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2624 | { |
| 2625 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2626 | 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] | 2627 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
| 2628 | CB_DEST_SIZE_LONG; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2629 | struct command_block *cb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2630 | u32 last_cb_element = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2631 | |
| 2632 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", |
| 2633 | src_address, dest_address, length); |
| 2634 | |
| 2635 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) |
| 2636 | return -1; |
| 2637 | |
| 2638 | last_cb_element = priv->sram_desc.last_cb_index; |
| 2639 | cb = &priv->sram_desc.cb_list[last_cb_element]; |
| 2640 | priv->sram_desc.last_cb_index++; |
| 2641 | |
| 2642 | /* Calculate the new CB control word */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2643 | if (interrupt_enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2644 | control |= CB_INT_ENABLED; |
| 2645 | |
| 2646 | if (is_last) |
| 2647 | control |= CB_LAST_VALID; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2648 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2649 | control |= length; |
| 2650 | |
| 2651 | /* Calculate the CB Element's checksum value */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2652 | cb->status = control ^ src_address ^ dest_address; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2653 | |
| 2654 | /* Copy the Source and Destination addresses */ |
| 2655 | cb->dest_addr = dest_address; |
| 2656 | cb->source_addr = src_address; |
| 2657 | |
| 2658 | /* Copy the Control Word last */ |
| 2659 | cb->control = control; |
| 2660 | |
| 2661 | return 0; |
| 2662 | } |
| 2663 | |
| 2664 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2665 | u32 src_phys, u32 dest_address, u32 length) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2666 | { |
| 2667 | u32 bytes_left = length; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2668 | u32 src_offset = 0; |
| 2669 | u32 dest_offset = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2670 | int status = 0; |
| 2671 | IPW_DEBUG_FW(">> \n"); |
| 2672 | IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n", |
| 2673 | src_phys, dest_address, length); |
| 2674 | while (bytes_left > CB_MAX_LENGTH) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2675 | status = ipw_fw_dma_add_command_block(priv, |
| 2676 | src_phys + src_offset, |
| 2677 | dest_address + |
| 2678 | dest_offset, |
| 2679 | CB_MAX_LENGTH, 0, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2680 | if (status) { |
| 2681 | IPW_DEBUG_FW_INFO(": Failed\n"); |
| 2682 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2683 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2684 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
| 2685 | |
| 2686 | src_offset += CB_MAX_LENGTH; |
| 2687 | dest_offset += CB_MAX_LENGTH; |
| 2688 | bytes_left -= CB_MAX_LENGTH; |
| 2689 | } |
| 2690 | |
| 2691 | /* add the buffer tail */ |
| 2692 | if (bytes_left > 0) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2693 | status = |
| 2694 | ipw_fw_dma_add_command_block(priv, src_phys + src_offset, |
| 2695 | dest_address + dest_offset, |
| 2696 | bytes_left, 0, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2697 | if (status) { |
| 2698 | IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n"); |
| 2699 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2700 | } else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2701 | IPW_DEBUG_FW_INFO |
| 2702 | (": Adding new cb - the buffer tail\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2703 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2704 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2705 | IPW_DEBUG_FW("<< \n"); |
| 2706 | return 0; |
| 2707 | } |
| 2708 | |
| 2709 | static int ipw_fw_dma_wait(struct ipw_priv *priv) |
| 2710 | { |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2711 | u32 current_index = 0, previous_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2712 | u32 watchdog = 0; |
| 2713 | |
| 2714 | IPW_DEBUG_FW(">> : \n"); |
| 2715 | |
| 2716 | current_index = ipw_fw_dma_command_block_index(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2717 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2718 | (int)priv->sram_desc.last_cb_index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2719 | |
| 2720 | while (current_index < priv->sram_desc.last_cb_index) { |
| 2721 | udelay(50); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2722 | previous_index = current_index; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2723 | current_index = ipw_fw_dma_command_block_index(priv); |
| 2724 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 2725 | if (previous_index < current_index) { |
| 2726 | watchdog = 0; |
| 2727 | continue; |
| 2728 | } |
| 2729 | if (++watchdog > 400) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2730 | IPW_DEBUG_FW_INFO("Timeout\n"); |
| 2731 | ipw_fw_dma_dump_command_block(priv); |
| 2732 | ipw_fw_dma_abort(priv); |
| 2733 | return -1; |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | ipw_fw_dma_abort(priv); |
| 2738 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2739 | /*Disable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2740 | ipw_set_bit(priv, IPW_RESET_REG, |
| 2741 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2742 | |
| 2743 | IPW_DEBUG_FW("<< dmaWaitSync \n"); |
| 2744 | return 0; |
| 2745 | } |
| 2746 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2747 | static void ipw_remove_current_network(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2748 | { |
| 2749 | struct list_head *element, *safe; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2750 | struct ieee80211_network *network = NULL; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2751 | unsigned long flags; |
| 2752 | |
| 2753 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2754 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
| 2755 | network = list_entry(element, struct ieee80211_network, list); |
| 2756 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 2757 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2758 | list_add_tail(&network->list, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2759 | &priv->ieee->network_free_list); |
| 2760 | } |
| 2761 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2762 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | /** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2766 | * Check that card is still alive. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2767 | * Reads debug register from domain0. |
| 2768 | * If card is present, pre-defined value should |
| 2769 | * be found there. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2770 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2771 | * @param priv |
| 2772 | * @return 1 if card is present, 0 otherwise |
| 2773 | */ |
| 2774 | static inline int ipw_alive(struct ipw_priv *priv) |
| 2775 | { |
| 2776 | return ipw_read32(priv, 0x90) == 0xd55555d5; |
| 2777 | } |
| 2778 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2779 | /* timeout in msec, attempted in 10-msec quanta */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2780 | 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] | 2781 | int timeout) |
| 2782 | { |
| 2783 | int i = 0; |
| 2784 | |
| 2785 | do { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2786 | if ((ipw_read32(priv, addr) & mask) == mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2787 | return i; |
| 2788 | mdelay(10); |
| 2789 | i += 10; |
| 2790 | } while (i < timeout); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2791 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2792 | return -ETIME; |
| 2793 | } |
| 2794 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2795 | /* These functions load the firmware and micro code for the operation of |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2796 | * the ipw hardware. It assumes the buffer has all the bits for the |
| 2797 | * image and the caller is handling the memory allocation and clean up. |
| 2798 | */ |
| 2799 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2800 | static int ipw_stop_master(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2801 | { |
| 2802 | int rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2803 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2804 | IPW_DEBUG_TRACE(">> \n"); |
| 2805 | /* stop master. typical delay - 0 */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2806 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2807 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2808 | /* timeout is in msec, polled in 10-msec quanta */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2809 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 2810 | IPW_RESET_REG_MASTER_DISABLED, 100); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2811 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 2812 | IPW_ERROR("wait for stop master failed after 100ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2813 | return -1; |
| 2814 | } |
| 2815 | |
| 2816 | IPW_DEBUG_INFO("stop master %dms\n", rc); |
| 2817 | |
| 2818 | return rc; |
| 2819 | } |
| 2820 | |
| 2821 | static void ipw_arc_release(struct ipw_priv *priv) |
| 2822 | { |
| 2823 | IPW_DEBUG_TRACE(">> \n"); |
| 2824 | mdelay(5); |
| 2825 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2826 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2827 | |
| 2828 | /* no one knows timing, for safety add some delay */ |
| 2829 | mdelay(5); |
| 2830 | } |
| 2831 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2832 | struct fw_chunk { |
| 2833 | u32 address; |
| 2834 | u32 length; |
| 2835 | }; |
| 2836 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2837 | 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] | 2838 | { |
| 2839 | int rc = 0, i, addr; |
| 2840 | u8 cr = 0; |
| 2841 | u16 *image; |
| 2842 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2843 | image = (u16 *) data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2844 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2845 | IPW_DEBUG_TRACE(">> \n"); |
| 2846 | |
| 2847 | rc = ipw_stop_master(priv); |
| 2848 | |
| 2849 | if (rc < 0) |
| 2850 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2851 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2852 | // spin_lock_irqsave(&priv->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2853 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2854 | for (addr = IPW_SHARED_LOWER_BOUND; |
| 2855 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2856 | ipw_write32(priv, addr, 0); |
| 2857 | } |
| 2858 | |
| 2859 | /* no ucode (yet) */ |
| 2860 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); |
| 2861 | /* destroy DMA queues */ |
| 2862 | /* reset sequence */ |
| 2863 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2864 | 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] | 2865 | ipw_arc_release(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2866 | 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] | 2867 | mdelay(1); |
| 2868 | |
| 2869 | /* reset PHY */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2870 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2871 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2872 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2873 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2874 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2875 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2876 | /* enable ucode store */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 2877 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
| 2878 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2879 | mdelay(1); |
| 2880 | |
| 2881 | /* write ucode */ |
| 2882 | /** |
| 2883 | * @bug |
| 2884 | * Do NOT set indirect address register once and then |
| 2885 | * store data to indirect data register in the loop. |
| 2886 | * It seems very reasonable, but in this case DINO do not |
| 2887 | * accept ucode. It is essential to set address each time. |
| 2888 | */ |
| 2889 | /* load new ipw uCode */ |
| 2890 | for (i = 0; i < len / 2; i++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2891 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2892 | cpu_to_le16(image[i])); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2893 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2894 | /* enable DINO */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2895 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
| 2896 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2897 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2898 | /* this is where the igx / win driver deveates from the VAP driver. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2899 | |
| 2900 | /* wait for alive response */ |
| 2901 | for (i = 0; i < 100; i++) { |
| 2902 | /* poll for incoming data */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2903 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2904 | if (cr & DINO_RXFIFO_DATA) |
| 2905 | break; |
| 2906 | mdelay(1); |
| 2907 | } |
| 2908 | |
| 2909 | if (cr & DINO_RXFIFO_DATA) { |
| 2910 | /* alive_command_responce size is NOT multiple of 4 */ |
| 2911 | u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2912 | |
| 2913 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2914 | response_buffer[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2915 | le32_to_cpu(ipw_read_reg32(priv, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2916 | IPW_BASEBAND_RX_FIFO_READ)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2917 | memcpy(&priv->dino_alive, response_buffer, |
| 2918 | sizeof(priv->dino_alive)); |
| 2919 | if (priv->dino_alive.alive_command == 1 |
| 2920 | && priv->dino_alive.ucode_valid == 1) { |
| 2921 | rc = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2922 | IPW_DEBUG_INFO |
| 2923 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " |
| 2924 | "of %02d/%02d/%02d %02d:%02d\n", |
| 2925 | priv->dino_alive.software_revision, |
| 2926 | priv->dino_alive.software_revision, |
| 2927 | priv->dino_alive.device_identifier, |
| 2928 | priv->dino_alive.device_identifier, |
| 2929 | priv->dino_alive.time_stamp[0], |
| 2930 | priv->dino_alive.time_stamp[1], |
| 2931 | priv->dino_alive.time_stamp[2], |
| 2932 | priv->dino_alive.time_stamp[3], |
| 2933 | priv->dino_alive.time_stamp[4]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2934 | } else { |
| 2935 | IPW_DEBUG_INFO("Microcode is not alive\n"); |
| 2936 | rc = -EINVAL; |
| 2937 | } |
| 2938 | } else { |
| 2939 | IPW_DEBUG_INFO("No alive response from DINO\n"); |
| 2940 | rc = -ETIME; |
| 2941 | } |
| 2942 | |
| 2943 | /* disable DINO, otherwise for some reason |
| 2944 | firmware have problem getting alive resp. */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2945 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2946 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2947 | // spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2948 | |
| 2949 | return rc; |
| 2950 | } |
| 2951 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2952 | 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] | 2953 | { |
| 2954 | int rc = -1; |
| 2955 | int offset = 0; |
| 2956 | struct fw_chunk *chunk; |
| 2957 | dma_addr_t shared_phys; |
| 2958 | u8 *shared_virt; |
| 2959 | |
| 2960 | IPW_DEBUG_TRACE("<< : \n"); |
| 2961 | shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys); |
| 2962 | |
| 2963 | if (!shared_virt) |
| 2964 | return -ENOMEM; |
| 2965 | |
| 2966 | memmove(shared_virt, data, len); |
| 2967 | |
| 2968 | /* Start the Dma */ |
| 2969 | rc = ipw_fw_dma_enable(priv); |
| 2970 | |
| 2971 | if (priv->sram_desc.last_cb_index > 0) { |
| 2972 | /* the DMA is already ready this would be a bug. */ |
| 2973 | BUG(); |
| 2974 | goto out; |
| 2975 | } |
| 2976 | |
| 2977 | do { |
| 2978 | chunk = (struct fw_chunk *)(data + offset); |
| 2979 | offset += sizeof(struct fw_chunk); |
| 2980 | /* build DMA packet and queue up for sending */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2981 | /* dma to chunk->address, the chunk->length bytes from data + |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2982 | * offeset*/ |
| 2983 | /* Dma loading */ |
| 2984 | rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2985 | le32_to_cpu(chunk->address), |
| 2986 | le32_to_cpu(chunk->length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2987 | if (rc) { |
| 2988 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
| 2989 | goto out; |
| 2990 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2991 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2992 | offset += le32_to_cpu(chunk->length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2993 | } while (offset < len); |
| 2994 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2995 | /* Run the DMA and wait for the answer */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2996 | rc = ipw_fw_dma_kick(priv); |
| 2997 | if (rc) { |
| 2998 | IPW_ERROR("dmaKick Failed\n"); |
| 2999 | goto out; |
| 3000 | } |
| 3001 | |
| 3002 | rc = ipw_fw_dma_wait(priv); |
| 3003 | if (rc) { |
| 3004 | IPW_ERROR("dmaWaitSync Failed\n"); |
| 3005 | goto out; |
| 3006 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3007 | out: |
| 3008 | pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3009 | return rc; |
| 3010 | } |
| 3011 | |
| 3012 | /* stop nic */ |
| 3013 | static int ipw_stop_nic(struct ipw_priv *priv) |
| 3014 | { |
| 3015 | int rc = 0; |
| 3016 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3017 | /* stop */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3018 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3019 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3020 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3021 | IPW_RESET_REG_MASTER_DISABLED, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3022 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3023 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3024 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3025 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3026 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3027 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3028 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3029 | return rc; |
| 3030 | } |
| 3031 | |
| 3032 | static void ipw_start_nic(struct ipw_priv *priv) |
| 3033 | { |
| 3034 | IPW_DEBUG_TRACE(">>\n"); |
| 3035 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3036 | /* prvHwStartNic release ARC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3037 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 3038 | IPW_RESET_REG_MASTER_DISABLED | |
| 3039 | IPW_RESET_REG_STOP_MASTER | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3040 | CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3041 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3042 | /* enable power management */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3043 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
| 3044 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3045 | |
| 3046 | IPW_DEBUG_TRACE("<<\n"); |
| 3047 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3048 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3049 | static int ipw_init_nic(struct ipw_priv *priv) |
| 3050 | { |
| 3051 | int rc; |
| 3052 | |
| 3053 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3054 | /* reset */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3055 | /*prvHwInitNic */ |
| 3056 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3057 | 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] | 3058 | |
| 3059 | /* low-level PLL activation */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3060 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
| 3061 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3062 | |
| 3063 | /* wait for clock stabilization */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3064 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
| 3065 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3066 | if (rc < 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3067 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
| 3068 | |
| 3069 | /* assert SW reset */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3070 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3071 | |
| 3072 | udelay(10); |
| 3073 | |
| 3074 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3075 | 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] | 3076 | |
| 3077 | IPW_DEBUG_TRACE(">>\n"); |
| 3078 | return 0; |
| 3079 | } |
| 3080 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3081 | /* Call this function from process context, it will sleep in request_firmware. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3082 | * Probe is an ok place to call this from. |
| 3083 | */ |
| 3084 | static int ipw_reset_nic(struct ipw_priv *priv) |
| 3085 | { |
| 3086 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3087 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3088 | |
| 3089 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3090 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3091 | rc = ipw_init_nic(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3092 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3093 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3094 | /* Clear the 'host command active' bit... */ |
| 3095 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 3096 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3097 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 3098 | wake_up_interruptible(&priv->wait_state); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3099 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3100 | |
| 3101 | IPW_DEBUG_TRACE("<<\n"); |
| 3102 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3103 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3104 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3105 | |
| 3106 | struct ipw_fw { |
| 3107 | u32 ver; |
| 3108 | u32 boot_size; |
| 3109 | u32 ucode_size; |
| 3110 | u32 fw_size; |
| 3111 | u8 data[0]; |
| 3112 | }; |
| 3113 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3114 | static int ipw_get_fw(struct ipw_priv *priv, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3115 | const struct firmware **raw, const char *name) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3116 | { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3117 | struct ipw_fw *fw; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3118 | int rc; |
| 3119 | |
| 3120 | /* ask firmware_class module to get the boot firmware off disk */ |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3121 | rc = request_firmware(raw, name, &priv->pci_dev->dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3122 | if (rc < 0) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3123 | IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3124 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3125 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3126 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3127 | if ((*raw)->size < sizeof(*fw)) { |
| 3128 | IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3129 | return -EINVAL; |
| 3130 | } |
| 3131 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3132 | fw = (void *)(*raw)->data; |
| 3133 | |
| 3134 | if ((*raw)->size < sizeof(*fw) + |
| 3135 | fw->boot_size + fw->ucode_size + fw->fw_size) { |
| 3136 | IPW_ERROR("%s is too small or corrupt (%zd)\n", |
| 3137 | name, (*raw)->size); |
| 3138 | return -EINVAL; |
| 3139 | } |
| 3140 | |
| 3141 | 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] | 3142 | name, |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3143 | le32_to_cpu(fw->ver) >> 16, |
| 3144 | le32_to_cpu(fw->ver) & 0xff, |
| 3145 | (*raw)->size - sizeof(*fw)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3146 | return 0; |
| 3147 | } |
| 3148 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3149 | #define IPW_RX_BUF_SIZE (3000) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3150 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3151 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3152 | struct ipw_rx_queue *rxq) |
| 3153 | { |
| 3154 | unsigned long flags; |
| 3155 | int i; |
| 3156 | |
| 3157 | spin_lock_irqsave(&rxq->lock, flags); |
| 3158 | |
| 3159 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3160 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3161 | |
| 3162 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3163 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3164 | /* In the reset function, these buffers may have been allocated |
| 3165 | * to an SKB, so we need to unmap and free potential storage */ |
| 3166 | if (rxq->pool[i].skb != NULL) { |
| 3167 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3168 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3169 | dev_kfree_skb(rxq->pool[i].skb); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3170 | rxq->pool[i].skb = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3171 | } |
| 3172 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3173 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3174 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3175 | /* Set us so that we have processed and used all buffers, but have |
| 3176 | * not restocked the Rx queue with fresh buffers */ |
| 3177 | rxq->read = rxq->write = 0; |
| 3178 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 3179 | rxq->free_count = 0; |
| 3180 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3181 | } |
| 3182 | |
| 3183 | #ifdef CONFIG_PM |
| 3184 | static int fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3185 | static const struct firmware *raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3186 | |
| 3187 | static void free_firmware(void) |
| 3188 | { |
| 3189 | if (fw_loaded) { |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3190 | release_firmware(raw); |
| 3191 | raw = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3192 | fw_loaded = 0; |
| 3193 | } |
| 3194 | } |
| 3195 | #else |
| 3196 | #define free_firmware() do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3197 | #endif |
| 3198 | |
| 3199 | static int ipw_load(struct ipw_priv *priv) |
| 3200 | { |
| 3201 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3202 | const struct firmware *raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3203 | #endif |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3204 | struct ipw_fw *fw; |
| 3205 | u8 *boot_img, *ucode_img, *fw_img; |
| 3206 | u8 *name = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3207 | int rc = 0, retries = 3; |
| 3208 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3209 | switch (priv->ieee->iw_mode) { |
| 3210 | case IW_MODE_ADHOC: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3211 | name = "ipw2200-ibss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3212 | break; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3213 | #ifdef CONFIG_IPW2200_MONITOR |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3214 | case IW_MODE_MONITOR: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3215 | name = "ipw2200-sniffer.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3216 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3217 | #endif |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3218 | case IW_MODE_INFRA: |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3219 | name = "ipw2200-bss.fw"; |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3220 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3221 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3222 | |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3223 | if (!name) { |
| 3224 | rc = -EINVAL; |
| 3225 | goto error; |
| 3226 | } |
| 3227 | |
| 3228 | #ifdef CONFIG_PM |
| 3229 | if (!fw_loaded) { |
| 3230 | #endif |
| 3231 | rc = ipw_get_fw(priv, &raw, name); |
| 3232 | if (rc < 0) |
| 3233 | goto error; |
| 3234 | #ifdef CONFIG_PM |
| 3235 | } |
| 3236 | #endif |
| 3237 | |
| 3238 | fw = (void *)raw->data; |
| 3239 | boot_img = &fw->data[0]; |
| 3240 | ucode_img = &fw->data[fw->boot_size]; |
| 3241 | fw_img = &fw->data[fw->boot_size + fw->ucode_size]; |
| 3242 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3243 | if (rc < 0) |
| 3244 | goto error; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3245 | |
| 3246 | if (!priv->rxq) |
| 3247 | priv->rxq = ipw_rx_queue_alloc(priv); |
| 3248 | else |
| 3249 | ipw_rx_queue_reset(priv, priv->rxq); |
| 3250 | if (!priv->rxq) { |
| 3251 | IPW_ERROR("Unable to initialize Rx queue\n"); |
| 3252 | goto error; |
| 3253 | } |
| 3254 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3255 | retry: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3256 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3257 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3258 | priv->status &= ~STATUS_INT_ENABLED; |
| 3259 | |
| 3260 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3261 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3262 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3263 | ipw_stop_nic(priv); |
| 3264 | |
| 3265 | rc = ipw_reset_nic(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3266 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3267 | IPW_ERROR("Unable to reset NIC\n"); |
| 3268 | goto error; |
| 3269 | } |
| 3270 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3271 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
| 3272 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3273 | |
| 3274 | /* DMA the initial boot firmware into the device */ |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3275 | rc = ipw_load_firmware(priv, boot_img, fw->boot_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3276 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3277 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3278 | goto error; |
| 3279 | } |
| 3280 | |
| 3281 | /* kick start the device */ |
| 3282 | ipw_start_nic(priv); |
| 3283 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3284 | /* wait for the device to finish its initial startup sequence */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3285 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3286 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3287 | if (rc < 0) { |
| 3288 | IPW_ERROR("device failed to boot initial fw image\n"); |
| 3289 | goto error; |
| 3290 | } |
| 3291 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); |
| 3292 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3293 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3294 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3295 | |
| 3296 | /* DMA the ucode into the device */ |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3297 | rc = ipw_load_ucode(priv, ucode_img, fw->ucode_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3298 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3299 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3300 | goto error; |
| 3301 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3302 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3303 | /* stop nic */ |
| 3304 | ipw_stop_nic(priv); |
| 3305 | |
| 3306 | /* DMA bss firmware into the device */ |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3307 | rc = ipw_load_firmware(priv, fw_img, fw->fw_size); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3308 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3309 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3310 | goto error; |
| 3311 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3312 | #ifdef CONFIG_PM |
| 3313 | fw_loaded = 1; |
| 3314 | #endif |
| 3315 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3316 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 3317 | |
| 3318 | rc = ipw_queue_reset(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3319 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3320 | IPW_ERROR("Unable to initialize queues\n"); |
| 3321 | goto error; |
| 3322 | } |
| 3323 | |
| 3324 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3325 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3326 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3327 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3328 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3329 | /* kick start the device */ |
| 3330 | ipw_start_nic(priv); |
| 3331 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3332 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3333 | if (retries > 0) { |
| 3334 | IPW_WARNING("Parity error. Retrying init.\n"); |
| 3335 | retries--; |
| 3336 | goto retry; |
| 3337 | } |
| 3338 | |
| 3339 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); |
| 3340 | rc = -EIO; |
| 3341 | goto error; |
| 3342 | } |
| 3343 | |
| 3344 | /* wait for the device */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3345 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3346 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3347 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3348 | IPW_ERROR("device failed to start within 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3349 | goto error; |
| 3350 | } |
| 3351 | IPW_DEBUG_INFO("device response after %dms\n", rc); |
| 3352 | |
| 3353 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3354 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3355 | |
| 3356 | /* read eeprom data and initialize the eeprom region of sram */ |
| 3357 | priv->eeprom_delay = 1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3358 | ipw_eeprom_init_sram(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3359 | |
| 3360 | /* enable interrupts */ |
| 3361 | ipw_enable_interrupts(priv); |
| 3362 | |
| 3363 | /* Ensure our queue has valid packets */ |
| 3364 | ipw_rx_queue_replenish(priv); |
| 3365 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3366 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3367 | |
| 3368 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3369 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3370 | |
| 3371 | #ifndef CONFIG_PM |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3372 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3373 | #endif |
| 3374 | return 0; |
| 3375 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3376 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3377 | if (priv->rxq) { |
| 3378 | ipw_rx_queue_free(priv, priv->rxq); |
| 3379 | priv->rxq = NULL; |
| 3380 | } |
| 3381 | ipw_tx_queue_free(priv); |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3382 | if (raw) |
| 3383 | release_firmware(raw); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3384 | #ifdef CONFIG_PM |
| 3385 | fw_loaded = 0; |
James Ketrenos | 9006ea7 | 2006-03-08 03:22:28 +0800 | [diff] [blame] | 3386 | raw = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3387 | #endif |
| 3388 | |
| 3389 | return rc; |
| 3390 | } |
| 3391 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3392 | /** |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3393 | * DMA services |
| 3394 | * |
| 3395 | * Theory of operation |
| 3396 | * |
| 3397 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 3398 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 3399 | * |
| 3400 | * 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] | 3401 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 3402 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3403 | * Tx queue resumed. |
| 3404 | * |
| 3405 | * The IPW operates with six queues, one receive queue in the device's |
| 3406 | * sram, one transmit queue for sending commands to the device firmware, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3407 | * and four transmit queues for data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3408 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3409 | * The four transmit queues allow for performing quality of service (qos) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3410 | * transmissions as per the 802.11 protocol. Currently Linux does not |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3411 | * provide a mechanism to the user for utilizing prioritized queues, so |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3412 | * we only utilize the first data transmit queue (queue1). |
| 3413 | */ |
| 3414 | |
| 3415 | /** |
| 3416 | * Driver allocates buffers of this size for Rx |
| 3417 | */ |
| 3418 | |
| 3419 | static inline int ipw_queue_space(const struct clx2_queue *q) |
| 3420 | { |
| 3421 | int s = q->last_used - q->first_empty; |
| 3422 | if (s <= 0) |
| 3423 | s += q->n_bd; |
| 3424 | s -= 2; /* keep some reserve to not confuse empty and full situations */ |
| 3425 | if (s < 0) |
| 3426 | s = 0; |
| 3427 | return s; |
| 3428 | } |
| 3429 | |
| 3430 | static inline int ipw_queue_inc_wrap(int index, int n_bd) |
| 3431 | { |
| 3432 | return (++index == n_bd) ? 0 : index; |
| 3433 | } |
| 3434 | |
| 3435 | /** |
| 3436 | * Initialize common DMA queue structure |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3437 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3438 | * @param q queue to init |
| 3439 | * @param count Number of BD's to allocate. Should be power of 2 |
| 3440 | * @param read_register Address for 'read' register |
| 3441 | * (not offset within BAR, full address) |
| 3442 | * @param write_register Address for 'write' register |
| 3443 | * (not offset within BAR, full address) |
| 3444 | * @param base_register Address for 'base' register |
| 3445 | * (not offset within BAR, full address) |
| 3446 | * @param size Address for 'size' register |
| 3447 | * (not offset within BAR, full address) |
| 3448 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3449 | 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] | 3450 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3451 | { |
| 3452 | q->n_bd = count; |
| 3453 | |
| 3454 | q->low_mark = q->n_bd / 4; |
| 3455 | if (q->low_mark < 4) |
| 3456 | q->low_mark = 4; |
| 3457 | |
| 3458 | q->high_mark = q->n_bd / 8; |
| 3459 | if (q->high_mark < 2) |
| 3460 | q->high_mark = 2; |
| 3461 | |
| 3462 | q->first_empty = q->last_used = 0; |
| 3463 | q->reg_r = read; |
| 3464 | q->reg_w = write; |
| 3465 | |
| 3466 | ipw_write32(priv, base, q->dma_addr); |
| 3467 | ipw_write32(priv, size, count); |
| 3468 | ipw_write32(priv, read, 0); |
| 3469 | ipw_write32(priv, write, 0); |
| 3470 | |
| 3471 | _ipw_read32(priv, 0x90); |
| 3472 | } |
| 3473 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3474 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3475 | struct clx2_tx_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3476 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3477 | { |
| 3478 | struct pci_dev *dev = priv->pci_dev; |
| 3479 | |
| 3480 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); |
| 3481 | if (!q->txb) { |
| 3482 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); |
| 3483 | return -ENOMEM; |
| 3484 | } |
| 3485 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3486 | q->bd = |
| 3487 | 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] | 3488 | if (!q->bd) { |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3489 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3490 | sizeof(q->bd[0]) * count); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3491 | kfree(q->txb); |
| 3492 | q->txb = NULL; |
| 3493 | return -ENOMEM; |
| 3494 | } |
| 3495 | |
| 3496 | ipw_queue_init(priv, &q->q, count, read, write, base, size); |
| 3497 | return 0; |
| 3498 | } |
| 3499 | |
| 3500 | /** |
| 3501 | * Free one TFD, those at index [txq->q.last_used]. |
| 3502 | * Do NOT advance any indexes |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3503 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3504 | * @param dev |
| 3505 | * @param txq |
| 3506 | */ |
| 3507 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, |
| 3508 | struct clx2_tx_queue *txq) |
| 3509 | { |
| 3510 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; |
| 3511 | struct pci_dev *dev = priv->pci_dev; |
| 3512 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3513 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3514 | /* classify bd */ |
| 3515 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) |
| 3516 | /* nothing to cleanup after for host commands */ |
| 3517 | return; |
| 3518 | |
| 3519 | /* sanity check */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3520 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
| 3521 | IPW_ERROR("Too many chunks: %i\n", |
| 3522 | le32_to_cpu(bd->u.data.num_chunks)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3523 | /** @todo issue fatal error, it is quite serious situation */ |
| 3524 | return; |
| 3525 | } |
| 3526 | |
| 3527 | /* unmap chunks if any */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3528 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
| 3529 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), |
| 3530 | le16_to_cpu(bd->u.data.chunk_len[i]), |
| 3531 | PCI_DMA_TODEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3532 | if (txq->txb[txq->q.last_used]) { |
| 3533 | ieee80211_txb_free(txq->txb[txq->q.last_used]); |
| 3534 | txq->txb[txq->q.last_used] = NULL; |
| 3535 | } |
| 3536 | } |
| 3537 | } |
| 3538 | |
| 3539 | /** |
| 3540 | * Deallocate DMA queue. |
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 | * Empty queue by removing and destroying all BD's. |
| 3543 | * Free all buffers. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3544 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3545 | * @param dev |
| 3546 | * @param q |
| 3547 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3548 | 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] | 3549 | { |
| 3550 | struct clx2_queue *q = &txq->q; |
| 3551 | struct pci_dev *dev = priv->pci_dev; |
| 3552 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3553 | if (q->n_bd == 0) |
| 3554 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3555 | |
| 3556 | /* first, empty all BD's */ |
| 3557 | for (; q->first_empty != q->last_used; |
| 3558 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3559 | ipw_queue_tx_free_tfd(priv, txq); |
| 3560 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3561 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3562 | /* free buffers belonging to queue itself */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3563 | 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] | 3564 | q->dma_addr); |
| 3565 | kfree(txq->txb); |
| 3566 | |
| 3567 | /* 0 fill whole structure */ |
| 3568 | memset(txq, 0, sizeof(*txq)); |
| 3569 | } |
| 3570 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3571 | /** |
| 3572 | * Destroy all DMA queues and structures |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3573 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3574 | * @param priv |
| 3575 | */ |
| 3576 | static void ipw_tx_queue_free(struct ipw_priv *priv) |
| 3577 | { |
| 3578 | /* Tx CMD queue */ |
| 3579 | ipw_queue_tx_free(priv, &priv->txq_cmd); |
| 3580 | |
| 3581 | /* Tx queues */ |
| 3582 | ipw_queue_tx_free(priv, &priv->txq[0]); |
| 3583 | ipw_queue_tx_free(priv, &priv->txq[1]); |
| 3584 | ipw_queue_tx_free(priv, &priv->txq[2]); |
| 3585 | ipw_queue_tx_free(priv, &priv->txq[3]); |
| 3586 | } |
| 3587 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3588 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3589 | { |
| 3590 | /* First 3 bytes are manufacturer */ |
| 3591 | bssid[0] = priv->mac_addr[0]; |
| 3592 | bssid[1] = priv->mac_addr[1]; |
| 3593 | bssid[2] = priv->mac_addr[2]; |
| 3594 | |
| 3595 | /* Last bytes are random */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3596 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3597 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3598 | bssid[0] &= 0xfe; /* clear multicast bit */ |
| 3599 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3600 | } |
| 3601 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3602 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3603 | { |
| 3604 | struct ipw_station_entry entry; |
| 3605 | int i; |
| 3606 | |
| 3607 | for (i = 0; i < priv->num_stations; i++) { |
| 3608 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { |
| 3609 | /* Another node is active in network */ |
| 3610 | priv->missed_adhoc_beacons = 0; |
| 3611 | if (!(priv->config & CFG_STATIC_CHANNEL)) |
| 3612 | /* when other nodes drop out, we drop out */ |
| 3613 | priv->config &= ~CFG_ADHOC_PERSIST; |
| 3614 | |
| 3615 | return i; |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | if (i == MAX_STATIONS) |
| 3620 | return IPW_INVALID_STATION; |
| 3621 | |
| 3622 | IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid)); |
| 3623 | |
| 3624 | entry.reserved = 0; |
| 3625 | entry.support_mode = 0; |
| 3626 | memcpy(entry.mac_addr, bssid, ETH_ALEN); |
| 3627 | memcpy(priv->stations[i], bssid, ETH_ALEN); |
| 3628 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3629 | &entry, sizeof(entry)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3630 | priv->num_stations++; |
| 3631 | |
| 3632 | return i; |
| 3633 | } |
| 3634 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3635 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3636 | { |
| 3637 | int i; |
| 3638 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3639 | for (i = 0; i < priv->num_stations; i++) |
| 3640 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3641 | return i; |
| 3642 | |
| 3643 | return IPW_INVALID_STATION; |
| 3644 | } |
| 3645 | |
| 3646 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) |
| 3647 | { |
| 3648 | int err; |
| 3649 | |
Hong Liu | 7b99659 | 2005-08-25 17:36:13 +0800 | [diff] [blame] | 3650 | if (priv->status & STATUS_ASSOCIATING) { |
| 3651 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); |
| 3652 | queue_work(priv->workqueue, &priv->disassociate); |
| 3653 | return; |
| 3654 | } |
| 3655 | |
| 3656 | if (!(priv->status & STATUS_ASSOCIATED)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3657 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
| 3658 | return; |
| 3659 | } |
| 3660 | |
| 3661 | IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " " |
| 3662 | "on channel %d.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3663 | MAC_ARG(priv->assoc_request.bssid), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3664 | priv->assoc_request.channel); |
| 3665 | |
| 3666 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); |
| 3667 | priv->status |= STATUS_DISASSOCIATING; |
| 3668 | |
| 3669 | if (quiet) |
| 3670 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; |
| 3671 | else |
| 3672 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 3673 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3674 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 3675 | if (err) { |
| 3676 | IPW_DEBUG_HC("Attempt to send [dis]associate command " |
| 3677 | "failed.\n"); |
| 3678 | return; |
| 3679 | } |
| 3680 | |
| 3681 | } |
| 3682 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3683 | static int ipw_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3684 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3685 | struct ipw_priv *priv = data; |
| 3686 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) |
| 3687 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3688 | ipw_send_disassociate(data, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3689 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3690 | } |
| 3691 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3692 | static void ipw_bg_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3693 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3694 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3695 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3696 | ipw_disassociate(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3697 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3698 | } |
| 3699 | |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 3700 | static void ipw_system_config(void *data) |
| 3701 | { |
| 3702 | struct ipw_priv *priv = data; |
| 3703 | ipw_send_system_config(priv, &priv->sys_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | struct ipw_status_code { |
| 3707 | u16 status; |
| 3708 | const char *reason; |
| 3709 | }; |
| 3710 | |
| 3711 | static const struct ipw_status_code ipw_status_codes[] = { |
| 3712 | {0x00, "Successful"}, |
| 3713 | {0x01, "Unspecified failure"}, |
| 3714 | {0x0A, "Cannot support all requested capabilities in the " |
| 3715 | "Capability information field"}, |
| 3716 | {0x0B, "Reassociation denied due to inability to confirm that " |
| 3717 | "association exists"}, |
| 3718 | {0x0C, "Association denied due to reason outside the scope of this " |
| 3719 | "standard"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3720 | {0x0D, |
| 3721 | "Responding station does not support the specified authentication " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3722 | "algorithm"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3723 | {0x0E, |
| 3724 | "Received an Authentication frame with authentication sequence " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3725 | "transaction sequence number out of expected sequence"}, |
| 3726 | {0x0F, "Authentication rejected because of challenge failure"}, |
| 3727 | {0x10, "Authentication rejected due to timeout waiting for next " |
| 3728 | "frame in sequence"}, |
| 3729 | {0x11, "Association denied because AP is unable to handle additional " |
| 3730 | "associated stations"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3731 | {0x12, |
| 3732 | "Association denied due to requesting station not supporting all " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3733 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3734 | {0x13, |
| 3735 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3736 | "short preamble operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3737 | {0x14, |
| 3738 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3739 | "PBCC encoding"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3740 | {0x15, |
| 3741 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3742 | "channel agility"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3743 | {0x19, |
| 3744 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3745 | "short slot operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3746 | {0x1A, |
| 3747 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3748 | "DSSS-OFDM operation"}, |
| 3749 | {0x28, "Invalid Information Element"}, |
| 3750 | {0x29, "Group Cipher is not valid"}, |
| 3751 | {0x2A, "Pairwise Cipher is not valid"}, |
| 3752 | {0x2B, "AKMP is not valid"}, |
| 3753 | {0x2C, "Unsupported RSN IE version"}, |
| 3754 | {0x2D, "Invalid RSN IE Capabilities"}, |
| 3755 | {0x2E, "Cipher suite is rejected per security policy"}, |
| 3756 | }; |
| 3757 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 3758 | #ifdef CONFIG_IPW2200_DEBUG |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3759 | static const char *ipw_get_status_code(u16 status) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3760 | { |
| 3761 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3762 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3763 | if (ipw_status_codes[i].status == (status & 0xff)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3764 | return ipw_status_codes[i].reason; |
| 3765 | return "Unknown status value."; |
| 3766 | } |
| 3767 | #endif |
| 3768 | |
| 3769 | static void inline average_init(struct average *avg) |
| 3770 | { |
| 3771 | memset(avg, 0, sizeof(*avg)); |
| 3772 | } |
| 3773 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 3774 | #define DEPTH_RSSI 8 |
| 3775 | #define DEPTH_NOISE 16 |
| 3776 | static s16 exponential_average(s16 prev_avg, s16 val, u8 depth) |
| 3777 | { |
| 3778 | return ((depth-1)*prev_avg + val)/depth; |
| 3779 | } |
| 3780 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3781 | static void average_add(struct average *avg, s16 val) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3782 | { |
| 3783 | avg->sum -= avg->entries[avg->pos]; |
| 3784 | avg->sum += val; |
| 3785 | avg->entries[avg->pos++] = val; |
| 3786 | if (unlikely(avg->pos == AVG_ENTRIES)) { |
| 3787 | avg->init = 1; |
| 3788 | avg->pos = 0; |
| 3789 | } |
| 3790 | } |
| 3791 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3792 | static s16 average_value(struct average *avg) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3793 | { |
| 3794 | if (!unlikely(avg->init)) { |
| 3795 | if (avg->pos) |
| 3796 | return avg->sum / avg->pos; |
| 3797 | return 0; |
| 3798 | } |
| 3799 | |
| 3800 | return avg->sum / AVG_ENTRIES; |
| 3801 | } |
| 3802 | |
| 3803 | static void ipw_reset_stats(struct ipw_priv *priv) |
| 3804 | { |
| 3805 | u32 len = sizeof(u32); |
| 3806 | |
| 3807 | priv->quality = 0; |
| 3808 | |
| 3809 | average_init(&priv->average_missed_beacons); |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 3810 | priv->exp_avg_rssi = -60; |
| 3811 | priv->exp_avg_noise = -85 + 0x100; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3812 | |
| 3813 | priv->last_rate = 0; |
| 3814 | priv->last_missed_beacons = 0; |
| 3815 | priv->last_rx_packets = 0; |
| 3816 | priv->last_tx_packets = 0; |
| 3817 | priv->last_tx_failures = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3818 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3819 | /* Firmware managed, reset only when NIC is restarted, so we have to |
| 3820 | * normalize on the current value */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3821 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3822 | &priv->last_rx_err, &len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3823 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3824 | &priv->last_tx_failures, &len); |
| 3825 | |
| 3826 | /* Driver managed, reset with each association */ |
| 3827 | priv->missed_adhoc_beacons = 0; |
| 3828 | priv->missed_beacons = 0; |
| 3829 | priv->tx_packets = 0; |
| 3830 | priv->rx_packets = 0; |
| 3831 | |
| 3832 | } |
| 3833 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3834 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3835 | { |
| 3836 | u32 i = 0x80000000; |
| 3837 | u32 mask = priv->rates_mask; |
| 3838 | /* If currently associated in B mode, restrict the maximum |
| 3839 | * rate match to B rates */ |
| 3840 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
| 3841 | mask &= IEEE80211_CCK_RATES_MASK; |
| 3842 | |
| 3843 | /* TODO: Verify that the rate is supported by the current rates |
| 3844 | * list. */ |
| 3845 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3846 | while (i && !(mask & i)) |
| 3847 | i >>= 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3848 | switch (i) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3849 | case IEEE80211_CCK_RATE_1MB_MASK: |
| 3850 | return 1000000; |
| 3851 | case IEEE80211_CCK_RATE_2MB_MASK: |
| 3852 | return 2000000; |
| 3853 | case IEEE80211_CCK_RATE_5MB_MASK: |
| 3854 | return 5500000; |
| 3855 | case IEEE80211_OFDM_RATE_6MB_MASK: |
| 3856 | return 6000000; |
| 3857 | case IEEE80211_OFDM_RATE_9MB_MASK: |
| 3858 | return 9000000; |
| 3859 | case IEEE80211_CCK_RATE_11MB_MASK: |
| 3860 | return 11000000; |
| 3861 | case IEEE80211_OFDM_RATE_12MB_MASK: |
| 3862 | return 12000000; |
| 3863 | case IEEE80211_OFDM_RATE_18MB_MASK: |
| 3864 | return 18000000; |
| 3865 | case IEEE80211_OFDM_RATE_24MB_MASK: |
| 3866 | return 24000000; |
| 3867 | case IEEE80211_OFDM_RATE_36MB_MASK: |
| 3868 | return 36000000; |
| 3869 | case IEEE80211_OFDM_RATE_48MB_MASK: |
| 3870 | return 48000000; |
| 3871 | case IEEE80211_OFDM_RATE_54MB_MASK: |
| 3872 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3873 | } |
| 3874 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3875 | if (priv->ieee->mode == IEEE_B) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3876 | return 11000000; |
| 3877 | else |
| 3878 | return 54000000; |
| 3879 | } |
| 3880 | |
| 3881 | static u32 ipw_get_current_rate(struct ipw_priv *priv) |
| 3882 | { |
| 3883 | u32 rate, len = sizeof(rate); |
| 3884 | int err; |
| 3885 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3886 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3887 | return 0; |
| 3888 | |
| 3889 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3890 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3891 | &len); |
| 3892 | if (err) { |
| 3893 | IPW_DEBUG_INFO("failed querying ordinals.\n"); |
| 3894 | return 0; |
| 3895 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3896 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3897 | return ipw_get_max_rate(priv); |
| 3898 | |
| 3899 | switch (rate) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3900 | case IPW_TX_RATE_1MB: |
| 3901 | return 1000000; |
| 3902 | case IPW_TX_RATE_2MB: |
| 3903 | return 2000000; |
| 3904 | case IPW_TX_RATE_5MB: |
| 3905 | return 5500000; |
| 3906 | case IPW_TX_RATE_6MB: |
| 3907 | return 6000000; |
| 3908 | case IPW_TX_RATE_9MB: |
| 3909 | return 9000000; |
| 3910 | case IPW_TX_RATE_11MB: |
| 3911 | return 11000000; |
| 3912 | case IPW_TX_RATE_12MB: |
| 3913 | return 12000000; |
| 3914 | case IPW_TX_RATE_18MB: |
| 3915 | return 18000000; |
| 3916 | case IPW_TX_RATE_24MB: |
| 3917 | return 24000000; |
| 3918 | case IPW_TX_RATE_36MB: |
| 3919 | return 36000000; |
| 3920 | case IPW_TX_RATE_48MB: |
| 3921 | return 48000000; |
| 3922 | case IPW_TX_RATE_54MB: |
| 3923 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | return 0; |
| 3927 | } |
| 3928 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3929 | #define IPW_STATS_INTERVAL (2 * HZ) |
| 3930 | static void ipw_gather_stats(struct ipw_priv *priv) |
| 3931 | { |
| 3932 | u32 rx_err, rx_err_delta, rx_packets_delta; |
| 3933 | u32 tx_failures, tx_failures_delta, tx_packets_delta; |
| 3934 | u32 missed_beacons_percent, missed_beacons_delta; |
| 3935 | u32 quality = 0; |
| 3936 | u32 len = sizeof(u32); |
| 3937 | s16 rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3938 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3939 | rate_quality; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3940 | u32 max_rate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3941 | |
| 3942 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 3943 | priv->quality = 0; |
| 3944 | return; |
| 3945 | } |
| 3946 | |
| 3947 | /* Update the statistics */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3948 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3949 | &priv->missed_beacons, &len); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3950 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3951 | priv->last_missed_beacons = priv->missed_beacons; |
| 3952 | if (priv->assoc_request.beacon_interval) { |
| 3953 | missed_beacons_percent = missed_beacons_delta * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3954 | (HZ * priv->assoc_request.beacon_interval) / |
| 3955 | (IPW_STATS_INTERVAL * 10); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3956 | } else { |
| 3957 | missed_beacons_percent = 0; |
| 3958 | } |
| 3959 | average_add(&priv->average_missed_beacons, missed_beacons_percent); |
| 3960 | |
| 3961 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); |
| 3962 | rx_err_delta = rx_err - priv->last_rx_err; |
| 3963 | priv->last_rx_err = rx_err; |
| 3964 | |
| 3965 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); |
| 3966 | tx_failures_delta = tx_failures - priv->last_tx_failures; |
| 3967 | priv->last_tx_failures = tx_failures; |
| 3968 | |
| 3969 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; |
| 3970 | priv->last_rx_packets = priv->rx_packets; |
| 3971 | |
| 3972 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; |
| 3973 | priv->last_tx_packets = priv->tx_packets; |
| 3974 | |
| 3975 | /* Calculate quality based on the following: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3976 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3977 | * Missed beacon: 100% = 0, 0% = 70% missed |
| 3978 | * Rate: 60% = 1Mbs, 100% = Max |
| 3979 | * Rx and Tx errors represent a straight % of total Rx/Tx |
| 3980 | * RSSI: 100% = > -50, 0% = < -80 |
| 3981 | * Rx errors: 100% = 0, 0% = 50% missed |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3982 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3983 | * The lowest computed quality is used. |
| 3984 | * |
| 3985 | */ |
| 3986 | #define BEACON_THRESHOLD 5 |
| 3987 | beacon_quality = 100 - missed_beacons_percent; |
| 3988 | if (beacon_quality < BEACON_THRESHOLD) |
| 3989 | beacon_quality = 0; |
| 3990 | else |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3991 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3992 | (100 - BEACON_THRESHOLD); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3993 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3994 | beacon_quality, missed_beacons_percent); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3995 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3996 | priv->last_rate = ipw_get_current_rate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3997 | max_rate = ipw_get_max_rate(priv); |
| 3998 | rate_quality = priv->last_rate * 40 / max_rate + 60; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3999 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
| 4000 | rate_quality, priv->last_rate / 1000000); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4001 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4002 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4003 | rx_quality = 100 - (rx_err_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4004 | (rx_packets_delta + rx_err_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4005 | else |
| 4006 | rx_quality = 100; |
| 4007 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", |
| 4008 | rx_quality, rx_err_delta, rx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4009 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4010 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4011 | tx_quality = 100 - (tx_failures_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4012 | (tx_packets_delta + tx_failures_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4013 | else |
| 4014 | tx_quality = 100; |
| 4015 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", |
| 4016 | tx_quality, tx_failures_delta, tx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4017 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4018 | rssi = priv->exp_avg_rssi; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4019 | signal_quality = |
| 4020 | (100 * |
| 4021 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4022 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - |
| 4023 | (priv->ieee->perfect_rssi - rssi) * |
| 4024 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + |
| 4025 | 62 * (priv->ieee->perfect_rssi - rssi))) / |
| 4026 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4027 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); |
| 4028 | if (signal_quality > 100) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4029 | signal_quality = 100; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4030 | else if (signal_quality < 1) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4031 | signal_quality = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4032 | |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4033 | IPW_ERROR("Signal level : %3d%% (%d dBm)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4034 | signal_quality, rssi); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4035 | |
| 4036 | quality = min(beacon_quality, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4037 | min(rate_quality, |
| 4038 | min(tx_quality, min(rx_quality, signal_quality)))); |
| 4039 | if (quality == beacon_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4040 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
| 4041 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4042 | if (quality == rate_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4043 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
| 4044 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4045 | if (quality == tx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4046 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
| 4047 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4048 | if (quality == rx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4049 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
| 4050 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4051 | if (quality == signal_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4052 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
| 4053 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4054 | |
| 4055 | priv->quality = quality; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4056 | |
| 4057 | queue_delayed_work(priv->workqueue, &priv->gather_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4058 | IPW_STATS_INTERVAL); |
| 4059 | } |
| 4060 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4061 | static void ipw_bg_gather_stats(void *data) |
| 4062 | { |
| 4063 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4064 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4065 | ipw_gather_stats(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4066 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4067 | } |
| 4068 | |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4069 | /* Missed beacon behavior: |
| 4070 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. |
| 4071 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. |
| 4072 | * Above disassociate threshold, give up and stop scanning. |
| 4073 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4074 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4075 | int missed_count) |
| 4076 | { |
| 4077 | priv->notif_missed_beacons = missed_count; |
| 4078 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4079 | if (missed_count > priv->disassociate_threshold && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4080 | priv->status & STATUS_ASSOCIATED) { |
| 4081 | /* If associated and we've hit the missed |
| 4082 | * beacon threshold, disassociate, turn |
| 4083 | * off roaming, and abort any active scans */ |
| 4084 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4085 | IPW_DL_STATE | IPW_DL_ASSOC, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4086 | "Missed beacon: %d - disassociate\n", missed_count); |
| 4087 | priv->status &= ~STATUS_ROAMING; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4088 | if (priv->status & STATUS_SCANNING) { |
| 4089 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 4090 | IPW_DL_STATE, |
| 4091 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4092 | queue_work(priv->workqueue, &priv->abort_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4093 | } |
| 4094 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4095 | queue_work(priv->workqueue, &priv->disassociate); |
| 4096 | return; |
| 4097 | } |
| 4098 | |
| 4099 | if (priv->status & STATUS_ROAMING) { |
| 4100 | /* If we are currently roaming, then just |
| 4101 | * print a debug statement... */ |
| 4102 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4103 | "Missed beacon: %d - roam in progress\n", |
| 4104 | missed_count); |
| 4105 | return; |
| 4106 | } |
| 4107 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 4108 | if (roaming && |
| 4109 | (missed_count > priv->roaming_threshold && |
| 4110 | missed_count <= priv->disassociate_threshold)) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4111 | /* If we are not already roaming, set the ROAM |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4112 | * bit in the status and kick off a scan. |
| 4113 | * This can happen several times before we reach |
| 4114 | * disassociate_threshold. */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4115 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4116 | "Missed beacon: %d - initiate " |
| 4117 | "roaming\n", missed_count); |
| 4118 | if (!(priv->status & STATUS_ROAMING)) { |
| 4119 | priv->status |= STATUS_ROAMING; |
| 4120 | if (!(priv->status & STATUS_SCANNING)) |
| 4121 | queue_work(priv->workqueue, |
| 4122 | &priv->request_scan); |
| 4123 | } |
| 4124 | return; |
| 4125 | } |
| 4126 | |
| 4127 | if (priv->status & STATUS_SCANNING) { |
| 4128 | /* Stop scan to keep fw from getting |
| 4129 | * stuck (only if we aren't roaming -- |
| 4130 | * otherwise we'll never scan more than 2 or 3 |
| 4131 | * channels..) */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4132 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
| 4133 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4134 | queue_work(priv->workqueue, &priv->abort_scan); |
| 4135 | } |
| 4136 | |
| 4137 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4138 | } |
| 4139 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4140 | /** |
| 4141 | * Handle host notification packet. |
| 4142 | * Called from interrupt routine |
| 4143 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4144 | static void ipw_rx_notification(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4145 | struct ipw_rx_notification *notif) |
| 4146 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4147 | notif->size = le16_to_cpu(notif->size); |
| 4148 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4149 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4150 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4151 | switch (notif->subtype) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4152 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
| 4153 | struct notif_association *assoc = ¬if->u.assoc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4154 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4155 | switch (assoc->state) { |
| 4156 | case CMAS_ASSOCIATED:{ |
| 4157 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4158 | IPW_DL_ASSOC, |
| 4159 | "associated: '%s' " MAC_FMT |
| 4160 | " \n", |
| 4161 | escape_essid(priv->essid, |
| 4162 | priv->essid_len), |
| 4163 | MAC_ARG(priv->bssid)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4164 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4165 | switch (priv->ieee->iw_mode) { |
| 4166 | case IW_MODE_INFRA: |
| 4167 | memcpy(priv->ieee->bssid, |
| 4168 | priv->bssid, ETH_ALEN); |
| 4169 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4170 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4171 | case IW_MODE_ADHOC: |
| 4172 | memcpy(priv->ieee->bssid, |
| 4173 | priv->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4174 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4175 | /* clear out the station table */ |
| 4176 | priv->num_stations = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4177 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4178 | IPW_DEBUG_ASSOC |
| 4179 | ("queueing adhoc check\n"); |
| 4180 | queue_delayed_work(priv-> |
| 4181 | workqueue, |
| 4182 | &priv-> |
| 4183 | adhoc_check, |
| 4184 | priv-> |
| 4185 | assoc_request. |
| 4186 | beacon_interval); |
| 4187 | break; |
| 4188 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4189 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4190 | priv->status &= ~STATUS_ASSOCIATING; |
| 4191 | priv->status |= STATUS_ASSOCIATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 4192 | queue_work(priv->workqueue, |
| 4193 | &priv->system_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4194 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4195 | #ifdef CONFIG_IPW_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4196 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
| 4197 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl)) |
| 4198 | if ((priv->status & STATUS_AUTH) && |
| 4199 | (IPW_GET_PACKET_STYPE(¬if->u.raw) |
| 4200 | == IEEE80211_STYPE_ASSOC_RESP)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4201 | if ((sizeof |
| 4202 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4203 | ieee80211_assoc_response) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4204 | <= notif->size) |
| 4205 | && (notif->size <= 2314)) { |
| 4206 | struct |
| 4207 | ieee80211_rx_stats |
| 4208 | stats = { |
| 4209 | .len = |
| 4210 | notif-> |
| 4211 | size - 1, |
| 4212 | }; |
| 4213 | |
| 4214 | IPW_DEBUG_QOS |
| 4215 | ("QoS Associate " |
| 4216 | "size %d\n", |
| 4217 | notif->size); |
| 4218 | ieee80211_rx_mgt(priv-> |
| 4219 | ieee, |
| 4220 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4221 | ieee80211_hdr_4addr |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4222 | *) |
| 4223 | ¬if->u.raw, &stats); |
| 4224 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4225 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4226 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4227 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4228 | schedule_work(&priv->link_up); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4229 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4230 | break; |
| 4231 | } |
| 4232 | |
| 4233 | case CMAS_AUTHENTICATED:{ |
| 4234 | if (priv-> |
| 4235 | status & (STATUS_ASSOCIATED | |
| 4236 | STATUS_AUTH)) { |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 4237 | #ifdef CONFIG_IPW2200_DEBUG |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4238 | struct notif_authenticate *auth |
| 4239 | = ¬if->u.auth; |
| 4240 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4241 | IPW_DL_STATE | |
| 4242 | IPW_DL_ASSOC, |
| 4243 | "deauthenticated: '%s' " |
| 4244 | MAC_FMT |
| 4245 | ": (0x%04X) - %s \n", |
| 4246 | escape_essid(priv-> |
| 4247 | essid, |
| 4248 | priv-> |
| 4249 | essid_len), |
| 4250 | MAC_ARG(priv->bssid), |
| 4251 | ntohs(auth->status), |
| 4252 | ipw_get_status_code |
| 4253 | (ntohs |
| 4254 | (auth->status))); |
| 4255 | #endif |
| 4256 | |
| 4257 | priv->status &= |
| 4258 | ~(STATUS_ASSOCIATING | |
| 4259 | STATUS_AUTH | |
| 4260 | STATUS_ASSOCIATED); |
| 4261 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4262 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4263 | break; |
| 4264 | } |
| 4265 | |
| 4266 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4267 | IPW_DL_ASSOC, |
| 4268 | "authenticated: '%s' " MAC_FMT |
| 4269 | "\n", |
| 4270 | escape_essid(priv->essid, |
| 4271 | priv->essid_len), |
| 4272 | MAC_ARG(priv->bssid)); |
| 4273 | break; |
| 4274 | } |
| 4275 | |
| 4276 | case CMAS_INIT:{ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4277 | if (priv->status & STATUS_AUTH) { |
| 4278 | struct |
| 4279 | ieee80211_assoc_response |
| 4280 | *resp; |
| 4281 | resp = |
| 4282 | (struct |
| 4283 | ieee80211_assoc_response |
| 4284 | *)¬if->u.raw; |
| 4285 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4286 | IPW_DL_STATE | |
| 4287 | IPW_DL_ASSOC, |
| 4288 | "association failed (0x%04X): %s\n", |
| 4289 | ntohs(resp->status), |
| 4290 | ipw_get_status_code |
| 4291 | (ntohs |
| 4292 | (resp->status))); |
| 4293 | } |
| 4294 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4295 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4296 | IPW_DL_ASSOC, |
| 4297 | "disassociated: '%s' " MAC_FMT |
| 4298 | " \n", |
| 4299 | escape_essid(priv->essid, |
| 4300 | priv->essid_len), |
| 4301 | MAC_ARG(priv->bssid)); |
| 4302 | |
| 4303 | priv->status &= |
| 4304 | ~(STATUS_DISASSOCIATING | |
| 4305 | STATUS_ASSOCIATING | |
| 4306 | STATUS_ASSOCIATED | STATUS_AUTH); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4307 | if (priv->assoc_network |
| 4308 | && (priv->assoc_network-> |
| 4309 | capability & |
| 4310 | WLAN_CAPABILITY_IBSS)) |
| 4311 | ipw_remove_current_network |
| 4312 | (priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4313 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4314 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4315 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4316 | break; |
| 4317 | } |
| 4318 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4319 | case CMAS_RX_ASSOC_RESP: |
| 4320 | break; |
| 4321 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4322 | default: |
| 4323 | IPW_ERROR("assoc: unknown (%d)\n", |
| 4324 | assoc->state); |
| 4325 | break; |
| 4326 | } |
| 4327 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4328 | break; |
| 4329 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4330 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4331 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
| 4332 | struct notif_authenticate *auth = ¬if->u.auth; |
| 4333 | switch (auth->state) { |
| 4334 | case CMAS_AUTHENTICATED: |
| 4335 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4336 | "authenticated: '%s' " MAC_FMT " \n", |
| 4337 | escape_essid(priv->essid, |
| 4338 | priv->essid_len), |
| 4339 | MAC_ARG(priv->bssid)); |
| 4340 | priv->status |= STATUS_AUTH; |
| 4341 | break; |
| 4342 | |
| 4343 | case CMAS_INIT: |
| 4344 | if (priv->status & STATUS_AUTH) { |
| 4345 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4346 | IPW_DL_ASSOC, |
| 4347 | "authentication failed (0x%04X): %s\n", |
| 4348 | ntohs(auth->status), |
| 4349 | ipw_get_status_code(ntohs |
| 4350 | (auth-> |
| 4351 | status))); |
| 4352 | } |
| 4353 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4354 | IPW_DL_ASSOC, |
| 4355 | "deauthenticated: '%s' " MAC_FMT "\n", |
| 4356 | escape_essid(priv->essid, |
| 4357 | priv->essid_len), |
| 4358 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4359 | |
| 4360 | priv->status &= ~(STATUS_ASSOCIATING | |
| 4361 | STATUS_AUTH | |
| 4362 | STATUS_ASSOCIATED); |
| 4363 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4364 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4365 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4366 | |
| 4367 | case CMAS_TX_AUTH_SEQ_1: |
| 4368 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4369 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); |
| 4370 | break; |
| 4371 | case CMAS_RX_AUTH_SEQ_2: |
| 4372 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4373 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); |
| 4374 | break; |
| 4375 | case CMAS_AUTH_SEQ_1_PASS: |
| 4376 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4377 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); |
| 4378 | break; |
| 4379 | case CMAS_AUTH_SEQ_1_FAIL: |
| 4380 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4381 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); |
| 4382 | break; |
| 4383 | case CMAS_TX_AUTH_SEQ_3: |
| 4384 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4385 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); |
| 4386 | break; |
| 4387 | case CMAS_RX_AUTH_SEQ_4: |
| 4388 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4389 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); |
| 4390 | break; |
| 4391 | case CMAS_AUTH_SEQ_2_PASS: |
| 4392 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4393 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); |
| 4394 | break; |
| 4395 | case CMAS_AUTH_SEQ_2_FAIL: |
| 4396 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4397 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); |
| 4398 | break; |
| 4399 | case CMAS_TX_ASSOC: |
| 4400 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4401 | IPW_DL_ASSOC, "TX_ASSOC\n"); |
| 4402 | break; |
| 4403 | case CMAS_RX_ASSOC_RESP: |
| 4404 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4405 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4406 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4407 | break; |
| 4408 | case CMAS_ASSOCIATED: |
| 4409 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4410 | IPW_DL_ASSOC, "ASSOCIATED\n"); |
| 4411 | break; |
| 4412 | default: |
| 4413 | IPW_DEBUG_NOTIF("auth: failure - %d\n", |
| 4414 | auth->state); |
| 4415 | break; |
| 4416 | } |
| 4417 | break; |
| 4418 | } |
| 4419 | |
| 4420 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
| 4421 | struct notif_channel_result *x = |
| 4422 | ¬if->u.channel_result; |
| 4423 | |
| 4424 | if (notif->size == sizeof(*x)) { |
| 4425 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
| 4426 | x->channel_num); |
| 4427 | } else { |
| 4428 | IPW_DEBUG_SCAN("Scan result of wrong size %d " |
| 4429 | "(should be %zd)\n", |
| 4430 | notif->size, sizeof(*x)); |
| 4431 | } |
| 4432 | break; |
| 4433 | } |
| 4434 | |
| 4435 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
| 4436 | struct notif_scan_complete *x = ¬if->u.scan_complete; |
| 4437 | if (notif->size == sizeof(*x)) { |
| 4438 | IPW_DEBUG_SCAN |
| 4439 | ("Scan completed: type %d, %d channels, " |
| 4440 | "%d status\n", x->scan_type, |
| 4441 | x->num_channels, x->status); |
| 4442 | } else { |
| 4443 | IPW_ERROR("Scan completed of wrong size %d " |
| 4444 | "(should be %zd)\n", |
| 4445 | notif->size, sizeof(*x)); |
| 4446 | } |
| 4447 | |
| 4448 | priv->status &= |
| 4449 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 4450 | |
James Ketrenos | a0e04ab | 2005-08-25 00:49:43 -0500 | [diff] [blame] | 4451 | wake_up_interruptible(&priv->wait_state); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4452 | cancel_delayed_work(&priv->scan_check); |
| 4453 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4454 | if (priv->status & STATUS_EXIT_PENDING) |
| 4455 | break; |
| 4456 | |
| 4457 | priv->ieee->scans++; |
| 4458 | |
| 4459 | #ifdef CONFIG_IPW2200_MONITOR |
| 4460 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4461 | priv->status |= STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4462 | queue_work(priv->workqueue, |
| 4463 | &priv->request_scan); |
| 4464 | break; |
| 4465 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4466 | priv->status &= ~STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4467 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 4468 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4469 | if (!(priv->status & (STATUS_ASSOCIATED | |
| 4470 | STATUS_ASSOCIATING | |
| 4471 | STATUS_ROAMING | |
| 4472 | STATUS_DISASSOCIATING))) |
| 4473 | queue_work(priv->workqueue, &priv->associate); |
| 4474 | else if (priv->status & STATUS_ROAMING) { |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4475 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4476 | /* If a scan completed and we are in roam mode, then |
| 4477 | * the scan that completed was the one requested as a |
| 4478 | * result of entering roam... so, schedule the |
| 4479 | * roam work */ |
| 4480 | queue_work(priv->workqueue, |
| 4481 | &priv->roam); |
| 4482 | else |
| 4483 | /* Don't schedule if we aborted the scan */ |
| 4484 | priv->status &= ~STATUS_ROAMING; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4485 | } else if (priv->status & STATUS_SCAN_PENDING) |
| 4486 | queue_work(priv->workqueue, |
| 4487 | &priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4488 | else if (priv->config & CFG_BACKGROUND_SCAN |
| 4489 | && priv->status & STATUS_ASSOCIATED) |
| 4490 | queue_delayed_work(priv->workqueue, |
| 4491 | &priv->request_scan, HZ); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4492 | break; |
| 4493 | } |
| 4494 | |
| 4495 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
| 4496 | struct notif_frag_length *x = ¬if->u.frag_len; |
| 4497 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4498 | if (notif->size == sizeof(*x)) |
| 4499 | IPW_ERROR("Frag length: %d\n", |
| 4500 | le16_to_cpu(x->frag_length)); |
| 4501 | else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4502 | IPW_ERROR("Frag length of wrong size %d " |
| 4503 | "(should be %zd)\n", |
| 4504 | notif->size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4505 | break; |
| 4506 | } |
| 4507 | |
| 4508 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
| 4509 | struct notif_link_deterioration *x = |
| 4510 | ¬if->u.link_deterioration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4511 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4512 | if (notif->size == sizeof(*x)) { |
| 4513 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Cahill, Ben M | 1297715 | 2006-03-08 02:58:02 +0800 | [diff] [blame] | 4514 | "link deterioration: type %d, cnt %d\n", |
| 4515 | x->silence_notification_type, |
| 4516 | x->silence_count); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4517 | memcpy(&priv->last_link_deterioration, x, |
| 4518 | sizeof(*x)); |
| 4519 | } else { |
| 4520 | IPW_ERROR("Link Deterioration of wrong size %d " |
| 4521 | "(should be %zd)\n", |
| 4522 | notif->size, sizeof(*x)); |
| 4523 | } |
| 4524 | break; |
| 4525 | } |
| 4526 | |
| 4527 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
| 4528 | IPW_ERROR("Dino config\n"); |
| 4529 | if (priv->hcmd |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4530 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4531 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4532 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4533 | break; |
| 4534 | } |
| 4535 | |
| 4536 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
| 4537 | struct notif_beacon_state *x = ¬if->u.beacon_state; |
| 4538 | if (notif->size != sizeof(*x)) { |
| 4539 | IPW_ERROR |
| 4540 | ("Beacon state of wrong size %d (should " |
| 4541 | "be %zd)\n", notif->size, sizeof(*x)); |
| 4542 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4543 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4544 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4545 | if (le32_to_cpu(x->state) == |
| 4546 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) |
| 4547 | ipw_handle_missed_beacon(priv, |
| 4548 | le32_to_cpu(x-> |
| 4549 | number)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4550 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4551 | break; |
| 4552 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4553 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4554 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
| 4555 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; |
| 4556 | if (notif->size == sizeof(*x)) { |
| 4557 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
| 4558 | "0x%02x station %d\n", |
| 4559 | x->key_state, x->security_type, |
| 4560 | x->station_index); |
| 4561 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4562 | } |
| 4563 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4564 | IPW_ERROR |
| 4565 | ("TGi Tx Key of wrong size %d (should be %zd)\n", |
| 4566 | notif->size, sizeof(*x)); |
| 4567 | break; |
| 4568 | } |
| 4569 | |
| 4570 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
| 4571 | struct notif_calibration *x = ¬if->u.calibration; |
| 4572 | |
| 4573 | if (notif->size == sizeof(*x)) { |
| 4574 | memcpy(&priv->calib, x, sizeof(*x)); |
| 4575 | IPW_DEBUG_INFO("TODO: Calibration\n"); |
| 4576 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4577 | } |
| 4578 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4579 | IPW_ERROR |
| 4580 | ("Calibration of wrong size %d (should be %zd)\n", |
| 4581 | notif->size, sizeof(*x)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4582 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4583 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4584 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4585 | case HOST_NOTIFICATION_NOISE_STATS:{ |
| 4586 | if (notif->size == sizeof(u32)) { |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 4587 | priv->exp_avg_noise = |
| 4588 | exponential_average(priv->exp_avg_noise, |
| 4589 | (u8) (le32_to_cpu(notif->u.noise.value) & 0xff), |
| 4590 | DEPTH_NOISE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4591 | break; |
| 4592 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4593 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4594 | IPW_ERROR |
| 4595 | ("Noise stat is wrong size %d (should be %zd)\n", |
| 4596 | notif->size, sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4597 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4598 | } |
| 4599 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4600 | default: |
Zhu Yi | 1dd31b6 | 2006-02-20 18:28:09 -0800 | [diff] [blame] | 4601 | IPW_DEBUG_NOTIF("Unknown notification: " |
| 4602 | "subtype=%d,flags=0x%2x,size=%d\n", |
| 4603 | notif->subtype, notif->flags, notif->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4604 | } |
| 4605 | } |
| 4606 | |
| 4607 | /** |
| 4608 | * Destroys all DMA structures and initialise them again |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4609 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4610 | * @param priv |
| 4611 | * @return error code |
| 4612 | */ |
| 4613 | static int ipw_queue_reset(struct ipw_priv *priv) |
| 4614 | { |
| 4615 | int rc = 0; |
| 4616 | /** @todo customize queue sizes */ |
| 4617 | int nTx = 64, nTxCmd = 8; |
| 4618 | ipw_tx_queue_free(priv); |
| 4619 | /* Tx CMD queue */ |
| 4620 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4621 | IPW_TX_CMD_QUEUE_READ_INDEX, |
| 4622 | IPW_TX_CMD_QUEUE_WRITE_INDEX, |
| 4623 | IPW_TX_CMD_QUEUE_BD_BASE, |
| 4624 | IPW_TX_CMD_QUEUE_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4625 | if (rc) { |
| 4626 | IPW_ERROR("Tx Cmd queue init failed\n"); |
| 4627 | goto error; |
| 4628 | } |
| 4629 | /* Tx queue(s) */ |
| 4630 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4631 | IPW_TX_QUEUE_0_READ_INDEX, |
| 4632 | IPW_TX_QUEUE_0_WRITE_INDEX, |
| 4633 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4634 | if (rc) { |
| 4635 | IPW_ERROR("Tx 0 queue init failed\n"); |
| 4636 | goto error; |
| 4637 | } |
| 4638 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4639 | IPW_TX_QUEUE_1_READ_INDEX, |
| 4640 | IPW_TX_QUEUE_1_WRITE_INDEX, |
| 4641 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4642 | if (rc) { |
| 4643 | IPW_ERROR("Tx 1 queue init failed\n"); |
| 4644 | goto error; |
| 4645 | } |
| 4646 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4647 | IPW_TX_QUEUE_2_READ_INDEX, |
| 4648 | IPW_TX_QUEUE_2_WRITE_INDEX, |
| 4649 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4650 | if (rc) { |
| 4651 | IPW_ERROR("Tx 2 queue init failed\n"); |
| 4652 | goto error; |
| 4653 | } |
| 4654 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4655 | IPW_TX_QUEUE_3_READ_INDEX, |
| 4656 | IPW_TX_QUEUE_3_WRITE_INDEX, |
| 4657 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4658 | if (rc) { |
| 4659 | IPW_ERROR("Tx 3 queue init failed\n"); |
| 4660 | goto error; |
| 4661 | } |
| 4662 | /* statistics */ |
| 4663 | priv->rx_bufs_min = 0; |
| 4664 | priv->rx_pend_max = 0; |
| 4665 | return rc; |
| 4666 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4667 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4668 | ipw_tx_queue_free(priv); |
| 4669 | return rc; |
| 4670 | } |
| 4671 | |
| 4672 | /** |
| 4673 | * Reclaim Tx queue entries no more used by NIC. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4674 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4675 | * When FW adwances 'R' index, all entries between old and |
| 4676 | * new 'R' index need to be reclaimed. As result, some free space |
| 4677 | * forms. If there is enough free space (> low mark), wake Tx queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4678 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4679 | * @note Need to protect against garbage in 'R' index |
| 4680 | * @param priv |
| 4681 | * @param txq |
| 4682 | * @param qindex |
| 4683 | * @return Number of used entries remains in the queue |
| 4684 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4685 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4686 | struct clx2_tx_queue *txq, int qindex) |
| 4687 | { |
| 4688 | u32 hw_tail; |
| 4689 | int used; |
| 4690 | struct clx2_queue *q = &txq->q; |
| 4691 | |
| 4692 | hw_tail = ipw_read32(priv, q->reg_r); |
| 4693 | if (hw_tail >= q->n_bd) { |
| 4694 | IPW_ERROR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4695 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
| 4696 | hw_tail, q->n_bd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4697 | goto done; |
| 4698 | } |
| 4699 | for (; q->last_used != hw_tail; |
| 4700 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 4701 | ipw_queue_tx_free_tfd(priv, txq); |
| 4702 | priv->tx_packets++; |
| 4703 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4704 | done: |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 4705 | if ((ipw_queue_space(q) > q->low_mark) && |
| 4706 | (qindex >= 0) && |
| 4707 | (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev)) |
| 4708 | netif_wake_queue(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4709 | used = q->first_empty - q->last_used; |
| 4710 | if (used < 0) |
| 4711 | used += q->n_bd; |
| 4712 | |
| 4713 | return used; |
| 4714 | } |
| 4715 | |
| 4716 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 4717 | int len, int sync) |
| 4718 | { |
| 4719 | struct clx2_tx_queue *txq = &priv->txq_cmd; |
| 4720 | struct clx2_queue *q = &txq->q; |
| 4721 | struct tfd_frame *tfd; |
| 4722 | |
| 4723 | if (ipw_queue_space(q) < (sync ? 1 : 2)) { |
| 4724 | IPW_ERROR("No space for Tx\n"); |
| 4725 | return -EBUSY; |
| 4726 | } |
| 4727 | |
| 4728 | tfd = &txq->bd[q->first_empty]; |
| 4729 | txq->txb[q->first_empty] = NULL; |
| 4730 | |
| 4731 | memset(tfd, 0, sizeof(*tfd)); |
| 4732 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; |
| 4733 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 4734 | priv->hcmd_seq++; |
| 4735 | tfd->u.cmd.index = hcmd; |
| 4736 | tfd->u.cmd.length = len; |
| 4737 | memcpy(tfd->u.cmd.payload, buf, len); |
| 4738 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 4739 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 4740 | _ipw_read32(priv, 0x90); |
| 4741 | |
| 4742 | return 0; |
| 4743 | } |
| 4744 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4745 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4746 | * Rx theory of operation |
| 4747 | * |
| 4748 | * The host allocates 32 DMA target addresses and passes the host address |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4749 | * 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] | 4750 | * 0 to 31 |
| 4751 | * |
| 4752 | * Rx Queue Indexes |
| 4753 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4754 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4755 | * The READ index maps to the first position that the firmware may be writing |
| 4756 | * to -- the driver can read up to (but not including) this position and get |
| 4757 | * good data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4758 | * The READ index is managed by the firmware once the card is enabled. |
| 4759 | * |
| 4760 | * The WRITE index maps to the last position the driver has read from -- the |
| 4761 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4762 | * |
| 4763 | * 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] | 4764 | * WRITE = READ. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4765 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4766 | * 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] | 4767 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4768 | * |
| 4769 | * When the firmware places a packet in a buffer it will advance the READ index |
| 4770 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4771 | * process as many packets as possible, moving the WRITE index forward as it |
| 4772 | * resets the Rx queue buffers with new memory. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4773 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4774 | * The management in the driver is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4775 | * + 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] | 4776 | * 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] | 4777 | * to replensish the ipw->rxq->rx_free. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4778 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
| 4779 | * ipw->rxq is replenished and the READ INDEX is updated (updating the |
| 4780 | * 'processed' and 'read' driver indexes as well) |
| 4781 | * + A received packet is processed and handed to the kernel network stack, |
| 4782 | * detached from the ipw->rxq. The driver 'processed' index is updated. |
| 4783 | * + 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] | 4784 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
| 4785 | * 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] | 4786 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4787 | * |
| 4788 | * |
| 4789 | * Driver sequence: |
| 4790 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4791 | * ipw_rx_queue_alloc() Allocates rx_free |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4792 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
| 4793 | * ipw_rx_queue_restock |
| 4794 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 4795 | * queue, updates firmware pointers, and updates |
| 4796 | * the WRITE index. If insufficient rx_free buffers |
| 4797 | * are available, schedules ipw_rx_queue_replenish |
| 4798 | * |
| 4799 | * -- enable interrupts -- |
| 4800 | * 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] | 4801 | * READ INDEX, detaching the SKB from the pool. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4802 | * Moves the packet buffer from queue to rx_used. |
| 4803 | * Calls ipw_rx_queue_restock to refill any empty |
| 4804 | * slots. |
| 4805 | * ... |
| 4806 | * |
| 4807 | */ |
| 4808 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4809 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4810 | * If there are slots in the RX queue that need to be restocked, |
| 4811 | * and we have free pre-allocated buffers, fill the ranks as much |
| 4812 | * as we can pulling from rx_free. |
| 4813 | * |
| 4814 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4815 | * also updates the memory address in the firmware to reference the new |
| 4816 | * target buffer. |
| 4817 | */ |
| 4818 | static void ipw_rx_queue_restock(struct ipw_priv *priv) |
| 4819 | { |
| 4820 | struct ipw_rx_queue *rxq = priv->rxq; |
| 4821 | struct list_head *element; |
| 4822 | struct ipw_rx_mem_buffer *rxb; |
| 4823 | unsigned long flags; |
| 4824 | int write; |
| 4825 | |
| 4826 | spin_lock_irqsave(&rxq->lock, flags); |
| 4827 | write = rxq->write; |
| 4828 | while ((rxq->write != rxq->processed) && (rxq->free_count)) { |
| 4829 | element = rxq->rx_free.next; |
| 4830 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
| 4831 | list_del(element); |
| 4832 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4833 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4834 | rxb->dma_addr); |
| 4835 | rxq->queue[rxq->write] = rxb; |
| 4836 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; |
| 4837 | rxq->free_count--; |
| 4838 | } |
| 4839 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4840 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4841 | /* If the pre-allocated buffer pool is dropping low, schedule to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4842 | * refill it */ |
| 4843 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4844 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4845 | |
| 4846 | /* 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] | 4847 | if (write != rxq->write) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4848 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | /* |
| 4852 | * 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] | 4853 | * Also restock the Rx queue via ipw_rx_queue_restock. |
| 4854 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4855 | * This is called as a scheduled work item (except for during intialization) |
| 4856 | */ |
| 4857 | static void ipw_rx_queue_replenish(void *data) |
| 4858 | { |
| 4859 | struct ipw_priv *priv = data; |
| 4860 | struct ipw_rx_queue *rxq = priv->rxq; |
| 4861 | struct list_head *element; |
| 4862 | struct ipw_rx_mem_buffer *rxb; |
| 4863 | unsigned long flags; |
| 4864 | |
| 4865 | spin_lock_irqsave(&rxq->lock, flags); |
| 4866 | while (!list_empty(&rxq->rx_used)) { |
| 4867 | element = rxq->rx_used.next; |
| 4868 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4869 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4870 | if (!rxb->skb) { |
| 4871 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", |
| 4872 | priv->net_dev->name); |
| 4873 | /* We don't reschedule replenish work here -- we will |
| 4874 | * call the restock method and if it still needs |
| 4875 | * more buffers it will schedule replenish */ |
| 4876 | break; |
| 4877 | } |
| 4878 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4879 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4880 | rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4881 | rxb->dma_addr = |
| 4882 | pci_map_single(priv->pci_dev, rxb->skb->data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4883 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4884 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4885 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4886 | rxq->free_count++; |
| 4887 | } |
| 4888 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4889 | |
| 4890 | ipw_rx_queue_restock(priv); |
| 4891 | } |
| 4892 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4893 | static void ipw_bg_rx_queue_replenish(void *data) |
| 4894 | { |
| 4895 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4896 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4897 | ipw_rx_queue_replenish(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4898 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4899 | } |
| 4900 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4901 | /* 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] | 4902 | * 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] | 4903 | * 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] | 4904 | * non NULL it is unmapped and freed |
| 4905 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4906 | 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] | 4907 | { |
| 4908 | int i; |
| 4909 | |
| 4910 | if (!rxq) |
| 4911 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4912 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4913 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4914 | if (rxq->pool[i].skb != NULL) { |
| 4915 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4916 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4917 | dev_kfree_skb(rxq->pool[i].skb); |
| 4918 | } |
| 4919 | } |
| 4920 | |
| 4921 | kfree(rxq); |
| 4922 | } |
| 4923 | |
| 4924 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) |
| 4925 | { |
| 4926 | struct ipw_rx_queue *rxq; |
| 4927 | int i; |
| 4928 | |
Takis | c75f474 | 2005-12-01 01:41:45 -0800 | [diff] [blame] | 4929 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
Panagiotis Issaris | ad18b0e | 2005-09-05 04:14:10 +0200 | [diff] [blame] | 4930 | if (unlikely(!rxq)) { |
| 4931 | IPW_ERROR("memory allocation failed\n"); |
| 4932 | return NULL; |
| 4933 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4934 | spin_lock_init(&rxq->lock); |
| 4935 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4936 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4937 | |
| 4938 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4939 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4940 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4941 | |
| 4942 | /* Set us so that we have processed and used all buffers, but have |
| 4943 | * not restocked the Rx queue with fresh buffers */ |
| 4944 | rxq->read = rxq->write = 0; |
| 4945 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 4946 | rxq->free_count = 0; |
| 4947 | |
| 4948 | return rxq; |
| 4949 | } |
| 4950 | |
| 4951 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) |
| 4952 | { |
| 4953 | rate &= ~IEEE80211_BASIC_RATE_MASK; |
| 4954 | if (ieee_mode == IEEE_A) { |
| 4955 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4956 | case IEEE80211_OFDM_RATE_6MB: |
| 4957 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4958 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4959 | case IEEE80211_OFDM_RATE_9MB: |
| 4960 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4961 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4962 | case IEEE80211_OFDM_RATE_12MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4963 | return priv-> |
| 4964 | rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4965 | case IEEE80211_OFDM_RATE_18MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4966 | return priv-> |
| 4967 | rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4968 | case IEEE80211_OFDM_RATE_24MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4969 | return priv-> |
| 4970 | rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4971 | case IEEE80211_OFDM_RATE_36MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4972 | return priv-> |
| 4973 | rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4974 | case IEEE80211_OFDM_RATE_48MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4975 | return priv-> |
| 4976 | rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4977 | case IEEE80211_OFDM_RATE_54MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4978 | return priv-> |
| 4979 | rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4980 | default: |
| 4981 | return 0; |
| 4982 | } |
| 4983 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4984 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4985 | /* B and G mixed */ |
| 4986 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4987 | case IEEE80211_CCK_RATE_1MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4988 | return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4989 | case IEEE80211_CCK_RATE_2MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4990 | return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4991 | case IEEE80211_CCK_RATE_5MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4992 | return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4993 | case IEEE80211_CCK_RATE_11MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4994 | return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0; |
| 4995 | } |
| 4996 | |
| 4997 | /* If we are limited to B modulations, bail at this point */ |
| 4998 | if (ieee_mode == IEEE_B) |
| 4999 | return 0; |
| 5000 | |
| 5001 | /* G */ |
| 5002 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5003 | case IEEE80211_OFDM_RATE_6MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5004 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5005 | case IEEE80211_OFDM_RATE_9MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5006 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5007 | case IEEE80211_OFDM_RATE_12MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5008 | return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5009 | case IEEE80211_OFDM_RATE_18MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5010 | return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5011 | case IEEE80211_OFDM_RATE_24MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5012 | return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5013 | case IEEE80211_OFDM_RATE_36MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5014 | return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5015 | case IEEE80211_OFDM_RATE_48MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5016 | return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5017 | case IEEE80211_OFDM_RATE_54MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5018 | return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
| 5019 | } |
| 5020 | |
| 5021 | return 0; |
| 5022 | } |
| 5023 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5024 | static int ipw_compatible_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5025 | const struct ieee80211_network *network, |
| 5026 | struct ipw_supported_rates *rates) |
| 5027 | { |
| 5028 | int num_rates, i; |
| 5029 | |
| 5030 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5031 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5032 | rates->num_rates = 0; |
| 5033 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5034 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5035 | network->rates[i])) { |
| 5036 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5037 | if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5038 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5039 | "rate %02X\n", |
| 5040 | network->rates[i]); |
| 5041 | rates->supported_rates[rates->num_rates++] = |
| 5042 | network->rates[i]; |
| 5043 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5044 | } |
| 5045 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5046 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5047 | network->rates[i], priv->rates_mask); |
| 5048 | continue; |
| 5049 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5050 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5051 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
| 5052 | } |
| 5053 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5054 | num_rates = min(network->rates_ex_len, |
| 5055 | (u8) (IPW_MAX_RATES - num_rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5056 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5057 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5058 | network->rates_ex[i])) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5059 | if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5060 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5061 | "rate %02X\n", |
| 5062 | network->rates_ex[i]); |
| 5063 | rates->supported_rates[rates->num_rates++] = |
| 5064 | network->rates[i]; |
| 5065 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5066 | } |
| 5067 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5068 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5069 | network->rates_ex[i], priv->rates_mask); |
| 5070 | continue; |
| 5071 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5072 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5073 | rates->supported_rates[rates->num_rates++] = |
| 5074 | network->rates_ex[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5075 | } |
| 5076 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5077 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5078 | } |
| 5079 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5080 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5081 | const struct ipw_supported_rates *src) |
| 5082 | { |
| 5083 | u8 i; |
| 5084 | for (i = 0; i < src->num_rates; i++) |
| 5085 | dest->supported_rates[i] = src->supported_rates[i]; |
| 5086 | dest->num_rates = src->num_rates; |
| 5087 | } |
| 5088 | |
| 5089 | /* TODO: Look at sniffed packets in the air to determine if the basic rate |
| 5090 | * mask should ever be used -- right now all callers to add the scan rates are |
| 5091 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ |
| 5092 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5093 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5094 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5095 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5096 | IEEE80211_BASIC_RATE_MASK : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5097 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5098 | if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5099 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5100 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5101 | |
| 5102 | if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5103 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5104 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5105 | |
| 5106 | if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5107 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5108 | IEEE80211_CCK_RATE_5MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5109 | |
| 5110 | if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5111 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5112 | IEEE80211_CCK_RATE_11MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5116 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5117 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5118 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5119 | IEEE80211_BASIC_RATE_MASK : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5120 | |
| 5121 | if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5122 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5123 | IEEE80211_OFDM_RATE_6MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5124 | |
| 5125 | if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5126 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5127 | IEEE80211_OFDM_RATE_9MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5128 | |
| 5129 | if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5130 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5131 | IEEE80211_OFDM_RATE_12MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5132 | |
| 5133 | if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5134 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5135 | IEEE80211_OFDM_RATE_18MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5136 | |
| 5137 | if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5138 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5139 | IEEE80211_OFDM_RATE_24MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5140 | |
| 5141 | if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5142 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5143 | IEEE80211_OFDM_RATE_36MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5144 | |
| 5145 | if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5146 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5147 | IEEE80211_OFDM_RATE_48MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5148 | |
| 5149 | if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5150 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5151 | IEEE80211_OFDM_RATE_54MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | struct ipw_network_match { |
| 5155 | struct ieee80211_network *network; |
| 5156 | struct ipw_supported_rates rates; |
| 5157 | }; |
| 5158 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5159 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
| 5160 | struct ipw_network_match *match, |
| 5161 | struct ieee80211_network *network, |
| 5162 | int roaming) |
| 5163 | { |
| 5164 | struct ipw_supported_rates rates; |
| 5165 | |
| 5166 | /* Verify that this network's capability is compatible with the |
| 5167 | * current mode (AdHoc or Infrastructure) */ |
| 5168 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5169 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5170 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to " |
| 5171 | "capability mismatch.\n", |
| 5172 | escape_essid(network->ssid, network->ssid_len), |
| 5173 | MAC_ARG(network->bssid)); |
| 5174 | return 0; |
| 5175 | } |
| 5176 | |
| 5177 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5178 | * it */ |
| 5179 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5180 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5181 | "because of hidden ESSID.\n", |
| 5182 | escape_essid(network->ssid, network->ssid_len), |
| 5183 | MAC_ARG(network->bssid)); |
| 5184 | return 0; |
| 5185 | } |
| 5186 | |
| 5187 | if (unlikely(roaming)) { |
| 5188 | /* If we are roaming, then ensure check if this is a valid |
| 5189 | * network to try and roam to */ |
| 5190 | if ((network->ssid_len != match->network->ssid_len) || |
| 5191 | memcmp(network->ssid, match->network->ssid, |
| 5192 | network->ssid_len)) { |
| 5193 | IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5194 | "because of non-network ESSID.\n", |
| 5195 | escape_essid(network->ssid, |
| 5196 | network->ssid_len), |
| 5197 | MAC_ARG(network->bssid)); |
| 5198 | return 0; |
| 5199 | } |
| 5200 | } else { |
| 5201 | /* If an ESSID has been configured then compare the broadcast |
| 5202 | * ESSID to ours */ |
| 5203 | if ((priv->config & CFG_STATIC_ESSID) && |
| 5204 | ((network->ssid_len != priv->essid_len) || |
| 5205 | memcmp(network->ssid, priv->essid, |
| 5206 | min(network->ssid_len, priv->essid_len)))) { |
| 5207 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5208 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5209 | strncpy(escaped, |
| 5210 | escape_essid(network->ssid, network->ssid_len), |
| 5211 | sizeof(escaped)); |
| 5212 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5213 | "because of ESSID mismatch: '%s'.\n", |
| 5214 | escaped, MAC_ARG(network->bssid), |
| 5215 | escape_essid(priv->essid, |
| 5216 | priv->essid_len)); |
| 5217 | return 0; |
| 5218 | } |
| 5219 | } |
| 5220 | |
| 5221 | /* If the old network rate is better than this one, don't bother |
| 5222 | * testing everything else. */ |
| 5223 | |
| 5224 | if (network->time_stamp[0] < match->network->time_stamp[0]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5225 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5226 | "current network.\n", |
| 5227 | escape_essid(match->network->ssid, |
| 5228 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5229 | return 0; |
| 5230 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5231 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5232 | "current network.\n", |
| 5233 | escape_essid(match->network->ssid, |
| 5234 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5235 | return 0; |
| 5236 | } |
| 5237 | |
| 5238 | /* Now go through and see if the requested network is valid... */ |
| 5239 | if (priv->ieee->scan_age != 0 && |
| 5240 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
| 5241 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5242 | "because of age: %ums.\n", |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5243 | escape_essid(network->ssid, network->ssid_len), |
| 5244 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5245 | jiffies_to_msecs(jiffies - |
| 5246 | network->last_scanned)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5247 | return 0; |
| 5248 | } |
| 5249 | |
| 5250 | if ((priv->config & CFG_STATIC_CHANNEL) && |
| 5251 | (network->channel != priv->channel)) { |
| 5252 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5253 | "because of channel mismatch: %d != %d.\n", |
| 5254 | escape_essid(network->ssid, network->ssid_len), |
| 5255 | MAC_ARG(network->bssid), |
| 5256 | network->channel, priv->channel); |
| 5257 | return 0; |
| 5258 | } |
| 5259 | |
| 5260 | /* Verify privacy compatability */ |
| 5261 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
| 5262 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5263 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5264 | "because of privacy mismatch: %s != %s.\n", |
| 5265 | escape_essid(network->ssid, network->ssid_len), |
| 5266 | MAC_ARG(network->bssid), |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5267 | priv-> |
| 5268 | capability & CAP_PRIVACY_ON ? "on" : "off", |
| 5269 | network-> |
| 5270 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : |
| 5271 | "off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5272 | return 0; |
| 5273 | } |
| 5274 | |
| 5275 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5276 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5277 | "because of the same BSSID match: " MAC_FMT |
| 5278 | ".\n", escape_essid(network->ssid, |
| 5279 | network->ssid_len), |
| 5280 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
| 5281 | return 0; |
| 5282 | } |
| 5283 | |
| 5284 | /* Filter out any incompatible freq / mode combinations */ |
| 5285 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5286 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5287 | "because of invalid frequency/mode " |
| 5288 | "combination.\n", |
| 5289 | escape_essid(network->ssid, network->ssid_len), |
| 5290 | MAC_ARG(network->bssid)); |
| 5291 | return 0; |
| 5292 | } |
| 5293 | |
| 5294 | /* Ensure that the rates supported by the driver are compatible with |
| 5295 | * this AP, including verification of basic rates (mandatory) */ |
| 5296 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5297 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5298 | "because configured rate mask excludes " |
| 5299 | "AP mandatory rate.\n", |
| 5300 | escape_essid(network->ssid, network->ssid_len), |
| 5301 | MAC_ARG(network->bssid)); |
| 5302 | return 0; |
| 5303 | } |
| 5304 | |
| 5305 | if (rates.num_rates == 0) { |
| 5306 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5307 | "because of no compatible rates.\n", |
| 5308 | escape_essid(network->ssid, network->ssid_len), |
| 5309 | MAC_ARG(network->bssid)); |
| 5310 | return 0; |
| 5311 | } |
| 5312 | |
| 5313 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5314 | * want to put too much policy logic here; intelligent scan selection |
| 5315 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5316 | |
| 5317 | /* Set up 'new' AP to this network */ |
| 5318 | ipw_copy_rates(&match->rates, &rates); |
| 5319 | match->network = network; |
| 5320 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5321 | escape_essid(network->ssid, network->ssid_len), |
| 5322 | MAC_ARG(network->bssid)); |
| 5323 | |
| 5324 | return 1; |
| 5325 | } |
| 5326 | |
| 5327 | static void ipw_merge_adhoc_network(void *data) |
| 5328 | { |
| 5329 | struct ipw_priv *priv = data; |
| 5330 | struct ieee80211_network *network = NULL; |
| 5331 | struct ipw_network_match match = { |
| 5332 | .network = priv->assoc_network |
| 5333 | }; |
| 5334 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5335 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5336 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5337 | /* First pass through ROAM process -- look for a better |
| 5338 | * network */ |
| 5339 | unsigned long flags; |
| 5340 | |
| 5341 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 5342 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 5343 | if (network != priv->assoc_network) |
| 5344 | ipw_find_adhoc_network(priv, &match, network, |
| 5345 | 1); |
| 5346 | } |
| 5347 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 5348 | |
| 5349 | if (match.network == priv->assoc_network) { |
| 5350 | IPW_DEBUG_MERGE("No better ADHOC in this network to " |
| 5351 | "merge to.\n"); |
| 5352 | return; |
| 5353 | } |
| 5354 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5355 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5356 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
| 5357 | IPW_DEBUG_MERGE("remove network %s\n", |
| 5358 | escape_essid(priv->essid, |
| 5359 | priv->essid_len)); |
| 5360 | ipw_remove_current_network(priv); |
| 5361 | } |
| 5362 | |
| 5363 | ipw_disassociate(priv); |
| 5364 | priv->assoc_network = match.network; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5365 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5366 | return; |
| 5367 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5368 | } |
| 5369 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5370 | static int ipw_best_network(struct ipw_priv *priv, |
| 5371 | struct ipw_network_match *match, |
| 5372 | struct ieee80211_network *network, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5373 | { |
| 5374 | struct ipw_supported_rates rates; |
| 5375 | |
| 5376 | /* Verify that this network's capability is compatible with the |
| 5377 | * current mode (AdHoc or Infrastructure) */ |
| 5378 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && |
Jouni Malinen | 2474385 | 2005-08-14 20:59:59 -0700 | [diff] [blame] | 5379 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5380 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5381 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5382 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5383 | "capability mismatch.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5384 | escape_essid(network->ssid, network->ssid_len), |
| 5385 | MAC_ARG(network->bssid)); |
| 5386 | return 0; |
| 5387 | } |
| 5388 | |
| 5389 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5390 | * it */ |
| 5391 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5392 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5393 | "because of hidden ESSID.\n", |
| 5394 | escape_essid(network->ssid, network->ssid_len), |
| 5395 | MAC_ARG(network->bssid)); |
| 5396 | return 0; |
| 5397 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5398 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5399 | if (unlikely(roaming)) { |
| 5400 | /* If we are roaming, then ensure check if this is a valid |
| 5401 | * network to try and roam to */ |
| 5402 | if ((network->ssid_len != match->network->ssid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5403 | memcmp(network->ssid, match->network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5404 | network->ssid_len)) { |
| 5405 | IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5406 | "because of non-network ESSID.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5407 | escape_essid(network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5408 | network->ssid_len), |
| 5409 | MAC_ARG(network->bssid)); |
| 5410 | return 0; |
| 5411 | } |
| 5412 | } else { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5413 | /* If an ESSID has been configured then compare the broadcast |
| 5414 | * ESSID to ours */ |
| 5415 | if ((priv->config & CFG_STATIC_ESSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5416 | ((network->ssid_len != priv->essid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5417 | memcmp(network->ssid, priv->essid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5418 | min(network->ssid_len, priv->essid_len)))) { |
| 5419 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5420 | strncpy(escaped, |
| 5421 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5422 | sizeof(escaped)); |
| 5423 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5424 | "because of ESSID mismatch: '%s'.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5425 | escaped, MAC_ARG(network->bssid), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5426 | escape_essid(priv->essid, |
| 5427 | priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5428 | return 0; |
| 5429 | } |
| 5430 | } |
| 5431 | |
| 5432 | /* If the old network rate is better than this one, don't bother |
| 5433 | * testing everything else. */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5434 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5435 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5436 | strncpy(escaped, |
| 5437 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5438 | sizeof(escaped)); |
| 5439 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because " |
| 5440 | "'%s (" MAC_FMT ")' has a stronger signal.\n", |
| 5441 | escaped, MAC_ARG(network->bssid), |
| 5442 | escape_essid(match->network->ssid, |
| 5443 | match->network->ssid_len), |
| 5444 | MAC_ARG(match->network->bssid)); |
| 5445 | return 0; |
| 5446 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5447 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5448 | /* If this network has already had an association attempt within the |
| 5449 | * last 3 seconds, do not try and associate again... */ |
| 5450 | if (network->last_associate && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5451 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5452 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5453 | "because of storming (%ums since last " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5454 | "assoc attempt).\n", |
| 5455 | escape_essid(network->ssid, network->ssid_len), |
| 5456 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5457 | jiffies_to_msecs(jiffies - |
| 5458 | network->last_associate)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5459 | return 0; |
| 5460 | } |
| 5461 | |
| 5462 | /* Now go through and see if the requested network is valid... */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5463 | if (priv->ieee->scan_age != 0 && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5464 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5465 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5466 | "because of age: %ums.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5467 | escape_essid(network->ssid, network->ssid_len), |
| 5468 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5469 | jiffies_to_msecs(jiffies - |
| 5470 | network->last_scanned)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5471 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5472 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5473 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5474 | if ((priv->config & CFG_STATIC_CHANNEL) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5475 | (network->channel != priv->channel)) { |
| 5476 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5477 | "because of channel mismatch: %d != %d.\n", |
| 5478 | escape_essid(network->ssid, network->ssid_len), |
| 5479 | MAC_ARG(network->bssid), |
| 5480 | network->channel, priv->channel); |
| 5481 | return 0; |
| 5482 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5483 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5484 | /* Verify privacy compatability */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5485 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5486 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5487 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5488 | "because of privacy mismatch: %s != %s.\n", |
| 5489 | escape_essid(network->ssid, network->ssid_len), |
| 5490 | MAC_ARG(network->bssid), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5491 | priv->capability & CAP_PRIVACY_ON ? "on" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5492 | "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5493 | network->capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5494 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5495 | return 0; |
| 5496 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5497 | |
| 5498 | if ((priv->config & CFG_STATIC_BSSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5499 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5500 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5501 | "because of BSSID mismatch: " MAC_FMT ".\n", |
| 5502 | escape_essid(network->ssid, network->ssid_len), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5503 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5504 | return 0; |
| 5505 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5506 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5507 | /* Filter out any incompatible freq / mode combinations */ |
| 5508 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5509 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5510 | "because of invalid frequency/mode " |
| 5511 | "combination.\n", |
| 5512 | escape_essid(network->ssid, network->ssid_len), |
| 5513 | MAC_ARG(network->bssid)); |
| 5514 | return 0; |
| 5515 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5516 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5517 | /* Filter out invalid channel in current GEO */ |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5518 | if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5519 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5520 | "because of invalid channel in current GEO\n", |
| 5521 | escape_essid(network->ssid, network->ssid_len), |
| 5522 | MAC_ARG(network->bssid)); |
| 5523 | return 0; |
| 5524 | } |
| 5525 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5526 | /* Ensure that the rates supported by the driver are compatible with |
| 5527 | * this AP, including verification of basic rates (mandatory) */ |
| 5528 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5529 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5530 | "because configured rate mask excludes " |
| 5531 | "AP mandatory rate.\n", |
| 5532 | escape_essid(network->ssid, network->ssid_len), |
| 5533 | MAC_ARG(network->bssid)); |
| 5534 | return 0; |
| 5535 | } |
| 5536 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5537 | if (rates.num_rates == 0) { |
| 5538 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5539 | "because of no compatible rates.\n", |
| 5540 | escape_essid(network->ssid, network->ssid_len), |
| 5541 | MAC_ARG(network->bssid)); |
| 5542 | return 0; |
| 5543 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5544 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5545 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5546 | * want to put too much policy logic here; intelligent scan selection |
| 5547 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5548 | |
| 5549 | /* Set up 'new' AP to this network */ |
| 5550 | ipw_copy_rates(&match->rates, &rates); |
| 5551 | match->network = network; |
| 5552 | |
| 5553 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5554 | escape_essid(network->ssid, network->ssid_len), |
| 5555 | MAC_ARG(network->bssid)); |
| 5556 | |
| 5557 | return 1; |
| 5558 | } |
| 5559 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5560 | static void ipw_adhoc_create(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5561 | struct ieee80211_network *network) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5562 | { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5563 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5564 | int i; |
| 5565 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5566 | /* |
| 5567 | * For the purposes of scanning, we can set our wireless mode |
| 5568 | * to trigger scans across combinations of bands, but when it |
| 5569 | * comes to creating a new ad-hoc network, we have tell the FW |
| 5570 | * exactly which band to use. |
| 5571 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5572 | * We also have the possibility of an invalid channel for the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5573 | * chossen band. Attempting to create a new ad-hoc network |
| 5574 | * with an invalid channel for wireless mode will trigger a |
| 5575 | * FW fatal error. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5576 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5577 | */ |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5578 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5579 | case IEEE80211_52GHZ_BAND: |
| 5580 | network->mode = IEEE_A; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5581 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5582 | BUG_ON(i == -1); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5583 | if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5584 | IPW_WARNING("Overriding invalid channel\n"); |
| 5585 | priv->channel = geo->a[0].channel; |
| 5586 | } |
| 5587 | break; |
| 5588 | |
| 5589 | case IEEE80211_24GHZ_BAND: |
| 5590 | if (priv->ieee->mode & IEEE_G) |
| 5591 | network->mode = IEEE_G; |
| 5592 | else |
| 5593 | network->mode = IEEE_B; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5594 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 5595 | BUG_ON(i == -1); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5596 | if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5597 | IPW_WARNING("Overriding invalid channel\n"); |
| 5598 | priv->channel = geo->bg[0].channel; |
| 5599 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5600 | break; |
| 5601 | |
| 5602 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5603 | IPW_WARNING("Overriding invalid channel\n"); |
| 5604 | if (priv->ieee->mode & IEEE_A) { |
| 5605 | network->mode = IEEE_A; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5606 | priv->channel = geo->a[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5607 | } else if (priv->ieee->mode & IEEE_G) { |
| 5608 | network->mode = IEEE_G; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5609 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5610 | } else { |
| 5611 | network->mode = IEEE_B; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5612 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5613 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5614 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5615 | } |
| 5616 | |
| 5617 | network->channel = priv->channel; |
| 5618 | priv->config |= CFG_ADHOC_PERSIST; |
| 5619 | ipw_create_bssid(priv, network->bssid); |
| 5620 | network->ssid_len = priv->essid_len; |
| 5621 | memcpy(network->ssid, priv->essid, priv->essid_len); |
| 5622 | memset(&network->stats, 0, sizeof(network->stats)); |
| 5623 | network->capability = WLAN_CAPABILITY_IBSS; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5624 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
| 5625 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5626 | if (priv->capability & CAP_PRIVACY_ON) |
| 5627 | network->capability |= WLAN_CAPABILITY_PRIVACY; |
| 5628 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5629 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5630 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5631 | memcpy(network->rates_ex, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5632 | &priv->rates.supported_rates[network->rates_len], |
| 5633 | network->rates_ex_len); |
| 5634 | network->last_scanned = 0; |
| 5635 | network->flags = 0; |
| 5636 | network->last_associate = 0; |
| 5637 | network->time_stamp[0] = 0; |
| 5638 | network->time_stamp[1] = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5639 | network->beacon_interval = 100; /* Default */ |
| 5640 | network->listen_interval = 10; /* Default */ |
| 5641 | network->atim_window = 0; /* Default */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5642 | network->wpa_ie_len = 0; |
| 5643 | network->rsn_ie_len = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5644 | } |
| 5645 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5646 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
| 5647 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5648 | struct ipw_tgi_tx_key key; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5649 | |
| 5650 | if (!(priv->ieee->sec.flags & (1 << index))) |
| 5651 | return; |
| 5652 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5653 | key.key_id = index; |
| 5654 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); |
| 5655 | key.security_type = type; |
| 5656 | key.station_index = 0; /* always 0 for BSS */ |
| 5657 | key.flags = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5658 | /* 0 for new key; previous value of counter (after fatal error) */ |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5659 | key.tx_counter[0] = 0; |
| 5660 | key.tx_counter[1] = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5661 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5662 | 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] | 5663 | } |
| 5664 | |
| 5665 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5666 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5667 | struct ipw_wep_key key; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5668 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5669 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5670 | key.cmd_id = DINO_CMD_WEP_KEY; |
| 5671 | key.seq_num = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5672 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5673 | /* Note: AES keys cannot be set for multiple times. |
| 5674 | * Only set it at the first time. */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5675 | for (i = 0; i < 4; i++) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5676 | key.key_index = i | type; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5677 | if (!(priv->ieee->sec.flags & (1 << i))) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5678 | key.key_size = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5679 | continue; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5680 | } |
| 5681 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5682 | key.key_size = priv->ieee->sec.key_sizes[i]; |
| 5683 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5684 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5685 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5686 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5687 | } |
| 5688 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 5689 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
| 5690 | { |
| 5691 | if (priv->ieee->host_encrypt) |
| 5692 | return; |
| 5693 | |
| 5694 | switch (level) { |
| 5695 | case SEC_LEVEL_3: |
| 5696 | priv->sys_config.disable_unicast_decryption = 0; |
| 5697 | priv->ieee->host_decrypt = 0; |
| 5698 | break; |
| 5699 | case SEC_LEVEL_2: |
| 5700 | priv->sys_config.disable_unicast_decryption = 1; |
| 5701 | priv->ieee->host_decrypt = 1; |
| 5702 | break; |
| 5703 | case SEC_LEVEL_1: |
| 5704 | priv->sys_config.disable_unicast_decryption = 0; |
| 5705 | priv->ieee->host_decrypt = 0; |
| 5706 | break; |
| 5707 | case SEC_LEVEL_0: |
| 5708 | priv->sys_config.disable_unicast_decryption = 1; |
| 5709 | break; |
| 5710 | default: |
| 5711 | break; |
| 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) |
| 5716 | { |
| 5717 | if (priv->ieee->host_encrypt) |
| 5718 | return; |
| 5719 | |
| 5720 | switch (level) { |
| 5721 | case SEC_LEVEL_3: |
| 5722 | priv->sys_config.disable_multicast_decryption = 0; |
| 5723 | break; |
| 5724 | case SEC_LEVEL_2: |
| 5725 | priv->sys_config.disable_multicast_decryption = 1; |
| 5726 | break; |
| 5727 | case SEC_LEVEL_1: |
| 5728 | priv->sys_config.disable_multicast_decryption = 0; |
| 5729 | break; |
| 5730 | case SEC_LEVEL_0: |
| 5731 | priv->sys_config.disable_multicast_decryption = 1; |
| 5732 | break; |
| 5733 | default: |
| 5734 | break; |
| 5735 | } |
| 5736 | } |
| 5737 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5738 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
| 5739 | { |
| 5740 | switch (priv->ieee->sec.level) { |
| 5741 | case SEC_LEVEL_3: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5742 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5743 | ipw_send_tgi_tx_key(priv, |
| 5744 | DCT_FLAG_EXT_SECURITY_CCM, |
| 5745 | priv->ieee->sec.active_key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5746 | |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 5747 | if (!priv->ieee->host_mc_decrypt) |
| 5748 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5749 | break; |
| 5750 | case SEC_LEVEL_2: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5751 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5752 | ipw_send_tgi_tx_key(priv, |
| 5753 | DCT_FLAG_EXT_SECURITY_TKIP, |
| 5754 | priv->ieee->sec.active_key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5755 | break; |
| 5756 | case SEC_LEVEL_1: |
| 5757 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Hong Liu | 29cb843 | 2005-09-12 10:43:33 -0500 | [diff] [blame] | 5758 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
| 5759 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5760 | break; |
| 5761 | case SEC_LEVEL_0: |
| 5762 | default: |
| 5763 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5764 | } |
| 5765 | } |
| 5766 | |
| 5767 | static void ipw_adhoc_check(void *data) |
| 5768 | { |
| 5769 | struct ipw_priv *priv = data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5770 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5771 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5772 | !(priv->config & CFG_ADHOC_PERSIST)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5773 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 5774 | IPW_DL_STATE | IPW_DL_ASSOC, |
| 5775 | "Missed beacon: %d - disassociate\n", |
| 5776 | priv->missed_adhoc_beacons); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5777 | ipw_remove_current_network(priv); |
| 5778 | ipw_disassociate(priv); |
| 5779 | return; |
| 5780 | } |
| 5781 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5782 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5783 | priv->assoc_request.beacon_interval); |
| 5784 | } |
| 5785 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5786 | static void ipw_bg_adhoc_check(void *data) |
| 5787 | { |
| 5788 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5789 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5790 | ipw_adhoc_check(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5791 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5792 | } |
| 5793 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 5794 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5795 | static void ipw_debug_config(struct ipw_priv *priv) |
| 5796 | { |
| 5797 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
| 5798 | "[CFG 0x%08X]\n", priv->config); |
| 5799 | if (priv->config & CFG_STATIC_CHANNEL) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5800 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5801 | else |
| 5802 | IPW_DEBUG_INFO("Channel unlocked.\n"); |
| 5803 | if (priv->config & CFG_STATIC_ESSID) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5804 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5805 | escape_essid(priv->essid, priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5806 | else |
| 5807 | IPW_DEBUG_INFO("ESSID unlocked.\n"); |
| 5808 | if (priv->config & CFG_STATIC_BSSID) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5809 | IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n", |
| 5810 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5811 | else |
| 5812 | IPW_DEBUG_INFO("BSSID unlocked.\n"); |
| 5813 | if (priv->capability & CAP_PRIVACY_ON) |
| 5814 | IPW_DEBUG_INFO("PRIVACY on\n"); |
| 5815 | else |
| 5816 | IPW_DEBUG_INFO("PRIVACY off\n"); |
| 5817 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); |
| 5818 | } |
| 5819 | #else |
Jiri Benc | 8d45ff7 | 2005-08-25 20:09:39 -0400 | [diff] [blame] | 5820 | #define ipw_debug_config(x) do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5821 | #endif |
| 5822 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5823 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5824 | { |
| 5825 | /* TODO: Verify that this works... */ |
| 5826 | struct ipw_fixed_rate fr = { |
| 5827 | .tx_rates = priv->rates_mask |
| 5828 | }; |
| 5829 | u32 reg; |
| 5830 | u16 mask = 0; |
| 5831 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5832 | /* Identify 'current FW band' and match it with the fixed |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5833 | * Tx rates */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5834 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5835 | switch (priv->ieee->freq_band) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5836 | case IEEE80211_52GHZ_BAND: /* A only */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5837 | /* IEEE_A */ |
| 5838 | if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { |
| 5839 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5840 | IPW_DEBUG_WX |
| 5841 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5842 | fr.tx_rates = 0; |
| 5843 | break; |
| 5844 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5845 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5846 | fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A; |
| 5847 | break; |
| 5848 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5849 | default: /* 2.4Ghz or Mixed */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5850 | /* IEEE_B */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5851 | if (mode == IEEE_B) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5852 | if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { |
| 5853 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5854 | IPW_DEBUG_WX |
| 5855 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5856 | fr.tx_rates = 0; |
| 5857 | } |
| 5858 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5859 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5860 | |
| 5861 | /* IEEE_G */ |
| 5862 | if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK | |
| 5863 | IEEE80211_OFDM_RATES_MASK)) { |
| 5864 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5865 | IPW_DEBUG_WX |
| 5866 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5867 | fr.tx_rates = 0; |
| 5868 | break; |
| 5869 | } |
| 5870 | |
| 5871 | if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) { |
| 5872 | mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1); |
| 5873 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK; |
| 5874 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5875 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5876 | if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) { |
| 5877 | mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1); |
| 5878 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK; |
| 5879 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5880 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5881 | if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) { |
| 5882 | mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1); |
| 5883 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK; |
| 5884 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5885 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5886 | fr.tx_rates |= mask; |
| 5887 | break; |
| 5888 | } |
| 5889 | |
| 5890 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5891 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5892 | } |
| 5893 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5894 | static void ipw_abort_scan(struct ipw_priv *priv) |
| 5895 | { |
| 5896 | int err; |
| 5897 | |
| 5898 | if (priv->status & STATUS_SCAN_ABORTING) { |
| 5899 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); |
| 5900 | return; |
| 5901 | } |
| 5902 | priv->status |= STATUS_SCAN_ABORTING; |
| 5903 | |
| 5904 | err = ipw_send_scan_abort(priv); |
| 5905 | if (err) |
| 5906 | IPW_DEBUG_HC("Request to abort scan failed.\n"); |
| 5907 | } |
| 5908 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5909 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
| 5910 | struct ipw_scan_request_ext *scan, |
| 5911 | int scan_type) |
| 5912 | { |
| 5913 | int channel_index = 0; |
| 5914 | const struct ieee80211_geo *geo; |
| 5915 | int i; |
| 5916 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5917 | geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5918 | |
| 5919 | if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { |
| 5920 | int start = channel_index; |
| 5921 | for (i = 0; i < geo->a_channels; i++) { |
| 5922 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5923 | geo->a[i].channel == priv->channel) |
| 5924 | continue; |
| 5925 | channel_index++; |
| 5926 | scan->channels_list[channel_index] = geo->a[i].channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5927 | ipw_set_scan_type(scan, channel_index, |
| 5928 | geo->a[i]. |
| 5929 | flags & IEEE80211_CH_PASSIVE_ONLY ? |
| 5930 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : |
| 5931 | scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | if (start != channel_index) { |
| 5935 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | |
| 5936 | (channel_index - start); |
| 5937 | channel_index++; |
| 5938 | } |
| 5939 | } |
| 5940 | |
| 5941 | if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { |
| 5942 | int start = channel_index; |
| 5943 | if (priv->config & CFG_SPEED_SCAN) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5944 | int index; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5945 | u8 channels[IEEE80211_24GHZ_CHANNELS] = { |
| 5946 | /* nop out the list */ |
| 5947 | [0] = 0 |
| 5948 | }; |
| 5949 | |
| 5950 | u8 channel; |
| 5951 | while (channel_index < IPW_SCAN_CHANNELS) { |
| 5952 | channel = |
| 5953 | priv->speed_scan[priv->speed_scan_pos]; |
| 5954 | if (channel == 0) { |
| 5955 | priv->speed_scan_pos = 0; |
| 5956 | channel = priv->speed_scan[0]; |
| 5957 | } |
| 5958 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5959 | channel == priv->channel) { |
| 5960 | priv->speed_scan_pos++; |
| 5961 | continue; |
| 5962 | } |
| 5963 | |
| 5964 | /* If this channel has already been |
| 5965 | * added in scan, break from loop |
| 5966 | * and this will be the first channel |
| 5967 | * in the next scan. |
| 5968 | */ |
| 5969 | if (channels[channel - 1] != 0) |
| 5970 | break; |
| 5971 | |
| 5972 | channels[channel - 1] = 1; |
| 5973 | priv->speed_scan_pos++; |
| 5974 | channel_index++; |
| 5975 | scan->channels_list[channel_index] = channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5976 | index = |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5977 | ieee80211_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5978 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5979 | geo->bg[index]. |
| 5980 | flags & |
| 5981 | IEEE80211_CH_PASSIVE_ONLY ? |
| 5982 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 5983 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5984 | } |
| 5985 | } else { |
| 5986 | for (i = 0; i < geo->bg_channels; i++) { |
| 5987 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5988 | geo->bg[i].channel == priv->channel) |
| 5989 | continue; |
| 5990 | channel_index++; |
| 5991 | scan->channels_list[channel_index] = |
| 5992 | geo->bg[i].channel; |
| 5993 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5994 | geo->bg[i]. |
| 5995 | flags & |
| 5996 | IEEE80211_CH_PASSIVE_ONLY ? |
| 5997 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 5998 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5999 | } |
| 6000 | } |
| 6001 | |
| 6002 | if (start != channel_index) { |
| 6003 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | |
| 6004 | (channel_index - start); |
| 6005 | } |
| 6006 | } |
| 6007 | } |
| 6008 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6009 | static int ipw_request_scan(struct ipw_priv *priv) |
| 6010 | { |
| 6011 | struct ipw_scan_request_ext scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6012 | int err = 0, scan_type; |
| 6013 | |
| 6014 | if (!(priv->status & STATUS_INIT) || |
| 6015 | (priv->status & STATUS_EXIT_PENDING)) |
| 6016 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6017 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6018 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6019 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6020 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6021 | IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6022 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6023 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6024 | } |
| 6025 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6026 | if (!(priv->status & STATUS_SCAN_FORCED) && |
| 6027 | priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6028 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6029 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6030 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6031 | } |
| 6032 | |
| 6033 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 6034 | IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6035 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6036 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6037 | } |
| 6038 | |
| 6039 | memset(&scan, 0, sizeof(scan)); |
| 6040 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6041 | if (priv->config & CFG_SPEED_SCAN) |
| 6042 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 6043 | cpu_to_le16(30); |
| 6044 | else |
| 6045 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 6046 | cpu_to_le16(20); |
| 6047 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6048 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 6049 | cpu_to_le16(20); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6050 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6051 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6052 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6053 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6054 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6055 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6056 | u8 channel; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6057 | u8 band = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6058 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 6059 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6060 | case IEEE80211_52GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6061 | band = (u8) (IPW_A_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6062 | channel = priv->channel; |
| 6063 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6064 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6065 | case IEEE80211_24GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6066 | band = (u8) (IPW_B_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6067 | channel = priv->channel; |
| 6068 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6069 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6070 | default: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6071 | band = (u8) (IPW_B_MODE << 6) | 1; |
| 6072 | channel = 9; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6073 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6074 | } |
| 6075 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6076 | scan.channels_list[0] = band; |
| 6077 | scan.channels_list[1] = channel; |
| 6078 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6079 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6080 | /* NOTE: The card will sit on this channel for this time |
| 6081 | * period. Scan aborts are timing sensitive and frequently |
| 6082 | * result in firmware restarts. As such, it is best to |
| 6083 | * set a small dwell_time here and just keep re-issuing |
| 6084 | * scans. Otherwise fast channel hopping will not actually |
| 6085 | * hop channels. |
| 6086 | * |
| 6087 | * TODO: Move SPEED SCAN support to all modes and bands */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6088 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
| 6089 | cpu_to_le16(2000); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6090 | } else { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6091 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 6092 | /* If we are roaming, then make this a directed scan for the |
| 6093 | * current network. Otherwise, ensure that every other scan |
| 6094 | * is a fast channel hop scan */ |
| 6095 | if ((priv->status & STATUS_ROAMING) |
| 6096 | || (!(priv->status & STATUS_ASSOCIATED) |
| 6097 | && (priv->config & CFG_STATIC_ESSID) |
| 6098 | && (le32_to_cpu(scan.full_scan_index) % 2))) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6099 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 6100 | if (err) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6101 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6102 | "failed.\n"); |
| 6103 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6104 | } |
| 6105 | |
| 6106 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6107 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6108 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6109 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6110 | ipw_add_scan_channels(priv, &scan, scan_type); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6111 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6112 | } |
| 6113 | #endif |
| 6114 | |
| 6115 | err = ipw_send_scan_request_ext(priv, &scan); |
| 6116 | if (err) { |
| 6117 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6118 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6119 | } |
| 6120 | |
| 6121 | priv->status |= STATUS_SCANNING; |
| 6122 | priv->status &= ~STATUS_SCAN_PENDING; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6123 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6124 | IPW_SCAN_CHECK_WATCHDOG); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6125 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6126 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6127 | return err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6128 | } |
| 6129 | |
| 6130 | static void ipw_bg_abort_scan(void *data) |
| 6131 | { |
| 6132 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6133 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6134 | ipw_abort_scan(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6135 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6136 | } |
| 6137 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6138 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
| 6139 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6140 | /* This is called when wpa_supplicant loads and closes the driver |
| 6141 | * interface. */ |
Hong Liu | cdd1fa1 | 2005-08-31 18:14:27 +0800 | [diff] [blame] | 6142 | priv->ieee->wpa_enabled = value; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6143 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6144 | } |
| 6145 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6146 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
| 6147 | { |
| 6148 | struct ieee80211_device *ieee = priv->ieee; |
| 6149 | struct ieee80211_security sec = { |
| 6150 | .flags = SEC_AUTH_MODE, |
| 6151 | }; |
| 6152 | int ret = 0; |
| 6153 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6154 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6155 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
| 6156 | ieee->open_wep = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6157 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6158 | sec.auth_mode = WLAN_AUTH_OPEN; |
| 6159 | ieee->open_wep = 1; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 6160 | } else if (value & IW_AUTH_ALG_LEAP) { |
| 6161 | sec.auth_mode = WLAN_AUTH_LEAP; |
| 6162 | ieee->open_wep = 1; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6163 | } else |
| 6164 | return -EINVAL; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6165 | |
| 6166 | if (ieee->set_security) |
| 6167 | ieee->set_security(ieee->dev, &sec); |
| 6168 | else |
| 6169 | ret = -EOPNOTSUPP; |
| 6170 | |
| 6171 | return ret; |
| 6172 | } |
| 6173 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 6174 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
| 6175 | int wpa_ie_len) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6176 | { |
| 6177 | /* make sure WPA is enabled */ |
| 6178 | ipw_wpa_enable(priv, 1); |
| 6179 | |
| 6180 | ipw_disassociate(priv); |
| 6181 | } |
| 6182 | |
| 6183 | static int ipw_set_rsn_capa(struct ipw_priv *priv, |
| 6184 | char *capabilities, int length) |
| 6185 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6186 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
| 6187 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6188 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 6189 | capabilities); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6190 | } |
| 6191 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6192 | /* |
| 6193 | * WE-18 support |
| 6194 | */ |
| 6195 | |
| 6196 | /* SIOCSIWGENIE */ |
| 6197 | static int ipw_wx_set_genie(struct net_device *dev, |
| 6198 | struct iw_request_info *info, |
| 6199 | union iwreq_data *wrqu, char *extra) |
| 6200 | { |
| 6201 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6202 | struct ieee80211_device *ieee = priv->ieee; |
| 6203 | u8 *buf; |
| 6204 | int err = 0; |
| 6205 | |
| 6206 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
| 6207 | (wrqu->data.length && extra == NULL)) |
| 6208 | return -EINVAL; |
| 6209 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6210 | //mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6211 | |
| 6212 | //if (!ieee->wpa_enabled) { |
| 6213 | // err = -EOPNOTSUPP; |
| 6214 | // goto out; |
| 6215 | //} |
| 6216 | |
| 6217 | if (wrqu->data.length) { |
| 6218 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 6219 | if (buf == NULL) { |
| 6220 | err = -ENOMEM; |
| 6221 | goto out; |
| 6222 | } |
| 6223 | |
| 6224 | memcpy(buf, extra, wrqu->data.length); |
| 6225 | kfree(ieee->wpa_ie); |
| 6226 | ieee->wpa_ie = buf; |
| 6227 | ieee->wpa_ie_len = wrqu->data.length; |
| 6228 | } else { |
| 6229 | kfree(ieee->wpa_ie); |
| 6230 | ieee->wpa_ie = NULL; |
| 6231 | ieee->wpa_ie_len = 0; |
| 6232 | } |
| 6233 | |
| 6234 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6235 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6236 | //mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6237 | return err; |
| 6238 | } |
| 6239 | |
| 6240 | /* SIOCGIWGENIE */ |
| 6241 | static int ipw_wx_get_genie(struct net_device *dev, |
| 6242 | struct iw_request_info *info, |
| 6243 | union iwreq_data *wrqu, char *extra) |
| 6244 | { |
| 6245 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6246 | struct ieee80211_device *ieee = priv->ieee; |
| 6247 | int err = 0; |
| 6248 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6249 | //mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6250 | |
| 6251 | //if (!ieee->wpa_enabled) { |
| 6252 | // err = -EOPNOTSUPP; |
| 6253 | // goto out; |
| 6254 | //} |
| 6255 | |
| 6256 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
| 6257 | wrqu->data.length = 0; |
| 6258 | goto out; |
| 6259 | } |
| 6260 | |
| 6261 | if (wrqu->data.length < ieee->wpa_ie_len) { |
| 6262 | err = -E2BIG; |
| 6263 | goto out; |
| 6264 | } |
| 6265 | |
| 6266 | wrqu->data.length = ieee->wpa_ie_len; |
| 6267 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6268 | |
| 6269 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6270 | //mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6271 | return err; |
| 6272 | } |
| 6273 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6274 | static int wext_cipher2level(int cipher) |
| 6275 | { |
| 6276 | switch (cipher) { |
| 6277 | case IW_AUTH_CIPHER_NONE: |
| 6278 | return SEC_LEVEL_0; |
| 6279 | case IW_AUTH_CIPHER_WEP40: |
| 6280 | case IW_AUTH_CIPHER_WEP104: |
| 6281 | return SEC_LEVEL_1; |
| 6282 | case IW_AUTH_CIPHER_TKIP: |
| 6283 | return SEC_LEVEL_2; |
| 6284 | case IW_AUTH_CIPHER_CCMP: |
| 6285 | return SEC_LEVEL_3; |
| 6286 | default: |
| 6287 | return -1; |
| 6288 | } |
| 6289 | } |
| 6290 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6291 | /* SIOCSIWAUTH */ |
| 6292 | static int ipw_wx_set_auth(struct net_device *dev, |
| 6293 | struct iw_request_info *info, |
| 6294 | union iwreq_data *wrqu, char *extra) |
| 6295 | { |
| 6296 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6297 | struct ieee80211_device *ieee = priv->ieee; |
| 6298 | struct iw_param *param = &wrqu->param; |
| 6299 | struct ieee80211_crypt_data *crypt; |
| 6300 | unsigned long flags; |
| 6301 | int ret = 0; |
| 6302 | |
| 6303 | switch (param->flags & IW_AUTH_INDEX) { |
| 6304 | case IW_AUTH_WPA_VERSION: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6305 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6306 | case IW_AUTH_CIPHER_PAIRWISE: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6307 | ipw_set_hw_decrypt_unicast(priv, |
| 6308 | wext_cipher2level(param->value)); |
| 6309 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6310 | case IW_AUTH_CIPHER_GROUP: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6311 | ipw_set_hw_decrypt_multicast(priv, |
| 6312 | wext_cipher2level(param->value)); |
| 6313 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6314 | case IW_AUTH_KEY_MGMT: |
| 6315 | /* |
| 6316 | * ipw2200 does not use these parameters |
| 6317 | */ |
| 6318 | break; |
| 6319 | |
| 6320 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6321 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6322 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6323 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6324 | |
| 6325 | flags = crypt->ops->get_flags(crypt->priv); |
| 6326 | |
| 6327 | if (param->value) |
| 6328 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6329 | else |
| 6330 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6331 | |
| 6332 | crypt->ops->set_flags(flags, crypt->priv); |
| 6333 | |
| 6334 | break; |
| 6335 | |
| 6336 | case IW_AUTH_DROP_UNENCRYPTED:{ |
| 6337 | /* HACK: |
| 6338 | * |
| 6339 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6340 | * is loaded and unloaded, regardless of if WPA is being |
| 6341 | * used. No other calls are made which can be used to |
| 6342 | * determine if encryption will be used or not prior to |
| 6343 | * association being expected. If encryption is not being |
| 6344 | * used, drop_unencrypted is set to false, else true -- we |
| 6345 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6346 | * be set. |
| 6347 | */ |
| 6348 | struct ieee80211_security sec = { |
| 6349 | .flags = SEC_ENABLED, |
| 6350 | .enabled = param->value, |
| 6351 | }; |
| 6352 | priv->ieee->drop_unencrypted = param->value; |
| 6353 | /* We only change SEC_LEVEL for open mode. Others |
| 6354 | * are set by ipw_wpa_set_encryption. |
| 6355 | */ |
| 6356 | if (!param->value) { |
| 6357 | sec.flags |= SEC_LEVEL; |
| 6358 | sec.level = SEC_LEVEL_0; |
| 6359 | } else { |
| 6360 | sec.flags |= SEC_LEVEL; |
| 6361 | sec.level = SEC_LEVEL_1; |
| 6362 | } |
| 6363 | if (priv->ieee->set_security) |
| 6364 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6365 | break; |
| 6366 | } |
| 6367 | |
| 6368 | case IW_AUTH_80211_AUTH_ALG: |
| 6369 | ret = ipw_wpa_set_auth_algs(priv, param->value); |
| 6370 | break; |
| 6371 | |
| 6372 | case IW_AUTH_WPA_ENABLED: |
| 6373 | ret = ipw_wpa_enable(priv, param->value); |
| 6374 | break; |
| 6375 | |
| 6376 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6377 | ieee->ieee802_1x = param->value; |
| 6378 | break; |
| 6379 | |
| 6380 | //case IW_AUTH_ROAMING_CONTROL: |
| 6381 | case IW_AUTH_PRIVACY_INVOKED: |
| 6382 | ieee->privacy_invoked = param->value; |
| 6383 | break; |
| 6384 | |
| 6385 | default: |
| 6386 | return -EOPNOTSUPP; |
| 6387 | } |
| 6388 | return ret; |
| 6389 | } |
| 6390 | |
| 6391 | /* SIOCGIWAUTH */ |
| 6392 | static int ipw_wx_get_auth(struct net_device *dev, |
| 6393 | struct iw_request_info *info, |
| 6394 | union iwreq_data *wrqu, char *extra) |
| 6395 | { |
| 6396 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6397 | struct ieee80211_device *ieee = priv->ieee; |
| 6398 | struct ieee80211_crypt_data *crypt; |
| 6399 | struct iw_param *param = &wrqu->param; |
| 6400 | int ret = 0; |
| 6401 | |
| 6402 | switch (param->flags & IW_AUTH_INDEX) { |
| 6403 | case IW_AUTH_WPA_VERSION: |
| 6404 | case IW_AUTH_CIPHER_PAIRWISE: |
| 6405 | case IW_AUTH_CIPHER_GROUP: |
| 6406 | case IW_AUTH_KEY_MGMT: |
| 6407 | /* |
| 6408 | * wpa_supplicant will control these internally |
| 6409 | */ |
| 6410 | ret = -EOPNOTSUPP; |
| 6411 | break; |
| 6412 | |
| 6413 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6414 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6415 | if (!crypt || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6416 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6417 | |
| 6418 | param->value = (crypt->ops->get_flags(crypt->priv) & |
| 6419 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; |
| 6420 | |
| 6421 | break; |
| 6422 | |
| 6423 | case IW_AUTH_DROP_UNENCRYPTED: |
| 6424 | param->value = ieee->drop_unencrypted; |
| 6425 | break; |
| 6426 | |
| 6427 | case IW_AUTH_80211_AUTH_ALG: |
| 6428 | param->value = ieee->sec.auth_mode; |
| 6429 | break; |
| 6430 | |
| 6431 | case IW_AUTH_WPA_ENABLED: |
| 6432 | param->value = ieee->wpa_enabled; |
| 6433 | break; |
| 6434 | |
| 6435 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6436 | param->value = ieee->ieee802_1x; |
| 6437 | break; |
| 6438 | |
| 6439 | case IW_AUTH_ROAMING_CONTROL: |
| 6440 | case IW_AUTH_PRIVACY_INVOKED: |
| 6441 | param->value = ieee->privacy_invoked; |
| 6442 | break; |
| 6443 | |
| 6444 | default: |
| 6445 | return -EOPNOTSUPP; |
| 6446 | } |
| 6447 | return 0; |
| 6448 | } |
| 6449 | |
| 6450 | /* SIOCSIWENCODEEXT */ |
| 6451 | static int ipw_wx_set_encodeext(struct net_device *dev, |
| 6452 | struct iw_request_info *info, |
| 6453 | union iwreq_data *wrqu, char *extra) |
| 6454 | { |
| 6455 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6456 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 6457 | |
| 6458 | if (hwcrypto) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6459 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6460 | /* IPW HW can't build TKIP MIC, |
| 6461 | host decryption still needed */ |
| 6462 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) |
| 6463 | priv->ieee->host_mc_decrypt = 1; |
| 6464 | else { |
| 6465 | priv->ieee->host_encrypt = 0; |
| 6466 | priv->ieee->host_encrypt_msdu = 1; |
| 6467 | priv->ieee->host_decrypt = 1; |
| 6468 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6469 | } else { |
| 6470 | priv->ieee->host_encrypt = 0; |
| 6471 | priv->ieee->host_encrypt_msdu = 0; |
| 6472 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6473 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
| 6478 | } |
| 6479 | |
| 6480 | /* SIOCGIWENCODEEXT */ |
| 6481 | static int ipw_wx_get_encodeext(struct net_device *dev, |
| 6482 | struct iw_request_info *info, |
| 6483 | union iwreq_data *wrqu, char *extra) |
| 6484 | { |
| 6485 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6486 | return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); |
| 6487 | } |
| 6488 | |
| 6489 | /* SIOCSIWMLME */ |
| 6490 | static int ipw_wx_set_mlme(struct net_device *dev, |
| 6491 | struct iw_request_info *info, |
| 6492 | union iwreq_data *wrqu, char *extra) |
| 6493 | { |
| 6494 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6495 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 6496 | u16 reason; |
| 6497 | |
| 6498 | reason = cpu_to_le16(mlme->reason_code); |
| 6499 | |
| 6500 | switch (mlme->cmd) { |
| 6501 | case IW_MLME_DEAUTH: |
| 6502 | // silently ignore |
| 6503 | break; |
| 6504 | |
| 6505 | case IW_MLME_DISASSOC: |
| 6506 | ipw_disassociate(priv); |
| 6507 | break; |
| 6508 | |
| 6509 | default: |
| 6510 | return -EOPNOTSUPP; |
| 6511 | } |
| 6512 | return 0; |
| 6513 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6514 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6515 | #ifdef CONFIG_IPW_QOS |
| 6516 | |
| 6517 | /* QoS */ |
| 6518 | /* |
| 6519 | * get the modulation type of the current network or |
| 6520 | * the card current mode |
| 6521 | */ |
Adrian Bunk | 53d0bcf | 2006-03-04 13:14:31 +0100 | [diff] [blame] | 6522 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6523 | { |
| 6524 | u8 mode = 0; |
| 6525 | |
| 6526 | if (priv->status & STATUS_ASSOCIATED) { |
| 6527 | unsigned long flags; |
| 6528 | |
| 6529 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6530 | mode = priv->assoc_network->mode; |
| 6531 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6532 | } else { |
| 6533 | mode = priv->ieee->mode; |
| 6534 | } |
| 6535 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); |
| 6536 | return mode; |
| 6537 | } |
| 6538 | |
| 6539 | /* |
| 6540 | * Handle management frame beacon and probe response |
| 6541 | */ |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6542 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
| 6543 | int active_network, |
| 6544 | struct ieee80211_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6545 | { |
| 6546 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6547 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6548 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6549 | network->qos_data.active = network->qos_data.supported; |
| 6550 | |
| 6551 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6552 | if (active_network && |
| 6553 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6554 | network->qos_data.active = network->qos_data.supported; |
| 6555 | |
| 6556 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 6557 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 6558 | (network->qos_data.old_param_count != |
| 6559 | network->qos_data.param_count)) { |
| 6560 | network->qos_data.old_param_count = |
| 6561 | network->qos_data.param_count; |
| 6562 | schedule_work(&priv->qos_activate); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6563 | IPW_DEBUG_QOS("QoS parameters change call " |
| 6564 | "qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6565 | } |
| 6566 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6567 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
| 6568 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6569 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6570 | else |
| 6571 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6572 | &def_parameters_OFDM, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6573 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6574 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
| 6575 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); |
| 6576 | schedule_work(&priv->qos_activate); |
| 6577 | } |
| 6578 | |
| 6579 | network->qos_data.active = 0; |
| 6580 | network->qos_data.supported = 0; |
| 6581 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6582 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6583 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { |
| 6584 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) |
| 6585 | if ((network->capability & WLAN_CAPABILITY_IBSS) && |
| 6586 | !(network->flags & NETWORK_EMPTY_ESSID)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6587 | if ((network->ssid_len == |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6588 | priv->assoc_network->ssid_len) && |
| 6589 | !memcmp(network->ssid, |
| 6590 | priv->assoc_network->ssid, |
| 6591 | network->ssid_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6592 | queue_work(priv->workqueue, |
| 6593 | &priv->merge_networks); |
| 6594 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6595 | } |
| 6596 | |
| 6597 | return 0; |
| 6598 | } |
| 6599 | |
| 6600 | /* |
| 6601 | * This function set up the firmware to support QoS. It sends |
| 6602 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO |
| 6603 | */ |
| 6604 | static int ipw_qos_activate(struct ipw_priv *priv, |
| 6605 | struct ieee80211_qos_data *qos_network_data) |
| 6606 | { |
| 6607 | int err; |
| 6608 | struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS]; |
| 6609 | struct ieee80211_qos_parameters *active_one = NULL; |
| 6610 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6611 | u32 burst_duration; |
| 6612 | int i; |
| 6613 | u8 type; |
| 6614 | |
| 6615 | type = ipw_qos_current_mode(priv); |
| 6616 | |
| 6617 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); |
| 6618 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); |
| 6619 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); |
| 6620 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); |
| 6621 | |
| 6622 | if (qos_network_data == NULL) { |
| 6623 | if (type == IEEE_B) { |
| 6624 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); |
| 6625 | active_one = &def_parameters_CCK; |
| 6626 | } else |
| 6627 | active_one = &def_parameters_OFDM; |
| 6628 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6629 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6630 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6631 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6632 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
| 6633 | (u16) burst_duration; |
| 6634 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6635 | if (type == IEEE_B) { |
| 6636 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", |
| 6637 | type); |
| 6638 | if (priv->qos_data.qos_enable == 0) |
| 6639 | active_one = &def_parameters_CCK; |
| 6640 | else |
| 6641 | active_one = priv->qos_data.def_qos_parm_CCK; |
| 6642 | } else { |
| 6643 | if (priv->qos_data.qos_enable == 0) |
| 6644 | active_one = &def_parameters_OFDM; |
| 6645 | else |
| 6646 | active_one = priv->qos_data.def_qos_parm_OFDM; |
| 6647 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6648 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6649 | } else { |
| 6650 | unsigned long flags; |
| 6651 | int active; |
| 6652 | |
| 6653 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6654 | active_one = &(qos_network_data->parameters); |
| 6655 | qos_network_data->old_param_count = |
| 6656 | qos_network_data->param_count; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6657 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6658 | active = qos_network_data->supported; |
| 6659 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6660 | |
| 6661 | if (active == 0) { |
| 6662 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6663 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
| 6664 | qos_parameters[QOS_PARAM_SET_ACTIVE]. |
| 6665 | tx_op_limit[i] = (u16) burst_duration; |
| 6666 | } |
| 6667 | } |
| 6668 | |
| 6669 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6670 | err = ipw_send_qos_params_command(priv, |
| 6671 | (struct ieee80211_qos_parameters *) |
| 6672 | &(qos_parameters[0])); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6673 | if (err) |
| 6674 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); |
| 6675 | |
| 6676 | return err; |
| 6677 | } |
| 6678 | |
| 6679 | /* |
| 6680 | * send IPW_CMD_WME_INFO to the firmware |
| 6681 | */ |
| 6682 | static int ipw_qos_set_info_element(struct ipw_priv *priv) |
| 6683 | { |
| 6684 | int ret = 0; |
| 6685 | struct ieee80211_qos_information_element qos_info; |
| 6686 | |
| 6687 | if (priv == NULL) |
| 6688 | return -1; |
| 6689 | |
| 6690 | qos_info.elementID = QOS_ELEMENT_ID; |
| 6691 | qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2; |
| 6692 | |
| 6693 | qos_info.version = QOS_VERSION_1; |
| 6694 | qos_info.ac_info = 0; |
| 6695 | |
| 6696 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); |
| 6697 | qos_info.qui_type = QOS_OUI_TYPE; |
| 6698 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; |
| 6699 | |
| 6700 | ret = ipw_send_qos_info_command(priv, &qos_info); |
| 6701 | if (ret != 0) { |
| 6702 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); |
| 6703 | } |
| 6704 | return ret; |
| 6705 | } |
| 6706 | |
| 6707 | /* |
| 6708 | * Set the QoS parameter with the association request structure |
| 6709 | */ |
| 6710 | static int ipw_qos_association(struct ipw_priv *priv, |
| 6711 | struct ieee80211_network *network) |
| 6712 | { |
| 6713 | int err = 0; |
| 6714 | struct ieee80211_qos_data *qos_data = NULL; |
| 6715 | struct ieee80211_qos_data ibss_data = { |
| 6716 | .supported = 1, |
| 6717 | .active = 1, |
| 6718 | }; |
| 6719 | |
| 6720 | switch (priv->ieee->iw_mode) { |
| 6721 | case IW_MODE_ADHOC: |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 6722 | BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6723 | |
| 6724 | qos_data = &ibss_data; |
| 6725 | break; |
| 6726 | |
| 6727 | case IW_MODE_INFRA: |
| 6728 | qos_data = &network->qos_data; |
| 6729 | break; |
| 6730 | |
| 6731 | default: |
| 6732 | BUG(); |
| 6733 | break; |
| 6734 | } |
| 6735 | |
| 6736 | err = ipw_qos_activate(priv, qos_data); |
| 6737 | if (err) { |
| 6738 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; |
| 6739 | return err; |
| 6740 | } |
| 6741 | |
| 6742 | if (priv->qos_data.qos_enable && qos_data->supported) { |
| 6743 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); |
| 6744 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; |
| 6745 | return ipw_qos_set_info_element(priv); |
| 6746 | } |
| 6747 | |
| 6748 | return 0; |
| 6749 | } |
| 6750 | |
| 6751 | /* |
| 6752 | * handling the beaconing responces. if we get different QoS setting |
| 6753 | * of the network from the the associated setting adjust the QoS |
| 6754 | * setting |
| 6755 | */ |
| 6756 | static int ipw_qos_association_resp(struct ipw_priv *priv, |
| 6757 | struct ieee80211_network *network) |
| 6758 | { |
| 6759 | int ret = 0; |
| 6760 | unsigned long flags; |
| 6761 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6762 | int set_qos_param = 0; |
| 6763 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6764 | if ((priv == NULL) || (network == NULL) || |
| 6765 | (priv->assoc_network == NULL)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6766 | return ret; |
| 6767 | |
| 6768 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 6769 | return ret; |
| 6770 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6771 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6772 | return ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6773 | |
| 6774 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6775 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6776 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6777 | sizeof(struct ieee80211_qos_data)); |
| 6778 | priv->assoc_network->qos_data.active = 1; |
| 6779 | if ((network->qos_data.old_param_count != |
| 6780 | network->qos_data.param_count)) { |
| 6781 | set_qos_param = 1; |
| 6782 | network->qos_data.old_param_count = |
| 6783 | network->qos_data.param_count; |
| 6784 | } |
| 6785 | |
| 6786 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6787 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
| 6788 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6789 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6790 | else |
| 6791 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6792 | &def_parameters_OFDM, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6793 | priv->assoc_network->qos_data.active = 0; |
| 6794 | priv->assoc_network->qos_data.supported = 0; |
| 6795 | set_qos_param = 1; |
| 6796 | } |
| 6797 | |
| 6798 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6799 | |
| 6800 | if (set_qos_param == 1) |
| 6801 | schedule_work(&priv->qos_activate); |
| 6802 | |
| 6803 | return ret; |
| 6804 | } |
| 6805 | |
| 6806 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) |
| 6807 | { |
| 6808 | u32 ret = 0; |
| 6809 | |
| 6810 | if ((priv == NULL)) |
| 6811 | return 0; |
| 6812 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6813 | if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6814 | ret = priv->qos_data.burst_duration_CCK; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6815 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6816 | ret = priv->qos_data.burst_duration_OFDM; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6817 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6818 | return ret; |
| 6819 | } |
| 6820 | |
| 6821 | /* |
| 6822 | * Initialize the setting of QoS global |
| 6823 | */ |
| 6824 | static void ipw_qos_init(struct ipw_priv *priv, int enable, |
| 6825 | int burst_enable, u32 burst_duration_CCK, |
| 6826 | u32 burst_duration_OFDM) |
| 6827 | { |
| 6828 | priv->qos_data.qos_enable = enable; |
| 6829 | |
| 6830 | if (priv->qos_data.qos_enable) { |
| 6831 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; |
| 6832 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; |
| 6833 | IPW_DEBUG_QOS("QoS is enabled\n"); |
| 6834 | } else { |
| 6835 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; |
| 6836 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; |
| 6837 | IPW_DEBUG_QOS("QoS is not enabled\n"); |
| 6838 | } |
| 6839 | |
| 6840 | priv->qos_data.burst_enable = burst_enable; |
| 6841 | |
| 6842 | if (burst_enable) { |
| 6843 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; |
| 6844 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; |
| 6845 | } else { |
| 6846 | priv->qos_data.burst_duration_CCK = 0; |
| 6847 | priv->qos_data.burst_duration_OFDM = 0; |
| 6848 | } |
| 6849 | } |
| 6850 | |
| 6851 | /* |
| 6852 | * map the packet priority to the right TX Queue |
| 6853 | */ |
| 6854 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) |
| 6855 | { |
| 6856 | if (priority > 7 || !priv->qos_data.qos_enable) |
| 6857 | priority = 0; |
| 6858 | |
| 6859 | return from_priority_to_tx_queue[priority] - 1; |
| 6860 | } |
| 6861 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame^] | 6862 | static int ipw_is_qos_active(struct net_device *dev, |
| 6863 | struct sk_buff *skb) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6864 | { |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame^] | 6865 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6866 | struct ieee80211_qos_data *qos_data = NULL; |
| 6867 | int active, supported; |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame^] | 6868 | u8 *daddr = skb->data + ETH_ALEN; |
| 6869 | int unicast = !is_multicast_ether_addr(daddr); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6870 | |
| 6871 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 6872 | return 0; |
| 6873 | |
| 6874 | qos_data = &priv->assoc_network->qos_data; |
| 6875 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6876 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 6877 | if (unicast == 0) |
| 6878 | qos_data->active = 0; |
| 6879 | else |
| 6880 | qos_data->active = qos_data->supported; |
| 6881 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6882 | active = qos_data->active; |
| 6883 | supported = qos_data->supported; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6884 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
| 6885 | "unicast %d\n", |
| 6886 | priv->qos_data.qos_enable, active, supported, unicast); |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame^] | 6887 | if (active && priv->qos_data.qos_enable) |
| 6888 | return 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6889 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame^] | 6890 | return 0; |
| 6891 | |
| 6892 | } |
| 6893 | /* |
| 6894 | * add QoS parameter to the TX command |
| 6895 | */ |
| 6896 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, |
| 6897 | u16 priority, |
| 6898 | struct tfd_data *tfd) |
| 6899 | { |
| 6900 | int tx_queue_id = 0; |
| 6901 | |
| 6902 | |
| 6903 | tx_queue_id = from_priority_to_tx_queue[priority] - 1; |
| 6904 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; |
| 6905 | |
| 6906 | if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) { |
| 6907 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; |
| 6908 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6909 | } |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame^] | 6910 | return 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6911 | } |
| 6912 | |
| 6913 | /* |
| 6914 | * background support to run QoS activate functionality |
| 6915 | */ |
| 6916 | static void ipw_bg_qos_activate(void *data) |
| 6917 | { |
| 6918 | struct ipw_priv *priv = data; |
| 6919 | |
| 6920 | if (priv == NULL) |
| 6921 | return; |
| 6922 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6923 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6924 | |
| 6925 | if (priv->status & STATUS_ASSOCIATED) |
| 6926 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); |
| 6927 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6928 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6929 | } |
| 6930 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6931 | static int ipw_handle_probe_response(struct net_device *dev, |
| 6932 | struct ieee80211_probe_response *resp, |
| 6933 | struct ieee80211_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6934 | { |
| 6935 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6936 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 6937 | (network == priv->assoc_network)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6938 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6939 | ipw_qos_handle_probe_response(priv, active_network, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6940 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6941 | return 0; |
| 6942 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6943 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6944 | static int ipw_handle_beacon(struct net_device *dev, |
| 6945 | struct ieee80211_beacon *resp, |
| 6946 | struct ieee80211_network *network) |
| 6947 | { |
| 6948 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6949 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 6950 | (network == priv->assoc_network)); |
| 6951 | |
| 6952 | ipw_qos_handle_probe_response(priv, active_network, network); |
| 6953 | |
| 6954 | return 0; |
| 6955 | } |
| 6956 | |
| 6957 | static int ipw_handle_assoc_response(struct net_device *dev, |
| 6958 | struct ieee80211_assoc_response *resp, |
| 6959 | struct ieee80211_network *network) |
| 6960 | { |
| 6961 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6962 | ipw_qos_association_resp(priv, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6963 | return 0; |
| 6964 | } |
| 6965 | |
| 6966 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
| 6967 | *qos_param) |
| 6968 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 6969 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
| 6970 | sizeof(*qos_param) * 3, qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6971 | } |
| 6972 | |
| 6973 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element |
| 6974 | *qos_param) |
| 6975 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 6976 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
| 6977 | qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6978 | } |
| 6979 | |
| 6980 | #endif /* CONFIG_IPW_QOS */ |
| 6981 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6982 | static int ipw_associate_network(struct ipw_priv *priv, |
| 6983 | struct ieee80211_network *network, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6984 | struct ipw_supported_rates *rates, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6985 | { |
| 6986 | int err; |
| 6987 | |
| 6988 | if (priv->config & CFG_FIXED_RATE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6989 | ipw_set_fixed_rate(priv, network->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6990 | |
| 6991 | if (!(priv->config & CFG_STATIC_ESSID)) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 6992 | priv->essid_len = min(network->ssid_len, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 6993 | (u8) IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 6994 | memcpy(priv->essid, network->ssid, priv->essid_len); |
| 6995 | } |
| 6996 | |
| 6997 | network->last_associate = jiffies; |
| 6998 | |
| 6999 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); |
| 7000 | priv->assoc_request.channel = network->channel; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7001 | priv->assoc_request.auth_key = 0; |
| 7002 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7003 | if ((priv->capability & CAP_PRIVACY_ON) && |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7004 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7005 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7006 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
| 7007 | |
Zhu Yi | 1ba61e0 | 2006-02-15 13:00:55 +0800 | [diff] [blame] | 7008 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7009 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7010 | |
| 7011 | } else if ((priv->capability & CAP_PRIVACY_ON) && |
| 7012 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) |
| 7013 | priv->assoc_request.auth_type = AUTH_LEAP; |
| 7014 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7015 | priv->assoc_request.auth_type = AUTH_OPEN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7016 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7017 | if (priv->ieee->wpa_ie_len) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7018 | priv->assoc_request.policy_support = 0x02; /* RSN active */ |
| 7019 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
| 7020 | priv->ieee->wpa_ie_len); |
| 7021 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7022 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7023 | /* |
| 7024 | * It is valid for our ieee device to support multiple modes, but |
| 7025 | * 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] | 7026 | * just one mode. |
| 7027 | */ |
| 7028 | if (network->mode & priv->ieee->mode & IEEE_A) |
| 7029 | priv->assoc_request.ieee_mode = IPW_A_MODE; |
| 7030 | else if (network->mode & priv->ieee->mode & IEEE_G) |
| 7031 | priv->assoc_request.ieee_mode = IPW_G_MODE; |
| 7032 | else if (network->mode & priv->ieee->mode & IEEE_B) |
| 7033 | priv->assoc_request.ieee_mode = IPW_B_MODE; |
| 7034 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7035 | priv->assoc_request.capability = network->capability; |
| 7036 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7037 | && !(priv->config & CFG_PREAMBLE_LONG)) { |
| 7038 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; |
| 7039 | } else { |
| 7040 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; |
| 7041 | |
| 7042 | /* Clear the short preamble if we won't be supporting it */ |
| 7043 | priv->assoc_request.capability &= |
| 7044 | ~WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 7045 | } |
| 7046 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7047 | /* Clear capability bits that aren't used in Ad Hoc */ |
| 7048 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7049 | priv->assoc_request.capability &= |
| 7050 | ~WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 7051 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7052 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7053 | "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] | 7054 | roaming ? "Rea" : "A", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7055 | escape_essid(priv->essid, priv->essid_len), |
| 7056 | network->channel, |
| 7057 | ipw_modes[priv->assoc_request.ieee_mode], |
| 7058 | rates->num_rates, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7059 | (priv->assoc_request.preamble_length == |
| 7060 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", |
| 7061 | network->capability & |
| 7062 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7063 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7064 | priv->capability & CAP_PRIVACY_ON ? |
| 7065 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7066 | "(open)") : "", |
| 7067 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7068 | priv->capability & CAP_PRIVACY_ON ? |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7069 | '1' + priv->ieee->sec.active_key : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7070 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7071 | |
| 7072 | priv->assoc_request.beacon_interval = network->beacon_interval; |
| 7073 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7074 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7075 | priv->assoc_request.assoc_type = HC_IBSS_START; |
| 7076 | priv->assoc_request.assoc_tsf_msw = 0; |
| 7077 | priv->assoc_request.assoc_tsf_lsw = 0; |
| 7078 | } else { |
| 7079 | if (unlikely(roaming)) |
| 7080 | priv->assoc_request.assoc_type = HC_REASSOCIATE; |
| 7081 | else |
| 7082 | priv->assoc_request.assoc_type = HC_ASSOCIATE; |
| 7083 | priv->assoc_request.assoc_tsf_msw = network->time_stamp[1]; |
| 7084 | priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0]; |
| 7085 | } |
| 7086 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7087 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7088 | |
| 7089 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7090 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); |
| 7091 | priv->assoc_request.atim_window = network->atim_window; |
| 7092 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7093 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7094 | priv->assoc_request.atim_window = 0; |
| 7095 | } |
| 7096 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7097 | priv->assoc_request.listen_interval = network->listen_interval; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7098 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7099 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 7100 | if (err) { |
| 7101 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); |
| 7102 | return err; |
| 7103 | } |
| 7104 | |
| 7105 | rates->ieee_mode = priv->assoc_request.ieee_mode; |
| 7106 | rates->purpose = IPW_RATE_CONNECT; |
| 7107 | ipw_send_supported_rates(priv, rates); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7108 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7109 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
| 7110 | priv->sys_config.dot11g_auto_detection = 1; |
| 7111 | else |
| 7112 | priv->sys_config.dot11g_auto_detection = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7113 | |
| 7114 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7115 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 7116 | else |
| 7117 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 7118 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7119 | err = ipw_send_system_config(priv, &priv->sys_config); |
| 7120 | if (err) { |
| 7121 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); |
| 7122 | return err; |
| 7123 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7124 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7125 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7126 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7127 | if (err) { |
| 7128 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7129 | return err; |
| 7130 | } |
| 7131 | |
| 7132 | /* |
| 7133 | * If preemption is enabled, it is possible for the association |
| 7134 | * to complete before we return from ipw_send_associate. Therefore |
| 7135 | * we have to be sure and update our priviate data first. |
| 7136 | */ |
| 7137 | priv->channel = network->channel; |
| 7138 | memcpy(priv->bssid, network->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7139 | priv->status |= STATUS_ASSOCIATING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7140 | priv->status &= ~STATUS_SECURITY_UPDATED; |
| 7141 | |
| 7142 | priv->assoc_network = network; |
| 7143 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7144 | #ifdef CONFIG_IPW_QOS |
| 7145 | ipw_qos_association(priv, network); |
| 7146 | #endif |
| 7147 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7148 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 7149 | if (err) { |
| 7150 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7151 | return err; |
| 7152 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7153 | |
| 7154 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7155 | escape_essid(priv->essid, priv->essid_len), |
| 7156 | MAC_ARG(priv->bssid)); |
| 7157 | |
| 7158 | return 0; |
| 7159 | } |
| 7160 | |
| 7161 | static void ipw_roam(void *data) |
| 7162 | { |
| 7163 | struct ipw_priv *priv = data; |
| 7164 | struct ieee80211_network *network = NULL; |
| 7165 | struct ipw_network_match match = { |
| 7166 | .network = priv->assoc_network |
| 7167 | }; |
| 7168 | |
| 7169 | /* The roaming process is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7170 | * |
| 7171 | * 1. Missed beacon threshold triggers the roaming process by |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7172 | * setting the status ROAM bit and requesting a scan. |
| 7173 | * 2. When the scan completes, it schedules the ROAM work |
| 7174 | * 3. The ROAM work looks at all of the known networks for one that |
| 7175 | * is a better network than the currently associated. If none |
| 7176 | * found, the ROAM process is over (ROAM bit cleared) |
| 7177 | * 4. If a better network is found, a disassociation request is |
| 7178 | * sent. |
| 7179 | * 5. When the disassociation completes, the roam work is again |
| 7180 | * scheduled. The second time through, the driver is no longer |
| 7181 | * associated, and the newly selected network is sent an |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7182 | * association request. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7183 | * 6. At this point ,the roaming process is complete and the ROAM |
| 7184 | * status bit is cleared. |
| 7185 | */ |
| 7186 | |
| 7187 | /* If we are no longer associated, and the roaming bit is no longer |
| 7188 | * set, then we are not actively roaming, so just return */ |
| 7189 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) |
| 7190 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7191 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7192 | if (priv->status & STATUS_ASSOCIATED) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7193 | /* First pass through ROAM process -- look for a better |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7194 | * network */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7195 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7196 | u8 rssi = priv->assoc_network->stats.rssi; |
| 7197 | priv->assoc_network->stats.rssi = -128; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7198 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7199 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 7200 | if (network != priv->assoc_network) |
| 7201 | ipw_best_network(priv, &match, network, 1); |
| 7202 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7203 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7204 | priv->assoc_network->stats.rssi = rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7205 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7206 | if (match.network == priv->assoc_network) { |
| 7207 | IPW_DEBUG_ASSOC("No better APs in this network to " |
| 7208 | "roam to.\n"); |
| 7209 | priv->status &= ~STATUS_ROAMING; |
| 7210 | ipw_debug_config(priv); |
| 7211 | return; |
| 7212 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7213 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7214 | ipw_send_disassociate(priv, 1); |
| 7215 | priv->assoc_network = match.network; |
| 7216 | |
| 7217 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7218 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7219 | |
| 7220 | /* Second pass through ROAM process -- request association */ |
| 7221 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); |
| 7222 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); |
| 7223 | priv->status &= ~STATUS_ROAMING; |
| 7224 | } |
| 7225 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7226 | static void ipw_bg_roam(void *data) |
| 7227 | { |
| 7228 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7229 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7230 | ipw_roam(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7231 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7232 | } |
| 7233 | |
| 7234 | static int ipw_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7235 | { |
| 7236 | struct ipw_priv *priv = data; |
| 7237 | |
| 7238 | struct ieee80211_network *network = NULL; |
| 7239 | struct ipw_network_match match = { |
| 7240 | .network = NULL |
| 7241 | }; |
| 7242 | struct ipw_supported_rates *rates; |
| 7243 | struct list_head *element; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7244 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7245 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7246 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 7247 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); |
| 7248 | return 0; |
| 7249 | } |
| 7250 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7251 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7252 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
| 7253 | "progress)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7254 | return 0; |
| 7255 | } |
| 7256 | |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 7257 | if (priv->status & STATUS_DISASSOCIATING) { |
| 7258 | IPW_DEBUG_ASSOC("Not attempting association (in " |
| 7259 | "disassociating)\n "); |
| 7260 | queue_work(priv->workqueue, &priv->associate); |
| 7261 | return 0; |
| 7262 | } |
| 7263 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7264 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7265 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
| 7266 | "initialized)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7267 | return 0; |
| 7268 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7269 | |
| 7270 | if (!(priv->config & CFG_ASSOCIATE) && |
| 7271 | !(priv->config & (CFG_STATIC_ESSID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7272 | CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7273 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7274 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7275 | } |
| 7276 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7277 | /* Protect our use of the network_list */ |
| 7278 | spin_lock_irqsave(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7279 | list_for_each_entry(network, &priv->ieee->network_list, list) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7280 | ipw_best_network(priv, &match, network, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7281 | |
| 7282 | network = match.network; |
| 7283 | rates = &match.rates; |
| 7284 | |
| 7285 | if (network == NULL && |
| 7286 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7287 | priv->config & CFG_ADHOC_CREATE && |
| 7288 | priv->config & CFG_STATIC_ESSID && |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7289 | priv->config & CFG_STATIC_CHANNEL && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7290 | !list_empty(&priv->ieee->network_free_list)) { |
| 7291 | element = priv->ieee->network_free_list.next; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7292 | network = list_entry(element, struct ieee80211_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7293 | ipw_adhoc_create(priv, network); |
| 7294 | rates = &priv->rates; |
| 7295 | list_del(element); |
| 7296 | list_add_tail(&network->list, &priv->ieee->network_list); |
| 7297 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7298 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7299 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7300 | /* If we reached the end of the list, then we don't have any valid |
| 7301 | * matching APs */ |
| 7302 | if (!network) { |
| 7303 | ipw_debug_config(priv); |
| 7304 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7305 | if (!(priv->status & STATUS_SCANNING)) { |
| 7306 | if (!(priv->config & CFG_SPEED_SCAN)) |
| 7307 | queue_delayed_work(priv->workqueue, |
| 7308 | &priv->request_scan, |
| 7309 | SCAN_INTERVAL); |
| 7310 | else |
| 7311 | queue_work(priv->workqueue, |
| 7312 | &priv->request_scan); |
| 7313 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7314 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7315 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7316 | } |
| 7317 | |
| 7318 | ipw_associate_network(priv, network, rates, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7319 | |
| 7320 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7321 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7322 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7323 | static void ipw_bg_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7324 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7325 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7326 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7327 | ipw_associate(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7328 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7329 | } |
| 7330 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7331 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
| 7332 | struct sk_buff *skb) |
| 7333 | { |
| 7334 | struct ieee80211_hdr *hdr; |
| 7335 | u16 fc; |
| 7336 | |
| 7337 | hdr = (struct ieee80211_hdr *)skb->data; |
| 7338 | fc = le16_to_cpu(hdr->frame_ctl); |
| 7339 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 7340 | return; |
| 7341 | |
| 7342 | fc &= ~IEEE80211_FCTL_PROTECTED; |
| 7343 | hdr->frame_ctl = cpu_to_le16(fc); |
| 7344 | switch (priv->ieee->sec.level) { |
| 7345 | case SEC_LEVEL_3: |
| 7346 | /* Remove CCMP HDR */ |
| 7347 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7348 | skb->data + IEEE80211_3ADDR_LEN + 8, |
| 7349 | skb->len - IEEE80211_3ADDR_LEN - 8); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7350 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7351 | break; |
| 7352 | case SEC_LEVEL_2: |
| 7353 | break; |
| 7354 | case SEC_LEVEL_1: |
| 7355 | /* Remove IV */ |
| 7356 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7357 | skb->data + IEEE80211_3ADDR_LEN + 4, |
| 7358 | skb->len - IEEE80211_3ADDR_LEN - 4); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7359 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7360 | break; |
| 7361 | case SEC_LEVEL_0: |
| 7362 | break; |
| 7363 | default: |
| 7364 | printk(KERN_ERR "Unknow security level %d\n", |
| 7365 | priv->ieee->sec.level); |
| 7366 | break; |
| 7367 | } |
| 7368 | } |
| 7369 | |
| 7370 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
| 7371 | struct ipw_rx_mem_buffer *rxb, |
| 7372 | struct ieee80211_rx_stats *stats) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7373 | { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7374 | struct ieee80211_hdr_4addr *hdr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7375 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7376 | |
| 7377 | /* We received data from the HW, so stop the watchdog */ |
| 7378 | priv->net_dev->trans_start = jiffies; |
| 7379 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7380 | /* We only process data packets if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7381 | * interface is open */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7382 | 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] | 7383 | skb_tailroom(rxb->skb))) { |
| 7384 | priv->ieee->stats.rx_errors++; |
| 7385 | priv->wstats.discard.misc++; |
| 7386 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7387 | return; |
| 7388 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7389 | priv->ieee->stats.rx_dropped++; |
| 7390 | priv->wstats.discard.misc++; |
| 7391 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7392 | return; |
| 7393 | } |
| 7394 | |
| 7395 | /* Advance skb->data to the start of the actual payload */ |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 7396 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7397 | |
| 7398 | /* Set the size of the skb to the size of the frame */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7399 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7400 | |
| 7401 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7402 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7403 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7404 | hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data; |
| 7405 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7406 | (is_multicast_ether_addr(hdr->addr1) ? |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7407 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7408 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
| 7409 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7410 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7411 | priv->ieee->stats.rx_errors++; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7412 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7413 | rxb->skb = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7414 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7415 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7416 | } |
| 7417 | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7418 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 7419 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, |
| 7420 | struct ipw_rx_mem_buffer *rxb, |
| 7421 | struct ieee80211_rx_stats *stats) |
| 7422 | { |
| 7423 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7424 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7425 | |
| 7426 | /* initial pull of some data */ |
| 7427 | u16 received_channel = frame->received_channel; |
| 7428 | u8 antennaAndPhy = frame->antennaAndPhy; |
| 7429 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ |
| 7430 | u16 pktrate = frame->rate; |
| 7431 | |
| 7432 | /* Magic struct that slots into the radiotap header -- no reason |
| 7433 | * to build this manually element by element, we can write it much |
| 7434 | * more efficiently than we can parse it. ORDER MATTERS HERE */ |
| 7435 | struct ipw_rt_hdr { |
| 7436 | struct ieee80211_radiotap_header rt_hdr; |
| 7437 | u8 rt_flags; /* radiotap packet flags */ |
| 7438 | u8 rt_rate; /* rate in 500kb/s */ |
| 7439 | u16 rt_channel; /* channel in mhz */ |
| 7440 | u16 rt_chbitmask; /* channel bitfield */ |
| 7441 | s8 rt_dbmsignal; /* signal in dbM, kluged to signed */ |
| 7442 | u8 rt_antenna; /* antenna number */ |
| 7443 | } *ipw_rt; |
| 7444 | |
| 7445 | short len = le16_to_cpu(pkt->u.frame.length); |
| 7446 | |
| 7447 | /* We received data from the HW, so stop the watchdog */ |
| 7448 | priv->net_dev->trans_start = jiffies; |
| 7449 | |
| 7450 | /* We only process data packets if the |
| 7451 | * interface is open */ |
| 7452 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
| 7453 | skb_tailroom(rxb->skb))) { |
| 7454 | priv->ieee->stats.rx_errors++; |
| 7455 | priv->wstats.discard.misc++; |
| 7456 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7457 | return; |
| 7458 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7459 | priv->ieee->stats.rx_dropped++; |
| 7460 | priv->wstats.discard.misc++; |
| 7461 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7462 | return; |
| 7463 | } |
| 7464 | |
| 7465 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7466 | * that now */ |
| 7467 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7468 | /* FIXME: Should alloc bigger skb instead */ |
| 7469 | priv->ieee->stats.rx_dropped++; |
| 7470 | priv->wstats.discard.misc++; |
| 7471 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7472 | return; |
| 7473 | } |
| 7474 | |
| 7475 | /* copy the frame itself */ |
| 7476 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), |
| 7477 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); |
| 7478 | |
| 7479 | /* Zero the radiotap static buffer ... We only need to zero the bytes NOT |
| 7480 | * part of our real header, saves a little time. |
| 7481 | * |
| 7482 | * No longer necessary since we fill in all our data. Purge before merging |
| 7483 | * patch officially. |
| 7484 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, |
| 7485 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); |
| 7486 | */ |
| 7487 | |
| 7488 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; |
| 7489 | |
| 7490 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7491 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
| 7492 | ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */ |
| 7493 | |
| 7494 | /* Big bitfield of all the fields we provide in radiotap */ |
| 7495 | ipw_rt->rt_hdr.it_present = |
| 7496 | ((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 7497 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7498 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7499 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 7500 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7501 | |
| 7502 | /* Zero the flags, we'll add to them as we go */ |
| 7503 | ipw_rt->rt_flags = 0; |
| 7504 | |
| 7505 | /* Convert signal to DBM */ |
| 7506 | ipw_rt->rt_dbmsignal = antsignal; |
| 7507 | |
| 7508 | /* Convert the channel data and set the flags */ |
| 7509 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); |
| 7510 | if (received_channel > 14) { /* 802.11a */ |
| 7511 | ipw_rt->rt_chbitmask = |
| 7512 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7513 | } else if (antennaAndPhy & 32) { /* 802.11b */ |
| 7514 | ipw_rt->rt_chbitmask = |
| 7515 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7516 | } else { /* 802.11g */ |
| 7517 | ipw_rt->rt_chbitmask = |
| 7518 | (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
| 7519 | } |
| 7520 | |
| 7521 | /* set the rate in multiples of 500k/s */ |
| 7522 | switch (pktrate) { |
| 7523 | case IPW_TX_RATE_1MB: |
| 7524 | ipw_rt->rt_rate = 2; |
| 7525 | break; |
| 7526 | case IPW_TX_RATE_2MB: |
| 7527 | ipw_rt->rt_rate = 4; |
| 7528 | break; |
| 7529 | case IPW_TX_RATE_5MB: |
| 7530 | ipw_rt->rt_rate = 10; |
| 7531 | break; |
| 7532 | case IPW_TX_RATE_6MB: |
| 7533 | ipw_rt->rt_rate = 12; |
| 7534 | break; |
| 7535 | case IPW_TX_RATE_9MB: |
| 7536 | ipw_rt->rt_rate = 18; |
| 7537 | break; |
| 7538 | case IPW_TX_RATE_11MB: |
| 7539 | ipw_rt->rt_rate = 22; |
| 7540 | break; |
| 7541 | case IPW_TX_RATE_12MB: |
| 7542 | ipw_rt->rt_rate = 24; |
| 7543 | break; |
| 7544 | case IPW_TX_RATE_18MB: |
| 7545 | ipw_rt->rt_rate = 36; |
| 7546 | break; |
| 7547 | case IPW_TX_RATE_24MB: |
| 7548 | ipw_rt->rt_rate = 48; |
| 7549 | break; |
| 7550 | case IPW_TX_RATE_36MB: |
| 7551 | ipw_rt->rt_rate = 72; |
| 7552 | break; |
| 7553 | case IPW_TX_RATE_48MB: |
| 7554 | ipw_rt->rt_rate = 96; |
| 7555 | break; |
| 7556 | case IPW_TX_RATE_54MB: |
| 7557 | ipw_rt->rt_rate = 108; |
| 7558 | break; |
| 7559 | default: |
| 7560 | ipw_rt->rt_rate = 0; |
| 7561 | break; |
| 7562 | } |
| 7563 | |
| 7564 | /* antenna number */ |
| 7565 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ |
| 7566 | |
| 7567 | /* set the preamble flag if we have it */ |
| 7568 | if ((antennaAndPhy & 64)) |
| 7569 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7570 | |
| 7571 | /* Set the size of the skb to the size of the frame */ |
| 7572 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7573 | |
| 7574 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7575 | |
| 7576 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
| 7577 | priv->ieee->stats.rx_errors++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7578 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7579 | rxb->skb = NULL; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7580 | /* no LED during capture */ |
| 7581 | } |
| 7582 | } |
| 7583 | #endif |
| 7584 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 7585 | static int is_network_packet(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7586 | struct ieee80211_hdr_4addr *header) |
| 7587 | { |
| 7588 | /* Filter incoming packets to determine if they are targetted toward |
| 7589 | * this network, discarding packets coming from ourselves */ |
| 7590 | switch (priv->ieee->iw_mode) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7591 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7592 | /* packets from our adapter are dropped (echo) */ |
| 7593 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7594 | return 0; |
| 7595 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7596 | /* {broad,multi}cast packets to our BSSID go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7597 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7598 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7599 | |
| 7600 | /* packets to our adapter go through */ |
| 7601 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7602 | ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7603 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7604 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7605 | /* packets from our adapter are dropped (echo) */ |
| 7606 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7607 | return 0; |
| 7608 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7609 | /* {broad,multi}cast packets to our BSS go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7610 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7611 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
| 7612 | |
| 7613 | /* packets to our adapter go through */ |
| 7614 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7615 | ETH_ALEN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7616 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7617 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7618 | return 1; |
| 7619 | } |
| 7620 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7621 | #define IPW_PACKET_RETRY_TIME HZ |
| 7622 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 7623 | static int is_duplicate_packet(struct ipw_priv *priv, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7624 | struct ieee80211_hdr_4addr *header) |
| 7625 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7626 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 7627 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 7628 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 7629 | u16 *last_seq, *last_frag; |
| 7630 | unsigned long *last_time; |
| 7631 | |
| 7632 | switch (priv->ieee->iw_mode) { |
| 7633 | case IW_MODE_ADHOC: |
| 7634 | { |
| 7635 | struct list_head *p; |
| 7636 | struct ipw_ibss_seq *entry = NULL; |
| 7637 | u8 *mac = header->addr2; |
| 7638 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; |
| 7639 | |
| 7640 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 7641 | entry = |
| 7642 | list_entry(p, struct ipw_ibss_seq, list); |
| 7643 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 7644 | break; |
| 7645 | } |
| 7646 | if (p == &priv->ibss_mac_hash[index]) { |
| 7647 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 7648 | if (!entry) { |
| 7649 | IPW_ERROR |
| 7650 | ("Cannot malloc new mac entry\n"); |
| 7651 | return 0; |
| 7652 | } |
| 7653 | memcpy(entry->mac, mac, ETH_ALEN); |
| 7654 | entry->seq_num = seq; |
| 7655 | entry->frag_num = frag; |
| 7656 | entry->packet_time = jiffies; |
| 7657 | list_add(&entry->list, |
| 7658 | &priv->ibss_mac_hash[index]); |
| 7659 | return 0; |
| 7660 | } |
| 7661 | last_seq = &entry->seq_num; |
| 7662 | last_frag = &entry->frag_num; |
| 7663 | last_time = &entry->packet_time; |
| 7664 | break; |
| 7665 | } |
| 7666 | case IW_MODE_INFRA: |
| 7667 | last_seq = &priv->last_seq_num; |
| 7668 | last_frag = &priv->last_frag_num; |
| 7669 | last_time = &priv->last_packet_time; |
| 7670 | break; |
| 7671 | default: |
| 7672 | return 0; |
| 7673 | } |
| 7674 | if ((*last_seq == seq) && |
| 7675 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { |
| 7676 | if (*last_frag == frag) |
| 7677 | goto drop; |
| 7678 | if (*last_frag + 1 != frag) |
| 7679 | /* out-of-order fragment */ |
| 7680 | goto drop; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7681 | } else |
| 7682 | *last_seq = seq; |
| 7683 | |
Zhu Yi | f57ce7c | 2005-07-13 12:22:15 -0500 | [diff] [blame] | 7684 | *last_frag = frag; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7685 | *last_time = jiffies; |
| 7686 | return 0; |
| 7687 | |
| 7688 | drop: |
Zhu Yi | 87b016c | 2005-08-05 17:17:35 +0800 | [diff] [blame] | 7689 | /* Comment this line now since we observed the card receives |
| 7690 | * duplicate packets but the FCTL_RETRY bit is not set in the |
| 7691 | * IBSS mode with fragmentation enabled. |
| 7692 | BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7693 | return 1; |
| 7694 | } |
| 7695 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7696 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
| 7697 | struct ipw_rx_mem_buffer *rxb, |
| 7698 | struct ieee80211_rx_stats *stats) |
| 7699 | { |
| 7700 | struct sk_buff *skb = rxb->skb; |
| 7701 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; |
| 7702 | struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *) |
| 7703 | (skb->data + IPW_RX_FRAME_SIZE); |
| 7704 | |
| 7705 | ieee80211_rx_mgt(priv->ieee, header, stats); |
| 7706 | |
| 7707 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7708 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 7709 | IEEE80211_STYPE_PROBE_RESP) || |
| 7710 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 7711 | IEEE80211_STYPE_BEACON))) { |
| 7712 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) |
| 7713 | ipw_add_station(priv, header->addr2); |
| 7714 | } |
| 7715 | |
| 7716 | if (priv->config & CFG_NET_STATS) { |
| 7717 | IPW_DEBUG_HC("sending stat packet\n"); |
| 7718 | |
| 7719 | /* Set the size of the skb to the size of the full |
| 7720 | * ipw header and 802.11 frame */ |
| 7721 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + |
| 7722 | IPW_RX_FRAME_SIZE); |
| 7723 | |
| 7724 | /* Advance past the ipw packet header to the 802.11 frame */ |
| 7725 | skb_pull(skb, IPW_RX_FRAME_SIZE); |
| 7726 | |
| 7727 | /* Push the ieee80211_rx_stats before the 802.11 frame */ |
| 7728 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
| 7729 | |
| 7730 | skb->dev = priv->ieee->dev; |
| 7731 | |
| 7732 | /* Point raw at the ieee80211_stats */ |
| 7733 | skb->mac.raw = skb->data; |
| 7734 | |
| 7735 | skb->pkt_type = PACKET_OTHERHOST; |
| 7736 | skb->protocol = __constant_htons(ETH_P_80211_STATS); |
| 7737 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
| 7738 | netif_rx(skb); |
| 7739 | rxb->skb = NULL; |
| 7740 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7741 | } |
| 7742 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7743 | /* |
| 7744 | * Main entry function for recieving a packet with 80211 headers. This |
| 7745 | * should be called when ever the FW has notified us that there is a new |
| 7746 | * skb in the recieve queue. |
| 7747 | */ |
| 7748 | static void ipw_rx(struct ipw_priv *priv) |
| 7749 | { |
| 7750 | struct ipw_rx_mem_buffer *rxb; |
| 7751 | struct ipw_rx_packet *pkt; |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 7752 | struct ieee80211_hdr_4addr *header; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7753 | u32 r, w, i; |
| 7754 | u8 network_packet; |
| 7755 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7756 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
| 7757 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7758 | i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE; |
| 7759 | |
| 7760 | while (i != r) { |
| 7761 | rxb = priv->rxq->queue[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7762 | if (unlikely(rxb == NULL)) { |
| 7763 | printk(KERN_CRIT "Queue not allocated!\n"); |
| 7764 | break; |
| 7765 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7766 | priv->rxq->queue[i] = NULL; |
| 7767 | |
| 7768 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7769 | IPW_RX_BUF_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7770 | PCI_DMA_FROMDEVICE); |
| 7771 | |
| 7772 | pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7773 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", |
| 7774 | pkt->header.message_type, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7775 | pkt->header.rx_seq_num, pkt->header.control_bits); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7776 | |
| 7777 | switch (pkt->header.message_type) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7778 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
| 7779 | struct ieee80211_rx_stats stats = { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7780 | .rssi = |
| 7781 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7782 | IPW_RSSI_TO_DBM, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7783 | .signal = |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 7784 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
| 7785 | IPW_RSSI_TO_DBM + 0x100, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7786 | .noise = |
| 7787 | le16_to_cpu(pkt->u.frame.noise), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7788 | .rate = pkt->u.frame.rate, |
| 7789 | .mac_time = jiffies, |
| 7790 | .received_channel = |
| 7791 | pkt->u.frame.received_channel, |
| 7792 | .freq = |
| 7793 | (pkt->u.frame. |
| 7794 | control & (1 << 0)) ? |
| 7795 | IEEE80211_24GHZ_BAND : |
| 7796 | IEEE80211_52GHZ_BAND, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7797 | .len = le16_to_cpu(pkt->u.frame.length), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7798 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7799 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7800 | if (stats.rssi != 0) |
| 7801 | stats.mask |= IEEE80211_STATMASK_RSSI; |
| 7802 | if (stats.signal != 0) |
| 7803 | stats.mask |= IEEE80211_STATMASK_SIGNAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7804 | if (stats.noise != 0) |
| 7805 | stats.mask |= IEEE80211_STATMASK_NOISE; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7806 | if (stats.rate != 0) |
| 7807 | stats.mask |= IEEE80211_STATMASK_RATE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7808 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7809 | priv->rx_packets++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7810 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7811 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7812 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7813 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 7814 | ipw_handle_data_packet_monitor(priv, |
| 7815 | rxb, |
| 7816 | &stats); |
| 7817 | #else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7818 | ipw_handle_data_packet(priv, rxb, |
| 7819 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7820 | #endif |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7821 | break; |
| 7822 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7823 | #endif |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7824 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7825 | header = |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 7826 | (struct ieee80211_hdr_4addr *)(rxb->skb-> |
| 7827 | data + |
| 7828 | IPW_RX_FRAME_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7829 | /* TODO: Check Ad-Hoc dest/source and make sure |
| 7830 | * that we are actually parsing these packets |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7831 | * correctly -- we should probably use the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7832 | * frame control of the packet and disregard |
| 7833 | * the current iw_mode */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7834 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7835 | network_packet = |
| 7836 | is_network_packet(priv, header); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7837 | if (network_packet && priv->assoc_network) { |
| 7838 | priv->assoc_network->stats.rssi = |
| 7839 | stats.rssi; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 7840 | priv->exp_avg_rssi = |
| 7841 | exponential_average(priv->exp_avg_rssi, |
| 7842 | stats.rssi, DEPTH_RSSI); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7843 | } |
| 7844 | |
| 7845 | IPW_DEBUG_RX("Frame: len=%u\n", |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7846 | le16_to_cpu(pkt->u.frame.length)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7847 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7848 | if (le16_to_cpu(pkt->u.frame.length) < |
Zhu Yi | 9d0be03 | 2006-02-15 06:18:19 +0800 | [diff] [blame] | 7849 | ieee80211_get_hdrlen(le16_to_cpu( |
| 7850 | header->frame_ctl))) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7851 | IPW_DEBUG_DROP |
| 7852 | ("Received packet is too small. " |
| 7853 | "Dropping.\n"); |
| 7854 | priv->ieee->stats.rx_errors++; |
| 7855 | priv->wstats.discard.misc++; |
| 7856 | break; |
| 7857 | } |
| 7858 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7859 | switch (WLAN_FC_GET_TYPE |
| 7860 | (le16_to_cpu(header->frame_ctl))) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7861 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7862 | case IEEE80211_FTYPE_MGMT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7863 | ipw_handle_mgmt_packet(priv, rxb, |
| 7864 | &stats); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7865 | break; |
| 7866 | |
| 7867 | case IEEE80211_FTYPE_CTL: |
| 7868 | break; |
| 7869 | |
| 7870 | case IEEE80211_FTYPE_DATA: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7871 | if (unlikely(!network_packet || |
| 7872 | is_duplicate_packet(priv, |
| 7873 | header))) |
| 7874 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7875 | IPW_DEBUG_DROP("Dropping: " |
| 7876 | MAC_FMT ", " |
| 7877 | MAC_FMT ", " |
| 7878 | MAC_FMT "\n", |
| 7879 | MAC_ARG(header-> |
| 7880 | addr1), |
| 7881 | MAC_ARG(header-> |
| 7882 | addr2), |
| 7883 | MAC_ARG(header-> |
| 7884 | addr3)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7885 | break; |
| 7886 | } |
| 7887 | |
| 7888 | ipw_handle_data_packet(priv, rxb, |
| 7889 | &stats); |
| 7890 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7891 | break; |
| 7892 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7893 | break; |
| 7894 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7895 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7896 | case RX_HOST_NOTIFICATION_TYPE:{ |
| 7897 | IPW_DEBUG_RX |
| 7898 | ("Notification: subtype=%02X flags=%02X size=%d\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7899 | pkt->u.notification.subtype, |
| 7900 | pkt->u.notification.flags, |
| 7901 | pkt->u.notification.size); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7902 | ipw_rx_notification(priv, &pkt->u.notification); |
| 7903 | break; |
| 7904 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7905 | |
| 7906 | default: |
| 7907 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", |
| 7908 | pkt->header.message_type); |
| 7909 | break; |
| 7910 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7911 | |
| 7912 | /* For now we just don't re-use anything. We can tweak this |
| 7913 | * later to try and re-use notification packets and SKBs that |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7914 | * fail to Rx correctly */ |
| 7915 | if (rxb->skb != NULL) { |
| 7916 | dev_kfree_skb_any(rxb->skb); |
| 7917 | rxb->skb = NULL; |
| 7918 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7919 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7920 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7921 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7922 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7923 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7924 | i = (i + 1) % RX_QUEUE_SIZE; |
| 7925 | } |
| 7926 | |
| 7927 | /* Backtrack one entry */ |
| 7928 | priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1; |
| 7929 | |
| 7930 | ipw_rx_queue_restock(priv); |
| 7931 | } |
| 7932 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7933 | #define DEFAULT_RTS_THRESHOLD 2304U |
| 7934 | #define MIN_RTS_THRESHOLD 1U |
| 7935 | #define MAX_RTS_THRESHOLD 2304U |
| 7936 | #define DEFAULT_BEACON_INTERVAL 100U |
| 7937 | #define DEFAULT_SHORT_RETRY_LIMIT 7U |
| 7938 | #define DEFAULT_LONG_RETRY_LIMIT 4U |
| 7939 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 7940 | /** |
| 7941 | * ipw_sw_reset |
| 7942 | * @option: options to control different reset behaviour |
| 7943 | * 0 = reset everything except the 'disable' module_param |
| 7944 | * 1 = reset everything and print out driver info (for probe only) |
| 7945 | * 2 = reset everything |
| 7946 | */ |
| 7947 | static int ipw_sw_reset(struct ipw_priv *priv, int option) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7948 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7949 | int band, modulation; |
| 7950 | int old_mode = priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7951 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7952 | /* Initialize module parameter values here */ |
| 7953 | priv->config = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7954 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7955 | /* We default to disabling the LED code as right now it causes |
| 7956 | * too many systems to lock up... */ |
| 7957 | if (!led) |
| 7958 | priv->config |= CFG_NO_LED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7959 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7960 | if (associate) |
| 7961 | priv->config |= CFG_ASSOCIATE; |
| 7962 | else |
| 7963 | IPW_DEBUG_INFO("Auto associate disabled.\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7964 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7965 | if (auto_create) |
| 7966 | priv->config |= CFG_ADHOC_CREATE; |
| 7967 | else |
| 7968 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); |
| 7969 | |
Zhu Yi | 17ed081 | 2006-01-24 16:36:31 +0800 | [diff] [blame] | 7970 | priv->config &= ~CFG_STATIC_ESSID; |
| 7971 | priv->essid_len = 0; |
| 7972 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7973 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 7974 | if (disable && option) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7975 | priv->status |= STATUS_RF_KILL_SW; |
| 7976 | IPW_DEBUG_INFO("Radio disabled.\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7977 | } |
| 7978 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7979 | if (channel != 0) { |
| 7980 | priv->config |= CFG_STATIC_CHANNEL; |
| 7981 | priv->channel = channel; |
| 7982 | IPW_DEBUG_INFO("Bind to static channel %d\n", channel); |
| 7983 | /* TODO: Validate that provided channel is in range */ |
| 7984 | } |
| 7985 | #ifdef CONFIG_IPW_QOS |
| 7986 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
| 7987 | burst_duration_CCK, burst_duration_OFDM); |
| 7988 | #endif /* CONFIG_IPW_QOS */ |
| 7989 | |
| 7990 | switch (mode) { |
| 7991 | case 1: |
| 7992 | priv->ieee->iw_mode = IW_MODE_ADHOC; |
| 7993 | priv->net_dev->type = ARPHRD_ETHER; |
| 7994 | |
| 7995 | break; |
| 7996 | #ifdef CONFIG_IPW2200_MONITOR |
| 7997 | case 2: |
| 7998 | priv->ieee->iw_mode = IW_MODE_MONITOR; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7999 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 8000 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8001 | #else |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8002 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8003 | #endif |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8004 | break; |
| 8005 | #endif |
| 8006 | default: |
| 8007 | case 0: |
| 8008 | priv->net_dev->type = ARPHRD_ETHER; |
| 8009 | priv->ieee->iw_mode = IW_MODE_INFRA; |
| 8010 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8011 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8012 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8013 | if (hwcrypto) { |
| 8014 | priv->ieee->host_encrypt = 0; |
| 8015 | priv->ieee->host_encrypt_msdu = 0; |
| 8016 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 8017 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8018 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8019 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8020 | |
Zhu Yi | e402c93 | 2005-08-05 17:20:40 +0800 | [diff] [blame] | 8021 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
| 8022 | priv->ieee->host_open_frag = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8023 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8024 | if ((priv->pci_dev->device == 0x4223) || |
| 8025 | (priv->pci_dev->device == 0x4224)) { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8026 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8027 | printk(KERN_INFO DRV_NAME |
| 8028 | ": Detected Intel PRO/Wireless 2915ABG Network " |
| 8029 | "Connection\n"); |
| 8030 | priv->ieee->abg_true = 1; |
| 8031 | band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; |
| 8032 | modulation = IEEE80211_OFDM_MODULATION | |
| 8033 | IEEE80211_CCK_MODULATION; |
| 8034 | priv->adapter = IPW_2915ABG; |
| 8035 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8036 | } else { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8037 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8038 | printk(KERN_INFO DRV_NAME |
| 8039 | ": Detected Intel PRO/Wireless 2200BG Network " |
| 8040 | "Connection\n"); |
| 8041 | |
| 8042 | priv->ieee->abg_true = 0; |
| 8043 | band = IEEE80211_24GHZ_BAND; |
| 8044 | modulation = IEEE80211_OFDM_MODULATION | |
| 8045 | IEEE80211_CCK_MODULATION; |
| 8046 | priv->adapter = IPW_2200BG; |
| 8047 | priv->ieee->mode = IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8048 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8049 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8050 | priv->ieee->freq_band = band; |
| 8051 | priv->ieee->modulation = modulation; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8052 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8053 | priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8054 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8055 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8056 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8057 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8058 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8059 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; |
| 8060 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8061 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8062 | /* If power management is turned on, default to AC mode */ |
| 8063 | priv->power_mode = IPW_POWER_AC; |
| 8064 | priv->tx_power = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8065 | |
Zhu Yi | 0ece35b | 2005-08-05 17:26:51 +0800 | [diff] [blame] | 8066 | return old_mode == priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8067 | } |
| 8068 | |
| 8069 | /* |
| 8070 | * This file defines the Wireless Extension handlers. It does not |
| 8071 | * define any methods of hardware manipulation and relies on the |
| 8072 | * functions defined in ipw_main to provide the HW interaction. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8073 | * |
| 8074 | * The exception to this is the use of the ipw_get_ordinal() |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8075 | * function used to poll the hardware vs. making unecessary calls. |
| 8076 | * |
| 8077 | */ |
| 8078 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8079 | static int ipw_wx_get_name(struct net_device *dev, |
| 8080 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8081 | union iwreq_data *wrqu, char *extra) |
| 8082 | { |
| 8083 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8084 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8085 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8086 | strcpy(wrqu->name, "radio off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8087 | else if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8088 | strcpy(wrqu->name, "unassociated"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8089 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8090 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c", |
| 8091 | ipw_modes[priv->assoc_request.ieee_mode]); |
| 8092 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8093 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8094 | return 0; |
| 8095 | } |
| 8096 | |
| 8097 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
| 8098 | { |
| 8099 | if (channel == 0) { |
| 8100 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); |
| 8101 | priv->config &= ~CFG_STATIC_CHANNEL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8102 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8103 | "parameters.\n"); |
| 8104 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8105 | return 0; |
| 8106 | } |
| 8107 | |
| 8108 | priv->config |= CFG_STATIC_CHANNEL; |
| 8109 | |
| 8110 | if (priv->channel == channel) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8111 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
| 8112 | channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8113 | return 0; |
| 8114 | } |
| 8115 | |
| 8116 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); |
| 8117 | priv->channel = channel; |
| 8118 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8119 | #ifdef CONFIG_IPW2200_MONITOR |
| 8120 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8121 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8122 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8123 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8124 | "channel change.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8125 | ipw_abort_scan(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8126 | } |
| 8127 | |
| 8128 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) |
| 8129 | udelay(10); |
| 8130 | |
| 8131 | if (priv->status & STATUS_SCANNING) |
| 8132 | IPW_DEBUG_SCAN("Still scanning...\n"); |
| 8133 | else |
| 8134 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", |
| 8135 | 1000 - i); |
| 8136 | |
| 8137 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8138 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8139 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 8140 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8141 | /* Network configuration changed -- force [re]association */ |
| 8142 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); |
| 8143 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8144 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8145 | |
| 8146 | return 0; |
| 8147 | } |
| 8148 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8149 | static int ipw_wx_set_freq(struct net_device *dev, |
| 8150 | struct iw_request_info *info, |
| 8151 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8152 | { |
| 8153 | struct ipw_priv *priv = ieee80211_priv(dev); |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8154 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8155 | struct iw_freq *fwrq = &wrqu->freq; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8156 | int ret = 0, i; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8157 | u8 channel, flags; |
| 8158 | int band; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8159 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8160 | if (fwrq->m == 0) { |
| 8161 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8162 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8163 | ret = ipw_set_channel(priv, 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8164 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8165 | return ret; |
| 8166 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8167 | /* if setting by freq convert to channel */ |
| 8168 | if (fwrq->e == 1) { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8169 | channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8170 | if (channel == 0) |
| 8171 | return -EINVAL; |
| 8172 | } else |
| 8173 | channel = fwrq->m; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8174 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8175 | if (!(band = ieee80211_is_valid_channel(priv->ieee, channel))) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8176 | return -EINVAL; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8177 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8178 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8179 | i = ieee80211_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8180 | if (i == -1) |
| 8181 | return -EINVAL; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8182 | |
| 8183 | flags = (band == IEEE80211_24GHZ_BAND) ? |
| 8184 | geo->bg[i].flags : geo->a[i].flags; |
| 8185 | if (flags & IEEE80211_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8186 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
| 8187 | return -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8188 | } |
| 8189 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8190 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8191 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8192 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8193 | ret = ipw_set_channel(priv, channel); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8194 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8195 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8196 | } |
| 8197 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8198 | static int ipw_wx_get_freq(struct net_device *dev, |
| 8199 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8200 | union iwreq_data *wrqu, char *extra) |
| 8201 | { |
| 8202 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8203 | |
| 8204 | wrqu->freq.e = 0; |
| 8205 | |
| 8206 | /* If we are associated, trying to associate, or have a statically |
| 8207 | * configured CHANNEL then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8208 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8209 | if (priv->config & CFG_STATIC_CHANNEL || |
| 8210 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) |
| 8211 | wrqu->freq.m = priv->channel; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8212 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8213 | wrqu->freq.m = 0; |
| 8214 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8215 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8216 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
| 8217 | return 0; |
| 8218 | } |
| 8219 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8220 | static int ipw_wx_set_mode(struct net_device *dev, |
| 8221 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8222 | union iwreq_data *wrqu, char *extra) |
| 8223 | { |
| 8224 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8225 | int err = 0; |
| 8226 | |
| 8227 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); |
| 8228 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8229 | switch (wrqu->mode) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8230 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8231 | case IW_MODE_MONITOR: |
| 8232 | #endif |
| 8233 | case IW_MODE_ADHOC: |
| 8234 | case IW_MODE_INFRA: |
| 8235 | break; |
| 8236 | case IW_MODE_AUTO: |
| 8237 | wrqu->mode = IW_MODE_INFRA; |
| 8238 | break; |
| 8239 | default: |
| 8240 | return -EINVAL; |
| 8241 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8242 | if (wrqu->mode == priv->ieee->iw_mode) |
| 8243 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8244 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8245 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8246 | |
| 8247 | ipw_sw_reset(priv, 0); |
| 8248 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8249 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8250 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8251 | priv->net_dev->type = ARPHRD_ETHER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8252 | |
| 8253 | if (wrqu->mode == IW_MODE_MONITOR) |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8254 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 8255 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8256 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8257 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8258 | #endif |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8259 | #endif /* CONFIG_IPW2200_MONITOR */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8260 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8261 | /* Free the existing firmware and reset the fw_loaded |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8262 | * flag so ipw_load() will bring in the new firmawre */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8263 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8264 | |
| 8265 | priv->ieee->iw_mode = wrqu->mode; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8266 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8267 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8268 | mutex_unlock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8269 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8270 | } |
| 8271 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8272 | static int ipw_wx_get_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8273 | struct iw_request_info *info, |
| 8274 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8275 | { |
| 8276 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8277 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8278 | wrqu->mode = priv->ieee->iw_mode; |
| 8279 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8280 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8281 | return 0; |
| 8282 | } |
| 8283 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8284 | /* Values are in microsecond */ |
| 8285 | static const s32 timeout_duration[] = { |
| 8286 | 350000, |
| 8287 | 250000, |
| 8288 | 75000, |
| 8289 | 37000, |
| 8290 | 25000, |
| 8291 | }; |
| 8292 | |
| 8293 | static const s32 period_duration[] = { |
| 8294 | 400000, |
| 8295 | 700000, |
| 8296 | 1000000, |
| 8297 | 1000000, |
| 8298 | 1000000 |
| 8299 | }; |
| 8300 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8301 | static int ipw_wx_get_range(struct net_device *dev, |
| 8302 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8303 | union iwreq_data *wrqu, char *extra) |
| 8304 | { |
| 8305 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8306 | struct iw_range *range = (struct iw_range *)extra; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8307 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8308 | int i = 0, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8309 | |
| 8310 | wrqu->data.length = sizeof(*range); |
| 8311 | memset(range, 0, sizeof(*range)); |
| 8312 | |
| 8313 | /* 54Mbs == ~27 Mb/s real (802.11g) */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8314 | range->throughput = 27 * 1000 * 1000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8315 | |
| 8316 | range->max_qual.qual = 100; |
| 8317 | /* TODO: Find real max RSSI and stick here */ |
| 8318 | range->max_qual.level = 0; |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8319 | range->max_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8320 | range->max_qual.updated = 7; /* Updated all three */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8321 | |
| 8322 | range->avg_qual.qual = 70; |
| 8323 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8324 | range->avg_qual.level = 0; /* FIXME to real average level */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8325 | range->avg_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8326 | range->avg_qual.updated = 7; /* Updated all three */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8327 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8328 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8329 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8330 | for (i = 0; i < range->num_bitrates; i++) |
| 8331 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8332 | 500000; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8333 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8334 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
| 8335 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 8336 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 8337 | |
| 8338 | range->encoding_size[0] = 5; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8339 | range->encoding_size[1] = 13; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8340 | range->num_encoding_sizes = 2; |
| 8341 | range->max_encoding_tokens = WEP_KEYS; |
| 8342 | |
| 8343 | /* Set the Wireless Extension versions */ |
| 8344 | range->we_version_compiled = WIRELESS_EXT; |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8345 | range->we_version_source = 18; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8346 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8347 | i = 0; |
| 8348 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8349 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8350 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
| 8351 | (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY)) |
| 8352 | continue; |
| 8353 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8354 | range->freq[i].i = geo->bg[j].channel; |
| 8355 | range->freq[i].m = geo->bg[j].freq * 100000; |
| 8356 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8357 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8358 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8359 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8360 | |
| 8361 | if (priv->ieee->mode & IEEE_A) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8362 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8363 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
| 8364 | (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY)) |
| 8365 | continue; |
| 8366 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8367 | range->freq[i].i = geo->a[j].channel; |
| 8368 | range->freq[i].m = geo->a[j].freq * 100000; |
| 8369 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8370 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8371 | } |
| 8372 | } |
| 8373 | |
| 8374 | range->num_channels = i; |
| 8375 | range->num_frequency = i; |
| 8376 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8377 | mutex_unlock(&priv->mutex); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8378 | |
| 8379 | /* Event capability (kernel + driver) */ |
| 8380 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 8381 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
| 8382 | IW_EVENT_CAPA_MASK(SIOCGIWAP)); |
| 8383 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8384 | |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8385 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 8386 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 8387 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8388 | IPW_DEBUG_WX("GET Range\n"); |
| 8389 | return 0; |
| 8390 | } |
| 8391 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8392 | static int ipw_wx_set_wap(struct net_device *dev, |
| 8393 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8394 | union iwreq_data *wrqu, char *extra) |
| 8395 | { |
| 8396 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8397 | |
| 8398 | static const unsigned char any[] = { |
| 8399 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 8400 | }; |
| 8401 | static const unsigned char off[] = { |
| 8402 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 8403 | }; |
| 8404 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8405 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8406 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8407 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8408 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
| 8409 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8410 | /* we disable mandatory BSSID association */ |
| 8411 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); |
| 8412 | priv->config &= ~CFG_STATIC_BSSID; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8413 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8414 | "parameters.\n"); |
| 8415 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8416 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8417 | return 0; |
| 8418 | } |
| 8419 | |
| 8420 | priv->config |= CFG_STATIC_BSSID; |
| 8421 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8422 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8423 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8424 | return 0; |
| 8425 | } |
| 8426 | |
| 8427 | IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n", |
| 8428 | MAC_ARG(wrqu->ap_addr.sa_data)); |
| 8429 | |
| 8430 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); |
| 8431 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8432 | /* Network configuration changed -- force [re]association */ |
| 8433 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); |
| 8434 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8435 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8436 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8437 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8438 | return 0; |
| 8439 | } |
| 8440 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8441 | static int ipw_wx_get_wap(struct net_device *dev, |
| 8442 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8443 | union iwreq_data *wrqu, char *extra) |
| 8444 | { |
| 8445 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8446 | /* If we are associated, trying to associate, or have a statically |
| 8447 | * configured BSSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8448 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8449 | if (priv->config & CFG_STATIC_BSSID || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8450 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8451 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8452 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8453 | } else |
| 8454 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 8455 | |
| 8456 | IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", |
| 8457 | MAC_ARG(wrqu->ap_addr.sa_data)); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8458 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8459 | return 0; |
| 8460 | } |
| 8461 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8462 | static int ipw_wx_set_essid(struct net_device *dev, |
| 8463 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8464 | union iwreq_data *wrqu, char *extra) |
| 8465 | { |
| 8466 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8467 | char *essid = ""; /* ANY */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8468 | int length = 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8469 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8470 | if (wrqu->essid.flags && wrqu->essid.length) { |
| 8471 | length = wrqu->essid.length - 1; |
| 8472 | essid = extra; |
| 8473 | } |
| 8474 | if (length == 0) { |
| 8475 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8476 | if ((priv->config & CFG_STATIC_ESSID) && |
| 8477 | !(priv->status & (STATUS_ASSOCIATED | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8478 | STATUS_ASSOCIATING))) { |
| 8479 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8480 | "parameters.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8481 | priv->config &= ~CFG_STATIC_ESSID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8482 | ipw_associate(priv); |
| 8483 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8484 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8485 | return 0; |
| 8486 | } |
| 8487 | |
| 8488 | length = min(length, IW_ESSID_MAX_SIZE); |
| 8489 | |
| 8490 | priv->config |= CFG_STATIC_ESSID; |
| 8491 | |
| 8492 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { |
| 8493 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8494 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8495 | return 0; |
| 8496 | } |
| 8497 | |
| 8498 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length), |
| 8499 | length); |
| 8500 | |
| 8501 | priv->essid_len = length; |
| 8502 | memcpy(priv->essid, essid, priv->essid_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8503 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8504 | /* Network configuration changed -- force [re]association */ |
| 8505 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); |
| 8506 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8507 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8508 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8509 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8510 | return 0; |
| 8511 | } |
| 8512 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8513 | static int ipw_wx_get_essid(struct net_device *dev, |
| 8514 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8515 | union iwreq_data *wrqu, char *extra) |
| 8516 | { |
| 8517 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8518 | |
| 8519 | /* If we are associated, trying to associate, or have a statically |
| 8520 | * configured ESSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8521 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8522 | if (priv->config & CFG_STATIC_ESSID || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8523 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8524 | IPW_DEBUG_WX("Getting essid: '%s'\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8525 | escape_essid(priv->essid, priv->essid_len)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8526 | memcpy(extra, priv->essid, priv->essid_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8527 | wrqu->essid.length = priv->essid_len; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8528 | wrqu->essid.flags = 1; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8529 | } else { |
| 8530 | IPW_DEBUG_WX("Getting essid: ANY\n"); |
| 8531 | wrqu->essid.length = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8532 | wrqu->essid.flags = 0; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8533 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8534 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8535 | return 0; |
| 8536 | } |
| 8537 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8538 | static int ipw_wx_set_nick(struct net_device *dev, |
| 8539 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8540 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8541 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8542 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8543 | |
| 8544 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); |
| 8545 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) |
| 8546 | return -E2BIG; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8547 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8548 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8549 | memset(priv->nick, 0, sizeof(priv->nick)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8550 | memcpy(priv->nick, extra, wrqu->data.length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8551 | IPW_DEBUG_TRACE("<<\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8552 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8553 | return 0; |
| 8554 | |
| 8555 | } |
| 8556 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8557 | static int ipw_wx_get_nick(struct net_device *dev, |
| 8558 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8559 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8560 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8561 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8562 | IPW_DEBUG_WX("Getting nick\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8563 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8564 | wrqu->data.length = strlen(priv->nick) + 1; |
| 8565 | memcpy(extra, priv->nick, wrqu->data.length); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8566 | wrqu->data.flags = 1; /* active */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8567 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8568 | return 0; |
| 8569 | } |
| 8570 | |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 8571 | static int ipw_wx_set_sens(struct net_device *dev, |
| 8572 | struct iw_request_info *info, |
| 8573 | union iwreq_data *wrqu, char *extra) |
| 8574 | { |
| 8575 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8576 | int err = 0; |
| 8577 | |
| 8578 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); |
| 8579 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); |
| 8580 | mutex_lock(&priv->mutex); |
| 8581 | |
| 8582 | if (wrqu->sens.fixed == 0) |
| 8583 | { |
| 8584 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
| 8585 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8586 | goto out; |
| 8587 | } |
| 8588 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || |
| 8589 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { |
| 8590 | err = -EINVAL; |
| 8591 | goto out; |
| 8592 | } |
| 8593 | |
| 8594 | priv->roaming_threshold = wrqu->sens.value; |
| 8595 | priv->disassociate_threshold = 3*wrqu->sens.value; |
| 8596 | out: |
| 8597 | mutex_unlock(&priv->mutex); |
| 8598 | return err; |
| 8599 | } |
| 8600 | |
| 8601 | static int ipw_wx_get_sens(struct net_device *dev, |
| 8602 | struct iw_request_info *info, |
| 8603 | union iwreq_data *wrqu, char *extra) |
| 8604 | { |
| 8605 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8606 | mutex_lock(&priv->mutex); |
| 8607 | wrqu->sens.fixed = 1; |
| 8608 | wrqu->sens.value = priv->roaming_threshold; |
| 8609 | mutex_unlock(&priv->mutex); |
| 8610 | |
| 8611 | IPW_DEBUG_WX("GET roaming threshold -> %s %d \n", |
| 8612 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
| 8613 | |
| 8614 | return 0; |
| 8615 | } |
| 8616 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8617 | static int ipw_wx_set_rate(struct net_device *dev, |
| 8618 | struct iw_request_info *info, |
| 8619 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8620 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8621 | /* TODO: We should use semaphores or locks for access to priv */ |
| 8622 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8623 | u32 target_rate = wrqu->bitrate.value; |
| 8624 | u32 fixed, mask; |
| 8625 | |
| 8626 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ |
| 8627 | /* value = X, fixed = 1 means only rate X */ |
| 8628 | /* value = X, fixed = 0 means all rates lower equal X */ |
| 8629 | |
| 8630 | if (target_rate == -1) { |
| 8631 | fixed = 0; |
| 8632 | mask = IEEE80211_DEFAULT_RATES_MASK; |
| 8633 | /* Now we should reassociate */ |
| 8634 | goto apply; |
| 8635 | } |
| 8636 | |
| 8637 | mask = 0; |
| 8638 | fixed = wrqu->bitrate.fixed; |
| 8639 | |
| 8640 | if (target_rate == 1000000 || !fixed) |
| 8641 | mask |= IEEE80211_CCK_RATE_1MB_MASK; |
| 8642 | if (target_rate == 1000000) |
| 8643 | goto apply; |
| 8644 | |
| 8645 | if (target_rate == 2000000 || !fixed) |
| 8646 | mask |= IEEE80211_CCK_RATE_2MB_MASK; |
| 8647 | if (target_rate == 2000000) |
| 8648 | goto apply; |
| 8649 | |
| 8650 | if (target_rate == 5500000 || !fixed) |
| 8651 | mask |= IEEE80211_CCK_RATE_5MB_MASK; |
| 8652 | if (target_rate == 5500000) |
| 8653 | goto apply; |
| 8654 | |
| 8655 | if (target_rate == 6000000 || !fixed) |
| 8656 | mask |= IEEE80211_OFDM_RATE_6MB_MASK; |
| 8657 | if (target_rate == 6000000) |
| 8658 | goto apply; |
| 8659 | |
| 8660 | if (target_rate == 9000000 || !fixed) |
| 8661 | mask |= IEEE80211_OFDM_RATE_9MB_MASK; |
| 8662 | if (target_rate == 9000000) |
| 8663 | goto apply; |
| 8664 | |
| 8665 | if (target_rate == 11000000 || !fixed) |
| 8666 | mask |= IEEE80211_CCK_RATE_11MB_MASK; |
| 8667 | if (target_rate == 11000000) |
| 8668 | goto apply; |
| 8669 | |
| 8670 | if (target_rate == 12000000 || !fixed) |
| 8671 | mask |= IEEE80211_OFDM_RATE_12MB_MASK; |
| 8672 | if (target_rate == 12000000) |
| 8673 | goto apply; |
| 8674 | |
| 8675 | if (target_rate == 18000000 || !fixed) |
| 8676 | mask |= IEEE80211_OFDM_RATE_18MB_MASK; |
| 8677 | if (target_rate == 18000000) |
| 8678 | goto apply; |
| 8679 | |
| 8680 | if (target_rate == 24000000 || !fixed) |
| 8681 | mask |= IEEE80211_OFDM_RATE_24MB_MASK; |
| 8682 | if (target_rate == 24000000) |
| 8683 | goto apply; |
| 8684 | |
| 8685 | if (target_rate == 36000000 || !fixed) |
| 8686 | mask |= IEEE80211_OFDM_RATE_36MB_MASK; |
| 8687 | if (target_rate == 36000000) |
| 8688 | goto apply; |
| 8689 | |
| 8690 | if (target_rate == 48000000 || !fixed) |
| 8691 | mask |= IEEE80211_OFDM_RATE_48MB_MASK; |
| 8692 | if (target_rate == 48000000) |
| 8693 | goto apply; |
| 8694 | |
| 8695 | if (target_rate == 54000000 || !fixed) |
| 8696 | mask |= IEEE80211_OFDM_RATE_54MB_MASK; |
| 8697 | if (target_rate == 54000000) |
| 8698 | goto apply; |
| 8699 | |
| 8700 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); |
| 8701 | return -EINVAL; |
| 8702 | |
| 8703 | apply: |
| 8704 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", |
| 8705 | mask, fixed ? "fixed" : "sub-rates"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8706 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8707 | if (mask == IEEE80211_DEFAULT_RATES_MASK) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8708 | priv->config &= ~CFG_FIXED_RATE; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8709 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
| 8710 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8711 | priv->config |= CFG_FIXED_RATE; |
| 8712 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8713 | if (priv->rates_mask == mask) { |
| 8714 | IPW_DEBUG_WX("Mask set to current mask.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8715 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8716 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8717 | } |
| 8718 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8719 | priv->rates_mask = mask; |
| 8720 | |
| 8721 | /* Network configuration changed -- force [re]association */ |
| 8722 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); |
| 8723 | if (!ipw_disassociate(priv)) |
| 8724 | ipw_associate(priv); |
| 8725 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8726 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8727 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8728 | } |
| 8729 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8730 | static int ipw_wx_get_rate(struct net_device *dev, |
| 8731 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8732 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8733 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8734 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8735 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8736 | wrqu->bitrate.value = priv->last_rate; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8737 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8738 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
| 8739 | return 0; |
| 8740 | } |
| 8741 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8742 | static int ipw_wx_set_rts(struct net_device *dev, |
| 8743 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8744 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8745 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8746 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8747 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8748 | if (wrqu->rts.disabled) |
| 8749 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8750 | else { |
| 8751 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8752 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8753 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8754 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8755 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8756 | priv->rts_threshold = wrqu->rts.value; |
| 8757 | } |
| 8758 | |
| 8759 | ipw_send_rts_threshold(priv, priv->rts_threshold); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8760 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8761 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
| 8762 | return 0; |
| 8763 | } |
| 8764 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8765 | static int ipw_wx_get_rts(struct net_device *dev, |
| 8766 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8767 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8768 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8769 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8770 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8771 | wrqu->rts.value = priv->rts_threshold; |
| 8772 | wrqu->rts.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8773 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8774 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8775 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
| 8776 | return 0; |
| 8777 | } |
| 8778 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8779 | static int ipw_wx_set_txpow(struct net_device *dev, |
| 8780 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8781 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8782 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8783 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8784 | int err = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8785 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8786 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8787 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8788 | err = -EINPROGRESS; |
| 8789 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8790 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8791 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8792 | if (!wrqu->power.fixed) |
| 8793 | wrqu->power.value = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8794 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8795 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8796 | err = -EINVAL; |
| 8797 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8798 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8799 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8800 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8801 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8802 | err = -EINVAL; |
| 8803 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8804 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8805 | |
| 8806 | priv->tx_power = wrqu->power.value; |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8807 | err = ipw_set_tx_power(priv); |
| 8808 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8809 | mutex_unlock(&priv->mutex); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8810 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8811 | } |
| 8812 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8813 | static int ipw_wx_get_txpow(struct net_device *dev, |
| 8814 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8815 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8816 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8817 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8818 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8819 | wrqu->power.value = priv->tx_power; |
| 8820 | wrqu->power.fixed = 1; |
| 8821 | wrqu->power.flags = IW_TXPOW_DBM; |
| 8822 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8823 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8824 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8825 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
Zhu Yi | 22501c8 | 2005-08-11 10:49:17 +0800 | [diff] [blame] | 8826 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8827 | |
| 8828 | return 0; |
| 8829 | } |
| 8830 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8831 | static int ipw_wx_set_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8832 | struct iw_request_info *info, |
| 8833 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8834 | { |
| 8835 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8836 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8837 | if (wrqu->frag.disabled) |
| 8838 | priv->ieee->fts = DEFAULT_FTS; |
| 8839 | else { |
| 8840 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8841 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8842 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8843 | return -EINVAL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8844 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8845 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8846 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
| 8847 | } |
| 8848 | |
| 8849 | ipw_send_frag_threshold(priv, wrqu->frag.value); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8850 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8851 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
| 8852 | return 0; |
| 8853 | } |
| 8854 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8855 | static int ipw_wx_get_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8856 | struct iw_request_info *info, |
| 8857 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8858 | { |
| 8859 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8860 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8861 | wrqu->frag.value = priv->ieee->fts; |
| 8862 | wrqu->frag.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8863 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8864 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8865 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
| 8866 | |
| 8867 | return 0; |
| 8868 | } |
| 8869 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8870 | static int ipw_wx_set_retry(struct net_device *dev, |
| 8871 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8872 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8873 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8874 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8875 | |
| 8876 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) |
| 8877 | return -EINVAL; |
| 8878 | |
| 8879 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) |
| 8880 | return 0; |
| 8881 | |
| 8882 | if (wrqu->retry.value < 0 || wrqu->retry.value > 255) |
| 8883 | return -EINVAL; |
| 8884 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8885 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8886 | if (wrqu->retry.flags & IW_RETRY_MIN) |
| 8887 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 8888 | else if (wrqu->retry.flags & IW_RETRY_MAX) |
| 8889 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 8890 | else { |
| 8891 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 8892 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 8893 | } |
| 8894 | |
| 8895 | ipw_send_retry_limit(priv, priv->short_retry_limit, |
| 8896 | priv->long_retry_limit); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8897 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8898 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
| 8899 | priv->short_retry_limit, priv->long_retry_limit); |
| 8900 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8901 | } |
| 8902 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8903 | static int ipw_wx_get_retry(struct net_device *dev, |
| 8904 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8905 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8906 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8907 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8908 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8909 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8910 | wrqu->retry.disabled = 0; |
| 8911 | |
| 8912 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8913 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8914 | return -EINVAL; |
| 8915 | } |
| 8916 | |
| 8917 | if (wrqu->retry.flags & IW_RETRY_MAX) { |
| 8918 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 8919 | wrqu->retry.value = priv->long_retry_limit; |
| 8920 | } else if (wrqu->retry.flags & IW_RETRY_MIN) { |
| 8921 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; |
| 8922 | wrqu->retry.value = priv->short_retry_limit; |
| 8923 | } else { |
| 8924 | wrqu->retry.flags = IW_RETRY_LIMIT; |
| 8925 | wrqu->retry.value = priv->short_retry_limit; |
| 8926 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8927 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8928 | |
| 8929 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); |
| 8930 | |
| 8931 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8932 | } |
| 8933 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8934 | static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid, |
| 8935 | int essid_len) |
| 8936 | { |
| 8937 | struct ipw_scan_request_ext scan; |
| 8938 | int err = 0, scan_type; |
| 8939 | |
Pekka Enberg | efb3442 | 2005-11-16 21:55:05 +0200 | [diff] [blame] | 8940 | if (!(priv->status & STATUS_INIT) || |
| 8941 | (priv->status & STATUS_EXIT_PENDING)) |
| 8942 | return 0; |
| 8943 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8944 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8945 | |
| 8946 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 8947 | IPW_DEBUG_HC("Aborting scan due to RF kill activation\n"); |
| 8948 | priv->status |= STATUS_SCAN_PENDING; |
| 8949 | goto done; |
| 8950 | } |
| 8951 | |
| 8952 | IPW_DEBUG_HC("starting request direct scan!\n"); |
| 8953 | |
| 8954 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
Olaf Kirch | d834a41 | 2006-01-09 17:00:37 +0100 | [diff] [blame] | 8955 | /* We should not sleep here; otherwise we will block most |
| 8956 | * of the system (for instance, we hold rtnl_lock when we |
| 8957 | * get here). |
| 8958 | */ |
| 8959 | err = -EAGAIN; |
| 8960 | goto done; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8961 | } |
| 8962 | memset(&scan, 0, sizeof(scan)); |
| 8963 | |
| 8964 | if (priv->config & CFG_SPEED_SCAN) |
| 8965 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 8966 | cpu_to_le16(30); |
| 8967 | else |
| 8968 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 8969 | cpu_to_le16(20); |
| 8970 | |
| 8971 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 8972 | cpu_to_le16(20); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8973 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8974 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
| 8975 | |
| 8976 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
| 8977 | |
| 8978 | err = ipw_send_ssid(priv, essid, essid_len); |
| 8979 | if (err) { |
| 8980 | IPW_DEBUG_HC("Attempt to send SSID command failed\n"); |
| 8981 | goto done; |
| 8982 | } |
| 8983 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
| 8984 | |
| 8985 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 8986 | |
| 8987 | err = ipw_send_scan_request_ext(priv, &scan); |
| 8988 | if (err) { |
| 8989 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
| 8990 | goto done; |
| 8991 | } |
| 8992 | |
| 8993 | priv->status |= STATUS_SCANNING; |
| 8994 | |
| 8995 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8996 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8997 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8998 | } |
| 8999 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9000 | static int ipw_wx_set_scan(struct net_device *dev, |
| 9001 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9002 | union iwreq_data *wrqu, char *extra) |
| 9003 | { |
| 9004 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9005 | struct iw_scan_req *req = NULL; |
| 9006 | if (wrqu->data.length |
| 9007 | && wrqu->data.length == sizeof(struct iw_scan_req)) { |
| 9008 | req = (struct iw_scan_req *)extra; |
| 9009 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
| 9010 | ipw_request_direct_scan(priv, req->essid, |
| 9011 | req->essid_len); |
| 9012 | return 0; |
| 9013 | } |
| 9014 | } |
James Ketrenos | 8935f39 | 2005-10-05 15:59:08 -0500 | [diff] [blame] | 9015 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9016 | IPW_DEBUG_WX("Start scan\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9017 | |
| 9018 | queue_work(priv->workqueue, &priv->request_scan); |
| 9019 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9020 | return 0; |
| 9021 | } |
| 9022 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9023 | static int ipw_wx_get_scan(struct net_device *dev, |
| 9024 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9025 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9026 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9027 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9028 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); |
| 9029 | } |
| 9030 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9031 | static int ipw_wx_set_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9032 | struct iw_request_info *info, |
| 9033 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9034 | { |
| 9035 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9036 | int ret; |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9037 | u32 cap = priv->capability; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9038 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9039 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9040 | ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9041 | |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9042 | /* In IBSS mode, we need to notify the firmware to update |
| 9043 | * the beacon info after we changed the capability. */ |
| 9044 | if (cap != priv->capability && |
| 9045 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 9046 | priv->status & STATUS_ASSOCIATED) |
| 9047 | ipw_disassociate(priv); |
| 9048 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9049 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9050 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9051 | } |
| 9052 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9053 | static int ipw_wx_get_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9054 | struct iw_request_info *info, |
| 9055 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9056 | { |
| 9057 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9058 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); |
| 9059 | } |
| 9060 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9061 | static int ipw_wx_set_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9062 | struct iw_request_info *info, |
| 9063 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9064 | { |
| 9065 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9066 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9067 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9068 | if (wrqu->power.disabled) { |
| 9069 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); |
| 9070 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); |
| 9071 | if (err) { |
| 9072 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9073 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9074 | return err; |
| 9075 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9076 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9077 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9078 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9079 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9080 | |
| 9081 | switch (wrqu->power.flags & IW_POWER_MODE) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9082 | case IW_POWER_ON: /* If not specified */ |
| 9083 | case IW_POWER_MODE: /* If set all mask */ |
| 9084 | case IW_POWER_ALL_R: /* If explicitely state all */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9085 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9086 | default: /* Otherwise we don't support it */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9087 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
| 9088 | wrqu->power.flags); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9089 | mutex_unlock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9090 | return -EOPNOTSUPP; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9091 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9092 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9093 | /* If the user hasn't specified a power management mode yet, default |
| 9094 | * to BATTERY */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9095 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9096 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9097 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9098 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
| 9099 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
| 9100 | if (err) { |
| 9101 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9102 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9103 | return err; |
| 9104 | } |
| 9105 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9106 | 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] | 9107 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9108 | return 0; |
| 9109 | } |
| 9110 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9111 | static int ipw_wx_get_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9112 | struct iw_request_info *info, |
| 9113 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9114 | { |
| 9115 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9116 | mutex_lock(&priv->mutex); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9117 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9118 | wrqu->power.disabled = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9119 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9120 | wrqu->power.disabled = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9121 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9122 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9123 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9124 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9125 | return 0; |
| 9126 | } |
| 9127 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9128 | static int ipw_wx_set_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9129 | struct iw_request_info *info, |
| 9130 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9131 | { |
| 9132 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9133 | int mode = *(int *)extra; |
| 9134 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9135 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9136 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) { |
| 9137 | mode = IPW_POWER_AC; |
| 9138 | priv->power_mode = mode; |
| 9139 | } else { |
| 9140 | priv->power_mode = IPW_POWER_ENABLED | mode; |
| 9141 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9142 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9143 | if (priv->power_mode != mode) { |
| 9144 | err = ipw_send_power_mode(priv, mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9145 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9146 | if (err) { |
| 9147 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9148 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9149 | return err; |
| 9150 | } |
| 9151 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9152 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9153 | return 0; |
| 9154 | } |
| 9155 | |
| 9156 | #define MAX_WX_STRING 80 |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9157 | static int ipw_wx_get_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9158 | struct iw_request_info *info, |
| 9159 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9160 | { |
| 9161 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9162 | int level = IPW_POWER_LEVEL(priv->power_mode); |
| 9163 | char *p = extra; |
| 9164 | |
| 9165 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); |
| 9166 | |
| 9167 | switch (level) { |
| 9168 | case IPW_POWER_AC: |
| 9169 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); |
| 9170 | break; |
| 9171 | case IPW_POWER_BATTERY: |
| 9172 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); |
| 9173 | break; |
| 9174 | default: |
| 9175 | p += snprintf(p, MAX_WX_STRING - (p - extra), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9176 | "(Timeout %dms, Period %dms)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9177 | timeout_duration[level - 1] / 1000, |
| 9178 | period_duration[level - 1] / 1000); |
| 9179 | } |
| 9180 | |
| 9181 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9182 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9183 | |
| 9184 | wrqu->data.length = p - extra + 1; |
| 9185 | |
| 9186 | return 0; |
| 9187 | } |
| 9188 | |
| 9189 | static int ipw_wx_set_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9190 | struct iw_request_info *info, |
| 9191 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9192 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9193 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9194 | int mode = *(int *)extra; |
| 9195 | u8 band = 0, modulation = 0; |
| 9196 | |
| 9197 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9198 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9199 | return -EINVAL; |
| 9200 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9201 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9202 | if (priv->adapter == IPW_2915ABG) { |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9203 | priv->ieee->abg_true = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9204 | if (mode & IEEE_A) { |
| 9205 | band |= IEEE80211_52GHZ_BAND; |
| 9206 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9207 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9208 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9209 | } else { |
| 9210 | if (mode & IEEE_A) { |
| 9211 | IPW_WARNING("Attempt to set 2200BG into " |
| 9212 | "802.11a mode\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9213 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9214 | return -EINVAL; |
| 9215 | } |
| 9216 | |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9217 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9218 | } |
| 9219 | |
| 9220 | if (mode & IEEE_B) { |
| 9221 | band |= IEEE80211_24GHZ_BAND; |
| 9222 | modulation |= IEEE80211_CCK_MODULATION; |
| 9223 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9224 | priv->ieee->abg_true = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9225 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9226 | if (mode & IEEE_G) { |
| 9227 | band |= IEEE80211_24GHZ_BAND; |
| 9228 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9229 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9230 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9231 | |
| 9232 | priv->ieee->mode = mode; |
| 9233 | priv->ieee->freq_band = band; |
| 9234 | priv->ieee->modulation = modulation; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9235 | init_supported_rates(priv, &priv->rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9236 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9237 | /* Network configuration changed -- force [re]association */ |
| 9238 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); |
| 9239 | if (!ipw_disassociate(priv)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9240 | ipw_send_supported_rates(priv, &priv->rates); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9241 | ipw_associate(priv); |
| 9242 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9243 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9244 | /* Update the band LEDs */ |
| 9245 | ipw_led_band_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9246 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9247 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9248 | mode & IEEE_A ? 'a' : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9249 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9250 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9251 | return 0; |
| 9252 | } |
| 9253 | |
| 9254 | static int ipw_wx_get_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9255 | struct iw_request_info *info, |
| 9256 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9257 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9258 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9259 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9260 | switch (priv->ieee->mode) { |
| 9261 | case IEEE_A: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9262 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
| 9263 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9264 | case IEEE_B: |
| 9265 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); |
| 9266 | break; |
| 9267 | case IEEE_A | IEEE_B: |
| 9268 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); |
| 9269 | break; |
| 9270 | case IEEE_G: |
| 9271 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); |
| 9272 | break; |
| 9273 | case IEEE_A | IEEE_G: |
| 9274 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); |
| 9275 | break; |
| 9276 | case IEEE_B | IEEE_G: |
| 9277 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); |
| 9278 | break; |
| 9279 | case IEEE_A | IEEE_B | IEEE_G: |
| 9280 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); |
| 9281 | break; |
| 9282 | default: |
| 9283 | strncpy(extra, "unknown", MAX_WX_STRING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9284 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9285 | } |
| 9286 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9287 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
| 9288 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9289 | wrqu->data.length = strlen(extra) + 1; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9290 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9291 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9292 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9293 | } |
| 9294 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9295 | static int ipw_wx_set_preamble(struct net_device *dev, |
| 9296 | struct iw_request_info *info, |
| 9297 | union iwreq_data *wrqu, char *extra) |
| 9298 | { |
| 9299 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9300 | int mode = *(int *)extra; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9301 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9302 | /* Switching from SHORT -> LONG requires a disassociation */ |
| 9303 | if (mode == 1) { |
| 9304 | if (!(priv->config & CFG_PREAMBLE_LONG)) { |
| 9305 | priv->config |= CFG_PREAMBLE_LONG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9306 | |
| 9307 | /* Network configuration changed -- force [re]association */ |
| 9308 | IPW_DEBUG_ASSOC |
| 9309 | ("[re]association triggered due to preamble change.\n"); |
| 9310 | if (!ipw_disassociate(priv)) |
| 9311 | ipw_associate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9312 | } |
| 9313 | goto done; |
| 9314 | } |
| 9315 | |
| 9316 | if (mode == 0) { |
| 9317 | priv->config &= ~CFG_PREAMBLE_LONG; |
| 9318 | goto done; |
| 9319 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9320 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9321 | return -EINVAL; |
| 9322 | |
| 9323 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9324 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9325 | return 0; |
| 9326 | } |
| 9327 | |
| 9328 | static int ipw_wx_get_preamble(struct net_device *dev, |
| 9329 | struct iw_request_info *info, |
| 9330 | union iwreq_data *wrqu, char *extra) |
| 9331 | { |
| 9332 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9333 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9334 | if (priv->config & CFG_PREAMBLE_LONG) |
| 9335 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); |
| 9336 | else |
| 9337 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9338 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9339 | return 0; |
| 9340 | } |
| 9341 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9342 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9343 | static int ipw_wx_set_monitor(struct net_device *dev, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9344 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9345 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9346 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9347 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9348 | int *parms = (int *)extra; |
| 9349 | int enable = (parms[0] > 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9350 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9351 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9352 | if (enable) { |
| 9353 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9354 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 9355 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 9356 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9357 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9358 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9359 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9360 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9361 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9362 | ipw_set_channel(priv, parms[1]); |
| 9363 | } else { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9364 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9365 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9366 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9367 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9368 | priv->net_dev->type = ARPHRD_ETHER; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9369 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9370 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9371 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9372 | return 0; |
| 9373 | } |
| 9374 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9375 | #endif // CONFIG_IPW2200_MONITOR |
| 9376 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9377 | static int ipw_wx_reset(struct net_device *dev, |
| 9378 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9379 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9380 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9381 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9382 | IPW_DEBUG_WX("RESET\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9383 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9384 | return 0; |
| 9385 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9386 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9387 | static int ipw_wx_sw_reset(struct net_device *dev, |
| 9388 | struct iw_request_info *info, |
| 9389 | union iwreq_data *wrqu, char *extra) |
| 9390 | { |
| 9391 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9392 | union iwreq_data wrqu_sec = { |
| 9393 | .encoding = { |
| 9394 | .flags = IW_ENCODE_DISABLED, |
| 9395 | }, |
| 9396 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9397 | int ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9398 | |
| 9399 | IPW_DEBUG_WX("SW_RESET\n"); |
| 9400 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9401 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9402 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 9403 | ret = ipw_sw_reset(priv, 2); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9404 | if (!ret) { |
| 9405 | free_firmware(); |
| 9406 | ipw_adapter_restart(priv); |
| 9407 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9408 | |
| 9409 | /* The SW reset bit might have been toggled on by the 'disable' |
| 9410 | * module parameter, so take appropriate action */ |
| 9411 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); |
| 9412 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9413 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9414 | ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9415 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9416 | |
| 9417 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 9418 | /* Configuration likely changed -- force [re]association */ |
| 9419 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " |
| 9420 | "reset.\n"); |
| 9421 | if (!ipw_disassociate(priv)) |
| 9422 | ipw_associate(priv); |
| 9423 | } |
| 9424 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9425 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9426 | |
| 9427 | return 0; |
| 9428 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9429 | |
| 9430 | /* Rebase the WE IOCTLs to zero for the handler array */ |
| 9431 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9432 | static iw_handler ipw_wx_handlers[] = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9433 | IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, |
| 9434 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, |
| 9435 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, |
| 9436 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, |
| 9437 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame] | 9438 | IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens, |
| 9439 | IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9440 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
| 9441 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, |
| 9442 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, |
| 9443 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, |
| 9444 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, |
| 9445 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, |
| 9446 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, |
| 9447 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, |
| 9448 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, |
| 9449 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, |
| 9450 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, |
| 9451 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, |
| 9452 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, |
| 9453 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, |
| 9454 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, |
| 9455 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, |
| 9456 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, |
| 9457 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, |
| 9458 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, |
| 9459 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, |
| 9460 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, |
| 9461 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, |
| 9462 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9463 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
| 9464 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, |
| 9465 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, |
| 9466 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9467 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
| 9468 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, |
| 9469 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, |
| 9470 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, |
| 9471 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, |
| 9472 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, |
| 9473 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9474 | }; |
| 9475 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9476 | enum { |
| 9477 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, |
| 9478 | IPW_PRIV_GET_POWER, |
| 9479 | IPW_PRIV_SET_MODE, |
| 9480 | IPW_PRIV_GET_MODE, |
| 9481 | IPW_PRIV_SET_PREAMBLE, |
| 9482 | IPW_PRIV_GET_PREAMBLE, |
| 9483 | IPW_PRIV_RESET, |
| 9484 | IPW_PRIV_SW_RESET, |
| 9485 | #ifdef CONFIG_IPW2200_MONITOR |
| 9486 | IPW_PRIV_SET_MONITOR, |
| 9487 | #endif |
| 9488 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9489 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9490 | static struct iw_priv_args ipw_priv_args[] = { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9491 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9492 | .cmd = IPW_PRIV_SET_POWER, |
| 9493 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9494 | .name = "set_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9495 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9496 | .cmd = IPW_PRIV_GET_POWER, |
| 9497 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9498 | .name = "get_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9499 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9500 | .cmd = IPW_PRIV_SET_MODE, |
| 9501 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9502 | .name = "set_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9503 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9504 | .cmd = IPW_PRIV_GET_MODE, |
| 9505 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9506 | .name = "get_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9507 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9508 | .cmd = IPW_PRIV_SET_PREAMBLE, |
| 9509 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9510 | .name = "set_preamble"}, |
| 9511 | { |
| 9512 | .cmd = IPW_PRIV_GET_PREAMBLE, |
| 9513 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, |
| 9514 | .name = "get_preamble"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9515 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9516 | IPW_PRIV_RESET, |
| 9517 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9518 | { |
| 9519 | IPW_PRIV_SW_RESET, |
| 9520 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, |
| 9521 | #ifdef CONFIG_IPW2200_MONITOR |
| 9522 | { |
| 9523 | IPW_PRIV_SET_MONITOR, |
| 9524 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, |
| 9525 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9526 | }; |
| 9527 | |
| 9528 | static iw_handler ipw_priv_handler[] = { |
| 9529 | ipw_wx_set_powermode, |
| 9530 | ipw_wx_get_powermode, |
| 9531 | ipw_wx_set_wireless_mode, |
| 9532 | ipw_wx_get_wireless_mode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9533 | ipw_wx_set_preamble, |
| 9534 | ipw_wx_get_preamble, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9535 | ipw_wx_reset, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9536 | ipw_wx_sw_reset, |
| 9537 | #ifdef CONFIG_IPW2200_MONITOR |
| 9538 | ipw_wx_set_monitor, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9539 | #endif |
| 9540 | }; |
| 9541 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9542 | static struct iw_handler_def ipw_wx_handler_def = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9543 | .standard = ipw_wx_handlers, |
| 9544 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), |
| 9545 | .num_private = ARRAY_SIZE(ipw_priv_handler), |
| 9546 | .num_private_args = ARRAY_SIZE(ipw_priv_args), |
| 9547 | .private = ipw_priv_handler, |
| 9548 | .private_args = ipw_priv_args, |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 9549 | .get_wireless_stats = ipw_get_wireless_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9550 | }; |
| 9551 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9552 | /* |
| 9553 | * Get wireless statistics. |
| 9554 | * Called by /proc/net/wireless |
| 9555 | * Also called by SIOCGIWSTATS |
| 9556 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9557 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9558 | { |
| 9559 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9560 | struct iw_statistics *wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9561 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9562 | wstats = &priv->wstats; |
| 9563 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9564 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9565 | * netdev->get_wireless_stats seems to be called before fw is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9566 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
| 9567 | * and associated; if not associcated, the values are all meaningless |
| 9568 | * anyway, so set them all to NULL and INVALID */ |
| 9569 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 9570 | wstats->miss.beacon = 0; |
| 9571 | wstats->discard.retries = 0; |
| 9572 | wstats->qual.qual = 0; |
| 9573 | wstats->qual.level = 0; |
| 9574 | wstats->qual.noise = 0; |
| 9575 | wstats->qual.updated = 7; |
| 9576 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9577 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9578 | return wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9579 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9580 | |
| 9581 | wstats->qual.qual = priv->quality; |
Zhu Yi | 00d21de | 2006-04-13 17:19:02 +0800 | [diff] [blame] | 9582 | wstats->qual.level = priv->exp_avg_rssi; |
| 9583 | wstats->qual.noise = priv->exp_avg_noise; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9584 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 9585 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9586 | |
| 9587 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); |
| 9588 | wstats->discard.retries = priv->last_tx_failures; |
| 9589 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9590 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9591 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
| 9592 | goto fail_get_ordinal; |
| 9593 | wstats->discard.retries += tx_retry; */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9594 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9595 | return wstats; |
| 9596 | } |
| 9597 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9598 | /* net device stuff */ |
| 9599 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 9600 | static void init_sys_config(struct ipw_sys_config *sys_config) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9601 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9602 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 9603 | sys_config->bt_coexistence = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9604 | sys_config->answer_broadcast_ssid_probe = 0; |
| 9605 | sys_config->accept_all_data_frames = 0; |
| 9606 | sys_config->accept_non_directed_frames = 1; |
| 9607 | sys_config->exclude_unicast_unencrypted = 0; |
| 9608 | sys_config->disable_unicast_decryption = 1; |
| 9609 | sys_config->exclude_multicast_unencrypted = 0; |
| 9610 | sys_config->disable_multicast_decryption = 1; |
Cahill, Ben M | 71de1f3 | 2006-03-08 03:02:27 +0800 | [diff] [blame] | 9611 | sys_config->antenna_diversity = CFG_SYS_ANTENNA_SLOW_DIV; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9612 | 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] | 9613 | sys_config->dot11g_auto_detection = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9614 | sys_config->enable_cts_to_self = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9615 | sys_config->bt_coexist_collision_thr = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9616 | 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] | 9617 | sys_config->silence_threshold = 0x1e; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9618 | } |
| 9619 | |
| 9620 | static int ipw_net_open(struct net_device *dev) |
| 9621 | { |
| 9622 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9623 | IPW_DEBUG_INFO("dev->open\n"); |
| 9624 | /* we should be verifying the device is ready to be opened */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9625 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9626 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 9627 | (priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9628 | netif_start_queue(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9629 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9630 | return 0; |
| 9631 | } |
| 9632 | |
| 9633 | static int ipw_net_stop(struct net_device *dev) |
| 9634 | { |
| 9635 | IPW_DEBUG_INFO("dev->close\n"); |
| 9636 | netif_stop_queue(dev); |
| 9637 | return 0; |
| 9638 | } |
| 9639 | |
| 9640 | /* |
| 9641 | todo: |
| 9642 | |
| 9643 | modify to send one tfd per fragment instead of using chunking. otherwise |
| 9644 | we need to heavily modify the ieee80211_skb_to_txb. |
| 9645 | */ |
| 9646 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 9647 | static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb, |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9648 | int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9649 | { |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame^] | 9650 | struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9651 | txb->fragments[0]->data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9652 | int i = 0; |
| 9653 | struct tfd_frame *tfd; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9654 | #ifdef CONFIG_IPW_QOS |
| 9655 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 9656 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 9657 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9658 | struct clx2_tx_queue *txq = &priv->txq[0]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9659 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9660 | struct clx2_queue *q = &txq->q; |
| 9661 | u8 id, hdr_len, unicast; |
| 9662 | u16 remaining_bytes; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9663 | int fc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9664 | |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame^] | 9665 | hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9666 | switch (priv->ieee->iw_mode) { |
| 9667 | case IW_MODE_ADHOC: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 9668 | unicast = !is_multicast_ether_addr(hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9669 | id = ipw_find_station(priv, hdr->addr1); |
| 9670 | if (id == IPW_INVALID_STATION) { |
| 9671 | id = ipw_add_station(priv, hdr->addr1); |
| 9672 | if (id == IPW_INVALID_STATION) { |
| 9673 | IPW_WARNING("Attempt to send data to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9674 | "invalid cell: " MAC_FMT "\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9675 | MAC_ARG(hdr->addr1)); |
| 9676 | goto drop; |
| 9677 | } |
| 9678 | } |
| 9679 | break; |
| 9680 | |
| 9681 | case IW_MODE_INFRA: |
| 9682 | default: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 9683 | unicast = !is_multicast_ether_addr(hdr->addr3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9684 | id = 0; |
| 9685 | break; |
| 9686 | } |
| 9687 | |
| 9688 | tfd = &txq->bd[q->first_empty]; |
| 9689 | txq->txb[q->first_empty] = txb; |
| 9690 | memset(tfd, 0, sizeof(*tfd)); |
| 9691 | tfd->u.data.station_number = id; |
| 9692 | |
| 9693 | tfd->control_flags.message_type = TX_FRAME_TYPE; |
| 9694 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 9695 | |
| 9696 | tfd->u.data.cmd_id = DINO_CMD_TX; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9697 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9698 | remaining_bytes = txb->payload_size; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9699 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9700 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9701 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9702 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9703 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9704 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9705 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
| 9706 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9707 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9708 | fc = le16_to_cpu(hdr->frame_ctl); |
| 9709 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9710 | |
| 9711 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); |
| 9712 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9713 | if (likely(unicast)) |
| 9714 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 9715 | |
| 9716 | if (txb->encrypted && !priv->ieee->host_encrypt) { |
| 9717 | switch (priv->ieee->sec.level) { |
| 9718 | case SEC_LEVEL_3: |
| 9719 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9720 | IEEE80211_FCTL_PROTECTED; |
| 9721 | /* XXX: ACK flag must be set for CCMP even if it |
| 9722 | * is a multicast/broadcast packet, because CCMP |
| 9723 | * group communication encrypted by GTK is |
| 9724 | * actually done by the AP. */ |
| 9725 | if (!unicast) |
| 9726 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 9727 | |
| 9728 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 9729 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; |
| 9730 | tfd->u.data.key_index = 0; |
| 9731 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; |
| 9732 | break; |
| 9733 | case SEC_LEVEL_2: |
| 9734 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9735 | IEEE80211_FCTL_PROTECTED; |
| 9736 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 9737 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; |
| 9738 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; |
| 9739 | break; |
| 9740 | case SEC_LEVEL_1: |
| 9741 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9742 | IEEE80211_FCTL_PROTECTED; |
| 9743 | tfd->u.data.key_index = priv->ieee->tx_keyidx; |
| 9744 | if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <= |
| 9745 | 40) |
| 9746 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; |
| 9747 | else |
| 9748 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; |
| 9749 | break; |
| 9750 | case SEC_LEVEL_0: |
| 9751 | break; |
| 9752 | default: |
| 9753 | printk(KERN_ERR "Unknow security level %d\n", |
| 9754 | priv->ieee->sec.level); |
| 9755 | break; |
| 9756 | } |
| 9757 | } else |
| 9758 | /* No hardware encryption */ |
| 9759 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; |
| 9760 | |
| 9761 | #ifdef CONFIG_IPW_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame^] | 9762 | if (fc & IEEE80211_STYPE_QOS_DATA) |
| 9763 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9764 | #endif /* CONFIG_IPW_QOS */ |
| 9765 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9766 | /* payload */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9767 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
| 9768 | txb->nr_frags)); |
| 9769 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", |
| 9770 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); |
| 9771 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { |
| 9772 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", |
| 9773 | i, le32_to_cpu(tfd->u.data.num_chunks), |
| 9774 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9775 | 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] | 9776 | i, tfd->u.data.num_chunks, |
| 9777 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9778 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9779 | txb->fragments[i]->len - hdr_len); |
| 9780 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9781 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9782 | cpu_to_le32(pci_map_single |
| 9783 | (priv->pci_dev, |
| 9784 | txb->fragments[i]->data + hdr_len, |
| 9785 | txb->fragments[i]->len - hdr_len, |
| 9786 | PCI_DMA_TODEVICE)); |
| 9787 | tfd->u.data.chunk_len[i] = |
| 9788 | cpu_to_le16(txb->fragments[i]->len - hdr_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9789 | } |
| 9790 | |
| 9791 | if (i != txb->nr_frags) { |
| 9792 | struct sk_buff *skb; |
| 9793 | u16 remaining_bytes = 0; |
| 9794 | int j; |
| 9795 | |
| 9796 | for (j = i; j < txb->nr_frags; j++) |
| 9797 | remaining_bytes += txb->fragments[j]->len - hdr_len; |
| 9798 | |
| 9799 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", |
| 9800 | remaining_bytes); |
| 9801 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); |
| 9802 | if (skb != NULL) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9803 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9804 | for (j = i; j < txb->nr_frags; j++) { |
| 9805 | int size = txb->fragments[j]->len - hdr_len; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9806 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9807 | printk(KERN_INFO "Adding frag %d %d...\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9808 | j, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9809 | memcpy(skb_put(skb, size), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9810 | txb->fragments[j]->data + hdr_len, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9811 | } |
| 9812 | dev_kfree_skb_any(txb->fragments[i]); |
| 9813 | txb->fragments[i] = skb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9814 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9815 | cpu_to_le32(pci_map_single |
| 9816 | (priv->pci_dev, skb->data, |
| 9817 | tfd->u.data.chunk_len[i], |
| 9818 | PCI_DMA_TODEVICE)); |
| 9819 | |
| 9820 | tfd->u.data.num_chunks = |
| 9821 | cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) + |
| 9822 | 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9823 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9824 | } |
| 9825 | |
| 9826 | /* kick DMA */ |
| 9827 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 9828 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 9829 | |
James Ketrenos | f697014 | 2006-02-14 09:10:51 +0800 | [diff] [blame] | 9830 | if (ipw_queue_space(q) < q->high_mark) |
| 9831 | netif_stop_queue(priv->net_dev); |
| 9832 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9833 | return NETDEV_TX_OK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9834 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9835 | drop: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9836 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
| 9837 | ieee80211_txb_free(txb); |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9838 | return NETDEV_TX_OK; |
| 9839 | } |
| 9840 | |
| 9841 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) |
| 9842 | { |
| 9843 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9844 | #ifdef CONFIG_IPW_QOS |
| 9845 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 9846 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 9847 | #else |
| 9848 | struct clx2_tx_queue *txq = &priv->txq[0]; |
| 9849 | #endif /* CONFIG_IPW_QOS */ |
| 9850 | |
| 9851 | if (ipw_queue_space(&txq->q) < txq->q.high_mark) |
| 9852 | return 1; |
| 9853 | |
| 9854 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9855 | } |
| 9856 | |
| 9857 | static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, |
James Ketrenos | c8d42d1 | 2005-09-21 12:23:43 -0500 | [diff] [blame] | 9858 | struct net_device *dev, int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9859 | { |
| 9860 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9861 | unsigned long flags; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9862 | int ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9863 | |
| 9864 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9865 | spin_lock_irqsave(&priv->lock, flags); |
| 9866 | |
| 9867 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 9868 | IPW_DEBUG_INFO("Tx attempt while not associated.\n"); |
| 9869 | priv->ieee->stats.tx_carrier_errors++; |
| 9870 | netif_stop_queue(dev); |
| 9871 | goto fail_unlock; |
| 9872 | } |
| 9873 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9874 | ret = ipw_tx_skb(priv, txb, pri); |
| 9875 | if (ret == NETDEV_TX_OK) |
| 9876 | __ipw_led_activity_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9877 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9878 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9879 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9880 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9881 | fail_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9882 | spin_unlock_irqrestore(&priv->lock, flags); |
| 9883 | return 1; |
| 9884 | } |
| 9885 | |
| 9886 | static struct net_device_stats *ipw_net_get_stats(struct net_device *dev) |
| 9887 | { |
| 9888 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9889 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9890 | priv->ieee->stats.tx_packets = priv->tx_packets; |
| 9891 | priv->ieee->stats.rx_packets = priv->rx_packets; |
| 9892 | return &priv->ieee->stats; |
| 9893 | } |
| 9894 | |
| 9895 | static void ipw_net_set_multicast_list(struct net_device *dev) |
| 9896 | { |
| 9897 | |
| 9898 | } |
| 9899 | |
| 9900 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) |
| 9901 | { |
| 9902 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9903 | struct sockaddr *addr = p; |
| 9904 | if (!is_valid_ether_addr(addr->sa_data)) |
| 9905 | return -EADDRNOTAVAIL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9906 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9907 | priv->config |= CFG_CUSTOM_MAC; |
| 9908 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
| 9909 | printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n", |
| 9910 | priv->net_dev->name, MAC_ARG(priv->mac_addr)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9911 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9912 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9913 | return 0; |
| 9914 | } |
| 9915 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9916 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9917 | struct ethtool_drvinfo *info) |
| 9918 | { |
| 9919 | struct ipw_priv *p = ieee80211_priv(dev); |
| 9920 | char vers[64]; |
| 9921 | char date[32]; |
| 9922 | u32 len; |
| 9923 | |
| 9924 | strcpy(info->driver, DRV_NAME); |
| 9925 | strcpy(info->version, DRV_VERSION); |
| 9926 | |
| 9927 | len = sizeof(vers); |
| 9928 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); |
| 9929 | len = sizeof(date); |
| 9930 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); |
| 9931 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9932 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9933 | vers, date); |
| 9934 | strcpy(info->bus_info, pci_name(p->pci_dev)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9935 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9936 | } |
| 9937 | |
| 9938 | static u32 ipw_ethtool_get_link(struct net_device *dev) |
| 9939 | { |
| 9940 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9941 | return (priv->status & STATUS_ASSOCIATED) != 0; |
| 9942 | } |
| 9943 | |
| 9944 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) |
| 9945 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9946 | return IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9947 | } |
| 9948 | |
| 9949 | static int ipw_ethtool_get_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9950 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9951 | { |
| 9952 | struct ipw_priv *p = ieee80211_priv(dev); |
| 9953 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9954 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9955 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9956 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9957 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9958 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9959 | return 0; |
| 9960 | } |
| 9961 | |
| 9962 | static int ipw_ethtool_set_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9963 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9964 | { |
| 9965 | struct ipw_priv *p = ieee80211_priv(dev); |
| 9966 | int i; |
| 9967 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9968 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9969 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9970 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9971 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
Adrian Bunk | 71e585f | 2006-03-11 04:42:58 +0100 | [diff] [blame] | 9972 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
| 9973 | ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9974 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9975 | return 0; |
| 9976 | } |
| 9977 | |
| 9978 | static struct ethtool_ops ipw_ethtool_ops = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9979 | .get_link = ipw_ethtool_get_link, |
| 9980 | .get_drvinfo = ipw_ethtool_get_drvinfo, |
| 9981 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, |
| 9982 | .get_eeprom = ipw_ethtool_get_eeprom, |
| 9983 | .set_eeprom = ipw_ethtool_set_eeprom, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9984 | }; |
| 9985 | |
| 9986 | static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs) |
| 9987 | { |
| 9988 | struct ipw_priv *priv = data; |
| 9989 | u32 inta, inta_mask; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9990 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9991 | if (!priv) |
| 9992 | return IRQ_NONE; |
| 9993 | |
| 9994 | spin_lock(&priv->lock); |
| 9995 | |
| 9996 | if (!(priv->status & STATUS_INT_ENABLED)) { |
| 9997 | /* Shared IRQ */ |
| 9998 | goto none; |
| 9999 | } |
| 10000 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10001 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 10002 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10003 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10004 | if (inta == 0xFFFFFFFF) { |
| 10005 | /* Hardware disappeared */ |
| 10006 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); |
| 10007 | goto none; |
| 10008 | } |
| 10009 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10010 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10011 | /* Shared interrupt */ |
| 10012 | goto none; |
| 10013 | } |
| 10014 | |
| 10015 | /* tell the device to stop sending interrupts */ |
| 10016 | ipw_disable_interrupts(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10017 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10018 | /* ack current interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10019 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
| 10020 | ipw_write32(priv, IPW_INTA_RW, inta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10021 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10022 | /* Cache INTA value for our tasklet */ |
| 10023 | priv->isr_inta = inta; |
| 10024 | |
| 10025 | tasklet_schedule(&priv->irq_tasklet); |
| 10026 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10027 | spin_unlock(&priv->lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10028 | |
| 10029 | return IRQ_HANDLED; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10030 | none: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10031 | spin_unlock(&priv->lock); |
| 10032 | return IRQ_NONE; |
| 10033 | } |
| 10034 | |
| 10035 | static void ipw_rf_kill(void *adapter) |
| 10036 | { |
| 10037 | struct ipw_priv *priv = adapter; |
| 10038 | unsigned long flags; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10039 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10040 | spin_lock_irqsave(&priv->lock, flags); |
| 10041 | |
| 10042 | if (rf_kill_active(priv)) { |
| 10043 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); |
| 10044 | if (priv->workqueue) |
| 10045 | queue_delayed_work(priv->workqueue, |
| 10046 | &priv->rf_kill, 2 * HZ); |
| 10047 | goto exit_unlock; |
| 10048 | } |
| 10049 | |
| 10050 | /* RF Kill is now disabled, so bring the device back up */ |
| 10051 | |
| 10052 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 10053 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " |
| 10054 | "device\n"); |
| 10055 | |
| 10056 | /* we can not do an adapter restart while inside an irq lock */ |
| 10057 | queue_work(priv->workqueue, &priv->adapter_restart); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10058 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10059 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
| 10060 | "enabled\n"); |
| 10061 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10062 | exit_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10063 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10064 | } |
| 10065 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10066 | static void ipw_bg_rf_kill(void *data) |
| 10067 | { |
| 10068 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10069 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10070 | ipw_rf_kill(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10071 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10072 | } |
| 10073 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10074 | static void ipw_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10075 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10076 | priv->last_seq_num = -1; |
| 10077 | priv->last_frag_num = -1; |
| 10078 | priv->last_packet_time = 0; |
| 10079 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10080 | netif_carrier_on(priv->net_dev); |
| 10081 | if (netif_queue_stopped(priv->net_dev)) { |
| 10082 | IPW_DEBUG_NOTIF("waking queue\n"); |
| 10083 | netif_wake_queue(priv->net_dev); |
| 10084 | } else { |
| 10085 | IPW_DEBUG_NOTIF("starting queue\n"); |
| 10086 | netif_start_queue(priv->net_dev); |
| 10087 | } |
| 10088 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10089 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10090 | ipw_reset_stats(priv); |
| 10091 | /* Ensure the rate is updated immediately */ |
| 10092 | priv->last_rate = ipw_get_current_rate(priv); |
| 10093 | ipw_gather_stats(priv); |
| 10094 | ipw_led_link_up(priv); |
| 10095 | notify_wx_assoc_event(priv); |
| 10096 | |
| 10097 | if (priv->config & CFG_BACKGROUND_SCAN) |
| 10098 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); |
| 10099 | } |
| 10100 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10101 | static void ipw_bg_link_up(void *data) |
| 10102 | { |
| 10103 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10104 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10105 | ipw_link_up(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10106 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10107 | } |
| 10108 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10109 | static void ipw_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10110 | { |
| 10111 | ipw_led_link_down(priv); |
| 10112 | netif_carrier_off(priv->net_dev); |
| 10113 | netif_stop_queue(priv->net_dev); |
| 10114 | notify_wx_assoc_event(priv); |
| 10115 | |
| 10116 | /* Cancel any queued work ... */ |
| 10117 | cancel_delayed_work(&priv->request_scan); |
| 10118 | cancel_delayed_work(&priv->adhoc_check); |
| 10119 | cancel_delayed_work(&priv->gather_stats); |
| 10120 | |
| 10121 | ipw_reset_stats(priv); |
| 10122 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10123 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
| 10124 | /* Queue up another scan... */ |
| 10125 | queue_work(priv->workqueue, &priv->request_scan); |
| 10126 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10127 | } |
| 10128 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10129 | static void ipw_bg_link_down(void *data) |
| 10130 | { |
| 10131 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10132 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10133 | ipw_link_down(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10134 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10135 | } |
| 10136 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10137 | static int ipw_setup_deferred_work(struct ipw_priv *priv) |
| 10138 | { |
| 10139 | int ret = 0; |
| 10140 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10141 | priv->workqueue = create_workqueue(DRV_NAME); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10142 | init_waitqueue_head(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10143 | init_waitqueue_head(&priv->wait_state); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10144 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10145 | INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv); |
| 10146 | INIT_WORK(&priv->associate, ipw_bg_associate, priv); |
| 10147 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv); |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 10148 | INIT_WORK(&priv->system_config, ipw_system_config, priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10149 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv); |
| 10150 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv); |
| 10151 | INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv); |
| 10152 | INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv); |
| 10153 | INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10154 | INIT_WORK(&priv->request_scan, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10155 | (void (*)(void *))ipw_request_scan, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10156 | INIT_WORK(&priv->gather_stats, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10157 | (void (*)(void *))ipw_bg_gather_stats, priv); |
| 10158 | INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv); |
| 10159 | INIT_WORK(&priv->roam, ipw_bg_roam, priv); |
| 10160 | INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv); |
| 10161 | INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv); |
| 10162 | INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv); |
| 10163 | INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10164 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10165 | INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10166 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10167 | INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off, |
| 10168 | priv); |
| 10169 | INIT_WORK(&priv->merge_networks, |
| 10170 | (void (*)(void *))ipw_merge_adhoc_network, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10171 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10172 | #ifdef CONFIG_IPW_QOS |
| 10173 | INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate, |
| 10174 | priv); |
| 10175 | #endif /* CONFIG_IPW_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10176 | |
| 10177 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 10178 | ipw_irq_tasklet, (unsigned long)priv); |
| 10179 | |
| 10180 | return ret; |
| 10181 | } |
| 10182 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10183 | static void shim__set_security(struct net_device *dev, |
| 10184 | struct ieee80211_security *sec) |
| 10185 | { |
| 10186 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10187 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10188 | for (i = 0; i < 4; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10189 | if (sec->flags & (1 << i)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10190 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10191 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10192 | if (sec->key_sizes[i] == 0) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10193 | priv->ieee->sec.flags &= ~(1 << i); |
| 10194 | else { |
| 10195 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10196 | sec->key_sizes[i]); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10197 | priv->ieee->sec.flags |= (1 << i); |
| 10198 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10199 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10200 | } else if (sec->level != SEC_LEVEL_1) |
| 10201 | priv->ieee->sec.flags &= ~(1 << i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10202 | } |
| 10203 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10204 | if (sec->flags & SEC_ACTIVE_KEY) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10205 | if (sec->active_key <= 3) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10206 | priv->ieee->sec.active_key = sec->active_key; |
| 10207 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10208 | } else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10209 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10210 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10211 | } else |
| 10212 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10213 | |
| 10214 | if ((sec->flags & SEC_AUTH_MODE) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10215 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
| 10216 | priv->ieee->sec.auth_mode = sec->auth_mode; |
| 10217 | priv->ieee->sec.flags |= SEC_AUTH_MODE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10218 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
| 10219 | priv->capability |= CAP_SHARED_KEY; |
| 10220 | else |
| 10221 | priv->capability &= ~CAP_SHARED_KEY; |
| 10222 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10223 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10224 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10225 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
| 10226 | priv->ieee->sec.flags |= SEC_ENABLED; |
| 10227 | priv->ieee->sec.enabled = sec->enabled; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10228 | priv->status |= STATUS_SECURITY_UPDATED; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10229 | if (sec->enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10230 | priv->capability |= CAP_PRIVACY_ON; |
| 10231 | else |
| 10232 | priv->capability &= ~CAP_PRIVACY_ON; |
| 10233 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10234 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10235 | if (sec->flags & SEC_ENCRYPT) |
| 10236 | priv->ieee->sec.encrypt = sec->encrypt; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10237 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10238 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
| 10239 | priv->ieee->sec.level = sec->level; |
| 10240 | priv->ieee->sec.flags |= SEC_LEVEL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10241 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10242 | } |
| 10243 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 10244 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
| 10245 | ipw_set_hwcrypto_keys(priv); |
| 10246 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10247 | /* To match current functionality of ipw2100 (which works well w/ |
| 10248 | * various supplicants, we don't force a disassociate if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10249 | * privacy capability changes ... */ |
| 10250 | #if 0 |
| 10251 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10252 | (((priv->assoc_request.capability & |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10253 | WLAN_CAPABILITY_PRIVACY) && !sec->enabled) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10254 | (!(priv->assoc_request.capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10255 | WLAN_CAPABILITY_PRIVACY) && sec->enabled))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10256 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
| 10257 | "change.\n"); |
| 10258 | ipw_disassociate(priv); |
| 10259 | } |
| 10260 | #endif |
| 10261 | } |
| 10262 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10263 | static int init_supported_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10264 | struct ipw_supported_rates *rates) |
| 10265 | { |
| 10266 | /* TODO: Mask out rates based on priv->rates_mask */ |
| 10267 | |
| 10268 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10269 | /* configure supported rates */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10270 | switch (priv->ieee->freq_band) { |
| 10271 | case IEEE80211_52GHZ_BAND: |
| 10272 | rates->ieee_mode = IPW_A_MODE; |
| 10273 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10274 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10275 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10276 | break; |
| 10277 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10278 | default: /* Mixed or 2.4Ghz */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10279 | rates->ieee_mode = IPW_G_MODE; |
| 10280 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10281 | ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10282 | IEEE80211_CCK_DEFAULT_RATES_MASK); |
| 10283 | if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) { |
| 10284 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10285 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10286 | } |
| 10287 | break; |
| 10288 | } |
| 10289 | |
| 10290 | return 0; |
| 10291 | } |
| 10292 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10293 | static int ipw_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10294 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10295 | /* This is only called from ipw_up, which resets/reloads the firmware |
| 10296 | so, we don't need to first disable the card before we configure |
| 10297 | it */ |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 10298 | if (ipw_set_tx_power(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10299 | goto error; |
| 10300 | |
| 10301 | /* initialize adapter address */ |
| 10302 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) |
| 10303 | goto error; |
| 10304 | |
| 10305 | /* set basic system config settings */ |
| 10306 | init_sys_config(&priv->sys_config); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10307 | |
| 10308 | /* Support Bluetooth if we have BT h/w on board, and user wants to. |
| 10309 | * Does not support BT priority yet (don't abort or defer our Tx) */ |
| 10310 | if (bt_coexist) { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10311 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10312 | |
| 10313 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) |
| 10314 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10315 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10316 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
| 10317 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10318 | |= CFG_BT_COEXISTENCE_OOB; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10319 | } |
| 10320 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10321 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 10322 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 10323 | else |
| 10324 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 10325 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10326 | if (ipw_send_system_config(priv, &priv->sys_config)) |
| 10327 | goto error; |
| 10328 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10329 | init_supported_rates(priv, &priv->rates); |
| 10330 | if (ipw_send_supported_rates(priv, &priv->rates)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10331 | goto error; |
| 10332 | |
| 10333 | /* Set request-to-send threshold */ |
| 10334 | if (priv->rts_threshold) { |
| 10335 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) |
| 10336 | goto error; |
| 10337 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10338 | #ifdef CONFIG_IPW_QOS |
| 10339 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
| 10340 | ipw_qos_activate(priv, NULL); |
| 10341 | #endif /* CONFIG_IPW_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10342 | |
| 10343 | if (ipw_set_random_seed(priv)) |
| 10344 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10345 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10346 | /* final state transition to the RUN state */ |
| 10347 | if (ipw_send_host_complete(priv)) |
| 10348 | goto error; |
| 10349 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10350 | priv->status |= STATUS_INIT; |
| 10351 | |
| 10352 | ipw_led_init(priv); |
| 10353 | ipw_led_radio_on(priv); |
| 10354 | priv->notif_missed_beacons = 0; |
| 10355 | |
| 10356 | /* Set hardware WEP key if it is configured. */ |
| 10357 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 10358 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 10359 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 10360 | ipw_set_hwcrypto_keys(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10361 | |
| 10362 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10363 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10364 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10365 | return -EIO; |
| 10366 | } |
| 10367 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10368 | /* |
| 10369 | * NOTE: |
| 10370 | * |
| 10371 | * These tables have been tested in conjunction with the |
| 10372 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. |
| 10373 | * |
| 10374 | * Altering this values, using it on other hardware, or in geographies |
| 10375 | * not intended for resale of the above mentioned Intel adapters has |
| 10376 | * not been tested. |
| 10377 | * |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 10378 | * Remember to update the table in README.ipw2200 when changing this |
| 10379 | * table. |
| 10380 | * |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10381 | */ |
| 10382 | static const struct ieee80211_geo ipw_geos[] = { |
| 10383 | { /* Restricted */ |
| 10384 | "---", |
| 10385 | .bg_channels = 11, |
| 10386 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10387 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10388 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10389 | {2457, 10}, {2462, 11}}, |
| 10390 | }, |
| 10391 | |
| 10392 | { /* Custom US/Canada */ |
| 10393 | "ZZF", |
| 10394 | .bg_channels = 11, |
| 10395 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10396 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10397 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10398 | {2457, 10}, {2462, 11}}, |
| 10399 | .a_channels = 8, |
| 10400 | .a = {{5180, 36}, |
| 10401 | {5200, 40}, |
| 10402 | {5220, 44}, |
| 10403 | {5240, 48}, |
| 10404 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10405 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10406 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10407 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10408 | }, |
| 10409 | |
| 10410 | { /* Rest of World */ |
| 10411 | "ZZD", |
| 10412 | .bg_channels = 13, |
| 10413 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10414 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10415 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10416 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10417 | {2472, 13}}, |
| 10418 | }, |
| 10419 | |
| 10420 | { /* Custom USA & Europe & High */ |
| 10421 | "ZZA", |
| 10422 | .bg_channels = 11, |
| 10423 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10424 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10425 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10426 | {2457, 10}, {2462, 11}}, |
| 10427 | .a_channels = 13, |
| 10428 | .a = {{5180, 36}, |
| 10429 | {5200, 40}, |
| 10430 | {5220, 44}, |
| 10431 | {5240, 48}, |
| 10432 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10433 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10434 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10435 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10436 | {5745, 149}, |
| 10437 | {5765, 153}, |
| 10438 | {5785, 157}, |
| 10439 | {5805, 161}, |
| 10440 | {5825, 165}}, |
| 10441 | }, |
| 10442 | |
| 10443 | { /* Custom NA & Europe */ |
| 10444 | "ZZB", |
| 10445 | .bg_channels = 11, |
| 10446 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10447 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10448 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10449 | {2457, 10}, {2462, 11}}, |
| 10450 | .a_channels = 13, |
| 10451 | .a = {{5180, 36}, |
| 10452 | {5200, 40}, |
| 10453 | {5220, 44}, |
| 10454 | {5240, 48}, |
| 10455 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10456 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10457 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10458 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10459 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10460 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10461 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10462 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10463 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10464 | }, |
| 10465 | |
| 10466 | { /* Custom Japan */ |
| 10467 | "ZZC", |
| 10468 | .bg_channels = 11, |
| 10469 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10470 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10471 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10472 | {2457, 10}, {2462, 11}}, |
| 10473 | .a_channels = 4, |
| 10474 | .a = {{5170, 34}, {5190, 38}, |
| 10475 | {5210, 42}, {5230, 46}}, |
| 10476 | }, |
| 10477 | |
| 10478 | { /* Custom */ |
| 10479 | "ZZM", |
| 10480 | .bg_channels = 11, |
| 10481 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10482 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10483 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10484 | {2457, 10}, {2462, 11}}, |
| 10485 | }, |
| 10486 | |
| 10487 | { /* Europe */ |
| 10488 | "ZZE", |
| 10489 | .bg_channels = 13, |
| 10490 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10491 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10492 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10493 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10494 | {2472, 13}}, |
| 10495 | .a_channels = 19, |
| 10496 | .a = {{5180, 36}, |
| 10497 | {5200, 40}, |
| 10498 | {5220, 44}, |
| 10499 | {5240, 48}, |
| 10500 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10501 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10502 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10503 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10504 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 10505 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 10506 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 10507 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 10508 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 10509 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 10510 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 10511 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 10512 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 10513 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 10514 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10515 | }, |
| 10516 | |
| 10517 | { /* Custom Japan */ |
| 10518 | "ZZJ", |
| 10519 | .bg_channels = 14, |
| 10520 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10521 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10522 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10523 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10524 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}}, |
| 10525 | .a_channels = 4, |
| 10526 | .a = {{5170, 34}, {5190, 38}, |
| 10527 | {5210, 42}, {5230, 46}}, |
| 10528 | }, |
| 10529 | |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 10530 | { /* Rest of World */ |
| 10531 | "ZZR", |
| 10532 | .bg_channels = 14, |
| 10533 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10534 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10535 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10536 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10537 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY | |
| 10538 | IEEE80211_CH_PASSIVE_ONLY}}, |
| 10539 | }, |
| 10540 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10541 | { /* High Band */ |
| 10542 | "ZZH", |
| 10543 | .bg_channels = 13, |
| 10544 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10545 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10546 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10547 | {2457, 10}, {2462, 11}, |
| 10548 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 10549 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10550 | .a_channels = 4, |
| 10551 | .a = {{5745, 149}, {5765, 153}, |
| 10552 | {5785, 157}, {5805, 161}}, |
| 10553 | }, |
| 10554 | |
| 10555 | { /* Custom Europe */ |
| 10556 | "ZZG", |
| 10557 | .bg_channels = 13, |
| 10558 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10559 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10560 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10561 | {2457, 10}, {2462, 11}, |
| 10562 | {2467, 12}, {2472, 13}}, |
| 10563 | .a_channels = 4, |
| 10564 | .a = {{5180, 36}, {5200, 40}, |
| 10565 | {5220, 44}, {5240, 48}}, |
| 10566 | }, |
| 10567 | |
| 10568 | { /* Europe */ |
| 10569 | "ZZK", |
| 10570 | .bg_channels = 13, |
| 10571 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10572 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10573 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10574 | {2457, 10}, {2462, 11}, |
| 10575 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 10576 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10577 | .a_channels = 24, |
| 10578 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 10579 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 10580 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 10581 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 10582 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10583 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10584 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10585 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10586 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 10587 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 10588 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 10589 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 10590 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 10591 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 10592 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 10593 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 10594 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 10595 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 10596 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}, |
| 10597 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10598 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10599 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10600 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10601 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10602 | }, |
| 10603 | |
| 10604 | { /* Europe */ |
| 10605 | "ZZL", |
| 10606 | .bg_channels = 11, |
| 10607 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10608 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10609 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10610 | {2457, 10}, {2462, 11}}, |
| 10611 | .a_channels = 13, |
| 10612 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 10613 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 10614 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 10615 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 10616 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10617 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10618 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10619 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10620 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10621 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10622 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10623 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10624 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10625 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10626 | }; |
| 10627 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10628 | #define MAX_HW_RESTARTS 5 |
| 10629 | static int ipw_up(struct ipw_priv *priv) |
| 10630 | { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10631 | int rc, i, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10632 | |
| 10633 | if (priv->status & STATUS_EXIT_PENDING) |
| 10634 | return -EIO; |
| 10635 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 10636 | if (cmdlog && !priv->cmdlog) { |
| 10637 | priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog, |
| 10638 | GFP_KERNEL); |
| 10639 | if (priv->cmdlog == NULL) { |
| 10640 | IPW_ERROR("Error allocating %d command log entries.\n", |
| 10641 | cmdlog); |
| 10642 | } else { |
| 10643 | memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog); |
| 10644 | priv->cmdlog_len = cmdlog; |
| 10645 | } |
| 10646 | } |
| 10647 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10648 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10649 | /* Load the microcode, firmware, and eeprom. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10650 | * Also start the clocks. */ |
| 10651 | rc = ipw_load(priv); |
| 10652 | if (rc) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 10653 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10654 | return rc; |
| 10655 | } |
| 10656 | |
| 10657 | ipw_init_ordinals(priv); |
| 10658 | if (!(priv->config & CFG_CUSTOM_MAC)) |
| 10659 | eeprom_parse_mac(priv, priv->mac_addr); |
| 10660 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
| 10661 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10662 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
| 10663 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], |
| 10664 | ipw_geos[j].name, 3)) |
| 10665 | break; |
| 10666 | } |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 10667 | if (j == ARRAY_SIZE(ipw_geos)) { |
| 10668 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", |
| 10669 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], |
| 10670 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], |
| 10671 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10672 | j = 0; |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 10673 | } |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 10674 | if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10675 | IPW_WARNING("Could not set geography."); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10676 | return 0; |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10677 | } |
| 10678 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10679 | if (priv->status & STATUS_RF_KILL_SW) { |
| 10680 | IPW_WARNING("Radio disabled by module parameter.\n"); |
| 10681 | return 0; |
| 10682 | } else if (rf_kill_active(priv)) { |
| 10683 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" |
| 10684 | "Kill switch must be turned off for " |
| 10685 | "wireless networking to work.\n"); |
| 10686 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
| 10687 | 2 * HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10688 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10689 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10690 | |
| 10691 | rc = ipw_config(priv); |
| 10692 | if (!rc) { |
| 10693 | IPW_DEBUG_INFO("Configured device on count %i\n", i); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10694 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10695 | /* If configure to try and auto-associate, kick |
| 10696 | * off a scan. */ |
| 10697 | queue_work(priv->workqueue, &priv->request_scan); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10698 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10699 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10700 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10701 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10702 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10703 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
| 10704 | i, MAX_HW_RESTARTS); |
| 10705 | |
| 10706 | /* We had an error bringing up the hardware, so take it |
| 10707 | * all the way back down so we can try again */ |
| 10708 | ipw_down(priv); |
| 10709 | } |
| 10710 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10711 | /* tried to restart and config the device for as long as our |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10712 | * patience could withstand */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10713 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10714 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10715 | return -EIO; |
| 10716 | } |
| 10717 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10718 | static void ipw_bg_up(void *data) |
| 10719 | { |
| 10720 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10721 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10722 | ipw_up(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10723 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10724 | } |
| 10725 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10726 | static void ipw_deinit(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10727 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10728 | int i; |
| 10729 | |
| 10730 | if (priv->status & STATUS_SCANNING) { |
| 10731 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); |
| 10732 | ipw_abort_scan(priv); |
| 10733 | } |
| 10734 | |
| 10735 | if (priv->status & STATUS_ASSOCIATED) { |
| 10736 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); |
| 10737 | ipw_disassociate(priv); |
| 10738 | } |
| 10739 | |
| 10740 | ipw_led_shutdown(priv); |
| 10741 | |
| 10742 | /* Wait up to 1s for status to change to not scanning and not |
| 10743 | * associated (disassociation can take a while for a ful 802.11 |
| 10744 | * exchange */ |
| 10745 | for (i = 1000; i && (priv->status & |
| 10746 | (STATUS_DISASSOCIATING | |
| 10747 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) |
| 10748 | udelay(10); |
| 10749 | |
| 10750 | if (priv->status & (STATUS_DISASSOCIATING | |
| 10751 | STATUS_ASSOCIATED | STATUS_SCANNING)) |
| 10752 | IPW_DEBUG_INFO("Still associated or scanning...\n"); |
| 10753 | else |
| 10754 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); |
| 10755 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10756 | /* Attempt to disable the card */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10757 | ipw_send_card_disable(priv, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10758 | |
| 10759 | priv->status &= ~STATUS_INIT; |
| 10760 | } |
| 10761 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10762 | static void ipw_down(struct ipw_priv *priv) |
| 10763 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10764 | int exit_pending = priv->status & STATUS_EXIT_PENDING; |
| 10765 | |
| 10766 | priv->status |= STATUS_EXIT_PENDING; |
| 10767 | |
| 10768 | if (ipw_is_init(priv)) |
| 10769 | ipw_deinit(priv); |
| 10770 | |
| 10771 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 10772 | * exiting the module */ |
| 10773 | if (!exit_pending) |
| 10774 | priv->status &= ~STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10775 | |
| 10776 | /* tell the device to stop sending interrupts */ |
| 10777 | ipw_disable_interrupts(priv); |
| 10778 | |
| 10779 | /* Clear all bits but the RF Kill */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10780 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10781 | netif_carrier_off(priv->net_dev); |
| 10782 | netif_stop_queue(priv->net_dev); |
| 10783 | |
| 10784 | ipw_stop_nic(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10785 | |
| 10786 | ipw_led_radio_off(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10787 | } |
| 10788 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10789 | static void ipw_bg_down(void *data) |
| 10790 | { |
| 10791 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10792 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10793 | ipw_down(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10794 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10795 | } |
| 10796 | |
| 10797 | /* Called by register_netdev() */ |
| 10798 | static int ipw_net_init(struct net_device *dev) |
| 10799 | { |
| 10800 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10801 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10802 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10803 | if (ipw_up(priv)) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10804 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10805 | return -EIO; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10806 | } |
| 10807 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10808 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10809 | return 0; |
| 10810 | } |
| 10811 | |
| 10812 | /* PCI driver stuff */ |
| 10813 | static struct pci_device_id card_ids[] = { |
| 10814 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
| 10815 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, |
| 10816 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, |
| 10817 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, |
| 10818 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, |
| 10819 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, |
| 10820 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, |
| 10821 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, |
| 10822 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, |
| 10823 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, |
| 10824 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, |
| 10825 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, |
| 10826 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, |
| 10827 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, |
| 10828 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, |
| 10829 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, |
| 10830 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, |
| 10831 | {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10832 | {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10833 | {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10834 | {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ |
| 10835 | {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10836 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10837 | /* required last entry */ |
| 10838 | {0,} |
| 10839 | }; |
| 10840 | |
| 10841 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 10842 | |
| 10843 | static struct attribute *ipw_sysfs_entries[] = { |
| 10844 | &dev_attr_rf_kill.attr, |
| 10845 | &dev_attr_direct_dword.attr, |
| 10846 | &dev_attr_indirect_byte.attr, |
| 10847 | &dev_attr_indirect_dword.attr, |
| 10848 | &dev_attr_mem_gpio_reg.attr, |
| 10849 | &dev_attr_command_event_reg.attr, |
| 10850 | &dev_attr_nic_type.attr, |
| 10851 | &dev_attr_status.attr, |
| 10852 | &dev_attr_cfg.attr, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 10853 | &dev_attr_error.attr, |
| 10854 | &dev_attr_event_log.attr, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 10855 | &dev_attr_cmd_log.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10856 | &dev_attr_eeprom_delay.attr, |
| 10857 | &dev_attr_ucode_version.attr, |
| 10858 | &dev_attr_rtc.attr, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10859 | &dev_attr_scan_age.attr, |
| 10860 | &dev_attr_led.attr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10861 | &dev_attr_speed_scan.attr, |
| 10862 | &dev_attr_net_stats.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10863 | NULL |
| 10864 | }; |
| 10865 | |
| 10866 | static struct attribute_group ipw_attribute_group = { |
| 10867 | .name = NULL, /* put in device directory */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10868 | .attrs = ipw_sysfs_entries, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10869 | }; |
| 10870 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10871 | static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10872 | { |
| 10873 | int err = 0; |
| 10874 | struct net_device *net_dev; |
| 10875 | void __iomem *base; |
| 10876 | u32 length, val; |
| 10877 | struct ipw_priv *priv; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10878 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10879 | |
| 10880 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv)); |
| 10881 | if (net_dev == NULL) { |
| 10882 | err = -ENOMEM; |
| 10883 | goto out; |
| 10884 | } |
| 10885 | |
| 10886 | priv = ieee80211_priv(net_dev); |
| 10887 | priv->ieee = netdev_priv(net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10888 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10889 | priv->net_dev = net_dev; |
| 10890 | priv->pci_dev = pdev; |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 10891 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10892 | ipw_debug_level = debug; |
| 10893 | #endif |
| 10894 | spin_lock_init(&priv->lock); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10895 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
| 10896 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10897 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10898 | mutex_init(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10899 | if (pci_enable_device(pdev)) { |
| 10900 | err = -ENODEV; |
| 10901 | goto out_free_ieee80211; |
| 10902 | } |
| 10903 | |
| 10904 | pci_set_master(pdev); |
| 10905 | |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 10906 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10907 | if (!err) |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 10908 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10909 | if (err) { |
| 10910 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 10911 | goto out_pci_disable_device; |
| 10912 | } |
| 10913 | |
| 10914 | pci_set_drvdata(pdev, priv); |
| 10915 | |
| 10916 | err = pci_request_regions(pdev, DRV_NAME); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10917 | if (err) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10918 | goto out_pci_disable_device; |
| 10919 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10920 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10921 | * PCI Tx retries from interfering with C3 CPU state */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10922 | pci_read_config_dword(pdev, 0x40, &val); |
| 10923 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10924 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10925 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10926 | length = pci_resource_len(pdev, 0); |
| 10927 | priv->hw_len = length; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10928 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10929 | base = ioremap_nocache(pci_resource_start(pdev, 0), length); |
| 10930 | if (!base) { |
| 10931 | err = -ENODEV; |
| 10932 | goto out_pci_release_regions; |
| 10933 | } |
| 10934 | |
| 10935 | priv->hw_base = base; |
| 10936 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); |
| 10937 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); |
| 10938 | |
| 10939 | err = ipw_setup_deferred_work(priv); |
| 10940 | if (err) { |
| 10941 | IPW_ERROR("Unable to setup deferred work\n"); |
| 10942 | goto out_iounmap; |
| 10943 | } |
| 10944 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10945 | ipw_sw_reset(priv, 1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10946 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10947 | err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10948 | if (err) { |
| 10949 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 10950 | goto out_destroy_workqueue; |
| 10951 | } |
| 10952 | |
| 10953 | SET_MODULE_OWNER(net_dev); |
| 10954 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
| 10955 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10956 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10957 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10958 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
| 10959 | priv->ieee->set_security = shim__set_security; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10960 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10961 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10962 | #ifdef CONFIG_IPW_QOS |
Zhu Yi | a5cf4fe | 2006-04-13 17:19:11 +0800 | [diff] [blame^] | 10963 | priv->ieee->is_qos_active = ipw_is_qos_active; |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 10964 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
| 10965 | priv->ieee->handle_beacon = ipw_handle_probe_response; |
| 10966 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10967 | #endif /* CONFIG_IPW_QOS */ |
| 10968 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10969 | priv->ieee->perfect_rssi = -20; |
| 10970 | priv->ieee->worst_rssi = -85; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10971 | |
| 10972 | net_dev->open = ipw_net_open; |
| 10973 | net_dev->stop = ipw_net_stop; |
| 10974 | net_dev->init = ipw_net_init; |
| 10975 | net_dev->get_stats = ipw_net_get_stats; |
| 10976 | net_dev->set_multicast_list = ipw_net_set_multicast_list; |
| 10977 | net_dev->set_mac_address = ipw_net_set_mac_address; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 10978 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 10979 | net_dev->wireless_data = &priv->wireless_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10980 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
| 10981 | net_dev->ethtool_ops = &ipw_ethtool_ops; |
| 10982 | net_dev->irq = pdev->irq; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10983 | net_dev->base_addr = (unsigned long)priv->hw_base; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10984 | net_dev->mem_start = pci_resource_start(pdev, 0); |
| 10985 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; |
| 10986 | |
| 10987 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 10988 | if (err) { |
| 10989 | IPW_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10990 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10991 | goto out_release_irq; |
| 10992 | } |
| 10993 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10994 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10995 | err = register_netdev(net_dev); |
| 10996 | if (err) { |
| 10997 | IPW_ERROR("failed to register network device\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10998 | goto out_remove_sysfs; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10999 | } |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11000 | |
| 11001 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " |
| 11002 | "channels, %d 802.11a channels)\n", |
| 11003 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, |
| 11004 | priv->ieee->geo.a_channels); |
| 11005 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11006 | return 0; |
| 11007 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11008 | out_remove_sysfs: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11009 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11010 | out_release_irq: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11011 | free_irq(pdev->irq, priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11012 | out_destroy_workqueue: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11013 | destroy_workqueue(priv->workqueue); |
| 11014 | priv->workqueue = NULL; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11015 | out_iounmap: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11016 | iounmap(priv->hw_base); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11017 | out_pci_release_regions: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11018 | pci_release_regions(pdev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11019 | out_pci_disable_device: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11020 | pci_disable_device(pdev); |
| 11021 | pci_set_drvdata(pdev, NULL); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11022 | out_free_ieee80211: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11023 | free_ieee80211(priv->net_dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11024 | out: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11025 | return err; |
| 11026 | } |
| 11027 | |
| 11028 | static void ipw_pci_remove(struct pci_dev *pdev) |
| 11029 | { |
| 11030 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11031 | struct list_head *p, *q; |
| 11032 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11033 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11034 | if (!priv) |
| 11035 | return; |
| 11036 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11037 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11038 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11039 | priv->status |= STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11040 | ipw_down(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11041 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11042 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11043 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11044 | |
| 11045 | unregister_netdev(priv->net_dev); |
| 11046 | |
| 11047 | if (priv->rxq) { |
| 11048 | ipw_rx_queue_free(priv, priv->rxq); |
| 11049 | priv->rxq = NULL; |
| 11050 | } |
| 11051 | ipw_tx_queue_free(priv); |
| 11052 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11053 | if (priv->cmdlog) { |
| 11054 | kfree(priv->cmdlog); |
| 11055 | priv->cmdlog = NULL; |
| 11056 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11057 | /* ipw_down will ensure that there is no more pending work |
| 11058 | * in the workqueue's, so we can safely remove them now. */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11059 | cancel_delayed_work(&priv->adhoc_check); |
| 11060 | cancel_delayed_work(&priv->gather_stats); |
| 11061 | cancel_delayed_work(&priv->request_scan); |
| 11062 | cancel_delayed_work(&priv->rf_kill); |
| 11063 | cancel_delayed_work(&priv->scan_check); |
| 11064 | destroy_workqueue(priv->workqueue); |
| 11065 | priv->workqueue = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11066 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11067 | /* Free MAC hash list for ADHOC */ |
| 11068 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { |
| 11069 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11070 | list_del(p); |
Zhu Yi | 489f445 | 2006-01-24 16:37:41 +0800 | [diff] [blame] | 11071 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11072 | } |
| 11073 | } |
| 11074 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 11075 | if (priv->error) { |
| 11076 | ipw_free_error_log(priv->error); |
| 11077 | priv->error = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11078 | } |
| 11079 | |
| 11080 | free_irq(pdev->irq, priv); |
| 11081 | iounmap(priv->hw_base); |
| 11082 | pci_release_regions(pdev); |
| 11083 | pci_disable_device(pdev); |
| 11084 | pci_set_drvdata(pdev, NULL); |
| 11085 | free_ieee80211(priv->net_dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11086 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11087 | } |
| 11088 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11089 | #ifdef CONFIG_PM |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11090 | 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] | 11091 | { |
| 11092 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11093 | struct net_device *dev = priv->net_dev; |
| 11094 | |
| 11095 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); |
| 11096 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11097 | /* Take down the device; powers it off, etc. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11098 | ipw_down(priv); |
| 11099 | |
| 11100 | /* Remove the PRESENT state of the device */ |
| 11101 | netif_device_detach(dev); |
| 11102 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11103 | pci_save_state(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11104 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11105 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11106 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11107 | return 0; |
| 11108 | } |
| 11109 | |
| 11110 | static int ipw_pci_resume(struct pci_dev *pdev) |
| 11111 | { |
| 11112 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11113 | struct net_device *dev = priv->net_dev; |
| 11114 | u32 val; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11115 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11116 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
| 11117 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11118 | pci_set_power_state(pdev, PCI_D0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11119 | pci_enable_device(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11120 | pci_restore_state(pdev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11121 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11122 | /* |
| 11123 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 11124 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 11125 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 11126 | * here since it only restores the first 64 bytes pci config header. |
| 11127 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11128 | pci_read_config_dword(pdev, 0x40, &val); |
| 11129 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11130 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 11131 | |
| 11132 | /* Set the device back into the PRESENT state; this will also wake |
| 11133 | * the queue of needed */ |
| 11134 | netif_device_attach(dev); |
| 11135 | |
| 11136 | /* Bring the device back up */ |
| 11137 | queue_work(priv->workqueue, &priv->up); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11138 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11139 | return 0; |
| 11140 | } |
| 11141 | #endif |
| 11142 | |
| 11143 | /* driver initialization stuff */ |
| 11144 | static struct pci_driver ipw_driver = { |
| 11145 | .name = DRV_NAME, |
| 11146 | .id_table = card_ids, |
| 11147 | .probe = ipw_pci_probe, |
| 11148 | .remove = __devexit_p(ipw_pci_remove), |
| 11149 | #ifdef CONFIG_PM |
| 11150 | .suspend = ipw_pci_suspend, |
| 11151 | .resume = ipw_pci_resume, |
| 11152 | #endif |
| 11153 | }; |
| 11154 | |
| 11155 | static int __init ipw_init(void) |
| 11156 | { |
| 11157 | int ret; |
| 11158 | |
| 11159 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 11160 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 11161 | |
| 11162 | ret = pci_module_init(&ipw_driver); |
| 11163 | if (ret) { |
| 11164 | IPW_ERROR("Unable to initialize PCI module\n"); |
| 11165 | return ret; |
| 11166 | } |
| 11167 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11168 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11169 | if (ret) { |
| 11170 | IPW_ERROR("Unable to create driver sysfs file\n"); |
| 11171 | pci_unregister_driver(&ipw_driver); |
| 11172 | return ret; |
| 11173 | } |
| 11174 | |
| 11175 | return ret; |
| 11176 | } |
| 11177 | |
| 11178 | static void __exit ipw_exit(void) |
| 11179 | { |
| 11180 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); |
| 11181 | pci_unregister_driver(&ipw_driver); |
| 11182 | } |
| 11183 | |
| 11184 | module_param(disable, int, 0444); |
| 11185 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 11186 | |
| 11187 | module_param(associate, int, 0444); |
| 11188 | MODULE_PARM_DESC(associate, "auto associate when scanning (default on)"); |
| 11189 | |
| 11190 | module_param(auto_create, int, 0444); |
| 11191 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); |
| 11192 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11193 | module_param(led, int, 0444); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11194 | MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11195 | |
Zhu Yi | 3e1555b | 2006-03-06 05:48:37 +0800 | [diff] [blame] | 11196 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11197 | module_param(debug, int, 0444); |
| 11198 | MODULE_PARM_DESC(debug, "debug output mask"); |
Zhu Yi | 3e1555b | 2006-03-06 05:48:37 +0800 | [diff] [blame] | 11199 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11200 | |
| 11201 | module_param(channel, int, 0444); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11202 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11203 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11204 | #ifdef CONFIG_IPW_QOS |
| 11205 | module_param(qos_enable, int, 0444); |
| 11206 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11207 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11208 | module_param(qos_burst_enable, int, 0444); |
| 11209 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); |
| 11210 | |
| 11211 | module_param(qos_no_ack_mask, int, 0444); |
| 11212 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); |
| 11213 | |
| 11214 | module_param(burst_duration_CCK, int, 0444); |
| 11215 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); |
| 11216 | |
| 11217 | module_param(burst_duration_OFDM, int, 0444); |
| 11218 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); |
| 11219 | #endif /* CONFIG_IPW_QOS */ |
| 11220 | |
| 11221 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11222 | module_param(mode, int, 0444); |
| 11223 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); |
| 11224 | #else |
| 11225 | module_param(mode, int, 0444); |
| 11226 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
| 11227 | #endif |
| 11228 | |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 11229 | module_param(bt_coexist, int, 0444); |
| 11230 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); |
| 11231 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11232 | module_param(hwcrypto, int, 0444); |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 11233 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11234 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11235 | module_param(cmdlog, int, 0444); |
| 11236 | MODULE_PARM_DESC(cmdlog, |
| 11237 | "allocate a ring buffer for logging firmware commands"); |
| 11238 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 11239 | module_param(roaming, int, 0444); |
| 11240 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); |
| 11241 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11242 | module_exit(ipw_exit); |
| 11243 | module_init(ipw_init); |