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 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3 | Copyright(c) 2003 - 2005 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 | 7c97eb3 | 2006-01-24 16:37:47 +0800 | [diff] [blame] | 36 | #define IPW2200_VERSION "git-1.0.10" |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 37 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 38 | #define DRV_COPYRIGHT "Copyright(c) 2003-2005 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 | |
| 2832 | struct fw_header { |
| 2833 | u32 version; |
| 2834 | u32 mode; |
| 2835 | }; |
| 2836 | |
| 2837 | struct fw_chunk { |
| 2838 | u32 address; |
| 2839 | u32 length; |
| 2840 | }; |
| 2841 | |
| 2842 | #define IPW_FW_MAJOR_VERSION 2 |
James Ketrenos | 8171537 | 2005-08-25 01:37:28 -0500 | [diff] [blame] | 2843 | #define IPW_FW_MINOR_VERSION 4 |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2844 | |
| 2845 | #define IPW_FW_MINOR(x) ((x & 0xff) >> 8) |
| 2846 | #define IPW_FW_MAJOR(x) (x & 0xff) |
| 2847 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2848 | #define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2849 | |
| 2850 | #define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \ |
| 2851 | "." __stringify(IPW_FW_MINOR_VERSION) "-" |
| 2852 | |
| 2853 | #if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0 |
| 2854 | #define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw" |
| 2855 | #else |
| 2856 | #define IPW_FW_NAME(x) "ipw2200_" x ".fw" |
| 2857 | #endif |
| 2858 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2859 | 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] | 2860 | { |
| 2861 | int rc = 0, i, addr; |
| 2862 | u8 cr = 0; |
| 2863 | u16 *image; |
| 2864 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2865 | image = (u16 *) data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2866 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2867 | IPW_DEBUG_TRACE(">> \n"); |
| 2868 | |
| 2869 | rc = ipw_stop_master(priv); |
| 2870 | |
| 2871 | if (rc < 0) |
| 2872 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2873 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2874 | // spin_lock_irqsave(&priv->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2875 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2876 | for (addr = IPW_SHARED_LOWER_BOUND; |
| 2877 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2878 | ipw_write32(priv, addr, 0); |
| 2879 | } |
| 2880 | |
| 2881 | /* no ucode (yet) */ |
| 2882 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); |
| 2883 | /* destroy DMA queues */ |
| 2884 | /* reset sequence */ |
| 2885 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2886 | 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] | 2887 | ipw_arc_release(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2888 | 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] | 2889 | mdelay(1); |
| 2890 | |
| 2891 | /* reset PHY */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2892 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2893 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2894 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2895 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2896 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2897 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2898 | /* enable ucode store */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 2899 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
| 2900 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2901 | mdelay(1); |
| 2902 | |
| 2903 | /* write ucode */ |
| 2904 | /** |
| 2905 | * @bug |
| 2906 | * Do NOT set indirect address register once and then |
| 2907 | * store data to indirect data register in the loop. |
| 2908 | * It seems very reasonable, but in this case DINO do not |
| 2909 | * accept ucode. It is essential to set address each time. |
| 2910 | */ |
| 2911 | /* load new ipw uCode */ |
| 2912 | for (i = 0; i < len / 2; i++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2913 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2914 | cpu_to_le16(image[i])); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2915 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2916 | /* enable DINO */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2917 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
| 2918 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2919 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2920 | /* this is where the igx / win driver deveates from the VAP driver. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2921 | |
| 2922 | /* wait for alive response */ |
| 2923 | for (i = 0; i < 100; i++) { |
| 2924 | /* poll for incoming data */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2925 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2926 | if (cr & DINO_RXFIFO_DATA) |
| 2927 | break; |
| 2928 | mdelay(1); |
| 2929 | } |
| 2930 | |
| 2931 | if (cr & DINO_RXFIFO_DATA) { |
| 2932 | /* alive_command_responce size is NOT multiple of 4 */ |
| 2933 | u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2934 | |
| 2935 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2936 | response_buffer[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2937 | le32_to_cpu(ipw_read_reg32(priv, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2938 | IPW_BASEBAND_RX_FIFO_READ)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2939 | memcpy(&priv->dino_alive, response_buffer, |
| 2940 | sizeof(priv->dino_alive)); |
| 2941 | if (priv->dino_alive.alive_command == 1 |
| 2942 | && priv->dino_alive.ucode_valid == 1) { |
| 2943 | rc = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2944 | IPW_DEBUG_INFO |
| 2945 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " |
| 2946 | "of %02d/%02d/%02d %02d:%02d\n", |
| 2947 | priv->dino_alive.software_revision, |
| 2948 | priv->dino_alive.software_revision, |
| 2949 | priv->dino_alive.device_identifier, |
| 2950 | priv->dino_alive.device_identifier, |
| 2951 | priv->dino_alive.time_stamp[0], |
| 2952 | priv->dino_alive.time_stamp[1], |
| 2953 | priv->dino_alive.time_stamp[2], |
| 2954 | priv->dino_alive.time_stamp[3], |
| 2955 | priv->dino_alive.time_stamp[4]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2956 | } else { |
| 2957 | IPW_DEBUG_INFO("Microcode is not alive\n"); |
| 2958 | rc = -EINVAL; |
| 2959 | } |
| 2960 | } else { |
| 2961 | IPW_DEBUG_INFO("No alive response from DINO\n"); |
| 2962 | rc = -ETIME; |
| 2963 | } |
| 2964 | |
| 2965 | /* disable DINO, otherwise for some reason |
| 2966 | firmware have problem getting alive resp. */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2967 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2968 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2969 | // spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2970 | |
| 2971 | return rc; |
| 2972 | } |
| 2973 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2974 | 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] | 2975 | { |
| 2976 | int rc = -1; |
| 2977 | int offset = 0; |
| 2978 | struct fw_chunk *chunk; |
| 2979 | dma_addr_t shared_phys; |
| 2980 | u8 *shared_virt; |
| 2981 | |
| 2982 | IPW_DEBUG_TRACE("<< : \n"); |
| 2983 | shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys); |
| 2984 | |
| 2985 | if (!shared_virt) |
| 2986 | return -ENOMEM; |
| 2987 | |
| 2988 | memmove(shared_virt, data, len); |
| 2989 | |
| 2990 | /* Start the Dma */ |
| 2991 | rc = ipw_fw_dma_enable(priv); |
| 2992 | |
| 2993 | if (priv->sram_desc.last_cb_index > 0) { |
| 2994 | /* the DMA is already ready this would be a bug. */ |
| 2995 | BUG(); |
| 2996 | goto out; |
| 2997 | } |
| 2998 | |
| 2999 | do { |
| 3000 | chunk = (struct fw_chunk *)(data + offset); |
| 3001 | offset += sizeof(struct fw_chunk); |
| 3002 | /* build DMA packet and queue up for sending */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3003 | /* dma to chunk->address, the chunk->length bytes from data + |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3004 | * offeset*/ |
| 3005 | /* Dma loading */ |
| 3006 | rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3007 | le32_to_cpu(chunk->address), |
| 3008 | le32_to_cpu(chunk->length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3009 | if (rc) { |
| 3010 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
| 3011 | goto out; |
| 3012 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3013 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3014 | offset += le32_to_cpu(chunk->length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3015 | } while (offset < len); |
| 3016 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3017 | /* Run the DMA and wait for the answer */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3018 | rc = ipw_fw_dma_kick(priv); |
| 3019 | if (rc) { |
| 3020 | IPW_ERROR("dmaKick Failed\n"); |
| 3021 | goto out; |
| 3022 | } |
| 3023 | |
| 3024 | rc = ipw_fw_dma_wait(priv); |
| 3025 | if (rc) { |
| 3026 | IPW_ERROR("dmaWaitSync Failed\n"); |
| 3027 | goto out; |
| 3028 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3029 | out: |
| 3030 | pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3031 | return rc; |
| 3032 | } |
| 3033 | |
| 3034 | /* stop nic */ |
| 3035 | static int ipw_stop_nic(struct ipw_priv *priv) |
| 3036 | { |
| 3037 | int rc = 0; |
| 3038 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3039 | /* stop */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3040 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3041 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3042 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3043 | IPW_RESET_REG_MASTER_DISABLED, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3044 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3045 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3046 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3047 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3048 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3049 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3050 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3051 | return rc; |
| 3052 | } |
| 3053 | |
| 3054 | static void ipw_start_nic(struct ipw_priv *priv) |
| 3055 | { |
| 3056 | IPW_DEBUG_TRACE(">>\n"); |
| 3057 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3058 | /* prvHwStartNic release ARC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3059 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 3060 | IPW_RESET_REG_MASTER_DISABLED | |
| 3061 | IPW_RESET_REG_STOP_MASTER | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3062 | CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3063 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3064 | /* enable power management */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3065 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
| 3066 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3067 | |
| 3068 | IPW_DEBUG_TRACE("<<\n"); |
| 3069 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3070 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3071 | static int ipw_init_nic(struct ipw_priv *priv) |
| 3072 | { |
| 3073 | int rc; |
| 3074 | |
| 3075 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3076 | /* reset */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3077 | /*prvHwInitNic */ |
| 3078 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3079 | 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] | 3080 | |
| 3081 | /* low-level PLL activation */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3082 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
| 3083 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3084 | |
| 3085 | /* wait for clock stabilization */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3086 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
| 3087 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3088 | if (rc < 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3089 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
| 3090 | |
| 3091 | /* assert SW reset */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3092 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3093 | |
| 3094 | udelay(10); |
| 3095 | |
| 3096 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3097 | 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] | 3098 | |
| 3099 | IPW_DEBUG_TRACE(">>\n"); |
| 3100 | return 0; |
| 3101 | } |
| 3102 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3103 | /* Call this function from process context, it will sleep in request_firmware. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3104 | * Probe is an ok place to call this from. |
| 3105 | */ |
| 3106 | static int ipw_reset_nic(struct ipw_priv *priv) |
| 3107 | { |
| 3108 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3109 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3110 | |
| 3111 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3112 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3113 | rc = ipw_init_nic(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3114 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3115 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3116 | /* Clear the 'host command active' bit... */ |
| 3117 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 3118 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3119 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 3120 | wake_up_interruptible(&priv->wait_state); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3121 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3122 | |
| 3123 | IPW_DEBUG_TRACE("<<\n"); |
| 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 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3127 | static int ipw_get_fw(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3128 | const struct firmware **fw, const char *name) |
| 3129 | { |
| 3130 | struct fw_header *header; |
| 3131 | int rc; |
| 3132 | |
| 3133 | /* ask firmware_class module to get the boot firmware off disk */ |
| 3134 | rc = request_firmware(fw, name, &priv->pci_dev->dev); |
| 3135 | if (rc < 0) { |
| 3136 | IPW_ERROR("%s load failed: Reason %d\n", name, rc); |
| 3137 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3138 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3139 | |
| 3140 | header = (struct fw_header *)(*fw)->data; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3141 | if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3142 | IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n", |
| 3143 | name, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3144 | IPW_FW_MAJOR(le32_to_cpu(header->version)), |
| 3145 | IPW_FW_MAJOR_VERSION); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3146 | return -EINVAL; |
| 3147 | } |
| 3148 | |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3149 | IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3150 | name, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3151 | IPW_FW_MAJOR(le32_to_cpu(header->version)), |
| 3152 | IPW_FW_MINOR(le32_to_cpu(header->version)), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3153 | (*fw)->size - sizeof(struct fw_header)); |
| 3154 | return 0; |
| 3155 | } |
| 3156 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3157 | #define IPW_RX_BUF_SIZE (3000) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3158 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3159 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3160 | struct ipw_rx_queue *rxq) |
| 3161 | { |
| 3162 | unsigned long flags; |
| 3163 | int i; |
| 3164 | |
| 3165 | spin_lock_irqsave(&rxq->lock, flags); |
| 3166 | |
| 3167 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3168 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3169 | |
| 3170 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3171 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3172 | /* In the reset function, these buffers may have been allocated |
| 3173 | * to an SKB, so we need to unmap and free potential storage */ |
| 3174 | if (rxq->pool[i].skb != NULL) { |
| 3175 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3176 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3177 | dev_kfree_skb(rxq->pool[i].skb); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3178 | rxq->pool[i].skb = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3179 | } |
| 3180 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3181 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3182 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3183 | /* Set us so that we have processed and used all buffers, but have |
| 3184 | * not restocked the Rx queue with fresh buffers */ |
| 3185 | rxq->read = rxq->write = 0; |
| 3186 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 3187 | rxq->free_count = 0; |
| 3188 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3189 | } |
| 3190 | |
| 3191 | #ifdef CONFIG_PM |
| 3192 | static int fw_loaded = 0; |
| 3193 | static const struct firmware *bootfw = NULL; |
| 3194 | static const struct firmware *firmware = NULL; |
| 3195 | static const struct firmware *ucode = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3196 | |
| 3197 | static void free_firmware(void) |
| 3198 | { |
| 3199 | if (fw_loaded) { |
| 3200 | release_firmware(bootfw); |
| 3201 | release_firmware(ucode); |
| 3202 | release_firmware(firmware); |
| 3203 | bootfw = ucode = firmware = NULL; |
| 3204 | fw_loaded = 0; |
| 3205 | } |
| 3206 | } |
| 3207 | #else |
| 3208 | #define free_firmware() do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3209 | #endif |
| 3210 | |
| 3211 | static int ipw_load(struct ipw_priv *priv) |
| 3212 | { |
| 3213 | #ifndef CONFIG_PM |
| 3214 | const struct firmware *bootfw = NULL; |
| 3215 | const struct firmware *firmware = NULL; |
| 3216 | const struct firmware *ucode = NULL; |
| 3217 | #endif |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3218 | char *ucode_name; |
| 3219 | char *fw_name; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3220 | int rc = 0, retries = 3; |
| 3221 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3222 | switch (priv->ieee->iw_mode) { |
| 3223 | case IW_MODE_ADHOC: |
| 3224 | ucode_name = IPW_FW_NAME("ibss_ucode"); |
| 3225 | fw_name = IPW_FW_NAME("ibss"); |
| 3226 | break; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3227 | #ifdef CONFIG_IPW2200_MONITOR |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3228 | case IW_MODE_MONITOR: |
| 3229 | ucode_name = IPW_FW_NAME("sniffer_ucode"); |
| 3230 | fw_name = IPW_FW_NAME("sniffer"); |
| 3231 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3232 | #endif |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3233 | case IW_MODE_INFRA: |
| 3234 | ucode_name = IPW_FW_NAME("bss_ucode"); |
| 3235 | fw_name = IPW_FW_NAME("bss"); |
| 3236 | break; |
| 3237 | default: |
| 3238 | rc = -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3239 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3240 | |
| 3241 | if (rc < 0) |
| 3242 | goto error; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3243 | |
| 3244 | if (!priv->rxq) |
| 3245 | priv->rxq = ipw_rx_queue_alloc(priv); |
| 3246 | else |
| 3247 | ipw_rx_queue_reset(priv, priv->rxq); |
| 3248 | if (!priv->rxq) { |
| 3249 | IPW_ERROR("Unable to initialize Rx queue\n"); |
| 3250 | goto error; |
| 3251 | } |
| 3252 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3253 | retry: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3254 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3255 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3256 | priv->status &= ~STATUS_INT_ENABLED; |
| 3257 | |
| 3258 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3259 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3260 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3261 | ipw_stop_nic(priv); |
| 3262 | |
| 3263 | rc = ipw_reset_nic(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3264 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3265 | IPW_ERROR("Unable to reset NIC\n"); |
| 3266 | goto error; |
| 3267 | } |
| 3268 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3269 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
| 3270 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3271 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3272 | #ifdef CONFIG_PM |
| 3273 | if (!fw_loaded) { |
| 3274 | #endif |
| 3275 | rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot")); |
| 3276 | if (rc < 0) |
| 3277 | goto error; |
| 3278 | #ifdef CONFIG_PM |
| 3279 | } |
| 3280 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3281 | /* DMA the initial boot firmware into the device */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3282 | rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3283 | bootfw->size - sizeof(struct fw_header)); |
| 3284 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3285 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3286 | goto error; |
| 3287 | } |
| 3288 | |
| 3289 | /* kick start the device */ |
| 3290 | ipw_start_nic(priv); |
| 3291 | |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3292 | /* wait for the device to finish its initial startup sequence */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3293 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3294 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3295 | if (rc < 0) { |
| 3296 | IPW_ERROR("device failed to boot initial fw image\n"); |
| 3297 | goto error; |
| 3298 | } |
| 3299 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); |
| 3300 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3301 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3302 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3303 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3304 | #ifdef CONFIG_PM |
| 3305 | if (!fw_loaded) { |
| 3306 | #endif |
| 3307 | rc = ipw_get_fw(priv, &ucode, ucode_name); |
| 3308 | if (rc < 0) |
| 3309 | goto error; |
| 3310 | #ifdef CONFIG_PM |
| 3311 | } |
| 3312 | #endif |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 3313 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3314 | /* DMA the ucode into the device */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3315 | rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3316 | ucode->size - sizeof(struct fw_header)); |
| 3317 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3318 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3319 | goto error; |
| 3320 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3321 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3322 | /* stop nic */ |
| 3323 | ipw_stop_nic(priv); |
| 3324 | |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3325 | #ifdef CONFIG_PM |
| 3326 | if (!fw_loaded) { |
| 3327 | #endif |
| 3328 | rc = ipw_get_fw(priv, &firmware, fw_name); |
| 3329 | if (rc < 0) |
| 3330 | goto error; |
| 3331 | #ifdef CONFIG_PM |
| 3332 | } |
| 3333 | #endif |
| 3334 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3335 | /* DMA bss firmware into the device */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3336 | rc = ipw_load_firmware(priv, firmware->data + |
| 3337 | sizeof(struct fw_header), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3338 | firmware->size - sizeof(struct fw_header)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3339 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3340 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3341 | goto error; |
| 3342 | } |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3343 | #ifdef CONFIG_PM |
| 3344 | fw_loaded = 1; |
| 3345 | #endif |
| 3346 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3347 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 3348 | |
| 3349 | rc = ipw_queue_reset(priv); |
Zhu Yi | 397ae12 | 2006-01-24 16:37:22 +0800 | [diff] [blame] | 3350 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3351 | IPW_ERROR("Unable to initialize queues\n"); |
| 3352 | goto error; |
| 3353 | } |
| 3354 | |
| 3355 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3356 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3357 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3358 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3359 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3360 | /* kick start the device */ |
| 3361 | ipw_start_nic(priv); |
| 3362 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3363 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3364 | if (retries > 0) { |
| 3365 | IPW_WARNING("Parity error. Retrying init.\n"); |
| 3366 | retries--; |
| 3367 | goto retry; |
| 3368 | } |
| 3369 | |
| 3370 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); |
| 3371 | rc = -EIO; |
| 3372 | goto error; |
| 3373 | } |
| 3374 | |
| 3375 | /* wait for the device */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3376 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3377 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3378 | if (rc < 0) { |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 3379 | IPW_ERROR("device failed to start within 500ms\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3380 | goto error; |
| 3381 | } |
| 3382 | IPW_DEBUG_INFO("device response after %dms\n", rc); |
| 3383 | |
| 3384 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3385 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3386 | |
| 3387 | /* read eeprom data and initialize the eeprom region of sram */ |
| 3388 | priv->eeprom_delay = 1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3389 | ipw_eeprom_init_sram(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3390 | |
| 3391 | /* enable interrupts */ |
| 3392 | ipw_enable_interrupts(priv); |
| 3393 | |
| 3394 | /* Ensure our queue has valid packets */ |
| 3395 | ipw_rx_queue_replenish(priv); |
| 3396 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3397 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3398 | |
| 3399 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3400 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3401 | |
| 3402 | #ifndef CONFIG_PM |
| 3403 | release_firmware(bootfw); |
| 3404 | release_firmware(ucode); |
| 3405 | release_firmware(firmware); |
| 3406 | #endif |
| 3407 | return 0; |
| 3408 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3409 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3410 | if (priv->rxq) { |
| 3411 | ipw_rx_queue_free(priv, priv->rxq); |
| 3412 | priv->rxq = NULL; |
| 3413 | } |
| 3414 | ipw_tx_queue_free(priv); |
| 3415 | if (bootfw) |
| 3416 | release_firmware(bootfw); |
| 3417 | if (ucode) |
| 3418 | release_firmware(ucode); |
| 3419 | if (firmware) |
| 3420 | release_firmware(firmware); |
| 3421 | #ifdef CONFIG_PM |
| 3422 | fw_loaded = 0; |
| 3423 | bootfw = ucode = firmware = NULL; |
| 3424 | #endif |
| 3425 | |
| 3426 | return rc; |
| 3427 | } |
| 3428 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3429 | /** |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3430 | * DMA services |
| 3431 | * |
| 3432 | * Theory of operation |
| 3433 | * |
| 3434 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 3435 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 3436 | * |
| 3437 | * 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] | 3438 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 3439 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3440 | * Tx queue resumed. |
| 3441 | * |
| 3442 | * The IPW operates with six queues, one receive queue in the device's |
| 3443 | * sram, one transmit queue for sending commands to the device firmware, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3444 | * and four transmit queues for data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3445 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3446 | * The four transmit queues allow for performing quality of service (qos) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3447 | * transmissions as per the 802.11 protocol. Currently Linux does not |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3448 | * provide a mechanism to the user for utilizing prioritized queues, so |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3449 | * we only utilize the first data transmit queue (queue1). |
| 3450 | */ |
| 3451 | |
| 3452 | /** |
| 3453 | * Driver allocates buffers of this size for Rx |
| 3454 | */ |
| 3455 | |
| 3456 | static inline int ipw_queue_space(const struct clx2_queue *q) |
| 3457 | { |
| 3458 | int s = q->last_used - q->first_empty; |
| 3459 | if (s <= 0) |
| 3460 | s += q->n_bd; |
| 3461 | s -= 2; /* keep some reserve to not confuse empty and full situations */ |
| 3462 | if (s < 0) |
| 3463 | s = 0; |
| 3464 | return s; |
| 3465 | } |
| 3466 | |
| 3467 | static inline int ipw_queue_inc_wrap(int index, int n_bd) |
| 3468 | { |
| 3469 | return (++index == n_bd) ? 0 : index; |
| 3470 | } |
| 3471 | |
| 3472 | /** |
| 3473 | * Initialize common DMA queue structure |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3474 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3475 | * @param q queue to init |
| 3476 | * @param count Number of BD's to allocate. Should be power of 2 |
| 3477 | * @param read_register Address for 'read' register |
| 3478 | * (not offset within BAR, full address) |
| 3479 | * @param write_register Address for 'write' register |
| 3480 | * (not offset within BAR, full address) |
| 3481 | * @param base_register Address for 'base' register |
| 3482 | * (not offset within BAR, full address) |
| 3483 | * @param size Address for 'size' register |
| 3484 | * (not offset within BAR, full address) |
| 3485 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3486 | 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] | 3487 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3488 | { |
| 3489 | q->n_bd = count; |
| 3490 | |
| 3491 | q->low_mark = q->n_bd / 4; |
| 3492 | if (q->low_mark < 4) |
| 3493 | q->low_mark = 4; |
| 3494 | |
| 3495 | q->high_mark = q->n_bd / 8; |
| 3496 | if (q->high_mark < 2) |
| 3497 | q->high_mark = 2; |
| 3498 | |
| 3499 | q->first_empty = q->last_used = 0; |
| 3500 | q->reg_r = read; |
| 3501 | q->reg_w = write; |
| 3502 | |
| 3503 | ipw_write32(priv, base, q->dma_addr); |
| 3504 | ipw_write32(priv, size, count); |
| 3505 | ipw_write32(priv, read, 0); |
| 3506 | ipw_write32(priv, write, 0); |
| 3507 | |
| 3508 | _ipw_read32(priv, 0x90); |
| 3509 | } |
| 3510 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3511 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3512 | struct clx2_tx_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3513 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3514 | { |
| 3515 | struct pci_dev *dev = priv->pci_dev; |
| 3516 | |
| 3517 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); |
| 3518 | if (!q->txb) { |
| 3519 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); |
| 3520 | return -ENOMEM; |
| 3521 | } |
| 3522 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3523 | q->bd = |
| 3524 | 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] | 3525 | if (!q->bd) { |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3526 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3527 | sizeof(q->bd[0]) * count); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3528 | kfree(q->txb); |
| 3529 | q->txb = NULL; |
| 3530 | return -ENOMEM; |
| 3531 | } |
| 3532 | |
| 3533 | ipw_queue_init(priv, &q->q, count, read, write, base, size); |
| 3534 | return 0; |
| 3535 | } |
| 3536 | |
| 3537 | /** |
| 3538 | * Free one TFD, those at index [txq->q.last_used]. |
| 3539 | * Do NOT advance any indexes |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3540 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3541 | * @param dev |
| 3542 | * @param txq |
| 3543 | */ |
| 3544 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, |
| 3545 | struct clx2_tx_queue *txq) |
| 3546 | { |
| 3547 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; |
| 3548 | struct pci_dev *dev = priv->pci_dev; |
| 3549 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3550 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3551 | /* classify bd */ |
| 3552 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) |
| 3553 | /* nothing to cleanup after for host commands */ |
| 3554 | return; |
| 3555 | |
| 3556 | /* sanity check */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3557 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
| 3558 | IPW_ERROR("Too many chunks: %i\n", |
| 3559 | le32_to_cpu(bd->u.data.num_chunks)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3560 | /** @todo issue fatal error, it is quite serious situation */ |
| 3561 | return; |
| 3562 | } |
| 3563 | |
| 3564 | /* unmap chunks if any */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3565 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
| 3566 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), |
| 3567 | le16_to_cpu(bd->u.data.chunk_len[i]), |
| 3568 | PCI_DMA_TODEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3569 | if (txq->txb[txq->q.last_used]) { |
| 3570 | ieee80211_txb_free(txq->txb[txq->q.last_used]); |
| 3571 | txq->txb[txq->q.last_used] = NULL; |
| 3572 | } |
| 3573 | } |
| 3574 | } |
| 3575 | |
| 3576 | /** |
| 3577 | * Deallocate DMA queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3578 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3579 | * Empty queue by removing and destroying all BD's. |
| 3580 | * Free all buffers. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3581 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3582 | * @param dev |
| 3583 | * @param q |
| 3584 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3585 | 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] | 3586 | { |
| 3587 | struct clx2_queue *q = &txq->q; |
| 3588 | struct pci_dev *dev = priv->pci_dev; |
| 3589 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3590 | if (q->n_bd == 0) |
| 3591 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3592 | |
| 3593 | /* first, empty all BD's */ |
| 3594 | for (; q->first_empty != q->last_used; |
| 3595 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3596 | ipw_queue_tx_free_tfd(priv, txq); |
| 3597 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3598 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3599 | /* free buffers belonging to queue itself */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3600 | 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] | 3601 | q->dma_addr); |
| 3602 | kfree(txq->txb); |
| 3603 | |
| 3604 | /* 0 fill whole structure */ |
| 3605 | memset(txq, 0, sizeof(*txq)); |
| 3606 | } |
| 3607 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3608 | /** |
| 3609 | * Destroy all DMA queues and structures |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3610 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3611 | * @param priv |
| 3612 | */ |
| 3613 | static void ipw_tx_queue_free(struct ipw_priv *priv) |
| 3614 | { |
| 3615 | /* Tx CMD queue */ |
| 3616 | ipw_queue_tx_free(priv, &priv->txq_cmd); |
| 3617 | |
| 3618 | /* Tx queues */ |
| 3619 | ipw_queue_tx_free(priv, &priv->txq[0]); |
| 3620 | ipw_queue_tx_free(priv, &priv->txq[1]); |
| 3621 | ipw_queue_tx_free(priv, &priv->txq[2]); |
| 3622 | ipw_queue_tx_free(priv, &priv->txq[3]); |
| 3623 | } |
| 3624 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3625 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3626 | { |
| 3627 | /* First 3 bytes are manufacturer */ |
| 3628 | bssid[0] = priv->mac_addr[0]; |
| 3629 | bssid[1] = priv->mac_addr[1]; |
| 3630 | bssid[2] = priv->mac_addr[2]; |
| 3631 | |
| 3632 | /* Last bytes are random */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3633 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3634 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3635 | bssid[0] &= 0xfe; /* clear multicast bit */ |
| 3636 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3637 | } |
| 3638 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3639 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3640 | { |
| 3641 | struct ipw_station_entry entry; |
| 3642 | int i; |
| 3643 | |
| 3644 | for (i = 0; i < priv->num_stations; i++) { |
| 3645 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { |
| 3646 | /* Another node is active in network */ |
| 3647 | priv->missed_adhoc_beacons = 0; |
| 3648 | if (!(priv->config & CFG_STATIC_CHANNEL)) |
| 3649 | /* when other nodes drop out, we drop out */ |
| 3650 | priv->config &= ~CFG_ADHOC_PERSIST; |
| 3651 | |
| 3652 | return i; |
| 3653 | } |
| 3654 | } |
| 3655 | |
| 3656 | if (i == MAX_STATIONS) |
| 3657 | return IPW_INVALID_STATION; |
| 3658 | |
| 3659 | IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid)); |
| 3660 | |
| 3661 | entry.reserved = 0; |
| 3662 | entry.support_mode = 0; |
| 3663 | memcpy(entry.mac_addr, bssid, ETH_ALEN); |
| 3664 | memcpy(priv->stations[i], bssid, ETH_ALEN); |
| 3665 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3666 | &entry, sizeof(entry)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3667 | priv->num_stations++; |
| 3668 | |
| 3669 | return i; |
| 3670 | } |
| 3671 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3672 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3673 | { |
| 3674 | int i; |
| 3675 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3676 | for (i = 0; i < priv->num_stations; i++) |
| 3677 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3678 | return i; |
| 3679 | |
| 3680 | return IPW_INVALID_STATION; |
| 3681 | } |
| 3682 | |
| 3683 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) |
| 3684 | { |
| 3685 | int err; |
| 3686 | |
Hong Liu | 7b99659 | 2005-08-25 17:36:13 +0800 | [diff] [blame] | 3687 | if (priv->status & STATUS_ASSOCIATING) { |
| 3688 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); |
| 3689 | queue_work(priv->workqueue, &priv->disassociate); |
| 3690 | return; |
| 3691 | } |
| 3692 | |
| 3693 | if (!(priv->status & STATUS_ASSOCIATED)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3694 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
| 3695 | return; |
| 3696 | } |
| 3697 | |
| 3698 | IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " " |
| 3699 | "on channel %d.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3700 | MAC_ARG(priv->assoc_request.bssid), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3701 | priv->assoc_request.channel); |
| 3702 | |
| 3703 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); |
| 3704 | priv->status |= STATUS_DISASSOCIATING; |
| 3705 | |
| 3706 | if (quiet) |
| 3707 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; |
| 3708 | else |
| 3709 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 3710 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3711 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 3712 | if (err) { |
| 3713 | IPW_DEBUG_HC("Attempt to send [dis]associate command " |
| 3714 | "failed.\n"); |
| 3715 | return; |
| 3716 | } |
| 3717 | |
| 3718 | } |
| 3719 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3720 | static int ipw_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3721 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3722 | struct ipw_priv *priv = data; |
| 3723 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) |
| 3724 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3725 | ipw_send_disassociate(data, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3726 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3727 | } |
| 3728 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3729 | static void ipw_bg_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3730 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3731 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3732 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3733 | ipw_disassociate(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 3734 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3735 | } |
| 3736 | |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 3737 | static void ipw_system_config(void *data) |
| 3738 | { |
| 3739 | struct ipw_priv *priv = data; |
| 3740 | ipw_send_system_config(priv, &priv->sys_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | struct ipw_status_code { |
| 3744 | u16 status; |
| 3745 | const char *reason; |
| 3746 | }; |
| 3747 | |
| 3748 | static const struct ipw_status_code ipw_status_codes[] = { |
| 3749 | {0x00, "Successful"}, |
| 3750 | {0x01, "Unspecified failure"}, |
| 3751 | {0x0A, "Cannot support all requested capabilities in the " |
| 3752 | "Capability information field"}, |
| 3753 | {0x0B, "Reassociation denied due to inability to confirm that " |
| 3754 | "association exists"}, |
| 3755 | {0x0C, "Association denied due to reason outside the scope of this " |
| 3756 | "standard"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3757 | {0x0D, |
| 3758 | "Responding station does not support the specified authentication " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3759 | "algorithm"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3760 | {0x0E, |
| 3761 | "Received an Authentication frame with authentication sequence " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3762 | "transaction sequence number out of expected sequence"}, |
| 3763 | {0x0F, "Authentication rejected because of challenge failure"}, |
| 3764 | {0x10, "Authentication rejected due to timeout waiting for next " |
| 3765 | "frame in sequence"}, |
| 3766 | {0x11, "Association denied because AP is unable to handle additional " |
| 3767 | "associated stations"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3768 | {0x12, |
| 3769 | "Association denied due to requesting station not supporting all " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3770 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3771 | {0x13, |
| 3772 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3773 | "short preamble operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3774 | {0x14, |
| 3775 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3776 | "PBCC encoding"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3777 | {0x15, |
| 3778 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3779 | "channel agility"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3780 | {0x19, |
| 3781 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3782 | "short slot operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3783 | {0x1A, |
| 3784 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3785 | "DSSS-OFDM operation"}, |
| 3786 | {0x28, "Invalid Information Element"}, |
| 3787 | {0x29, "Group Cipher is not valid"}, |
| 3788 | {0x2A, "Pairwise Cipher is not valid"}, |
| 3789 | {0x2B, "AKMP is not valid"}, |
| 3790 | {0x2C, "Unsupported RSN IE version"}, |
| 3791 | {0x2D, "Invalid RSN IE Capabilities"}, |
| 3792 | {0x2E, "Cipher suite is rejected per security policy"}, |
| 3793 | }; |
| 3794 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 3795 | #ifdef CONFIG_IPW2200_DEBUG |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3796 | static const char *ipw_get_status_code(u16 status) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3797 | { |
| 3798 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3799 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3800 | if (ipw_status_codes[i].status == (status & 0xff)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3801 | return ipw_status_codes[i].reason; |
| 3802 | return "Unknown status value."; |
| 3803 | } |
| 3804 | #endif |
| 3805 | |
| 3806 | static void inline average_init(struct average *avg) |
| 3807 | { |
| 3808 | memset(avg, 0, sizeof(*avg)); |
| 3809 | } |
| 3810 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3811 | static void average_add(struct average *avg, s16 val) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3812 | { |
| 3813 | avg->sum -= avg->entries[avg->pos]; |
| 3814 | avg->sum += val; |
| 3815 | avg->entries[avg->pos++] = val; |
| 3816 | if (unlikely(avg->pos == AVG_ENTRIES)) { |
| 3817 | avg->init = 1; |
| 3818 | avg->pos = 0; |
| 3819 | } |
| 3820 | } |
| 3821 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3822 | static s16 average_value(struct average *avg) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3823 | { |
| 3824 | if (!unlikely(avg->init)) { |
| 3825 | if (avg->pos) |
| 3826 | return avg->sum / avg->pos; |
| 3827 | return 0; |
| 3828 | } |
| 3829 | |
| 3830 | return avg->sum / AVG_ENTRIES; |
| 3831 | } |
| 3832 | |
| 3833 | static void ipw_reset_stats(struct ipw_priv *priv) |
| 3834 | { |
| 3835 | u32 len = sizeof(u32); |
| 3836 | |
| 3837 | priv->quality = 0; |
| 3838 | |
| 3839 | average_init(&priv->average_missed_beacons); |
| 3840 | average_init(&priv->average_rssi); |
| 3841 | average_init(&priv->average_noise); |
| 3842 | |
| 3843 | priv->last_rate = 0; |
| 3844 | priv->last_missed_beacons = 0; |
| 3845 | priv->last_rx_packets = 0; |
| 3846 | priv->last_tx_packets = 0; |
| 3847 | priv->last_tx_failures = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3848 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3849 | /* Firmware managed, reset only when NIC is restarted, so we have to |
| 3850 | * normalize on the current value */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3851 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3852 | &priv->last_rx_err, &len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3853 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3854 | &priv->last_tx_failures, &len); |
| 3855 | |
| 3856 | /* Driver managed, reset with each association */ |
| 3857 | priv->missed_adhoc_beacons = 0; |
| 3858 | priv->missed_beacons = 0; |
| 3859 | priv->tx_packets = 0; |
| 3860 | priv->rx_packets = 0; |
| 3861 | |
| 3862 | } |
| 3863 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3864 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3865 | { |
| 3866 | u32 i = 0x80000000; |
| 3867 | u32 mask = priv->rates_mask; |
| 3868 | /* If currently associated in B mode, restrict the maximum |
| 3869 | * rate match to B rates */ |
| 3870 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
| 3871 | mask &= IEEE80211_CCK_RATES_MASK; |
| 3872 | |
| 3873 | /* TODO: Verify that the rate is supported by the current rates |
| 3874 | * list. */ |
| 3875 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3876 | while (i && !(mask & i)) |
| 3877 | i >>= 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3878 | switch (i) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3879 | case IEEE80211_CCK_RATE_1MB_MASK: |
| 3880 | return 1000000; |
| 3881 | case IEEE80211_CCK_RATE_2MB_MASK: |
| 3882 | return 2000000; |
| 3883 | case IEEE80211_CCK_RATE_5MB_MASK: |
| 3884 | return 5500000; |
| 3885 | case IEEE80211_OFDM_RATE_6MB_MASK: |
| 3886 | return 6000000; |
| 3887 | case IEEE80211_OFDM_RATE_9MB_MASK: |
| 3888 | return 9000000; |
| 3889 | case IEEE80211_CCK_RATE_11MB_MASK: |
| 3890 | return 11000000; |
| 3891 | case IEEE80211_OFDM_RATE_12MB_MASK: |
| 3892 | return 12000000; |
| 3893 | case IEEE80211_OFDM_RATE_18MB_MASK: |
| 3894 | return 18000000; |
| 3895 | case IEEE80211_OFDM_RATE_24MB_MASK: |
| 3896 | return 24000000; |
| 3897 | case IEEE80211_OFDM_RATE_36MB_MASK: |
| 3898 | return 36000000; |
| 3899 | case IEEE80211_OFDM_RATE_48MB_MASK: |
| 3900 | return 48000000; |
| 3901 | case IEEE80211_OFDM_RATE_54MB_MASK: |
| 3902 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3903 | } |
| 3904 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3905 | if (priv->ieee->mode == IEEE_B) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3906 | return 11000000; |
| 3907 | else |
| 3908 | return 54000000; |
| 3909 | } |
| 3910 | |
| 3911 | static u32 ipw_get_current_rate(struct ipw_priv *priv) |
| 3912 | { |
| 3913 | u32 rate, len = sizeof(rate); |
| 3914 | int err; |
| 3915 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3916 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3917 | return 0; |
| 3918 | |
| 3919 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3920 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3921 | &len); |
| 3922 | if (err) { |
| 3923 | IPW_DEBUG_INFO("failed querying ordinals.\n"); |
| 3924 | return 0; |
| 3925 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3926 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3927 | return ipw_get_max_rate(priv); |
| 3928 | |
| 3929 | switch (rate) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3930 | case IPW_TX_RATE_1MB: |
| 3931 | return 1000000; |
| 3932 | case IPW_TX_RATE_2MB: |
| 3933 | return 2000000; |
| 3934 | case IPW_TX_RATE_5MB: |
| 3935 | return 5500000; |
| 3936 | case IPW_TX_RATE_6MB: |
| 3937 | return 6000000; |
| 3938 | case IPW_TX_RATE_9MB: |
| 3939 | return 9000000; |
| 3940 | case IPW_TX_RATE_11MB: |
| 3941 | return 11000000; |
| 3942 | case IPW_TX_RATE_12MB: |
| 3943 | return 12000000; |
| 3944 | case IPW_TX_RATE_18MB: |
| 3945 | return 18000000; |
| 3946 | case IPW_TX_RATE_24MB: |
| 3947 | return 24000000; |
| 3948 | case IPW_TX_RATE_36MB: |
| 3949 | return 36000000; |
| 3950 | case IPW_TX_RATE_48MB: |
| 3951 | return 48000000; |
| 3952 | case IPW_TX_RATE_54MB: |
| 3953 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | return 0; |
| 3957 | } |
| 3958 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3959 | #define IPW_STATS_INTERVAL (2 * HZ) |
| 3960 | static void ipw_gather_stats(struct ipw_priv *priv) |
| 3961 | { |
| 3962 | u32 rx_err, rx_err_delta, rx_packets_delta; |
| 3963 | u32 tx_failures, tx_failures_delta, tx_packets_delta; |
| 3964 | u32 missed_beacons_percent, missed_beacons_delta; |
| 3965 | u32 quality = 0; |
| 3966 | u32 len = sizeof(u32); |
| 3967 | s16 rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3968 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3969 | rate_quality; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3970 | u32 max_rate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3971 | |
| 3972 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 3973 | priv->quality = 0; |
| 3974 | return; |
| 3975 | } |
| 3976 | |
| 3977 | /* Update the statistics */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3978 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3979 | &priv->missed_beacons, &len); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3980 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3981 | priv->last_missed_beacons = priv->missed_beacons; |
| 3982 | if (priv->assoc_request.beacon_interval) { |
| 3983 | missed_beacons_percent = missed_beacons_delta * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3984 | (HZ * priv->assoc_request.beacon_interval) / |
| 3985 | (IPW_STATS_INTERVAL * 10); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3986 | } else { |
| 3987 | missed_beacons_percent = 0; |
| 3988 | } |
| 3989 | average_add(&priv->average_missed_beacons, missed_beacons_percent); |
| 3990 | |
| 3991 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); |
| 3992 | rx_err_delta = rx_err - priv->last_rx_err; |
| 3993 | priv->last_rx_err = rx_err; |
| 3994 | |
| 3995 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); |
| 3996 | tx_failures_delta = tx_failures - priv->last_tx_failures; |
| 3997 | priv->last_tx_failures = tx_failures; |
| 3998 | |
| 3999 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; |
| 4000 | priv->last_rx_packets = priv->rx_packets; |
| 4001 | |
| 4002 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; |
| 4003 | priv->last_tx_packets = priv->tx_packets; |
| 4004 | |
| 4005 | /* Calculate quality based on the following: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4006 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4007 | * Missed beacon: 100% = 0, 0% = 70% missed |
| 4008 | * Rate: 60% = 1Mbs, 100% = Max |
| 4009 | * Rx and Tx errors represent a straight % of total Rx/Tx |
| 4010 | * RSSI: 100% = > -50, 0% = < -80 |
| 4011 | * Rx errors: 100% = 0, 0% = 50% missed |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4012 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4013 | * The lowest computed quality is used. |
| 4014 | * |
| 4015 | */ |
| 4016 | #define BEACON_THRESHOLD 5 |
| 4017 | beacon_quality = 100 - missed_beacons_percent; |
| 4018 | if (beacon_quality < BEACON_THRESHOLD) |
| 4019 | beacon_quality = 0; |
| 4020 | else |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4021 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4022 | (100 - BEACON_THRESHOLD); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4023 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4024 | beacon_quality, missed_beacons_percent); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4025 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4026 | priv->last_rate = ipw_get_current_rate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4027 | max_rate = ipw_get_max_rate(priv); |
| 4028 | rate_quality = priv->last_rate * 40 / max_rate + 60; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4029 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
| 4030 | rate_quality, priv->last_rate / 1000000); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4031 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4032 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4033 | rx_quality = 100 - (rx_err_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4034 | (rx_packets_delta + rx_err_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4035 | else |
| 4036 | rx_quality = 100; |
| 4037 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", |
| 4038 | rx_quality, rx_err_delta, rx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4039 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4040 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4041 | tx_quality = 100 - (tx_failures_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4042 | (tx_packets_delta + tx_failures_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4043 | else |
| 4044 | tx_quality = 100; |
| 4045 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", |
| 4046 | tx_quality, tx_failures_delta, tx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4047 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4048 | rssi = average_value(&priv->average_rssi); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4049 | signal_quality = |
| 4050 | (100 * |
| 4051 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4052 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - |
| 4053 | (priv->ieee->perfect_rssi - rssi) * |
| 4054 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + |
| 4055 | 62 * (priv->ieee->perfect_rssi - rssi))) / |
| 4056 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4057 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); |
| 4058 | if (signal_quality > 100) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4059 | signal_quality = 100; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4060 | else if (signal_quality < 1) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4061 | signal_quality = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4062 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4063 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
| 4064 | signal_quality, rssi); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4065 | |
| 4066 | quality = min(beacon_quality, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4067 | min(rate_quality, |
| 4068 | min(tx_quality, min(rx_quality, signal_quality)))); |
| 4069 | if (quality == beacon_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4070 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
| 4071 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4072 | if (quality == rate_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4073 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
| 4074 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4075 | if (quality == tx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4076 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
| 4077 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4078 | if (quality == rx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4079 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
| 4080 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4081 | if (quality == signal_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4082 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
| 4083 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4084 | |
| 4085 | priv->quality = quality; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4086 | |
| 4087 | queue_delayed_work(priv->workqueue, &priv->gather_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4088 | IPW_STATS_INTERVAL); |
| 4089 | } |
| 4090 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4091 | static void ipw_bg_gather_stats(void *data) |
| 4092 | { |
| 4093 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4094 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4095 | ipw_gather_stats(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4096 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4097 | } |
| 4098 | |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4099 | /* Missed beacon behavior: |
| 4100 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. |
| 4101 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. |
| 4102 | * Above disassociate threshold, give up and stop scanning. |
| 4103 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4104 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4105 | int missed_count) |
| 4106 | { |
| 4107 | priv->notif_missed_beacons = missed_count; |
| 4108 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4109 | if (missed_count > priv->disassociate_threshold && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4110 | priv->status & STATUS_ASSOCIATED) { |
| 4111 | /* If associated and we've hit the missed |
| 4112 | * beacon threshold, disassociate, turn |
| 4113 | * off roaming, and abort any active scans */ |
| 4114 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4115 | IPW_DL_STATE | IPW_DL_ASSOC, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4116 | "Missed beacon: %d - disassociate\n", missed_count); |
| 4117 | priv->status &= ~STATUS_ROAMING; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4118 | if (priv->status & STATUS_SCANNING) { |
| 4119 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 4120 | IPW_DL_STATE, |
| 4121 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4122 | queue_work(priv->workqueue, &priv->abort_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4123 | } |
| 4124 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4125 | queue_work(priv->workqueue, &priv->disassociate); |
| 4126 | return; |
| 4127 | } |
| 4128 | |
| 4129 | if (priv->status & STATUS_ROAMING) { |
| 4130 | /* If we are currently roaming, then just |
| 4131 | * print a debug statement... */ |
| 4132 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4133 | "Missed beacon: %d - roam in progress\n", |
| 4134 | missed_count); |
| 4135 | return; |
| 4136 | } |
| 4137 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 4138 | if (roaming && |
| 4139 | (missed_count > priv->roaming_threshold && |
| 4140 | missed_count <= priv->disassociate_threshold)) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4141 | /* If we are not already roaming, set the ROAM |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4142 | * bit in the status and kick off a scan. |
| 4143 | * This can happen several times before we reach |
| 4144 | * disassociate_threshold. */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4145 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4146 | "Missed beacon: %d - initiate " |
| 4147 | "roaming\n", missed_count); |
| 4148 | if (!(priv->status & STATUS_ROAMING)) { |
| 4149 | priv->status |= STATUS_ROAMING; |
| 4150 | if (!(priv->status & STATUS_SCANNING)) |
| 4151 | queue_work(priv->workqueue, |
| 4152 | &priv->request_scan); |
| 4153 | } |
| 4154 | return; |
| 4155 | } |
| 4156 | |
| 4157 | if (priv->status & STATUS_SCANNING) { |
| 4158 | /* Stop scan to keep fw from getting |
| 4159 | * stuck (only if we aren't roaming -- |
| 4160 | * otherwise we'll never scan more than 2 or 3 |
| 4161 | * channels..) */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4162 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
| 4163 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4164 | queue_work(priv->workqueue, &priv->abort_scan); |
| 4165 | } |
| 4166 | |
| 4167 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4168 | } |
| 4169 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4170 | /** |
| 4171 | * Handle host notification packet. |
| 4172 | * Called from interrupt routine |
| 4173 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4174 | static void ipw_rx_notification(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4175 | struct ipw_rx_notification *notif) |
| 4176 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4177 | notif->size = le16_to_cpu(notif->size); |
| 4178 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4179 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4180 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4181 | switch (notif->subtype) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4182 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
| 4183 | struct notif_association *assoc = ¬if->u.assoc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4184 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4185 | switch (assoc->state) { |
| 4186 | case CMAS_ASSOCIATED:{ |
| 4187 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4188 | IPW_DL_ASSOC, |
| 4189 | "associated: '%s' " MAC_FMT |
| 4190 | " \n", |
| 4191 | escape_essid(priv->essid, |
| 4192 | priv->essid_len), |
| 4193 | MAC_ARG(priv->bssid)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4194 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4195 | switch (priv->ieee->iw_mode) { |
| 4196 | case IW_MODE_INFRA: |
| 4197 | memcpy(priv->ieee->bssid, |
| 4198 | priv->bssid, ETH_ALEN); |
| 4199 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4200 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4201 | case IW_MODE_ADHOC: |
| 4202 | memcpy(priv->ieee->bssid, |
| 4203 | priv->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4204 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4205 | /* clear out the station table */ |
| 4206 | priv->num_stations = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4207 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4208 | IPW_DEBUG_ASSOC |
| 4209 | ("queueing adhoc check\n"); |
| 4210 | queue_delayed_work(priv-> |
| 4211 | workqueue, |
| 4212 | &priv-> |
| 4213 | adhoc_check, |
| 4214 | priv-> |
| 4215 | assoc_request. |
| 4216 | beacon_interval); |
| 4217 | break; |
| 4218 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4219 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4220 | priv->status &= ~STATUS_ASSOCIATING; |
| 4221 | priv->status |= STATUS_ASSOCIATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 4222 | queue_work(priv->workqueue, |
| 4223 | &priv->system_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4224 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4225 | #ifdef CONFIG_IPW_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4226 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
| 4227 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl)) |
| 4228 | if ((priv->status & STATUS_AUTH) && |
| 4229 | (IPW_GET_PACKET_STYPE(¬if->u.raw) |
| 4230 | == IEEE80211_STYPE_ASSOC_RESP)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4231 | if ((sizeof |
| 4232 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4233 | ieee80211_assoc_response) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4234 | <= notif->size) |
| 4235 | && (notif->size <= 2314)) { |
| 4236 | struct |
| 4237 | ieee80211_rx_stats |
| 4238 | stats = { |
| 4239 | .len = |
| 4240 | notif-> |
| 4241 | size - 1, |
| 4242 | }; |
| 4243 | |
| 4244 | IPW_DEBUG_QOS |
| 4245 | ("QoS Associate " |
| 4246 | "size %d\n", |
| 4247 | notif->size); |
| 4248 | ieee80211_rx_mgt(priv-> |
| 4249 | ieee, |
| 4250 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4251 | ieee80211_hdr_4addr |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4252 | *) |
| 4253 | ¬if->u.raw, &stats); |
| 4254 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4255 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4256 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4257 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4258 | schedule_work(&priv->link_up); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4259 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4260 | break; |
| 4261 | } |
| 4262 | |
| 4263 | case CMAS_AUTHENTICATED:{ |
| 4264 | if (priv-> |
| 4265 | status & (STATUS_ASSOCIATED | |
| 4266 | STATUS_AUTH)) { |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 4267 | #ifdef CONFIG_IPW2200_DEBUG |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4268 | struct notif_authenticate *auth |
| 4269 | = ¬if->u.auth; |
| 4270 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4271 | IPW_DL_STATE | |
| 4272 | IPW_DL_ASSOC, |
| 4273 | "deauthenticated: '%s' " |
| 4274 | MAC_FMT |
| 4275 | ": (0x%04X) - %s \n", |
| 4276 | escape_essid(priv-> |
| 4277 | essid, |
| 4278 | priv-> |
| 4279 | essid_len), |
| 4280 | MAC_ARG(priv->bssid), |
| 4281 | ntohs(auth->status), |
| 4282 | ipw_get_status_code |
| 4283 | (ntohs |
| 4284 | (auth->status))); |
| 4285 | #endif |
| 4286 | |
| 4287 | priv->status &= |
| 4288 | ~(STATUS_ASSOCIATING | |
| 4289 | STATUS_AUTH | |
| 4290 | STATUS_ASSOCIATED); |
| 4291 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4292 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4293 | break; |
| 4294 | } |
| 4295 | |
| 4296 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4297 | IPW_DL_ASSOC, |
| 4298 | "authenticated: '%s' " MAC_FMT |
| 4299 | "\n", |
| 4300 | escape_essid(priv->essid, |
| 4301 | priv->essid_len), |
| 4302 | MAC_ARG(priv->bssid)); |
| 4303 | break; |
| 4304 | } |
| 4305 | |
| 4306 | case CMAS_INIT:{ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4307 | if (priv->status & STATUS_AUTH) { |
| 4308 | struct |
| 4309 | ieee80211_assoc_response |
| 4310 | *resp; |
| 4311 | resp = |
| 4312 | (struct |
| 4313 | ieee80211_assoc_response |
| 4314 | *)¬if->u.raw; |
| 4315 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4316 | IPW_DL_STATE | |
| 4317 | IPW_DL_ASSOC, |
| 4318 | "association failed (0x%04X): %s\n", |
| 4319 | ntohs(resp->status), |
| 4320 | ipw_get_status_code |
| 4321 | (ntohs |
| 4322 | (resp->status))); |
| 4323 | } |
| 4324 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4325 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4326 | IPW_DL_ASSOC, |
| 4327 | "disassociated: '%s' " MAC_FMT |
| 4328 | " \n", |
| 4329 | escape_essid(priv->essid, |
| 4330 | priv->essid_len), |
| 4331 | MAC_ARG(priv->bssid)); |
| 4332 | |
| 4333 | priv->status &= |
| 4334 | ~(STATUS_DISASSOCIATING | |
| 4335 | STATUS_ASSOCIATING | |
| 4336 | STATUS_ASSOCIATED | STATUS_AUTH); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4337 | if (priv->assoc_network |
| 4338 | && (priv->assoc_network-> |
| 4339 | capability & |
| 4340 | WLAN_CAPABILITY_IBSS)) |
| 4341 | ipw_remove_current_network |
| 4342 | (priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4343 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4344 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4345 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4346 | break; |
| 4347 | } |
| 4348 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4349 | case CMAS_RX_ASSOC_RESP: |
| 4350 | break; |
| 4351 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4352 | default: |
| 4353 | IPW_ERROR("assoc: unknown (%d)\n", |
| 4354 | assoc->state); |
| 4355 | break; |
| 4356 | } |
| 4357 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4358 | break; |
| 4359 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4360 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4361 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
| 4362 | struct notif_authenticate *auth = ¬if->u.auth; |
| 4363 | switch (auth->state) { |
| 4364 | case CMAS_AUTHENTICATED: |
| 4365 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4366 | "authenticated: '%s' " MAC_FMT " \n", |
| 4367 | escape_essid(priv->essid, |
| 4368 | priv->essid_len), |
| 4369 | MAC_ARG(priv->bssid)); |
| 4370 | priv->status |= STATUS_AUTH; |
| 4371 | break; |
| 4372 | |
| 4373 | case CMAS_INIT: |
| 4374 | if (priv->status & STATUS_AUTH) { |
| 4375 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4376 | IPW_DL_ASSOC, |
| 4377 | "authentication failed (0x%04X): %s\n", |
| 4378 | ntohs(auth->status), |
| 4379 | ipw_get_status_code(ntohs |
| 4380 | (auth-> |
| 4381 | status))); |
| 4382 | } |
| 4383 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4384 | IPW_DL_ASSOC, |
| 4385 | "deauthenticated: '%s' " MAC_FMT "\n", |
| 4386 | escape_essid(priv->essid, |
| 4387 | priv->essid_len), |
| 4388 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4389 | |
| 4390 | priv->status &= ~(STATUS_ASSOCIATING | |
| 4391 | STATUS_AUTH | |
| 4392 | STATUS_ASSOCIATED); |
| 4393 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4394 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4395 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4396 | |
| 4397 | case CMAS_TX_AUTH_SEQ_1: |
| 4398 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4399 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); |
| 4400 | break; |
| 4401 | case CMAS_RX_AUTH_SEQ_2: |
| 4402 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4403 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); |
| 4404 | break; |
| 4405 | case CMAS_AUTH_SEQ_1_PASS: |
| 4406 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4407 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); |
| 4408 | break; |
| 4409 | case CMAS_AUTH_SEQ_1_FAIL: |
| 4410 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4411 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); |
| 4412 | break; |
| 4413 | case CMAS_TX_AUTH_SEQ_3: |
| 4414 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4415 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); |
| 4416 | break; |
| 4417 | case CMAS_RX_AUTH_SEQ_4: |
| 4418 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4419 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); |
| 4420 | break; |
| 4421 | case CMAS_AUTH_SEQ_2_PASS: |
| 4422 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4423 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); |
| 4424 | break; |
| 4425 | case CMAS_AUTH_SEQ_2_FAIL: |
| 4426 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4427 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); |
| 4428 | break; |
| 4429 | case CMAS_TX_ASSOC: |
| 4430 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4431 | IPW_DL_ASSOC, "TX_ASSOC\n"); |
| 4432 | break; |
| 4433 | case CMAS_RX_ASSOC_RESP: |
| 4434 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4435 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4436 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4437 | break; |
| 4438 | case CMAS_ASSOCIATED: |
| 4439 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4440 | IPW_DL_ASSOC, "ASSOCIATED\n"); |
| 4441 | break; |
| 4442 | default: |
| 4443 | IPW_DEBUG_NOTIF("auth: failure - %d\n", |
| 4444 | auth->state); |
| 4445 | break; |
| 4446 | } |
| 4447 | break; |
| 4448 | } |
| 4449 | |
| 4450 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
| 4451 | struct notif_channel_result *x = |
| 4452 | ¬if->u.channel_result; |
| 4453 | |
| 4454 | if (notif->size == sizeof(*x)) { |
| 4455 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
| 4456 | x->channel_num); |
| 4457 | } else { |
| 4458 | IPW_DEBUG_SCAN("Scan result of wrong size %d " |
| 4459 | "(should be %zd)\n", |
| 4460 | notif->size, sizeof(*x)); |
| 4461 | } |
| 4462 | break; |
| 4463 | } |
| 4464 | |
| 4465 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
| 4466 | struct notif_scan_complete *x = ¬if->u.scan_complete; |
| 4467 | if (notif->size == sizeof(*x)) { |
| 4468 | IPW_DEBUG_SCAN |
| 4469 | ("Scan completed: type %d, %d channels, " |
| 4470 | "%d status\n", x->scan_type, |
| 4471 | x->num_channels, x->status); |
| 4472 | } else { |
| 4473 | IPW_ERROR("Scan completed of wrong size %d " |
| 4474 | "(should be %zd)\n", |
| 4475 | notif->size, sizeof(*x)); |
| 4476 | } |
| 4477 | |
| 4478 | priv->status &= |
| 4479 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 4480 | |
James Ketrenos | a0e04ab | 2005-08-25 00:49:43 -0500 | [diff] [blame] | 4481 | wake_up_interruptible(&priv->wait_state); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4482 | cancel_delayed_work(&priv->scan_check); |
| 4483 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4484 | if (priv->status & STATUS_EXIT_PENDING) |
| 4485 | break; |
| 4486 | |
| 4487 | priv->ieee->scans++; |
| 4488 | |
| 4489 | #ifdef CONFIG_IPW2200_MONITOR |
| 4490 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4491 | priv->status |= STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4492 | queue_work(priv->workqueue, |
| 4493 | &priv->request_scan); |
| 4494 | break; |
| 4495 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4496 | priv->status &= ~STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4497 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 4498 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4499 | if (!(priv->status & (STATUS_ASSOCIATED | |
| 4500 | STATUS_ASSOCIATING | |
| 4501 | STATUS_ROAMING | |
| 4502 | STATUS_DISASSOCIATING))) |
| 4503 | queue_work(priv->workqueue, &priv->associate); |
| 4504 | else if (priv->status & STATUS_ROAMING) { |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4505 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4506 | /* If a scan completed and we are in roam mode, then |
| 4507 | * the scan that completed was the one requested as a |
| 4508 | * result of entering roam... so, schedule the |
| 4509 | * roam work */ |
| 4510 | queue_work(priv->workqueue, |
| 4511 | &priv->roam); |
| 4512 | else |
| 4513 | /* Don't schedule if we aborted the scan */ |
| 4514 | priv->status &= ~STATUS_ROAMING; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4515 | } else if (priv->status & STATUS_SCAN_PENDING) |
| 4516 | queue_work(priv->workqueue, |
| 4517 | &priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4518 | else if (priv->config & CFG_BACKGROUND_SCAN |
| 4519 | && priv->status & STATUS_ASSOCIATED) |
| 4520 | queue_delayed_work(priv->workqueue, |
| 4521 | &priv->request_scan, HZ); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4522 | break; |
| 4523 | } |
| 4524 | |
| 4525 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
| 4526 | struct notif_frag_length *x = ¬if->u.frag_len; |
| 4527 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4528 | if (notif->size == sizeof(*x)) |
| 4529 | IPW_ERROR("Frag length: %d\n", |
| 4530 | le16_to_cpu(x->frag_length)); |
| 4531 | else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4532 | IPW_ERROR("Frag length of wrong size %d " |
| 4533 | "(should be %zd)\n", |
| 4534 | notif->size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4535 | break; |
| 4536 | } |
| 4537 | |
| 4538 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
| 4539 | struct notif_link_deterioration *x = |
| 4540 | ¬if->u.link_deterioration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4541 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4542 | if (notif->size == sizeof(*x)) { |
| 4543 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
Cahill, Ben M | 1297715 | 2006-03-08 02:58:02 +0800 | [diff] [blame] | 4544 | "link deterioration: type %d, cnt %d\n", |
| 4545 | x->silence_notification_type, |
| 4546 | x->silence_count); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4547 | memcpy(&priv->last_link_deterioration, x, |
| 4548 | sizeof(*x)); |
| 4549 | } else { |
| 4550 | IPW_ERROR("Link Deterioration of wrong size %d " |
| 4551 | "(should be %zd)\n", |
| 4552 | notif->size, sizeof(*x)); |
| 4553 | } |
| 4554 | break; |
| 4555 | } |
| 4556 | |
| 4557 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
| 4558 | IPW_ERROR("Dino config\n"); |
| 4559 | if (priv->hcmd |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4560 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4561 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4562 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4563 | break; |
| 4564 | } |
| 4565 | |
| 4566 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
| 4567 | struct notif_beacon_state *x = ¬if->u.beacon_state; |
| 4568 | if (notif->size != sizeof(*x)) { |
| 4569 | IPW_ERROR |
| 4570 | ("Beacon state of wrong size %d (should " |
| 4571 | "be %zd)\n", notif->size, sizeof(*x)); |
| 4572 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4573 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4574 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4575 | if (le32_to_cpu(x->state) == |
| 4576 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) |
| 4577 | ipw_handle_missed_beacon(priv, |
| 4578 | le32_to_cpu(x-> |
| 4579 | number)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4580 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4581 | break; |
| 4582 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4583 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4584 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
| 4585 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; |
| 4586 | if (notif->size == sizeof(*x)) { |
| 4587 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
| 4588 | "0x%02x station %d\n", |
| 4589 | x->key_state, x->security_type, |
| 4590 | x->station_index); |
| 4591 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4592 | } |
| 4593 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4594 | IPW_ERROR |
| 4595 | ("TGi Tx Key of wrong size %d (should be %zd)\n", |
| 4596 | notif->size, sizeof(*x)); |
| 4597 | break; |
| 4598 | } |
| 4599 | |
| 4600 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
| 4601 | struct notif_calibration *x = ¬if->u.calibration; |
| 4602 | |
| 4603 | if (notif->size == sizeof(*x)) { |
| 4604 | memcpy(&priv->calib, x, sizeof(*x)); |
| 4605 | IPW_DEBUG_INFO("TODO: Calibration\n"); |
| 4606 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4607 | } |
| 4608 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4609 | IPW_ERROR |
| 4610 | ("Calibration of wrong size %d (should be %zd)\n", |
| 4611 | notif->size, sizeof(*x)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4612 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4613 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4614 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4615 | case HOST_NOTIFICATION_NOISE_STATS:{ |
| 4616 | if (notif->size == sizeof(u32)) { |
| 4617 | priv->last_noise = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4618 | (u8) (le32_to_cpu(notif->u.noise.value) & |
| 4619 | 0xff); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4620 | average_add(&priv->average_noise, |
| 4621 | priv->last_noise); |
| 4622 | break; |
| 4623 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4624 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4625 | IPW_ERROR |
| 4626 | ("Noise stat is wrong size %d (should be %zd)\n", |
| 4627 | notif->size, sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4628 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4629 | } |
| 4630 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4631 | default: |
Zhu Yi | 1dd31b6 | 2006-02-20 18:28:09 -0800 | [diff] [blame] | 4632 | IPW_DEBUG_NOTIF("Unknown notification: " |
| 4633 | "subtype=%d,flags=0x%2x,size=%d\n", |
| 4634 | notif->subtype, notif->flags, notif->size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4635 | } |
| 4636 | } |
| 4637 | |
| 4638 | /** |
| 4639 | * Destroys all DMA structures and initialise them again |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4640 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4641 | * @param priv |
| 4642 | * @return error code |
| 4643 | */ |
| 4644 | static int ipw_queue_reset(struct ipw_priv *priv) |
| 4645 | { |
| 4646 | int rc = 0; |
| 4647 | /** @todo customize queue sizes */ |
| 4648 | int nTx = 64, nTxCmd = 8; |
| 4649 | ipw_tx_queue_free(priv); |
| 4650 | /* Tx CMD queue */ |
| 4651 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4652 | IPW_TX_CMD_QUEUE_READ_INDEX, |
| 4653 | IPW_TX_CMD_QUEUE_WRITE_INDEX, |
| 4654 | IPW_TX_CMD_QUEUE_BD_BASE, |
| 4655 | IPW_TX_CMD_QUEUE_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4656 | if (rc) { |
| 4657 | IPW_ERROR("Tx Cmd queue init failed\n"); |
| 4658 | goto error; |
| 4659 | } |
| 4660 | /* Tx queue(s) */ |
| 4661 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4662 | IPW_TX_QUEUE_0_READ_INDEX, |
| 4663 | IPW_TX_QUEUE_0_WRITE_INDEX, |
| 4664 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4665 | if (rc) { |
| 4666 | IPW_ERROR("Tx 0 queue init failed\n"); |
| 4667 | goto error; |
| 4668 | } |
| 4669 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4670 | IPW_TX_QUEUE_1_READ_INDEX, |
| 4671 | IPW_TX_QUEUE_1_WRITE_INDEX, |
| 4672 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4673 | if (rc) { |
| 4674 | IPW_ERROR("Tx 1 queue init failed\n"); |
| 4675 | goto error; |
| 4676 | } |
| 4677 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4678 | IPW_TX_QUEUE_2_READ_INDEX, |
| 4679 | IPW_TX_QUEUE_2_WRITE_INDEX, |
| 4680 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4681 | if (rc) { |
| 4682 | IPW_ERROR("Tx 2 queue init failed\n"); |
| 4683 | goto error; |
| 4684 | } |
| 4685 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4686 | IPW_TX_QUEUE_3_READ_INDEX, |
| 4687 | IPW_TX_QUEUE_3_WRITE_INDEX, |
| 4688 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4689 | if (rc) { |
| 4690 | IPW_ERROR("Tx 3 queue init failed\n"); |
| 4691 | goto error; |
| 4692 | } |
| 4693 | /* statistics */ |
| 4694 | priv->rx_bufs_min = 0; |
| 4695 | priv->rx_pend_max = 0; |
| 4696 | return rc; |
| 4697 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4698 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4699 | ipw_tx_queue_free(priv); |
| 4700 | return rc; |
| 4701 | } |
| 4702 | |
| 4703 | /** |
| 4704 | * Reclaim Tx queue entries no more used by NIC. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4705 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4706 | * When FW adwances 'R' index, all entries between old and |
| 4707 | * new 'R' index need to be reclaimed. As result, some free space |
| 4708 | * forms. If there is enough free space (> low mark), wake Tx queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4709 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4710 | * @note Need to protect against garbage in 'R' index |
| 4711 | * @param priv |
| 4712 | * @param txq |
| 4713 | * @param qindex |
| 4714 | * @return Number of used entries remains in the queue |
| 4715 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4716 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4717 | struct clx2_tx_queue *txq, int qindex) |
| 4718 | { |
| 4719 | u32 hw_tail; |
| 4720 | int used; |
| 4721 | struct clx2_queue *q = &txq->q; |
| 4722 | |
| 4723 | hw_tail = ipw_read32(priv, q->reg_r); |
| 4724 | if (hw_tail >= q->n_bd) { |
| 4725 | IPW_ERROR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4726 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
| 4727 | hw_tail, q->n_bd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4728 | goto done; |
| 4729 | } |
| 4730 | for (; q->last_used != hw_tail; |
| 4731 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 4732 | ipw_queue_tx_free_tfd(priv, txq); |
| 4733 | priv->tx_packets++; |
| 4734 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4735 | done: |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 4736 | if ((ipw_queue_space(q) > q->low_mark) && |
| 4737 | (qindex >= 0) && |
| 4738 | (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev)) |
| 4739 | netif_wake_queue(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4740 | used = q->first_empty - q->last_used; |
| 4741 | if (used < 0) |
| 4742 | used += q->n_bd; |
| 4743 | |
| 4744 | return used; |
| 4745 | } |
| 4746 | |
| 4747 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 4748 | int len, int sync) |
| 4749 | { |
| 4750 | struct clx2_tx_queue *txq = &priv->txq_cmd; |
| 4751 | struct clx2_queue *q = &txq->q; |
| 4752 | struct tfd_frame *tfd; |
| 4753 | |
| 4754 | if (ipw_queue_space(q) < (sync ? 1 : 2)) { |
| 4755 | IPW_ERROR("No space for Tx\n"); |
| 4756 | return -EBUSY; |
| 4757 | } |
| 4758 | |
| 4759 | tfd = &txq->bd[q->first_empty]; |
| 4760 | txq->txb[q->first_empty] = NULL; |
| 4761 | |
| 4762 | memset(tfd, 0, sizeof(*tfd)); |
| 4763 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; |
| 4764 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 4765 | priv->hcmd_seq++; |
| 4766 | tfd->u.cmd.index = hcmd; |
| 4767 | tfd->u.cmd.length = len; |
| 4768 | memcpy(tfd->u.cmd.payload, buf, len); |
| 4769 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 4770 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 4771 | _ipw_read32(priv, 0x90); |
| 4772 | |
| 4773 | return 0; |
| 4774 | } |
| 4775 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4776 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4777 | * Rx theory of operation |
| 4778 | * |
| 4779 | * The host allocates 32 DMA target addresses and passes the host address |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4780 | * 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] | 4781 | * 0 to 31 |
| 4782 | * |
| 4783 | * Rx Queue Indexes |
| 4784 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4785 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4786 | * The READ index maps to the first position that the firmware may be writing |
| 4787 | * to -- the driver can read up to (but not including) this position and get |
| 4788 | * good data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4789 | * The READ index is managed by the firmware once the card is enabled. |
| 4790 | * |
| 4791 | * The WRITE index maps to the last position the driver has read from -- the |
| 4792 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4793 | * |
| 4794 | * 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] | 4795 | * WRITE = READ. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4796 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4797 | * 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] | 4798 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4799 | * |
| 4800 | * When the firmware places a packet in a buffer it will advance the READ index |
| 4801 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4802 | * process as many packets as possible, moving the WRITE index forward as it |
| 4803 | * resets the Rx queue buffers with new memory. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4804 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4805 | * The management in the driver is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4806 | * + 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] | 4807 | * 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] | 4808 | * to replensish the ipw->rxq->rx_free. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4809 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
| 4810 | * ipw->rxq is replenished and the READ INDEX is updated (updating the |
| 4811 | * 'processed' and 'read' driver indexes as well) |
| 4812 | * + A received packet is processed and handed to the kernel network stack, |
| 4813 | * detached from the ipw->rxq. The driver 'processed' index is updated. |
| 4814 | * + 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] | 4815 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
| 4816 | * 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] | 4817 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4818 | * |
| 4819 | * |
| 4820 | * Driver sequence: |
| 4821 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4822 | * ipw_rx_queue_alloc() Allocates rx_free |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4823 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
| 4824 | * ipw_rx_queue_restock |
| 4825 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 4826 | * queue, updates firmware pointers, and updates |
| 4827 | * the WRITE index. If insufficient rx_free buffers |
| 4828 | * are available, schedules ipw_rx_queue_replenish |
| 4829 | * |
| 4830 | * -- enable interrupts -- |
| 4831 | * 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] | 4832 | * READ INDEX, detaching the SKB from the pool. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4833 | * Moves the packet buffer from queue to rx_used. |
| 4834 | * Calls ipw_rx_queue_restock to refill any empty |
| 4835 | * slots. |
| 4836 | * ... |
| 4837 | * |
| 4838 | */ |
| 4839 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4840 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4841 | * If there are slots in the RX queue that need to be restocked, |
| 4842 | * and we have free pre-allocated buffers, fill the ranks as much |
| 4843 | * as we can pulling from rx_free. |
| 4844 | * |
| 4845 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4846 | * also updates the memory address in the firmware to reference the new |
| 4847 | * target buffer. |
| 4848 | */ |
| 4849 | static void ipw_rx_queue_restock(struct ipw_priv *priv) |
| 4850 | { |
| 4851 | struct ipw_rx_queue *rxq = priv->rxq; |
| 4852 | struct list_head *element; |
| 4853 | struct ipw_rx_mem_buffer *rxb; |
| 4854 | unsigned long flags; |
| 4855 | int write; |
| 4856 | |
| 4857 | spin_lock_irqsave(&rxq->lock, flags); |
| 4858 | write = rxq->write; |
| 4859 | while ((rxq->write != rxq->processed) && (rxq->free_count)) { |
| 4860 | element = rxq->rx_free.next; |
| 4861 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
| 4862 | list_del(element); |
| 4863 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4864 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4865 | rxb->dma_addr); |
| 4866 | rxq->queue[rxq->write] = rxb; |
| 4867 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; |
| 4868 | rxq->free_count--; |
| 4869 | } |
| 4870 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4871 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4872 | /* If the pre-allocated buffer pool is dropping low, schedule to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4873 | * refill it */ |
| 4874 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4875 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4876 | |
| 4877 | /* 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] | 4878 | if (write != rxq->write) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4879 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | /* |
| 4883 | * 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] | 4884 | * Also restock the Rx queue via ipw_rx_queue_restock. |
| 4885 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4886 | * This is called as a scheduled work item (except for during intialization) |
| 4887 | */ |
| 4888 | static void ipw_rx_queue_replenish(void *data) |
| 4889 | { |
| 4890 | struct ipw_priv *priv = data; |
| 4891 | struct ipw_rx_queue *rxq = priv->rxq; |
| 4892 | struct list_head *element; |
| 4893 | struct ipw_rx_mem_buffer *rxb; |
| 4894 | unsigned long flags; |
| 4895 | |
| 4896 | spin_lock_irqsave(&rxq->lock, flags); |
| 4897 | while (!list_empty(&rxq->rx_used)) { |
| 4898 | element = rxq->rx_used.next; |
| 4899 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4900 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4901 | if (!rxb->skb) { |
| 4902 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", |
| 4903 | priv->net_dev->name); |
| 4904 | /* We don't reschedule replenish work here -- we will |
| 4905 | * call the restock method and if it still needs |
| 4906 | * more buffers it will schedule replenish */ |
| 4907 | break; |
| 4908 | } |
| 4909 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4910 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4911 | rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4912 | rxb->dma_addr = |
| 4913 | pci_map_single(priv->pci_dev, rxb->skb->data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4914 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4915 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4916 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4917 | rxq->free_count++; |
| 4918 | } |
| 4919 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4920 | |
| 4921 | ipw_rx_queue_restock(priv); |
| 4922 | } |
| 4923 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4924 | static void ipw_bg_rx_queue_replenish(void *data) |
| 4925 | { |
| 4926 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4927 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4928 | ipw_rx_queue_replenish(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 4929 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4930 | } |
| 4931 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4932 | /* 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] | 4933 | * 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] | 4934 | * 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] | 4935 | * non NULL it is unmapped and freed |
| 4936 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4937 | 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] | 4938 | { |
| 4939 | int i; |
| 4940 | |
| 4941 | if (!rxq) |
| 4942 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4943 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4944 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4945 | if (rxq->pool[i].skb != NULL) { |
| 4946 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4947 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4948 | dev_kfree_skb(rxq->pool[i].skb); |
| 4949 | } |
| 4950 | } |
| 4951 | |
| 4952 | kfree(rxq); |
| 4953 | } |
| 4954 | |
| 4955 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) |
| 4956 | { |
| 4957 | struct ipw_rx_queue *rxq; |
| 4958 | int i; |
| 4959 | |
Takis | c75f474 | 2005-12-01 01:41:45 -0800 | [diff] [blame] | 4960 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
Panagiotis Issaris | ad18b0e | 2005-09-05 04:14:10 +0200 | [diff] [blame] | 4961 | if (unlikely(!rxq)) { |
| 4962 | IPW_ERROR("memory allocation failed\n"); |
| 4963 | return NULL; |
| 4964 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4965 | spin_lock_init(&rxq->lock); |
| 4966 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4967 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4968 | |
| 4969 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4970 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4971 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4972 | |
| 4973 | /* Set us so that we have processed and used all buffers, but have |
| 4974 | * not restocked the Rx queue with fresh buffers */ |
| 4975 | rxq->read = rxq->write = 0; |
| 4976 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 4977 | rxq->free_count = 0; |
| 4978 | |
| 4979 | return rxq; |
| 4980 | } |
| 4981 | |
| 4982 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) |
| 4983 | { |
| 4984 | rate &= ~IEEE80211_BASIC_RATE_MASK; |
| 4985 | if (ieee_mode == IEEE_A) { |
| 4986 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4987 | case IEEE80211_OFDM_RATE_6MB: |
| 4988 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4989 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4990 | case IEEE80211_OFDM_RATE_9MB: |
| 4991 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4992 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4993 | case IEEE80211_OFDM_RATE_12MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4994 | return priv-> |
| 4995 | rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4996 | case IEEE80211_OFDM_RATE_18MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4997 | return priv-> |
| 4998 | rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4999 | case IEEE80211_OFDM_RATE_24MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5000 | return priv-> |
| 5001 | rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5002 | case IEEE80211_OFDM_RATE_36MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5003 | return priv-> |
| 5004 | rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5005 | case IEEE80211_OFDM_RATE_48MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5006 | return priv-> |
| 5007 | rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5008 | case IEEE80211_OFDM_RATE_54MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5009 | return priv-> |
| 5010 | rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5011 | default: |
| 5012 | return 0; |
| 5013 | } |
| 5014 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5015 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5016 | /* B and G mixed */ |
| 5017 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5018 | case IEEE80211_CCK_RATE_1MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5019 | return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5020 | case IEEE80211_CCK_RATE_2MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5021 | return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5022 | case IEEE80211_CCK_RATE_5MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5023 | return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5024 | case IEEE80211_CCK_RATE_11MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5025 | return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0; |
| 5026 | } |
| 5027 | |
| 5028 | /* If we are limited to B modulations, bail at this point */ |
| 5029 | if (ieee_mode == IEEE_B) |
| 5030 | return 0; |
| 5031 | |
| 5032 | /* G */ |
| 5033 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5034 | case IEEE80211_OFDM_RATE_6MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5035 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5036 | case IEEE80211_OFDM_RATE_9MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5037 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5038 | case IEEE80211_OFDM_RATE_12MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5039 | return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5040 | case IEEE80211_OFDM_RATE_18MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5041 | return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5042 | case IEEE80211_OFDM_RATE_24MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5043 | return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5044 | case IEEE80211_OFDM_RATE_36MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5045 | return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5046 | case IEEE80211_OFDM_RATE_48MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5047 | return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5048 | case IEEE80211_OFDM_RATE_54MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5049 | return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
| 5050 | } |
| 5051 | |
| 5052 | return 0; |
| 5053 | } |
| 5054 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5055 | static int ipw_compatible_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5056 | const struct ieee80211_network *network, |
| 5057 | struct ipw_supported_rates *rates) |
| 5058 | { |
| 5059 | int num_rates, i; |
| 5060 | |
| 5061 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5062 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5063 | rates->num_rates = 0; |
| 5064 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5065 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5066 | network->rates[i])) { |
| 5067 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5068 | if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5069 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5070 | "rate %02X\n", |
| 5071 | network->rates[i]); |
| 5072 | rates->supported_rates[rates->num_rates++] = |
| 5073 | network->rates[i]; |
| 5074 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5075 | } |
| 5076 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5077 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5078 | network->rates[i], priv->rates_mask); |
| 5079 | continue; |
| 5080 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5081 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5082 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
| 5083 | } |
| 5084 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5085 | num_rates = min(network->rates_ex_len, |
| 5086 | (u8) (IPW_MAX_RATES - num_rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5087 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5088 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5089 | network->rates_ex[i])) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5090 | if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5091 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5092 | "rate %02X\n", |
| 5093 | network->rates_ex[i]); |
| 5094 | rates->supported_rates[rates->num_rates++] = |
| 5095 | network->rates[i]; |
| 5096 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5097 | } |
| 5098 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5099 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5100 | network->rates_ex[i], priv->rates_mask); |
| 5101 | continue; |
| 5102 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5103 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5104 | rates->supported_rates[rates->num_rates++] = |
| 5105 | network->rates_ex[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5106 | } |
| 5107 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5108 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5109 | } |
| 5110 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5111 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5112 | const struct ipw_supported_rates *src) |
| 5113 | { |
| 5114 | u8 i; |
| 5115 | for (i = 0; i < src->num_rates; i++) |
| 5116 | dest->supported_rates[i] = src->supported_rates[i]; |
| 5117 | dest->num_rates = src->num_rates; |
| 5118 | } |
| 5119 | |
| 5120 | /* TODO: Look at sniffed packets in the air to determine if the basic rate |
| 5121 | * mask should ever be used -- right now all callers to add the scan rates are |
| 5122 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ |
| 5123 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5124 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5125 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5126 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5127 | IEEE80211_BASIC_RATE_MASK : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5128 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5129 | if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5130 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5131 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5132 | |
| 5133 | if (rate_mask & IEEE80211_CCK_RATE_2MB_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_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5136 | |
| 5137 | if (rate_mask & IEEE80211_CCK_RATE_5MB_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_CCK_RATE_5MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5140 | |
| 5141 | if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5142 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5143 | IEEE80211_CCK_RATE_11MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5147 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5148 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5149 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5150 | IEEE80211_BASIC_RATE_MASK : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5151 | |
| 5152 | if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5153 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5154 | IEEE80211_OFDM_RATE_6MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5155 | |
| 5156 | if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5157 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5158 | IEEE80211_OFDM_RATE_9MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5159 | |
| 5160 | if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5161 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5162 | IEEE80211_OFDM_RATE_12MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5163 | |
| 5164 | if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5165 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5166 | IEEE80211_OFDM_RATE_18MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5167 | |
| 5168 | if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5169 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5170 | IEEE80211_OFDM_RATE_24MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5171 | |
| 5172 | if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5173 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5174 | IEEE80211_OFDM_RATE_36MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5175 | |
| 5176 | if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5177 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5178 | IEEE80211_OFDM_RATE_48MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5179 | |
| 5180 | if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5181 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5182 | IEEE80211_OFDM_RATE_54MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | struct ipw_network_match { |
| 5186 | struct ieee80211_network *network; |
| 5187 | struct ipw_supported_rates rates; |
| 5188 | }; |
| 5189 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5190 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
| 5191 | struct ipw_network_match *match, |
| 5192 | struct ieee80211_network *network, |
| 5193 | int roaming) |
| 5194 | { |
| 5195 | struct ipw_supported_rates rates; |
| 5196 | |
| 5197 | /* Verify that this network's capability is compatible with the |
| 5198 | * current mode (AdHoc or Infrastructure) */ |
| 5199 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5200 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5201 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to " |
| 5202 | "capability mismatch.\n", |
| 5203 | escape_essid(network->ssid, network->ssid_len), |
| 5204 | MAC_ARG(network->bssid)); |
| 5205 | return 0; |
| 5206 | } |
| 5207 | |
| 5208 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5209 | * it */ |
| 5210 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5211 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5212 | "because of hidden ESSID.\n", |
| 5213 | escape_essid(network->ssid, network->ssid_len), |
| 5214 | MAC_ARG(network->bssid)); |
| 5215 | return 0; |
| 5216 | } |
| 5217 | |
| 5218 | if (unlikely(roaming)) { |
| 5219 | /* If we are roaming, then ensure check if this is a valid |
| 5220 | * network to try and roam to */ |
| 5221 | if ((network->ssid_len != match->network->ssid_len) || |
| 5222 | memcmp(network->ssid, match->network->ssid, |
| 5223 | network->ssid_len)) { |
| 5224 | IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5225 | "because of non-network ESSID.\n", |
| 5226 | escape_essid(network->ssid, |
| 5227 | network->ssid_len), |
| 5228 | MAC_ARG(network->bssid)); |
| 5229 | return 0; |
| 5230 | } |
| 5231 | } else { |
| 5232 | /* If an ESSID has been configured then compare the broadcast |
| 5233 | * ESSID to ours */ |
| 5234 | if ((priv->config & CFG_STATIC_ESSID) && |
| 5235 | ((network->ssid_len != priv->essid_len) || |
| 5236 | memcmp(network->ssid, priv->essid, |
| 5237 | min(network->ssid_len, priv->essid_len)))) { |
| 5238 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5239 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5240 | strncpy(escaped, |
| 5241 | escape_essid(network->ssid, network->ssid_len), |
| 5242 | sizeof(escaped)); |
| 5243 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5244 | "because of ESSID mismatch: '%s'.\n", |
| 5245 | escaped, MAC_ARG(network->bssid), |
| 5246 | escape_essid(priv->essid, |
| 5247 | priv->essid_len)); |
| 5248 | return 0; |
| 5249 | } |
| 5250 | } |
| 5251 | |
| 5252 | /* If the old network rate is better than this one, don't bother |
| 5253 | * testing everything else. */ |
| 5254 | |
| 5255 | if (network->time_stamp[0] < match->network->time_stamp[0]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5256 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5257 | "current network.\n", |
| 5258 | escape_essid(match->network->ssid, |
| 5259 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5260 | return 0; |
| 5261 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5262 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5263 | "current network.\n", |
| 5264 | escape_essid(match->network->ssid, |
| 5265 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5266 | return 0; |
| 5267 | } |
| 5268 | |
| 5269 | /* Now go through and see if the requested network is valid... */ |
| 5270 | if (priv->ieee->scan_age != 0 && |
| 5271 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
| 5272 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5273 | "because of age: %ums.\n", |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5274 | escape_essid(network->ssid, network->ssid_len), |
| 5275 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5276 | jiffies_to_msecs(jiffies - |
| 5277 | network->last_scanned)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5278 | return 0; |
| 5279 | } |
| 5280 | |
| 5281 | if ((priv->config & CFG_STATIC_CHANNEL) && |
| 5282 | (network->channel != priv->channel)) { |
| 5283 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5284 | "because of channel mismatch: %d != %d.\n", |
| 5285 | escape_essid(network->ssid, network->ssid_len), |
| 5286 | MAC_ARG(network->bssid), |
| 5287 | network->channel, priv->channel); |
| 5288 | return 0; |
| 5289 | } |
| 5290 | |
| 5291 | /* Verify privacy compatability */ |
| 5292 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
| 5293 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5294 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5295 | "because of privacy mismatch: %s != %s.\n", |
| 5296 | escape_essid(network->ssid, network->ssid_len), |
| 5297 | MAC_ARG(network->bssid), |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5298 | priv-> |
| 5299 | capability & CAP_PRIVACY_ON ? "on" : "off", |
| 5300 | network-> |
| 5301 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : |
| 5302 | "off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5303 | return 0; |
| 5304 | } |
| 5305 | |
| 5306 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5307 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5308 | "because of the same BSSID match: " MAC_FMT |
| 5309 | ".\n", escape_essid(network->ssid, |
| 5310 | network->ssid_len), |
| 5311 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
| 5312 | return 0; |
| 5313 | } |
| 5314 | |
| 5315 | /* Filter out any incompatible freq / mode combinations */ |
| 5316 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5317 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5318 | "because of invalid frequency/mode " |
| 5319 | "combination.\n", |
| 5320 | escape_essid(network->ssid, network->ssid_len), |
| 5321 | MAC_ARG(network->bssid)); |
| 5322 | return 0; |
| 5323 | } |
| 5324 | |
| 5325 | /* Ensure that the rates supported by the driver are compatible with |
| 5326 | * this AP, including verification of basic rates (mandatory) */ |
| 5327 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5328 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5329 | "because configured rate mask excludes " |
| 5330 | "AP mandatory rate.\n", |
| 5331 | escape_essid(network->ssid, network->ssid_len), |
| 5332 | MAC_ARG(network->bssid)); |
| 5333 | return 0; |
| 5334 | } |
| 5335 | |
| 5336 | if (rates.num_rates == 0) { |
| 5337 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5338 | "because of no compatible rates.\n", |
| 5339 | escape_essid(network->ssid, network->ssid_len), |
| 5340 | MAC_ARG(network->bssid)); |
| 5341 | return 0; |
| 5342 | } |
| 5343 | |
| 5344 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5345 | * want to put too much policy logic here; intelligent scan selection |
| 5346 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5347 | |
| 5348 | /* Set up 'new' AP to this network */ |
| 5349 | ipw_copy_rates(&match->rates, &rates); |
| 5350 | match->network = network; |
| 5351 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5352 | escape_essid(network->ssid, network->ssid_len), |
| 5353 | MAC_ARG(network->bssid)); |
| 5354 | |
| 5355 | return 1; |
| 5356 | } |
| 5357 | |
| 5358 | static void ipw_merge_adhoc_network(void *data) |
| 5359 | { |
| 5360 | struct ipw_priv *priv = data; |
| 5361 | struct ieee80211_network *network = NULL; |
| 5362 | struct ipw_network_match match = { |
| 5363 | .network = priv->assoc_network |
| 5364 | }; |
| 5365 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5366 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5367 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5368 | /* First pass through ROAM process -- look for a better |
| 5369 | * network */ |
| 5370 | unsigned long flags; |
| 5371 | |
| 5372 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 5373 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 5374 | if (network != priv->assoc_network) |
| 5375 | ipw_find_adhoc_network(priv, &match, network, |
| 5376 | 1); |
| 5377 | } |
| 5378 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 5379 | |
| 5380 | if (match.network == priv->assoc_network) { |
| 5381 | IPW_DEBUG_MERGE("No better ADHOC in this network to " |
| 5382 | "merge to.\n"); |
| 5383 | return; |
| 5384 | } |
| 5385 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5386 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5387 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
| 5388 | IPW_DEBUG_MERGE("remove network %s\n", |
| 5389 | escape_essid(priv->essid, |
| 5390 | priv->essid_len)); |
| 5391 | ipw_remove_current_network(priv); |
| 5392 | } |
| 5393 | |
| 5394 | ipw_disassociate(priv); |
| 5395 | priv->assoc_network = match.network; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5396 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5397 | return; |
| 5398 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5399 | } |
| 5400 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5401 | static int ipw_best_network(struct ipw_priv *priv, |
| 5402 | struct ipw_network_match *match, |
| 5403 | struct ieee80211_network *network, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5404 | { |
| 5405 | struct ipw_supported_rates rates; |
| 5406 | |
| 5407 | /* Verify that this network's capability is compatible with the |
| 5408 | * current mode (AdHoc or Infrastructure) */ |
| 5409 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && |
Jouni Malinen | 2474385 | 2005-08-14 20:59:59 -0700 | [diff] [blame] | 5410 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5411 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5412 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5413 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5414 | "capability mismatch.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5415 | escape_essid(network->ssid, network->ssid_len), |
| 5416 | MAC_ARG(network->bssid)); |
| 5417 | return 0; |
| 5418 | } |
| 5419 | |
| 5420 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5421 | * it */ |
| 5422 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5423 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5424 | "because of hidden ESSID.\n", |
| 5425 | escape_essid(network->ssid, network->ssid_len), |
| 5426 | MAC_ARG(network->bssid)); |
| 5427 | return 0; |
| 5428 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5429 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5430 | if (unlikely(roaming)) { |
| 5431 | /* If we are roaming, then ensure check if this is a valid |
| 5432 | * network to try and roam to */ |
| 5433 | if ((network->ssid_len != match->network->ssid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5434 | memcmp(network->ssid, match->network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5435 | network->ssid_len)) { |
| 5436 | IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5437 | "because of non-network ESSID.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5438 | escape_essid(network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5439 | network->ssid_len), |
| 5440 | MAC_ARG(network->bssid)); |
| 5441 | return 0; |
| 5442 | } |
| 5443 | } else { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5444 | /* If an ESSID has been configured then compare the broadcast |
| 5445 | * ESSID to ours */ |
| 5446 | if ((priv->config & CFG_STATIC_ESSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5447 | ((network->ssid_len != priv->essid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5448 | memcmp(network->ssid, priv->essid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5449 | min(network->ssid_len, priv->essid_len)))) { |
| 5450 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5451 | strncpy(escaped, |
| 5452 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5453 | sizeof(escaped)); |
| 5454 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5455 | "because of ESSID mismatch: '%s'.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5456 | escaped, MAC_ARG(network->bssid), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5457 | escape_essid(priv->essid, |
| 5458 | priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5459 | return 0; |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | /* If the old network rate is better than this one, don't bother |
| 5464 | * testing everything else. */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5465 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5466 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5467 | strncpy(escaped, |
| 5468 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5469 | sizeof(escaped)); |
| 5470 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because " |
| 5471 | "'%s (" MAC_FMT ")' has a stronger signal.\n", |
| 5472 | escaped, MAC_ARG(network->bssid), |
| 5473 | escape_essid(match->network->ssid, |
| 5474 | match->network->ssid_len), |
| 5475 | MAC_ARG(match->network->bssid)); |
| 5476 | return 0; |
| 5477 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5478 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5479 | /* If this network has already had an association attempt within the |
| 5480 | * last 3 seconds, do not try and associate again... */ |
| 5481 | if (network->last_associate && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5482 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5483 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5484 | "because of storming (%ums since last " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5485 | "assoc attempt).\n", |
| 5486 | escape_essid(network->ssid, network->ssid_len), |
| 5487 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5488 | jiffies_to_msecs(jiffies - |
| 5489 | network->last_associate)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5490 | return 0; |
| 5491 | } |
| 5492 | |
| 5493 | /* Now go through and see if the requested network is valid... */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5494 | if (priv->ieee->scan_age != 0 && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5495 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5496 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Zhu Yi | c7b6a67 | 2006-01-24 16:37:05 +0800 | [diff] [blame] | 5497 | "because of age: %ums.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5498 | escape_essid(network->ssid, network->ssid_len), |
| 5499 | MAC_ARG(network->bssid), |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 5500 | jiffies_to_msecs(jiffies - |
| 5501 | network->last_scanned)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5502 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5503 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5504 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5505 | if ((priv->config & CFG_STATIC_CHANNEL) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5506 | (network->channel != priv->channel)) { |
| 5507 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5508 | "because of channel mismatch: %d != %d.\n", |
| 5509 | escape_essid(network->ssid, network->ssid_len), |
| 5510 | MAC_ARG(network->bssid), |
| 5511 | network->channel, priv->channel); |
| 5512 | return 0; |
| 5513 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5514 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5515 | /* Verify privacy compatability */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5516 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5517 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5518 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5519 | "because of privacy mismatch: %s != %s.\n", |
| 5520 | escape_essid(network->ssid, network->ssid_len), |
| 5521 | MAC_ARG(network->bssid), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5522 | priv->capability & CAP_PRIVACY_ON ? "on" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5523 | "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5524 | network->capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5525 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5526 | return 0; |
| 5527 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5528 | |
| 5529 | if ((priv->config & CFG_STATIC_BSSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5530 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5531 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5532 | "because of BSSID mismatch: " MAC_FMT ".\n", |
| 5533 | escape_essid(network->ssid, network->ssid_len), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5534 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5535 | return 0; |
| 5536 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5537 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5538 | /* Filter out any incompatible freq / mode combinations */ |
| 5539 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5540 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5541 | "because of invalid frequency/mode " |
| 5542 | "combination.\n", |
| 5543 | escape_essid(network->ssid, network->ssid_len), |
| 5544 | MAC_ARG(network->bssid)); |
| 5545 | return 0; |
| 5546 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5547 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5548 | /* Filter out invalid channel in current GEO */ |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5549 | if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5550 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5551 | "because of invalid channel in current GEO\n", |
| 5552 | escape_essid(network->ssid, network->ssid_len), |
| 5553 | MAC_ARG(network->bssid)); |
| 5554 | return 0; |
| 5555 | } |
| 5556 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5557 | /* Ensure that the rates supported by the driver are compatible with |
| 5558 | * this AP, including verification of basic rates (mandatory) */ |
| 5559 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5560 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5561 | "because configured rate mask excludes " |
| 5562 | "AP mandatory rate.\n", |
| 5563 | escape_essid(network->ssid, network->ssid_len), |
| 5564 | MAC_ARG(network->bssid)); |
| 5565 | return 0; |
| 5566 | } |
| 5567 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5568 | if (rates.num_rates == 0) { |
| 5569 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5570 | "because of no compatible rates.\n", |
| 5571 | escape_essid(network->ssid, network->ssid_len), |
| 5572 | MAC_ARG(network->bssid)); |
| 5573 | return 0; |
| 5574 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5575 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5576 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5577 | * want to put too much policy logic here; intelligent scan selection |
| 5578 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5579 | |
| 5580 | /* Set up 'new' AP to this network */ |
| 5581 | ipw_copy_rates(&match->rates, &rates); |
| 5582 | match->network = network; |
| 5583 | |
| 5584 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5585 | escape_essid(network->ssid, network->ssid_len), |
| 5586 | MAC_ARG(network->bssid)); |
| 5587 | |
| 5588 | return 1; |
| 5589 | } |
| 5590 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5591 | static void ipw_adhoc_create(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5592 | struct ieee80211_network *network) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5593 | { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5594 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5595 | int i; |
| 5596 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5597 | /* |
| 5598 | * For the purposes of scanning, we can set our wireless mode |
| 5599 | * to trigger scans across combinations of bands, but when it |
| 5600 | * comes to creating a new ad-hoc network, we have tell the FW |
| 5601 | * exactly which band to use. |
| 5602 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5603 | * We also have the possibility of an invalid channel for the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5604 | * chossen band. Attempting to create a new ad-hoc network |
| 5605 | * with an invalid channel for wireless mode will trigger a |
| 5606 | * FW fatal error. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5607 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5608 | */ |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5609 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5610 | case IEEE80211_52GHZ_BAND: |
| 5611 | network->mode = IEEE_A; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5612 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5613 | if (i == -1) |
| 5614 | BUG(); |
| 5615 | if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5616 | IPW_WARNING("Overriding invalid channel\n"); |
| 5617 | priv->channel = geo->a[0].channel; |
| 5618 | } |
| 5619 | break; |
| 5620 | |
| 5621 | case IEEE80211_24GHZ_BAND: |
| 5622 | if (priv->ieee->mode & IEEE_G) |
| 5623 | network->mode = IEEE_G; |
| 5624 | else |
| 5625 | network->mode = IEEE_B; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5626 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5627 | if (i == -1) |
| 5628 | BUG(); |
| 5629 | if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5630 | IPW_WARNING("Overriding invalid channel\n"); |
| 5631 | priv->channel = geo->bg[0].channel; |
| 5632 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5633 | break; |
| 5634 | |
| 5635 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5636 | IPW_WARNING("Overriding invalid channel\n"); |
| 5637 | if (priv->ieee->mode & IEEE_A) { |
| 5638 | network->mode = IEEE_A; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5639 | priv->channel = geo->a[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5640 | } else if (priv->ieee->mode & IEEE_G) { |
| 5641 | network->mode = IEEE_G; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5642 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5643 | } else { |
| 5644 | network->mode = IEEE_B; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5645 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5646 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5647 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5648 | } |
| 5649 | |
| 5650 | network->channel = priv->channel; |
| 5651 | priv->config |= CFG_ADHOC_PERSIST; |
| 5652 | ipw_create_bssid(priv, network->bssid); |
| 5653 | network->ssid_len = priv->essid_len; |
| 5654 | memcpy(network->ssid, priv->essid, priv->essid_len); |
| 5655 | memset(&network->stats, 0, sizeof(network->stats)); |
| 5656 | network->capability = WLAN_CAPABILITY_IBSS; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5657 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
| 5658 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5659 | if (priv->capability & CAP_PRIVACY_ON) |
| 5660 | network->capability |= WLAN_CAPABILITY_PRIVACY; |
| 5661 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5662 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5663 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5664 | memcpy(network->rates_ex, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5665 | &priv->rates.supported_rates[network->rates_len], |
| 5666 | network->rates_ex_len); |
| 5667 | network->last_scanned = 0; |
| 5668 | network->flags = 0; |
| 5669 | network->last_associate = 0; |
| 5670 | network->time_stamp[0] = 0; |
| 5671 | network->time_stamp[1] = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5672 | network->beacon_interval = 100; /* Default */ |
| 5673 | network->listen_interval = 10; /* Default */ |
| 5674 | network->atim_window = 0; /* Default */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5675 | network->wpa_ie_len = 0; |
| 5676 | network->rsn_ie_len = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5677 | } |
| 5678 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5679 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
| 5680 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5681 | struct ipw_tgi_tx_key key; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5682 | |
| 5683 | if (!(priv->ieee->sec.flags & (1 << index))) |
| 5684 | return; |
| 5685 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5686 | key.key_id = index; |
| 5687 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); |
| 5688 | key.security_type = type; |
| 5689 | key.station_index = 0; /* always 0 for BSS */ |
| 5690 | key.flags = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5691 | /* 0 for new key; previous value of counter (after fatal error) */ |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5692 | key.tx_counter[0] = 0; |
| 5693 | key.tx_counter[1] = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5694 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5695 | 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] | 5696 | } |
| 5697 | |
| 5698 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5699 | { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5700 | struct ipw_wep_key key; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5701 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5702 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5703 | key.cmd_id = DINO_CMD_WEP_KEY; |
| 5704 | key.seq_num = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5705 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5706 | /* Note: AES keys cannot be set for multiple times. |
| 5707 | * Only set it at the first time. */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5708 | for (i = 0; i < 4; i++) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5709 | key.key_index = i | type; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5710 | if (!(priv->ieee->sec.flags & (1 << i))) { |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5711 | key.key_size = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5712 | continue; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5713 | } |
| 5714 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5715 | key.key_size = priv->ieee->sec.key_sizes[i]; |
| 5716 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5717 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 5718 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5719 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5720 | } |
| 5721 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 5722 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
| 5723 | { |
| 5724 | if (priv->ieee->host_encrypt) |
| 5725 | return; |
| 5726 | |
| 5727 | switch (level) { |
| 5728 | case SEC_LEVEL_3: |
| 5729 | priv->sys_config.disable_unicast_decryption = 0; |
| 5730 | priv->ieee->host_decrypt = 0; |
| 5731 | break; |
| 5732 | case SEC_LEVEL_2: |
| 5733 | priv->sys_config.disable_unicast_decryption = 1; |
| 5734 | priv->ieee->host_decrypt = 1; |
| 5735 | break; |
| 5736 | case SEC_LEVEL_1: |
| 5737 | priv->sys_config.disable_unicast_decryption = 0; |
| 5738 | priv->ieee->host_decrypt = 0; |
| 5739 | break; |
| 5740 | case SEC_LEVEL_0: |
| 5741 | priv->sys_config.disable_unicast_decryption = 1; |
| 5742 | break; |
| 5743 | default: |
| 5744 | break; |
| 5745 | } |
| 5746 | } |
| 5747 | |
| 5748 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) |
| 5749 | { |
| 5750 | if (priv->ieee->host_encrypt) |
| 5751 | return; |
| 5752 | |
| 5753 | switch (level) { |
| 5754 | case SEC_LEVEL_3: |
| 5755 | priv->sys_config.disable_multicast_decryption = 0; |
| 5756 | break; |
| 5757 | case SEC_LEVEL_2: |
| 5758 | priv->sys_config.disable_multicast_decryption = 1; |
| 5759 | break; |
| 5760 | case SEC_LEVEL_1: |
| 5761 | priv->sys_config.disable_multicast_decryption = 0; |
| 5762 | break; |
| 5763 | case SEC_LEVEL_0: |
| 5764 | priv->sys_config.disable_multicast_decryption = 1; |
| 5765 | break; |
| 5766 | default: |
| 5767 | break; |
| 5768 | } |
| 5769 | } |
| 5770 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5771 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
| 5772 | { |
| 5773 | switch (priv->ieee->sec.level) { |
| 5774 | case SEC_LEVEL_3: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5775 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5776 | ipw_send_tgi_tx_key(priv, |
| 5777 | DCT_FLAG_EXT_SECURITY_CCM, |
| 5778 | priv->ieee->sec.active_key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5779 | |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 5780 | if (!priv->ieee->host_mc_decrypt) |
| 5781 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5782 | break; |
| 5783 | case SEC_LEVEL_2: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5784 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5785 | ipw_send_tgi_tx_key(priv, |
| 5786 | DCT_FLAG_EXT_SECURITY_TKIP, |
| 5787 | priv->ieee->sec.active_key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5788 | break; |
| 5789 | case SEC_LEVEL_1: |
| 5790 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Hong Liu | 29cb843 | 2005-09-12 10:43:33 -0500 | [diff] [blame] | 5791 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
| 5792 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5793 | break; |
| 5794 | case SEC_LEVEL_0: |
| 5795 | default: |
| 5796 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5797 | } |
| 5798 | } |
| 5799 | |
| 5800 | static void ipw_adhoc_check(void *data) |
| 5801 | { |
| 5802 | struct ipw_priv *priv = data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5803 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5804 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5805 | !(priv->config & CFG_ADHOC_PERSIST)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5806 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 5807 | IPW_DL_STATE | IPW_DL_ASSOC, |
| 5808 | "Missed beacon: %d - disassociate\n", |
| 5809 | priv->missed_adhoc_beacons); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5810 | ipw_remove_current_network(priv); |
| 5811 | ipw_disassociate(priv); |
| 5812 | return; |
| 5813 | } |
| 5814 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5815 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5816 | priv->assoc_request.beacon_interval); |
| 5817 | } |
| 5818 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5819 | static void ipw_bg_adhoc_check(void *data) |
| 5820 | { |
| 5821 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5822 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5823 | ipw_adhoc_check(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 5824 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5825 | } |
| 5826 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 5827 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5828 | static void ipw_debug_config(struct ipw_priv *priv) |
| 5829 | { |
| 5830 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
| 5831 | "[CFG 0x%08X]\n", priv->config); |
| 5832 | if (priv->config & CFG_STATIC_CHANNEL) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5833 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5834 | else |
| 5835 | IPW_DEBUG_INFO("Channel unlocked.\n"); |
| 5836 | if (priv->config & CFG_STATIC_ESSID) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5837 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5838 | escape_essid(priv->essid, priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5839 | else |
| 5840 | IPW_DEBUG_INFO("ESSID unlocked.\n"); |
| 5841 | if (priv->config & CFG_STATIC_BSSID) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5842 | IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n", |
| 5843 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5844 | else |
| 5845 | IPW_DEBUG_INFO("BSSID unlocked.\n"); |
| 5846 | if (priv->capability & CAP_PRIVACY_ON) |
| 5847 | IPW_DEBUG_INFO("PRIVACY on\n"); |
| 5848 | else |
| 5849 | IPW_DEBUG_INFO("PRIVACY off\n"); |
| 5850 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); |
| 5851 | } |
| 5852 | #else |
Jiri Benc | 8d45ff7 | 2005-08-25 20:09:39 -0400 | [diff] [blame] | 5853 | #define ipw_debug_config(x) do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5854 | #endif |
| 5855 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5856 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5857 | { |
| 5858 | /* TODO: Verify that this works... */ |
| 5859 | struct ipw_fixed_rate fr = { |
| 5860 | .tx_rates = priv->rates_mask |
| 5861 | }; |
| 5862 | u32 reg; |
| 5863 | u16 mask = 0; |
| 5864 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5865 | /* Identify 'current FW band' and match it with the fixed |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5866 | * Tx rates */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5867 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5868 | switch (priv->ieee->freq_band) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5869 | case IEEE80211_52GHZ_BAND: /* A only */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5870 | /* IEEE_A */ |
| 5871 | if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { |
| 5872 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5873 | IPW_DEBUG_WX |
| 5874 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5875 | fr.tx_rates = 0; |
| 5876 | break; |
| 5877 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5878 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5879 | fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A; |
| 5880 | break; |
| 5881 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5882 | default: /* 2.4Ghz or Mixed */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5883 | /* IEEE_B */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5884 | if (mode == IEEE_B) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5885 | if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { |
| 5886 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5887 | IPW_DEBUG_WX |
| 5888 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5889 | fr.tx_rates = 0; |
| 5890 | } |
| 5891 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5892 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5893 | |
| 5894 | /* IEEE_G */ |
| 5895 | if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK | |
| 5896 | IEEE80211_OFDM_RATES_MASK)) { |
| 5897 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5898 | IPW_DEBUG_WX |
| 5899 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5900 | fr.tx_rates = 0; |
| 5901 | break; |
| 5902 | } |
| 5903 | |
| 5904 | if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) { |
| 5905 | mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1); |
| 5906 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK; |
| 5907 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5908 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5909 | if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) { |
| 5910 | mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1); |
| 5911 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK; |
| 5912 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5913 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5914 | if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) { |
| 5915 | mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1); |
| 5916 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK; |
| 5917 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5918 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5919 | fr.tx_rates |= mask; |
| 5920 | break; |
| 5921 | } |
| 5922 | |
| 5923 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5924 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5925 | } |
| 5926 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5927 | static void ipw_abort_scan(struct ipw_priv *priv) |
| 5928 | { |
| 5929 | int err; |
| 5930 | |
| 5931 | if (priv->status & STATUS_SCAN_ABORTING) { |
| 5932 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); |
| 5933 | return; |
| 5934 | } |
| 5935 | priv->status |= STATUS_SCAN_ABORTING; |
| 5936 | |
| 5937 | err = ipw_send_scan_abort(priv); |
| 5938 | if (err) |
| 5939 | IPW_DEBUG_HC("Request to abort scan failed.\n"); |
| 5940 | } |
| 5941 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5942 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
| 5943 | struct ipw_scan_request_ext *scan, |
| 5944 | int scan_type) |
| 5945 | { |
| 5946 | int channel_index = 0; |
| 5947 | const struct ieee80211_geo *geo; |
| 5948 | int i; |
| 5949 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 5950 | geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5951 | |
| 5952 | if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { |
| 5953 | int start = channel_index; |
| 5954 | for (i = 0; i < geo->a_channels; i++) { |
| 5955 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5956 | geo->a[i].channel == priv->channel) |
| 5957 | continue; |
| 5958 | channel_index++; |
| 5959 | scan->channels_list[channel_index] = geo->a[i].channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5960 | ipw_set_scan_type(scan, channel_index, |
| 5961 | geo->a[i]. |
| 5962 | flags & IEEE80211_CH_PASSIVE_ONLY ? |
| 5963 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : |
| 5964 | scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | if (start != channel_index) { |
| 5968 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | |
| 5969 | (channel_index - start); |
| 5970 | channel_index++; |
| 5971 | } |
| 5972 | } |
| 5973 | |
| 5974 | if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { |
| 5975 | int start = channel_index; |
| 5976 | if (priv->config & CFG_SPEED_SCAN) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5977 | int index; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5978 | u8 channels[IEEE80211_24GHZ_CHANNELS] = { |
| 5979 | /* nop out the list */ |
| 5980 | [0] = 0 |
| 5981 | }; |
| 5982 | |
| 5983 | u8 channel; |
| 5984 | while (channel_index < IPW_SCAN_CHANNELS) { |
| 5985 | channel = |
| 5986 | priv->speed_scan[priv->speed_scan_pos]; |
| 5987 | if (channel == 0) { |
| 5988 | priv->speed_scan_pos = 0; |
| 5989 | channel = priv->speed_scan[0]; |
| 5990 | } |
| 5991 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5992 | channel == priv->channel) { |
| 5993 | priv->speed_scan_pos++; |
| 5994 | continue; |
| 5995 | } |
| 5996 | |
| 5997 | /* If this channel has already been |
| 5998 | * added in scan, break from loop |
| 5999 | * and this will be the first channel |
| 6000 | * in the next scan. |
| 6001 | */ |
| 6002 | if (channels[channel - 1] != 0) |
| 6003 | break; |
| 6004 | |
| 6005 | channels[channel - 1] = 1; |
| 6006 | priv->speed_scan_pos++; |
| 6007 | channel_index++; |
| 6008 | scan->channels_list[channel_index] = channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6009 | index = |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 6010 | ieee80211_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6011 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6012 | geo->bg[index]. |
| 6013 | flags & |
| 6014 | IEEE80211_CH_PASSIVE_ONLY ? |
| 6015 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6016 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6017 | } |
| 6018 | } else { |
| 6019 | for (i = 0; i < geo->bg_channels; i++) { |
| 6020 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6021 | geo->bg[i].channel == priv->channel) |
| 6022 | continue; |
| 6023 | channel_index++; |
| 6024 | scan->channels_list[channel_index] = |
| 6025 | geo->bg[i].channel; |
| 6026 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6027 | geo->bg[i]. |
| 6028 | flags & |
| 6029 | IEEE80211_CH_PASSIVE_ONLY ? |
| 6030 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6031 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6032 | } |
| 6033 | } |
| 6034 | |
| 6035 | if (start != channel_index) { |
| 6036 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | |
| 6037 | (channel_index - start); |
| 6038 | } |
| 6039 | } |
| 6040 | } |
| 6041 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6042 | static int ipw_request_scan(struct ipw_priv *priv) |
| 6043 | { |
| 6044 | struct ipw_scan_request_ext scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6045 | int err = 0, scan_type; |
| 6046 | |
| 6047 | if (!(priv->status & STATUS_INIT) || |
| 6048 | (priv->status & STATUS_EXIT_PENDING)) |
| 6049 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6050 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6051 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6052 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6053 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6054 | IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6055 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6056 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6057 | } |
| 6058 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6059 | if (!(priv->status & STATUS_SCAN_FORCED) && |
| 6060 | priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6061 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6062 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6063 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 6067 | IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6068 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6069 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | memset(&scan, 0, sizeof(scan)); |
| 6073 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6074 | if (priv->config & CFG_SPEED_SCAN) |
| 6075 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 6076 | cpu_to_le16(30); |
| 6077 | else |
| 6078 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 6079 | cpu_to_le16(20); |
| 6080 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6081 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 6082 | cpu_to_le16(20); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6083 | 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] | 6084 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6085 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6086 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6087 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6088 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6089 | u8 channel; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6090 | u8 band = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6091 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 6092 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6093 | case IEEE80211_52GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6094 | band = (u8) (IPW_A_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6095 | channel = priv->channel; |
| 6096 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6097 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6098 | case IEEE80211_24GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6099 | band = (u8) (IPW_B_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6100 | channel = priv->channel; |
| 6101 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6102 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6103 | default: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6104 | band = (u8) (IPW_B_MODE << 6) | 1; |
| 6105 | channel = 9; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6106 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6107 | } |
| 6108 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6109 | scan.channels_list[0] = band; |
| 6110 | scan.channels_list[1] = channel; |
| 6111 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6112 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6113 | /* NOTE: The card will sit on this channel for this time |
| 6114 | * period. Scan aborts are timing sensitive and frequently |
| 6115 | * result in firmware restarts. As such, it is best to |
| 6116 | * set a small dwell_time here and just keep re-issuing |
| 6117 | * scans. Otherwise fast channel hopping will not actually |
| 6118 | * hop channels. |
| 6119 | * |
| 6120 | * TODO: Move SPEED SCAN support to all modes and bands */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6121 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
| 6122 | cpu_to_le16(2000); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6123 | } else { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6124 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 6125 | /* If we are roaming, then make this a directed scan for the |
| 6126 | * current network. Otherwise, ensure that every other scan |
| 6127 | * is a fast channel hop scan */ |
| 6128 | if ((priv->status & STATUS_ROAMING) |
| 6129 | || (!(priv->status & STATUS_ASSOCIATED) |
| 6130 | && (priv->config & CFG_STATIC_ESSID) |
| 6131 | && (le32_to_cpu(scan.full_scan_index) % 2))) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6132 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 6133 | if (err) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6134 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6135 | "failed.\n"); |
| 6136 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6140 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6141 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6142 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6143 | ipw_add_scan_channels(priv, &scan, scan_type); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6144 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6145 | } |
| 6146 | #endif |
| 6147 | |
| 6148 | err = ipw_send_scan_request_ext(priv, &scan); |
| 6149 | if (err) { |
| 6150 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6151 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | priv->status |= STATUS_SCANNING; |
| 6155 | priv->status &= ~STATUS_SCAN_PENDING; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6156 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6157 | IPW_SCAN_CHECK_WATCHDOG); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6158 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6159 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6160 | return err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6161 | } |
| 6162 | |
| 6163 | static void ipw_bg_abort_scan(void *data) |
| 6164 | { |
| 6165 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6166 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6167 | ipw_abort_scan(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6168 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6169 | } |
| 6170 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6171 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
| 6172 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6173 | /* This is called when wpa_supplicant loads and closes the driver |
| 6174 | * interface. */ |
Hong Liu | cdd1fa1 | 2005-08-31 18:14:27 +0800 | [diff] [blame] | 6175 | priv->ieee->wpa_enabled = value; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6176 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6177 | } |
| 6178 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6179 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
| 6180 | { |
| 6181 | struct ieee80211_device *ieee = priv->ieee; |
| 6182 | struct ieee80211_security sec = { |
| 6183 | .flags = SEC_AUTH_MODE, |
| 6184 | }; |
| 6185 | int ret = 0; |
| 6186 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6187 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6188 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
| 6189 | ieee->open_wep = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6190 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6191 | sec.auth_mode = WLAN_AUTH_OPEN; |
| 6192 | ieee->open_wep = 1; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 6193 | } else if (value & IW_AUTH_ALG_LEAP) { |
| 6194 | sec.auth_mode = WLAN_AUTH_LEAP; |
| 6195 | ieee->open_wep = 1; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6196 | } else |
| 6197 | return -EINVAL; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6198 | |
| 6199 | if (ieee->set_security) |
| 6200 | ieee->set_security(ieee->dev, &sec); |
| 6201 | else |
| 6202 | ret = -EOPNOTSUPP; |
| 6203 | |
| 6204 | return ret; |
| 6205 | } |
| 6206 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 6207 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
| 6208 | int wpa_ie_len) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6209 | { |
| 6210 | /* make sure WPA is enabled */ |
| 6211 | ipw_wpa_enable(priv, 1); |
| 6212 | |
| 6213 | ipw_disassociate(priv); |
| 6214 | } |
| 6215 | |
| 6216 | static int ipw_set_rsn_capa(struct ipw_priv *priv, |
| 6217 | char *capabilities, int length) |
| 6218 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6219 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
| 6220 | |
Zhu Yi | 0a7bcf2 | 2006-01-24 16:37:28 +0800 | [diff] [blame] | 6221 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 6222 | capabilities); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6223 | } |
| 6224 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6225 | /* |
| 6226 | * WE-18 support |
| 6227 | */ |
| 6228 | |
| 6229 | /* SIOCSIWGENIE */ |
| 6230 | static int ipw_wx_set_genie(struct net_device *dev, |
| 6231 | struct iw_request_info *info, |
| 6232 | union iwreq_data *wrqu, char *extra) |
| 6233 | { |
| 6234 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6235 | struct ieee80211_device *ieee = priv->ieee; |
| 6236 | u8 *buf; |
| 6237 | int err = 0; |
| 6238 | |
| 6239 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
| 6240 | (wrqu->data.length && extra == NULL)) |
| 6241 | return -EINVAL; |
| 6242 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6243 | //mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6244 | |
| 6245 | //if (!ieee->wpa_enabled) { |
| 6246 | // err = -EOPNOTSUPP; |
| 6247 | // goto out; |
| 6248 | //} |
| 6249 | |
| 6250 | if (wrqu->data.length) { |
| 6251 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 6252 | if (buf == NULL) { |
| 6253 | err = -ENOMEM; |
| 6254 | goto out; |
| 6255 | } |
| 6256 | |
| 6257 | memcpy(buf, extra, wrqu->data.length); |
| 6258 | kfree(ieee->wpa_ie); |
| 6259 | ieee->wpa_ie = buf; |
| 6260 | ieee->wpa_ie_len = wrqu->data.length; |
| 6261 | } else { |
| 6262 | kfree(ieee->wpa_ie); |
| 6263 | ieee->wpa_ie = NULL; |
| 6264 | ieee->wpa_ie_len = 0; |
| 6265 | } |
| 6266 | |
| 6267 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6268 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6269 | //mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6270 | return err; |
| 6271 | } |
| 6272 | |
| 6273 | /* SIOCGIWGENIE */ |
| 6274 | static int ipw_wx_get_genie(struct net_device *dev, |
| 6275 | struct iw_request_info *info, |
| 6276 | union iwreq_data *wrqu, char *extra) |
| 6277 | { |
| 6278 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6279 | struct ieee80211_device *ieee = priv->ieee; |
| 6280 | int err = 0; |
| 6281 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6282 | //mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6283 | |
| 6284 | //if (!ieee->wpa_enabled) { |
| 6285 | // err = -EOPNOTSUPP; |
| 6286 | // goto out; |
| 6287 | //} |
| 6288 | |
| 6289 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
| 6290 | wrqu->data.length = 0; |
| 6291 | goto out; |
| 6292 | } |
| 6293 | |
| 6294 | if (wrqu->data.length < ieee->wpa_ie_len) { |
| 6295 | err = -E2BIG; |
| 6296 | goto out; |
| 6297 | } |
| 6298 | |
| 6299 | wrqu->data.length = ieee->wpa_ie_len; |
| 6300 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6301 | |
| 6302 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6303 | //mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6304 | return err; |
| 6305 | } |
| 6306 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6307 | static int wext_cipher2level(int cipher) |
| 6308 | { |
| 6309 | switch (cipher) { |
| 6310 | case IW_AUTH_CIPHER_NONE: |
| 6311 | return SEC_LEVEL_0; |
| 6312 | case IW_AUTH_CIPHER_WEP40: |
| 6313 | case IW_AUTH_CIPHER_WEP104: |
| 6314 | return SEC_LEVEL_1; |
| 6315 | case IW_AUTH_CIPHER_TKIP: |
| 6316 | return SEC_LEVEL_2; |
| 6317 | case IW_AUTH_CIPHER_CCMP: |
| 6318 | return SEC_LEVEL_3; |
| 6319 | default: |
| 6320 | return -1; |
| 6321 | } |
| 6322 | } |
| 6323 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6324 | /* SIOCSIWAUTH */ |
| 6325 | static int ipw_wx_set_auth(struct net_device *dev, |
| 6326 | struct iw_request_info *info, |
| 6327 | union iwreq_data *wrqu, char *extra) |
| 6328 | { |
| 6329 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6330 | struct ieee80211_device *ieee = priv->ieee; |
| 6331 | struct iw_param *param = &wrqu->param; |
| 6332 | struct ieee80211_crypt_data *crypt; |
| 6333 | unsigned long flags; |
| 6334 | int ret = 0; |
| 6335 | |
| 6336 | switch (param->flags & IW_AUTH_INDEX) { |
| 6337 | case IW_AUTH_WPA_VERSION: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6338 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6339 | case IW_AUTH_CIPHER_PAIRWISE: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6340 | ipw_set_hw_decrypt_unicast(priv, |
| 6341 | wext_cipher2level(param->value)); |
| 6342 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6343 | case IW_AUTH_CIPHER_GROUP: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6344 | ipw_set_hw_decrypt_multicast(priv, |
| 6345 | wext_cipher2level(param->value)); |
| 6346 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6347 | case IW_AUTH_KEY_MGMT: |
| 6348 | /* |
| 6349 | * ipw2200 does not use these parameters |
| 6350 | */ |
| 6351 | break; |
| 6352 | |
| 6353 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6354 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6355 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6356 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6357 | |
| 6358 | flags = crypt->ops->get_flags(crypt->priv); |
| 6359 | |
| 6360 | if (param->value) |
| 6361 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6362 | else |
| 6363 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6364 | |
| 6365 | crypt->ops->set_flags(flags, crypt->priv); |
| 6366 | |
| 6367 | break; |
| 6368 | |
| 6369 | case IW_AUTH_DROP_UNENCRYPTED:{ |
| 6370 | /* HACK: |
| 6371 | * |
| 6372 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6373 | * is loaded and unloaded, regardless of if WPA is being |
| 6374 | * used. No other calls are made which can be used to |
| 6375 | * determine if encryption will be used or not prior to |
| 6376 | * association being expected. If encryption is not being |
| 6377 | * used, drop_unencrypted is set to false, else true -- we |
| 6378 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6379 | * be set. |
| 6380 | */ |
| 6381 | struct ieee80211_security sec = { |
| 6382 | .flags = SEC_ENABLED, |
| 6383 | .enabled = param->value, |
| 6384 | }; |
| 6385 | priv->ieee->drop_unencrypted = param->value; |
| 6386 | /* We only change SEC_LEVEL for open mode. Others |
| 6387 | * are set by ipw_wpa_set_encryption. |
| 6388 | */ |
| 6389 | if (!param->value) { |
| 6390 | sec.flags |= SEC_LEVEL; |
| 6391 | sec.level = SEC_LEVEL_0; |
| 6392 | } else { |
| 6393 | sec.flags |= SEC_LEVEL; |
| 6394 | sec.level = SEC_LEVEL_1; |
| 6395 | } |
| 6396 | if (priv->ieee->set_security) |
| 6397 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6398 | break; |
| 6399 | } |
| 6400 | |
| 6401 | case IW_AUTH_80211_AUTH_ALG: |
| 6402 | ret = ipw_wpa_set_auth_algs(priv, param->value); |
| 6403 | break; |
| 6404 | |
| 6405 | case IW_AUTH_WPA_ENABLED: |
| 6406 | ret = ipw_wpa_enable(priv, param->value); |
| 6407 | break; |
| 6408 | |
| 6409 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6410 | ieee->ieee802_1x = param->value; |
| 6411 | break; |
| 6412 | |
| 6413 | //case IW_AUTH_ROAMING_CONTROL: |
| 6414 | case IW_AUTH_PRIVACY_INVOKED: |
| 6415 | ieee->privacy_invoked = param->value; |
| 6416 | break; |
| 6417 | |
| 6418 | default: |
| 6419 | return -EOPNOTSUPP; |
| 6420 | } |
| 6421 | return ret; |
| 6422 | } |
| 6423 | |
| 6424 | /* SIOCGIWAUTH */ |
| 6425 | static int ipw_wx_get_auth(struct net_device *dev, |
| 6426 | struct iw_request_info *info, |
| 6427 | union iwreq_data *wrqu, char *extra) |
| 6428 | { |
| 6429 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6430 | struct ieee80211_device *ieee = priv->ieee; |
| 6431 | struct ieee80211_crypt_data *crypt; |
| 6432 | struct iw_param *param = &wrqu->param; |
| 6433 | int ret = 0; |
| 6434 | |
| 6435 | switch (param->flags & IW_AUTH_INDEX) { |
| 6436 | case IW_AUTH_WPA_VERSION: |
| 6437 | case IW_AUTH_CIPHER_PAIRWISE: |
| 6438 | case IW_AUTH_CIPHER_GROUP: |
| 6439 | case IW_AUTH_KEY_MGMT: |
| 6440 | /* |
| 6441 | * wpa_supplicant will control these internally |
| 6442 | */ |
| 6443 | ret = -EOPNOTSUPP; |
| 6444 | break; |
| 6445 | |
| 6446 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6447 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6448 | if (!crypt || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6449 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6450 | |
| 6451 | param->value = (crypt->ops->get_flags(crypt->priv) & |
| 6452 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; |
| 6453 | |
| 6454 | break; |
| 6455 | |
| 6456 | case IW_AUTH_DROP_UNENCRYPTED: |
| 6457 | param->value = ieee->drop_unencrypted; |
| 6458 | break; |
| 6459 | |
| 6460 | case IW_AUTH_80211_AUTH_ALG: |
| 6461 | param->value = ieee->sec.auth_mode; |
| 6462 | break; |
| 6463 | |
| 6464 | case IW_AUTH_WPA_ENABLED: |
| 6465 | param->value = ieee->wpa_enabled; |
| 6466 | break; |
| 6467 | |
| 6468 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6469 | param->value = ieee->ieee802_1x; |
| 6470 | break; |
| 6471 | |
| 6472 | case IW_AUTH_ROAMING_CONTROL: |
| 6473 | case IW_AUTH_PRIVACY_INVOKED: |
| 6474 | param->value = ieee->privacy_invoked; |
| 6475 | break; |
| 6476 | |
| 6477 | default: |
| 6478 | return -EOPNOTSUPP; |
| 6479 | } |
| 6480 | return 0; |
| 6481 | } |
| 6482 | |
| 6483 | /* SIOCSIWENCODEEXT */ |
| 6484 | static int ipw_wx_set_encodeext(struct net_device *dev, |
| 6485 | struct iw_request_info *info, |
| 6486 | union iwreq_data *wrqu, char *extra) |
| 6487 | { |
| 6488 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6489 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 6490 | |
| 6491 | if (hwcrypto) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6492 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6493 | /* IPW HW can't build TKIP MIC, |
| 6494 | host decryption still needed */ |
| 6495 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) |
| 6496 | priv->ieee->host_mc_decrypt = 1; |
| 6497 | else { |
| 6498 | priv->ieee->host_encrypt = 0; |
| 6499 | priv->ieee->host_encrypt_msdu = 1; |
| 6500 | priv->ieee->host_decrypt = 1; |
| 6501 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6502 | } else { |
| 6503 | priv->ieee->host_encrypt = 0; |
| 6504 | priv->ieee->host_encrypt_msdu = 0; |
| 6505 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6506 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6507 | } |
| 6508 | } |
| 6509 | |
| 6510 | return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
| 6511 | } |
| 6512 | |
| 6513 | /* SIOCGIWENCODEEXT */ |
| 6514 | static int ipw_wx_get_encodeext(struct net_device *dev, |
| 6515 | struct iw_request_info *info, |
| 6516 | union iwreq_data *wrqu, char *extra) |
| 6517 | { |
| 6518 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6519 | return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); |
| 6520 | } |
| 6521 | |
| 6522 | /* SIOCSIWMLME */ |
| 6523 | static int ipw_wx_set_mlme(struct net_device *dev, |
| 6524 | struct iw_request_info *info, |
| 6525 | union iwreq_data *wrqu, char *extra) |
| 6526 | { |
| 6527 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6528 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 6529 | u16 reason; |
| 6530 | |
| 6531 | reason = cpu_to_le16(mlme->reason_code); |
| 6532 | |
| 6533 | switch (mlme->cmd) { |
| 6534 | case IW_MLME_DEAUTH: |
| 6535 | // silently ignore |
| 6536 | break; |
| 6537 | |
| 6538 | case IW_MLME_DISASSOC: |
| 6539 | ipw_disassociate(priv); |
| 6540 | break; |
| 6541 | |
| 6542 | default: |
| 6543 | return -EOPNOTSUPP; |
| 6544 | } |
| 6545 | return 0; |
| 6546 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6547 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6548 | #ifdef CONFIG_IPW_QOS |
| 6549 | |
| 6550 | /* QoS */ |
| 6551 | /* |
| 6552 | * get the modulation type of the current network or |
| 6553 | * the card current mode |
| 6554 | */ |
Adrian Bunk | 53d0bcf | 2006-03-04 13:14:31 +0100 | [diff] [blame] | 6555 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6556 | { |
| 6557 | u8 mode = 0; |
| 6558 | |
| 6559 | if (priv->status & STATUS_ASSOCIATED) { |
| 6560 | unsigned long flags; |
| 6561 | |
| 6562 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6563 | mode = priv->assoc_network->mode; |
| 6564 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6565 | } else { |
| 6566 | mode = priv->ieee->mode; |
| 6567 | } |
| 6568 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); |
| 6569 | return mode; |
| 6570 | } |
| 6571 | |
| 6572 | /* |
| 6573 | * Handle management frame beacon and probe response |
| 6574 | */ |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6575 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
| 6576 | int active_network, |
| 6577 | struct ieee80211_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6578 | { |
| 6579 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6580 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6581 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6582 | network->qos_data.active = network->qos_data.supported; |
| 6583 | |
| 6584 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6585 | if (active_network && |
| 6586 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6587 | network->qos_data.active = network->qos_data.supported; |
| 6588 | |
| 6589 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 6590 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 6591 | (network->qos_data.old_param_count != |
| 6592 | network->qos_data.param_count)) { |
| 6593 | network->qos_data.old_param_count = |
| 6594 | network->qos_data.param_count; |
| 6595 | schedule_work(&priv->qos_activate); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6596 | IPW_DEBUG_QOS("QoS parameters change call " |
| 6597 | "qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6598 | } |
| 6599 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6600 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
| 6601 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6602 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6603 | else |
| 6604 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6605 | &def_parameters_OFDM, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6606 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6607 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
| 6608 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); |
| 6609 | schedule_work(&priv->qos_activate); |
| 6610 | } |
| 6611 | |
| 6612 | network->qos_data.active = 0; |
| 6613 | network->qos_data.supported = 0; |
| 6614 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6615 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6616 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { |
| 6617 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) |
| 6618 | if ((network->capability & WLAN_CAPABILITY_IBSS) && |
| 6619 | !(network->flags & NETWORK_EMPTY_ESSID)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6620 | if ((network->ssid_len == |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6621 | priv->assoc_network->ssid_len) && |
| 6622 | !memcmp(network->ssid, |
| 6623 | priv->assoc_network->ssid, |
| 6624 | network->ssid_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6625 | queue_work(priv->workqueue, |
| 6626 | &priv->merge_networks); |
| 6627 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6628 | } |
| 6629 | |
| 6630 | return 0; |
| 6631 | } |
| 6632 | |
| 6633 | /* |
| 6634 | * This function set up the firmware to support QoS. It sends |
| 6635 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO |
| 6636 | */ |
| 6637 | static int ipw_qos_activate(struct ipw_priv *priv, |
| 6638 | struct ieee80211_qos_data *qos_network_data) |
| 6639 | { |
| 6640 | int err; |
| 6641 | struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS]; |
| 6642 | struct ieee80211_qos_parameters *active_one = NULL; |
| 6643 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6644 | u32 burst_duration; |
| 6645 | int i; |
| 6646 | u8 type; |
| 6647 | |
| 6648 | type = ipw_qos_current_mode(priv); |
| 6649 | |
| 6650 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); |
| 6651 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); |
| 6652 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); |
| 6653 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); |
| 6654 | |
| 6655 | if (qos_network_data == NULL) { |
| 6656 | if (type == IEEE_B) { |
| 6657 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); |
| 6658 | active_one = &def_parameters_CCK; |
| 6659 | } else |
| 6660 | active_one = &def_parameters_OFDM; |
| 6661 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6662 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6663 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6664 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6665 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
| 6666 | (u16) burst_duration; |
| 6667 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6668 | if (type == IEEE_B) { |
| 6669 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", |
| 6670 | type); |
| 6671 | if (priv->qos_data.qos_enable == 0) |
| 6672 | active_one = &def_parameters_CCK; |
| 6673 | else |
| 6674 | active_one = priv->qos_data.def_qos_parm_CCK; |
| 6675 | } else { |
| 6676 | if (priv->qos_data.qos_enable == 0) |
| 6677 | active_one = &def_parameters_OFDM; |
| 6678 | else |
| 6679 | active_one = priv->qos_data.def_qos_parm_OFDM; |
| 6680 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6681 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6682 | } else { |
| 6683 | unsigned long flags; |
| 6684 | int active; |
| 6685 | |
| 6686 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6687 | active_one = &(qos_network_data->parameters); |
| 6688 | qos_network_data->old_param_count = |
| 6689 | qos_network_data->param_count; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6690 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6691 | active = qos_network_data->supported; |
| 6692 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6693 | |
| 6694 | if (active == 0) { |
| 6695 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6696 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
| 6697 | qos_parameters[QOS_PARAM_SET_ACTIVE]. |
| 6698 | tx_op_limit[i] = (u16) burst_duration; |
| 6699 | } |
| 6700 | } |
| 6701 | |
| 6702 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6703 | err = ipw_send_qos_params_command(priv, |
| 6704 | (struct ieee80211_qos_parameters *) |
| 6705 | &(qos_parameters[0])); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6706 | if (err) |
| 6707 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); |
| 6708 | |
| 6709 | return err; |
| 6710 | } |
| 6711 | |
| 6712 | /* |
| 6713 | * send IPW_CMD_WME_INFO to the firmware |
| 6714 | */ |
| 6715 | static int ipw_qos_set_info_element(struct ipw_priv *priv) |
| 6716 | { |
| 6717 | int ret = 0; |
| 6718 | struct ieee80211_qos_information_element qos_info; |
| 6719 | |
| 6720 | if (priv == NULL) |
| 6721 | return -1; |
| 6722 | |
| 6723 | qos_info.elementID = QOS_ELEMENT_ID; |
| 6724 | qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2; |
| 6725 | |
| 6726 | qos_info.version = QOS_VERSION_1; |
| 6727 | qos_info.ac_info = 0; |
| 6728 | |
| 6729 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); |
| 6730 | qos_info.qui_type = QOS_OUI_TYPE; |
| 6731 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; |
| 6732 | |
| 6733 | ret = ipw_send_qos_info_command(priv, &qos_info); |
| 6734 | if (ret != 0) { |
| 6735 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); |
| 6736 | } |
| 6737 | return ret; |
| 6738 | } |
| 6739 | |
| 6740 | /* |
| 6741 | * Set the QoS parameter with the association request structure |
| 6742 | */ |
| 6743 | static int ipw_qos_association(struct ipw_priv *priv, |
| 6744 | struct ieee80211_network *network) |
| 6745 | { |
| 6746 | int err = 0; |
| 6747 | struct ieee80211_qos_data *qos_data = NULL; |
| 6748 | struct ieee80211_qos_data ibss_data = { |
| 6749 | .supported = 1, |
| 6750 | .active = 1, |
| 6751 | }; |
| 6752 | |
| 6753 | switch (priv->ieee->iw_mode) { |
| 6754 | case IW_MODE_ADHOC: |
| 6755 | if (!(network->capability & WLAN_CAPABILITY_IBSS)) |
| 6756 | BUG(); |
| 6757 | |
| 6758 | qos_data = &ibss_data; |
| 6759 | break; |
| 6760 | |
| 6761 | case IW_MODE_INFRA: |
| 6762 | qos_data = &network->qos_data; |
| 6763 | break; |
| 6764 | |
| 6765 | default: |
| 6766 | BUG(); |
| 6767 | break; |
| 6768 | } |
| 6769 | |
| 6770 | err = ipw_qos_activate(priv, qos_data); |
| 6771 | if (err) { |
| 6772 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; |
| 6773 | return err; |
| 6774 | } |
| 6775 | |
| 6776 | if (priv->qos_data.qos_enable && qos_data->supported) { |
| 6777 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); |
| 6778 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; |
| 6779 | return ipw_qos_set_info_element(priv); |
| 6780 | } |
| 6781 | |
| 6782 | return 0; |
| 6783 | } |
| 6784 | |
| 6785 | /* |
| 6786 | * handling the beaconing responces. if we get different QoS setting |
| 6787 | * of the network from the the associated setting adjust the QoS |
| 6788 | * setting |
| 6789 | */ |
| 6790 | static int ipw_qos_association_resp(struct ipw_priv *priv, |
| 6791 | struct ieee80211_network *network) |
| 6792 | { |
| 6793 | int ret = 0; |
| 6794 | unsigned long flags; |
| 6795 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6796 | int set_qos_param = 0; |
| 6797 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6798 | if ((priv == NULL) || (network == NULL) || |
| 6799 | (priv->assoc_network == NULL)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6800 | return ret; |
| 6801 | |
| 6802 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 6803 | return ret; |
| 6804 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6805 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6806 | return ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6807 | |
| 6808 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6809 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6810 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6811 | sizeof(struct ieee80211_qos_data)); |
| 6812 | priv->assoc_network->qos_data.active = 1; |
| 6813 | if ((network->qos_data.old_param_count != |
| 6814 | network->qos_data.param_count)) { |
| 6815 | set_qos_param = 1; |
| 6816 | network->qos_data.old_param_count = |
| 6817 | network->qos_data.param_count; |
| 6818 | } |
| 6819 | |
| 6820 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6821 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
| 6822 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6823 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6824 | else |
| 6825 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6826 | &def_parameters_OFDM, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6827 | priv->assoc_network->qos_data.active = 0; |
| 6828 | priv->assoc_network->qos_data.supported = 0; |
| 6829 | set_qos_param = 1; |
| 6830 | } |
| 6831 | |
| 6832 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6833 | |
| 6834 | if (set_qos_param == 1) |
| 6835 | schedule_work(&priv->qos_activate); |
| 6836 | |
| 6837 | return ret; |
| 6838 | } |
| 6839 | |
| 6840 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) |
| 6841 | { |
| 6842 | u32 ret = 0; |
| 6843 | |
| 6844 | if ((priv == NULL)) |
| 6845 | return 0; |
| 6846 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6847 | if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6848 | ret = priv->qos_data.burst_duration_CCK; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6849 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6850 | ret = priv->qos_data.burst_duration_OFDM; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6851 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6852 | return ret; |
| 6853 | } |
| 6854 | |
| 6855 | /* |
| 6856 | * Initialize the setting of QoS global |
| 6857 | */ |
| 6858 | static void ipw_qos_init(struct ipw_priv *priv, int enable, |
| 6859 | int burst_enable, u32 burst_duration_CCK, |
| 6860 | u32 burst_duration_OFDM) |
| 6861 | { |
| 6862 | priv->qos_data.qos_enable = enable; |
| 6863 | |
| 6864 | if (priv->qos_data.qos_enable) { |
| 6865 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; |
| 6866 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; |
| 6867 | IPW_DEBUG_QOS("QoS is enabled\n"); |
| 6868 | } else { |
| 6869 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; |
| 6870 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; |
| 6871 | IPW_DEBUG_QOS("QoS is not enabled\n"); |
| 6872 | } |
| 6873 | |
| 6874 | priv->qos_data.burst_enable = burst_enable; |
| 6875 | |
| 6876 | if (burst_enable) { |
| 6877 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; |
| 6878 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; |
| 6879 | } else { |
| 6880 | priv->qos_data.burst_duration_CCK = 0; |
| 6881 | priv->qos_data.burst_duration_OFDM = 0; |
| 6882 | } |
| 6883 | } |
| 6884 | |
| 6885 | /* |
| 6886 | * map the packet priority to the right TX Queue |
| 6887 | */ |
| 6888 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) |
| 6889 | { |
| 6890 | if (priority > 7 || !priv->qos_data.qos_enable) |
| 6891 | priority = 0; |
| 6892 | |
| 6893 | return from_priority_to_tx_queue[priority] - 1; |
| 6894 | } |
| 6895 | |
| 6896 | /* |
| 6897 | * add QoS parameter to the TX command |
| 6898 | */ |
| 6899 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, |
| 6900 | u16 priority, |
| 6901 | struct tfd_data *tfd, u8 unicast) |
| 6902 | { |
| 6903 | int ret = 0; |
| 6904 | int tx_queue_id = 0; |
| 6905 | struct ieee80211_qos_data *qos_data = NULL; |
| 6906 | int active, supported; |
| 6907 | unsigned long flags; |
| 6908 | |
| 6909 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 6910 | return 0; |
| 6911 | |
| 6912 | qos_data = &priv->assoc_network->qos_data; |
| 6913 | |
| 6914 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6915 | |
| 6916 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 6917 | if (unicast == 0) |
| 6918 | qos_data->active = 0; |
| 6919 | else |
| 6920 | qos_data->active = qos_data->supported; |
| 6921 | } |
| 6922 | |
| 6923 | active = qos_data->active; |
| 6924 | supported = qos_data->supported; |
| 6925 | |
| 6926 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6927 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6928 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
| 6929 | "unicast %d\n", |
| 6930 | priv->qos_data.qos_enable, active, supported, unicast); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6931 | if (active && priv->qos_data.qos_enable) { |
| 6932 | ret = from_priority_to_tx_queue[priority]; |
| 6933 | tx_queue_id = ret - 1; |
| 6934 | IPW_DEBUG_QOS("QoS packet priority is %d \n", priority); |
| 6935 | if (priority <= 7) { |
| 6936 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; |
| 6937 | tfd->tfd.tfd_26.mchdr.qos_ctrl = priority; |
| 6938 | tfd->tfd.tfd_26.mchdr.frame_ctl |= |
| 6939 | IEEE80211_STYPE_QOS_DATA; |
| 6940 | |
| 6941 | if (priv->qos_data.qos_no_ack_mask & |
| 6942 | (1UL << tx_queue_id)) { |
| 6943 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; |
| 6944 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= |
| 6945 | CTRL_QOS_NO_ACK; |
| 6946 | } |
| 6947 | } |
| 6948 | } |
| 6949 | |
| 6950 | return ret; |
| 6951 | } |
| 6952 | |
| 6953 | /* |
| 6954 | * background support to run QoS activate functionality |
| 6955 | */ |
| 6956 | static void ipw_bg_qos_activate(void *data) |
| 6957 | { |
| 6958 | struct ipw_priv *priv = data; |
| 6959 | |
| 6960 | if (priv == NULL) |
| 6961 | return; |
| 6962 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6963 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6964 | |
| 6965 | if (priv->status & STATUS_ASSOCIATED) |
| 6966 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); |
| 6967 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 6968 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6969 | } |
| 6970 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6971 | static int ipw_handle_probe_response(struct net_device *dev, |
| 6972 | struct ieee80211_probe_response *resp, |
| 6973 | struct ieee80211_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6974 | { |
| 6975 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6976 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 6977 | (network == priv->assoc_network)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6978 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6979 | ipw_qos_handle_probe_response(priv, active_network, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6980 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6981 | return 0; |
| 6982 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6983 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6984 | static int ipw_handle_beacon(struct net_device *dev, |
| 6985 | struct ieee80211_beacon *resp, |
| 6986 | struct ieee80211_network *network) |
| 6987 | { |
| 6988 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6989 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 6990 | (network == priv->assoc_network)); |
| 6991 | |
| 6992 | ipw_qos_handle_probe_response(priv, active_network, network); |
| 6993 | |
| 6994 | return 0; |
| 6995 | } |
| 6996 | |
| 6997 | static int ipw_handle_assoc_response(struct net_device *dev, |
| 6998 | struct ieee80211_assoc_response *resp, |
| 6999 | struct ieee80211_network *network) |
| 7000 | { |
| 7001 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 7002 | ipw_qos_association_resp(priv, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7003 | return 0; |
| 7004 | } |
| 7005 | |
| 7006 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
| 7007 | *qos_param) |
| 7008 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7009 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
| 7010 | sizeof(*qos_param) * 3, qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7011 | } |
| 7012 | |
| 7013 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element |
| 7014 | *qos_param) |
| 7015 | { |
Zhu Yi | 4e22699 | 2006-01-24 16:37:36 +0800 | [diff] [blame] | 7016 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
| 7017 | qos_param); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7018 | } |
| 7019 | |
| 7020 | #endif /* CONFIG_IPW_QOS */ |
| 7021 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7022 | static int ipw_associate_network(struct ipw_priv *priv, |
| 7023 | struct ieee80211_network *network, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7024 | struct ipw_supported_rates *rates, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7025 | { |
| 7026 | int err; |
| 7027 | |
| 7028 | if (priv->config & CFG_FIXED_RATE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7029 | ipw_set_fixed_rate(priv, network->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7030 | |
| 7031 | if (!(priv->config & CFG_STATIC_ESSID)) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7032 | priv->essid_len = min(network->ssid_len, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7033 | (u8) IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7034 | memcpy(priv->essid, network->ssid, priv->essid_len); |
| 7035 | } |
| 7036 | |
| 7037 | network->last_associate = jiffies; |
| 7038 | |
| 7039 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); |
| 7040 | priv->assoc_request.channel = network->channel; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7041 | priv->assoc_request.auth_key = 0; |
| 7042 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7043 | if ((priv->capability & CAP_PRIVACY_ON) && |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7044 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7045 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7046 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
| 7047 | |
Zhu Yi | 1ba61e0 | 2006-02-15 13:00:55 +0800 | [diff] [blame] | 7048 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7049 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7050 | |
| 7051 | } else if ((priv->capability & CAP_PRIVACY_ON) && |
| 7052 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) |
| 7053 | priv->assoc_request.auth_type = AUTH_LEAP; |
| 7054 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7055 | priv->assoc_request.auth_type = AUTH_OPEN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7056 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7057 | if (priv->ieee->wpa_ie_len) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7058 | priv->assoc_request.policy_support = 0x02; /* RSN active */ |
| 7059 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
| 7060 | priv->ieee->wpa_ie_len); |
| 7061 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7062 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7063 | /* |
| 7064 | * It is valid for our ieee device to support multiple modes, but |
| 7065 | * 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] | 7066 | * just one mode. |
| 7067 | */ |
| 7068 | if (network->mode & priv->ieee->mode & IEEE_A) |
| 7069 | priv->assoc_request.ieee_mode = IPW_A_MODE; |
| 7070 | else if (network->mode & priv->ieee->mode & IEEE_G) |
| 7071 | priv->assoc_request.ieee_mode = IPW_G_MODE; |
| 7072 | else if (network->mode & priv->ieee->mode & IEEE_B) |
| 7073 | priv->assoc_request.ieee_mode = IPW_B_MODE; |
| 7074 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7075 | priv->assoc_request.capability = network->capability; |
| 7076 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7077 | && !(priv->config & CFG_PREAMBLE_LONG)) { |
| 7078 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; |
| 7079 | } else { |
| 7080 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; |
| 7081 | |
| 7082 | /* Clear the short preamble if we won't be supporting it */ |
| 7083 | priv->assoc_request.capability &= |
| 7084 | ~WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 7085 | } |
| 7086 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7087 | /* Clear capability bits that aren't used in Ad Hoc */ |
| 7088 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7089 | priv->assoc_request.capability &= |
| 7090 | ~WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 7091 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7092 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7093 | "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] | 7094 | roaming ? "Rea" : "A", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7095 | escape_essid(priv->essid, priv->essid_len), |
| 7096 | network->channel, |
| 7097 | ipw_modes[priv->assoc_request.ieee_mode], |
| 7098 | rates->num_rates, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7099 | (priv->assoc_request.preamble_length == |
| 7100 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", |
| 7101 | network->capability & |
| 7102 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7103 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7104 | priv->capability & CAP_PRIVACY_ON ? |
| 7105 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7106 | "(open)") : "", |
| 7107 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7108 | priv->capability & CAP_PRIVACY_ON ? |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7109 | '1' + priv->ieee->sec.active_key : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7110 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7111 | |
| 7112 | priv->assoc_request.beacon_interval = network->beacon_interval; |
| 7113 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7114 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7115 | priv->assoc_request.assoc_type = HC_IBSS_START; |
| 7116 | priv->assoc_request.assoc_tsf_msw = 0; |
| 7117 | priv->assoc_request.assoc_tsf_lsw = 0; |
| 7118 | } else { |
| 7119 | if (unlikely(roaming)) |
| 7120 | priv->assoc_request.assoc_type = HC_REASSOCIATE; |
| 7121 | else |
| 7122 | priv->assoc_request.assoc_type = HC_ASSOCIATE; |
| 7123 | priv->assoc_request.assoc_tsf_msw = network->time_stamp[1]; |
| 7124 | priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0]; |
| 7125 | } |
| 7126 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7127 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7128 | |
| 7129 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7130 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); |
| 7131 | priv->assoc_request.atim_window = network->atim_window; |
| 7132 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7133 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7134 | priv->assoc_request.atim_window = 0; |
| 7135 | } |
| 7136 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7137 | priv->assoc_request.listen_interval = network->listen_interval; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7138 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7139 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 7140 | if (err) { |
| 7141 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); |
| 7142 | return err; |
| 7143 | } |
| 7144 | |
| 7145 | rates->ieee_mode = priv->assoc_request.ieee_mode; |
| 7146 | rates->purpose = IPW_RATE_CONNECT; |
| 7147 | ipw_send_supported_rates(priv, rates); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7148 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7149 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
| 7150 | priv->sys_config.dot11g_auto_detection = 1; |
| 7151 | else |
| 7152 | priv->sys_config.dot11g_auto_detection = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7153 | |
| 7154 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7155 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 7156 | else |
| 7157 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 7158 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7159 | err = ipw_send_system_config(priv, &priv->sys_config); |
| 7160 | if (err) { |
| 7161 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); |
| 7162 | return err; |
| 7163 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7164 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7165 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7166 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7167 | if (err) { |
| 7168 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7169 | return err; |
| 7170 | } |
| 7171 | |
| 7172 | /* |
| 7173 | * If preemption is enabled, it is possible for the association |
| 7174 | * to complete before we return from ipw_send_associate. Therefore |
| 7175 | * we have to be sure and update our priviate data first. |
| 7176 | */ |
| 7177 | priv->channel = network->channel; |
| 7178 | memcpy(priv->bssid, network->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7179 | priv->status |= STATUS_ASSOCIATING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7180 | priv->status &= ~STATUS_SECURITY_UPDATED; |
| 7181 | |
| 7182 | priv->assoc_network = network; |
| 7183 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7184 | #ifdef CONFIG_IPW_QOS |
| 7185 | ipw_qos_association(priv, network); |
| 7186 | #endif |
| 7187 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7188 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 7189 | if (err) { |
| 7190 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7191 | return err; |
| 7192 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7193 | |
| 7194 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7195 | escape_essid(priv->essid, priv->essid_len), |
| 7196 | MAC_ARG(priv->bssid)); |
| 7197 | |
| 7198 | return 0; |
| 7199 | } |
| 7200 | |
| 7201 | static void ipw_roam(void *data) |
| 7202 | { |
| 7203 | struct ipw_priv *priv = data; |
| 7204 | struct ieee80211_network *network = NULL; |
| 7205 | struct ipw_network_match match = { |
| 7206 | .network = priv->assoc_network |
| 7207 | }; |
| 7208 | |
| 7209 | /* The roaming process is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7210 | * |
| 7211 | * 1. Missed beacon threshold triggers the roaming process by |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7212 | * setting the status ROAM bit and requesting a scan. |
| 7213 | * 2. When the scan completes, it schedules the ROAM work |
| 7214 | * 3. The ROAM work looks at all of the known networks for one that |
| 7215 | * is a better network than the currently associated. If none |
| 7216 | * found, the ROAM process is over (ROAM bit cleared) |
| 7217 | * 4. If a better network is found, a disassociation request is |
| 7218 | * sent. |
| 7219 | * 5. When the disassociation completes, the roam work is again |
| 7220 | * scheduled. The second time through, the driver is no longer |
| 7221 | * associated, and the newly selected network is sent an |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7222 | * association request. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7223 | * 6. At this point ,the roaming process is complete and the ROAM |
| 7224 | * status bit is cleared. |
| 7225 | */ |
| 7226 | |
| 7227 | /* If we are no longer associated, and the roaming bit is no longer |
| 7228 | * set, then we are not actively roaming, so just return */ |
| 7229 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) |
| 7230 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7231 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7232 | if (priv->status & STATUS_ASSOCIATED) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7233 | /* First pass through ROAM process -- look for a better |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7234 | * network */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7235 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7236 | u8 rssi = priv->assoc_network->stats.rssi; |
| 7237 | priv->assoc_network->stats.rssi = -128; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7238 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7239 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 7240 | if (network != priv->assoc_network) |
| 7241 | ipw_best_network(priv, &match, network, 1); |
| 7242 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7243 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7244 | priv->assoc_network->stats.rssi = rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7245 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7246 | if (match.network == priv->assoc_network) { |
| 7247 | IPW_DEBUG_ASSOC("No better APs in this network to " |
| 7248 | "roam to.\n"); |
| 7249 | priv->status &= ~STATUS_ROAMING; |
| 7250 | ipw_debug_config(priv); |
| 7251 | return; |
| 7252 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7253 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7254 | ipw_send_disassociate(priv, 1); |
| 7255 | priv->assoc_network = match.network; |
| 7256 | |
| 7257 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7258 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7259 | |
| 7260 | /* Second pass through ROAM process -- request association */ |
| 7261 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); |
| 7262 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); |
| 7263 | priv->status &= ~STATUS_ROAMING; |
| 7264 | } |
| 7265 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7266 | static void ipw_bg_roam(void *data) |
| 7267 | { |
| 7268 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7269 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7270 | ipw_roam(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7271 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7272 | } |
| 7273 | |
| 7274 | static int ipw_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7275 | { |
| 7276 | struct ipw_priv *priv = data; |
| 7277 | |
| 7278 | struct ieee80211_network *network = NULL; |
| 7279 | struct ipw_network_match match = { |
| 7280 | .network = NULL |
| 7281 | }; |
| 7282 | struct ipw_supported_rates *rates; |
| 7283 | struct list_head *element; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7284 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7285 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7286 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 7287 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); |
| 7288 | return 0; |
| 7289 | } |
| 7290 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7291 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7292 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
| 7293 | "progress)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7294 | return 0; |
| 7295 | } |
| 7296 | |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 7297 | if (priv->status & STATUS_DISASSOCIATING) { |
| 7298 | IPW_DEBUG_ASSOC("Not attempting association (in " |
| 7299 | "disassociating)\n "); |
| 7300 | queue_work(priv->workqueue, &priv->associate); |
| 7301 | return 0; |
| 7302 | } |
| 7303 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7304 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7305 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
| 7306 | "initialized)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7307 | return 0; |
| 7308 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7309 | |
| 7310 | if (!(priv->config & CFG_ASSOCIATE) && |
| 7311 | !(priv->config & (CFG_STATIC_ESSID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7312 | CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7313 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7314 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7315 | } |
| 7316 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7317 | /* Protect our use of the network_list */ |
| 7318 | spin_lock_irqsave(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7319 | list_for_each_entry(network, &priv->ieee->network_list, list) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7320 | ipw_best_network(priv, &match, network, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7321 | |
| 7322 | network = match.network; |
| 7323 | rates = &match.rates; |
| 7324 | |
| 7325 | if (network == NULL && |
| 7326 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7327 | priv->config & CFG_ADHOC_CREATE && |
| 7328 | priv->config & CFG_STATIC_ESSID && |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7329 | priv->config & CFG_STATIC_CHANNEL && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7330 | !list_empty(&priv->ieee->network_free_list)) { |
| 7331 | element = priv->ieee->network_free_list.next; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7332 | network = list_entry(element, struct ieee80211_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7333 | ipw_adhoc_create(priv, network); |
| 7334 | rates = &priv->rates; |
| 7335 | list_del(element); |
| 7336 | list_add_tail(&network->list, &priv->ieee->network_list); |
| 7337 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7338 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7339 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7340 | /* If we reached the end of the list, then we don't have any valid |
| 7341 | * matching APs */ |
| 7342 | if (!network) { |
| 7343 | ipw_debug_config(priv); |
| 7344 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7345 | if (!(priv->status & STATUS_SCANNING)) { |
| 7346 | if (!(priv->config & CFG_SPEED_SCAN)) |
| 7347 | queue_delayed_work(priv->workqueue, |
| 7348 | &priv->request_scan, |
| 7349 | SCAN_INTERVAL); |
| 7350 | else |
| 7351 | queue_work(priv->workqueue, |
| 7352 | &priv->request_scan); |
| 7353 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7354 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7355 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7356 | } |
| 7357 | |
| 7358 | ipw_associate_network(priv, network, rates, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7359 | |
| 7360 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7361 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7362 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7363 | static void ipw_bg_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7364 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7365 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7366 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7367 | ipw_associate(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 7368 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7369 | } |
| 7370 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7371 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
| 7372 | struct sk_buff *skb) |
| 7373 | { |
| 7374 | struct ieee80211_hdr *hdr; |
| 7375 | u16 fc; |
| 7376 | |
| 7377 | hdr = (struct ieee80211_hdr *)skb->data; |
| 7378 | fc = le16_to_cpu(hdr->frame_ctl); |
| 7379 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 7380 | return; |
| 7381 | |
| 7382 | fc &= ~IEEE80211_FCTL_PROTECTED; |
| 7383 | hdr->frame_ctl = cpu_to_le16(fc); |
| 7384 | switch (priv->ieee->sec.level) { |
| 7385 | case SEC_LEVEL_3: |
| 7386 | /* Remove CCMP HDR */ |
| 7387 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7388 | skb->data + IEEE80211_3ADDR_LEN + 8, |
| 7389 | skb->len - IEEE80211_3ADDR_LEN - 8); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7390 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7391 | break; |
| 7392 | case SEC_LEVEL_2: |
| 7393 | break; |
| 7394 | case SEC_LEVEL_1: |
| 7395 | /* Remove IV */ |
| 7396 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7397 | skb->data + IEEE80211_3ADDR_LEN + 4, |
| 7398 | skb->len - IEEE80211_3ADDR_LEN - 4); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7399 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7400 | break; |
| 7401 | case SEC_LEVEL_0: |
| 7402 | break; |
| 7403 | default: |
| 7404 | printk(KERN_ERR "Unknow security level %d\n", |
| 7405 | priv->ieee->sec.level); |
| 7406 | break; |
| 7407 | } |
| 7408 | } |
| 7409 | |
| 7410 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
| 7411 | struct ipw_rx_mem_buffer *rxb, |
| 7412 | struct ieee80211_rx_stats *stats) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7413 | { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7414 | struct ieee80211_hdr_4addr *hdr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7415 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7416 | |
| 7417 | /* We received data from the HW, so stop the watchdog */ |
| 7418 | priv->net_dev->trans_start = jiffies; |
| 7419 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7420 | /* We only process data packets if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7421 | * interface is open */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7422 | 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] | 7423 | skb_tailroom(rxb->skb))) { |
| 7424 | priv->ieee->stats.rx_errors++; |
| 7425 | priv->wstats.discard.misc++; |
| 7426 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7427 | return; |
| 7428 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7429 | priv->ieee->stats.rx_dropped++; |
| 7430 | priv->wstats.discard.misc++; |
| 7431 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7432 | return; |
| 7433 | } |
| 7434 | |
| 7435 | /* Advance skb->data to the start of the actual payload */ |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 7436 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7437 | |
| 7438 | /* Set the size of the skb to the size of the frame */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7439 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7440 | |
| 7441 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7442 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7443 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7444 | hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data; |
| 7445 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7446 | (is_multicast_ether_addr(hdr->addr1) ? |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7447 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7448 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
| 7449 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7450 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7451 | priv->ieee->stats.rx_errors++; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7452 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7453 | rxb->skb = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7454 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7455 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7456 | } |
| 7457 | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7458 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 7459 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, |
| 7460 | struct ipw_rx_mem_buffer *rxb, |
| 7461 | struct ieee80211_rx_stats *stats) |
| 7462 | { |
| 7463 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7464 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7465 | |
| 7466 | /* initial pull of some data */ |
| 7467 | u16 received_channel = frame->received_channel; |
| 7468 | u8 antennaAndPhy = frame->antennaAndPhy; |
| 7469 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ |
| 7470 | u16 pktrate = frame->rate; |
| 7471 | |
| 7472 | /* Magic struct that slots into the radiotap header -- no reason |
| 7473 | * to build this manually element by element, we can write it much |
| 7474 | * more efficiently than we can parse it. ORDER MATTERS HERE */ |
| 7475 | struct ipw_rt_hdr { |
| 7476 | struct ieee80211_radiotap_header rt_hdr; |
| 7477 | u8 rt_flags; /* radiotap packet flags */ |
| 7478 | u8 rt_rate; /* rate in 500kb/s */ |
| 7479 | u16 rt_channel; /* channel in mhz */ |
| 7480 | u16 rt_chbitmask; /* channel bitfield */ |
| 7481 | s8 rt_dbmsignal; /* signal in dbM, kluged to signed */ |
| 7482 | u8 rt_antenna; /* antenna number */ |
| 7483 | } *ipw_rt; |
| 7484 | |
| 7485 | short len = le16_to_cpu(pkt->u.frame.length); |
| 7486 | |
| 7487 | /* We received data from the HW, so stop the watchdog */ |
| 7488 | priv->net_dev->trans_start = jiffies; |
| 7489 | |
| 7490 | /* We only process data packets if the |
| 7491 | * interface is open */ |
| 7492 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
| 7493 | skb_tailroom(rxb->skb))) { |
| 7494 | priv->ieee->stats.rx_errors++; |
| 7495 | priv->wstats.discard.misc++; |
| 7496 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7497 | return; |
| 7498 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7499 | priv->ieee->stats.rx_dropped++; |
| 7500 | priv->wstats.discard.misc++; |
| 7501 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7502 | return; |
| 7503 | } |
| 7504 | |
| 7505 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7506 | * that now */ |
| 7507 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7508 | /* FIXME: Should alloc bigger skb instead */ |
| 7509 | priv->ieee->stats.rx_dropped++; |
| 7510 | priv->wstats.discard.misc++; |
| 7511 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7512 | return; |
| 7513 | } |
| 7514 | |
| 7515 | /* copy the frame itself */ |
| 7516 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), |
| 7517 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); |
| 7518 | |
| 7519 | /* Zero the radiotap static buffer ... We only need to zero the bytes NOT |
| 7520 | * part of our real header, saves a little time. |
| 7521 | * |
| 7522 | * No longer necessary since we fill in all our data. Purge before merging |
| 7523 | * patch officially. |
| 7524 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, |
| 7525 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); |
| 7526 | */ |
| 7527 | |
| 7528 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; |
| 7529 | |
| 7530 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7531 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
| 7532 | ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */ |
| 7533 | |
| 7534 | /* Big bitfield of all the fields we provide in radiotap */ |
| 7535 | ipw_rt->rt_hdr.it_present = |
| 7536 | ((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 7537 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7538 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7539 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 7540 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7541 | |
| 7542 | /* Zero the flags, we'll add to them as we go */ |
| 7543 | ipw_rt->rt_flags = 0; |
| 7544 | |
| 7545 | /* Convert signal to DBM */ |
| 7546 | ipw_rt->rt_dbmsignal = antsignal; |
| 7547 | |
| 7548 | /* Convert the channel data and set the flags */ |
| 7549 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); |
| 7550 | if (received_channel > 14) { /* 802.11a */ |
| 7551 | ipw_rt->rt_chbitmask = |
| 7552 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7553 | } else if (antennaAndPhy & 32) { /* 802.11b */ |
| 7554 | ipw_rt->rt_chbitmask = |
| 7555 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7556 | } else { /* 802.11g */ |
| 7557 | ipw_rt->rt_chbitmask = |
| 7558 | (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
| 7559 | } |
| 7560 | |
| 7561 | /* set the rate in multiples of 500k/s */ |
| 7562 | switch (pktrate) { |
| 7563 | case IPW_TX_RATE_1MB: |
| 7564 | ipw_rt->rt_rate = 2; |
| 7565 | break; |
| 7566 | case IPW_TX_RATE_2MB: |
| 7567 | ipw_rt->rt_rate = 4; |
| 7568 | break; |
| 7569 | case IPW_TX_RATE_5MB: |
| 7570 | ipw_rt->rt_rate = 10; |
| 7571 | break; |
| 7572 | case IPW_TX_RATE_6MB: |
| 7573 | ipw_rt->rt_rate = 12; |
| 7574 | break; |
| 7575 | case IPW_TX_RATE_9MB: |
| 7576 | ipw_rt->rt_rate = 18; |
| 7577 | break; |
| 7578 | case IPW_TX_RATE_11MB: |
| 7579 | ipw_rt->rt_rate = 22; |
| 7580 | break; |
| 7581 | case IPW_TX_RATE_12MB: |
| 7582 | ipw_rt->rt_rate = 24; |
| 7583 | break; |
| 7584 | case IPW_TX_RATE_18MB: |
| 7585 | ipw_rt->rt_rate = 36; |
| 7586 | break; |
| 7587 | case IPW_TX_RATE_24MB: |
| 7588 | ipw_rt->rt_rate = 48; |
| 7589 | break; |
| 7590 | case IPW_TX_RATE_36MB: |
| 7591 | ipw_rt->rt_rate = 72; |
| 7592 | break; |
| 7593 | case IPW_TX_RATE_48MB: |
| 7594 | ipw_rt->rt_rate = 96; |
| 7595 | break; |
| 7596 | case IPW_TX_RATE_54MB: |
| 7597 | ipw_rt->rt_rate = 108; |
| 7598 | break; |
| 7599 | default: |
| 7600 | ipw_rt->rt_rate = 0; |
| 7601 | break; |
| 7602 | } |
| 7603 | |
| 7604 | /* antenna number */ |
| 7605 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ |
| 7606 | |
| 7607 | /* set the preamble flag if we have it */ |
| 7608 | if ((antennaAndPhy & 64)) |
| 7609 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7610 | |
| 7611 | /* Set the size of the skb to the size of the frame */ |
| 7612 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7613 | |
| 7614 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7615 | |
| 7616 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
| 7617 | priv->ieee->stats.rx_errors++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7618 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7619 | rxb->skb = NULL; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7620 | /* no LED during capture */ |
| 7621 | } |
| 7622 | } |
| 7623 | #endif |
| 7624 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 7625 | static int is_network_packet(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7626 | struct ieee80211_hdr_4addr *header) |
| 7627 | { |
| 7628 | /* Filter incoming packets to determine if they are targetted toward |
| 7629 | * this network, discarding packets coming from ourselves */ |
| 7630 | switch (priv->ieee->iw_mode) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7631 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7632 | /* packets from our adapter are dropped (echo) */ |
| 7633 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7634 | return 0; |
| 7635 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7636 | /* {broad,multi}cast packets to our BSSID go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7637 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7638 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7639 | |
| 7640 | /* packets to our adapter go through */ |
| 7641 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7642 | ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7643 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7644 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7645 | /* packets from our adapter are dropped (echo) */ |
| 7646 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7647 | return 0; |
| 7648 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7649 | /* {broad,multi}cast packets to our BSS go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7650 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7651 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
| 7652 | |
| 7653 | /* packets to our adapter go through */ |
| 7654 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7655 | ETH_ALEN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7656 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7657 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7658 | return 1; |
| 7659 | } |
| 7660 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7661 | #define IPW_PACKET_RETRY_TIME HZ |
| 7662 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 7663 | static int is_duplicate_packet(struct ipw_priv *priv, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7664 | struct ieee80211_hdr_4addr *header) |
| 7665 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7666 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 7667 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 7668 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 7669 | u16 *last_seq, *last_frag; |
| 7670 | unsigned long *last_time; |
| 7671 | |
| 7672 | switch (priv->ieee->iw_mode) { |
| 7673 | case IW_MODE_ADHOC: |
| 7674 | { |
| 7675 | struct list_head *p; |
| 7676 | struct ipw_ibss_seq *entry = NULL; |
| 7677 | u8 *mac = header->addr2; |
| 7678 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; |
| 7679 | |
| 7680 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 7681 | entry = |
| 7682 | list_entry(p, struct ipw_ibss_seq, list); |
| 7683 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 7684 | break; |
| 7685 | } |
| 7686 | if (p == &priv->ibss_mac_hash[index]) { |
| 7687 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 7688 | if (!entry) { |
| 7689 | IPW_ERROR |
| 7690 | ("Cannot malloc new mac entry\n"); |
| 7691 | return 0; |
| 7692 | } |
| 7693 | memcpy(entry->mac, mac, ETH_ALEN); |
| 7694 | entry->seq_num = seq; |
| 7695 | entry->frag_num = frag; |
| 7696 | entry->packet_time = jiffies; |
| 7697 | list_add(&entry->list, |
| 7698 | &priv->ibss_mac_hash[index]); |
| 7699 | return 0; |
| 7700 | } |
| 7701 | last_seq = &entry->seq_num; |
| 7702 | last_frag = &entry->frag_num; |
| 7703 | last_time = &entry->packet_time; |
| 7704 | break; |
| 7705 | } |
| 7706 | case IW_MODE_INFRA: |
| 7707 | last_seq = &priv->last_seq_num; |
| 7708 | last_frag = &priv->last_frag_num; |
| 7709 | last_time = &priv->last_packet_time; |
| 7710 | break; |
| 7711 | default: |
| 7712 | return 0; |
| 7713 | } |
| 7714 | if ((*last_seq == seq) && |
| 7715 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { |
| 7716 | if (*last_frag == frag) |
| 7717 | goto drop; |
| 7718 | if (*last_frag + 1 != frag) |
| 7719 | /* out-of-order fragment */ |
| 7720 | goto drop; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7721 | } else |
| 7722 | *last_seq = seq; |
| 7723 | |
Zhu Yi | f57ce7c | 2005-07-13 12:22:15 -0500 | [diff] [blame] | 7724 | *last_frag = frag; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7725 | *last_time = jiffies; |
| 7726 | return 0; |
| 7727 | |
| 7728 | drop: |
Zhu Yi | 87b016c | 2005-08-05 17:17:35 +0800 | [diff] [blame] | 7729 | /* Comment this line now since we observed the card receives |
| 7730 | * duplicate packets but the FCTL_RETRY bit is not set in the |
| 7731 | * IBSS mode with fragmentation enabled. |
| 7732 | BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7733 | return 1; |
| 7734 | } |
| 7735 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7736 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
| 7737 | struct ipw_rx_mem_buffer *rxb, |
| 7738 | struct ieee80211_rx_stats *stats) |
| 7739 | { |
| 7740 | struct sk_buff *skb = rxb->skb; |
| 7741 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; |
| 7742 | struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *) |
| 7743 | (skb->data + IPW_RX_FRAME_SIZE); |
| 7744 | |
| 7745 | ieee80211_rx_mgt(priv->ieee, header, stats); |
| 7746 | |
| 7747 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7748 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 7749 | IEEE80211_STYPE_PROBE_RESP) || |
| 7750 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 7751 | IEEE80211_STYPE_BEACON))) { |
| 7752 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) |
| 7753 | ipw_add_station(priv, header->addr2); |
| 7754 | } |
| 7755 | |
| 7756 | if (priv->config & CFG_NET_STATS) { |
| 7757 | IPW_DEBUG_HC("sending stat packet\n"); |
| 7758 | |
| 7759 | /* Set the size of the skb to the size of the full |
| 7760 | * ipw header and 802.11 frame */ |
| 7761 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + |
| 7762 | IPW_RX_FRAME_SIZE); |
| 7763 | |
| 7764 | /* Advance past the ipw packet header to the 802.11 frame */ |
| 7765 | skb_pull(skb, IPW_RX_FRAME_SIZE); |
| 7766 | |
| 7767 | /* Push the ieee80211_rx_stats before the 802.11 frame */ |
| 7768 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
| 7769 | |
| 7770 | skb->dev = priv->ieee->dev; |
| 7771 | |
| 7772 | /* Point raw at the ieee80211_stats */ |
| 7773 | skb->mac.raw = skb->data; |
| 7774 | |
| 7775 | skb->pkt_type = PACKET_OTHERHOST; |
| 7776 | skb->protocol = __constant_htons(ETH_P_80211_STATS); |
| 7777 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
| 7778 | netif_rx(skb); |
| 7779 | rxb->skb = NULL; |
| 7780 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7781 | } |
| 7782 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7783 | /* |
| 7784 | * Main entry function for recieving a packet with 80211 headers. This |
| 7785 | * should be called when ever the FW has notified us that there is a new |
| 7786 | * skb in the recieve queue. |
| 7787 | */ |
| 7788 | static void ipw_rx(struct ipw_priv *priv) |
| 7789 | { |
| 7790 | struct ipw_rx_mem_buffer *rxb; |
| 7791 | struct ipw_rx_packet *pkt; |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 7792 | struct ieee80211_hdr_4addr *header; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7793 | u32 r, w, i; |
| 7794 | u8 network_packet; |
| 7795 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7796 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
| 7797 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7798 | i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE; |
| 7799 | |
| 7800 | while (i != r) { |
| 7801 | rxb = priv->rxq->queue[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7802 | if (unlikely(rxb == NULL)) { |
| 7803 | printk(KERN_CRIT "Queue not allocated!\n"); |
| 7804 | break; |
| 7805 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7806 | priv->rxq->queue[i] = NULL; |
| 7807 | |
| 7808 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7809 | IPW_RX_BUF_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7810 | PCI_DMA_FROMDEVICE); |
| 7811 | |
| 7812 | pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7813 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", |
| 7814 | pkt->header.message_type, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7815 | pkt->header.rx_seq_num, pkt->header.control_bits); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7816 | |
| 7817 | switch (pkt->header.message_type) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7818 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
| 7819 | struct ieee80211_rx_stats stats = { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7820 | .rssi = |
| 7821 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7822 | IPW_RSSI_TO_DBM, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7823 | .signal = |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 7824 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
| 7825 | IPW_RSSI_TO_DBM + 0x100, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7826 | .noise = |
| 7827 | le16_to_cpu(pkt->u.frame.noise), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7828 | .rate = pkt->u.frame.rate, |
| 7829 | .mac_time = jiffies, |
| 7830 | .received_channel = |
| 7831 | pkt->u.frame.received_channel, |
| 7832 | .freq = |
| 7833 | (pkt->u.frame. |
| 7834 | control & (1 << 0)) ? |
| 7835 | IEEE80211_24GHZ_BAND : |
| 7836 | IEEE80211_52GHZ_BAND, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7837 | .len = le16_to_cpu(pkt->u.frame.length), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7838 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7839 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7840 | if (stats.rssi != 0) |
| 7841 | stats.mask |= IEEE80211_STATMASK_RSSI; |
| 7842 | if (stats.signal != 0) |
| 7843 | stats.mask |= IEEE80211_STATMASK_SIGNAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7844 | if (stats.noise != 0) |
| 7845 | stats.mask |= IEEE80211_STATMASK_NOISE; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7846 | if (stats.rate != 0) |
| 7847 | stats.mask |= IEEE80211_STATMASK_RATE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7848 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7849 | priv->rx_packets++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7850 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7851 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7852 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7853 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 7854 | ipw_handle_data_packet_monitor(priv, |
| 7855 | rxb, |
| 7856 | &stats); |
| 7857 | #else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7858 | ipw_handle_data_packet(priv, rxb, |
| 7859 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7860 | #endif |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7861 | break; |
| 7862 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7863 | #endif |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7864 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7865 | header = |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 7866 | (struct ieee80211_hdr_4addr *)(rxb->skb-> |
| 7867 | data + |
| 7868 | IPW_RX_FRAME_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7869 | /* TODO: Check Ad-Hoc dest/source and make sure |
| 7870 | * that we are actually parsing these packets |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7871 | * correctly -- we should probably use the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7872 | * frame control of the packet and disregard |
| 7873 | * the current iw_mode */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7874 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7875 | network_packet = |
| 7876 | is_network_packet(priv, header); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7877 | if (network_packet && priv->assoc_network) { |
| 7878 | priv->assoc_network->stats.rssi = |
| 7879 | stats.rssi; |
| 7880 | average_add(&priv->average_rssi, |
| 7881 | stats.rssi); |
| 7882 | priv->last_rx_rssi = stats.rssi; |
| 7883 | } |
| 7884 | |
| 7885 | IPW_DEBUG_RX("Frame: len=%u\n", |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7886 | le16_to_cpu(pkt->u.frame.length)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7887 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7888 | if (le16_to_cpu(pkt->u.frame.length) < |
Zhu Yi | 9d0be03 | 2006-02-15 06:18:19 +0800 | [diff] [blame] | 7889 | ieee80211_get_hdrlen(le16_to_cpu( |
| 7890 | header->frame_ctl))) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7891 | IPW_DEBUG_DROP |
| 7892 | ("Received packet is too small. " |
| 7893 | "Dropping.\n"); |
| 7894 | priv->ieee->stats.rx_errors++; |
| 7895 | priv->wstats.discard.misc++; |
| 7896 | break; |
| 7897 | } |
| 7898 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7899 | switch (WLAN_FC_GET_TYPE |
| 7900 | (le16_to_cpu(header->frame_ctl))) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7901 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7902 | case IEEE80211_FTYPE_MGMT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7903 | ipw_handle_mgmt_packet(priv, rxb, |
| 7904 | &stats); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7905 | break; |
| 7906 | |
| 7907 | case IEEE80211_FTYPE_CTL: |
| 7908 | break; |
| 7909 | |
| 7910 | case IEEE80211_FTYPE_DATA: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7911 | if (unlikely(!network_packet || |
| 7912 | is_duplicate_packet(priv, |
| 7913 | header))) |
| 7914 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7915 | IPW_DEBUG_DROP("Dropping: " |
| 7916 | MAC_FMT ", " |
| 7917 | MAC_FMT ", " |
| 7918 | MAC_FMT "\n", |
| 7919 | MAC_ARG(header-> |
| 7920 | addr1), |
| 7921 | MAC_ARG(header-> |
| 7922 | addr2), |
| 7923 | MAC_ARG(header-> |
| 7924 | addr3)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7925 | break; |
| 7926 | } |
| 7927 | |
| 7928 | ipw_handle_data_packet(priv, rxb, |
| 7929 | &stats); |
| 7930 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7931 | break; |
| 7932 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7933 | break; |
| 7934 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7935 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7936 | case RX_HOST_NOTIFICATION_TYPE:{ |
| 7937 | IPW_DEBUG_RX |
| 7938 | ("Notification: subtype=%02X flags=%02X size=%d\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7939 | pkt->u.notification.subtype, |
| 7940 | pkt->u.notification.flags, |
| 7941 | pkt->u.notification.size); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7942 | ipw_rx_notification(priv, &pkt->u.notification); |
| 7943 | break; |
| 7944 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7945 | |
| 7946 | default: |
| 7947 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", |
| 7948 | pkt->header.message_type); |
| 7949 | break; |
| 7950 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7951 | |
| 7952 | /* For now we just don't re-use anything. We can tweak this |
| 7953 | * later to try and re-use notification packets and SKBs that |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7954 | * fail to Rx correctly */ |
| 7955 | if (rxb->skb != NULL) { |
| 7956 | dev_kfree_skb_any(rxb->skb); |
| 7957 | rxb->skb = NULL; |
| 7958 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7959 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7960 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7961 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7962 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7963 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7964 | i = (i + 1) % RX_QUEUE_SIZE; |
| 7965 | } |
| 7966 | |
| 7967 | /* Backtrack one entry */ |
| 7968 | priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1; |
| 7969 | |
| 7970 | ipw_rx_queue_restock(priv); |
| 7971 | } |
| 7972 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7973 | #define DEFAULT_RTS_THRESHOLD 2304U |
| 7974 | #define MIN_RTS_THRESHOLD 1U |
| 7975 | #define MAX_RTS_THRESHOLD 2304U |
| 7976 | #define DEFAULT_BEACON_INTERVAL 100U |
| 7977 | #define DEFAULT_SHORT_RETRY_LIMIT 7U |
| 7978 | #define DEFAULT_LONG_RETRY_LIMIT 4U |
| 7979 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 7980 | /** |
| 7981 | * ipw_sw_reset |
| 7982 | * @option: options to control different reset behaviour |
| 7983 | * 0 = reset everything except the 'disable' module_param |
| 7984 | * 1 = reset everything and print out driver info (for probe only) |
| 7985 | * 2 = reset everything |
| 7986 | */ |
| 7987 | static int ipw_sw_reset(struct ipw_priv *priv, int option) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7988 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7989 | int band, modulation; |
| 7990 | int old_mode = priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7991 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7992 | /* Initialize module parameter values here */ |
| 7993 | priv->config = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7994 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7995 | /* We default to disabling the LED code as right now it causes |
| 7996 | * too many systems to lock up... */ |
| 7997 | if (!led) |
| 7998 | priv->config |= CFG_NO_LED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7999 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8000 | if (associate) |
| 8001 | priv->config |= CFG_ASSOCIATE; |
| 8002 | else |
| 8003 | IPW_DEBUG_INFO("Auto associate disabled.\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8004 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8005 | if (auto_create) |
| 8006 | priv->config |= CFG_ADHOC_CREATE; |
| 8007 | else |
| 8008 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); |
| 8009 | |
Zhu Yi | 17ed081 | 2006-01-24 16:36:31 +0800 | [diff] [blame] | 8010 | priv->config &= ~CFG_STATIC_ESSID; |
| 8011 | priv->essid_len = 0; |
| 8012 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 8013 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 8014 | if (disable && option) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8015 | priv->status |= STATUS_RF_KILL_SW; |
| 8016 | IPW_DEBUG_INFO("Radio disabled.\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8017 | } |
| 8018 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8019 | if (channel != 0) { |
| 8020 | priv->config |= CFG_STATIC_CHANNEL; |
| 8021 | priv->channel = channel; |
| 8022 | IPW_DEBUG_INFO("Bind to static channel %d\n", channel); |
| 8023 | /* TODO: Validate that provided channel is in range */ |
| 8024 | } |
| 8025 | #ifdef CONFIG_IPW_QOS |
| 8026 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
| 8027 | burst_duration_CCK, burst_duration_OFDM); |
| 8028 | #endif /* CONFIG_IPW_QOS */ |
| 8029 | |
| 8030 | switch (mode) { |
| 8031 | case 1: |
| 8032 | priv->ieee->iw_mode = IW_MODE_ADHOC; |
| 8033 | priv->net_dev->type = ARPHRD_ETHER; |
| 8034 | |
| 8035 | break; |
| 8036 | #ifdef CONFIG_IPW2200_MONITOR |
| 8037 | case 2: |
| 8038 | priv->ieee->iw_mode = IW_MODE_MONITOR; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8039 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 8040 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8041 | #else |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8042 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8043 | #endif |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8044 | break; |
| 8045 | #endif |
| 8046 | default: |
| 8047 | case 0: |
| 8048 | priv->net_dev->type = ARPHRD_ETHER; |
| 8049 | priv->ieee->iw_mode = IW_MODE_INFRA; |
| 8050 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8051 | } |
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 | if (hwcrypto) { |
| 8054 | priv->ieee->host_encrypt = 0; |
| 8055 | priv->ieee->host_encrypt_msdu = 0; |
| 8056 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 8057 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8058 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8059 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8060 | |
Zhu Yi | e402c93 | 2005-08-05 17:20:40 +0800 | [diff] [blame] | 8061 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
| 8062 | priv->ieee->host_open_frag = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8063 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8064 | if ((priv->pci_dev->device == 0x4223) || |
| 8065 | (priv->pci_dev->device == 0x4224)) { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8066 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8067 | printk(KERN_INFO DRV_NAME |
| 8068 | ": Detected Intel PRO/Wireless 2915ABG Network " |
| 8069 | "Connection\n"); |
| 8070 | priv->ieee->abg_true = 1; |
| 8071 | band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; |
| 8072 | modulation = IEEE80211_OFDM_MODULATION | |
| 8073 | IEEE80211_CCK_MODULATION; |
| 8074 | priv->adapter = IPW_2915ABG; |
| 8075 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8076 | } else { |
Zhu Yi | e8c69e2 | 2006-02-17 08:25:12 +0800 | [diff] [blame] | 8077 | if (option == 1) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8078 | printk(KERN_INFO DRV_NAME |
| 8079 | ": Detected Intel PRO/Wireless 2200BG Network " |
| 8080 | "Connection\n"); |
| 8081 | |
| 8082 | priv->ieee->abg_true = 0; |
| 8083 | band = IEEE80211_24GHZ_BAND; |
| 8084 | modulation = IEEE80211_OFDM_MODULATION | |
| 8085 | IEEE80211_CCK_MODULATION; |
| 8086 | priv->adapter = IPW_2200BG; |
| 8087 | priv->ieee->mode = IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8088 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8089 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8090 | priv->ieee->freq_band = band; |
| 8091 | priv->ieee->modulation = modulation; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8092 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8093 | priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8094 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8095 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8096 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8097 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8098 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8099 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; |
| 8100 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8101 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8102 | /* If power management is turned on, default to AC mode */ |
| 8103 | priv->power_mode = IPW_POWER_AC; |
| 8104 | priv->tx_power = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8105 | |
Zhu Yi | 0ece35b | 2005-08-05 17:26:51 +0800 | [diff] [blame] | 8106 | return old_mode == priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8107 | } |
| 8108 | |
| 8109 | /* |
| 8110 | * This file defines the Wireless Extension handlers. It does not |
| 8111 | * define any methods of hardware manipulation and relies on the |
| 8112 | * functions defined in ipw_main to provide the HW interaction. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8113 | * |
| 8114 | * The exception to this is the use of the ipw_get_ordinal() |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8115 | * function used to poll the hardware vs. making unecessary calls. |
| 8116 | * |
| 8117 | */ |
| 8118 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8119 | static int ipw_wx_get_name(struct net_device *dev, |
| 8120 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8121 | union iwreq_data *wrqu, char *extra) |
| 8122 | { |
| 8123 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8124 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8125 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8126 | strcpy(wrqu->name, "radio off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8127 | else if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8128 | strcpy(wrqu->name, "unassociated"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8129 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8130 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c", |
| 8131 | ipw_modes[priv->assoc_request.ieee_mode]); |
| 8132 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8133 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8134 | return 0; |
| 8135 | } |
| 8136 | |
| 8137 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
| 8138 | { |
| 8139 | if (channel == 0) { |
| 8140 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); |
| 8141 | priv->config &= ~CFG_STATIC_CHANNEL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8142 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8143 | "parameters.\n"); |
| 8144 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8145 | return 0; |
| 8146 | } |
| 8147 | |
| 8148 | priv->config |= CFG_STATIC_CHANNEL; |
| 8149 | |
| 8150 | if (priv->channel == channel) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8151 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
| 8152 | channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8153 | return 0; |
| 8154 | } |
| 8155 | |
| 8156 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); |
| 8157 | priv->channel = channel; |
| 8158 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8159 | #ifdef CONFIG_IPW2200_MONITOR |
| 8160 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8161 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8162 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8163 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8164 | "channel change.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8165 | ipw_abort_scan(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8166 | } |
| 8167 | |
| 8168 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) |
| 8169 | udelay(10); |
| 8170 | |
| 8171 | if (priv->status & STATUS_SCANNING) |
| 8172 | IPW_DEBUG_SCAN("Still scanning...\n"); |
| 8173 | else |
| 8174 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", |
| 8175 | 1000 - i); |
| 8176 | |
| 8177 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8178 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8179 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 8180 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8181 | /* Network configuration changed -- force [re]association */ |
| 8182 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); |
| 8183 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8184 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8185 | |
| 8186 | return 0; |
| 8187 | } |
| 8188 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8189 | static int ipw_wx_set_freq(struct net_device *dev, |
| 8190 | struct iw_request_info *info, |
| 8191 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8192 | { |
| 8193 | struct ipw_priv *priv = ieee80211_priv(dev); |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8194 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8195 | struct iw_freq *fwrq = &wrqu->freq; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8196 | int ret = 0, i; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8197 | u8 channel, flags; |
| 8198 | int band; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8199 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8200 | if (fwrq->m == 0) { |
| 8201 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8202 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8203 | ret = ipw_set_channel(priv, 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8204 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8205 | return ret; |
| 8206 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8207 | /* if setting by freq convert to channel */ |
| 8208 | if (fwrq->e == 1) { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8209 | channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8210 | if (channel == 0) |
| 8211 | return -EINVAL; |
| 8212 | } else |
| 8213 | channel = fwrq->m; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8214 | |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8215 | if (!(band = ieee80211_is_valid_channel(priv->ieee, channel))) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8216 | return -EINVAL; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8217 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8218 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8219 | i = ieee80211_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8220 | if (i == -1) |
| 8221 | return -EINVAL; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8222 | |
| 8223 | flags = (band == IEEE80211_24GHZ_BAND) ? |
| 8224 | geo->bg[i].flags : geo->a[i].flags; |
| 8225 | if (flags & IEEE80211_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8226 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
| 8227 | return -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8228 | } |
| 8229 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8230 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8231 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8232 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8233 | ret = ipw_set_channel(priv, channel); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8234 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8235 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8236 | } |
| 8237 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8238 | static int ipw_wx_get_freq(struct net_device *dev, |
| 8239 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8240 | union iwreq_data *wrqu, char *extra) |
| 8241 | { |
| 8242 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8243 | |
| 8244 | wrqu->freq.e = 0; |
| 8245 | |
| 8246 | /* If we are associated, trying to associate, or have a statically |
| 8247 | * configured CHANNEL then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8248 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8249 | if (priv->config & CFG_STATIC_CHANNEL || |
| 8250 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) |
| 8251 | wrqu->freq.m = priv->channel; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8252 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8253 | wrqu->freq.m = 0; |
| 8254 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8255 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8256 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
| 8257 | return 0; |
| 8258 | } |
| 8259 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8260 | static int ipw_wx_set_mode(struct net_device *dev, |
| 8261 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8262 | union iwreq_data *wrqu, char *extra) |
| 8263 | { |
| 8264 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8265 | int err = 0; |
| 8266 | |
| 8267 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); |
| 8268 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8269 | switch (wrqu->mode) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8270 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8271 | case IW_MODE_MONITOR: |
| 8272 | #endif |
| 8273 | case IW_MODE_ADHOC: |
| 8274 | case IW_MODE_INFRA: |
| 8275 | break; |
| 8276 | case IW_MODE_AUTO: |
| 8277 | wrqu->mode = IW_MODE_INFRA; |
| 8278 | break; |
| 8279 | default: |
| 8280 | return -EINVAL; |
| 8281 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8282 | if (wrqu->mode == priv->ieee->iw_mode) |
| 8283 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8284 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8285 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8286 | |
| 8287 | ipw_sw_reset(priv, 0); |
| 8288 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8289 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8290 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8291 | priv->net_dev->type = ARPHRD_ETHER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8292 | |
| 8293 | if (wrqu->mode == IW_MODE_MONITOR) |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8294 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 8295 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8296 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8297 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8298 | #endif |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8299 | #endif /* CONFIG_IPW2200_MONITOR */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8300 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8301 | /* Free the existing firmware and reset the fw_loaded |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8302 | * flag so ipw_load() will bring in the new firmawre */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8303 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8304 | |
| 8305 | priv->ieee->iw_mode = wrqu->mode; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8306 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8307 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8308 | mutex_unlock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8309 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8310 | } |
| 8311 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8312 | static int ipw_wx_get_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8313 | struct iw_request_info *info, |
| 8314 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8315 | { |
| 8316 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8317 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8318 | wrqu->mode = priv->ieee->iw_mode; |
| 8319 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8320 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8321 | return 0; |
| 8322 | } |
| 8323 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8324 | /* Values are in microsecond */ |
| 8325 | static const s32 timeout_duration[] = { |
| 8326 | 350000, |
| 8327 | 250000, |
| 8328 | 75000, |
| 8329 | 37000, |
| 8330 | 25000, |
| 8331 | }; |
| 8332 | |
| 8333 | static const s32 period_duration[] = { |
| 8334 | 400000, |
| 8335 | 700000, |
| 8336 | 1000000, |
| 8337 | 1000000, |
| 8338 | 1000000 |
| 8339 | }; |
| 8340 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8341 | static int ipw_wx_get_range(struct net_device *dev, |
| 8342 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8343 | union iwreq_data *wrqu, char *extra) |
| 8344 | { |
| 8345 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8346 | struct iw_range *range = (struct iw_range *)extra; |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 8347 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8348 | int i = 0, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8349 | |
| 8350 | wrqu->data.length = sizeof(*range); |
| 8351 | memset(range, 0, sizeof(*range)); |
| 8352 | |
| 8353 | /* 54Mbs == ~27 Mb/s real (802.11g) */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8354 | range->throughput = 27 * 1000 * 1000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8355 | |
| 8356 | range->max_qual.qual = 100; |
| 8357 | /* TODO: Find real max RSSI and stick here */ |
| 8358 | range->max_qual.level = 0; |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 8359 | range->max_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8360 | range->max_qual.updated = 7; /* Updated all three */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8361 | |
| 8362 | range->avg_qual.qual = 70; |
| 8363 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8364 | range->avg_qual.level = 0; /* FIXME to real average level */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8365 | range->avg_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8366 | range->avg_qual.updated = 7; /* Updated all three */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8367 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8368 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8369 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8370 | for (i = 0; i < range->num_bitrates; i++) |
| 8371 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8372 | 500000; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8373 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8374 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
| 8375 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 8376 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 8377 | |
| 8378 | range->encoding_size[0] = 5; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8379 | range->encoding_size[1] = 13; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8380 | range->num_encoding_sizes = 2; |
| 8381 | range->max_encoding_tokens = WEP_KEYS; |
| 8382 | |
| 8383 | /* Set the Wireless Extension versions */ |
| 8384 | range->we_version_compiled = WIRELESS_EXT; |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8385 | range->we_version_source = 18; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8386 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8387 | i = 0; |
| 8388 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8389 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8390 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
| 8391 | (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY)) |
| 8392 | continue; |
| 8393 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8394 | range->freq[i].i = geo->bg[j].channel; |
| 8395 | range->freq[i].m = geo->bg[j].freq * 100000; |
| 8396 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8397 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8398 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8399 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8400 | |
| 8401 | if (priv->ieee->mode & IEEE_A) { |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8402 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { |
| 8403 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
| 8404 | (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY)) |
| 8405 | continue; |
| 8406 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8407 | range->freq[i].i = geo->a[j].channel; |
| 8408 | range->freq[i].m = geo->a[j].freq * 100000; |
| 8409 | range->freq[i].e = 1; |
Zhu Yi | e815de4 | 2006-03-02 05:55:51 +0800 | [diff] [blame] | 8410 | i++; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8411 | } |
| 8412 | } |
| 8413 | |
| 8414 | range->num_channels = i; |
| 8415 | range->num_frequency = i; |
| 8416 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8417 | mutex_unlock(&priv->mutex); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8418 | |
| 8419 | /* Event capability (kernel + driver) */ |
| 8420 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 8421 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
| 8422 | IW_EVENT_CAPA_MASK(SIOCGIWAP)); |
| 8423 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8424 | |
Dan Williams | f1b5086 | 2006-01-30 13:58:56 -0500 | [diff] [blame] | 8425 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 8426 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 8427 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8428 | IPW_DEBUG_WX("GET Range\n"); |
| 8429 | return 0; |
| 8430 | } |
| 8431 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8432 | static int ipw_wx_set_wap(struct net_device *dev, |
| 8433 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8434 | union iwreq_data *wrqu, char *extra) |
| 8435 | { |
| 8436 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8437 | |
| 8438 | static const unsigned char any[] = { |
| 8439 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 8440 | }; |
| 8441 | static const unsigned char off[] = { |
| 8442 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 8443 | }; |
| 8444 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8445 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8446 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8447 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8448 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
| 8449 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8450 | /* we disable mandatory BSSID association */ |
| 8451 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); |
| 8452 | priv->config &= ~CFG_STATIC_BSSID; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8453 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8454 | "parameters.\n"); |
| 8455 | ipw_associate(priv); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8456 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8457 | return 0; |
| 8458 | } |
| 8459 | |
| 8460 | priv->config |= CFG_STATIC_BSSID; |
| 8461 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8462 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8463 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8464 | return 0; |
| 8465 | } |
| 8466 | |
| 8467 | IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n", |
| 8468 | MAC_ARG(wrqu->ap_addr.sa_data)); |
| 8469 | |
| 8470 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); |
| 8471 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8472 | /* Network configuration changed -- force [re]association */ |
| 8473 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); |
| 8474 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8475 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8476 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8477 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8478 | return 0; |
| 8479 | } |
| 8480 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8481 | static int ipw_wx_get_wap(struct net_device *dev, |
| 8482 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8483 | union iwreq_data *wrqu, char *extra) |
| 8484 | { |
| 8485 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8486 | /* If we are associated, trying to associate, or have a statically |
| 8487 | * configured BSSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8488 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8489 | if (priv->config & CFG_STATIC_BSSID || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8490 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8491 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8492 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8493 | } else |
| 8494 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 8495 | |
| 8496 | IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", |
| 8497 | MAC_ARG(wrqu->ap_addr.sa_data)); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8498 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8499 | return 0; |
| 8500 | } |
| 8501 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8502 | static int ipw_wx_set_essid(struct net_device *dev, |
| 8503 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8504 | union iwreq_data *wrqu, char *extra) |
| 8505 | { |
| 8506 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8507 | char *essid = ""; /* ANY */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8508 | int length = 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8509 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8510 | if (wrqu->essid.flags && wrqu->essid.length) { |
| 8511 | length = wrqu->essid.length - 1; |
| 8512 | essid = extra; |
| 8513 | } |
| 8514 | if (length == 0) { |
| 8515 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8516 | if ((priv->config & CFG_STATIC_ESSID) && |
| 8517 | !(priv->status & (STATUS_ASSOCIATED | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8518 | STATUS_ASSOCIATING))) { |
| 8519 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8520 | "parameters.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8521 | priv->config &= ~CFG_STATIC_ESSID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8522 | ipw_associate(priv); |
| 8523 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8524 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8525 | return 0; |
| 8526 | } |
| 8527 | |
| 8528 | length = min(length, IW_ESSID_MAX_SIZE); |
| 8529 | |
| 8530 | priv->config |= CFG_STATIC_ESSID; |
| 8531 | |
| 8532 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { |
| 8533 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
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 | |
| 8538 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length), |
| 8539 | length); |
| 8540 | |
| 8541 | priv->essid_len = length; |
| 8542 | memcpy(priv->essid, essid, priv->essid_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8543 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8544 | /* Network configuration changed -- force [re]association */ |
| 8545 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); |
| 8546 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8547 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8548 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8549 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8550 | return 0; |
| 8551 | } |
| 8552 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8553 | static int ipw_wx_get_essid(struct net_device *dev, |
| 8554 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8555 | union iwreq_data *wrqu, char *extra) |
| 8556 | { |
| 8557 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8558 | |
| 8559 | /* If we are associated, trying to associate, or have a statically |
| 8560 | * configured ESSID then return that; otherwise return ANY */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8561 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8562 | if (priv->config & CFG_STATIC_ESSID || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8563 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8564 | IPW_DEBUG_WX("Getting essid: '%s'\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8565 | escape_essid(priv->essid, priv->essid_len)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8566 | memcpy(extra, priv->essid, priv->essid_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8567 | wrqu->essid.length = priv->essid_len; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8568 | wrqu->essid.flags = 1; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8569 | } else { |
| 8570 | IPW_DEBUG_WX("Getting essid: ANY\n"); |
| 8571 | wrqu->essid.length = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8572 | wrqu->essid.flags = 0; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8573 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8574 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8575 | return 0; |
| 8576 | } |
| 8577 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8578 | static int ipw_wx_set_nick(struct net_device *dev, |
| 8579 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8580 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8581 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8582 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8583 | |
| 8584 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); |
| 8585 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) |
| 8586 | return -E2BIG; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8587 | mutex_lock(&priv->mutex); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8588 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8589 | memset(priv->nick, 0, sizeof(priv->nick)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8590 | memcpy(priv->nick, extra, wrqu->data.length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8591 | IPW_DEBUG_TRACE("<<\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8592 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8593 | return 0; |
| 8594 | |
| 8595 | } |
| 8596 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8597 | static int ipw_wx_get_nick(struct net_device *dev, |
| 8598 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8599 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8600 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8601 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8602 | IPW_DEBUG_WX("Getting nick\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8603 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8604 | wrqu->data.length = strlen(priv->nick) + 1; |
| 8605 | memcpy(extra, priv->nick, wrqu->data.length); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8606 | wrqu->data.flags = 1; /* active */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8607 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8608 | return 0; |
| 8609 | } |
| 8610 | |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame^] | 8611 | static int ipw_wx_set_sens(struct net_device *dev, |
| 8612 | struct iw_request_info *info, |
| 8613 | union iwreq_data *wrqu, char *extra) |
| 8614 | { |
| 8615 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8616 | int err = 0; |
| 8617 | |
| 8618 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); |
| 8619 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); |
| 8620 | mutex_lock(&priv->mutex); |
| 8621 | |
| 8622 | if (wrqu->sens.fixed == 0) |
| 8623 | { |
| 8624 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
| 8625 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8626 | goto out; |
| 8627 | } |
| 8628 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || |
| 8629 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { |
| 8630 | err = -EINVAL; |
| 8631 | goto out; |
| 8632 | } |
| 8633 | |
| 8634 | priv->roaming_threshold = wrqu->sens.value; |
| 8635 | priv->disassociate_threshold = 3*wrqu->sens.value; |
| 8636 | out: |
| 8637 | mutex_unlock(&priv->mutex); |
| 8638 | return err; |
| 8639 | } |
| 8640 | |
| 8641 | static int ipw_wx_get_sens(struct net_device *dev, |
| 8642 | struct iw_request_info *info, |
| 8643 | union iwreq_data *wrqu, char *extra) |
| 8644 | { |
| 8645 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8646 | mutex_lock(&priv->mutex); |
| 8647 | wrqu->sens.fixed = 1; |
| 8648 | wrqu->sens.value = priv->roaming_threshold; |
| 8649 | mutex_unlock(&priv->mutex); |
| 8650 | |
| 8651 | IPW_DEBUG_WX("GET roaming threshold -> %s %d \n", |
| 8652 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
| 8653 | |
| 8654 | return 0; |
| 8655 | } |
| 8656 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8657 | static int ipw_wx_set_rate(struct net_device *dev, |
| 8658 | struct iw_request_info *info, |
| 8659 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8660 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8661 | /* TODO: We should use semaphores or locks for access to priv */ |
| 8662 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8663 | u32 target_rate = wrqu->bitrate.value; |
| 8664 | u32 fixed, mask; |
| 8665 | |
| 8666 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ |
| 8667 | /* value = X, fixed = 1 means only rate X */ |
| 8668 | /* value = X, fixed = 0 means all rates lower equal X */ |
| 8669 | |
| 8670 | if (target_rate == -1) { |
| 8671 | fixed = 0; |
| 8672 | mask = IEEE80211_DEFAULT_RATES_MASK; |
| 8673 | /* Now we should reassociate */ |
| 8674 | goto apply; |
| 8675 | } |
| 8676 | |
| 8677 | mask = 0; |
| 8678 | fixed = wrqu->bitrate.fixed; |
| 8679 | |
| 8680 | if (target_rate == 1000000 || !fixed) |
| 8681 | mask |= IEEE80211_CCK_RATE_1MB_MASK; |
| 8682 | if (target_rate == 1000000) |
| 8683 | goto apply; |
| 8684 | |
| 8685 | if (target_rate == 2000000 || !fixed) |
| 8686 | mask |= IEEE80211_CCK_RATE_2MB_MASK; |
| 8687 | if (target_rate == 2000000) |
| 8688 | goto apply; |
| 8689 | |
| 8690 | if (target_rate == 5500000 || !fixed) |
| 8691 | mask |= IEEE80211_CCK_RATE_5MB_MASK; |
| 8692 | if (target_rate == 5500000) |
| 8693 | goto apply; |
| 8694 | |
| 8695 | if (target_rate == 6000000 || !fixed) |
| 8696 | mask |= IEEE80211_OFDM_RATE_6MB_MASK; |
| 8697 | if (target_rate == 6000000) |
| 8698 | goto apply; |
| 8699 | |
| 8700 | if (target_rate == 9000000 || !fixed) |
| 8701 | mask |= IEEE80211_OFDM_RATE_9MB_MASK; |
| 8702 | if (target_rate == 9000000) |
| 8703 | goto apply; |
| 8704 | |
| 8705 | if (target_rate == 11000000 || !fixed) |
| 8706 | mask |= IEEE80211_CCK_RATE_11MB_MASK; |
| 8707 | if (target_rate == 11000000) |
| 8708 | goto apply; |
| 8709 | |
| 8710 | if (target_rate == 12000000 || !fixed) |
| 8711 | mask |= IEEE80211_OFDM_RATE_12MB_MASK; |
| 8712 | if (target_rate == 12000000) |
| 8713 | goto apply; |
| 8714 | |
| 8715 | if (target_rate == 18000000 || !fixed) |
| 8716 | mask |= IEEE80211_OFDM_RATE_18MB_MASK; |
| 8717 | if (target_rate == 18000000) |
| 8718 | goto apply; |
| 8719 | |
| 8720 | if (target_rate == 24000000 || !fixed) |
| 8721 | mask |= IEEE80211_OFDM_RATE_24MB_MASK; |
| 8722 | if (target_rate == 24000000) |
| 8723 | goto apply; |
| 8724 | |
| 8725 | if (target_rate == 36000000 || !fixed) |
| 8726 | mask |= IEEE80211_OFDM_RATE_36MB_MASK; |
| 8727 | if (target_rate == 36000000) |
| 8728 | goto apply; |
| 8729 | |
| 8730 | if (target_rate == 48000000 || !fixed) |
| 8731 | mask |= IEEE80211_OFDM_RATE_48MB_MASK; |
| 8732 | if (target_rate == 48000000) |
| 8733 | goto apply; |
| 8734 | |
| 8735 | if (target_rate == 54000000 || !fixed) |
| 8736 | mask |= IEEE80211_OFDM_RATE_54MB_MASK; |
| 8737 | if (target_rate == 54000000) |
| 8738 | goto apply; |
| 8739 | |
| 8740 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); |
| 8741 | return -EINVAL; |
| 8742 | |
| 8743 | apply: |
| 8744 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", |
| 8745 | mask, fixed ? "fixed" : "sub-rates"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8746 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8747 | if (mask == IEEE80211_DEFAULT_RATES_MASK) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8748 | priv->config &= ~CFG_FIXED_RATE; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8749 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
| 8750 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8751 | priv->config |= CFG_FIXED_RATE; |
| 8752 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8753 | if (priv->rates_mask == mask) { |
| 8754 | IPW_DEBUG_WX("Mask set to current mask.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8755 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8756 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8757 | } |
| 8758 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8759 | priv->rates_mask = mask; |
| 8760 | |
| 8761 | /* Network configuration changed -- force [re]association */ |
| 8762 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); |
| 8763 | if (!ipw_disassociate(priv)) |
| 8764 | ipw_associate(priv); |
| 8765 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8766 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8767 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8768 | } |
| 8769 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8770 | static int ipw_wx_get_rate(struct net_device *dev, |
| 8771 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8772 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8773 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8774 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8775 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8776 | wrqu->bitrate.value = priv->last_rate; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8777 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8778 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
| 8779 | return 0; |
| 8780 | } |
| 8781 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8782 | static int ipw_wx_set_rts(struct net_device *dev, |
| 8783 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8784 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8785 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8786 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8787 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8788 | if (wrqu->rts.disabled) |
| 8789 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8790 | else { |
| 8791 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8792 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8793 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8794 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8795 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8796 | priv->rts_threshold = wrqu->rts.value; |
| 8797 | } |
| 8798 | |
| 8799 | ipw_send_rts_threshold(priv, priv->rts_threshold); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8800 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8801 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
| 8802 | return 0; |
| 8803 | } |
| 8804 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8805 | static int ipw_wx_get_rts(struct net_device *dev, |
| 8806 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8807 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8808 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8809 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8810 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8811 | wrqu->rts.value = priv->rts_threshold; |
| 8812 | wrqu->rts.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8813 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8814 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8815 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
| 8816 | return 0; |
| 8817 | } |
| 8818 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8819 | static int ipw_wx_set_txpow(struct net_device *dev, |
| 8820 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8821 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8822 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8823 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8824 | int err = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8825 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8826 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8827 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8828 | err = -EINPROGRESS; |
| 8829 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8830 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8831 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8832 | if (!wrqu->power.fixed) |
| 8833 | wrqu->power.value = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8834 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8835 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8836 | err = -EINVAL; |
| 8837 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8838 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8839 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8840 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8841 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8842 | err = -EINVAL; |
| 8843 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8844 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8845 | |
| 8846 | priv->tx_power = wrqu->power.value; |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8847 | err = ipw_set_tx_power(priv); |
| 8848 | out: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8849 | mutex_unlock(&priv->mutex); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8850 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8851 | } |
| 8852 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8853 | static int ipw_wx_get_txpow(struct net_device *dev, |
| 8854 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8855 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8856 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8857 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8858 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8859 | wrqu->power.value = priv->tx_power; |
| 8860 | wrqu->power.fixed = 1; |
| 8861 | wrqu->power.flags = IW_TXPOW_DBM; |
| 8862 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8863 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8864 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8865 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
Zhu Yi | 22501c8 | 2005-08-11 10:49:17 +0800 | [diff] [blame] | 8866 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8867 | |
| 8868 | return 0; |
| 8869 | } |
| 8870 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8871 | static int ipw_wx_set_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8872 | struct iw_request_info *info, |
| 8873 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8874 | { |
| 8875 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8876 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8877 | if (wrqu->frag.disabled) |
| 8878 | priv->ieee->fts = DEFAULT_FTS; |
| 8879 | else { |
| 8880 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8881 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8882 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8883 | return -EINVAL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8884 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8885 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8886 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
| 8887 | } |
| 8888 | |
| 8889 | ipw_send_frag_threshold(priv, wrqu->frag.value); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8890 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8891 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
| 8892 | return 0; |
| 8893 | } |
| 8894 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8895 | static int ipw_wx_get_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8896 | struct iw_request_info *info, |
| 8897 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8898 | { |
| 8899 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8900 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8901 | wrqu->frag.value = priv->ieee->fts; |
| 8902 | wrqu->frag.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8903 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8904 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8905 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
| 8906 | |
| 8907 | return 0; |
| 8908 | } |
| 8909 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8910 | static int ipw_wx_set_retry(struct net_device *dev, |
| 8911 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8912 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8913 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8914 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8915 | |
| 8916 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) |
| 8917 | return -EINVAL; |
| 8918 | |
| 8919 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) |
| 8920 | return 0; |
| 8921 | |
| 8922 | if (wrqu->retry.value < 0 || wrqu->retry.value > 255) |
| 8923 | return -EINVAL; |
| 8924 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8925 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8926 | if (wrqu->retry.flags & IW_RETRY_MIN) |
| 8927 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 8928 | else if (wrqu->retry.flags & IW_RETRY_MAX) |
| 8929 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 8930 | else { |
| 8931 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 8932 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 8933 | } |
| 8934 | |
| 8935 | ipw_send_retry_limit(priv, priv->short_retry_limit, |
| 8936 | priv->long_retry_limit); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8937 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8938 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
| 8939 | priv->short_retry_limit, priv->long_retry_limit); |
| 8940 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8941 | } |
| 8942 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8943 | static int ipw_wx_get_retry(struct net_device *dev, |
| 8944 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8945 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8946 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8947 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8948 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8949 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8950 | wrqu->retry.disabled = 0; |
| 8951 | |
| 8952 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8953 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8954 | return -EINVAL; |
| 8955 | } |
| 8956 | |
| 8957 | if (wrqu->retry.flags & IW_RETRY_MAX) { |
| 8958 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 8959 | wrqu->retry.value = priv->long_retry_limit; |
| 8960 | } else if (wrqu->retry.flags & IW_RETRY_MIN) { |
| 8961 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; |
| 8962 | wrqu->retry.value = priv->short_retry_limit; |
| 8963 | } else { |
| 8964 | wrqu->retry.flags = IW_RETRY_LIMIT; |
| 8965 | wrqu->retry.value = priv->short_retry_limit; |
| 8966 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8967 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8968 | |
| 8969 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); |
| 8970 | |
| 8971 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8972 | } |
| 8973 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8974 | static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid, |
| 8975 | int essid_len) |
| 8976 | { |
| 8977 | struct ipw_scan_request_ext scan; |
| 8978 | int err = 0, scan_type; |
| 8979 | |
Pekka Enberg | efb3442 | 2005-11-16 21:55:05 +0200 | [diff] [blame] | 8980 | if (!(priv->status & STATUS_INIT) || |
| 8981 | (priv->status & STATUS_EXIT_PENDING)) |
| 8982 | return 0; |
| 8983 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 8984 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8985 | |
| 8986 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 8987 | IPW_DEBUG_HC("Aborting scan due to RF kill activation\n"); |
| 8988 | priv->status |= STATUS_SCAN_PENDING; |
| 8989 | goto done; |
| 8990 | } |
| 8991 | |
| 8992 | IPW_DEBUG_HC("starting request direct scan!\n"); |
| 8993 | |
| 8994 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
Olaf Kirch | d834a41 | 2006-01-09 17:00:37 +0100 | [diff] [blame] | 8995 | /* We should not sleep here; otherwise we will block most |
| 8996 | * of the system (for instance, we hold rtnl_lock when we |
| 8997 | * get here). |
| 8998 | */ |
| 8999 | err = -EAGAIN; |
| 9000 | goto done; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9001 | } |
| 9002 | memset(&scan, 0, sizeof(scan)); |
| 9003 | |
| 9004 | if (priv->config & CFG_SPEED_SCAN) |
| 9005 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 9006 | cpu_to_le16(30); |
| 9007 | else |
| 9008 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 9009 | cpu_to_le16(20); |
| 9010 | |
| 9011 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 9012 | cpu_to_le16(20); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 9013 | 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] | 9014 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
| 9015 | |
| 9016 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
| 9017 | |
| 9018 | err = ipw_send_ssid(priv, essid, essid_len); |
| 9019 | if (err) { |
| 9020 | IPW_DEBUG_HC("Attempt to send SSID command failed\n"); |
| 9021 | goto done; |
| 9022 | } |
| 9023 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
| 9024 | |
| 9025 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 9026 | |
| 9027 | err = ipw_send_scan_request_ext(priv, &scan); |
| 9028 | if (err) { |
| 9029 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
| 9030 | goto done; |
| 9031 | } |
| 9032 | |
| 9033 | priv->status |= STATUS_SCANNING; |
| 9034 | |
| 9035 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9036 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9037 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9038 | } |
| 9039 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9040 | static int ipw_wx_set_scan(struct net_device *dev, |
| 9041 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9042 | union iwreq_data *wrqu, char *extra) |
| 9043 | { |
| 9044 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9045 | struct iw_scan_req *req = NULL; |
| 9046 | if (wrqu->data.length |
| 9047 | && wrqu->data.length == sizeof(struct iw_scan_req)) { |
| 9048 | req = (struct iw_scan_req *)extra; |
| 9049 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
| 9050 | ipw_request_direct_scan(priv, req->essid, |
| 9051 | req->essid_len); |
| 9052 | return 0; |
| 9053 | } |
| 9054 | } |
James Ketrenos | 8935f39 | 2005-10-05 15:59:08 -0500 | [diff] [blame] | 9055 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9056 | IPW_DEBUG_WX("Start scan\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9057 | |
| 9058 | queue_work(priv->workqueue, &priv->request_scan); |
| 9059 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9060 | return 0; |
| 9061 | } |
| 9062 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9063 | static int ipw_wx_get_scan(struct net_device *dev, |
| 9064 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9065 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9066 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9067 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9068 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); |
| 9069 | } |
| 9070 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9071 | static int ipw_wx_set_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9072 | struct iw_request_info *info, |
| 9073 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9074 | { |
| 9075 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9076 | int ret; |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9077 | u32 cap = priv->capability; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9078 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9079 | mutex_lock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9080 | ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9081 | |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9082 | /* In IBSS mode, we need to notify the firmware to update |
| 9083 | * the beacon info after we changed the capability. */ |
| 9084 | if (cap != priv->capability && |
| 9085 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 9086 | priv->status & STATUS_ASSOCIATED) |
| 9087 | ipw_disassociate(priv); |
| 9088 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9089 | mutex_unlock(&priv->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9090 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9091 | } |
| 9092 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9093 | static int ipw_wx_get_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9094 | struct iw_request_info *info, |
| 9095 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9096 | { |
| 9097 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9098 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); |
| 9099 | } |
| 9100 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9101 | static int ipw_wx_set_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9102 | struct iw_request_info *info, |
| 9103 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9104 | { |
| 9105 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9106 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9107 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9108 | if (wrqu->power.disabled) { |
| 9109 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); |
| 9110 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); |
| 9111 | if (err) { |
| 9112 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9113 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9114 | return err; |
| 9115 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9116 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9117 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9118 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9119 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9120 | |
| 9121 | switch (wrqu->power.flags & IW_POWER_MODE) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9122 | case IW_POWER_ON: /* If not specified */ |
| 9123 | case IW_POWER_MODE: /* If set all mask */ |
| 9124 | case IW_POWER_ALL_R: /* If explicitely state all */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9125 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9126 | default: /* Otherwise we don't support it */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9127 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
| 9128 | wrqu->power.flags); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9129 | mutex_unlock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9130 | return -EOPNOTSUPP; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9131 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9132 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9133 | /* If the user hasn't specified a power management mode yet, default |
| 9134 | * to BATTERY */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9135 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9136 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9137 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9138 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
| 9139 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
| 9140 | if (err) { |
| 9141 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9142 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9143 | return err; |
| 9144 | } |
| 9145 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9146 | 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] | 9147 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9148 | return 0; |
| 9149 | } |
| 9150 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9151 | static int ipw_wx_get_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9152 | struct iw_request_info *info, |
| 9153 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9154 | { |
| 9155 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9156 | mutex_lock(&priv->mutex); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9157 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9158 | wrqu->power.disabled = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9159 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9160 | wrqu->power.disabled = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9161 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9162 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9163 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9164 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9165 | return 0; |
| 9166 | } |
| 9167 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9168 | static int ipw_wx_set_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9169 | struct iw_request_info *info, |
| 9170 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9171 | { |
| 9172 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9173 | int mode = *(int *)extra; |
| 9174 | int err; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9175 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9176 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) { |
| 9177 | mode = IPW_POWER_AC; |
| 9178 | priv->power_mode = mode; |
| 9179 | } else { |
| 9180 | priv->power_mode = IPW_POWER_ENABLED | mode; |
| 9181 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9182 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9183 | if (priv->power_mode != mode) { |
| 9184 | err = ipw_send_power_mode(priv, mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9185 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9186 | if (err) { |
| 9187 | IPW_DEBUG_WX("failed setting power mode.\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9188 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9189 | return err; |
| 9190 | } |
| 9191 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9192 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9193 | return 0; |
| 9194 | } |
| 9195 | |
| 9196 | #define MAX_WX_STRING 80 |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9197 | static int ipw_wx_get_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9198 | struct iw_request_info *info, |
| 9199 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9200 | { |
| 9201 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9202 | int level = IPW_POWER_LEVEL(priv->power_mode); |
| 9203 | char *p = extra; |
| 9204 | |
| 9205 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); |
| 9206 | |
| 9207 | switch (level) { |
| 9208 | case IPW_POWER_AC: |
| 9209 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); |
| 9210 | break; |
| 9211 | case IPW_POWER_BATTERY: |
| 9212 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); |
| 9213 | break; |
| 9214 | default: |
| 9215 | p += snprintf(p, MAX_WX_STRING - (p - extra), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9216 | "(Timeout %dms, Period %dms)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9217 | timeout_duration[level - 1] / 1000, |
| 9218 | period_duration[level - 1] / 1000); |
| 9219 | } |
| 9220 | |
| 9221 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9222 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9223 | |
| 9224 | wrqu->data.length = p - extra + 1; |
| 9225 | |
| 9226 | return 0; |
| 9227 | } |
| 9228 | |
| 9229 | static int ipw_wx_set_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9230 | struct iw_request_info *info, |
| 9231 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9232 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9233 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9234 | int mode = *(int *)extra; |
| 9235 | u8 band = 0, modulation = 0; |
| 9236 | |
| 9237 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9238 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9239 | return -EINVAL; |
| 9240 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9241 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9242 | if (priv->adapter == IPW_2915ABG) { |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9243 | priv->ieee->abg_true = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9244 | if (mode & IEEE_A) { |
| 9245 | band |= IEEE80211_52GHZ_BAND; |
| 9246 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9247 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9248 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9249 | } else { |
| 9250 | if (mode & IEEE_A) { |
| 9251 | IPW_WARNING("Attempt to set 2200BG into " |
| 9252 | "802.11a mode\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9253 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9254 | return -EINVAL; |
| 9255 | } |
| 9256 | |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9257 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9258 | } |
| 9259 | |
| 9260 | if (mode & IEEE_B) { |
| 9261 | band |= IEEE80211_24GHZ_BAND; |
| 9262 | modulation |= IEEE80211_CCK_MODULATION; |
| 9263 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9264 | priv->ieee->abg_true = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9265 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9266 | if (mode & IEEE_G) { |
| 9267 | band |= IEEE80211_24GHZ_BAND; |
| 9268 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9269 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9270 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9271 | |
| 9272 | priv->ieee->mode = mode; |
| 9273 | priv->ieee->freq_band = band; |
| 9274 | priv->ieee->modulation = modulation; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9275 | init_supported_rates(priv, &priv->rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9276 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9277 | /* Network configuration changed -- force [re]association */ |
| 9278 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); |
| 9279 | if (!ipw_disassociate(priv)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9280 | ipw_send_supported_rates(priv, &priv->rates); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9281 | ipw_associate(priv); |
| 9282 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9283 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9284 | /* Update the band LEDs */ |
| 9285 | ipw_led_band_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9286 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9287 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9288 | mode & IEEE_A ? 'a' : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9289 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
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 | return 0; |
| 9292 | } |
| 9293 | |
| 9294 | static int ipw_wx_get_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9295 | struct iw_request_info *info, |
| 9296 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9297 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9298 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9299 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9300 | switch (priv->ieee->mode) { |
| 9301 | case IEEE_A: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9302 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
| 9303 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9304 | case IEEE_B: |
| 9305 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); |
| 9306 | break; |
| 9307 | case IEEE_A | IEEE_B: |
| 9308 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); |
| 9309 | break; |
| 9310 | case IEEE_G: |
| 9311 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); |
| 9312 | break; |
| 9313 | case IEEE_A | IEEE_G: |
| 9314 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); |
| 9315 | break; |
| 9316 | case IEEE_B | IEEE_G: |
| 9317 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); |
| 9318 | break; |
| 9319 | case IEEE_A | IEEE_B | IEEE_G: |
| 9320 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); |
| 9321 | break; |
| 9322 | default: |
| 9323 | strncpy(extra, "unknown", MAX_WX_STRING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9324 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9325 | } |
| 9326 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9327 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
| 9328 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9329 | wrqu->data.length = strlen(extra) + 1; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9330 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9331 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9332 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9333 | } |
| 9334 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9335 | static int ipw_wx_set_preamble(struct net_device *dev, |
| 9336 | struct iw_request_info *info, |
| 9337 | union iwreq_data *wrqu, char *extra) |
| 9338 | { |
| 9339 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9340 | int mode = *(int *)extra; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9341 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9342 | /* Switching from SHORT -> LONG requires a disassociation */ |
| 9343 | if (mode == 1) { |
| 9344 | if (!(priv->config & CFG_PREAMBLE_LONG)) { |
| 9345 | priv->config |= CFG_PREAMBLE_LONG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9346 | |
| 9347 | /* Network configuration changed -- force [re]association */ |
| 9348 | IPW_DEBUG_ASSOC |
| 9349 | ("[re]association triggered due to preamble change.\n"); |
| 9350 | if (!ipw_disassociate(priv)) |
| 9351 | ipw_associate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9352 | } |
| 9353 | goto done; |
| 9354 | } |
| 9355 | |
| 9356 | if (mode == 0) { |
| 9357 | priv->config &= ~CFG_PREAMBLE_LONG; |
| 9358 | goto done; |
| 9359 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9360 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9361 | return -EINVAL; |
| 9362 | |
| 9363 | done: |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9364 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9365 | return 0; |
| 9366 | } |
| 9367 | |
| 9368 | static int ipw_wx_get_preamble(struct net_device *dev, |
| 9369 | struct iw_request_info *info, |
| 9370 | union iwreq_data *wrqu, char *extra) |
| 9371 | { |
| 9372 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9373 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9374 | if (priv->config & CFG_PREAMBLE_LONG) |
| 9375 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); |
| 9376 | else |
| 9377 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9378 | mutex_unlock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9379 | return 0; |
| 9380 | } |
| 9381 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9382 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9383 | static int ipw_wx_set_monitor(struct net_device *dev, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9384 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9385 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9386 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9387 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9388 | int *parms = (int *)extra; |
| 9389 | int enable = (parms[0] > 0); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9390 | mutex_lock(&priv->mutex); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9391 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9392 | if (enable) { |
| 9393 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9394 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 9395 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 9396 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9397 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9398 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9399 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9400 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9401 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9402 | ipw_set_channel(priv, parms[1]); |
| 9403 | } else { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9404 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9405 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9406 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9407 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9408 | priv->net_dev->type = ARPHRD_ETHER; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9409 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9410 | } |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9411 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9412 | return 0; |
| 9413 | } |
| 9414 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9415 | #endif // CONFIG_IPW2200_MONITOR |
| 9416 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9417 | static int ipw_wx_reset(struct net_device *dev, |
| 9418 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9419 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9420 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9421 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9422 | IPW_DEBUG_WX("RESET\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9423 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9424 | return 0; |
| 9425 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9426 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9427 | static int ipw_wx_sw_reset(struct net_device *dev, |
| 9428 | struct iw_request_info *info, |
| 9429 | union iwreq_data *wrqu, char *extra) |
| 9430 | { |
| 9431 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9432 | union iwreq_data wrqu_sec = { |
| 9433 | .encoding = { |
| 9434 | .flags = IW_ENCODE_DISABLED, |
| 9435 | }, |
| 9436 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9437 | int ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9438 | |
| 9439 | IPW_DEBUG_WX("SW_RESET\n"); |
| 9440 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9441 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9442 | |
Zhu Yi | d6d5b5c | 2006-02-16 16:21:09 +0800 | [diff] [blame] | 9443 | ret = ipw_sw_reset(priv, 2); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9444 | if (!ret) { |
| 9445 | free_firmware(); |
| 9446 | ipw_adapter_restart(priv); |
| 9447 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9448 | |
| 9449 | /* The SW reset bit might have been toggled on by the 'disable' |
| 9450 | * module parameter, so take appropriate action */ |
| 9451 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); |
| 9452 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9453 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9454 | ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9455 | mutex_lock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9456 | |
| 9457 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 9458 | /* Configuration likely changed -- force [re]association */ |
| 9459 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " |
| 9460 | "reset.\n"); |
| 9461 | if (!ipw_disassociate(priv)) |
| 9462 | ipw_associate(priv); |
| 9463 | } |
| 9464 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9465 | mutex_unlock(&priv->mutex); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9466 | |
| 9467 | return 0; |
| 9468 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9469 | |
| 9470 | /* Rebase the WE IOCTLs to zero for the handler array */ |
| 9471 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9472 | static iw_handler ipw_wx_handlers[] = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9473 | IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, |
| 9474 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, |
| 9475 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, |
| 9476 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, |
| 9477 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, |
Olivier Hochreutiner | 651be26 | 2006-03-08 03:13:55 +0800 | [diff] [blame^] | 9478 | IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens, |
| 9479 | IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9480 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
| 9481 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, |
| 9482 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, |
| 9483 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, |
| 9484 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, |
| 9485 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, |
| 9486 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, |
| 9487 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, |
| 9488 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, |
| 9489 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, |
| 9490 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, |
| 9491 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, |
| 9492 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, |
| 9493 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, |
| 9494 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, |
| 9495 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, |
| 9496 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, |
| 9497 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, |
| 9498 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, |
| 9499 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, |
| 9500 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, |
| 9501 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, |
| 9502 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9503 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
| 9504 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, |
| 9505 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, |
| 9506 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9507 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
| 9508 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, |
| 9509 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, |
| 9510 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, |
| 9511 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, |
| 9512 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, |
| 9513 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9514 | }; |
| 9515 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9516 | enum { |
| 9517 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, |
| 9518 | IPW_PRIV_GET_POWER, |
| 9519 | IPW_PRIV_SET_MODE, |
| 9520 | IPW_PRIV_GET_MODE, |
| 9521 | IPW_PRIV_SET_PREAMBLE, |
| 9522 | IPW_PRIV_GET_PREAMBLE, |
| 9523 | IPW_PRIV_RESET, |
| 9524 | IPW_PRIV_SW_RESET, |
| 9525 | #ifdef CONFIG_IPW2200_MONITOR |
| 9526 | IPW_PRIV_SET_MONITOR, |
| 9527 | #endif |
| 9528 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9529 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9530 | static struct iw_priv_args ipw_priv_args[] = { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9531 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9532 | .cmd = IPW_PRIV_SET_POWER, |
| 9533 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9534 | .name = "set_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9535 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9536 | .cmd = IPW_PRIV_GET_POWER, |
| 9537 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9538 | .name = "get_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9539 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9540 | .cmd = IPW_PRIV_SET_MODE, |
| 9541 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9542 | .name = "set_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9543 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9544 | .cmd = IPW_PRIV_GET_MODE, |
| 9545 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9546 | .name = "get_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9547 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9548 | .cmd = IPW_PRIV_SET_PREAMBLE, |
| 9549 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9550 | .name = "set_preamble"}, |
| 9551 | { |
| 9552 | .cmd = IPW_PRIV_GET_PREAMBLE, |
| 9553 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, |
| 9554 | .name = "get_preamble"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9555 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9556 | IPW_PRIV_RESET, |
| 9557 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9558 | { |
| 9559 | IPW_PRIV_SW_RESET, |
| 9560 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, |
| 9561 | #ifdef CONFIG_IPW2200_MONITOR |
| 9562 | { |
| 9563 | IPW_PRIV_SET_MONITOR, |
| 9564 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, |
| 9565 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9566 | }; |
| 9567 | |
| 9568 | static iw_handler ipw_priv_handler[] = { |
| 9569 | ipw_wx_set_powermode, |
| 9570 | ipw_wx_get_powermode, |
| 9571 | ipw_wx_set_wireless_mode, |
| 9572 | ipw_wx_get_wireless_mode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9573 | ipw_wx_set_preamble, |
| 9574 | ipw_wx_get_preamble, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9575 | ipw_wx_reset, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9576 | ipw_wx_sw_reset, |
| 9577 | #ifdef CONFIG_IPW2200_MONITOR |
| 9578 | ipw_wx_set_monitor, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9579 | #endif |
| 9580 | }; |
| 9581 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9582 | static struct iw_handler_def ipw_wx_handler_def = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9583 | .standard = ipw_wx_handlers, |
| 9584 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), |
| 9585 | .num_private = ARRAY_SIZE(ipw_priv_handler), |
| 9586 | .num_private_args = ARRAY_SIZE(ipw_priv_args), |
| 9587 | .private = ipw_priv_handler, |
| 9588 | .private_args = ipw_priv_args, |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 9589 | .get_wireless_stats = ipw_get_wireless_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9590 | }; |
| 9591 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9592 | /* |
| 9593 | * Get wireless statistics. |
| 9594 | * Called by /proc/net/wireless |
| 9595 | * Also called by SIOCGIWSTATS |
| 9596 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9597 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9598 | { |
| 9599 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9600 | struct iw_statistics *wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9601 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9602 | wstats = &priv->wstats; |
| 9603 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9604 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9605 | * netdev->get_wireless_stats seems to be called before fw is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9606 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
| 9607 | * and associated; if not associcated, the values are all meaningless |
| 9608 | * anyway, so set them all to NULL and INVALID */ |
| 9609 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 9610 | wstats->miss.beacon = 0; |
| 9611 | wstats->discard.retries = 0; |
| 9612 | wstats->qual.qual = 0; |
| 9613 | wstats->qual.level = 0; |
| 9614 | wstats->qual.noise = 0; |
| 9615 | wstats->qual.updated = 7; |
| 9616 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9617 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9618 | return wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9619 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9620 | |
| 9621 | wstats->qual.qual = priv->quality; |
| 9622 | wstats->qual.level = average_value(&priv->average_rssi); |
| 9623 | wstats->qual.noise = average_value(&priv->average_noise); |
| 9624 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
Bill Moss | b191608 | 2006-02-15 08:50:18 +0800 | [diff] [blame] | 9625 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9626 | |
| 9627 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); |
| 9628 | wstats->discard.retries = priv->last_tx_failures; |
| 9629 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9630 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9631 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
| 9632 | goto fail_get_ordinal; |
| 9633 | wstats->discard.retries += tx_retry; */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9634 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9635 | return wstats; |
| 9636 | } |
| 9637 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9638 | /* net device stuff */ |
| 9639 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 9640 | static void init_sys_config(struct ipw_sys_config *sys_config) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9641 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9642 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 9643 | sys_config->bt_coexistence = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9644 | sys_config->answer_broadcast_ssid_probe = 0; |
| 9645 | sys_config->accept_all_data_frames = 0; |
| 9646 | sys_config->accept_non_directed_frames = 1; |
| 9647 | sys_config->exclude_unicast_unencrypted = 0; |
| 9648 | sys_config->disable_unicast_decryption = 1; |
| 9649 | sys_config->exclude_multicast_unencrypted = 0; |
| 9650 | sys_config->disable_multicast_decryption = 1; |
Cahill, Ben M | 71de1f3 | 2006-03-08 03:02:27 +0800 | [diff] [blame] | 9651 | sys_config->antenna_diversity = CFG_SYS_ANTENNA_SLOW_DIV; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9652 | 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] | 9653 | sys_config->dot11g_auto_detection = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9654 | sys_config->enable_cts_to_self = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9655 | sys_config->bt_coexist_collision_thr = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9656 | 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] | 9657 | sys_config->silence_threshold = 0x1e; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9658 | } |
| 9659 | |
| 9660 | static int ipw_net_open(struct net_device *dev) |
| 9661 | { |
| 9662 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9663 | IPW_DEBUG_INFO("dev->open\n"); |
| 9664 | /* we should be verifying the device is ready to be opened */ |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9665 | mutex_lock(&priv->mutex); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9666 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 9667 | (priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9668 | netif_start_queue(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9669 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9670 | return 0; |
| 9671 | } |
| 9672 | |
| 9673 | static int ipw_net_stop(struct net_device *dev) |
| 9674 | { |
| 9675 | IPW_DEBUG_INFO("dev->close\n"); |
| 9676 | netif_stop_queue(dev); |
| 9677 | return 0; |
| 9678 | } |
| 9679 | |
| 9680 | /* |
| 9681 | todo: |
| 9682 | |
| 9683 | modify to send one tfd per fragment instead of using chunking. otherwise |
| 9684 | we need to heavily modify the ieee80211_skb_to_txb. |
| 9685 | */ |
| 9686 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 9687 | 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] | 9688 | int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9689 | { |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 9690 | struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9691 | txb->fragments[0]->data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9692 | int i = 0; |
| 9693 | struct tfd_frame *tfd; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9694 | #ifdef CONFIG_IPW_QOS |
| 9695 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 9696 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 9697 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9698 | struct clx2_tx_queue *txq = &priv->txq[0]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9699 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9700 | struct clx2_queue *q = &txq->q; |
| 9701 | u8 id, hdr_len, unicast; |
| 9702 | u16 remaining_bytes; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9703 | int fc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9704 | |
| 9705 | switch (priv->ieee->iw_mode) { |
| 9706 | case IW_MODE_ADHOC: |
| 9707 | hdr_len = IEEE80211_3ADDR_LEN; |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 9708 | unicast = !is_multicast_ether_addr(hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9709 | id = ipw_find_station(priv, hdr->addr1); |
| 9710 | if (id == IPW_INVALID_STATION) { |
| 9711 | id = ipw_add_station(priv, hdr->addr1); |
| 9712 | if (id == IPW_INVALID_STATION) { |
| 9713 | IPW_WARNING("Attempt to send data to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9714 | "invalid cell: " MAC_FMT "\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9715 | MAC_ARG(hdr->addr1)); |
| 9716 | goto drop; |
| 9717 | } |
| 9718 | } |
| 9719 | break; |
| 9720 | |
| 9721 | case IW_MODE_INFRA: |
| 9722 | default: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 9723 | unicast = !is_multicast_ether_addr(hdr->addr3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9724 | hdr_len = IEEE80211_3ADDR_LEN; |
| 9725 | id = 0; |
| 9726 | break; |
| 9727 | } |
| 9728 | |
| 9729 | tfd = &txq->bd[q->first_empty]; |
| 9730 | txq->txb[q->first_empty] = txb; |
| 9731 | memset(tfd, 0, sizeof(*tfd)); |
| 9732 | tfd->u.data.station_number = id; |
| 9733 | |
| 9734 | tfd->control_flags.message_type = TX_FRAME_TYPE; |
| 9735 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 9736 | |
| 9737 | tfd->u.data.cmd_id = DINO_CMD_TX; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9738 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9739 | remaining_bytes = txb->payload_size; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9740 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9741 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9742 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9743 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9744 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9745 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9746 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
| 9747 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9748 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9749 | fc = le16_to_cpu(hdr->frame_ctl); |
| 9750 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9751 | |
| 9752 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); |
| 9753 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9754 | if (likely(unicast)) |
| 9755 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 9756 | |
| 9757 | if (txb->encrypted && !priv->ieee->host_encrypt) { |
| 9758 | switch (priv->ieee->sec.level) { |
| 9759 | case SEC_LEVEL_3: |
| 9760 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9761 | IEEE80211_FCTL_PROTECTED; |
| 9762 | /* XXX: ACK flag must be set for CCMP even if it |
| 9763 | * is a multicast/broadcast packet, because CCMP |
| 9764 | * group communication encrypted by GTK is |
| 9765 | * actually done by the AP. */ |
| 9766 | if (!unicast) |
| 9767 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 9768 | |
| 9769 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 9770 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; |
| 9771 | tfd->u.data.key_index = 0; |
| 9772 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; |
| 9773 | break; |
| 9774 | case SEC_LEVEL_2: |
| 9775 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9776 | IEEE80211_FCTL_PROTECTED; |
| 9777 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 9778 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; |
| 9779 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; |
| 9780 | break; |
| 9781 | case SEC_LEVEL_1: |
| 9782 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9783 | IEEE80211_FCTL_PROTECTED; |
| 9784 | tfd->u.data.key_index = priv->ieee->tx_keyidx; |
| 9785 | if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <= |
| 9786 | 40) |
| 9787 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; |
| 9788 | else |
| 9789 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; |
| 9790 | break; |
| 9791 | case SEC_LEVEL_0: |
| 9792 | break; |
| 9793 | default: |
| 9794 | printk(KERN_ERR "Unknow security level %d\n", |
| 9795 | priv->ieee->sec.level); |
| 9796 | break; |
| 9797 | } |
| 9798 | } else |
| 9799 | /* No hardware encryption */ |
| 9800 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; |
| 9801 | |
| 9802 | #ifdef CONFIG_IPW_QOS |
| 9803 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast); |
| 9804 | #endif /* CONFIG_IPW_QOS */ |
| 9805 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9806 | /* payload */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9807 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
| 9808 | txb->nr_frags)); |
| 9809 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", |
| 9810 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); |
| 9811 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { |
| 9812 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", |
| 9813 | i, le32_to_cpu(tfd->u.data.num_chunks), |
| 9814 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9815 | 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] | 9816 | i, tfd->u.data.num_chunks, |
| 9817 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9818 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9819 | txb->fragments[i]->len - hdr_len); |
| 9820 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9821 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9822 | cpu_to_le32(pci_map_single |
| 9823 | (priv->pci_dev, |
| 9824 | txb->fragments[i]->data + hdr_len, |
| 9825 | txb->fragments[i]->len - hdr_len, |
| 9826 | PCI_DMA_TODEVICE)); |
| 9827 | tfd->u.data.chunk_len[i] = |
| 9828 | cpu_to_le16(txb->fragments[i]->len - hdr_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9829 | } |
| 9830 | |
| 9831 | if (i != txb->nr_frags) { |
| 9832 | struct sk_buff *skb; |
| 9833 | u16 remaining_bytes = 0; |
| 9834 | int j; |
| 9835 | |
| 9836 | for (j = i; j < txb->nr_frags; j++) |
| 9837 | remaining_bytes += txb->fragments[j]->len - hdr_len; |
| 9838 | |
| 9839 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", |
| 9840 | remaining_bytes); |
| 9841 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); |
| 9842 | if (skb != NULL) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9843 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9844 | for (j = i; j < txb->nr_frags; j++) { |
| 9845 | int size = txb->fragments[j]->len - hdr_len; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9846 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9847 | printk(KERN_INFO "Adding frag %d %d...\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9848 | j, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9849 | memcpy(skb_put(skb, size), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9850 | txb->fragments[j]->data + hdr_len, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9851 | } |
| 9852 | dev_kfree_skb_any(txb->fragments[i]); |
| 9853 | txb->fragments[i] = skb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9854 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9855 | cpu_to_le32(pci_map_single |
| 9856 | (priv->pci_dev, skb->data, |
| 9857 | tfd->u.data.chunk_len[i], |
| 9858 | PCI_DMA_TODEVICE)); |
| 9859 | |
| 9860 | tfd->u.data.num_chunks = |
| 9861 | cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) + |
| 9862 | 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9863 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9864 | } |
| 9865 | |
| 9866 | /* kick DMA */ |
| 9867 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 9868 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 9869 | |
James Ketrenos | f697014 | 2006-02-14 09:10:51 +0800 | [diff] [blame] | 9870 | if (ipw_queue_space(q) < q->high_mark) |
| 9871 | netif_stop_queue(priv->net_dev); |
| 9872 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9873 | return NETDEV_TX_OK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9874 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9875 | drop: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9876 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
| 9877 | ieee80211_txb_free(txb); |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9878 | return NETDEV_TX_OK; |
| 9879 | } |
| 9880 | |
| 9881 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) |
| 9882 | { |
| 9883 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9884 | #ifdef CONFIG_IPW_QOS |
| 9885 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 9886 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 9887 | #else |
| 9888 | struct clx2_tx_queue *txq = &priv->txq[0]; |
| 9889 | #endif /* CONFIG_IPW_QOS */ |
| 9890 | |
| 9891 | if (ipw_queue_space(&txq->q) < txq->q.high_mark) |
| 9892 | return 1; |
| 9893 | |
| 9894 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9895 | } |
| 9896 | |
| 9897 | static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, |
James Ketrenos | c8d42d1 | 2005-09-21 12:23:43 -0500 | [diff] [blame] | 9898 | struct net_device *dev, int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9899 | { |
| 9900 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9901 | unsigned long flags; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9902 | int ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9903 | |
| 9904 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9905 | spin_lock_irqsave(&priv->lock, flags); |
| 9906 | |
| 9907 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 9908 | IPW_DEBUG_INFO("Tx attempt while not associated.\n"); |
| 9909 | priv->ieee->stats.tx_carrier_errors++; |
| 9910 | netif_stop_queue(dev); |
| 9911 | goto fail_unlock; |
| 9912 | } |
| 9913 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9914 | ret = ipw_tx_skb(priv, txb, pri); |
| 9915 | if (ret == NETDEV_TX_OK) |
| 9916 | __ipw_led_activity_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9917 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9918 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9919 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9920 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9921 | fail_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9922 | spin_unlock_irqrestore(&priv->lock, flags); |
| 9923 | return 1; |
| 9924 | } |
| 9925 | |
| 9926 | static struct net_device_stats *ipw_net_get_stats(struct net_device *dev) |
| 9927 | { |
| 9928 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9929 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9930 | priv->ieee->stats.tx_packets = priv->tx_packets; |
| 9931 | priv->ieee->stats.rx_packets = priv->rx_packets; |
| 9932 | return &priv->ieee->stats; |
| 9933 | } |
| 9934 | |
| 9935 | static void ipw_net_set_multicast_list(struct net_device *dev) |
| 9936 | { |
| 9937 | |
| 9938 | } |
| 9939 | |
| 9940 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) |
| 9941 | { |
| 9942 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9943 | struct sockaddr *addr = p; |
| 9944 | if (!is_valid_ether_addr(addr->sa_data)) |
| 9945 | return -EADDRNOTAVAIL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9946 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9947 | priv->config |= CFG_CUSTOM_MAC; |
| 9948 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
| 9949 | printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n", |
| 9950 | priv->net_dev->name, MAC_ARG(priv->mac_addr)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9951 | queue_work(priv->workqueue, &priv->adapter_restart); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9952 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9953 | return 0; |
| 9954 | } |
| 9955 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9956 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9957 | struct ethtool_drvinfo *info) |
| 9958 | { |
| 9959 | struct ipw_priv *p = ieee80211_priv(dev); |
| 9960 | char vers[64]; |
| 9961 | char date[32]; |
| 9962 | u32 len; |
| 9963 | |
| 9964 | strcpy(info->driver, DRV_NAME); |
| 9965 | strcpy(info->version, DRV_VERSION); |
| 9966 | |
| 9967 | len = sizeof(vers); |
| 9968 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); |
| 9969 | len = sizeof(date); |
| 9970 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); |
| 9971 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9972 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9973 | vers, date); |
| 9974 | strcpy(info->bus_info, pci_name(p->pci_dev)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9975 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9976 | } |
| 9977 | |
| 9978 | static u32 ipw_ethtool_get_link(struct net_device *dev) |
| 9979 | { |
| 9980 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9981 | return (priv->status & STATUS_ASSOCIATED) != 0; |
| 9982 | } |
| 9983 | |
| 9984 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) |
| 9985 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9986 | return IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9987 | } |
| 9988 | |
| 9989 | static int ipw_ethtool_get_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9990 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9991 | { |
| 9992 | struct ipw_priv *p = ieee80211_priv(dev); |
| 9993 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9994 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9995 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9996 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9997 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 9998 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9999 | return 0; |
| 10000 | } |
| 10001 | |
| 10002 | static int ipw_ethtool_set_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10003 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10004 | { |
| 10005 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10006 | int i; |
| 10007 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10008 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10009 | return -EINVAL; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10010 | mutex_lock(&p->mutex); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10011 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10012 | for (i = IPW_EEPROM_DATA; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10013 | i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10014 | ipw_write8(p, i, p->eeprom[i]); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10015 | mutex_unlock(&p->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10016 | return 0; |
| 10017 | } |
| 10018 | |
| 10019 | static struct ethtool_ops ipw_ethtool_ops = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10020 | .get_link = ipw_ethtool_get_link, |
| 10021 | .get_drvinfo = ipw_ethtool_get_drvinfo, |
| 10022 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, |
| 10023 | .get_eeprom = ipw_ethtool_get_eeprom, |
| 10024 | .set_eeprom = ipw_ethtool_set_eeprom, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10025 | }; |
| 10026 | |
| 10027 | static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs) |
| 10028 | { |
| 10029 | struct ipw_priv *priv = data; |
| 10030 | u32 inta, inta_mask; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10031 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10032 | if (!priv) |
| 10033 | return IRQ_NONE; |
| 10034 | |
| 10035 | spin_lock(&priv->lock); |
| 10036 | |
| 10037 | if (!(priv->status & STATUS_INT_ENABLED)) { |
| 10038 | /* Shared IRQ */ |
| 10039 | goto none; |
| 10040 | } |
| 10041 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10042 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 10043 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10044 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10045 | if (inta == 0xFFFFFFFF) { |
| 10046 | /* Hardware disappeared */ |
| 10047 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); |
| 10048 | goto none; |
| 10049 | } |
| 10050 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10051 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10052 | /* Shared interrupt */ |
| 10053 | goto none; |
| 10054 | } |
| 10055 | |
| 10056 | /* tell the device to stop sending interrupts */ |
| 10057 | ipw_disable_interrupts(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10058 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10059 | /* ack current interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10060 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
| 10061 | ipw_write32(priv, IPW_INTA_RW, inta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10062 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10063 | /* Cache INTA value for our tasklet */ |
| 10064 | priv->isr_inta = inta; |
| 10065 | |
| 10066 | tasklet_schedule(&priv->irq_tasklet); |
| 10067 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10068 | spin_unlock(&priv->lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10069 | |
| 10070 | return IRQ_HANDLED; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10071 | none: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10072 | spin_unlock(&priv->lock); |
| 10073 | return IRQ_NONE; |
| 10074 | } |
| 10075 | |
| 10076 | static void ipw_rf_kill(void *adapter) |
| 10077 | { |
| 10078 | struct ipw_priv *priv = adapter; |
| 10079 | unsigned long flags; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10080 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10081 | spin_lock_irqsave(&priv->lock, flags); |
| 10082 | |
| 10083 | if (rf_kill_active(priv)) { |
| 10084 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); |
| 10085 | if (priv->workqueue) |
| 10086 | queue_delayed_work(priv->workqueue, |
| 10087 | &priv->rf_kill, 2 * HZ); |
| 10088 | goto exit_unlock; |
| 10089 | } |
| 10090 | |
| 10091 | /* RF Kill is now disabled, so bring the device back up */ |
| 10092 | |
| 10093 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 10094 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " |
| 10095 | "device\n"); |
| 10096 | |
| 10097 | /* we can not do an adapter restart while inside an irq lock */ |
| 10098 | queue_work(priv->workqueue, &priv->adapter_restart); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10099 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10100 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
| 10101 | "enabled\n"); |
| 10102 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10103 | exit_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10104 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10105 | } |
| 10106 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10107 | static void ipw_bg_rf_kill(void *data) |
| 10108 | { |
| 10109 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10110 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10111 | ipw_rf_kill(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10112 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10113 | } |
| 10114 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10115 | static void ipw_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10116 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10117 | priv->last_seq_num = -1; |
| 10118 | priv->last_frag_num = -1; |
| 10119 | priv->last_packet_time = 0; |
| 10120 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10121 | netif_carrier_on(priv->net_dev); |
| 10122 | if (netif_queue_stopped(priv->net_dev)) { |
| 10123 | IPW_DEBUG_NOTIF("waking queue\n"); |
| 10124 | netif_wake_queue(priv->net_dev); |
| 10125 | } else { |
| 10126 | IPW_DEBUG_NOTIF("starting queue\n"); |
| 10127 | netif_start_queue(priv->net_dev); |
| 10128 | } |
| 10129 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10130 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10131 | ipw_reset_stats(priv); |
| 10132 | /* Ensure the rate is updated immediately */ |
| 10133 | priv->last_rate = ipw_get_current_rate(priv); |
| 10134 | ipw_gather_stats(priv); |
| 10135 | ipw_led_link_up(priv); |
| 10136 | notify_wx_assoc_event(priv); |
| 10137 | |
| 10138 | if (priv->config & CFG_BACKGROUND_SCAN) |
| 10139 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); |
| 10140 | } |
| 10141 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10142 | static void ipw_bg_link_up(void *data) |
| 10143 | { |
| 10144 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10145 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10146 | ipw_link_up(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10147 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10148 | } |
| 10149 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10150 | static void ipw_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10151 | { |
| 10152 | ipw_led_link_down(priv); |
| 10153 | netif_carrier_off(priv->net_dev); |
| 10154 | netif_stop_queue(priv->net_dev); |
| 10155 | notify_wx_assoc_event(priv); |
| 10156 | |
| 10157 | /* Cancel any queued work ... */ |
| 10158 | cancel_delayed_work(&priv->request_scan); |
| 10159 | cancel_delayed_work(&priv->adhoc_check); |
| 10160 | cancel_delayed_work(&priv->gather_stats); |
| 10161 | |
| 10162 | ipw_reset_stats(priv); |
| 10163 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10164 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
| 10165 | /* Queue up another scan... */ |
| 10166 | queue_work(priv->workqueue, &priv->request_scan); |
| 10167 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10168 | } |
| 10169 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10170 | static void ipw_bg_link_down(void *data) |
| 10171 | { |
| 10172 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10173 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10174 | ipw_link_down(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10175 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10176 | } |
| 10177 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10178 | static int ipw_setup_deferred_work(struct ipw_priv *priv) |
| 10179 | { |
| 10180 | int ret = 0; |
| 10181 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10182 | priv->workqueue = create_workqueue(DRV_NAME); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10183 | init_waitqueue_head(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10184 | init_waitqueue_head(&priv->wait_state); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10185 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10186 | INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv); |
| 10187 | INIT_WORK(&priv->associate, ipw_bg_associate, priv); |
| 10188 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv); |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 10189 | INIT_WORK(&priv->system_config, ipw_system_config, priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10190 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv); |
| 10191 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv); |
| 10192 | INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv); |
| 10193 | INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv); |
| 10194 | INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10195 | INIT_WORK(&priv->request_scan, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10196 | (void (*)(void *))ipw_request_scan, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10197 | INIT_WORK(&priv->gather_stats, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10198 | (void (*)(void *))ipw_bg_gather_stats, priv); |
| 10199 | INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv); |
| 10200 | INIT_WORK(&priv->roam, ipw_bg_roam, priv); |
| 10201 | INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv); |
| 10202 | INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv); |
| 10203 | INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv); |
| 10204 | 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] | 10205 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10206 | 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] | 10207 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10208 | INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off, |
| 10209 | priv); |
| 10210 | INIT_WORK(&priv->merge_networks, |
| 10211 | (void (*)(void *))ipw_merge_adhoc_network, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10212 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10213 | #ifdef CONFIG_IPW_QOS |
| 10214 | INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate, |
| 10215 | priv); |
| 10216 | #endif /* CONFIG_IPW_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10217 | |
| 10218 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 10219 | ipw_irq_tasklet, (unsigned long)priv); |
| 10220 | |
| 10221 | return ret; |
| 10222 | } |
| 10223 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10224 | static void shim__set_security(struct net_device *dev, |
| 10225 | struct ieee80211_security *sec) |
| 10226 | { |
| 10227 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10228 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10229 | for (i = 0; i < 4; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10230 | if (sec->flags & (1 << i)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10231 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10232 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10233 | if (sec->key_sizes[i] == 0) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10234 | priv->ieee->sec.flags &= ~(1 << i); |
| 10235 | else { |
| 10236 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10237 | sec->key_sizes[i]); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10238 | priv->ieee->sec.flags |= (1 << i); |
| 10239 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10240 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10241 | } else if (sec->level != SEC_LEVEL_1) |
| 10242 | priv->ieee->sec.flags &= ~(1 << i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10243 | } |
| 10244 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10245 | if (sec->flags & SEC_ACTIVE_KEY) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10246 | if (sec->active_key <= 3) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10247 | priv->ieee->sec.active_key = sec->active_key; |
| 10248 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10249 | } else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10250 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10251 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10252 | } else |
| 10253 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10254 | |
| 10255 | if ((sec->flags & SEC_AUTH_MODE) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10256 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
| 10257 | priv->ieee->sec.auth_mode = sec->auth_mode; |
| 10258 | priv->ieee->sec.flags |= SEC_AUTH_MODE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10259 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
| 10260 | priv->capability |= CAP_SHARED_KEY; |
| 10261 | else |
| 10262 | priv->capability &= ~CAP_SHARED_KEY; |
| 10263 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10264 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10265 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10266 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
| 10267 | priv->ieee->sec.flags |= SEC_ENABLED; |
| 10268 | priv->ieee->sec.enabled = sec->enabled; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10269 | priv->status |= STATUS_SECURITY_UPDATED; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10270 | if (sec->enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10271 | priv->capability |= CAP_PRIVACY_ON; |
| 10272 | else |
| 10273 | priv->capability &= ~CAP_PRIVACY_ON; |
| 10274 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10275 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10276 | if (sec->flags & SEC_ENCRYPT) |
| 10277 | priv->ieee->sec.encrypt = sec->encrypt; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10278 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10279 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
| 10280 | priv->ieee->sec.level = sec->level; |
| 10281 | priv->ieee->sec.flags |= SEC_LEVEL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10282 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10283 | } |
| 10284 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 10285 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
| 10286 | ipw_set_hwcrypto_keys(priv); |
| 10287 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10288 | /* To match current functionality of ipw2100 (which works well w/ |
| 10289 | * various supplicants, we don't force a disassociate if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10290 | * privacy capability changes ... */ |
| 10291 | #if 0 |
| 10292 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10293 | (((priv->assoc_request.capability & |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10294 | WLAN_CAPABILITY_PRIVACY) && !sec->enabled) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10295 | (!(priv->assoc_request.capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10296 | WLAN_CAPABILITY_PRIVACY) && sec->enabled))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10297 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
| 10298 | "change.\n"); |
| 10299 | ipw_disassociate(priv); |
| 10300 | } |
| 10301 | #endif |
| 10302 | } |
| 10303 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10304 | static int init_supported_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10305 | struct ipw_supported_rates *rates) |
| 10306 | { |
| 10307 | /* TODO: Mask out rates based on priv->rates_mask */ |
| 10308 | |
| 10309 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10310 | /* configure supported rates */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10311 | switch (priv->ieee->freq_band) { |
| 10312 | case IEEE80211_52GHZ_BAND: |
| 10313 | rates->ieee_mode = IPW_A_MODE; |
| 10314 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10315 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10316 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10317 | break; |
| 10318 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10319 | default: /* Mixed or 2.4Ghz */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10320 | rates->ieee_mode = IPW_G_MODE; |
| 10321 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10322 | ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10323 | IEEE80211_CCK_DEFAULT_RATES_MASK); |
| 10324 | if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) { |
| 10325 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10326 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10327 | } |
| 10328 | break; |
| 10329 | } |
| 10330 | |
| 10331 | return 0; |
| 10332 | } |
| 10333 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10334 | static int ipw_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10335 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10336 | /* This is only called from ipw_up, which resets/reloads the firmware |
| 10337 | so, we don't need to first disable the card before we configure |
| 10338 | it */ |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 10339 | if (ipw_set_tx_power(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10340 | goto error; |
| 10341 | |
| 10342 | /* initialize adapter address */ |
| 10343 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) |
| 10344 | goto error; |
| 10345 | |
| 10346 | /* set basic system config settings */ |
| 10347 | init_sys_config(&priv->sys_config); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10348 | |
| 10349 | /* Support Bluetooth if we have BT h/w on board, and user wants to. |
| 10350 | * Does not support BT priority yet (don't abort or defer our Tx) */ |
| 10351 | if (bt_coexist) { |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10352 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10353 | |
| 10354 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) |
| 10355 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10356 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10357 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
| 10358 | priv->sys_config.bt_coexistence |
Zhu Yi | 2638bc3 | 2006-01-24 16:37:52 +0800 | [diff] [blame] | 10359 | |= CFG_BT_COEXISTENCE_OOB; |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 10360 | } |
| 10361 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10362 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 10363 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 10364 | else |
| 10365 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 10366 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10367 | if (ipw_send_system_config(priv, &priv->sys_config)) |
| 10368 | goto error; |
| 10369 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10370 | init_supported_rates(priv, &priv->rates); |
| 10371 | if (ipw_send_supported_rates(priv, &priv->rates)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10372 | goto error; |
| 10373 | |
| 10374 | /* Set request-to-send threshold */ |
| 10375 | if (priv->rts_threshold) { |
| 10376 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) |
| 10377 | goto error; |
| 10378 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10379 | #ifdef CONFIG_IPW_QOS |
| 10380 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
| 10381 | ipw_qos_activate(priv, NULL); |
| 10382 | #endif /* CONFIG_IPW_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10383 | |
| 10384 | if (ipw_set_random_seed(priv)) |
| 10385 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10386 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10387 | /* final state transition to the RUN state */ |
| 10388 | if (ipw_send_host_complete(priv)) |
| 10389 | goto error; |
| 10390 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10391 | priv->status |= STATUS_INIT; |
| 10392 | |
| 10393 | ipw_led_init(priv); |
| 10394 | ipw_led_radio_on(priv); |
| 10395 | priv->notif_missed_beacons = 0; |
| 10396 | |
| 10397 | /* Set hardware WEP key if it is configured. */ |
| 10398 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 10399 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 10400 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 10401 | ipw_set_hwcrypto_keys(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10402 | |
| 10403 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10404 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10405 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10406 | return -EIO; |
| 10407 | } |
| 10408 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10409 | /* |
| 10410 | * NOTE: |
| 10411 | * |
| 10412 | * These tables have been tested in conjunction with the |
| 10413 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. |
| 10414 | * |
| 10415 | * Altering this values, using it on other hardware, or in geographies |
| 10416 | * not intended for resale of the above mentioned Intel adapters has |
| 10417 | * not been tested. |
| 10418 | * |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 10419 | * Remember to update the table in README.ipw2200 when changing this |
| 10420 | * table. |
| 10421 | * |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10422 | */ |
| 10423 | static const struct ieee80211_geo ipw_geos[] = { |
| 10424 | { /* Restricted */ |
| 10425 | "---", |
| 10426 | .bg_channels = 11, |
| 10427 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10428 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10429 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10430 | {2457, 10}, {2462, 11}}, |
| 10431 | }, |
| 10432 | |
| 10433 | { /* Custom US/Canada */ |
| 10434 | "ZZF", |
| 10435 | .bg_channels = 11, |
| 10436 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10437 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10438 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10439 | {2457, 10}, {2462, 11}}, |
| 10440 | .a_channels = 8, |
| 10441 | .a = {{5180, 36}, |
| 10442 | {5200, 40}, |
| 10443 | {5220, 44}, |
| 10444 | {5240, 48}, |
| 10445 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10446 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10447 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10448 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10449 | }, |
| 10450 | |
| 10451 | { /* Rest of World */ |
| 10452 | "ZZD", |
| 10453 | .bg_channels = 13, |
| 10454 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10455 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10456 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10457 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10458 | {2472, 13}}, |
| 10459 | }, |
| 10460 | |
| 10461 | { /* Custom USA & Europe & High */ |
| 10462 | "ZZA", |
| 10463 | .bg_channels = 11, |
| 10464 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10465 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10466 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10467 | {2457, 10}, {2462, 11}}, |
| 10468 | .a_channels = 13, |
| 10469 | .a = {{5180, 36}, |
| 10470 | {5200, 40}, |
| 10471 | {5220, 44}, |
| 10472 | {5240, 48}, |
| 10473 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10474 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10475 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10476 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10477 | {5745, 149}, |
| 10478 | {5765, 153}, |
| 10479 | {5785, 157}, |
| 10480 | {5805, 161}, |
| 10481 | {5825, 165}}, |
| 10482 | }, |
| 10483 | |
| 10484 | { /* Custom NA & Europe */ |
| 10485 | "ZZB", |
| 10486 | .bg_channels = 11, |
| 10487 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10488 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10489 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10490 | {2457, 10}, {2462, 11}}, |
| 10491 | .a_channels = 13, |
| 10492 | .a = {{5180, 36}, |
| 10493 | {5200, 40}, |
| 10494 | {5220, 44}, |
| 10495 | {5240, 48}, |
| 10496 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10497 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10498 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10499 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10500 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10501 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10502 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10503 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10504 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10505 | }, |
| 10506 | |
| 10507 | { /* Custom Japan */ |
| 10508 | "ZZC", |
| 10509 | .bg_channels = 11, |
| 10510 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10511 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10512 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10513 | {2457, 10}, {2462, 11}}, |
| 10514 | .a_channels = 4, |
| 10515 | .a = {{5170, 34}, {5190, 38}, |
| 10516 | {5210, 42}, {5230, 46}}, |
| 10517 | }, |
| 10518 | |
| 10519 | { /* Custom */ |
| 10520 | "ZZM", |
| 10521 | .bg_channels = 11, |
| 10522 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10523 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10524 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10525 | {2457, 10}, {2462, 11}}, |
| 10526 | }, |
| 10527 | |
| 10528 | { /* Europe */ |
| 10529 | "ZZE", |
| 10530 | .bg_channels = 13, |
| 10531 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10532 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10533 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10534 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10535 | {2472, 13}}, |
| 10536 | .a_channels = 19, |
| 10537 | .a = {{5180, 36}, |
| 10538 | {5200, 40}, |
| 10539 | {5220, 44}, |
| 10540 | {5240, 48}, |
| 10541 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10542 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10543 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10544 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10545 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 10546 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 10547 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 10548 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 10549 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 10550 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 10551 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 10552 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 10553 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 10554 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 10555 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10556 | }, |
| 10557 | |
| 10558 | { /* Custom Japan */ |
| 10559 | "ZZJ", |
| 10560 | .bg_channels = 14, |
| 10561 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10562 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10563 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10564 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10565 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}}, |
| 10566 | .a_channels = 4, |
| 10567 | .a = {{5170, 34}, {5190, 38}, |
| 10568 | {5210, 42}, {5230, 46}}, |
| 10569 | }, |
| 10570 | |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 10571 | { /* Rest of World */ |
| 10572 | "ZZR", |
| 10573 | .bg_channels = 14, |
| 10574 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10575 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10576 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10577 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10578 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY | |
| 10579 | IEEE80211_CH_PASSIVE_ONLY}}, |
| 10580 | }, |
| 10581 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10582 | { /* High Band */ |
| 10583 | "ZZH", |
| 10584 | .bg_channels = 13, |
| 10585 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10586 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10587 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10588 | {2457, 10}, {2462, 11}, |
| 10589 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 10590 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10591 | .a_channels = 4, |
| 10592 | .a = {{5745, 149}, {5765, 153}, |
| 10593 | {5785, 157}, {5805, 161}}, |
| 10594 | }, |
| 10595 | |
| 10596 | { /* Custom Europe */ |
| 10597 | "ZZG", |
| 10598 | .bg_channels = 13, |
| 10599 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10600 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10601 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10602 | {2457, 10}, {2462, 11}, |
| 10603 | {2467, 12}, {2472, 13}}, |
| 10604 | .a_channels = 4, |
| 10605 | .a = {{5180, 36}, {5200, 40}, |
| 10606 | {5220, 44}, {5240, 48}}, |
| 10607 | }, |
| 10608 | |
| 10609 | { /* Europe */ |
| 10610 | "ZZK", |
| 10611 | .bg_channels = 13, |
| 10612 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10613 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10614 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10615 | {2457, 10}, {2462, 11}, |
| 10616 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 10617 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10618 | .a_channels = 24, |
| 10619 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 10620 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 10621 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 10622 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 10623 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10624 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10625 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10626 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10627 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 10628 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 10629 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 10630 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 10631 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 10632 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 10633 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 10634 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 10635 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 10636 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 10637 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}, |
| 10638 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10639 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10640 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10641 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10642 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10643 | }, |
| 10644 | |
| 10645 | { /* Europe */ |
| 10646 | "ZZL", |
| 10647 | .bg_channels = 11, |
| 10648 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10649 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10650 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10651 | {2457, 10}, {2462, 11}}, |
| 10652 | .a_channels = 13, |
| 10653 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 10654 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 10655 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 10656 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 10657 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10658 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10659 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10660 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10661 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10662 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10663 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10664 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10665 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10666 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10667 | }; |
| 10668 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10669 | #define MAX_HW_RESTARTS 5 |
| 10670 | static int ipw_up(struct ipw_priv *priv) |
| 10671 | { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10672 | int rc, i, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10673 | |
| 10674 | if (priv->status & STATUS_EXIT_PENDING) |
| 10675 | return -EIO; |
| 10676 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 10677 | if (cmdlog && !priv->cmdlog) { |
| 10678 | priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog, |
| 10679 | GFP_KERNEL); |
| 10680 | if (priv->cmdlog == NULL) { |
| 10681 | IPW_ERROR("Error allocating %d command log entries.\n", |
| 10682 | cmdlog); |
| 10683 | } else { |
| 10684 | memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog); |
| 10685 | priv->cmdlog_len = cmdlog; |
| 10686 | } |
| 10687 | } |
| 10688 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10689 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10690 | /* Load the microcode, firmware, and eeprom. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10691 | * Also start the clocks. */ |
| 10692 | rc = ipw_load(priv); |
| 10693 | if (rc) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 10694 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10695 | return rc; |
| 10696 | } |
| 10697 | |
| 10698 | ipw_init_ordinals(priv); |
| 10699 | if (!(priv->config & CFG_CUSTOM_MAC)) |
| 10700 | eeprom_parse_mac(priv, priv->mac_addr); |
| 10701 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
| 10702 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10703 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
| 10704 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], |
| 10705 | ipw_geos[j].name, 3)) |
| 10706 | break; |
| 10707 | } |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 10708 | if (j == ARRAY_SIZE(ipw_geos)) { |
| 10709 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", |
| 10710 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], |
| 10711 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], |
| 10712 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10713 | j = 0; |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 10714 | } |
Larry Finger | 1867b11 | 2006-02-28 09:48:28 -0600 | [diff] [blame] | 10715 | if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10716 | IPW_WARNING("Could not set geography."); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10717 | return 0; |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10718 | } |
| 10719 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10720 | if (priv->status & STATUS_RF_KILL_SW) { |
| 10721 | IPW_WARNING("Radio disabled by module parameter.\n"); |
| 10722 | return 0; |
| 10723 | } else if (rf_kill_active(priv)) { |
| 10724 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" |
| 10725 | "Kill switch must be turned off for " |
| 10726 | "wireless networking to work.\n"); |
| 10727 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
| 10728 | 2 * HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10729 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10730 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10731 | |
| 10732 | rc = ipw_config(priv); |
| 10733 | if (!rc) { |
| 10734 | IPW_DEBUG_INFO("Configured device on count %i\n", i); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10735 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10736 | /* If configure to try and auto-associate, kick |
| 10737 | * off a scan. */ |
| 10738 | queue_work(priv->workqueue, &priv->request_scan); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10739 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10740 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10741 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10742 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10743 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10744 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
| 10745 | i, MAX_HW_RESTARTS); |
| 10746 | |
| 10747 | /* We had an error bringing up the hardware, so take it |
| 10748 | * all the way back down so we can try again */ |
| 10749 | ipw_down(priv); |
| 10750 | } |
| 10751 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10752 | /* tried to restart and config the device for as long as our |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10753 | * patience could withstand */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10754 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10755 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10756 | return -EIO; |
| 10757 | } |
| 10758 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10759 | static void ipw_bg_up(void *data) |
| 10760 | { |
| 10761 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10762 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10763 | ipw_up(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10764 | mutex_unlock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10765 | } |
| 10766 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10767 | static void ipw_deinit(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10768 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10769 | int i; |
| 10770 | |
| 10771 | if (priv->status & STATUS_SCANNING) { |
| 10772 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); |
| 10773 | ipw_abort_scan(priv); |
| 10774 | } |
| 10775 | |
| 10776 | if (priv->status & STATUS_ASSOCIATED) { |
| 10777 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); |
| 10778 | ipw_disassociate(priv); |
| 10779 | } |
| 10780 | |
| 10781 | ipw_led_shutdown(priv); |
| 10782 | |
| 10783 | /* Wait up to 1s for status to change to not scanning and not |
| 10784 | * associated (disassociation can take a while for a ful 802.11 |
| 10785 | * exchange */ |
| 10786 | for (i = 1000; i && (priv->status & |
| 10787 | (STATUS_DISASSOCIATING | |
| 10788 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) |
| 10789 | udelay(10); |
| 10790 | |
| 10791 | if (priv->status & (STATUS_DISASSOCIATING | |
| 10792 | STATUS_ASSOCIATED | STATUS_SCANNING)) |
| 10793 | IPW_DEBUG_INFO("Still associated or scanning...\n"); |
| 10794 | else |
| 10795 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); |
| 10796 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10797 | /* Attempt to disable the card */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10798 | ipw_send_card_disable(priv, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10799 | |
| 10800 | priv->status &= ~STATUS_INIT; |
| 10801 | } |
| 10802 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10803 | static void ipw_down(struct ipw_priv *priv) |
| 10804 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10805 | int exit_pending = priv->status & STATUS_EXIT_PENDING; |
| 10806 | |
| 10807 | priv->status |= STATUS_EXIT_PENDING; |
| 10808 | |
| 10809 | if (ipw_is_init(priv)) |
| 10810 | ipw_deinit(priv); |
| 10811 | |
| 10812 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 10813 | * exiting the module */ |
| 10814 | if (!exit_pending) |
| 10815 | priv->status &= ~STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10816 | |
| 10817 | /* tell the device to stop sending interrupts */ |
| 10818 | ipw_disable_interrupts(priv); |
| 10819 | |
| 10820 | /* Clear all bits but the RF Kill */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10821 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10822 | netif_carrier_off(priv->net_dev); |
| 10823 | netif_stop_queue(priv->net_dev); |
| 10824 | |
| 10825 | ipw_stop_nic(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10826 | |
| 10827 | ipw_led_radio_off(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10828 | } |
| 10829 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10830 | static void ipw_bg_down(void *data) |
| 10831 | { |
| 10832 | struct ipw_priv *priv = data; |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10833 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10834 | ipw_down(data); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10835 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10836 | } |
| 10837 | |
| 10838 | /* Called by register_netdev() */ |
| 10839 | static int ipw_net_init(struct net_device *dev) |
| 10840 | { |
| 10841 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10842 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10843 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10844 | if (ipw_up(priv)) { |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10845 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10846 | return -EIO; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10847 | } |
| 10848 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10849 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10850 | return 0; |
| 10851 | } |
| 10852 | |
| 10853 | /* PCI driver stuff */ |
| 10854 | static struct pci_device_id card_ids[] = { |
| 10855 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
| 10856 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, |
| 10857 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, |
| 10858 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, |
| 10859 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, |
| 10860 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, |
| 10861 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, |
| 10862 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, |
| 10863 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, |
| 10864 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, |
| 10865 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, |
| 10866 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, |
| 10867 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, |
| 10868 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, |
| 10869 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, |
| 10870 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, |
| 10871 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, |
| 10872 | {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] | 10873 | {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] | 10874 | {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] | 10875 | {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ |
| 10876 | {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] | 10877 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10878 | /* required last entry */ |
| 10879 | {0,} |
| 10880 | }; |
| 10881 | |
| 10882 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 10883 | |
| 10884 | static struct attribute *ipw_sysfs_entries[] = { |
| 10885 | &dev_attr_rf_kill.attr, |
| 10886 | &dev_attr_direct_dword.attr, |
| 10887 | &dev_attr_indirect_byte.attr, |
| 10888 | &dev_attr_indirect_dword.attr, |
| 10889 | &dev_attr_mem_gpio_reg.attr, |
| 10890 | &dev_attr_command_event_reg.attr, |
| 10891 | &dev_attr_nic_type.attr, |
| 10892 | &dev_attr_status.attr, |
| 10893 | &dev_attr_cfg.attr, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 10894 | &dev_attr_error.attr, |
| 10895 | &dev_attr_event_log.attr, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 10896 | &dev_attr_cmd_log.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10897 | &dev_attr_eeprom_delay.attr, |
| 10898 | &dev_attr_ucode_version.attr, |
| 10899 | &dev_attr_rtc.attr, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10900 | &dev_attr_scan_age.attr, |
| 10901 | &dev_attr_led.attr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10902 | &dev_attr_speed_scan.attr, |
| 10903 | &dev_attr_net_stats.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10904 | NULL |
| 10905 | }; |
| 10906 | |
| 10907 | static struct attribute_group ipw_attribute_group = { |
| 10908 | .name = NULL, /* put in device directory */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10909 | .attrs = ipw_sysfs_entries, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10910 | }; |
| 10911 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10912 | 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] | 10913 | { |
| 10914 | int err = 0; |
| 10915 | struct net_device *net_dev; |
| 10916 | void __iomem *base; |
| 10917 | u32 length, val; |
| 10918 | struct ipw_priv *priv; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10919 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10920 | |
| 10921 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv)); |
| 10922 | if (net_dev == NULL) { |
| 10923 | err = -ENOMEM; |
| 10924 | goto out; |
| 10925 | } |
| 10926 | |
| 10927 | priv = ieee80211_priv(net_dev); |
| 10928 | priv->ieee = netdev_priv(net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10929 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10930 | priv->net_dev = net_dev; |
| 10931 | priv->pci_dev = pdev; |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 10932 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10933 | ipw_debug_level = debug; |
| 10934 | #endif |
| 10935 | spin_lock_init(&priv->lock); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10936 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
| 10937 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10938 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10939 | mutex_init(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10940 | if (pci_enable_device(pdev)) { |
| 10941 | err = -ENODEV; |
| 10942 | goto out_free_ieee80211; |
| 10943 | } |
| 10944 | |
| 10945 | pci_set_master(pdev); |
| 10946 | |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 10947 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10948 | if (!err) |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 10949 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10950 | if (err) { |
| 10951 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 10952 | goto out_pci_disable_device; |
| 10953 | } |
| 10954 | |
| 10955 | pci_set_drvdata(pdev, priv); |
| 10956 | |
| 10957 | err = pci_request_regions(pdev, DRV_NAME); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10958 | if (err) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10959 | goto out_pci_disable_device; |
| 10960 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10961 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10962 | * PCI Tx retries from interfering with C3 CPU state */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10963 | pci_read_config_dword(pdev, 0x40, &val); |
| 10964 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10965 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10966 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10967 | length = pci_resource_len(pdev, 0); |
| 10968 | priv->hw_len = length; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10969 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10970 | base = ioremap_nocache(pci_resource_start(pdev, 0), length); |
| 10971 | if (!base) { |
| 10972 | err = -ENODEV; |
| 10973 | goto out_pci_release_regions; |
| 10974 | } |
| 10975 | |
| 10976 | priv->hw_base = base; |
| 10977 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); |
| 10978 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); |
| 10979 | |
| 10980 | err = ipw_setup_deferred_work(priv); |
| 10981 | if (err) { |
| 10982 | IPW_ERROR("Unable to setup deferred work\n"); |
| 10983 | goto out_iounmap; |
| 10984 | } |
| 10985 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10986 | ipw_sw_reset(priv, 1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10987 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10988 | err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10989 | if (err) { |
| 10990 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 10991 | goto out_destroy_workqueue; |
| 10992 | } |
| 10993 | |
| 10994 | SET_MODULE_OWNER(net_dev); |
| 10995 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
| 10996 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 10997 | mutex_lock(&priv->mutex); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10998 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10999 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
| 11000 | priv->ieee->set_security = shim__set_security; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 11001 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11002 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11003 | #ifdef CONFIG_IPW_QOS |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 11004 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
| 11005 | priv->ieee->handle_beacon = ipw_handle_probe_response; |
| 11006 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11007 | #endif /* CONFIG_IPW_QOS */ |
| 11008 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11009 | priv->ieee->perfect_rssi = -20; |
| 11010 | priv->ieee->worst_rssi = -85; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11011 | |
| 11012 | net_dev->open = ipw_net_open; |
| 11013 | net_dev->stop = ipw_net_stop; |
| 11014 | net_dev->init = ipw_net_init; |
| 11015 | net_dev->get_stats = ipw_net_get_stats; |
| 11016 | net_dev->set_multicast_list = ipw_net_set_multicast_list; |
| 11017 | net_dev->set_mac_address = ipw_net_set_mac_address; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11018 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11019 | net_dev->wireless_data = &priv->wireless_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11020 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
| 11021 | net_dev->ethtool_ops = &ipw_ethtool_ops; |
| 11022 | net_dev->irq = pdev->irq; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11023 | net_dev->base_addr = (unsigned long)priv->hw_base; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11024 | net_dev->mem_start = pci_resource_start(pdev, 0); |
| 11025 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; |
| 11026 | |
| 11027 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11028 | if (err) { |
| 11029 | IPW_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11030 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11031 | goto out_release_irq; |
| 11032 | } |
| 11033 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11034 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11035 | err = register_netdev(net_dev); |
| 11036 | if (err) { |
| 11037 | IPW_ERROR("failed to register network device\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11038 | goto out_remove_sysfs; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11039 | } |
Henrik Brix Andersen | 48a8477 | 2006-02-14 09:09:52 +0800 | [diff] [blame] | 11040 | |
| 11041 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " |
| 11042 | "channels, %d 802.11a channels)\n", |
| 11043 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, |
| 11044 | priv->ieee->geo.a_channels); |
| 11045 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11046 | return 0; |
| 11047 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11048 | out_remove_sysfs: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11049 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11050 | out_release_irq: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11051 | free_irq(pdev->irq, priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11052 | out_destroy_workqueue: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11053 | destroy_workqueue(priv->workqueue); |
| 11054 | priv->workqueue = NULL; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11055 | out_iounmap: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11056 | iounmap(priv->hw_base); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11057 | out_pci_release_regions: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11058 | pci_release_regions(pdev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11059 | out_pci_disable_device: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11060 | pci_disable_device(pdev); |
| 11061 | pci_set_drvdata(pdev, NULL); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11062 | out_free_ieee80211: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11063 | free_ieee80211(priv->net_dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11064 | out: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11065 | return err; |
| 11066 | } |
| 11067 | |
| 11068 | static void ipw_pci_remove(struct pci_dev *pdev) |
| 11069 | { |
| 11070 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11071 | struct list_head *p, *q; |
| 11072 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11073 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11074 | if (!priv) |
| 11075 | return; |
| 11076 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11077 | mutex_lock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11078 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11079 | priv->status |= STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11080 | ipw_down(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11081 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11082 | |
Zhu Yi | 4644151 | 2006-01-24 16:37:59 +0800 | [diff] [blame] | 11083 | mutex_unlock(&priv->mutex); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11084 | |
| 11085 | unregister_netdev(priv->net_dev); |
| 11086 | |
| 11087 | if (priv->rxq) { |
| 11088 | ipw_rx_queue_free(priv, priv->rxq); |
| 11089 | priv->rxq = NULL; |
| 11090 | } |
| 11091 | ipw_tx_queue_free(priv); |
| 11092 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11093 | if (priv->cmdlog) { |
| 11094 | kfree(priv->cmdlog); |
| 11095 | priv->cmdlog = NULL; |
| 11096 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11097 | /* ipw_down will ensure that there is no more pending work |
| 11098 | * in the workqueue's, so we can safely remove them now. */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11099 | cancel_delayed_work(&priv->adhoc_check); |
| 11100 | cancel_delayed_work(&priv->gather_stats); |
| 11101 | cancel_delayed_work(&priv->request_scan); |
| 11102 | cancel_delayed_work(&priv->rf_kill); |
| 11103 | cancel_delayed_work(&priv->scan_check); |
| 11104 | destroy_workqueue(priv->workqueue); |
| 11105 | priv->workqueue = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11106 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11107 | /* Free MAC hash list for ADHOC */ |
| 11108 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { |
| 11109 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11110 | list_del(p); |
Zhu Yi | 489f445 | 2006-01-24 16:37:41 +0800 | [diff] [blame] | 11111 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11112 | } |
| 11113 | } |
| 11114 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 11115 | if (priv->error) { |
| 11116 | ipw_free_error_log(priv->error); |
| 11117 | priv->error = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11118 | } |
| 11119 | |
| 11120 | free_irq(pdev->irq, priv); |
| 11121 | iounmap(priv->hw_base); |
| 11122 | pci_release_regions(pdev); |
| 11123 | pci_disable_device(pdev); |
| 11124 | pci_set_drvdata(pdev, NULL); |
| 11125 | free_ieee80211(priv->net_dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11126 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11127 | } |
| 11128 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11129 | #ifdef CONFIG_PM |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11130 | 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] | 11131 | { |
| 11132 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11133 | struct net_device *dev = priv->net_dev; |
| 11134 | |
| 11135 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); |
| 11136 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11137 | /* Take down the device; powers it off, etc. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11138 | ipw_down(priv); |
| 11139 | |
| 11140 | /* Remove the PRESENT state of the device */ |
| 11141 | netif_device_detach(dev); |
| 11142 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11143 | pci_save_state(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11144 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11145 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11146 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11147 | return 0; |
| 11148 | } |
| 11149 | |
| 11150 | static int ipw_pci_resume(struct pci_dev *pdev) |
| 11151 | { |
| 11152 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11153 | struct net_device *dev = priv->net_dev; |
| 11154 | u32 val; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11155 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11156 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
| 11157 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11158 | pci_set_power_state(pdev, PCI_D0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11159 | pci_enable_device(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11160 | pci_restore_state(pdev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11161 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11162 | /* |
| 11163 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 11164 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 11165 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 11166 | * here since it only restores the first 64 bytes pci config header. |
| 11167 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11168 | pci_read_config_dword(pdev, 0x40, &val); |
| 11169 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11170 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 11171 | |
| 11172 | /* Set the device back into the PRESENT state; this will also wake |
| 11173 | * the queue of needed */ |
| 11174 | netif_device_attach(dev); |
| 11175 | |
| 11176 | /* Bring the device back up */ |
| 11177 | queue_work(priv->workqueue, &priv->up); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11178 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11179 | return 0; |
| 11180 | } |
| 11181 | #endif |
| 11182 | |
| 11183 | /* driver initialization stuff */ |
| 11184 | static struct pci_driver ipw_driver = { |
| 11185 | .name = DRV_NAME, |
| 11186 | .id_table = card_ids, |
| 11187 | .probe = ipw_pci_probe, |
| 11188 | .remove = __devexit_p(ipw_pci_remove), |
| 11189 | #ifdef CONFIG_PM |
| 11190 | .suspend = ipw_pci_suspend, |
| 11191 | .resume = ipw_pci_resume, |
| 11192 | #endif |
| 11193 | }; |
| 11194 | |
| 11195 | static int __init ipw_init(void) |
| 11196 | { |
| 11197 | int ret; |
| 11198 | |
| 11199 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 11200 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 11201 | |
| 11202 | ret = pci_module_init(&ipw_driver); |
| 11203 | if (ret) { |
| 11204 | IPW_ERROR("Unable to initialize PCI module\n"); |
| 11205 | return ret; |
| 11206 | } |
| 11207 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11208 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11209 | if (ret) { |
| 11210 | IPW_ERROR("Unable to create driver sysfs file\n"); |
| 11211 | pci_unregister_driver(&ipw_driver); |
| 11212 | return ret; |
| 11213 | } |
| 11214 | |
| 11215 | return ret; |
| 11216 | } |
| 11217 | |
| 11218 | static void __exit ipw_exit(void) |
| 11219 | { |
| 11220 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); |
| 11221 | pci_unregister_driver(&ipw_driver); |
| 11222 | } |
| 11223 | |
| 11224 | module_param(disable, int, 0444); |
| 11225 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 11226 | |
| 11227 | module_param(associate, int, 0444); |
| 11228 | MODULE_PARM_DESC(associate, "auto associate when scanning (default on)"); |
| 11229 | |
| 11230 | module_param(auto_create, int, 0444); |
| 11231 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); |
| 11232 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11233 | module_param(led, int, 0444); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11234 | 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] | 11235 | |
Zhu Yi | 3e1555b | 2006-03-06 05:48:37 +0800 | [diff] [blame] | 11236 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11237 | module_param(debug, int, 0444); |
| 11238 | MODULE_PARM_DESC(debug, "debug output mask"); |
Zhu Yi | 3e1555b | 2006-03-06 05:48:37 +0800 | [diff] [blame] | 11239 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11240 | |
| 11241 | module_param(channel, int, 0444); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11242 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11243 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11244 | #ifdef CONFIG_IPW_QOS |
| 11245 | module_param(qos_enable, int, 0444); |
| 11246 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11247 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11248 | module_param(qos_burst_enable, int, 0444); |
| 11249 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); |
| 11250 | |
| 11251 | module_param(qos_no_ack_mask, int, 0444); |
| 11252 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); |
| 11253 | |
| 11254 | module_param(burst_duration_CCK, int, 0444); |
| 11255 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); |
| 11256 | |
| 11257 | module_param(burst_duration_OFDM, int, 0444); |
| 11258 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); |
| 11259 | #endif /* CONFIG_IPW_QOS */ |
| 11260 | |
| 11261 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11262 | module_param(mode, int, 0444); |
| 11263 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); |
| 11264 | #else |
| 11265 | module_param(mode, int, 0444); |
| 11266 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
| 11267 | #endif |
| 11268 | |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame] | 11269 | module_param(bt_coexist, int, 0444); |
| 11270 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); |
| 11271 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11272 | module_param(hwcrypto, int, 0444); |
Zhu Yi | bde37d0 | 2006-01-24 16:38:08 +0800 | [diff] [blame] | 11273 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11274 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11275 | module_param(cmdlog, int, 0444); |
| 11276 | MODULE_PARM_DESC(cmdlog, |
| 11277 | "allocate a ring buffer for logging firmware commands"); |
| 11278 | |
Zhu Yi | 4bfdb91 | 2006-01-24 16:37:16 +0800 | [diff] [blame] | 11279 | module_param(roaming, int, 0444); |
| 11280 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); |
| 11281 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11282 | module_exit(ipw_exit); |
| 11283 | module_init(ipw_init); |