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 | |
James Ketrenos | cf1b479 | 2005-10-20 16:35:24 -0500 | [diff] [blame] | 36 | #define IPW2200_VERSION "git-1.0.8" |
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; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 59 | static int hwcrypto = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 60 | static const char ipw_modes[] = { |
| 61 | 'a', 'b', 'g', '?' |
| 62 | }; |
| 63 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 64 | #ifdef CONFIG_IPW_QOS |
| 65 | static int qos_enable = 0; |
| 66 | static int qos_burst_enable = 0; |
| 67 | static int qos_no_ack_mask = 0; |
| 68 | static int burst_duration_CCK = 0; |
| 69 | static int burst_duration_OFDM = 0; |
| 70 | |
| 71 | static struct ieee80211_qos_parameters def_qos_parameters_OFDM = { |
| 72 | {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, |
| 73 | QOS_TX3_CW_MIN_OFDM}, |
| 74 | {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, |
| 75 | QOS_TX3_CW_MAX_OFDM}, |
| 76 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 77 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 78 | {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, |
| 79 | QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} |
| 80 | }; |
| 81 | |
| 82 | static struct ieee80211_qos_parameters def_qos_parameters_CCK = { |
| 83 | {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, |
| 84 | QOS_TX3_CW_MIN_CCK}, |
| 85 | {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, |
| 86 | QOS_TX3_CW_MAX_CCK}, |
| 87 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 88 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 89 | {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, |
| 90 | QOS_TX3_TXOP_LIMIT_CCK} |
| 91 | }; |
| 92 | |
| 93 | static struct ieee80211_qos_parameters def_parameters_OFDM = { |
| 94 | {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, |
| 95 | DEF_TX3_CW_MIN_OFDM}, |
| 96 | {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, |
| 97 | DEF_TX3_CW_MAX_OFDM}, |
| 98 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 99 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 100 | {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, |
| 101 | DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} |
| 102 | }; |
| 103 | |
| 104 | static struct ieee80211_qos_parameters def_parameters_CCK = { |
| 105 | {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, |
| 106 | DEF_TX3_CW_MIN_CCK}, |
| 107 | {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, |
| 108 | DEF_TX3_CW_MAX_CCK}, |
| 109 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 110 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 111 | {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, |
| 112 | DEF_TX3_TXOP_LIMIT_CCK} |
| 113 | }; |
| 114 | |
| 115 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; |
| 116 | |
| 117 | static int from_priority_to_tx_queue[] = { |
| 118 | IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, |
| 119 | IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 |
| 120 | }; |
| 121 | |
| 122 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); |
| 123 | |
| 124 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
| 125 | *qos_param); |
| 126 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element |
| 127 | *qos_param); |
| 128 | #endif /* CONFIG_IPW_QOS */ |
| 129 | |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 130 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 131 | static void ipw_remove_current_network(struct ipw_priv *priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 132 | static void ipw_rx(struct ipw_priv *priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 133 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 134 | struct clx2_tx_queue *txq, int qindex); |
| 135 | static int ipw_queue_reset(struct ipw_priv *priv); |
| 136 | |
| 137 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 138 | int len, int sync); |
| 139 | |
| 140 | static void ipw_tx_queue_free(struct ipw_priv *); |
| 141 | |
| 142 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); |
| 143 | static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); |
| 144 | static void ipw_rx_queue_replenish(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 145 | static int ipw_up(struct ipw_priv *); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 146 | static void ipw_bg_up(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 147 | static void ipw_down(struct ipw_priv *); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 148 | static void ipw_bg_down(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 149 | static int ipw_config(struct ipw_priv *); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 150 | static int init_supported_rates(struct ipw_priv *priv, |
| 151 | struct ipw_supported_rates *prates); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 152 | static void ipw_set_hwcrypto_keys(struct ipw_priv *); |
| 153 | static void ipw_send_wep_keys(struct ipw_priv *, int); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 154 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 155 | static int ipw_is_valid_channel(struct ieee80211_device *, u8); |
| 156 | static int ipw_channel_to_index(struct ieee80211_device *, u8); |
| 157 | static u8 ipw_freq_to_channel(struct ieee80211_device *, u32); |
| 158 | static int ipw_set_geo(struct ieee80211_device *, const struct ieee80211_geo *); |
| 159 | static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 160 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 161 | static int snprint_line(char *buf, size_t count, |
| 162 | const u8 * data, u32 len, u32 ofs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 163 | { |
| 164 | int out, i, j, l; |
| 165 | char c; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 166 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 167 | out = snprintf(buf, count, "%08X", ofs); |
| 168 | |
| 169 | for (l = 0, i = 0; i < 2; i++) { |
| 170 | out += snprintf(buf + out, count - out, " "); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 171 | for (j = 0; j < 8 && l < len; j++, l++) |
| 172 | out += snprintf(buf + out, count - out, "%02X ", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 173 | data[(i * 8 + j)]); |
| 174 | for (; j < 8; j++) |
| 175 | out += snprintf(buf + out, count - out, " "); |
| 176 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 177 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 178 | out += snprintf(buf + out, count - out, " "); |
| 179 | for (l = 0, i = 0; i < 2; i++) { |
| 180 | out += snprintf(buf + out, count - out, " "); |
| 181 | for (j = 0; j < 8 && l < len; j++, l++) { |
| 182 | c = data[(i * 8 + j)]; |
| 183 | if (!isascii(c) || !isprint(c)) |
| 184 | c = '.'; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 185 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 186 | out += snprintf(buf + out, count - out, "%c", c); |
| 187 | } |
| 188 | |
| 189 | for (; j < 8; j++) |
| 190 | out += snprintf(buf + out, count - out, " "); |
| 191 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 192 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 193 | return out; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 194 | } |
| 195 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 196 | static void printk_buf(int level, const u8 * data, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 197 | { |
| 198 | char line[81]; |
| 199 | u32 ofs = 0; |
| 200 | if (!(ipw_debug_level & level)) |
| 201 | return; |
| 202 | |
| 203 | while (len) { |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 204 | snprint_line(line, sizeof(line), &data[ofs], |
| 205 | min(len, 16U), ofs); |
| 206 | printk(KERN_DEBUG "%s\n", line); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 207 | ofs += 16; |
| 208 | len -= min(len, 16U); |
| 209 | } |
| 210 | } |
| 211 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 212 | static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len) |
| 213 | { |
| 214 | size_t out = size; |
| 215 | u32 ofs = 0; |
| 216 | int total = 0; |
| 217 | |
| 218 | while (size && len) { |
| 219 | out = snprint_line(output, size, &data[ofs], |
| 220 | min_t(size_t, len, 16U), ofs); |
| 221 | |
| 222 | ofs += 16; |
| 223 | output += out; |
| 224 | size -= out; |
| 225 | len -= min_t(size_t, len, 16U); |
| 226 | total += out; |
| 227 | } |
| 228 | return total; |
| 229 | } |
| 230 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 231 | /* 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] | 232 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); |
| 233 | #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) |
| 234 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 235 | /* 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] | 236 | static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); |
| 237 | #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) |
| 238 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 239 | /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 240 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); |
| 241 | static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) |
| 242 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 243 | IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, |
| 244 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 245 | _ipw_write_reg8(a, b, c); |
| 246 | } |
| 247 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 248 | /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 249 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); |
| 250 | static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) |
| 251 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 252 | IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, |
| 253 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 254 | _ipw_write_reg16(a, b, c); |
| 255 | } |
| 256 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 257 | /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 258 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); |
| 259 | static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) |
| 260 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 261 | IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, |
| 262 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 263 | _ipw_write_reg32(a, b, c); |
| 264 | } |
| 265 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 266 | /* 8-bit direct write (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 267 | #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 268 | |
| 269 | /* 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] | 270 | #define ipw_write8(ipw, ofs, val) \ |
| 271 | IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 272 | _ipw_write8(ipw, ofs, val) |
| 273 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 274 | |
| 275 | /* 16-bit direct write (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 276 | #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 277 | |
| 278 | /* 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] | 279 | #define ipw_write16(ipw, ofs, val) \ |
| 280 | IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 281 | _ipw_write16(ipw, ofs, val) |
| 282 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 283 | |
| 284 | /* 32-bit direct write (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 285 | #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 286 | |
| 287 | /* 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] | 288 | #define ipw_write32(ipw, ofs, val) \ |
| 289 | IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 290 | _ipw_write32(ipw, ofs, val) |
| 291 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 292 | |
| 293 | /* 8-bit direct read (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 294 | #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 295 | |
| 296 | /* 8-bit direct read (low 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 297 | static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 298 | { |
| 299 | 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] | 300 | return _ipw_read8(ipw, ofs); |
| 301 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 302 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 303 | /* 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] | 304 | #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs) |
| 305 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 306 | |
| 307 | /* 16-bit direct read (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 308 | #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 309 | |
| 310 | /* 16-bit direct read (low 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 311 | static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 312 | { |
| 313 | 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] | 314 | return _ipw_read16(ipw, ofs); |
| 315 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 316 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 317 | /* 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] | 318 | #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs) |
| 319 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 320 | |
| 321 | /* 32-bit direct read (low 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 322 | #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs)) |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 323 | |
| 324 | /* 32-bit direct read (low 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 325 | static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 326 | { |
| 327 | 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] | 328 | return _ipw_read32(ipw, ofs); |
| 329 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 330 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 331 | /* 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] | 332 | #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs) |
| 333 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 334 | |
| 335 | /* multi-byte read (above 4K), with debug wrapper */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 336 | static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 337 | static inline void __ipw_read_indirect(const char *f, int l, |
| 338 | struct ipw_priv *a, u32 b, u8 * c, int d) |
| 339 | { |
| 340 | IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b), |
| 341 | d); |
| 342 | _ipw_read_indirect(a, b, c, d); |
| 343 | } |
| 344 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 345 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 346 | #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] | 347 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 348 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 349 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, |
| 350 | int num); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 351 | #define ipw_write_indirect(a, b, c, d) \ |
| 352 | 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] | 353 | _ipw_write_indirect(a, b, c, d) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 354 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 355 | /* 32-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 356 | 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] | 357 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 358 | 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] | 359 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 360 | _ipw_write32(priv, IPW_INDIRECT_DATA, 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 | /* 8-bit indirect write (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 364 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) |
| 365 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 366 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
| 367 | u32 dif_len = reg - aligned_addr; |
| 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_write8(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 | /* 16-bit indirect write (above 4K) */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 375 | 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] | 376 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 377 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
| 378 | u32 dif_len = (reg - aligned_addr) & (~0x1ul); |
| 379 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 380 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 381 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
| 382 | _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 383 | } |
| 384 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 385 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 386 | /* 8-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 387 | static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) |
| 388 | { |
| 389 | u32 word; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 390 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 391 | IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 392 | word = _ipw_read32(priv, IPW_INDIRECT_DATA); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 393 | return (word >> ((reg & 0x3) * 8)) & 0xff; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 394 | } |
| 395 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 396 | /* 32-bit indirect read (above 4K) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 397 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) |
| 398 | { |
| 399 | u32 value; |
| 400 | |
| 401 | IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); |
| 402 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 403 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 404 | value = _ipw_read32(priv, IPW_INDIRECT_DATA); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 405 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); |
| 406 | return value; |
| 407 | } |
| 408 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 409 | /* General purpose, no alignment requirement, iterative (multi-byte) read, */ |
| 410 | /* for area above 1st 4K of SRAM/reg space */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 411 | static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
| 412 | int num) |
| 413 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 414 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 415 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 416 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 417 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 418 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
| 419 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 420 | if (num <= 0) { |
| 421 | return; |
| 422 | } |
| 423 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 424 | /* Read the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 425 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 426 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 427 | /* Start reading at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 428 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 429 | *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 430 | aligned_addr += 4; |
| 431 | } |
| 432 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 433 | /* Read all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 434 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 435 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 436 | *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 437 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 438 | /* Read the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 439 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 440 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 441 | for (i = 0; num > 0; i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 442 | *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 443 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 444 | } |
| 445 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 446 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 447 | /* for area above 1st 4K of SRAM/reg space */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 448 | 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] | 449 | int num) |
| 450 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 451 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 452 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 453 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 454 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 455 | 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] | 456 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 457 | if (num <= 0) { |
| 458 | return; |
| 459 | } |
| 460 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 461 | /* Write the first dword (or portion) byte by byte */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 462 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 463 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 464 | /* Start writing at aligned_addr + dif_len */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 465 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 466 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 467 | aligned_addr += 4; |
| 468 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 469 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 470 | /* Write all of the middle dwords as dwords, with auto-increment */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 471 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 472 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 473 | _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 474 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 475 | /* Write the last dword (or portion) byte by byte */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 476 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 477 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 478 | for (i = 0; num > 0; i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 479 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 480 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 481 | } |
| 482 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 483 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
| 484 | /* for 1st 4K of SRAM/regs space */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 485 | 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] | 486 | int num) |
| 487 | { |
| 488 | memcpy_toio((priv->hw_base + addr), buf, num); |
| 489 | } |
| 490 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 491 | /* Set bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 492 | static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 493 | { |
| 494 | ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); |
| 495 | } |
| 496 | |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 497 | /* Clear bit(s) in low 4K of SRAM/regs */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 498 | static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 499 | { |
| 500 | ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); |
| 501 | } |
| 502 | |
| 503 | static inline void ipw_enable_interrupts(struct ipw_priv *priv) |
| 504 | { |
| 505 | if (priv->status & STATUS_INT_ENABLED) |
| 506 | return; |
| 507 | priv->status |= STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 508 | ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static inline void ipw_disable_interrupts(struct ipw_priv *priv) |
| 512 | { |
| 513 | if (!(priv->status & STATUS_INT_ENABLED)) |
| 514 | return; |
| 515 | priv->status &= ~STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 516 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 517 | } |
| 518 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 519 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 520 | static char *ipw_error_desc(u32 val) |
| 521 | { |
| 522 | switch (val) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 523 | case IPW_FW_ERROR_OK: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 524 | return "ERROR_OK"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 525 | case IPW_FW_ERROR_FAIL: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 526 | return "ERROR_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 527 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 528 | return "MEMORY_UNDERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 529 | case IPW_FW_ERROR_MEMORY_OVERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 530 | return "MEMORY_OVERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 531 | case IPW_FW_ERROR_BAD_PARAM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 532 | return "BAD_PARAM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 533 | case IPW_FW_ERROR_BAD_CHECKSUM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 534 | return "BAD_CHECKSUM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 535 | case IPW_FW_ERROR_NMI_INTERRUPT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 536 | return "NMI_INTERRUPT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 537 | case IPW_FW_ERROR_BAD_DATABASE: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 538 | return "BAD_DATABASE"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 539 | case IPW_FW_ERROR_ALLOC_FAIL: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 540 | return "ALLOC_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 541 | case IPW_FW_ERROR_DMA_UNDERRUN: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 542 | return "DMA_UNDERRUN"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 543 | case IPW_FW_ERROR_DMA_STATUS: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 544 | return "DMA_STATUS"; |
| 545 | case IPW_FW_ERROR_DINO_ERROR: |
| 546 | return "DINO_ERROR"; |
| 547 | case IPW_FW_ERROR_EEPROM_ERROR: |
| 548 | return "EEPROM_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 549 | case IPW_FW_ERROR_SYSASSERT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 550 | return "SYSASSERT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 551 | case IPW_FW_ERROR_FATAL_ERROR: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 552 | return "FATAL_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 553 | default: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 554 | return "UNKNOWN_ERROR"; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 558 | static void ipw_dump_error_log(struct ipw_priv *priv, |
| 559 | struct ipw_fw_error *error) |
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 | u32 i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 562 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 563 | if (!error) { |
| 564 | IPW_ERROR("Error allocating and capturing error log. " |
| 565 | "Nothing to dump.\n"); |
| 566 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 567 | } |
| 568 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 569 | IPW_ERROR("Start IPW Error Log Dump:\n"); |
| 570 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", |
| 571 | error->status, error->config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 572 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 573 | for (i = 0; i < error->elem_len; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 574 | 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] | 575 | ipw_error_desc(error->elem[i].desc), |
| 576 | error->elem[i].time, |
| 577 | error->elem[i].blink1, |
| 578 | error->elem[i].blink2, |
| 579 | error->elem[i].link1, |
| 580 | error->elem[i].link2, error->elem[i].data); |
| 581 | for (i = 0; i < error->log_len; i++) |
| 582 | IPW_ERROR("%i\t0x%08x\t%i\n", |
| 583 | error->log[i].time, |
James Ketrenos | 286568a | 2005-08-30 10:34:25 -0500 | [diff] [blame] | 584 | error->log[i].data, error->log[i].event); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 585 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 586 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 587 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 588 | static inline int ipw_is_init(struct ipw_priv *priv) |
| 589 | { |
| 590 | return (priv->status & STATUS_INIT) ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 591 | } |
| 592 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 593 | 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] | 594 | { |
| 595 | u32 addr, field_info, field_len, field_count, total_len; |
| 596 | |
| 597 | IPW_DEBUG_ORD("ordinal = %i\n", ord); |
| 598 | |
| 599 | if (!priv || !val || !len) { |
| 600 | IPW_DEBUG_ORD("Invalid argument\n"); |
| 601 | return -EINVAL; |
| 602 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 603 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 604 | /* verify device ordinal tables have been initialized */ |
| 605 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { |
| 606 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); |
| 607 | return -EINVAL; |
| 608 | } |
| 609 | |
| 610 | switch (IPW_ORD_TABLE_ID_MASK & ord) { |
| 611 | case IPW_ORD_TABLE_0_MASK: |
| 612 | /* |
| 613 | * TABLE 0: Direct access to a table of 32 bit values |
| 614 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 615 | * This is a very simple table with the data directly |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 616 | * read from the table |
| 617 | */ |
| 618 | |
| 619 | /* remove the table id from the ordinal */ |
| 620 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 621 | |
| 622 | /* boundary check */ |
| 623 | if (ord > priv->table0_len) { |
| 624 | IPW_DEBUG_ORD("ordinal value (%i) longer then " |
| 625 | "max (%i)\n", ord, priv->table0_len); |
| 626 | return -EINVAL; |
| 627 | } |
| 628 | |
| 629 | /* verify we have enough room to store the value */ |
| 630 | if (*len < sizeof(u32)) { |
| 631 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 632 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 633 | return -EINVAL; |
| 634 | } |
| 635 | |
| 636 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 637 | ord, priv->table0_addr + (ord << 2)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 638 | |
| 639 | *len = sizeof(u32); |
| 640 | ord <<= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 641 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 642 | break; |
| 643 | |
| 644 | case IPW_ORD_TABLE_1_MASK: |
| 645 | /* |
| 646 | * TABLE 1: Indirect access to a table of 32 bit values |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 647 | * |
| 648 | * This is a fairly large table of u32 values each |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 649 | * representing starting addr for the data (which is |
| 650 | * also a u32) |
| 651 | */ |
| 652 | |
| 653 | /* remove the table id from the ordinal */ |
| 654 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 655 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 656 | /* boundary check */ |
| 657 | if (ord > priv->table1_len) { |
| 658 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 659 | return -EINVAL; |
| 660 | } |
| 661 | |
| 662 | /* verify we have enough room to store the value */ |
| 663 | if (*len < sizeof(u32)) { |
| 664 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 665 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 666 | return -EINVAL; |
| 667 | } |
| 668 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 669 | *((u32 *) val) = |
| 670 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 671 | *len = sizeof(u32); |
| 672 | break; |
| 673 | |
| 674 | case IPW_ORD_TABLE_2_MASK: |
| 675 | /* |
| 676 | * TABLE 2: Indirect access to a table of variable sized values |
| 677 | * |
| 678 | * This table consist of six values, each containing |
| 679 | * - dword containing the starting offset of the data |
| 680 | * - dword containing the lengh in the first 16bits |
| 681 | * and the count in the second 16bits |
| 682 | */ |
| 683 | |
| 684 | /* remove the table id from the ordinal */ |
| 685 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 686 | |
| 687 | /* boundary check */ |
| 688 | if (ord > priv->table2_len) { |
| 689 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 690 | return -EINVAL; |
| 691 | } |
| 692 | |
| 693 | /* get the address of statistic */ |
| 694 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 695 | |
| 696 | /* get the second DW of statistics ; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 697 | * two 16-bit words - first is length, second is count */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 698 | field_info = |
| 699 | ipw_read_reg32(priv, |
| 700 | priv->table2_addr + (ord << 3) + |
| 701 | sizeof(u32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 702 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 703 | /* get each entry length */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 704 | field_len = *((u16 *) & field_info); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 705 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 706 | /* get number of entries */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 707 | field_count = *(((u16 *) & field_info) + 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 708 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 709 | /* abort if not enought memory */ |
| 710 | total_len = field_len * field_count; |
| 711 | if (total_len > *len) { |
| 712 | *len = total_len; |
| 713 | return -EINVAL; |
| 714 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 715 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 716 | *len = total_len; |
| 717 | if (!total_len) |
| 718 | return 0; |
| 719 | |
| 720 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 721 | "field_info = 0x%08x\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 722 | addr, total_len, field_info); |
| 723 | ipw_read_indirect(priv, addr, val, total_len); |
| 724 | break; |
| 725 | |
| 726 | default: |
| 727 | IPW_DEBUG_ORD("Invalid ordinal!\n"); |
| 728 | return -EINVAL; |
| 729 | |
| 730 | } |
| 731 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | static void ipw_init_ordinals(struct ipw_priv *priv) |
| 736 | { |
| 737 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 738 | priv->table0_len = ipw_read32(priv, priv->table0_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 739 | |
| 740 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", |
| 741 | priv->table0_addr, priv->table0_len); |
| 742 | |
| 743 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); |
| 744 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); |
| 745 | |
| 746 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", |
| 747 | priv->table1_addr, priv->table1_len); |
| 748 | |
| 749 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); |
| 750 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 751 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 752 | |
| 753 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", |
| 754 | priv->table2_addr, priv->table2_len); |
| 755 | |
| 756 | } |
| 757 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 758 | static u32 ipw_register_toggle(u32 reg) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 759 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 760 | reg &= ~IPW_START_STANDBY; |
| 761 | if (reg & IPW_GATE_ODMA) |
| 762 | reg &= ~IPW_GATE_ODMA; |
| 763 | if (reg & IPW_GATE_IDMA) |
| 764 | reg &= ~IPW_GATE_IDMA; |
| 765 | if (reg & IPW_GATE_ADMA) |
| 766 | reg &= ~IPW_GATE_ADMA; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 767 | return reg; |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | * LED behavior: |
| 772 | * - On radio ON, turn on any LEDs that require to be on during start |
| 773 | * - On initialization, start unassociated blink |
| 774 | * - On association, disable unassociated blink |
| 775 | * - On disassociation, start unassociated blink |
| 776 | * - On radio OFF, turn off any LEDs started during radio on |
| 777 | * |
| 778 | */ |
| 779 | #define LD_TIME_LINK_ON 300 |
| 780 | #define LD_TIME_LINK_OFF 2700 |
| 781 | #define LD_TIME_ACT_ON 250 |
| 782 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 783 | static void ipw_led_link_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 784 | { |
| 785 | unsigned long flags; |
| 786 | u32 led; |
| 787 | |
| 788 | /* If configured to not use LEDs, or nic_type is 1, |
| 789 | * then we don't toggle a LINK led */ |
| 790 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 791 | return; |
| 792 | |
| 793 | spin_lock_irqsave(&priv->lock, flags); |
| 794 | |
| 795 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 796 | !(priv->status & STATUS_LED_LINK_ON)) { |
| 797 | IPW_DEBUG_LED("Link LED On\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 798 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 799 | led |= priv->led_association_on; |
| 800 | |
| 801 | led = ipw_register_toggle(led); |
| 802 | |
| 803 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 804 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 805 | |
| 806 | priv->status |= STATUS_LED_LINK_ON; |
| 807 | |
| 808 | /* If we aren't associated, schedule turning the LED off */ |
| 809 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 810 | queue_delayed_work(priv->workqueue, |
| 811 | &priv->led_link_off, |
| 812 | LD_TIME_LINK_ON); |
| 813 | } |
| 814 | |
| 815 | spin_unlock_irqrestore(&priv->lock, flags); |
| 816 | } |
| 817 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 818 | static void ipw_bg_led_link_on(void *data) |
| 819 | { |
| 820 | struct ipw_priv *priv = data; |
| 821 | down(&priv->sem); |
| 822 | ipw_led_link_on(data); |
| 823 | up(&priv->sem); |
| 824 | } |
| 825 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 826 | static void ipw_led_link_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 827 | { |
| 828 | unsigned long flags; |
| 829 | u32 led; |
| 830 | |
| 831 | /* If configured not to use LEDs, or nic type is 1, |
| 832 | * then we don't goggle the LINK led. */ |
| 833 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 834 | return; |
| 835 | |
| 836 | spin_lock_irqsave(&priv->lock, flags); |
| 837 | |
| 838 | if (priv->status & STATUS_LED_LINK_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 839 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 840 | led &= priv->led_association_off; |
| 841 | led = ipw_register_toggle(led); |
| 842 | |
| 843 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 844 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 845 | |
| 846 | IPW_DEBUG_LED("Link LED Off\n"); |
| 847 | |
| 848 | priv->status &= ~STATUS_LED_LINK_ON; |
| 849 | |
| 850 | /* If we aren't associated and the radio is on, schedule |
| 851 | * turning the LED on (blink while unassociated) */ |
| 852 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 853 | !(priv->status & STATUS_ASSOCIATED)) |
| 854 | queue_delayed_work(priv->workqueue, &priv->led_link_on, |
| 855 | LD_TIME_LINK_OFF); |
| 856 | |
| 857 | } |
| 858 | |
| 859 | spin_unlock_irqrestore(&priv->lock, flags); |
| 860 | } |
| 861 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 862 | static void ipw_bg_led_link_off(void *data) |
| 863 | { |
| 864 | struct ipw_priv *priv = data; |
| 865 | down(&priv->sem); |
| 866 | ipw_led_link_off(data); |
| 867 | up(&priv->sem); |
| 868 | } |
| 869 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 870 | static void __ipw_led_activity_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 871 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 872 | u32 led; |
| 873 | |
| 874 | if (priv->config & CFG_NO_LED) |
| 875 | return; |
| 876 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 877 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 878 | return; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 879 | |
| 880 | if (!(priv->status & STATUS_LED_ACT_ON)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 881 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 882 | led |= priv->led_activity_on; |
| 883 | |
| 884 | led = ipw_register_toggle(led); |
| 885 | |
| 886 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 887 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 888 | |
| 889 | IPW_DEBUG_LED("Activity LED On\n"); |
| 890 | |
| 891 | priv->status |= STATUS_LED_ACT_ON; |
| 892 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 893 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 894 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 895 | LD_TIME_ACT_ON); |
| 896 | } else { |
| 897 | /* Reschedule LED off for full time period */ |
| 898 | cancel_delayed_work(&priv->led_act_off); |
| 899 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 900 | LD_TIME_ACT_ON); |
| 901 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 902 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 903 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 904 | #if 0 |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 905 | void ipw_led_activity_on(struct ipw_priv *priv) |
| 906 | { |
| 907 | unsigned long flags; |
| 908 | spin_lock_irqsave(&priv->lock, flags); |
| 909 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 910 | spin_unlock_irqrestore(&priv->lock, flags); |
| 911 | } |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 912 | #endif /* 0 */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 913 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 914 | static void ipw_led_activity_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 915 | { |
| 916 | unsigned long flags; |
| 917 | u32 led; |
| 918 | |
| 919 | if (priv->config & CFG_NO_LED) |
| 920 | return; |
| 921 | |
| 922 | spin_lock_irqsave(&priv->lock, flags); |
| 923 | |
| 924 | if (priv->status & STATUS_LED_ACT_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 925 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 926 | led &= priv->led_activity_off; |
| 927 | |
| 928 | led = ipw_register_toggle(led); |
| 929 | |
| 930 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 931 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 932 | |
| 933 | IPW_DEBUG_LED("Activity LED Off\n"); |
| 934 | |
| 935 | priv->status &= ~STATUS_LED_ACT_ON; |
| 936 | } |
| 937 | |
| 938 | spin_unlock_irqrestore(&priv->lock, flags); |
| 939 | } |
| 940 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 941 | static void ipw_bg_led_activity_off(void *data) |
| 942 | { |
| 943 | struct ipw_priv *priv = data; |
| 944 | down(&priv->sem); |
| 945 | ipw_led_activity_off(data); |
| 946 | up(&priv->sem); |
| 947 | } |
| 948 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 949 | static void ipw_led_band_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 950 | { |
| 951 | unsigned long flags; |
| 952 | u32 led; |
| 953 | |
| 954 | /* Only nic type 1 supports mode LEDs */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 955 | if (priv->config & CFG_NO_LED || |
| 956 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 957 | return; |
| 958 | |
| 959 | spin_lock_irqsave(&priv->lock, flags); |
| 960 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 961 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 962 | if (priv->assoc_network->mode == IEEE_A) { |
| 963 | led |= priv->led_ofdm_on; |
| 964 | led &= priv->led_association_off; |
| 965 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); |
| 966 | } else if (priv->assoc_network->mode == IEEE_G) { |
| 967 | led |= priv->led_ofdm_on; |
| 968 | led |= priv->led_association_on; |
| 969 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); |
| 970 | } else { |
| 971 | led &= priv->led_ofdm_off; |
| 972 | led |= priv->led_association_on; |
| 973 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); |
| 974 | } |
| 975 | |
| 976 | led = ipw_register_toggle(led); |
| 977 | |
| 978 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 979 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 980 | |
| 981 | spin_unlock_irqrestore(&priv->lock, flags); |
| 982 | } |
| 983 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 984 | static void ipw_led_band_off(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 985 | { |
| 986 | unsigned long flags; |
| 987 | u32 led; |
| 988 | |
| 989 | /* Only nic type 1 supports mode LEDs */ |
| 990 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) |
| 991 | return; |
| 992 | |
| 993 | spin_lock_irqsave(&priv->lock, flags); |
| 994 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 995 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 996 | led &= priv->led_ofdm_off; |
| 997 | led &= priv->led_association_off; |
| 998 | |
| 999 | led = ipw_register_toggle(led); |
| 1000 | |
| 1001 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1002 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1003 | |
| 1004 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1005 | } |
| 1006 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1007 | static void ipw_led_radio_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1008 | { |
| 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_radio_off(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 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1018 | static void ipw_led_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1019 | { |
| 1020 | /* Set the Link Led on for all nic types */ |
| 1021 | ipw_led_link_on(priv); |
| 1022 | } |
| 1023 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1024 | static void ipw_led_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1025 | { |
| 1026 | ipw_led_activity_off(priv); |
| 1027 | ipw_led_link_off(priv); |
| 1028 | |
| 1029 | if (priv->status & STATUS_RF_KILL_MASK) |
| 1030 | ipw_led_radio_off(priv); |
| 1031 | } |
| 1032 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1033 | static void ipw_led_init(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1034 | { |
| 1035 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; |
| 1036 | |
| 1037 | /* Set the default PINs for the link and activity leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1038 | priv->led_activity_on = IPW_ACTIVITY_LED; |
| 1039 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1040 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1041 | priv->led_association_on = IPW_ASSOCIATED_LED; |
| 1042 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1043 | |
| 1044 | /* Set the default PINs for the OFDM leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1045 | priv->led_ofdm_on = IPW_OFDM_LED; |
| 1046 | priv->led_ofdm_off = ~(IPW_OFDM_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1047 | |
| 1048 | switch (priv->nic_type) { |
| 1049 | case EEPROM_NIC_TYPE_1: |
| 1050 | /* In this NIC type, the LEDs are reversed.... */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1051 | priv->led_activity_on = IPW_ASSOCIATED_LED; |
| 1052 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); |
| 1053 | priv->led_association_on = IPW_ACTIVITY_LED; |
| 1054 | priv->led_association_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1055 | |
| 1056 | if (!(priv->config & CFG_NO_LED)) |
| 1057 | ipw_led_band_on(priv); |
| 1058 | |
| 1059 | /* And we don't blink link LEDs for this nic, so |
| 1060 | * just return here */ |
| 1061 | return; |
| 1062 | |
| 1063 | case EEPROM_NIC_TYPE_3: |
| 1064 | case EEPROM_NIC_TYPE_2: |
| 1065 | case EEPROM_NIC_TYPE_4: |
| 1066 | case EEPROM_NIC_TYPE_0: |
| 1067 | break; |
| 1068 | |
| 1069 | default: |
| 1070 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", |
| 1071 | priv->nic_type); |
| 1072 | priv->nic_type = EEPROM_NIC_TYPE_0; |
| 1073 | break; |
| 1074 | } |
| 1075 | |
| 1076 | if (!(priv->config & CFG_NO_LED)) { |
| 1077 | if (priv->status & STATUS_ASSOCIATED) |
| 1078 | ipw_led_link_on(priv); |
| 1079 | else |
| 1080 | ipw_led_link_off(priv); |
| 1081 | } |
| 1082 | } |
| 1083 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 1084 | static void ipw_led_shutdown(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1085 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1086 | ipw_led_activity_off(priv); |
| 1087 | ipw_led_link_off(priv); |
| 1088 | ipw_led_band_off(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1089 | cancel_delayed_work(&priv->led_link_on); |
| 1090 | cancel_delayed_work(&priv->led_link_off); |
| 1091 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1092 | } |
| 1093 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1094 | /* |
| 1095 | * The following adds a new attribute to the sysfs representation |
| 1096 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) |
| 1097 | * used for controling the debug level. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1098 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1099 | * See the level definitions in ipw for details. |
| 1100 | */ |
| 1101 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 1102 | { |
| 1103 | return sprintf(buf, "0x%08X\n", ipw_debug_level); |
| 1104 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1105 | |
| 1106 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, |
| 1107 | size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1108 | { |
| 1109 | char *p = (char *)buf; |
| 1110 | u32 val; |
| 1111 | |
| 1112 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1113 | p++; |
| 1114 | if (p[0] == 'x' || p[0] == 'X') |
| 1115 | p++; |
| 1116 | val = simple_strtoul(p, &p, 16); |
| 1117 | } else |
| 1118 | val = simple_strtoul(p, &p, 10); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1119 | if (p == buf) |
| 1120 | printk(KERN_INFO DRV_NAME |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1121 | ": %s is not in hex or decimal form.\n", buf); |
| 1122 | else |
| 1123 | ipw_debug_level = val; |
| 1124 | |
| 1125 | return strnlen(buf, count); |
| 1126 | } |
| 1127 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1128 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1129 | show_debug_level, store_debug_level); |
| 1130 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1131 | static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) |
| 1132 | { |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 1133 | /* length = 1st dword in log */ |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1134 | return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); |
| 1135 | } |
| 1136 | |
| 1137 | static void ipw_capture_event_log(struct ipw_priv *priv, |
| 1138 | u32 log_len, struct ipw_event *log) |
| 1139 | { |
| 1140 | u32 base; |
| 1141 | |
| 1142 | if (log_len) { |
| 1143 | base = ipw_read32(priv, IPW_EVENT_LOG); |
| 1144 | ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), |
| 1145 | (u8 *) log, sizeof(*log) * log_len); |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) |
| 1150 | { |
| 1151 | struct ipw_fw_error *error; |
| 1152 | u32 log_len = ipw_get_event_log_len(priv); |
| 1153 | u32 base = ipw_read32(priv, IPW_ERROR_LOG); |
| 1154 | u32 elem_len = ipw_read_reg32(priv, base); |
| 1155 | |
| 1156 | error = kmalloc(sizeof(*error) + |
| 1157 | sizeof(*error->elem) * elem_len + |
| 1158 | sizeof(*error->log) * log_len, GFP_ATOMIC); |
| 1159 | if (!error) { |
| 1160 | IPW_ERROR("Memory allocation for firmware error log " |
| 1161 | "failed.\n"); |
| 1162 | return NULL; |
| 1163 | } |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1164 | error->jiffies = jiffies; |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1165 | error->status = priv->status; |
| 1166 | error->config = priv->config; |
| 1167 | error->elem_len = elem_len; |
| 1168 | error->log_len = log_len; |
| 1169 | error->elem = (struct ipw_error_elem *)error->payload; |
Zhu Yi | 3b26b11 | 2005-11-17 13:58:30 +0800 | [diff] [blame] | 1170 | error->log = (struct ipw_event *)(error->elem + elem_len); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1171 | |
| 1172 | ipw_capture_event_log(priv, log_len, error->log); |
| 1173 | |
| 1174 | if (elem_len) |
| 1175 | ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, |
| 1176 | sizeof(*error->elem) * elem_len); |
| 1177 | |
| 1178 | return error; |
| 1179 | } |
| 1180 | |
| 1181 | static void ipw_free_error_log(struct ipw_fw_error *error) |
| 1182 | { |
| 1183 | if (error) |
| 1184 | kfree(error); |
| 1185 | } |
| 1186 | |
| 1187 | static ssize_t show_event_log(struct device *d, |
| 1188 | struct device_attribute *attr, char *buf) |
| 1189 | { |
| 1190 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1191 | u32 log_len = ipw_get_event_log_len(priv); |
| 1192 | struct ipw_event log[log_len]; |
| 1193 | u32 len = 0, i; |
| 1194 | |
| 1195 | ipw_capture_event_log(priv, log_len, log); |
| 1196 | |
| 1197 | len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); |
| 1198 | for (i = 0; i < log_len; i++) |
| 1199 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1200 | "\n%08X%08X%08X", |
| 1201 | log[i].time, log[i].event, log[i].data); |
| 1202 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1203 | return len; |
| 1204 | } |
| 1205 | |
| 1206 | static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL); |
| 1207 | |
| 1208 | static ssize_t show_error(struct device *d, |
| 1209 | struct device_attribute *attr, char *buf) |
| 1210 | { |
| 1211 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1212 | u32 len = 0, i; |
| 1213 | if (!priv->error) |
| 1214 | return 0; |
| 1215 | len += snprintf(buf + len, PAGE_SIZE - len, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1216 | "%08lX%08X%08X%08X", |
| 1217 | priv->error->jiffies, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1218 | priv->error->status, |
| 1219 | priv->error->config, priv->error->elem_len); |
| 1220 | for (i = 0; i < priv->error->elem_len; i++) |
| 1221 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1222 | "\n%08X%08X%08X%08X%08X%08X%08X", |
| 1223 | priv->error->elem[i].time, |
| 1224 | priv->error->elem[i].desc, |
| 1225 | priv->error->elem[i].blink1, |
| 1226 | priv->error->elem[i].blink2, |
| 1227 | priv->error->elem[i].link1, |
| 1228 | priv->error->elem[i].link2, |
| 1229 | priv->error->elem[i].data); |
| 1230 | |
| 1231 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1232 | "\n%08X", priv->error->log_len); |
| 1233 | for (i = 0; i < priv->error->log_len; i++) |
| 1234 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 1235 | "\n%08X%08X%08X", |
| 1236 | priv->error->log[i].time, |
| 1237 | priv->error->log[i].event, |
| 1238 | priv->error->log[i].data); |
| 1239 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1240 | return len; |
| 1241 | } |
| 1242 | |
| 1243 | static ssize_t clear_error(struct device *d, |
| 1244 | struct device_attribute *attr, |
| 1245 | const char *buf, size_t count) |
| 1246 | { |
| 1247 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1248 | if (priv->error) { |
| 1249 | ipw_free_error_log(priv->error); |
| 1250 | priv->error = NULL; |
| 1251 | } |
| 1252 | return count; |
| 1253 | } |
| 1254 | |
| 1255 | static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error); |
| 1256 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1257 | static ssize_t show_cmd_log(struct device *d, |
| 1258 | struct device_attribute *attr, char *buf) |
| 1259 | { |
| 1260 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1261 | u32 len = 0, i; |
| 1262 | if (!priv->cmdlog) |
| 1263 | return 0; |
| 1264 | for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; |
| 1265 | (i != priv->cmdlog_pos) && (PAGE_SIZE - len); |
| 1266 | i = (i + 1) % priv->cmdlog_len) { |
| 1267 | len += |
| 1268 | snprintf(buf + len, PAGE_SIZE - len, |
| 1269 | "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, |
| 1270 | priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, |
| 1271 | priv->cmdlog[i].cmd.len); |
| 1272 | len += |
| 1273 | snprintk_buf(buf + len, PAGE_SIZE - len, |
| 1274 | (u8 *) priv->cmdlog[i].cmd.param, |
| 1275 | priv->cmdlog[i].cmd.len); |
| 1276 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1277 | } |
| 1278 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 1279 | return len; |
| 1280 | } |
| 1281 | |
| 1282 | static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL); |
| 1283 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1284 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
| 1285 | char *buf) |
| 1286 | { |
| 1287 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1288 | return sprintf(buf, "%d\n", priv->ieee->scan_age); |
| 1289 | } |
| 1290 | |
| 1291 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, |
| 1292 | const char *buf, size_t count) |
| 1293 | { |
| 1294 | struct ipw_priv *priv = dev_get_drvdata(d); |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 1295 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1296 | struct net_device *dev = priv->net_dev; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1297 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1298 | char buffer[] = "00000000"; |
| 1299 | unsigned long len = |
| 1300 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; |
| 1301 | unsigned long val; |
| 1302 | char *p = buffer; |
| 1303 | |
| 1304 | IPW_DEBUG_INFO("enter\n"); |
| 1305 | |
| 1306 | strncpy(buffer, buf, len); |
| 1307 | buffer[len] = 0; |
| 1308 | |
| 1309 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1310 | p++; |
| 1311 | if (p[0] == 'x' || p[0] == 'X') |
| 1312 | p++; |
| 1313 | val = simple_strtoul(p, &p, 16); |
| 1314 | } else |
| 1315 | val = simple_strtoul(p, &p, 10); |
| 1316 | if (p == buffer) { |
| 1317 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); |
| 1318 | } else { |
| 1319 | priv->ieee->scan_age = val; |
| 1320 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); |
| 1321 | } |
| 1322 | |
| 1323 | IPW_DEBUG_INFO("exit\n"); |
| 1324 | return len; |
| 1325 | } |
| 1326 | |
| 1327 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); |
| 1328 | |
| 1329 | static ssize_t show_led(struct device *d, struct device_attribute *attr, |
| 1330 | char *buf) |
| 1331 | { |
| 1332 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1333 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); |
| 1334 | } |
| 1335 | |
| 1336 | static ssize_t store_led(struct device *d, struct device_attribute *attr, |
| 1337 | const char *buf, size_t count) |
| 1338 | { |
| 1339 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1340 | |
| 1341 | IPW_DEBUG_INFO("enter\n"); |
| 1342 | |
| 1343 | if (count == 0) |
| 1344 | return 0; |
| 1345 | |
| 1346 | if (*buf == 0) { |
| 1347 | IPW_DEBUG_LED("Disabling LED control.\n"); |
| 1348 | priv->config |= CFG_NO_LED; |
| 1349 | ipw_led_shutdown(priv); |
| 1350 | } else { |
| 1351 | IPW_DEBUG_LED("Enabling LED control.\n"); |
| 1352 | priv->config &= ~CFG_NO_LED; |
| 1353 | ipw_led_init(priv); |
| 1354 | } |
| 1355 | |
| 1356 | IPW_DEBUG_INFO("exit\n"); |
| 1357 | return count; |
| 1358 | } |
| 1359 | |
| 1360 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); |
| 1361 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1362 | static ssize_t show_status(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1363 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1364 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1365 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1366 | return sprintf(buf, "0x%08x\n", (int)p->status); |
| 1367 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1368 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1369 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 1370 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1371 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
| 1372 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1373 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1374 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1375 | return sprintf(buf, "0x%08x\n", (int)p->config); |
| 1376 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1377 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1378 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); |
| 1379 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1380 | static ssize_t show_nic_type(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1381 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1382 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1383 | struct ipw_priv *priv = d->driver_data; |
| 1384 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1385 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1386 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1387 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); |
| 1388 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1389 | static ssize_t show_ucode_version(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1390 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1391 | { |
| 1392 | u32 len = sizeof(u32), tmp = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1393 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1394 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1395 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1396 | return 0; |
| 1397 | |
| 1398 | return sprintf(buf, "0x%08x\n", tmp); |
| 1399 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1400 | |
| 1401 | 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] | 1402 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1403 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, |
| 1404 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1405 | { |
| 1406 | u32 len = sizeof(u32), tmp = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1407 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1408 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1409 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1410 | return 0; |
| 1411 | |
| 1412 | return sprintf(buf, "0x%08x\n", tmp); |
| 1413 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1414 | |
| 1415 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1416 | |
| 1417 | /* |
| 1418 | * Add a device attribute to view/control the delay between eeprom |
| 1419 | * operations. |
| 1420 | */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1421 | static ssize_t show_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1422 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1423 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1424 | int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1425 | return sprintf(buf, "%i\n", n); |
| 1426 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1427 | static ssize_t store_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1428 | struct device_attribute *attr, |
| 1429 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1430 | { |
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 | sscanf(buf, "%i", &p->eeprom_delay); |
| 1433 | return strnlen(buf, count); |
| 1434 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1435 | |
| 1436 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, |
| 1437 | show_eeprom_delay, store_eeprom_delay); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1438 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1439 | static ssize_t show_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1440 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1441 | { |
| 1442 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1443 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1444 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1445 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1446 | return sprintf(buf, "0x%08x\n", reg); |
| 1447 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1448 | static ssize_t store_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1449 | struct device_attribute *attr, |
| 1450 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1451 | { |
| 1452 | u32 reg; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1453 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1454 | |
| 1455 | sscanf(buf, "%x", ®); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1456 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1457 | return strnlen(buf, count); |
| 1458 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1459 | |
| 1460 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, |
| 1461 | show_command_event_reg, store_command_event_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1462 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1463 | static ssize_t show_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1464 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1465 | { |
| 1466 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1467 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1468 | |
| 1469 | reg = ipw_read_reg32(p, 0x301100); |
| 1470 | return sprintf(buf, "0x%08x\n", reg); |
| 1471 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1472 | static ssize_t store_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1473 | struct device_attribute *attr, |
| 1474 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1475 | { |
| 1476 | u32 reg; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1477 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1478 | |
| 1479 | sscanf(buf, "%x", ®); |
| 1480 | ipw_write_reg32(p, 0x301100, reg); |
| 1481 | return strnlen(buf, count); |
| 1482 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1483 | |
| 1484 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, |
| 1485 | show_mem_gpio_reg, store_mem_gpio_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1486 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1487 | static ssize_t show_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1488 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1489 | { |
| 1490 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1491 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1492 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1493 | if (priv->status & STATUS_INDIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1494 | reg = ipw_read_reg32(priv, priv->indirect_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1495 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1496 | reg = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1497 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1498 | return sprintf(buf, "0x%08x\n", reg); |
| 1499 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1500 | static ssize_t store_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1501 | struct device_attribute *attr, |
| 1502 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1503 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1504 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1505 | |
| 1506 | sscanf(buf, "%x", &priv->indirect_dword); |
| 1507 | priv->status |= STATUS_INDIRECT_DWORD; |
| 1508 | return strnlen(buf, count); |
| 1509 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1510 | |
| 1511 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, |
| 1512 | show_indirect_dword, store_indirect_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1513 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1514 | static ssize_t show_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1515 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1516 | { |
| 1517 | u8 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1518 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1519 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1520 | if (priv->status & STATUS_INDIRECT_BYTE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1521 | reg = ipw_read_reg8(priv, priv->indirect_byte); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1522 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1523 | reg = 0; |
| 1524 | |
| 1525 | return sprintf(buf, "0x%02x\n", reg); |
| 1526 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1527 | static ssize_t store_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1528 | struct device_attribute *attr, |
| 1529 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1530 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1531 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1532 | |
| 1533 | sscanf(buf, "%x", &priv->indirect_byte); |
| 1534 | priv->status |= STATUS_INDIRECT_BYTE; |
| 1535 | return strnlen(buf, count); |
| 1536 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1537 | |
| 1538 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1539 | show_indirect_byte, store_indirect_byte); |
| 1540 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1541 | static ssize_t show_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1542 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1543 | { |
| 1544 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1545 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1546 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1547 | if (priv->status & STATUS_DIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1548 | reg = ipw_read32(priv, priv->direct_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1549 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1550 | reg = 0; |
| 1551 | |
| 1552 | return sprintf(buf, "0x%08x\n", reg); |
| 1553 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1554 | static ssize_t store_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1555 | struct device_attribute *attr, |
| 1556 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1557 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1558 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1559 | |
| 1560 | sscanf(buf, "%x", &priv->direct_dword); |
| 1561 | priv->status |= STATUS_DIRECT_DWORD; |
| 1562 | return strnlen(buf, count); |
| 1563 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1564 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1565 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, |
| 1566 | show_direct_dword, store_direct_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1567 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1568 | static int rf_kill_active(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1569 | { |
| 1570 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) |
| 1571 | priv->status |= STATUS_RF_KILL_HW; |
| 1572 | else |
| 1573 | priv->status &= ~STATUS_RF_KILL_HW; |
| 1574 | |
| 1575 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; |
| 1576 | } |
| 1577 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1578 | 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] | 1579 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1580 | { |
| 1581 | /* 0 - RF kill not enabled |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1582 | 1 - SW based RF kill active (sysfs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1583 | 2 - HW based RF kill active |
| 1584 | 3 - Both HW and SW baed RF kill active */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1585 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1586 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1587 | (rf_kill_active(priv) ? 0x2 : 0x0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1588 | return sprintf(buf, "%i\n", val); |
| 1589 | } |
| 1590 | |
| 1591 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) |
| 1592 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1593 | if ((disable_radio ? 1 : 0) == |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1594 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1595 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1596 | |
| 1597 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", |
| 1598 | disable_radio ? "OFF" : "ON"); |
| 1599 | |
| 1600 | if (disable_radio) { |
| 1601 | priv->status |= STATUS_RF_KILL_SW; |
| 1602 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1603 | if (priv->workqueue) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1604 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1605 | queue_work(priv->workqueue, &priv->down); |
| 1606 | } else { |
| 1607 | priv->status &= ~STATUS_RF_KILL_SW; |
| 1608 | if (rf_kill_active(priv)) { |
| 1609 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1610 | "disabled by HW switch\n"); |
| 1611 | /* Make sure the RF_KILL check timer is running */ |
| 1612 | cancel_delayed_work(&priv->rf_kill); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1613 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1614 | 2 * HZ); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1615 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1616 | queue_work(priv->workqueue, &priv->up); |
| 1617 | } |
| 1618 | |
| 1619 | return 1; |
| 1620 | } |
| 1621 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1622 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
| 1623 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1624 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1625 | struct ipw_priv *priv = d->driver_data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1626 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1627 | ipw_radio_kill_sw(priv, buf[0] == '1'); |
| 1628 | |
| 1629 | return count; |
| 1630 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1631 | |
| 1632 | 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] | 1633 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1634 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, |
| 1635 | char *buf) |
| 1636 | { |
| 1637 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1638 | int pos = 0, len = 0; |
| 1639 | if (priv->config & CFG_SPEED_SCAN) { |
| 1640 | while (priv->speed_scan[pos] != 0) |
| 1641 | len += sprintf(&buf[len], "%d ", |
| 1642 | priv->speed_scan[pos++]); |
| 1643 | return len + sprintf(&buf[len], "\n"); |
| 1644 | } |
| 1645 | |
| 1646 | return sprintf(buf, "0\n"); |
| 1647 | } |
| 1648 | |
| 1649 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, |
| 1650 | const char *buf, size_t count) |
| 1651 | { |
| 1652 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1653 | int channel, pos = 0; |
| 1654 | const char *p = buf; |
| 1655 | |
| 1656 | /* list of space separated channels to scan, optionally ending with 0 */ |
| 1657 | while ((channel = simple_strtol(p, NULL, 0))) { |
| 1658 | if (pos == MAX_SPEED_SCAN - 1) { |
| 1659 | priv->speed_scan[pos] = 0; |
| 1660 | break; |
| 1661 | } |
| 1662 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 1663 | if (ipw_is_valid_channel(priv->ieee, channel)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1664 | priv->speed_scan[pos++] = channel; |
| 1665 | else |
| 1666 | IPW_WARNING("Skipping invalid channel request: %d\n", |
| 1667 | channel); |
| 1668 | p = strchr(p, ' '); |
| 1669 | if (!p) |
| 1670 | break; |
| 1671 | while (*p == ' ' || *p == '\t') |
| 1672 | p++; |
| 1673 | } |
| 1674 | |
| 1675 | if (pos == 0) |
| 1676 | priv->config &= ~CFG_SPEED_SCAN; |
| 1677 | else { |
| 1678 | priv->speed_scan_pos = 0; |
| 1679 | priv->config |= CFG_SPEED_SCAN; |
| 1680 | } |
| 1681 | |
| 1682 | return count; |
| 1683 | } |
| 1684 | |
| 1685 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, |
| 1686 | store_speed_scan); |
| 1687 | |
| 1688 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, |
| 1689 | char *buf) |
| 1690 | { |
| 1691 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1692 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); |
| 1693 | } |
| 1694 | |
| 1695 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, |
| 1696 | const char *buf, size_t count) |
| 1697 | { |
| 1698 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1699 | if (buf[0] == '1') |
| 1700 | priv->config |= CFG_NET_STATS; |
| 1701 | else |
| 1702 | priv->config &= ~CFG_NET_STATS; |
| 1703 | |
| 1704 | return count; |
| 1705 | } |
| 1706 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1707 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, |
| 1708 | show_net_stats, store_net_stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1709 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1710 | static void notify_wx_assoc_event(struct ipw_priv *priv) |
| 1711 | { |
| 1712 | union iwreq_data wrqu; |
| 1713 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1714 | if (priv->status & STATUS_ASSOCIATED) |
| 1715 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); |
| 1716 | else |
| 1717 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 1718 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); |
| 1719 | } |
| 1720 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1721 | static void ipw_irq_tasklet(struct ipw_priv *priv) |
| 1722 | { |
| 1723 | u32 inta, inta_mask, handled = 0; |
| 1724 | unsigned long flags; |
| 1725 | int rc = 0; |
| 1726 | |
| 1727 | spin_lock_irqsave(&priv->lock, flags); |
| 1728 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1729 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 1730 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
| 1731 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1732 | |
| 1733 | /* Add any cached INTA values that need to be handled */ |
| 1734 | inta |= priv->isr_inta; |
| 1735 | |
| 1736 | /* handle all the justifications for the interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1737 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1738 | ipw_rx(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1739 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1740 | } |
| 1741 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1742 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1743 | IPW_DEBUG_HC("Command completed.\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1744 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1745 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1746 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1747 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
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_1) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1751 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1752 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1753 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
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_2) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1757 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1758 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1759 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
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_TX_QUEUE_3) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1763 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1764 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1765 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1766 | } |
| 1767 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1768 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1769 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1770 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1771 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1772 | } |
| 1773 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1774 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1775 | IPW_WARNING("STATUS_CHANGE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1776 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1777 | } |
| 1778 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1779 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1780 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1781 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1782 | } |
| 1783 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1784 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1785 | IPW_WARNING("HOST_CMD_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1786 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1787 | } |
| 1788 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1789 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1790 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1791 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1792 | } |
| 1793 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1794 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1795 | IPW_WARNING("PHY_OFF_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1796 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1797 | } |
| 1798 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1799 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1800 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
| 1801 | priv->status |= STATUS_RF_KILL_HW; |
| 1802 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1803 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1804 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1805 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1806 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1807 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1808 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1809 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1810 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1811 | IPW_ERROR("Firmware error detected. Restarting.\n"); |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1812 | if (priv->error) { |
| 1813 | IPW_ERROR("Sysfs 'error' log already exists.\n"); |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 1814 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1815 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
| 1816 | struct ipw_fw_error *error = |
| 1817 | ipw_alloc_error_log(priv); |
| 1818 | ipw_dump_error_log(priv, error); |
| 1819 | if (error) |
| 1820 | ipw_free_error_log(error); |
| 1821 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1822 | #endif |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1823 | } else { |
| 1824 | priv->error = ipw_alloc_error_log(priv); |
| 1825 | if (priv->error) |
| 1826 | IPW_ERROR("Sysfs 'error' log captured.\n"); |
| 1827 | else |
| 1828 | IPW_ERROR("Error allocating sysfs 'error' " |
| 1829 | "log.\n"); |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 1830 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 1831 | if (ipw_debug_level & IPW_DL_FW_ERRORS) |
| 1832 | ipw_dump_error_log(priv, priv->error); |
| 1833 | #endif |
| 1834 | } |
| 1835 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1836 | /* XXX: If hardware encryption is for WPA/WPA2, |
| 1837 | * we have to notify the supplicant. */ |
| 1838 | if (priv->ieee->sec.encrypt) { |
| 1839 | priv->status &= ~STATUS_ASSOCIATED; |
| 1840 | notify_wx_assoc_event(priv); |
| 1841 | } |
| 1842 | |
| 1843 | /* Keep the restart process from trying to send host |
| 1844 | * commands by clearing the INIT status bit */ |
| 1845 | priv->status &= ~STATUS_INIT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1846 | |
| 1847 | /* Cancel currently queued command. */ |
| 1848 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1849 | wake_up_interruptible(&priv->wait_command_queue); |
| 1850 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1851 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1852 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1853 | } |
| 1854 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1855 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1856 | IPW_ERROR("Parity error\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1857 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | if (handled != inta) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1861 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | /* enable all interrupts */ |
| 1865 | ipw_enable_interrupts(priv); |
| 1866 | |
| 1867 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1868 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1869 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1870 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
| 1871 | static char *get_cmd_string(u8 cmd) |
| 1872 | { |
| 1873 | switch (cmd) { |
| 1874 | IPW_CMD(HOST_COMPLETE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1875 | IPW_CMD(POWER_DOWN); |
| 1876 | IPW_CMD(SYSTEM_CONFIG); |
| 1877 | IPW_CMD(MULTICAST_ADDRESS); |
| 1878 | IPW_CMD(SSID); |
| 1879 | IPW_CMD(ADAPTER_ADDRESS); |
| 1880 | IPW_CMD(PORT_TYPE); |
| 1881 | IPW_CMD(RTS_THRESHOLD); |
| 1882 | IPW_CMD(FRAG_THRESHOLD); |
| 1883 | IPW_CMD(POWER_MODE); |
| 1884 | IPW_CMD(WEP_KEY); |
| 1885 | IPW_CMD(TGI_TX_KEY); |
| 1886 | IPW_CMD(SCAN_REQUEST); |
| 1887 | IPW_CMD(SCAN_REQUEST_EXT); |
| 1888 | IPW_CMD(ASSOCIATE); |
| 1889 | IPW_CMD(SUPPORTED_RATES); |
| 1890 | IPW_CMD(SCAN_ABORT); |
| 1891 | IPW_CMD(TX_FLUSH); |
| 1892 | IPW_CMD(QOS_PARAMETERS); |
| 1893 | IPW_CMD(DINO_CONFIG); |
| 1894 | IPW_CMD(RSN_CAPABILITIES); |
| 1895 | IPW_CMD(RX_KEY); |
| 1896 | IPW_CMD(CARD_DISABLE); |
| 1897 | IPW_CMD(SEED_NUMBER); |
| 1898 | IPW_CMD(TX_POWER); |
| 1899 | IPW_CMD(COUNTRY_INFO); |
| 1900 | IPW_CMD(AIRONET_INFO); |
| 1901 | IPW_CMD(AP_TX_POWER); |
| 1902 | IPW_CMD(CCKM_INFO); |
| 1903 | IPW_CMD(CCX_VER_INFO); |
| 1904 | IPW_CMD(SET_CALIBRATION); |
| 1905 | IPW_CMD(SENSITIVITY_CALIB); |
| 1906 | IPW_CMD(RETRY_LIMIT); |
| 1907 | IPW_CMD(IPW_PRE_POWER_DOWN); |
| 1908 | IPW_CMD(VAP_BEACON_TEMPLATE); |
| 1909 | IPW_CMD(VAP_DTIM_PERIOD); |
| 1910 | IPW_CMD(EXT_SUPPORTED_RATES); |
| 1911 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); |
| 1912 | IPW_CMD(VAP_QUIET_INTERVALS); |
| 1913 | IPW_CMD(VAP_CHANNEL_SWITCH); |
| 1914 | IPW_CMD(VAP_MANDATORY_CHANNELS); |
| 1915 | IPW_CMD(VAP_CELL_PWR_LIMIT); |
| 1916 | IPW_CMD(VAP_CF_PARAM_SET); |
| 1917 | IPW_CMD(VAP_SET_BEACONING_STATE); |
| 1918 | IPW_CMD(MEASUREMENT); |
| 1919 | IPW_CMD(POWER_CAPABILITY); |
| 1920 | IPW_CMD(SUPPORTED_CHANNELS); |
| 1921 | IPW_CMD(TPC_REPORT); |
| 1922 | IPW_CMD(WME_INFO); |
| 1923 | IPW_CMD(PRODUCTION_COMMAND); |
| 1924 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1925 | return "UNKNOWN"; |
| 1926 | } |
| 1927 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1928 | |
| 1929 | #define HOST_COMPLETE_TIMEOUT HZ |
| 1930 | static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd) |
| 1931 | { |
| 1932 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1933 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1934 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1935 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1936 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 1937 | IPW_ERROR("Failed to send %s: Already sending a command.\n", |
| 1938 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1939 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 1940 | return -EAGAIN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | priv->status |= STATUS_HCMD_ACTIVE; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1944 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1945 | if (priv->cmdlog) { |
| 1946 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; |
| 1947 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; |
| 1948 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; |
| 1949 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, |
| 1950 | cmd->len); |
| 1951 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; |
| 1952 | } |
| 1953 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1954 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
| 1955 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, |
| 1956 | priv->status); |
Zhu Yi | f516dbc | 2006-01-24 16:36:44 +0800 | [diff] [blame] | 1957 | |
| 1958 | #ifndef DEBUG_CMD_WEP_KEY |
| 1959 | if (cmd->cmd == IPW_CMD_WEP_KEY) |
| 1960 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); |
| 1961 | else |
| 1962 | #endif |
| 1963 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); |
| 1964 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1965 | |
| 1966 | 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] | 1967 | if (rc) { |
| 1968 | priv->status &= ~STATUS_HCMD_ACTIVE; |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 1969 | IPW_ERROR("Failed to send %s: Reason %d\n", |
| 1970 | get_cmd_string(cmd->cmd), rc); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1971 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1972 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1973 | } |
| 1974 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1975 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1976 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 1977 | !(priv-> |
| 1978 | status & STATUS_HCMD_ACTIVE), |
| 1979 | HOST_COMPLETE_TIMEOUT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1980 | if (rc == 0) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1981 | spin_lock_irqsave(&priv->lock, flags); |
| 1982 | if (priv->status & STATUS_HCMD_ACTIVE) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 1983 | IPW_ERROR("Failed to send %s: Command timed out.\n", |
| 1984 | get_cmd_string(cmd->cmd)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1985 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1986 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1987 | rc = -EIO; |
| 1988 | goto exit; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1989 | } |
| 1990 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 1991 | } else |
| 1992 | rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1993 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1994 | if (priv->status & STATUS_RF_KILL_HW) { |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 1995 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", |
| 1996 | get_cmd_string(cmd->cmd)); |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 1997 | rc = -EIO; |
| 1998 | goto exit; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1999 | } |
| 2000 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 2001 | exit: |
| 2002 | if (priv->cmdlog) { |
| 2003 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; |
| 2004 | priv->cmdlog_pos %= priv->cmdlog_len; |
| 2005 | } |
| 2006 | return rc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | static int ipw_send_host_complete(struct ipw_priv *priv) |
| 2010 | { |
| 2011 | struct host_cmd cmd = { |
| 2012 | .cmd = IPW_CMD_HOST_COMPLETE, |
| 2013 | .len = 0 |
| 2014 | }; |
| 2015 | |
| 2016 | if (!priv) { |
| 2017 | IPW_ERROR("Invalid args\n"); |
| 2018 | return -1; |
| 2019 | } |
| 2020 | |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2021 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2022 | } |
| 2023 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2024 | static int ipw_send_system_config(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2025 | struct ipw_sys_config *config) |
| 2026 | { |
| 2027 | struct host_cmd cmd = { |
| 2028 | .cmd = IPW_CMD_SYSTEM_CONFIG, |
| 2029 | .len = sizeof(*config) |
| 2030 | }; |
| 2031 | |
| 2032 | if (!priv || !config) { |
| 2033 | IPW_ERROR("Invalid args\n"); |
| 2034 | return -1; |
| 2035 | } |
| 2036 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2037 | memcpy(cmd.param, config, sizeof(*config)); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2038 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2039 | } |
| 2040 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2041 | 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] | 2042 | { |
| 2043 | struct host_cmd cmd = { |
| 2044 | .cmd = IPW_CMD_SSID, |
| 2045 | .len = min(len, IW_ESSID_MAX_SIZE) |
| 2046 | }; |
| 2047 | |
| 2048 | if (!priv || !ssid) { |
| 2049 | IPW_ERROR("Invalid args\n"); |
| 2050 | return -1; |
| 2051 | } |
| 2052 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2053 | memcpy(cmd.param, ssid, cmd.len); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2054 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2055 | } |
| 2056 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2057 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2058 | { |
| 2059 | struct host_cmd cmd = { |
| 2060 | .cmd = IPW_CMD_ADAPTER_ADDRESS, |
| 2061 | .len = ETH_ALEN |
| 2062 | }; |
| 2063 | |
| 2064 | if (!priv || !mac) { |
| 2065 | IPW_ERROR("Invalid args\n"); |
| 2066 | return -1; |
| 2067 | } |
| 2068 | |
| 2069 | IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n", |
| 2070 | priv->net_dev->name, MAC_ARG(mac)); |
| 2071 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2072 | memcpy(cmd.param, mac, ETH_ALEN); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2073 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2074 | } |
| 2075 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2076 | /* |
| 2077 | * NOTE: This must be executed from our workqueue as it results in udelay |
| 2078 | * being called which may corrupt the keyboard if executed on default |
| 2079 | * workqueue |
| 2080 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2081 | static void ipw_adapter_restart(void *adapter) |
| 2082 | { |
| 2083 | struct ipw_priv *priv = adapter; |
| 2084 | |
| 2085 | if (priv->status & STATUS_RF_KILL_MASK) |
| 2086 | return; |
| 2087 | |
| 2088 | ipw_down(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2089 | |
| 2090 | if (priv->assoc_network && |
| 2091 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) |
| 2092 | ipw_remove_current_network(priv); |
| 2093 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2094 | if (ipw_up(priv)) { |
| 2095 | IPW_ERROR("Failed to up device\n"); |
| 2096 | return; |
| 2097 | } |
| 2098 | } |
| 2099 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2100 | static void ipw_bg_adapter_restart(void *data) |
| 2101 | { |
| 2102 | struct ipw_priv *priv = data; |
| 2103 | down(&priv->sem); |
| 2104 | ipw_adapter_restart(data); |
| 2105 | up(&priv->sem); |
| 2106 | } |
| 2107 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2108 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
| 2109 | |
| 2110 | static void ipw_scan_check(void *data) |
| 2111 | { |
| 2112 | struct ipw_priv *priv = data; |
| 2113 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
| 2114 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2115 | "adapter (%dms).\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2116 | IPW_SCAN_CHECK_WATCHDOG / 100); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2117 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2118 | } |
| 2119 | } |
| 2120 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 2121 | static void ipw_bg_scan_check(void *data) |
| 2122 | { |
| 2123 | struct ipw_priv *priv = data; |
| 2124 | down(&priv->sem); |
| 2125 | ipw_scan_check(data); |
| 2126 | up(&priv->sem); |
| 2127 | } |
| 2128 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2129 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
| 2130 | struct ipw_scan_request_ext *request) |
| 2131 | { |
| 2132 | struct host_cmd cmd = { |
| 2133 | .cmd = IPW_CMD_SCAN_REQUEST_EXT, |
| 2134 | .len = sizeof(*request) |
| 2135 | }; |
| 2136 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2137 | memcpy(cmd.param, request, sizeof(*request)); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2138 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | static int ipw_send_scan_abort(struct ipw_priv *priv) |
| 2142 | { |
| 2143 | struct host_cmd cmd = { |
| 2144 | .cmd = IPW_CMD_SCAN_ABORT, |
| 2145 | .len = 0 |
| 2146 | }; |
| 2147 | |
| 2148 | if (!priv) { |
| 2149 | IPW_ERROR("Invalid args\n"); |
| 2150 | return -1; |
| 2151 | } |
| 2152 | |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2153 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) |
| 2157 | { |
| 2158 | struct host_cmd cmd = { |
| 2159 | .cmd = IPW_CMD_SENSITIVITY_CALIB, |
| 2160 | .len = sizeof(struct ipw_sensitivity_calib) |
| 2161 | }; |
| 2162 | struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2163 | &cmd.param; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2164 | calib->beacon_rssi_raw = sens; |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2165 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | static int ipw_send_associate(struct ipw_priv *priv, |
| 2169 | struct ipw_associate *associate) |
| 2170 | { |
| 2171 | struct host_cmd cmd = { |
| 2172 | .cmd = IPW_CMD_ASSOCIATE, |
| 2173 | .len = sizeof(*associate) |
| 2174 | }; |
| 2175 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2176 | struct ipw_associate tmp_associate; |
| 2177 | memcpy(&tmp_associate, associate, sizeof(*associate)); |
| 2178 | tmp_associate.policy_support = |
| 2179 | cpu_to_le16(tmp_associate.policy_support); |
| 2180 | tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw); |
| 2181 | tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw); |
| 2182 | tmp_associate.capability = cpu_to_le16(tmp_associate.capability); |
| 2183 | tmp_associate.listen_interval = |
| 2184 | cpu_to_le16(tmp_associate.listen_interval); |
| 2185 | tmp_associate.beacon_interval = |
| 2186 | cpu_to_le16(tmp_associate.beacon_interval); |
| 2187 | tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window); |
| 2188 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2189 | if (!priv || !associate) { |
| 2190 | IPW_ERROR("Invalid args\n"); |
| 2191 | return -1; |
| 2192 | } |
| 2193 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2194 | memcpy(cmd.param, &tmp_associate, sizeof(*associate)); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2195 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | static int ipw_send_supported_rates(struct ipw_priv *priv, |
| 2199 | struct ipw_supported_rates *rates) |
| 2200 | { |
| 2201 | struct host_cmd cmd = { |
| 2202 | .cmd = IPW_CMD_SUPPORTED_RATES, |
| 2203 | .len = sizeof(*rates) |
| 2204 | }; |
| 2205 | |
| 2206 | if (!priv || !rates) { |
| 2207 | IPW_ERROR("Invalid args\n"); |
| 2208 | return -1; |
| 2209 | } |
| 2210 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2211 | memcpy(cmd.param, rates, sizeof(*rates)); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2212 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | static int ipw_set_random_seed(struct ipw_priv *priv) |
| 2216 | { |
| 2217 | struct host_cmd cmd = { |
| 2218 | .cmd = IPW_CMD_SEED_NUMBER, |
| 2219 | .len = sizeof(u32) |
| 2220 | }; |
| 2221 | |
| 2222 | if (!priv) { |
| 2223 | IPW_ERROR("Invalid args\n"); |
| 2224 | return -1; |
| 2225 | } |
| 2226 | |
| 2227 | get_random_bytes(&cmd.param, sizeof(u32)); |
| 2228 | |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2229 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2230 | } |
| 2231 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2232 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
| 2233 | { |
| 2234 | struct host_cmd cmd = { |
| 2235 | .cmd = IPW_CMD_CARD_DISABLE, |
| 2236 | .len = sizeof(u32) |
| 2237 | }; |
| 2238 | |
| 2239 | if (!priv) { |
| 2240 | IPW_ERROR("Invalid args\n"); |
| 2241 | return -1; |
| 2242 | } |
| 2243 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2244 | *((u32 *) & cmd.param) = phy_off; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2245 | |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2246 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2247 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2248 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2249 | 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] | 2250 | { |
| 2251 | struct host_cmd cmd = { |
| 2252 | .cmd = IPW_CMD_TX_POWER, |
| 2253 | .len = sizeof(*power) |
| 2254 | }; |
| 2255 | |
| 2256 | if (!priv || !power) { |
| 2257 | IPW_ERROR("Invalid args\n"); |
| 2258 | return -1; |
| 2259 | } |
| 2260 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2261 | memcpy(cmd.param, power, sizeof(*power)); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2262 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2263 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2264 | |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2265 | static int ipw_set_tx_power(struct ipw_priv *priv) |
| 2266 | { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 2267 | const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2268 | struct ipw_tx_power tx_power; |
| 2269 | s8 max_power; |
| 2270 | int i; |
| 2271 | |
| 2272 | memset(&tx_power, 0, sizeof(tx_power)); |
| 2273 | |
| 2274 | /* configure device for 'G' band */ |
| 2275 | tx_power.ieee_mode = IPW_G_MODE; |
| 2276 | tx_power.num_channels = geo->bg_channels; |
| 2277 | for (i = 0; i < geo->bg_channels; i++) { |
| 2278 | max_power = geo->bg[i].max_power; |
| 2279 | tx_power.channels_tx_power[i].channel_number = |
| 2280 | geo->bg[i].channel; |
| 2281 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2282 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2283 | } |
| 2284 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2285 | return -EIO; |
| 2286 | |
| 2287 | /* configure device to also handle 'B' band */ |
| 2288 | tx_power.ieee_mode = IPW_B_MODE; |
| 2289 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2290 | return -EIO; |
| 2291 | |
| 2292 | /* configure device to also handle 'A' band */ |
| 2293 | if (priv->ieee->abg_true) { |
| 2294 | tx_power.ieee_mode = IPW_A_MODE; |
| 2295 | tx_power.num_channels = geo->a_channels; |
| 2296 | for (i = 0; i < tx_power.num_channels; i++) { |
| 2297 | max_power = geo->a[i].max_power; |
| 2298 | tx_power.channels_tx_power[i].channel_number = |
| 2299 | geo->a[i].channel; |
| 2300 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2301 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2302 | } |
| 2303 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2304 | return -EIO; |
| 2305 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2306 | return 0; |
| 2307 | } |
| 2308 | |
| 2309 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) |
| 2310 | { |
| 2311 | struct ipw_rts_threshold rts_threshold = { |
| 2312 | .rts_threshold = rts, |
| 2313 | }; |
| 2314 | struct host_cmd cmd = { |
| 2315 | .cmd = IPW_CMD_RTS_THRESHOLD, |
| 2316 | .len = sizeof(rts_threshold) |
| 2317 | }; |
| 2318 | |
| 2319 | if (!priv) { |
| 2320 | IPW_ERROR("Invalid args\n"); |
| 2321 | return -1; |
| 2322 | } |
| 2323 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2324 | memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold)); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2325 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) |
| 2329 | { |
| 2330 | struct ipw_frag_threshold frag_threshold = { |
| 2331 | .frag_threshold = frag, |
| 2332 | }; |
| 2333 | struct host_cmd cmd = { |
| 2334 | .cmd = IPW_CMD_FRAG_THRESHOLD, |
| 2335 | .len = sizeof(frag_threshold) |
| 2336 | }; |
| 2337 | |
| 2338 | if (!priv) { |
| 2339 | IPW_ERROR("Invalid args\n"); |
| 2340 | return -1; |
| 2341 | } |
| 2342 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2343 | memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold)); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2344 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) |
| 2348 | { |
| 2349 | struct host_cmd cmd = { |
| 2350 | .cmd = IPW_CMD_POWER_MODE, |
| 2351 | .len = sizeof(u32) |
| 2352 | }; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2353 | u32 *param = (u32 *) (&cmd.param); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2354 | |
| 2355 | if (!priv) { |
| 2356 | IPW_ERROR("Invalid args\n"); |
| 2357 | return -1; |
| 2358 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2359 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2360 | /* If on battery, set to 3, if AC set to CAM, else user |
| 2361 | * level */ |
| 2362 | switch (mode) { |
| 2363 | case IPW_POWER_BATTERY: |
| 2364 | *param = IPW_POWER_INDEX_3; |
| 2365 | break; |
| 2366 | case IPW_POWER_AC: |
| 2367 | *param = IPW_POWER_MODE_CAM; |
| 2368 | break; |
| 2369 | default: |
| 2370 | *param = mode; |
| 2371 | break; |
| 2372 | } |
| 2373 | |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2374 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2375 | } |
| 2376 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2377 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
| 2378 | { |
| 2379 | struct ipw_retry_limit retry_limit = { |
| 2380 | .short_retry_limit = slimit, |
| 2381 | .long_retry_limit = llimit |
| 2382 | }; |
| 2383 | struct host_cmd cmd = { |
| 2384 | .cmd = IPW_CMD_RETRY_LIMIT, |
| 2385 | .len = sizeof(retry_limit) |
| 2386 | }; |
| 2387 | |
| 2388 | if (!priv) { |
| 2389 | IPW_ERROR("Invalid args\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2390 | return -1; |
| 2391 | } |
| 2392 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2393 | memcpy(cmd.param, &retry_limit, sizeof(retry_limit)); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 2394 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | /* |
| 2398 | * The IPW device contains a Microwire compatible EEPROM that stores |
| 2399 | * various data like the MAC address. Usually the firmware has exclusive |
| 2400 | * access to the eeprom, but during device initialization (before the |
| 2401 | * device driver has sent the HostComplete command to the firmware) the |
| 2402 | * device driver has read access to the EEPROM by way of indirect addressing |
| 2403 | * through a couple of memory mapped registers. |
| 2404 | * |
| 2405 | * The following is a simplified implementation for pulling data out of the |
| 2406 | * the eeprom, along with some helper functions to find information in |
| 2407 | * the per device private data's copy of the eeprom. |
| 2408 | * |
| 2409 | * NOTE: To better understand how these functions work (i.e what is a chip |
| 2410 | * select and why do have to keep driving the eeprom clock?), read |
| 2411 | * just about any data sheet for a Microwire compatible EEPROM. |
| 2412 | */ |
| 2413 | |
| 2414 | /* write a 32 bit value into the indirect accessor register */ |
| 2415 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) |
| 2416 | { |
| 2417 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2418 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2419 | /* the eeprom requires some time to complete the operation */ |
| 2420 | udelay(p->eeprom_delay); |
| 2421 | |
| 2422 | return; |
| 2423 | } |
| 2424 | |
| 2425 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2426 | static void eeprom_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2427 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2428 | eeprom_write_reg(priv, 0); |
| 2429 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2430 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2431 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | /* perform a chip select operation */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2435 | static void eeprom_disable_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2436 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2437 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2438 | eeprom_write_reg(priv, 0); |
| 2439 | eeprom_write_reg(priv, EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | /* push a single bit down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2443 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2444 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2445 | int d = (bit ? EEPROM_BIT_DI : 0); |
| 2446 | eeprom_write_reg(p, EEPROM_BIT_CS | d); |
| 2447 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | /* push an opcode followed by an address down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2451 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2452 | { |
| 2453 | int i; |
| 2454 | |
| 2455 | eeprom_cs(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2456 | eeprom_write_bit(priv, 1); |
| 2457 | eeprom_write_bit(priv, op & 2); |
| 2458 | eeprom_write_bit(priv, op & 1); |
| 2459 | for (i = 7; i >= 0; i--) { |
| 2460 | eeprom_write_bit(priv, addr & (1 << i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | /* pull 16 bits off the eeprom, one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2465 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2466 | { |
| 2467 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2468 | u16 r = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2469 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2470 | /* Send READ Opcode */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2471 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2472 | |
| 2473 | /* Send dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2474 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2475 | |
| 2476 | /* Read the byte off the eeprom one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2477 | for (i = 0; i < 16; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2478 | u32 data = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2479 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2480 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2481 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); |
| 2482 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2483 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2484 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2485 | /* Send another dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2486 | eeprom_write_reg(priv, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2487 | eeprom_disable_cs(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2488 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2489 | return r; |
| 2490 | } |
| 2491 | |
| 2492 | /* helper function for pulling the mac address out of the private */ |
| 2493 | /* data's copy of the eeprom data */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2494 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2495 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2496 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | /* |
| 2500 | * Either the device driver (i.e. the host) or the firmware can |
| 2501 | * load eeprom data into the designated region in SRAM. If neither |
| 2502 | * happens then the FW will shutdown with a fatal error. |
| 2503 | * |
| 2504 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE |
| 2505 | * bit needs region of shared SRAM needs to be non-zero. |
| 2506 | */ |
| 2507 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) |
| 2508 | { |
| 2509 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2510 | u16 *eeprom = (u16 *) priv->eeprom; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2511 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2512 | IPW_DEBUG_TRACE(">>\n"); |
| 2513 | |
| 2514 | /* read entire contents of eeprom into private buffer */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2515 | for (i = 0; i < 128; i++) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2516 | eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2517 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2518 | /* |
| 2519 | If the data looks correct, then copy it to our private |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2520 | copy. Otherwise let the firmware know to perform the operation |
| 2521 | on it's own |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2522 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2523 | if ((priv->eeprom + EEPROM_VERSION) != 0) { |
| 2524 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
| 2525 | |
| 2526 | /* write the eeprom data to sram */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2527 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2528 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2529 | |
| 2530 | /* Do not load eeprom data on fatal error or suspend */ |
| 2531 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 2532 | } else { |
| 2533 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); |
| 2534 | |
| 2535 | /* Load eeprom data on fatal error or suspend */ |
| 2536 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); |
| 2537 | } |
| 2538 | |
| 2539 | IPW_DEBUG_TRACE("<<\n"); |
| 2540 | } |
| 2541 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2542 | 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] | 2543 | { |
| 2544 | count >>= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2545 | if (!count) |
| 2546 | return; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2547 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2548 | while (count--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2549 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) |
| 2553 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2554 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2555 | CB_NUMBER_OF_ELEMENTS_SMALL * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2556 | sizeof(struct command_block)); |
| 2557 | } |
| 2558 | |
| 2559 | static int ipw_fw_dma_enable(struct ipw_priv *priv) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2560 | { /* start dma engine but no transfers yet */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2561 | |
| 2562 | IPW_DEBUG_FW(">> : \n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2563 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2564 | /* Start the dma */ |
| 2565 | ipw_fw_dma_reset_command_blocks(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2566 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2567 | /* Write CB base address */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2568 | 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] | 2569 | |
| 2570 | IPW_DEBUG_FW("<< : \n"); |
| 2571 | return 0; |
| 2572 | } |
| 2573 | |
| 2574 | static void ipw_fw_dma_abort(struct ipw_priv *priv) |
| 2575 | { |
| 2576 | u32 control = 0; |
| 2577 | |
| 2578 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2579 | |
| 2580 | //set the Stop and Abort bit |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2581 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2582 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2583 | priv->sram_desc.last_cb_index = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2584 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2585 | IPW_DEBUG_FW("<< \n"); |
| 2586 | } |
| 2587 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2588 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
| 2589 | struct command_block *cb) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2590 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2591 | u32 address = |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2592 | IPW_SHARED_SRAM_DMA_CONTROL + |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2593 | (sizeof(struct command_block) * index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2594 | IPW_DEBUG_FW(">> :\n"); |
| 2595 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2596 | ipw_write_indirect(priv, address, (u8 *) cb, |
| 2597 | (int)sizeof(struct command_block)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2598 | |
| 2599 | IPW_DEBUG_FW("<< :\n"); |
| 2600 | return 0; |
| 2601 | |
| 2602 | } |
| 2603 | |
| 2604 | static int ipw_fw_dma_kick(struct ipw_priv *priv) |
| 2605 | { |
| 2606 | u32 control = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2607 | u32 index = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2608 | |
| 2609 | IPW_DEBUG_FW(">> :\n"); |
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 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2612 | ipw_fw_dma_write_command_block(priv, index, |
| 2613 | &priv->sram_desc.cb_list[index]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2614 | |
| 2615 | /* Enable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2616 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 2617 | IPW_RESET_REG_MASTER_DISABLED | |
| 2618 | IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2619 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2620 | /* Set the Start bit. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2621 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2622 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2623 | |
| 2624 | IPW_DEBUG_FW("<< :\n"); |
| 2625 | return 0; |
| 2626 | } |
| 2627 | |
| 2628 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) |
| 2629 | { |
| 2630 | u32 address; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2631 | u32 register_value = 0; |
| 2632 | u32 cb_fields_address = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2633 | |
| 2634 | IPW_DEBUG_FW(">> :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2635 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2636 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2637 | |
| 2638 | /* Read the DMA Controlor register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2639 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
| 2640 | 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] | 2641 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2642 | /* Print the CB values */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2643 | cb_fields_address = address; |
| 2644 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2645 | 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] | 2646 | |
| 2647 | cb_fields_address += sizeof(u32); |
| 2648 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2649 | 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] | 2650 | |
| 2651 | cb_fields_address += sizeof(u32); |
| 2652 | register_value = ipw_read_reg32(priv, cb_fields_address); |
| 2653 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", |
| 2654 | register_value); |
| 2655 | |
| 2656 | cb_fields_address += sizeof(u32); |
| 2657 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2658 | 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] | 2659 | |
| 2660 | IPW_DEBUG_FW(">> :\n"); |
| 2661 | } |
| 2662 | |
| 2663 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) |
| 2664 | { |
| 2665 | u32 current_cb_address = 0; |
| 2666 | u32 current_cb_index = 0; |
| 2667 | |
| 2668 | IPW_DEBUG_FW("<< :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2669 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2670 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2671 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2672 | sizeof(struct command_block); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2673 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2674 | 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] | 2675 | current_cb_index, current_cb_address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2676 | |
| 2677 | IPW_DEBUG_FW(">> :\n"); |
| 2678 | return current_cb_index; |
| 2679 | |
| 2680 | } |
| 2681 | |
| 2682 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, |
| 2683 | u32 src_address, |
| 2684 | u32 dest_address, |
| 2685 | u32 length, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2686 | int interrupt_enabled, int is_last) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2687 | { |
| 2688 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2689 | 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] | 2690 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
| 2691 | CB_DEST_SIZE_LONG; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2692 | struct command_block *cb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2693 | u32 last_cb_element = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2694 | |
| 2695 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", |
| 2696 | src_address, dest_address, length); |
| 2697 | |
| 2698 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) |
| 2699 | return -1; |
| 2700 | |
| 2701 | last_cb_element = priv->sram_desc.last_cb_index; |
| 2702 | cb = &priv->sram_desc.cb_list[last_cb_element]; |
| 2703 | priv->sram_desc.last_cb_index++; |
| 2704 | |
| 2705 | /* Calculate the new CB control word */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2706 | if (interrupt_enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2707 | control |= CB_INT_ENABLED; |
| 2708 | |
| 2709 | if (is_last) |
| 2710 | control |= CB_LAST_VALID; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2711 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2712 | control |= length; |
| 2713 | |
| 2714 | /* Calculate the CB Element's checksum value */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2715 | cb->status = control ^ src_address ^ dest_address; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2716 | |
| 2717 | /* Copy the Source and Destination addresses */ |
| 2718 | cb->dest_addr = dest_address; |
| 2719 | cb->source_addr = src_address; |
| 2720 | |
| 2721 | /* Copy the Control Word last */ |
| 2722 | cb->control = control; |
| 2723 | |
| 2724 | return 0; |
| 2725 | } |
| 2726 | |
| 2727 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2728 | u32 src_phys, u32 dest_address, u32 length) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2729 | { |
| 2730 | u32 bytes_left = length; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2731 | u32 src_offset = 0; |
| 2732 | u32 dest_offset = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2733 | int status = 0; |
| 2734 | IPW_DEBUG_FW(">> \n"); |
| 2735 | IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n", |
| 2736 | src_phys, dest_address, length); |
| 2737 | while (bytes_left > CB_MAX_LENGTH) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2738 | status = ipw_fw_dma_add_command_block(priv, |
| 2739 | src_phys + src_offset, |
| 2740 | dest_address + |
| 2741 | dest_offset, |
| 2742 | CB_MAX_LENGTH, 0, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2743 | if (status) { |
| 2744 | IPW_DEBUG_FW_INFO(": Failed\n"); |
| 2745 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2746 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2747 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
| 2748 | |
| 2749 | src_offset += CB_MAX_LENGTH; |
| 2750 | dest_offset += CB_MAX_LENGTH; |
| 2751 | bytes_left -= CB_MAX_LENGTH; |
| 2752 | } |
| 2753 | |
| 2754 | /* add the buffer tail */ |
| 2755 | if (bytes_left > 0) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2756 | status = |
| 2757 | ipw_fw_dma_add_command_block(priv, src_phys + src_offset, |
| 2758 | dest_address + dest_offset, |
| 2759 | bytes_left, 0, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2760 | if (status) { |
| 2761 | IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n"); |
| 2762 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2763 | } else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2764 | IPW_DEBUG_FW_INFO |
| 2765 | (": Adding new cb - the buffer tail\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2766 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2767 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2768 | IPW_DEBUG_FW("<< \n"); |
| 2769 | return 0; |
| 2770 | } |
| 2771 | |
| 2772 | static int ipw_fw_dma_wait(struct ipw_priv *priv) |
| 2773 | { |
| 2774 | u32 current_index = 0; |
| 2775 | u32 watchdog = 0; |
| 2776 | |
| 2777 | IPW_DEBUG_FW(">> : \n"); |
| 2778 | |
| 2779 | current_index = ipw_fw_dma_command_block_index(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2780 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2781 | (int)priv->sram_desc.last_cb_index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2782 | |
| 2783 | while (current_index < priv->sram_desc.last_cb_index) { |
| 2784 | udelay(50); |
| 2785 | current_index = ipw_fw_dma_command_block_index(priv); |
| 2786 | |
| 2787 | watchdog++; |
| 2788 | |
| 2789 | if (watchdog > 400) { |
| 2790 | IPW_DEBUG_FW_INFO("Timeout\n"); |
| 2791 | ipw_fw_dma_dump_command_block(priv); |
| 2792 | ipw_fw_dma_abort(priv); |
| 2793 | return -1; |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | ipw_fw_dma_abort(priv); |
| 2798 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2799 | /*Disable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2800 | ipw_set_bit(priv, IPW_RESET_REG, |
| 2801 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2802 | |
| 2803 | IPW_DEBUG_FW("<< dmaWaitSync \n"); |
| 2804 | return 0; |
| 2805 | } |
| 2806 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2807 | static void ipw_remove_current_network(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2808 | { |
| 2809 | struct list_head *element, *safe; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2810 | struct ieee80211_network *network = NULL; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2811 | unsigned long flags; |
| 2812 | |
| 2813 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2814 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
| 2815 | network = list_entry(element, struct ieee80211_network, list); |
| 2816 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 2817 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2818 | list_add_tail(&network->list, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2819 | &priv->ieee->network_free_list); |
| 2820 | } |
| 2821 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2822 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | /** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2826 | * Check that card is still alive. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2827 | * Reads debug register from domain0. |
| 2828 | * If card is present, pre-defined value should |
| 2829 | * be found there. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2830 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2831 | * @param priv |
| 2832 | * @return 1 if card is present, 0 otherwise |
| 2833 | */ |
| 2834 | static inline int ipw_alive(struct ipw_priv *priv) |
| 2835 | { |
| 2836 | return ipw_read32(priv, 0x90) == 0xd55555d5; |
| 2837 | } |
| 2838 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2839 | 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] | 2840 | int timeout) |
| 2841 | { |
| 2842 | int i = 0; |
| 2843 | |
| 2844 | do { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2845 | if ((ipw_read32(priv, addr) & mask) == mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2846 | return i; |
| 2847 | mdelay(10); |
| 2848 | i += 10; |
| 2849 | } while (i < timeout); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2850 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2851 | return -ETIME; |
| 2852 | } |
| 2853 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2854 | /* These functions load the firmware and micro code for the operation of |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2855 | * the ipw hardware. It assumes the buffer has all the bits for the |
| 2856 | * image and the caller is handling the memory allocation and clean up. |
| 2857 | */ |
| 2858 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2859 | static int ipw_stop_master(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2860 | { |
| 2861 | int rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2862 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2863 | IPW_DEBUG_TRACE(">> \n"); |
| 2864 | /* stop master. typical delay - 0 */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2865 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2866 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2867 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 2868 | IPW_RESET_REG_MASTER_DISABLED, 100); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2869 | if (rc < 0) { |
| 2870 | IPW_ERROR("stop master failed in 10ms\n"); |
| 2871 | return -1; |
| 2872 | } |
| 2873 | |
| 2874 | IPW_DEBUG_INFO("stop master %dms\n", rc); |
| 2875 | |
| 2876 | return rc; |
| 2877 | } |
| 2878 | |
| 2879 | static void ipw_arc_release(struct ipw_priv *priv) |
| 2880 | { |
| 2881 | IPW_DEBUG_TRACE(">> \n"); |
| 2882 | mdelay(5); |
| 2883 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2884 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2885 | |
| 2886 | /* no one knows timing, for safety add some delay */ |
| 2887 | mdelay(5); |
| 2888 | } |
| 2889 | |
| 2890 | struct fw_header { |
| 2891 | u32 version; |
| 2892 | u32 mode; |
| 2893 | }; |
| 2894 | |
| 2895 | struct fw_chunk { |
| 2896 | u32 address; |
| 2897 | u32 length; |
| 2898 | }; |
| 2899 | |
| 2900 | #define IPW_FW_MAJOR_VERSION 2 |
James Ketrenos | 81715376 | 2005-08-25 01:37:28 -0500 | [diff] [blame] | 2901 | #define IPW_FW_MINOR_VERSION 4 |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2902 | |
| 2903 | #define IPW_FW_MINOR(x) ((x & 0xff) >> 8) |
| 2904 | #define IPW_FW_MAJOR(x) (x & 0xff) |
| 2905 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2906 | #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] | 2907 | |
| 2908 | #define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \ |
| 2909 | "." __stringify(IPW_FW_MINOR_VERSION) "-" |
| 2910 | |
| 2911 | #if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0 |
| 2912 | #define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw" |
| 2913 | #else |
| 2914 | #define IPW_FW_NAME(x) "ipw2200_" x ".fw" |
| 2915 | #endif |
| 2916 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2917 | 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] | 2918 | { |
| 2919 | int rc = 0, i, addr; |
| 2920 | u8 cr = 0; |
| 2921 | u16 *image; |
| 2922 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2923 | image = (u16 *) data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2924 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2925 | IPW_DEBUG_TRACE(">> \n"); |
| 2926 | |
| 2927 | rc = ipw_stop_master(priv); |
| 2928 | |
| 2929 | if (rc < 0) |
| 2930 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2931 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2932 | // spin_lock_irqsave(&priv->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2933 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2934 | for (addr = IPW_SHARED_LOWER_BOUND; |
| 2935 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2936 | ipw_write32(priv, addr, 0); |
| 2937 | } |
| 2938 | |
| 2939 | /* no ucode (yet) */ |
| 2940 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); |
| 2941 | /* destroy DMA queues */ |
| 2942 | /* reset sequence */ |
| 2943 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2944 | 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] | 2945 | ipw_arc_release(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2946 | 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] | 2947 | mdelay(1); |
| 2948 | |
| 2949 | /* reset PHY */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2950 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2951 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2952 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2953 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2954 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2955 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2956 | /* enable ucode store */ |
Zhu Yi | c8fe667 | 2006-01-24 16:36:36 +0800 | [diff] [blame] | 2957 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
| 2958 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2959 | mdelay(1); |
| 2960 | |
| 2961 | /* write ucode */ |
| 2962 | /** |
| 2963 | * @bug |
| 2964 | * Do NOT set indirect address register once and then |
| 2965 | * store data to indirect data register in the loop. |
| 2966 | * It seems very reasonable, but in this case DINO do not |
| 2967 | * accept ucode. It is essential to set address each time. |
| 2968 | */ |
| 2969 | /* load new ipw uCode */ |
| 2970 | for (i = 0; i < len / 2; i++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2971 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2972 | cpu_to_le16(image[i])); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2973 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2974 | /* enable DINO */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2975 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
| 2976 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2977 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2978 | /* this is where the igx / win driver deveates from the VAP driver. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2979 | |
| 2980 | /* wait for alive response */ |
| 2981 | for (i = 0; i < 100; i++) { |
| 2982 | /* poll for incoming data */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2983 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2984 | if (cr & DINO_RXFIFO_DATA) |
| 2985 | break; |
| 2986 | mdelay(1); |
| 2987 | } |
| 2988 | |
| 2989 | if (cr & DINO_RXFIFO_DATA) { |
| 2990 | /* alive_command_responce size is NOT multiple of 4 */ |
| 2991 | u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2992 | |
| 2993 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2994 | response_buffer[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2995 | le32_to_cpu(ipw_read_reg32(priv, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2996 | IPW_BASEBAND_RX_FIFO_READ)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2997 | memcpy(&priv->dino_alive, response_buffer, |
| 2998 | sizeof(priv->dino_alive)); |
| 2999 | if (priv->dino_alive.alive_command == 1 |
| 3000 | && priv->dino_alive.ucode_valid == 1) { |
| 3001 | rc = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3002 | IPW_DEBUG_INFO |
| 3003 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " |
| 3004 | "of %02d/%02d/%02d %02d:%02d\n", |
| 3005 | priv->dino_alive.software_revision, |
| 3006 | priv->dino_alive.software_revision, |
| 3007 | priv->dino_alive.device_identifier, |
| 3008 | priv->dino_alive.device_identifier, |
| 3009 | priv->dino_alive.time_stamp[0], |
| 3010 | priv->dino_alive.time_stamp[1], |
| 3011 | priv->dino_alive.time_stamp[2], |
| 3012 | priv->dino_alive.time_stamp[3], |
| 3013 | priv->dino_alive.time_stamp[4]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3014 | } else { |
| 3015 | IPW_DEBUG_INFO("Microcode is not alive\n"); |
| 3016 | rc = -EINVAL; |
| 3017 | } |
| 3018 | } else { |
| 3019 | IPW_DEBUG_INFO("No alive response from DINO\n"); |
| 3020 | rc = -ETIME; |
| 3021 | } |
| 3022 | |
| 3023 | /* disable DINO, otherwise for some reason |
| 3024 | firmware have problem getting alive resp. */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3025 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3026 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3027 | // spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3028 | |
| 3029 | return rc; |
| 3030 | } |
| 3031 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3032 | 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] | 3033 | { |
| 3034 | int rc = -1; |
| 3035 | int offset = 0; |
| 3036 | struct fw_chunk *chunk; |
| 3037 | dma_addr_t shared_phys; |
| 3038 | u8 *shared_virt; |
| 3039 | |
| 3040 | IPW_DEBUG_TRACE("<< : \n"); |
| 3041 | shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys); |
| 3042 | |
| 3043 | if (!shared_virt) |
| 3044 | return -ENOMEM; |
| 3045 | |
| 3046 | memmove(shared_virt, data, len); |
| 3047 | |
| 3048 | /* Start the Dma */ |
| 3049 | rc = ipw_fw_dma_enable(priv); |
| 3050 | |
| 3051 | if (priv->sram_desc.last_cb_index > 0) { |
| 3052 | /* the DMA is already ready this would be a bug. */ |
| 3053 | BUG(); |
| 3054 | goto out; |
| 3055 | } |
| 3056 | |
| 3057 | do { |
| 3058 | chunk = (struct fw_chunk *)(data + offset); |
| 3059 | offset += sizeof(struct fw_chunk); |
| 3060 | /* build DMA packet and queue up for sending */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3061 | /* dma to chunk->address, the chunk->length bytes from data + |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3062 | * offeset*/ |
| 3063 | /* Dma loading */ |
| 3064 | rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3065 | le32_to_cpu(chunk->address), |
| 3066 | le32_to_cpu(chunk->length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3067 | if (rc) { |
| 3068 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
| 3069 | goto out; |
| 3070 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3071 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3072 | offset += le32_to_cpu(chunk->length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3073 | } while (offset < len); |
| 3074 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3075 | /* Run the DMA and wait for the answer */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3076 | rc = ipw_fw_dma_kick(priv); |
| 3077 | if (rc) { |
| 3078 | IPW_ERROR("dmaKick Failed\n"); |
| 3079 | goto out; |
| 3080 | } |
| 3081 | |
| 3082 | rc = ipw_fw_dma_wait(priv); |
| 3083 | if (rc) { |
| 3084 | IPW_ERROR("dmaWaitSync Failed\n"); |
| 3085 | goto out; |
| 3086 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3087 | out: |
| 3088 | pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3089 | return rc; |
| 3090 | } |
| 3091 | |
| 3092 | /* stop nic */ |
| 3093 | static int ipw_stop_nic(struct ipw_priv *priv) |
| 3094 | { |
| 3095 | int rc = 0; |
| 3096 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3097 | /* stop */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3098 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3099 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3100 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 3101 | IPW_RESET_REG_MASTER_DISABLED, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3102 | if (rc < 0) { |
| 3103 | IPW_ERROR("wait for reg master disabled failed\n"); |
| 3104 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3105 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3106 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3107 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3108 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3109 | return rc; |
| 3110 | } |
| 3111 | |
| 3112 | static void ipw_start_nic(struct ipw_priv *priv) |
| 3113 | { |
| 3114 | IPW_DEBUG_TRACE(">>\n"); |
| 3115 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3116 | /* prvHwStartNic release ARC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3117 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 3118 | IPW_RESET_REG_MASTER_DISABLED | |
| 3119 | IPW_RESET_REG_STOP_MASTER | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3120 | CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3121 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3122 | /* enable power management */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3123 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
| 3124 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3125 | |
| 3126 | IPW_DEBUG_TRACE("<<\n"); |
| 3127 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3128 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3129 | static int ipw_init_nic(struct ipw_priv *priv) |
| 3130 | { |
| 3131 | int rc; |
| 3132 | |
| 3133 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3134 | /* reset */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3135 | /*prvHwInitNic */ |
| 3136 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3137 | 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] | 3138 | |
| 3139 | /* low-level PLL activation */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3140 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
| 3141 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3142 | |
| 3143 | /* wait for clock stabilization */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3144 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
| 3145 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3146 | if (rc < 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3147 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
| 3148 | |
| 3149 | /* assert SW reset */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3150 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3151 | |
| 3152 | udelay(10); |
| 3153 | |
| 3154 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3155 | 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] | 3156 | |
| 3157 | IPW_DEBUG_TRACE(">>\n"); |
| 3158 | return 0; |
| 3159 | } |
| 3160 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3161 | /* Call this function from process context, it will sleep in request_firmware. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3162 | * Probe is an ok place to call this from. |
| 3163 | */ |
| 3164 | static int ipw_reset_nic(struct ipw_priv *priv) |
| 3165 | { |
| 3166 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3167 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3168 | |
| 3169 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3170 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3171 | rc = ipw_init_nic(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3172 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3173 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3174 | /* Clear the 'host command active' bit... */ |
| 3175 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 3176 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3177 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 3178 | wake_up_interruptible(&priv->wait_state); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3179 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3180 | |
| 3181 | IPW_DEBUG_TRACE("<<\n"); |
| 3182 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3183 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3184 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3185 | static int ipw_get_fw(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3186 | const struct firmware **fw, const char *name) |
| 3187 | { |
| 3188 | struct fw_header *header; |
| 3189 | int rc; |
| 3190 | |
| 3191 | /* ask firmware_class module to get the boot firmware off disk */ |
| 3192 | rc = request_firmware(fw, name, &priv->pci_dev->dev); |
| 3193 | if (rc < 0) { |
| 3194 | IPW_ERROR("%s load failed: Reason %d\n", name, rc); |
| 3195 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3196 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3197 | |
| 3198 | header = (struct fw_header *)(*fw)->data; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3199 | 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] | 3200 | IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n", |
| 3201 | name, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3202 | IPW_FW_MAJOR(le32_to_cpu(header->version)), |
| 3203 | IPW_FW_MAJOR_VERSION); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3204 | return -EINVAL; |
| 3205 | } |
| 3206 | |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3207 | 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] | 3208 | name, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3209 | IPW_FW_MAJOR(le32_to_cpu(header->version)), |
| 3210 | IPW_FW_MINOR(le32_to_cpu(header->version)), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3211 | (*fw)->size - sizeof(struct fw_header)); |
| 3212 | return 0; |
| 3213 | } |
| 3214 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3215 | #define IPW_RX_BUF_SIZE (3000) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3216 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3217 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3218 | struct ipw_rx_queue *rxq) |
| 3219 | { |
| 3220 | unsigned long flags; |
| 3221 | int i; |
| 3222 | |
| 3223 | spin_lock_irqsave(&rxq->lock, flags); |
| 3224 | |
| 3225 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3226 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3227 | |
| 3228 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3229 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3230 | /* In the reset function, these buffers may have been allocated |
| 3231 | * to an SKB, so we need to unmap and free potential storage */ |
| 3232 | if (rxq->pool[i].skb != NULL) { |
| 3233 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3234 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3235 | dev_kfree_skb(rxq->pool[i].skb); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3236 | rxq->pool[i].skb = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3237 | } |
| 3238 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3239 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3240 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3241 | /* Set us so that we have processed and used all buffers, but have |
| 3242 | * not restocked the Rx queue with fresh buffers */ |
| 3243 | rxq->read = rxq->write = 0; |
| 3244 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 3245 | rxq->free_count = 0; |
| 3246 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3247 | } |
| 3248 | |
| 3249 | #ifdef CONFIG_PM |
| 3250 | static int fw_loaded = 0; |
| 3251 | static const struct firmware *bootfw = NULL; |
| 3252 | static const struct firmware *firmware = NULL; |
| 3253 | static const struct firmware *ucode = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3254 | |
| 3255 | static void free_firmware(void) |
| 3256 | { |
| 3257 | if (fw_loaded) { |
| 3258 | release_firmware(bootfw); |
| 3259 | release_firmware(ucode); |
| 3260 | release_firmware(firmware); |
| 3261 | bootfw = ucode = firmware = NULL; |
| 3262 | fw_loaded = 0; |
| 3263 | } |
| 3264 | } |
| 3265 | #else |
| 3266 | #define free_firmware() do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3267 | #endif |
| 3268 | |
| 3269 | static int ipw_load(struct ipw_priv *priv) |
| 3270 | { |
| 3271 | #ifndef CONFIG_PM |
| 3272 | const struct firmware *bootfw = NULL; |
| 3273 | const struct firmware *firmware = NULL; |
| 3274 | const struct firmware *ucode = NULL; |
| 3275 | #endif |
| 3276 | int rc = 0, retries = 3; |
| 3277 | |
| 3278 | #ifdef CONFIG_PM |
| 3279 | if (!fw_loaded) { |
| 3280 | #endif |
| 3281 | rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot")); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3282 | if (rc) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3283 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3284 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3285 | switch (priv->ieee->iw_mode) { |
| 3286 | case IW_MODE_ADHOC: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3287 | rc = ipw_get_fw(priv, &ucode, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3288 | IPW_FW_NAME("ibss_ucode")); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3289 | if (rc) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3290 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3291 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3292 | rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss")); |
| 3293 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3294 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3295 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3296 | case IW_MODE_MONITOR: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3297 | rc = ipw_get_fw(priv, &ucode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3298 | IPW_FW_NAME("sniffer_ucode")); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3299 | if (rc) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3300 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3301 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3302 | rc = ipw_get_fw(priv, &firmware, |
| 3303 | IPW_FW_NAME("sniffer")); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3304 | break; |
| 3305 | #endif |
| 3306 | case IW_MODE_INFRA: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3307 | rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode")); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3308 | if (rc) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3309 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3310 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3311 | rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss")); |
| 3312 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3313 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3314 | default: |
| 3315 | rc = -EINVAL; |
| 3316 | } |
| 3317 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3318 | if (rc) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3319 | goto error; |
| 3320 | |
| 3321 | #ifdef CONFIG_PM |
| 3322 | fw_loaded = 1; |
| 3323 | } |
| 3324 | #endif |
| 3325 | |
| 3326 | if (!priv->rxq) |
| 3327 | priv->rxq = ipw_rx_queue_alloc(priv); |
| 3328 | else |
| 3329 | ipw_rx_queue_reset(priv, priv->rxq); |
| 3330 | if (!priv->rxq) { |
| 3331 | IPW_ERROR("Unable to initialize Rx queue\n"); |
| 3332 | goto error; |
| 3333 | } |
| 3334 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3335 | retry: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3336 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3337 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3338 | priv->status &= ~STATUS_INT_ENABLED; |
| 3339 | |
| 3340 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3341 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3342 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3343 | ipw_stop_nic(priv); |
| 3344 | |
| 3345 | rc = ipw_reset_nic(priv); |
| 3346 | if (rc) { |
| 3347 | IPW_ERROR("Unable to reset NIC\n"); |
| 3348 | goto error; |
| 3349 | } |
| 3350 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3351 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
| 3352 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3353 | |
| 3354 | /* DMA the initial boot firmware into the device */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3355 | rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3356 | bootfw->size - sizeof(struct fw_header)); |
| 3357 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3358 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3359 | goto error; |
| 3360 | } |
| 3361 | |
| 3362 | /* kick start the device */ |
| 3363 | ipw_start_nic(priv); |
| 3364 | |
| 3365 | /* wait for the device to finish it's initial startup sequence */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3366 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3367 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3368 | if (rc < 0) { |
| 3369 | IPW_ERROR("device failed to boot initial fw image\n"); |
| 3370 | goto error; |
| 3371 | } |
| 3372 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); |
| 3373 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3374 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3375 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3376 | |
| 3377 | /* DMA the ucode into the device */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3378 | rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3379 | ucode->size - sizeof(struct fw_header)); |
| 3380 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3381 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3382 | goto error; |
| 3383 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3384 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3385 | /* stop nic */ |
| 3386 | ipw_stop_nic(priv); |
| 3387 | |
| 3388 | /* DMA bss firmware into the device */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3389 | rc = ipw_load_firmware(priv, firmware->data + |
| 3390 | sizeof(struct fw_header), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3391 | firmware->size - sizeof(struct fw_header)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3392 | if (rc < 0) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 3393 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3394 | goto error; |
| 3395 | } |
| 3396 | |
| 3397 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 3398 | |
| 3399 | rc = ipw_queue_reset(priv); |
| 3400 | if (rc) { |
| 3401 | IPW_ERROR("Unable to initialize queues\n"); |
| 3402 | goto error; |
| 3403 | } |
| 3404 | |
| 3405 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3406 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3407 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3408 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3409 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3410 | /* kick start the device */ |
| 3411 | ipw_start_nic(priv); |
| 3412 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3413 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3414 | if (retries > 0) { |
| 3415 | IPW_WARNING("Parity error. Retrying init.\n"); |
| 3416 | retries--; |
| 3417 | goto retry; |
| 3418 | } |
| 3419 | |
| 3420 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); |
| 3421 | rc = -EIO; |
| 3422 | goto error; |
| 3423 | } |
| 3424 | |
| 3425 | /* wait for the device */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3426 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3427 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3428 | if (rc < 0) { |
| 3429 | IPW_ERROR("device failed to start after 500ms\n"); |
| 3430 | goto error; |
| 3431 | } |
| 3432 | IPW_DEBUG_INFO("device response after %dms\n", rc); |
| 3433 | |
| 3434 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3435 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3436 | |
| 3437 | /* read eeprom data and initialize the eeprom region of sram */ |
| 3438 | priv->eeprom_delay = 1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3439 | ipw_eeprom_init_sram(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3440 | |
| 3441 | /* enable interrupts */ |
| 3442 | ipw_enable_interrupts(priv); |
| 3443 | |
| 3444 | /* Ensure our queue has valid packets */ |
| 3445 | ipw_rx_queue_replenish(priv); |
| 3446 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3447 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3448 | |
| 3449 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3450 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3451 | |
| 3452 | #ifndef CONFIG_PM |
| 3453 | release_firmware(bootfw); |
| 3454 | release_firmware(ucode); |
| 3455 | release_firmware(firmware); |
| 3456 | #endif |
| 3457 | return 0; |
| 3458 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3459 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3460 | if (priv->rxq) { |
| 3461 | ipw_rx_queue_free(priv, priv->rxq); |
| 3462 | priv->rxq = NULL; |
| 3463 | } |
| 3464 | ipw_tx_queue_free(priv); |
| 3465 | if (bootfw) |
| 3466 | release_firmware(bootfw); |
| 3467 | if (ucode) |
| 3468 | release_firmware(ucode); |
| 3469 | if (firmware) |
| 3470 | release_firmware(firmware); |
| 3471 | #ifdef CONFIG_PM |
| 3472 | fw_loaded = 0; |
| 3473 | bootfw = ucode = firmware = NULL; |
| 3474 | #endif |
| 3475 | |
| 3476 | return rc; |
| 3477 | } |
| 3478 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3479 | /** |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3480 | * DMA services |
| 3481 | * |
| 3482 | * Theory of operation |
| 3483 | * |
| 3484 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 3485 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 3486 | * |
| 3487 | * 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] | 3488 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 3489 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3490 | * Tx queue resumed. |
| 3491 | * |
| 3492 | * The IPW operates with six queues, one receive queue in the device's |
| 3493 | * sram, one transmit queue for sending commands to the device firmware, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3494 | * and four transmit queues for data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3495 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3496 | * The four transmit queues allow for performing quality of service (qos) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3497 | * transmissions as per the 802.11 protocol. Currently Linux does not |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3498 | * provide a mechanism to the user for utilizing prioritized queues, so |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3499 | * we only utilize the first data transmit queue (queue1). |
| 3500 | */ |
| 3501 | |
| 3502 | /** |
| 3503 | * Driver allocates buffers of this size for Rx |
| 3504 | */ |
| 3505 | |
| 3506 | static inline int ipw_queue_space(const struct clx2_queue *q) |
| 3507 | { |
| 3508 | int s = q->last_used - q->first_empty; |
| 3509 | if (s <= 0) |
| 3510 | s += q->n_bd; |
| 3511 | s -= 2; /* keep some reserve to not confuse empty and full situations */ |
| 3512 | if (s < 0) |
| 3513 | s = 0; |
| 3514 | return s; |
| 3515 | } |
| 3516 | |
| 3517 | static inline int ipw_queue_inc_wrap(int index, int n_bd) |
| 3518 | { |
| 3519 | return (++index == n_bd) ? 0 : index; |
| 3520 | } |
| 3521 | |
| 3522 | /** |
| 3523 | * Initialize common DMA queue structure |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3524 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3525 | * @param q queue to init |
| 3526 | * @param count Number of BD's to allocate. Should be power of 2 |
| 3527 | * @param read_register Address for 'read' register |
| 3528 | * (not offset within BAR, full address) |
| 3529 | * @param write_register Address for 'write' register |
| 3530 | * (not offset within BAR, full address) |
| 3531 | * @param base_register Address for 'base' register |
| 3532 | * (not offset within BAR, full address) |
| 3533 | * @param size Address for 'size' register |
| 3534 | * (not offset within BAR, full address) |
| 3535 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3536 | 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] | 3537 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3538 | { |
| 3539 | q->n_bd = count; |
| 3540 | |
| 3541 | q->low_mark = q->n_bd / 4; |
| 3542 | if (q->low_mark < 4) |
| 3543 | q->low_mark = 4; |
| 3544 | |
| 3545 | q->high_mark = q->n_bd / 8; |
| 3546 | if (q->high_mark < 2) |
| 3547 | q->high_mark = 2; |
| 3548 | |
| 3549 | q->first_empty = q->last_used = 0; |
| 3550 | q->reg_r = read; |
| 3551 | q->reg_w = write; |
| 3552 | |
| 3553 | ipw_write32(priv, base, q->dma_addr); |
| 3554 | ipw_write32(priv, size, count); |
| 3555 | ipw_write32(priv, read, 0); |
| 3556 | ipw_write32(priv, write, 0); |
| 3557 | |
| 3558 | _ipw_read32(priv, 0x90); |
| 3559 | } |
| 3560 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3561 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3562 | struct clx2_tx_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3563 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3564 | { |
| 3565 | struct pci_dev *dev = priv->pci_dev; |
| 3566 | |
| 3567 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); |
| 3568 | if (!q->txb) { |
| 3569 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); |
| 3570 | return -ENOMEM; |
| 3571 | } |
| 3572 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3573 | q->bd = |
| 3574 | 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] | 3575 | if (!q->bd) { |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3576 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3577 | sizeof(q->bd[0]) * count); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3578 | kfree(q->txb); |
| 3579 | q->txb = NULL; |
| 3580 | return -ENOMEM; |
| 3581 | } |
| 3582 | |
| 3583 | ipw_queue_init(priv, &q->q, count, read, write, base, size); |
| 3584 | return 0; |
| 3585 | } |
| 3586 | |
| 3587 | /** |
| 3588 | * Free one TFD, those at index [txq->q.last_used]. |
| 3589 | * Do NOT advance any indexes |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3590 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3591 | * @param dev |
| 3592 | * @param txq |
| 3593 | */ |
| 3594 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, |
| 3595 | struct clx2_tx_queue *txq) |
| 3596 | { |
| 3597 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; |
| 3598 | struct pci_dev *dev = priv->pci_dev; |
| 3599 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3600 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3601 | /* classify bd */ |
| 3602 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) |
| 3603 | /* nothing to cleanup after for host commands */ |
| 3604 | return; |
| 3605 | |
| 3606 | /* sanity check */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3607 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
| 3608 | IPW_ERROR("Too many chunks: %i\n", |
| 3609 | le32_to_cpu(bd->u.data.num_chunks)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3610 | /** @todo issue fatal error, it is quite serious situation */ |
| 3611 | return; |
| 3612 | } |
| 3613 | |
| 3614 | /* unmap chunks if any */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3615 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
| 3616 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), |
| 3617 | le16_to_cpu(bd->u.data.chunk_len[i]), |
| 3618 | PCI_DMA_TODEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3619 | if (txq->txb[txq->q.last_used]) { |
| 3620 | ieee80211_txb_free(txq->txb[txq->q.last_used]); |
| 3621 | txq->txb[txq->q.last_used] = NULL; |
| 3622 | } |
| 3623 | } |
| 3624 | } |
| 3625 | |
| 3626 | /** |
| 3627 | * Deallocate DMA queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3628 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3629 | * Empty queue by removing and destroying all BD's. |
| 3630 | * Free all buffers. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3631 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3632 | * @param dev |
| 3633 | * @param q |
| 3634 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3635 | 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] | 3636 | { |
| 3637 | struct clx2_queue *q = &txq->q; |
| 3638 | struct pci_dev *dev = priv->pci_dev; |
| 3639 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3640 | if (q->n_bd == 0) |
| 3641 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3642 | |
| 3643 | /* first, empty all BD's */ |
| 3644 | for (; q->first_empty != q->last_used; |
| 3645 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3646 | ipw_queue_tx_free_tfd(priv, txq); |
| 3647 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3648 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3649 | /* free buffers belonging to queue itself */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3650 | 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] | 3651 | q->dma_addr); |
| 3652 | kfree(txq->txb); |
| 3653 | |
| 3654 | /* 0 fill whole structure */ |
| 3655 | memset(txq, 0, sizeof(*txq)); |
| 3656 | } |
| 3657 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3658 | /** |
| 3659 | * Destroy all DMA queues and structures |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3660 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3661 | * @param priv |
| 3662 | */ |
| 3663 | static void ipw_tx_queue_free(struct ipw_priv *priv) |
| 3664 | { |
| 3665 | /* Tx CMD queue */ |
| 3666 | ipw_queue_tx_free(priv, &priv->txq_cmd); |
| 3667 | |
| 3668 | /* Tx queues */ |
| 3669 | ipw_queue_tx_free(priv, &priv->txq[0]); |
| 3670 | ipw_queue_tx_free(priv, &priv->txq[1]); |
| 3671 | ipw_queue_tx_free(priv, &priv->txq[2]); |
| 3672 | ipw_queue_tx_free(priv, &priv->txq[3]); |
| 3673 | } |
| 3674 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3675 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3676 | { |
| 3677 | /* First 3 bytes are manufacturer */ |
| 3678 | bssid[0] = priv->mac_addr[0]; |
| 3679 | bssid[1] = priv->mac_addr[1]; |
| 3680 | bssid[2] = priv->mac_addr[2]; |
| 3681 | |
| 3682 | /* Last bytes are random */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3683 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3684 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3685 | bssid[0] &= 0xfe; /* clear multicast bit */ |
| 3686 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3687 | } |
| 3688 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3689 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3690 | { |
| 3691 | struct ipw_station_entry entry; |
| 3692 | int i; |
| 3693 | |
| 3694 | for (i = 0; i < priv->num_stations; i++) { |
| 3695 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { |
| 3696 | /* Another node is active in network */ |
| 3697 | priv->missed_adhoc_beacons = 0; |
| 3698 | if (!(priv->config & CFG_STATIC_CHANNEL)) |
| 3699 | /* when other nodes drop out, we drop out */ |
| 3700 | priv->config &= ~CFG_ADHOC_PERSIST; |
| 3701 | |
| 3702 | return i; |
| 3703 | } |
| 3704 | } |
| 3705 | |
| 3706 | if (i == MAX_STATIONS) |
| 3707 | return IPW_INVALID_STATION; |
| 3708 | |
| 3709 | IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid)); |
| 3710 | |
| 3711 | entry.reserved = 0; |
| 3712 | entry.support_mode = 0; |
| 3713 | memcpy(entry.mac_addr, bssid, ETH_ALEN); |
| 3714 | memcpy(priv->stations[i], bssid, ETH_ALEN); |
| 3715 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3716 | &entry, sizeof(entry)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3717 | priv->num_stations++; |
| 3718 | |
| 3719 | return i; |
| 3720 | } |
| 3721 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3722 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3723 | { |
| 3724 | int i; |
| 3725 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3726 | for (i = 0; i < priv->num_stations; i++) |
| 3727 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3728 | return i; |
| 3729 | |
| 3730 | return IPW_INVALID_STATION; |
| 3731 | } |
| 3732 | |
| 3733 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) |
| 3734 | { |
| 3735 | int err; |
| 3736 | |
Hong Liu | 7b99659 | 2005-08-25 17:36:13 +0800 | [diff] [blame] | 3737 | if (priv->status & STATUS_ASSOCIATING) { |
| 3738 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); |
| 3739 | queue_work(priv->workqueue, &priv->disassociate); |
| 3740 | return; |
| 3741 | } |
| 3742 | |
| 3743 | if (!(priv->status & STATUS_ASSOCIATED)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3744 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
| 3745 | return; |
| 3746 | } |
| 3747 | |
| 3748 | IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " " |
| 3749 | "on channel %d.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3750 | MAC_ARG(priv->assoc_request.bssid), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3751 | priv->assoc_request.channel); |
| 3752 | |
| 3753 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); |
| 3754 | priv->status |= STATUS_DISASSOCIATING; |
| 3755 | |
| 3756 | if (quiet) |
| 3757 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; |
| 3758 | else |
| 3759 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 3760 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3761 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 3762 | if (err) { |
| 3763 | IPW_DEBUG_HC("Attempt to send [dis]associate command " |
| 3764 | "failed.\n"); |
| 3765 | return; |
| 3766 | } |
| 3767 | |
| 3768 | } |
| 3769 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3770 | static int ipw_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3771 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3772 | struct ipw_priv *priv = data; |
| 3773 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) |
| 3774 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3775 | ipw_send_disassociate(data, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3776 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3777 | } |
| 3778 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3779 | static void ipw_bg_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3780 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3781 | struct ipw_priv *priv = data; |
| 3782 | down(&priv->sem); |
| 3783 | ipw_disassociate(data); |
| 3784 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3785 | } |
| 3786 | |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 3787 | static void ipw_system_config(void *data) |
| 3788 | { |
| 3789 | struct ipw_priv *priv = data; |
| 3790 | ipw_send_system_config(priv, &priv->sys_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | struct ipw_status_code { |
| 3794 | u16 status; |
| 3795 | const char *reason; |
| 3796 | }; |
| 3797 | |
| 3798 | static const struct ipw_status_code ipw_status_codes[] = { |
| 3799 | {0x00, "Successful"}, |
| 3800 | {0x01, "Unspecified failure"}, |
| 3801 | {0x0A, "Cannot support all requested capabilities in the " |
| 3802 | "Capability information field"}, |
| 3803 | {0x0B, "Reassociation denied due to inability to confirm that " |
| 3804 | "association exists"}, |
| 3805 | {0x0C, "Association denied due to reason outside the scope of this " |
| 3806 | "standard"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3807 | {0x0D, |
| 3808 | "Responding station does not support the specified authentication " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3809 | "algorithm"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3810 | {0x0E, |
| 3811 | "Received an Authentication frame with authentication sequence " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3812 | "transaction sequence number out of expected sequence"}, |
| 3813 | {0x0F, "Authentication rejected because of challenge failure"}, |
| 3814 | {0x10, "Authentication rejected due to timeout waiting for next " |
| 3815 | "frame in sequence"}, |
| 3816 | {0x11, "Association denied because AP is unable to handle additional " |
| 3817 | "associated stations"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3818 | {0x12, |
| 3819 | "Association denied due to requesting station not supporting all " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3820 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3821 | {0x13, |
| 3822 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3823 | "short preamble operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3824 | {0x14, |
| 3825 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3826 | "PBCC encoding"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3827 | {0x15, |
| 3828 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3829 | "channel agility"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3830 | {0x19, |
| 3831 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3832 | "short slot operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3833 | {0x1A, |
| 3834 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3835 | "DSSS-OFDM operation"}, |
| 3836 | {0x28, "Invalid Information Element"}, |
| 3837 | {0x29, "Group Cipher is not valid"}, |
| 3838 | {0x2A, "Pairwise Cipher is not valid"}, |
| 3839 | {0x2B, "AKMP is not valid"}, |
| 3840 | {0x2C, "Unsupported RSN IE version"}, |
| 3841 | {0x2D, "Invalid RSN IE Capabilities"}, |
| 3842 | {0x2E, "Cipher suite is rejected per security policy"}, |
| 3843 | }; |
| 3844 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 3845 | #ifdef CONFIG_IPW2200_DEBUG |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3846 | static const char *ipw_get_status_code(u16 status) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3847 | { |
| 3848 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3849 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3850 | if (ipw_status_codes[i].status == (status & 0xff)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3851 | return ipw_status_codes[i].reason; |
| 3852 | return "Unknown status value."; |
| 3853 | } |
| 3854 | #endif |
| 3855 | |
| 3856 | static void inline average_init(struct average *avg) |
| 3857 | { |
| 3858 | memset(avg, 0, sizeof(*avg)); |
| 3859 | } |
| 3860 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3861 | static void average_add(struct average *avg, s16 val) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3862 | { |
| 3863 | avg->sum -= avg->entries[avg->pos]; |
| 3864 | avg->sum += val; |
| 3865 | avg->entries[avg->pos++] = val; |
| 3866 | if (unlikely(avg->pos == AVG_ENTRIES)) { |
| 3867 | avg->init = 1; |
| 3868 | avg->pos = 0; |
| 3869 | } |
| 3870 | } |
| 3871 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3872 | static s16 average_value(struct average *avg) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3873 | { |
| 3874 | if (!unlikely(avg->init)) { |
| 3875 | if (avg->pos) |
| 3876 | return avg->sum / avg->pos; |
| 3877 | return 0; |
| 3878 | } |
| 3879 | |
| 3880 | return avg->sum / AVG_ENTRIES; |
| 3881 | } |
| 3882 | |
| 3883 | static void ipw_reset_stats(struct ipw_priv *priv) |
| 3884 | { |
| 3885 | u32 len = sizeof(u32); |
| 3886 | |
| 3887 | priv->quality = 0; |
| 3888 | |
| 3889 | average_init(&priv->average_missed_beacons); |
| 3890 | average_init(&priv->average_rssi); |
| 3891 | average_init(&priv->average_noise); |
| 3892 | |
| 3893 | priv->last_rate = 0; |
| 3894 | priv->last_missed_beacons = 0; |
| 3895 | priv->last_rx_packets = 0; |
| 3896 | priv->last_tx_packets = 0; |
| 3897 | priv->last_tx_failures = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3898 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3899 | /* Firmware managed, reset only when NIC is restarted, so we have to |
| 3900 | * normalize on the current value */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3901 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3902 | &priv->last_rx_err, &len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3903 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3904 | &priv->last_tx_failures, &len); |
| 3905 | |
| 3906 | /* Driver managed, reset with each association */ |
| 3907 | priv->missed_adhoc_beacons = 0; |
| 3908 | priv->missed_beacons = 0; |
| 3909 | priv->tx_packets = 0; |
| 3910 | priv->rx_packets = 0; |
| 3911 | |
| 3912 | } |
| 3913 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3914 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3915 | { |
| 3916 | u32 i = 0x80000000; |
| 3917 | u32 mask = priv->rates_mask; |
| 3918 | /* If currently associated in B mode, restrict the maximum |
| 3919 | * rate match to B rates */ |
| 3920 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
| 3921 | mask &= IEEE80211_CCK_RATES_MASK; |
| 3922 | |
| 3923 | /* TODO: Verify that the rate is supported by the current rates |
| 3924 | * list. */ |
| 3925 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3926 | while (i && !(mask & i)) |
| 3927 | i >>= 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3928 | switch (i) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3929 | case IEEE80211_CCK_RATE_1MB_MASK: |
| 3930 | return 1000000; |
| 3931 | case IEEE80211_CCK_RATE_2MB_MASK: |
| 3932 | return 2000000; |
| 3933 | case IEEE80211_CCK_RATE_5MB_MASK: |
| 3934 | return 5500000; |
| 3935 | case IEEE80211_OFDM_RATE_6MB_MASK: |
| 3936 | return 6000000; |
| 3937 | case IEEE80211_OFDM_RATE_9MB_MASK: |
| 3938 | return 9000000; |
| 3939 | case IEEE80211_CCK_RATE_11MB_MASK: |
| 3940 | return 11000000; |
| 3941 | case IEEE80211_OFDM_RATE_12MB_MASK: |
| 3942 | return 12000000; |
| 3943 | case IEEE80211_OFDM_RATE_18MB_MASK: |
| 3944 | return 18000000; |
| 3945 | case IEEE80211_OFDM_RATE_24MB_MASK: |
| 3946 | return 24000000; |
| 3947 | case IEEE80211_OFDM_RATE_36MB_MASK: |
| 3948 | return 36000000; |
| 3949 | case IEEE80211_OFDM_RATE_48MB_MASK: |
| 3950 | return 48000000; |
| 3951 | case IEEE80211_OFDM_RATE_54MB_MASK: |
| 3952 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3953 | } |
| 3954 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3955 | if (priv->ieee->mode == IEEE_B) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3956 | return 11000000; |
| 3957 | else |
| 3958 | return 54000000; |
| 3959 | } |
| 3960 | |
| 3961 | static u32 ipw_get_current_rate(struct ipw_priv *priv) |
| 3962 | { |
| 3963 | u32 rate, len = sizeof(rate); |
| 3964 | int err; |
| 3965 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3966 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3967 | return 0; |
| 3968 | |
| 3969 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3970 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3971 | &len); |
| 3972 | if (err) { |
| 3973 | IPW_DEBUG_INFO("failed querying ordinals.\n"); |
| 3974 | return 0; |
| 3975 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3976 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3977 | return ipw_get_max_rate(priv); |
| 3978 | |
| 3979 | switch (rate) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3980 | case IPW_TX_RATE_1MB: |
| 3981 | return 1000000; |
| 3982 | case IPW_TX_RATE_2MB: |
| 3983 | return 2000000; |
| 3984 | case IPW_TX_RATE_5MB: |
| 3985 | return 5500000; |
| 3986 | case IPW_TX_RATE_6MB: |
| 3987 | return 6000000; |
| 3988 | case IPW_TX_RATE_9MB: |
| 3989 | return 9000000; |
| 3990 | case IPW_TX_RATE_11MB: |
| 3991 | return 11000000; |
| 3992 | case IPW_TX_RATE_12MB: |
| 3993 | return 12000000; |
| 3994 | case IPW_TX_RATE_18MB: |
| 3995 | return 18000000; |
| 3996 | case IPW_TX_RATE_24MB: |
| 3997 | return 24000000; |
| 3998 | case IPW_TX_RATE_36MB: |
| 3999 | return 36000000; |
| 4000 | case IPW_TX_RATE_48MB: |
| 4001 | return 48000000; |
| 4002 | case IPW_TX_RATE_54MB: |
| 4003 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | return 0; |
| 4007 | } |
| 4008 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4009 | #define IPW_STATS_INTERVAL (2 * HZ) |
| 4010 | static void ipw_gather_stats(struct ipw_priv *priv) |
| 4011 | { |
| 4012 | u32 rx_err, rx_err_delta, rx_packets_delta; |
| 4013 | u32 tx_failures, tx_failures_delta, tx_packets_delta; |
| 4014 | u32 missed_beacons_percent, missed_beacons_delta; |
| 4015 | u32 quality = 0; |
| 4016 | u32 len = sizeof(u32); |
| 4017 | s16 rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4018 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4019 | rate_quality; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4020 | u32 max_rate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4021 | |
| 4022 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 4023 | priv->quality = 0; |
| 4024 | return; |
| 4025 | } |
| 4026 | |
| 4027 | /* Update the statistics */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4028 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4029 | &priv->missed_beacons, &len); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4030 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4031 | priv->last_missed_beacons = priv->missed_beacons; |
| 4032 | if (priv->assoc_request.beacon_interval) { |
| 4033 | missed_beacons_percent = missed_beacons_delta * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4034 | (HZ * priv->assoc_request.beacon_interval) / |
| 4035 | (IPW_STATS_INTERVAL * 10); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4036 | } else { |
| 4037 | missed_beacons_percent = 0; |
| 4038 | } |
| 4039 | average_add(&priv->average_missed_beacons, missed_beacons_percent); |
| 4040 | |
| 4041 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); |
| 4042 | rx_err_delta = rx_err - priv->last_rx_err; |
| 4043 | priv->last_rx_err = rx_err; |
| 4044 | |
| 4045 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); |
| 4046 | tx_failures_delta = tx_failures - priv->last_tx_failures; |
| 4047 | priv->last_tx_failures = tx_failures; |
| 4048 | |
| 4049 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; |
| 4050 | priv->last_rx_packets = priv->rx_packets; |
| 4051 | |
| 4052 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; |
| 4053 | priv->last_tx_packets = priv->tx_packets; |
| 4054 | |
| 4055 | /* Calculate quality based on the following: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4056 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4057 | * Missed beacon: 100% = 0, 0% = 70% missed |
| 4058 | * Rate: 60% = 1Mbs, 100% = Max |
| 4059 | * Rx and Tx errors represent a straight % of total Rx/Tx |
| 4060 | * RSSI: 100% = > -50, 0% = < -80 |
| 4061 | * Rx errors: 100% = 0, 0% = 50% missed |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4062 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4063 | * The lowest computed quality is used. |
| 4064 | * |
| 4065 | */ |
| 4066 | #define BEACON_THRESHOLD 5 |
| 4067 | beacon_quality = 100 - missed_beacons_percent; |
| 4068 | if (beacon_quality < BEACON_THRESHOLD) |
| 4069 | beacon_quality = 0; |
| 4070 | else |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4071 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4072 | (100 - BEACON_THRESHOLD); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4073 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4074 | beacon_quality, missed_beacons_percent); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4075 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4076 | priv->last_rate = ipw_get_current_rate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4077 | max_rate = ipw_get_max_rate(priv); |
| 4078 | rate_quality = priv->last_rate * 40 / max_rate + 60; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4079 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
| 4080 | rate_quality, priv->last_rate / 1000000); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4081 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4082 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4083 | rx_quality = 100 - (rx_err_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4084 | (rx_packets_delta + rx_err_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4085 | else |
| 4086 | rx_quality = 100; |
| 4087 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", |
| 4088 | rx_quality, rx_err_delta, rx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4089 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4090 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4091 | tx_quality = 100 - (tx_failures_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4092 | (tx_packets_delta + tx_failures_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4093 | else |
| 4094 | tx_quality = 100; |
| 4095 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", |
| 4096 | tx_quality, tx_failures_delta, tx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4097 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4098 | rssi = average_value(&priv->average_rssi); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4099 | signal_quality = |
| 4100 | (100 * |
| 4101 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4102 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - |
| 4103 | (priv->ieee->perfect_rssi - rssi) * |
| 4104 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + |
| 4105 | 62 * (priv->ieee->perfect_rssi - rssi))) / |
| 4106 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 4107 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); |
| 4108 | if (signal_quality > 100) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4109 | signal_quality = 100; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4110 | else if (signal_quality < 1) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4111 | signal_quality = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4112 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4113 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
| 4114 | signal_quality, rssi); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4115 | |
| 4116 | quality = min(beacon_quality, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4117 | min(rate_quality, |
| 4118 | min(tx_quality, min(rx_quality, signal_quality)))); |
| 4119 | if (quality == beacon_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4120 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
| 4121 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4122 | if (quality == rate_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4123 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
| 4124 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4125 | if (quality == tx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4126 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
| 4127 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4128 | if (quality == rx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4129 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
| 4130 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4131 | if (quality == signal_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4132 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
| 4133 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4134 | |
| 4135 | priv->quality = quality; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4136 | |
| 4137 | queue_delayed_work(priv->workqueue, &priv->gather_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4138 | IPW_STATS_INTERVAL); |
| 4139 | } |
| 4140 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4141 | static void ipw_bg_gather_stats(void *data) |
| 4142 | { |
| 4143 | struct ipw_priv *priv = data; |
| 4144 | down(&priv->sem); |
| 4145 | ipw_gather_stats(data); |
| 4146 | up(&priv->sem); |
| 4147 | } |
| 4148 | |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4149 | /* Missed beacon behavior: |
| 4150 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. |
| 4151 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. |
| 4152 | * Above disassociate threshold, give up and stop scanning. |
| 4153 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4154 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4155 | int missed_count) |
| 4156 | { |
| 4157 | priv->notif_missed_beacons = missed_count; |
| 4158 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4159 | if (missed_count > priv->disassociate_threshold && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4160 | priv->status & STATUS_ASSOCIATED) { |
| 4161 | /* If associated and we've hit the missed |
| 4162 | * beacon threshold, disassociate, turn |
| 4163 | * off roaming, and abort any active scans */ |
| 4164 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4165 | IPW_DL_STATE | IPW_DL_ASSOC, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4166 | "Missed beacon: %d - disassociate\n", missed_count); |
| 4167 | priv->status &= ~STATUS_ROAMING; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4168 | if (priv->status & STATUS_SCANNING) { |
| 4169 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 4170 | IPW_DL_STATE, |
| 4171 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4172 | queue_work(priv->workqueue, &priv->abort_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4173 | } |
| 4174 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4175 | queue_work(priv->workqueue, &priv->disassociate); |
| 4176 | return; |
| 4177 | } |
| 4178 | |
| 4179 | if (priv->status & STATUS_ROAMING) { |
| 4180 | /* If we are currently roaming, then just |
| 4181 | * print a debug statement... */ |
| 4182 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4183 | "Missed beacon: %d - roam in progress\n", |
| 4184 | missed_count); |
| 4185 | return; |
| 4186 | } |
| 4187 | |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4188 | if (missed_count > priv->roaming_threshold && |
| 4189 | missed_count <= priv->disassociate_threshold) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4190 | /* If we are not already roaming, set the ROAM |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4191 | * bit in the status and kick off a scan. |
| 4192 | * This can happen several times before we reach |
| 4193 | * disassociate_threshold. */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4194 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4195 | "Missed beacon: %d - initiate " |
| 4196 | "roaming\n", missed_count); |
| 4197 | if (!(priv->status & STATUS_ROAMING)) { |
| 4198 | priv->status |= STATUS_ROAMING; |
| 4199 | if (!(priv->status & STATUS_SCANNING)) |
| 4200 | queue_work(priv->workqueue, |
| 4201 | &priv->request_scan); |
| 4202 | } |
| 4203 | return; |
| 4204 | } |
| 4205 | |
| 4206 | if (priv->status & STATUS_SCANNING) { |
| 4207 | /* Stop scan to keep fw from getting |
| 4208 | * stuck (only if we aren't roaming -- |
| 4209 | * otherwise we'll never scan more than 2 or 3 |
| 4210 | * channels..) */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4211 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
| 4212 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4213 | queue_work(priv->workqueue, &priv->abort_scan); |
| 4214 | } |
| 4215 | |
| 4216 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); |
| 4217 | |
| 4218 | } |
| 4219 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4220 | /** |
| 4221 | * Handle host notification packet. |
| 4222 | * Called from interrupt routine |
| 4223 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 4224 | static void ipw_rx_notification(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4225 | struct ipw_rx_notification *notif) |
| 4226 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4227 | notif->size = le16_to_cpu(notif->size); |
| 4228 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4229 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4230 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4231 | switch (notif->subtype) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4232 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
| 4233 | struct notif_association *assoc = ¬if->u.assoc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4234 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4235 | switch (assoc->state) { |
| 4236 | case CMAS_ASSOCIATED:{ |
| 4237 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4238 | IPW_DL_ASSOC, |
| 4239 | "associated: '%s' " MAC_FMT |
| 4240 | " \n", |
| 4241 | escape_essid(priv->essid, |
| 4242 | priv->essid_len), |
| 4243 | MAC_ARG(priv->bssid)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4244 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4245 | switch (priv->ieee->iw_mode) { |
| 4246 | case IW_MODE_INFRA: |
| 4247 | memcpy(priv->ieee->bssid, |
| 4248 | priv->bssid, ETH_ALEN); |
| 4249 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4250 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4251 | case IW_MODE_ADHOC: |
| 4252 | memcpy(priv->ieee->bssid, |
| 4253 | priv->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4254 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4255 | /* clear out the station table */ |
| 4256 | priv->num_stations = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4257 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4258 | IPW_DEBUG_ASSOC |
| 4259 | ("queueing adhoc check\n"); |
| 4260 | queue_delayed_work(priv-> |
| 4261 | workqueue, |
| 4262 | &priv-> |
| 4263 | adhoc_check, |
| 4264 | priv-> |
| 4265 | assoc_request. |
| 4266 | beacon_interval); |
| 4267 | break; |
| 4268 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4269 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4270 | priv->status &= ~STATUS_ASSOCIATING; |
| 4271 | priv->status |= STATUS_ASSOCIATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 4272 | queue_work(priv->workqueue, |
| 4273 | &priv->system_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4274 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4275 | #ifdef CONFIG_IPW_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4276 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
| 4277 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl)) |
| 4278 | if ((priv->status & STATUS_AUTH) && |
| 4279 | (IPW_GET_PACKET_STYPE(¬if->u.raw) |
| 4280 | == IEEE80211_STYPE_ASSOC_RESP)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4281 | if ((sizeof |
| 4282 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4283 | ieee80211_assoc_response) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4284 | <= notif->size) |
| 4285 | && (notif->size <= 2314)) { |
| 4286 | struct |
| 4287 | ieee80211_rx_stats |
| 4288 | stats = { |
| 4289 | .len = |
| 4290 | notif-> |
| 4291 | size - 1, |
| 4292 | }; |
| 4293 | |
| 4294 | IPW_DEBUG_QOS |
| 4295 | ("QoS Associate " |
| 4296 | "size %d\n", |
| 4297 | notif->size); |
| 4298 | ieee80211_rx_mgt(priv-> |
| 4299 | ieee, |
| 4300 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4301 | ieee80211_hdr_4addr |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4302 | *) |
| 4303 | ¬if->u.raw, &stats); |
| 4304 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4305 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4306 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4307 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4308 | schedule_work(&priv->link_up); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4309 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4310 | break; |
| 4311 | } |
| 4312 | |
| 4313 | case CMAS_AUTHENTICATED:{ |
| 4314 | if (priv-> |
| 4315 | status & (STATUS_ASSOCIATED | |
| 4316 | STATUS_AUTH)) { |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 4317 | #ifdef CONFIG_IPW2200_DEBUG |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4318 | struct notif_authenticate *auth |
| 4319 | = ¬if->u.auth; |
| 4320 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4321 | IPW_DL_STATE | |
| 4322 | IPW_DL_ASSOC, |
| 4323 | "deauthenticated: '%s' " |
| 4324 | MAC_FMT |
| 4325 | ": (0x%04X) - %s \n", |
| 4326 | escape_essid(priv-> |
| 4327 | essid, |
| 4328 | priv-> |
| 4329 | essid_len), |
| 4330 | MAC_ARG(priv->bssid), |
| 4331 | ntohs(auth->status), |
| 4332 | ipw_get_status_code |
| 4333 | (ntohs |
| 4334 | (auth->status))); |
| 4335 | #endif |
| 4336 | |
| 4337 | priv->status &= |
| 4338 | ~(STATUS_ASSOCIATING | |
| 4339 | STATUS_AUTH | |
| 4340 | STATUS_ASSOCIATED); |
| 4341 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4342 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4343 | break; |
| 4344 | } |
| 4345 | |
| 4346 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4347 | IPW_DL_ASSOC, |
| 4348 | "authenticated: '%s' " MAC_FMT |
| 4349 | "\n", |
| 4350 | escape_essid(priv->essid, |
| 4351 | priv->essid_len), |
| 4352 | MAC_ARG(priv->bssid)); |
| 4353 | break; |
| 4354 | } |
| 4355 | |
| 4356 | case CMAS_INIT:{ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4357 | if (priv->status & STATUS_AUTH) { |
| 4358 | struct |
| 4359 | ieee80211_assoc_response |
| 4360 | *resp; |
| 4361 | resp = |
| 4362 | (struct |
| 4363 | ieee80211_assoc_response |
| 4364 | *)¬if->u.raw; |
| 4365 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4366 | IPW_DL_STATE | |
| 4367 | IPW_DL_ASSOC, |
| 4368 | "association failed (0x%04X): %s\n", |
| 4369 | ntohs(resp->status), |
| 4370 | ipw_get_status_code |
| 4371 | (ntohs |
| 4372 | (resp->status))); |
| 4373 | } |
| 4374 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4375 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4376 | IPW_DL_ASSOC, |
| 4377 | "disassociated: '%s' " MAC_FMT |
| 4378 | " \n", |
| 4379 | escape_essid(priv->essid, |
| 4380 | priv->essid_len), |
| 4381 | MAC_ARG(priv->bssid)); |
| 4382 | |
| 4383 | priv->status &= |
| 4384 | ~(STATUS_DISASSOCIATING | |
| 4385 | STATUS_ASSOCIATING | |
| 4386 | STATUS_ASSOCIATED | STATUS_AUTH); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4387 | if (priv->assoc_network |
| 4388 | && (priv->assoc_network-> |
| 4389 | capability & |
| 4390 | WLAN_CAPABILITY_IBSS)) |
| 4391 | ipw_remove_current_network |
| 4392 | (priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4393 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4394 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4395 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4396 | break; |
| 4397 | } |
| 4398 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4399 | case CMAS_RX_ASSOC_RESP: |
| 4400 | break; |
| 4401 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4402 | default: |
| 4403 | IPW_ERROR("assoc: unknown (%d)\n", |
| 4404 | assoc->state); |
| 4405 | break; |
| 4406 | } |
| 4407 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4408 | break; |
| 4409 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4410 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4411 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
| 4412 | struct notif_authenticate *auth = ¬if->u.auth; |
| 4413 | switch (auth->state) { |
| 4414 | case CMAS_AUTHENTICATED: |
| 4415 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4416 | "authenticated: '%s' " MAC_FMT " \n", |
| 4417 | escape_essid(priv->essid, |
| 4418 | priv->essid_len), |
| 4419 | MAC_ARG(priv->bssid)); |
| 4420 | priv->status |= STATUS_AUTH; |
| 4421 | break; |
| 4422 | |
| 4423 | case CMAS_INIT: |
| 4424 | if (priv->status & STATUS_AUTH) { |
| 4425 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4426 | IPW_DL_ASSOC, |
| 4427 | "authentication failed (0x%04X): %s\n", |
| 4428 | ntohs(auth->status), |
| 4429 | ipw_get_status_code(ntohs |
| 4430 | (auth-> |
| 4431 | status))); |
| 4432 | } |
| 4433 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4434 | IPW_DL_ASSOC, |
| 4435 | "deauthenticated: '%s' " MAC_FMT "\n", |
| 4436 | escape_essid(priv->essid, |
| 4437 | priv->essid_len), |
| 4438 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4439 | |
| 4440 | priv->status &= ~(STATUS_ASSOCIATING | |
| 4441 | STATUS_AUTH | |
| 4442 | STATUS_ASSOCIATED); |
| 4443 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4444 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4445 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4446 | |
| 4447 | case CMAS_TX_AUTH_SEQ_1: |
| 4448 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4449 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); |
| 4450 | break; |
| 4451 | case CMAS_RX_AUTH_SEQ_2: |
| 4452 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4453 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); |
| 4454 | break; |
| 4455 | case CMAS_AUTH_SEQ_1_PASS: |
| 4456 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4457 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); |
| 4458 | break; |
| 4459 | case CMAS_AUTH_SEQ_1_FAIL: |
| 4460 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4461 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); |
| 4462 | break; |
| 4463 | case CMAS_TX_AUTH_SEQ_3: |
| 4464 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4465 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); |
| 4466 | break; |
| 4467 | case CMAS_RX_AUTH_SEQ_4: |
| 4468 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4469 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); |
| 4470 | break; |
| 4471 | case CMAS_AUTH_SEQ_2_PASS: |
| 4472 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4473 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); |
| 4474 | break; |
| 4475 | case CMAS_AUTH_SEQ_2_FAIL: |
| 4476 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4477 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); |
| 4478 | break; |
| 4479 | case CMAS_TX_ASSOC: |
| 4480 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4481 | IPW_DL_ASSOC, "TX_ASSOC\n"); |
| 4482 | break; |
| 4483 | case CMAS_RX_ASSOC_RESP: |
| 4484 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4485 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4486 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4487 | break; |
| 4488 | case CMAS_ASSOCIATED: |
| 4489 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4490 | IPW_DL_ASSOC, "ASSOCIATED\n"); |
| 4491 | break; |
| 4492 | default: |
| 4493 | IPW_DEBUG_NOTIF("auth: failure - %d\n", |
| 4494 | auth->state); |
| 4495 | break; |
| 4496 | } |
| 4497 | break; |
| 4498 | } |
| 4499 | |
| 4500 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
| 4501 | struct notif_channel_result *x = |
| 4502 | ¬if->u.channel_result; |
| 4503 | |
| 4504 | if (notif->size == sizeof(*x)) { |
| 4505 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
| 4506 | x->channel_num); |
| 4507 | } else { |
| 4508 | IPW_DEBUG_SCAN("Scan result of wrong size %d " |
| 4509 | "(should be %zd)\n", |
| 4510 | notif->size, sizeof(*x)); |
| 4511 | } |
| 4512 | break; |
| 4513 | } |
| 4514 | |
| 4515 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
| 4516 | struct notif_scan_complete *x = ¬if->u.scan_complete; |
| 4517 | if (notif->size == sizeof(*x)) { |
| 4518 | IPW_DEBUG_SCAN |
| 4519 | ("Scan completed: type %d, %d channels, " |
| 4520 | "%d status\n", x->scan_type, |
| 4521 | x->num_channels, x->status); |
| 4522 | } else { |
| 4523 | IPW_ERROR("Scan completed of wrong size %d " |
| 4524 | "(should be %zd)\n", |
| 4525 | notif->size, sizeof(*x)); |
| 4526 | } |
| 4527 | |
| 4528 | priv->status &= |
| 4529 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 4530 | |
James Ketrenos | a0e04ab | 2005-08-25 00:49:43 -0500 | [diff] [blame] | 4531 | wake_up_interruptible(&priv->wait_state); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4532 | cancel_delayed_work(&priv->scan_check); |
| 4533 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4534 | if (priv->status & STATUS_EXIT_PENDING) |
| 4535 | break; |
| 4536 | |
| 4537 | priv->ieee->scans++; |
| 4538 | |
| 4539 | #ifdef CONFIG_IPW2200_MONITOR |
| 4540 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4541 | priv->status |= STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4542 | queue_work(priv->workqueue, |
| 4543 | &priv->request_scan); |
| 4544 | break; |
| 4545 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4546 | priv->status &= ~STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4547 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 4548 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4549 | if (!(priv->status & (STATUS_ASSOCIATED | |
| 4550 | STATUS_ASSOCIATING | |
| 4551 | STATUS_ROAMING | |
| 4552 | STATUS_DISASSOCIATING))) |
| 4553 | queue_work(priv->workqueue, &priv->associate); |
| 4554 | else if (priv->status & STATUS_ROAMING) { |
Ben Cahill | e758256 | 2005-10-06 15:34:41 -0500 | [diff] [blame] | 4555 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
| 4556 | /* If a scan completed and we are in roam mode, then |
| 4557 | * the scan that completed was the one requested as a |
| 4558 | * result of entering roam... so, schedule the |
| 4559 | * roam work */ |
| 4560 | queue_work(priv->workqueue, |
| 4561 | &priv->roam); |
| 4562 | else |
| 4563 | /* Don't schedule if we aborted the scan */ |
| 4564 | priv->status &= ~STATUS_ROAMING; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4565 | } else if (priv->status & STATUS_SCAN_PENDING) |
| 4566 | queue_work(priv->workqueue, |
| 4567 | &priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4568 | else if (priv->config & CFG_BACKGROUND_SCAN |
| 4569 | && priv->status & STATUS_ASSOCIATED) |
| 4570 | queue_delayed_work(priv->workqueue, |
| 4571 | &priv->request_scan, HZ); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4572 | break; |
| 4573 | } |
| 4574 | |
| 4575 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
| 4576 | struct notif_frag_length *x = ¬if->u.frag_len; |
| 4577 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4578 | if (notif->size == sizeof(*x)) |
| 4579 | IPW_ERROR("Frag length: %d\n", |
| 4580 | le16_to_cpu(x->frag_length)); |
| 4581 | else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4582 | IPW_ERROR("Frag length of wrong size %d " |
| 4583 | "(should be %zd)\n", |
| 4584 | notif->size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4585 | break; |
| 4586 | } |
| 4587 | |
| 4588 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
| 4589 | struct notif_link_deterioration *x = |
| 4590 | ¬if->u.link_deterioration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4591 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4592 | if (notif->size == sizeof(*x)) { |
| 4593 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4594 | "link deterioration: '%s' " MAC_FMT |
| 4595 | " \n", escape_essid(priv->essid, |
| 4596 | priv->essid_len), |
| 4597 | MAC_ARG(priv->bssid)); |
| 4598 | memcpy(&priv->last_link_deterioration, x, |
| 4599 | sizeof(*x)); |
| 4600 | } else { |
| 4601 | IPW_ERROR("Link Deterioration of wrong size %d " |
| 4602 | "(should be %zd)\n", |
| 4603 | notif->size, sizeof(*x)); |
| 4604 | } |
| 4605 | break; |
| 4606 | } |
| 4607 | |
| 4608 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
| 4609 | IPW_ERROR("Dino config\n"); |
| 4610 | if (priv->hcmd |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4611 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4612 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4613 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4614 | break; |
| 4615 | } |
| 4616 | |
| 4617 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
| 4618 | struct notif_beacon_state *x = ¬if->u.beacon_state; |
| 4619 | if (notif->size != sizeof(*x)) { |
| 4620 | IPW_ERROR |
| 4621 | ("Beacon state of wrong size %d (should " |
| 4622 | "be %zd)\n", notif->size, sizeof(*x)); |
| 4623 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4624 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4625 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4626 | if (le32_to_cpu(x->state) == |
| 4627 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) |
| 4628 | ipw_handle_missed_beacon(priv, |
| 4629 | le32_to_cpu(x-> |
| 4630 | number)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4631 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4632 | break; |
| 4633 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4634 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4635 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
| 4636 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; |
| 4637 | if (notif->size == sizeof(*x)) { |
| 4638 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
| 4639 | "0x%02x station %d\n", |
| 4640 | x->key_state, x->security_type, |
| 4641 | x->station_index); |
| 4642 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4643 | } |
| 4644 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4645 | IPW_ERROR |
| 4646 | ("TGi Tx Key of wrong size %d (should be %zd)\n", |
| 4647 | notif->size, sizeof(*x)); |
| 4648 | break; |
| 4649 | } |
| 4650 | |
| 4651 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
| 4652 | struct notif_calibration *x = ¬if->u.calibration; |
| 4653 | |
| 4654 | if (notif->size == sizeof(*x)) { |
| 4655 | memcpy(&priv->calib, x, sizeof(*x)); |
| 4656 | IPW_DEBUG_INFO("TODO: Calibration\n"); |
| 4657 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4658 | } |
| 4659 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4660 | IPW_ERROR |
| 4661 | ("Calibration of wrong size %d (should be %zd)\n", |
| 4662 | notif->size, sizeof(*x)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4663 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4664 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4665 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4666 | case HOST_NOTIFICATION_NOISE_STATS:{ |
| 4667 | if (notif->size == sizeof(u32)) { |
| 4668 | priv->last_noise = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4669 | (u8) (le32_to_cpu(notif->u.noise.value) & |
| 4670 | 0xff); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4671 | average_add(&priv->average_noise, |
| 4672 | priv->last_noise); |
| 4673 | break; |
| 4674 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4675 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4676 | IPW_ERROR |
| 4677 | ("Noise stat is wrong size %d (should be %zd)\n", |
| 4678 | notif->size, sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4679 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4680 | } |
| 4681 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4682 | default: |
| 4683 | IPW_ERROR("Unknown notification: " |
| 4684 | "subtype=%d,flags=0x%2x,size=%d\n", |
| 4685 | notif->subtype, notif->flags, notif->size); |
| 4686 | } |
| 4687 | } |
| 4688 | |
| 4689 | /** |
| 4690 | * Destroys all DMA structures and initialise them again |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4691 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4692 | * @param priv |
| 4693 | * @return error code |
| 4694 | */ |
| 4695 | static int ipw_queue_reset(struct ipw_priv *priv) |
| 4696 | { |
| 4697 | int rc = 0; |
| 4698 | /** @todo customize queue sizes */ |
| 4699 | int nTx = 64, nTxCmd = 8; |
| 4700 | ipw_tx_queue_free(priv); |
| 4701 | /* Tx CMD queue */ |
| 4702 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4703 | IPW_TX_CMD_QUEUE_READ_INDEX, |
| 4704 | IPW_TX_CMD_QUEUE_WRITE_INDEX, |
| 4705 | IPW_TX_CMD_QUEUE_BD_BASE, |
| 4706 | IPW_TX_CMD_QUEUE_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4707 | if (rc) { |
| 4708 | IPW_ERROR("Tx Cmd queue init failed\n"); |
| 4709 | goto error; |
| 4710 | } |
| 4711 | /* Tx queue(s) */ |
| 4712 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4713 | IPW_TX_QUEUE_0_READ_INDEX, |
| 4714 | IPW_TX_QUEUE_0_WRITE_INDEX, |
| 4715 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4716 | if (rc) { |
| 4717 | IPW_ERROR("Tx 0 queue init failed\n"); |
| 4718 | goto error; |
| 4719 | } |
| 4720 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4721 | IPW_TX_QUEUE_1_READ_INDEX, |
| 4722 | IPW_TX_QUEUE_1_WRITE_INDEX, |
| 4723 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4724 | if (rc) { |
| 4725 | IPW_ERROR("Tx 1 queue init failed\n"); |
| 4726 | goto error; |
| 4727 | } |
| 4728 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4729 | IPW_TX_QUEUE_2_READ_INDEX, |
| 4730 | IPW_TX_QUEUE_2_WRITE_INDEX, |
| 4731 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4732 | if (rc) { |
| 4733 | IPW_ERROR("Tx 2 queue init failed\n"); |
| 4734 | goto error; |
| 4735 | } |
| 4736 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4737 | IPW_TX_QUEUE_3_READ_INDEX, |
| 4738 | IPW_TX_QUEUE_3_WRITE_INDEX, |
| 4739 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4740 | if (rc) { |
| 4741 | IPW_ERROR("Tx 3 queue init failed\n"); |
| 4742 | goto error; |
| 4743 | } |
| 4744 | /* statistics */ |
| 4745 | priv->rx_bufs_min = 0; |
| 4746 | priv->rx_pend_max = 0; |
| 4747 | return rc; |
| 4748 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4749 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4750 | ipw_tx_queue_free(priv); |
| 4751 | return rc; |
| 4752 | } |
| 4753 | |
| 4754 | /** |
| 4755 | * Reclaim Tx queue entries no more used by NIC. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4756 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4757 | * When FW adwances 'R' index, all entries between old and |
| 4758 | * new 'R' index need to be reclaimed. As result, some free space |
| 4759 | * forms. If there is enough free space (> low mark), wake Tx queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4760 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4761 | * @note Need to protect against garbage in 'R' index |
| 4762 | * @param priv |
| 4763 | * @param txq |
| 4764 | * @param qindex |
| 4765 | * @return Number of used entries remains in the queue |
| 4766 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4767 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4768 | struct clx2_tx_queue *txq, int qindex) |
| 4769 | { |
| 4770 | u32 hw_tail; |
| 4771 | int used; |
| 4772 | struct clx2_queue *q = &txq->q; |
| 4773 | |
| 4774 | hw_tail = ipw_read32(priv, q->reg_r); |
| 4775 | if (hw_tail >= q->n_bd) { |
| 4776 | IPW_ERROR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4777 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
| 4778 | hw_tail, q->n_bd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4779 | goto done; |
| 4780 | } |
| 4781 | for (; q->last_used != hw_tail; |
| 4782 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 4783 | ipw_queue_tx_free_tfd(priv, txq); |
| 4784 | priv->tx_packets++; |
| 4785 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4786 | done: |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 4787 | if ((ipw_queue_space(q) > q->low_mark) && |
| 4788 | (qindex >= 0) && |
| 4789 | (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev)) |
| 4790 | netif_wake_queue(priv->net_dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4791 | used = q->first_empty - q->last_used; |
| 4792 | if (used < 0) |
| 4793 | used += q->n_bd; |
| 4794 | |
| 4795 | return used; |
| 4796 | } |
| 4797 | |
| 4798 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 4799 | int len, int sync) |
| 4800 | { |
| 4801 | struct clx2_tx_queue *txq = &priv->txq_cmd; |
| 4802 | struct clx2_queue *q = &txq->q; |
| 4803 | struct tfd_frame *tfd; |
| 4804 | |
| 4805 | if (ipw_queue_space(q) < (sync ? 1 : 2)) { |
| 4806 | IPW_ERROR("No space for Tx\n"); |
| 4807 | return -EBUSY; |
| 4808 | } |
| 4809 | |
| 4810 | tfd = &txq->bd[q->first_empty]; |
| 4811 | txq->txb[q->first_empty] = NULL; |
| 4812 | |
| 4813 | memset(tfd, 0, sizeof(*tfd)); |
| 4814 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; |
| 4815 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 4816 | priv->hcmd_seq++; |
| 4817 | tfd->u.cmd.index = hcmd; |
| 4818 | tfd->u.cmd.length = len; |
| 4819 | memcpy(tfd->u.cmd.payload, buf, len); |
| 4820 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 4821 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 4822 | _ipw_read32(priv, 0x90); |
| 4823 | |
| 4824 | return 0; |
| 4825 | } |
| 4826 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4827 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4828 | * Rx theory of operation |
| 4829 | * |
| 4830 | * The host allocates 32 DMA target addresses and passes the host address |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4831 | * 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] | 4832 | * 0 to 31 |
| 4833 | * |
| 4834 | * Rx Queue Indexes |
| 4835 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4836 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4837 | * The READ index maps to the first position that the firmware may be writing |
| 4838 | * to -- the driver can read up to (but not including) this position and get |
| 4839 | * good data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4840 | * The READ index is managed by the firmware once the card is enabled. |
| 4841 | * |
| 4842 | * The WRITE index maps to the last position the driver has read from -- the |
| 4843 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4844 | * |
| 4845 | * 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] | 4846 | * WRITE = READ. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4847 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4848 | * 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] | 4849 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4850 | * |
| 4851 | * When the firmware places a packet in a buffer it will advance the READ index |
| 4852 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4853 | * process as many packets as possible, moving the WRITE index forward as it |
| 4854 | * resets the Rx queue buffers with new memory. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4855 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4856 | * The management in the driver is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4857 | * + 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] | 4858 | * 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] | 4859 | * to replensish the ipw->rxq->rx_free. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4860 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
| 4861 | * ipw->rxq is replenished and the READ INDEX is updated (updating the |
| 4862 | * 'processed' and 'read' driver indexes as well) |
| 4863 | * + A received packet is processed and handed to the kernel network stack, |
| 4864 | * detached from the ipw->rxq. The driver 'processed' index is updated. |
| 4865 | * + 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] | 4866 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
| 4867 | * 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] | 4868 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4869 | * |
| 4870 | * |
| 4871 | * Driver sequence: |
| 4872 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4873 | * ipw_rx_queue_alloc() Allocates rx_free |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4874 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
| 4875 | * ipw_rx_queue_restock |
| 4876 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 4877 | * queue, updates firmware pointers, and updates |
| 4878 | * the WRITE index. If insufficient rx_free buffers |
| 4879 | * are available, schedules ipw_rx_queue_replenish |
| 4880 | * |
| 4881 | * -- enable interrupts -- |
| 4882 | * 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] | 4883 | * READ INDEX, detaching the SKB from the pool. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4884 | * Moves the packet buffer from queue to rx_used. |
| 4885 | * Calls ipw_rx_queue_restock to refill any empty |
| 4886 | * slots. |
| 4887 | * ... |
| 4888 | * |
| 4889 | */ |
| 4890 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4891 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4892 | * If there are slots in the RX queue that need to be restocked, |
| 4893 | * and we have free pre-allocated buffers, fill the ranks as much |
| 4894 | * as we can pulling from rx_free. |
| 4895 | * |
| 4896 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4897 | * also updates the memory address in the firmware to reference the new |
| 4898 | * target buffer. |
| 4899 | */ |
| 4900 | static void ipw_rx_queue_restock(struct ipw_priv *priv) |
| 4901 | { |
| 4902 | struct ipw_rx_queue *rxq = priv->rxq; |
| 4903 | struct list_head *element; |
| 4904 | struct ipw_rx_mem_buffer *rxb; |
| 4905 | unsigned long flags; |
| 4906 | int write; |
| 4907 | |
| 4908 | spin_lock_irqsave(&rxq->lock, flags); |
| 4909 | write = rxq->write; |
| 4910 | while ((rxq->write != rxq->processed) && (rxq->free_count)) { |
| 4911 | element = rxq->rx_free.next; |
| 4912 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
| 4913 | list_del(element); |
| 4914 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4915 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4916 | rxb->dma_addr); |
| 4917 | rxq->queue[rxq->write] = rxb; |
| 4918 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; |
| 4919 | rxq->free_count--; |
| 4920 | } |
| 4921 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4922 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4923 | /* If the pre-allocated buffer pool is dropping low, schedule to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4924 | * refill it */ |
| 4925 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4926 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4927 | |
| 4928 | /* 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] | 4929 | if (write != rxq->write) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4930 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4931 | } |
| 4932 | |
| 4933 | /* |
| 4934 | * 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] | 4935 | * Also restock the Rx queue via ipw_rx_queue_restock. |
| 4936 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4937 | * This is called as a scheduled work item (except for during intialization) |
| 4938 | */ |
| 4939 | static void ipw_rx_queue_replenish(void *data) |
| 4940 | { |
| 4941 | struct ipw_priv *priv = data; |
| 4942 | struct ipw_rx_queue *rxq = priv->rxq; |
| 4943 | struct list_head *element; |
| 4944 | struct ipw_rx_mem_buffer *rxb; |
| 4945 | unsigned long flags; |
| 4946 | |
| 4947 | spin_lock_irqsave(&rxq->lock, flags); |
| 4948 | while (!list_empty(&rxq->rx_used)) { |
| 4949 | element = rxq->rx_used.next; |
| 4950 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4951 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4952 | if (!rxb->skb) { |
| 4953 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", |
| 4954 | priv->net_dev->name); |
| 4955 | /* We don't reschedule replenish work here -- we will |
| 4956 | * call the restock method and if it still needs |
| 4957 | * more buffers it will schedule replenish */ |
| 4958 | break; |
| 4959 | } |
| 4960 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4961 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4962 | rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4963 | rxb->dma_addr = |
| 4964 | pci_map_single(priv->pci_dev, rxb->skb->data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4965 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4966 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4967 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4968 | rxq->free_count++; |
| 4969 | } |
| 4970 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4971 | |
| 4972 | ipw_rx_queue_restock(priv); |
| 4973 | } |
| 4974 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4975 | static void ipw_bg_rx_queue_replenish(void *data) |
| 4976 | { |
| 4977 | struct ipw_priv *priv = data; |
| 4978 | down(&priv->sem); |
| 4979 | ipw_rx_queue_replenish(data); |
| 4980 | up(&priv->sem); |
| 4981 | } |
| 4982 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4983 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
| 4984 | * If an SKB has been detached, the POOL needs to have it's SKB set to NULL |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4985 | * 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] | 4986 | * non NULL it is unmapped and freed |
| 4987 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4988 | 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] | 4989 | { |
| 4990 | int i; |
| 4991 | |
| 4992 | if (!rxq) |
| 4993 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4994 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4995 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4996 | if (rxq->pool[i].skb != NULL) { |
| 4997 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4998 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4999 | dev_kfree_skb(rxq->pool[i].skb); |
| 5000 | } |
| 5001 | } |
| 5002 | |
| 5003 | kfree(rxq); |
| 5004 | } |
| 5005 | |
| 5006 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) |
| 5007 | { |
| 5008 | struct ipw_rx_queue *rxq; |
| 5009 | int i; |
| 5010 | |
Takis | c75f474 | 2005-12-01 01:41:45 -0800 | [diff] [blame] | 5011 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
Panagiotis Issaris | ad18b0e | 2005-09-05 04:14:10 +0200 | [diff] [blame] | 5012 | if (unlikely(!rxq)) { |
| 5013 | IPW_ERROR("memory allocation failed\n"); |
| 5014 | return NULL; |
| 5015 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5016 | spin_lock_init(&rxq->lock); |
| 5017 | INIT_LIST_HEAD(&rxq->rx_free); |
| 5018 | INIT_LIST_HEAD(&rxq->rx_used); |
| 5019 | |
| 5020 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5021 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5022 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 5023 | |
| 5024 | /* Set us so that we have processed and used all buffers, but have |
| 5025 | * not restocked the Rx queue with fresh buffers */ |
| 5026 | rxq->read = rxq->write = 0; |
| 5027 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 5028 | rxq->free_count = 0; |
| 5029 | |
| 5030 | return rxq; |
| 5031 | } |
| 5032 | |
| 5033 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) |
| 5034 | { |
| 5035 | rate &= ~IEEE80211_BASIC_RATE_MASK; |
| 5036 | if (ieee_mode == IEEE_A) { |
| 5037 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5038 | case IEEE80211_OFDM_RATE_6MB: |
| 5039 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5040 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5041 | case IEEE80211_OFDM_RATE_9MB: |
| 5042 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5043 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5044 | case IEEE80211_OFDM_RATE_12MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5045 | return priv-> |
| 5046 | rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5047 | case IEEE80211_OFDM_RATE_18MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5048 | return priv-> |
| 5049 | rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5050 | case IEEE80211_OFDM_RATE_24MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5051 | return priv-> |
| 5052 | rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5053 | case IEEE80211_OFDM_RATE_36MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5054 | return priv-> |
| 5055 | rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5056 | case IEEE80211_OFDM_RATE_48MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5057 | return priv-> |
| 5058 | rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5059 | case IEEE80211_OFDM_RATE_54MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5060 | return priv-> |
| 5061 | rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5062 | default: |
| 5063 | return 0; |
| 5064 | } |
| 5065 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5066 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5067 | /* B and G mixed */ |
| 5068 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5069 | case IEEE80211_CCK_RATE_1MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5070 | return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5071 | case IEEE80211_CCK_RATE_2MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5072 | return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5073 | case IEEE80211_CCK_RATE_5MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5074 | return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5075 | case IEEE80211_CCK_RATE_11MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5076 | return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0; |
| 5077 | } |
| 5078 | |
| 5079 | /* If we are limited to B modulations, bail at this point */ |
| 5080 | if (ieee_mode == IEEE_B) |
| 5081 | return 0; |
| 5082 | |
| 5083 | /* G */ |
| 5084 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5085 | case IEEE80211_OFDM_RATE_6MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5086 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5087 | case IEEE80211_OFDM_RATE_9MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5088 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5089 | case IEEE80211_OFDM_RATE_12MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5090 | return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5091 | case IEEE80211_OFDM_RATE_18MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5092 | return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5093 | case IEEE80211_OFDM_RATE_24MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5094 | return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5095 | case IEEE80211_OFDM_RATE_36MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5096 | return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5097 | case IEEE80211_OFDM_RATE_48MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5098 | return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5099 | case IEEE80211_OFDM_RATE_54MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5100 | return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
| 5101 | } |
| 5102 | |
| 5103 | return 0; |
| 5104 | } |
| 5105 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5106 | static int ipw_compatible_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5107 | const struct ieee80211_network *network, |
| 5108 | struct ipw_supported_rates *rates) |
| 5109 | { |
| 5110 | int num_rates, i; |
| 5111 | |
| 5112 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5113 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5114 | rates->num_rates = 0; |
| 5115 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5116 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5117 | network->rates[i])) { |
| 5118 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5119 | if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5120 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5121 | "rate %02X\n", |
| 5122 | network->rates[i]); |
| 5123 | rates->supported_rates[rates->num_rates++] = |
| 5124 | network->rates[i]; |
| 5125 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5126 | } |
| 5127 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5128 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5129 | network->rates[i], priv->rates_mask); |
| 5130 | continue; |
| 5131 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5132 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5133 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
| 5134 | } |
| 5135 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5136 | num_rates = min(network->rates_ex_len, |
| 5137 | (u8) (IPW_MAX_RATES - num_rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5138 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5139 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 5140 | network->rates_ex[i])) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5141 | if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5142 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 5143 | "rate %02X\n", |
| 5144 | network->rates_ex[i]); |
| 5145 | rates->supported_rates[rates->num_rates++] = |
| 5146 | network->rates[i]; |
| 5147 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5148 | } |
| 5149 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5150 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 5151 | network->rates_ex[i], priv->rates_mask); |
| 5152 | continue; |
| 5153 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5154 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5155 | rates->supported_rates[rates->num_rates++] = |
| 5156 | network->rates_ex[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5157 | } |
| 5158 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5159 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5160 | } |
| 5161 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5162 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5163 | const struct ipw_supported_rates *src) |
| 5164 | { |
| 5165 | u8 i; |
| 5166 | for (i = 0; i < src->num_rates; i++) |
| 5167 | dest->supported_rates[i] = src->supported_rates[i]; |
| 5168 | dest->num_rates = src->num_rates; |
| 5169 | } |
| 5170 | |
| 5171 | /* TODO: Look at sniffed packets in the air to determine if the basic rate |
| 5172 | * mask should ever be used -- right now all callers to add the scan rates are |
| 5173 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ |
| 5174 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5175 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5176 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5177 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5178 | IEEE80211_BASIC_RATE_MASK : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5179 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5180 | if (rate_mask & IEEE80211_CCK_RATE_1MB_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_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5183 | |
| 5184 | if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5185 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5186 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5187 | |
| 5188 | if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5189 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5190 | IEEE80211_CCK_RATE_5MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5191 | |
| 5192 | if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5193 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5194 | IEEE80211_CCK_RATE_11MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5198 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5199 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5200 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5201 | IEEE80211_BASIC_RATE_MASK : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5202 | |
| 5203 | if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5204 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5205 | IEEE80211_OFDM_RATE_6MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5206 | |
| 5207 | if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5208 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5209 | IEEE80211_OFDM_RATE_9MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5210 | |
| 5211 | if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5212 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5213 | IEEE80211_OFDM_RATE_12MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5214 | |
| 5215 | if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5216 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5217 | IEEE80211_OFDM_RATE_18MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5218 | |
| 5219 | if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5220 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5221 | IEEE80211_OFDM_RATE_24MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5222 | |
| 5223 | if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5224 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5225 | IEEE80211_OFDM_RATE_36MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5226 | |
| 5227 | if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5228 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5229 | IEEE80211_OFDM_RATE_48MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5230 | |
| 5231 | if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5232 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5233 | IEEE80211_OFDM_RATE_54MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | struct ipw_network_match { |
| 5237 | struct ieee80211_network *network; |
| 5238 | struct ipw_supported_rates rates; |
| 5239 | }; |
| 5240 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5241 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
| 5242 | struct ipw_network_match *match, |
| 5243 | struct ieee80211_network *network, |
| 5244 | int roaming) |
| 5245 | { |
| 5246 | struct ipw_supported_rates rates; |
| 5247 | |
| 5248 | /* Verify that this network's capability is compatible with the |
| 5249 | * current mode (AdHoc or Infrastructure) */ |
| 5250 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5251 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5252 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to " |
| 5253 | "capability mismatch.\n", |
| 5254 | escape_essid(network->ssid, network->ssid_len), |
| 5255 | MAC_ARG(network->bssid)); |
| 5256 | return 0; |
| 5257 | } |
| 5258 | |
| 5259 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5260 | * it */ |
| 5261 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5262 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5263 | "because of hidden ESSID.\n", |
| 5264 | escape_essid(network->ssid, network->ssid_len), |
| 5265 | MAC_ARG(network->bssid)); |
| 5266 | return 0; |
| 5267 | } |
| 5268 | |
| 5269 | if (unlikely(roaming)) { |
| 5270 | /* If we are roaming, then ensure check if this is a valid |
| 5271 | * network to try and roam to */ |
| 5272 | if ((network->ssid_len != match->network->ssid_len) || |
| 5273 | memcmp(network->ssid, match->network->ssid, |
| 5274 | network->ssid_len)) { |
| 5275 | IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5276 | "because of non-network ESSID.\n", |
| 5277 | escape_essid(network->ssid, |
| 5278 | network->ssid_len), |
| 5279 | MAC_ARG(network->bssid)); |
| 5280 | return 0; |
| 5281 | } |
| 5282 | } else { |
| 5283 | /* If an ESSID has been configured then compare the broadcast |
| 5284 | * ESSID to ours */ |
| 5285 | if ((priv->config & CFG_STATIC_ESSID) && |
| 5286 | ((network->ssid_len != priv->essid_len) || |
| 5287 | memcmp(network->ssid, priv->essid, |
| 5288 | min(network->ssid_len, priv->essid_len)))) { |
| 5289 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5290 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5291 | strncpy(escaped, |
| 5292 | escape_essid(network->ssid, network->ssid_len), |
| 5293 | sizeof(escaped)); |
| 5294 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5295 | "because of ESSID mismatch: '%s'.\n", |
| 5296 | escaped, MAC_ARG(network->bssid), |
| 5297 | escape_essid(priv->essid, |
| 5298 | priv->essid_len)); |
| 5299 | return 0; |
| 5300 | } |
| 5301 | } |
| 5302 | |
| 5303 | /* If the old network rate is better than this one, don't bother |
| 5304 | * testing everything else. */ |
| 5305 | |
| 5306 | if (network->time_stamp[0] < match->network->time_stamp[0]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5307 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5308 | "current network.\n", |
| 5309 | escape_essid(match->network->ssid, |
| 5310 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5311 | return 0; |
| 5312 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5313 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5314 | "current network.\n", |
| 5315 | escape_essid(match->network->ssid, |
| 5316 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5317 | return 0; |
| 5318 | } |
| 5319 | |
| 5320 | /* Now go through and see if the requested network is valid... */ |
| 5321 | if (priv->ieee->scan_age != 0 && |
| 5322 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
| 5323 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5324 | "because of age: %lums.\n", |
| 5325 | escape_essid(network->ssid, network->ssid_len), |
| 5326 | MAC_ARG(network->bssid), |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5327 | 1000 * (jiffies - network->last_scanned) / HZ); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5328 | return 0; |
| 5329 | } |
| 5330 | |
| 5331 | if ((priv->config & CFG_STATIC_CHANNEL) && |
| 5332 | (network->channel != priv->channel)) { |
| 5333 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5334 | "because of channel mismatch: %d != %d.\n", |
| 5335 | escape_essid(network->ssid, network->ssid_len), |
| 5336 | MAC_ARG(network->bssid), |
| 5337 | network->channel, priv->channel); |
| 5338 | return 0; |
| 5339 | } |
| 5340 | |
| 5341 | /* Verify privacy compatability */ |
| 5342 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
| 5343 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5344 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5345 | "because of privacy mismatch: %s != %s.\n", |
| 5346 | escape_essid(network->ssid, network->ssid_len), |
| 5347 | MAC_ARG(network->bssid), |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5348 | priv-> |
| 5349 | capability & CAP_PRIVACY_ON ? "on" : "off", |
| 5350 | network-> |
| 5351 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : |
| 5352 | "off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5353 | return 0; |
| 5354 | } |
| 5355 | |
| 5356 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5357 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5358 | "because of the same BSSID match: " MAC_FMT |
| 5359 | ".\n", escape_essid(network->ssid, |
| 5360 | network->ssid_len), |
| 5361 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
| 5362 | return 0; |
| 5363 | } |
| 5364 | |
| 5365 | /* Filter out any incompatible freq / mode combinations */ |
| 5366 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5367 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5368 | "because of invalid frequency/mode " |
| 5369 | "combination.\n", |
| 5370 | escape_essid(network->ssid, network->ssid_len), |
| 5371 | MAC_ARG(network->bssid)); |
| 5372 | return 0; |
| 5373 | } |
| 5374 | |
| 5375 | /* Ensure that the rates supported by the driver are compatible with |
| 5376 | * this AP, including verification of basic rates (mandatory) */ |
| 5377 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5378 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5379 | "because configured rate mask excludes " |
| 5380 | "AP mandatory rate.\n", |
| 5381 | escape_essid(network->ssid, network->ssid_len), |
| 5382 | MAC_ARG(network->bssid)); |
| 5383 | return 0; |
| 5384 | } |
| 5385 | |
| 5386 | if (rates.num_rates == 0) { |
| 5387 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5388 | "because of no compatible rates.\n", |
| 5389 | escape_essid(network->ssid, network->ssid_len), |
| 5390 | MAC_ARG(network->bssid)); |
| 5391 | return 0; |
| 5392 | } |
| 5393 | |
| 5394 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5395 | * want to put too much policy logic here; intelligent scan selection |
| 5396 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5397 | |
| 5398 | /* Set up 'new' AP to this network */ |
| 5399 | ipw_copy_rates(&match->rates, &rates); |
| 5400 | match->network = network; |
| 5401 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5402 | escape_essid(network->ssid, network->ssid_len), |
| 5403 | MAC_ARG(network->bssid)); |
| 5404 | |
| 5405 | return 1; |
| 5406 | } |
| 5407 | |
| 5408 | static void ipw_merge_adhoc_network(void *data) |
| 5409 | { |
| 5410 | struct ipw_priv *priv = data; |
| 5411 | struct ieee80211_network *network = NULL; |
| 5412 | struct ipw_network_match match = { |
| 5413 | .network = priv->assoc_network |
| 5414 | }; |
| 5415 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5416 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5417 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5418 | /* First pass through ROAM process -- look for a better |
| 5419 | * network */ |
| 5420 | unsigned long flags; |
| 5421 | |
| 5422 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 5423 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 5424 | if (network != priv->assoc_network) |
| 5425 | ipw_find_adhoc_network(priv, &match, network, |
| 5426 | 1); |
| 5427 | } |
| 5428 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 5429 | |
| 5430 | if (match.network == priv->assoc_network) { |
| 5431 | IPW_DEBUG_MERGE("No better ADHOC in this network to " |
| 5432 | "merge to.\n"); |
| 5433 | return; |
| 5434 | } |
| 5435 | |
| 5436 | down(&priv->sem); |
| 5437 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
| 5438 | IPW_DEBUG_MERGE("remove network %s\n", |
| 5439 | escape_essid(priv->essid, |
| 5440 | priv->essid_len)); |
| 5441 | ipw_remove_current_network(priv); |
| 5442 | } |
| 5443 | |
| 5444 | ipw_disassociate(priv); |
| 5445 | priv->assoc_network = match.network; |
| 5446 | up(&priv->sem); |
| 5447 | return; |
| 5448 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5449 | } |
| 5450 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5451 | static int ipw_best_network(struct ipw_priv *priv, |
| 5452 | struct ipw_network_match *match, |
| 5453 | struct ieee80211_network *network, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5454 | { |
| 5455 | struct ipw_supported_rates rates; |
| 5456 | |
| 5457 | /* Verify that this network's capability is compatible with the |
| 5458 | * current mode (AdHoc or Infrastructure) */ |
| 5459 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && |
Jouni Malinen | 2474385 | 2005-08-14 20:59:59 -0700 | [diff] [blame] | 5460 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5461 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5462 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5463 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5464 | "capability mismatch.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5465 | escape_essid(network->ssid, network->ssid_len), |
| 5466 | MAC_ARG(network->bssid)); |
| 5467 | return 0; |
| 5468 | } |
| 5469 | |
| 5470 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5471 | * it */ |
| 5472 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5473 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5474 | "because of hidden ESSID.\n", |
| 5475 | escape_essid(network->ssid, network->ssid_len), |
| 5476 | MAC_ARG(network->bssid)); |
| 5477 | return 0; |
| 5478 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5479 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5480 | if (unlikely(roaming)) { |
| 5481 | /* If we are roaming, then ensure check if this is a valid |
| 5482 | * network to try and roam to */ |
| 5483 | if ((network->ssid_len != match->network->ssid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5484 | memcmp(network->ssid, match->network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5485 | network->ssid_len)) { |
| 5486 | IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5487 | "because of non-network ESSID.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5488 | escape_essid(network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5489 | network->ssid_len), |
| 5490 | MAC_ARG(network->bssid)); |
| 5491 | return 0; |
| 5492 | } |
| 5493 | } else { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5494 | /* If an ESSID has been configured then compare the broadcast |
| 5495 | * ESSID to ours */ |
| 5496 | if ((priv->config & CFG_STATIC_ESSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5497 | ((network->ssid_len != priv->essid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5498 | memcmp(network->ssid, priv->essid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5499 | min(network->ssid_len, priv->essid_len)))) { |
| 5500 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5501 | strncpy(escaped, |
| 5502 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5503 | sizeof(escaped)); |
| 5504 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5505 | "because of ESSID mismatch: '%s'.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5506 | escaped, MAC_ARG(network->bssid), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5507 | escape_essid(priv->essid, |
| 5508 | priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5509 | return 0; |
| 5510 | } |
| 5511 | } |
| 5512 | |
| 5513 | /* If the old network rate is better than this one, don't bother |
| 5514 | * testing everything else. */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5515 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5516 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5517 | strncpy(escaped, |
| 5518 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5519 | sizeof(escaped)); |
| 5520 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because " |
| 5521 | "'%s (" MAC_FMT ")' has a stronger signal.\n", |
| 5522 | escaped, MAC_ARG(network->bssid), |
| 5523 | escape_essid(match->network->ssid, |
| 5524 | match->network->ssid_len), |
| 5525 | MAC_ARG(match->network->bssid)); |
| 5526 | return 0; |
| 5527 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5528 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5529 | /* If this network has already had an association attempt within the |
| 5530 | * last 3 seconds, do not try and associate again... */ |
| 5531 | if (network->last_associate && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5532 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5533 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5534 | "because of storming (%lus since last " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5535 | "assoc attempt).\n", |
| 5536 | escape_essid(network->ssid, network->ssid_len), |
| 5537 | MAC_ARG(network->bssid), |
| 5538 | (jiffies - network->last_associate) / HZ); |
| 5539 | return 0; |
| 5540 | } |
| 5541 | |
| 5542 | /* Now go through and see if the requested network is valid... */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5543 | if (priv->ieee->scan_age != 0 && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5544 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5545 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5546 | "because of age: %lums.\n", |
| 5547 | escape_essid(network->ssid, network->ssid_len), |
| 5548 | MAC_ARG(network->bssid), |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5549 | 1000 * (jiffies - network->last_scanned) / HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5550 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5551 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5552 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5553 | if ((priv->config & CFG_STATIC_CHANNEL) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5554 | (network->channel != priv->channel)) { |
| 5555 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5556 | "because of channel mismatch: %d != %d.\n", |
| 5557 | escape_essid(network->ssid, network->ssid_len), |
| 5558 | MAC_ARG(network->bssid), |
| 5559 | network->channel, priv->channel); |
| 5560 | return 0; |
| 5561 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5562 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5563 | /* Verify privacy compatability */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5564 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5565 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5566 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5567 | "because of privacy mismatch: %s != %s.\n", |
| 5568 | escape_essid(network->ssid, network->ssid_len), |
| 5569 | MAC_ARG(network->bssid), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5570 | priv->capability & CAP_PRIVACY_ON ? "on" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5571 | "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5572 | network->capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5573 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5574 | return 0; |
| 5575 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5576 | |
Hong Liu | cdd1fa1 | 2005-08-31 18:14:27 +0800 | [diff] [blame] | 5577 | if (!priv->ieee->wpa_enabled && (network->wpa_ie_len > 0 || |
| 5578 | network->rsn_ie_len > 0)) { |
| 5579 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5580 | "because of WPA capability mismatch.\n", |
| 5581 | escape_essid(network->ssid, network->ssid_len), |
| 5582 | MAC_ARG(network->bssid)); |
| 5583 | return 0; |
| 5584 | } |
| 5585 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5586 | if ((priv->config & CFG_STATIC_BSSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5587 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5588 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5589 | "because of BSSID mismatch: " MAC_FMT ".\n", |
| 5590 | escape_essid(network->ssid, network->ssid_len), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5591 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5592 | return 0; |
| 5593 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5594 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5595 | /* Filter out any incompatible freq / mode combinations */ |
| 5596 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5597 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5598 | "because of invalid frequency/mode " |
| 5599 | "combination.\n", |
| 5600 | escape_essid(network->ssid, network->ssid_len), |
| 5601 | MAC_ARG(network->bssid)); |
| 5602 | return 0; |
| 5603 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5604 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5605 | /* Filter out invalid channel in current GEO */ |
| 5606 | if (!ipw_is_valid_channel(priv->ieee, network->channel)) { |
| 5607 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5608 | "because of invalid channel in current GEO\n", |
| 5609 | escape_essid(network->ssid, network->ssid_len), |
| 5610 | MAC_ARG(network->bssid)); |
| 5611 | return 0; |
| 5612 | } |
| 5613 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5614 | /* Ensure that the rates supported by the driver are compatible with |
| 5615 | * this AP, including verification of basic rates (mandatory) */ |
| 5616 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5617 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5618 | "because configured rate mask excludes " |
| 5619 | "AP mandatory rate.\n", |
| 5620 | escape_essid(network->ssid, network->ssid_len), |
| 5621 | MAC_ARG(network->bssid)); |
| 5622 | return 0; |
| 5623 | } |
| 5624 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5625 | if (rates.num_rates == 0) { |
| 5626 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5627 | "because of no compatible rates.\n", |
| 5628 | escape_essid(network->ssid, network->ssid_len), |
| 5629 | MAC_ARG(network->bssid)); |
| 5630 | return 0; |
| 5631 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5632 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5633 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5634 | * want to put too much policy logic here; intelligent scan selection |
| 5635 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5636 | |
| 5637 | /* Set up 'new' AP to this network */ |
| 5638 | ipw_copy_rates(&match->rates, &rates); |
| 5639 | match->network = network; |
| 5640 | |
| 5641 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5642 | escape_essid(network->ssid, network->ssid_len), |
| 5643 | MAC_ARG(network->bssid)); |
| 5644 | |
| 5645 | return 1; |
| 5646 | } |
| 5647 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5648 | static void ipw_adhoc_create(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5649 | struct ieee80211_network *network) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5650 | { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5651 | const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5652 | int i; |
| 5653 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5654 | /* |
| 5655 | * For the purposes of scanning, we can set our wireless mode |
| 5656 | * to trigger scans across combinations of bands, but when it |
| 5657 | * comes to creating a new ad-hoc network, we have tell the FW |
| 5658 | * exactly which band to use. |
| 5659 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5660 | * We also have the possibility of an invalid channel for the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5661 | * chossen band. Attempting to create a new ad-hoc network |
| 5662 | * with an invalid channel for wireless mode will trigger a |
| 5663 | * FW fatal error. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5664 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5665 | */ |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5666 | switch (ipw_is_valid_channel(priv->ieee, priv->channel)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5667 | case IEEE80211_52GHZ_BAND: |
| 5668 | network->mode = IEEE_A; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5669 | i = ipw_channel_to_index(priv->ieee, priv->channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5670 | if (i == -1) |
| 5671 | BUG(); |
| 5672 | if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5673 | IPW_WARNING("Overriding invalid channel\n"); |
| 5674 | priv->channel = geo->a[0].channel; |
| 5675 | } |
| 5676 | break; |
| 5677 | |
| 5678 | case IEEE80211_24GHZ_BAND: |
| 5679 | if (priv->ieee->mode & IEEE_G) |
| 5680 | network->mode = IEEE_G; |
| 5681 | else |
| 5682 | network->mode = IEEE_B; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 5683 | i = ipw_channel_to_index(priv->ieee, priv->channel); |
| 5684 | if (i == -1) |
| 5685 | BUG(); |
| 5686 | if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5687 | IPW_WARNING("Overriding invalid channel\n"); |
| 5688 | priv->channel = geo->bg[0].channel; |
| 5689 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5690 | break; |
| 5691 | |
| 5692 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5693 | IPW_WARNING("Overriding invalid channel\n"); |
| 5694 | if (priv->ieee->mode & IEEE_A) { |
| 5695 | network->mode = IEEE_A; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5696 | priv->channel = geo->a[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5697 | } else if (priv->ieee->mode & IEEE_G) { |
| 5698 | network->mode = IEEE_G; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5699 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5700 | } else { |
| 5701 | network->mode = IEEE_B; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5702 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5703 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5704 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5705 | } |
| 5706 | |
| 5707 | network->channel = priv->channel; |
| 5708 | priv->config |= CFG_ADHOC_PERSIST; |
| 5709 | ipw_create_bssid(priv, network->bssid); |
| 5710 | network->ssid_len = priv->essid_len; |
| 5711 | memcpy(network->ssid, priv->essid, priv->essid_len); |
| 5712 | memset(&network->stats, 0, sizeof(network->stats)); |
| 5713 | network->capability = WLAN_CAPABILITY_IBSS; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5714 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
| 5715 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5716 | if (priv->capability & CAP_PRIVACY_ON) |
| 5717 | network->capability |= WLAN_CAPABILITY_PRIVACY; |
| 5718 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5719 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5720 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5721 | memcpy(network->rates_ex, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5722 | &priv->rates.supported_rates[network->rates_len], |
| 5723 | network->rates_ex_len); |
| 5724 | network->last_scanned = 0; |
| 5725 | network->flags = 0; |
| 5726 | network->last_associate = 0; |
| 5727 | network->time_stamp[0] = 0; |
| 5728 | network->time_stamp[1] = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5729 | network->beacon_interval = 100; /* Default */ |
| 5730 | network->listen_interval = 10; /* Default */ |
| 5731 | network->atim_window = 0; /* Default */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5732 | network->wpa_ie_len = 0; |
| 5733 | network->rsn_ie_len = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5734 | } |
| 5735 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5736 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
| 5737 | { |
| 5738 | struct ipw_tgi_tx_key *key; |
| 5739 | struct host_cmd cmd = { |
| 5740 | .cmd = IPW_CMD_TGI_TX_KEY, |
| 5741 | .len = sizeof(*key) |
| 5742 | }; |
| 5743 | |
| 5744 | if (!(priv->ieee->sec.flags & (1 << index))) |
| 5745 | return; |
| 5746 | |
| 5747 | key = (struct ipw_tgi_tx_key *)&cmd.param; |
| 5748 | key->key_id = index; |
| 5749 | memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); |
| 5750 | key->security_type = type; |
| 5751 | key->station_index = 0; /* always 0 for BSS */ |
| 5752 | key->flags = 0; |
| 5753 | /* 0 for new key; previous value of counter (after fatal error) */ |
| 5754 | key->tx_counter[0] = 0; |
| 5755 | key->tx_counter[1] = 0; |
| 5756 | |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 5757 | ipw_send_cmd(priv, &cmd); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5761 | { |
| 5762 | struct ipw_wep_key *key; |
| 5763 | int i; |
| 5764 | struct host_cmd cmd = { |
| 5765 | .cmd = IPW_CMD_WEP_KEY, |
| 5766 | .len = sizeof(*key) |
| 5767 | }; |
| 5768 | |
| 5769 | key = (struct ipw_wep_key *)&cmd.param; |
| 5770 | key->cmd_id = DINO_CMD_WEP_KEY; |
| 5771 | key->seq_num = 0; |
| 5772 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5773 | /* Note: AES keys cannot be set for multiple times. |
| 5774 | * Only set it at the first time. */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5775 | for (i = 0; i < 4; i++) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5776 | key->key_index = i | type; |
| 5777 | if (!(priv->ieee->sec.flags & (1 << i))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5778 | key->key_size = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5779 | continue; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5780 | } |
| 5781 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5782 | key->key_size = priv->ieee->sec.key_sizes[i]; |
| 5783 | memcpy(key->key, priv->ieee->sec.keys[i], key->key_size); |
| 5784 | |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 5785 | ipw_send_cmd(priv, &cmd); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5786 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5787 | } |
| 5788 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 5789 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
| 5790 | { |
| 5791 | if (priv->ieee->host_encrypt) |
| 5792 | return; |
| 5793 | |
| 5794 | switch (level) { |
| 5795 | case SEC_LEVEL_3: |
| 5796 | priv->sys_config.disable_unicast_decryption = 0; |
| 5797 | priv->ieee->host_decrypt = 0; |
| 5798 | break; |
| 5799 | case SEC_LEVEL_2: |
| 5800 | priv->sys_config.disable_unicast_decryption = 1; |
| 5801 | priv->ieee->host_decrypt = 1; |
| 5802 | break; |
| 5803 | case SEC_LEVEL_1: |
| 5804 | priv->sys_config.disable_unicast_decryption = 0; |
| 5805 | priv->ieee->host_decrypt = 0; |
| 5806 | break; |
| 5807 | case SEC_LEVEL_0: |
| 5808 | priv->sys_config.disable_unicast_decryption = 1; |
| 5809 | break; |
| 5810 | default: |
| 5811 | break; |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) |
| 5816 | { |
| 5817 | if (priv->ieee->host_encrypt) |
| 5818 | return; |
| 5819 | |
| 5820 | switch (level) { |
| 5821 | case SEC_LEVEL_3: |
| 5822 | priv->sys_config.disable_multicast_decryption = 0; |
| 5823 | break; |
| 5824 | case SEC_LEVEL_2: |
| 5825 | priv->sys_config.disable_multicast_decryption = 1; |
| 5826 | break; |
| 5827 | case SEC_LEVEL_1: |
| 5828 | priv->sys_config.disable_multicast_decryption = 0; |
| 5829 | break; |
| 5830 | case SEC_LEVEL_0: |
| 5831 | priv->sys_config.disable_multicast_decryption = 1; |
| 5832 | break; |
| 5833 | default: |
| 5834 | break; |
| 5835 | } |
| 5836 | } |
| 5837 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5838 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
| 5839 | { |
| 5840 | switch (priv->ieee->sec.level) { |
| 5841 | case SEC_LEVEL_3: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5842 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5843 | ipw_send_tgi_tx_key(priv, |
| 5844 | DCT_FLAG_EXT_SECURITY_CCM, |
| 5845 | priv->ieee->sec.active_key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5846 | |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 5847 | if (!priv->ieee->host_mc_decrypt) |
| 5848 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5849 | break; |
| 5850 | case SEC_LEVEL_2: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5851 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5852 | ipw_send_tgi_tx_key(priv, |
| 5853 | DCT_FLAG_EXT_SECURITY_TKIP, |
| 5854 | priv->ieee->sec.active_key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5855 | break; |
| 5856 | case SEC_LEVEL_1: |
| 5857 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Hong Liu | 29cb843 | 2005-09-12 10:43:33 -0500 | [diff] [blame] | 5858 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
| 5859 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5860 | break; |
| 5861 | case SEC_LEVEL_0: |
| 5862 | default: |
| 5863 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5864 | } |
| 5865 | } |
| 5866 | |
| 5867 | static void ipw_adhoc_check(void *data) |
| 5868 | { |
| 5869 | struct ipw_priv *priv = data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5870 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5871 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5872 | !(priv->config & CFG_ADHOC_PERSIST)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5873 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 5874 | IPW_DL_STATE | IPW_DL_ASSOC, |
| 5875 | "Missed beacon: %d - disassociate\n", |
| 5876 | priv->missed_adhoc_beacons); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5877 | ipw_remove_current_network(priv); |
| 5878 | ipw_disassociate(priv); |
| 5879 | return; |
| 5880 | } |
| 5881 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5882 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5883 | priv->assoc_request.beacon_interval); |
| 5884 | } |
| 5885 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5886 | static void ipw_bg_adhoc_check(void *data) |
| 5887 | { |
| 5888 | struct ipw_priv *priv = data; |
| 5889 | down(&priv->sem); |
| 5890 | ipw_adhoc_check(data); |
| 5891 | up(&priv->sem); |
| 5892 | } |
| 5893 | |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 5894 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5895 | static void ipw_debug_config(struct ipw_priv *priv) |
| 5896 | { |
| 5897 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
| 5898 | "[CFG 0x%08X]\n", priv->config); |
| 5899 | if (priv->config & CFG_STATIC_CHANNEL) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5900 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5901 | else |
| 5902 | IPW_DEBUG_INFO("Channel unlocked.\n"); |
| 5903 | if (priv->config & CFG_STATIC_ESSID) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5904 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5905 | escape_essid(priv->essid, priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5906 | else |
| 5907 | IPW_DEBUG_INFO("ESSID unlocked.\n"); |
| 5908 | if (priv->config & CFG_STATIC_BSSID) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5909 | IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n", |
| 5910 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5911 | else |
| 5912 | IPW_DEBUG_INFO("BSSID unlocked.\n"); |
| 5913 | if (priv->capability & CAP_PRIVACY_ON) |
| 5914 | IPW_DEBUG_INFO("PRIVACY on\n"); |
| 5915 | else |
| 5916 | IPW_DEBUG_INFO("PRIVACY off\n"); |
| 5917 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); |
| 5918 | } |
| 5919 | #else |
Jiri Benc | 8d45ff7 | 2005-08-25 20:09:39 -0400 | [diff] [blame] | 5920 | #define ipw_debug_config(x) do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5921 | #endif |
| 5922 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 5923 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5924 | { |
| 5925 | /* TODO: Verify that this works... */ |
| 5926 | struct ipw_fixed_rate fr = { |
| 5927 | .tx_rates = priv->rates_mask |
| 5928 | }; |
| 5929 | u32 reg; |
| 5930 | u16 mask = 0; |
| 5931 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5932 | /* Identify 'current FW band' and match it with the fixed |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5933 | * Tx rates */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5934 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5935 | switch (priv->ieee->freq_band) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5936 | case IEEE80211_52GHZ_BAND: /* A only */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5937 | /* IEEE_A */ |
| 5938 | if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { |
| 5939 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5940 | IPW_DEBUG_WX |
| 5941 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5942 | fr.tx_rates = 0; |
| 5943 | break; |
| 5944 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5945 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5946 | fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A; |
| 5947 | break; |
| 5948 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5949 | default: /* 2.4Ghz or Mixed */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5950 | /* IEEE_B */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5951 | if (mode == IEEE_B) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5952 | if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { |
| 5953 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5954 | IPW_DEBUG_WX |
| 5955 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5956 | fr.tx_rates = 0; |
| 5957 | } |
| 5958 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5959 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5960 | |
| 5961 | /* IEEE_G */ |
| 5962 | if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK | |
| 5963 | IEEE80211_OFDM_RATES_MASK)) { |
| 5964 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5965 | IPW_DEBUG_WX |
| 5966 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5967 | fr.tx_rates = 0; |
| 5968 | break; |
| 5969 | } |
| 5970 | |
| 5971 | if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) { |
| 5972 | mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1); |
| 5973 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK; |
| 5974 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5975 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5976 | if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) { |
| 5977 | mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1); |
| 5978 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK; |
| 5979 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5980 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5981 | if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) { |
| 5982 | mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1); |
| 5983 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK; |
| 5984 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5985 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5986 | fr.tx_rates |= mask; |
| 5987 | break; |
| 5988 | } |
| 5989 | |
| 5990 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5991 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5992 | } |
| 5993 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5994 | static void ipw_abort_scan(struct ipw_priv *priv) |
| 5995 | { |
| 5996 | int err; |
| 5997 | |
| 5998 | if (priv->status & STATUS_SCAN_ABORTING) { |
| 5999 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); |
| 6000 | return; |
| 6001 | } |
| 6002 | priv->status |= STATUS_SCAN_ABORTING; |
| 6003 | |
| 6004 | err = ipw_send_scan_abort(priv); |
| 6005 | if (err) |
| 6006 | IPW_DEBUG_HC("Request to abort scan failed.\n"); |
| 6007 | } |
| 6008 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6009 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
| 6010 | struct ipw_scan_request_ext *scan, |
| 6011 | int scan_type) |
| 6012 | { |
| 6013 | int channel_index = 0; |
| 6014 | const struct ieee80211_geo *geo; |
| 6015 | int i; |
| 6016 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6017 | geo = ipw_get_geo(priv->ieee); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6018 | |
| 6019 | if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { |
| 6020 | int start = channel_index; |
| 6021 | for (i = 0; i < geo->a_channels; i++) { |
| 6022 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6023 | geo->a[i].channel == priv->channel) |
| 6024 | continue; |
| 6025 | channel_index++; |
| 6026 | scan->channels_list[channel_index] = geo->a[i].channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6027 | ipw_set_scan_type(scan, channel_index, |
| 6028 | geo->a[i]. |
| 6029 | flags & 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 | if (start != channel_index) { |
| 6035 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | |
| 6036 | (channel_index - start); |
| 6037 | channel_index++; |
| 6038 | } |
| 6039 | } |
| 6040 | |
| 6041 | if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { |
| 6042 | int start = channel_index; |
| 6043 | if (priv->config & CFG_SPEED_SCAN) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6044 | int index; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6045 | u8 channels[IEEE80211_24GHZ_CHANNELS] = { |
| 6046 | /* nop out the list */ |
| 6047 | [0] = 0 |
| 6048 | }; |
| 6049 | |
| 6050 | u8 channel; |
| 6051 | while (channel_index < IPW_SCAN_CHANNELS) { |
| 6052 | channel = |
| 6053 | priv->speed_scan[priv->speed_scan_pos]; |
| 6054 | if (channel == 0) { |
| 6055 | priv->speed_scan_pos = 0; |
| 6056 | channel = priv->speed_scan[0]; |
| 6057 | } |
| 6058 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6059 | channel == priv->channel) { |
| 6060 | priv->speed_scan_pos++; |
| 6061 | continue; |
| 6062 | } |
| 6063 | |
| 6064 | /* If this channel has already been |
| 6065 | * added in scan, break from loop |
| 6066 | * and this will be the first channel |
| 6067 | * in the next scan. |
| 6068 | */ |
| 6069 | if (channels[channel - 1] != 0) |
| 6070 | break; |
| 6071 | |
| 6072 | channels[channel - 1] = 1; |
| 6073 | priv->speed_scan_pos++; |
| 6074 | channel_index++; |
| 6075 | scan->channels_list[channel_index] = channel; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6076 | index = |
| 6077 | ipw_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6078 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6079 | geo->bg[index]. |
| 6080 | flags & |
| 6081 | IEEE80211_CH_PASSIVE_ONLY ? |
| 6082 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6083 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6084 | } |
| 6085 | } else { |
| 6086 | for (i = 0; i < geo->bg_channels; i++) { |
| 6087 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6088 | geo->bg[i].channel == priv->channel) |
| 6089 | continue; |
| 6090 | channel_index++; |
| 6091 | scan->channels_list[channel_index] = |
| 6092 | geo->bg[i].channel; |
| 6093 | ipw_set_scan_type(scan, channel_index, |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6094 | geo->bg[i]. |
| 6095 | flags & |
| 6096 | IEEE80211_CH_PASSIVE_ONLY ? |
| 6097 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
| 6098 | : scan_type); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6099 | } |
| 6100 | } |
| 6101 | |
| 6102 | if (start != channel_index) { |
| 6103 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | |
| 6104 | (channel_index - start); |
| 6105 | } |
| 6106 | } |
| 6107 | } |
| 6108 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6109 | static int ipw_request_scan(struct ipw_priv *priv) |
| 6110 | { |
| 6111 | struct ipw_scan_request_ext scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6112 | int err = 0, scan_type; |
| 6113 | |
| 6114 | if (!(priv->status & STATUS_INIT) || |
| 6115 | (priv->status & STATUS_EXIT_PENDING)) |
| 6116 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6117 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6118 | down(&priv->sem); |
| 6119 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6120 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6121 | IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6122 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6123 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6124 | } |
| 6125 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6126 | if (!(priv->status & STATUS_SCAN_FORCED) && |
| 6127 | priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6128 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6129 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6130 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6131 | } |
| 6132 | |
| 6133 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 6134 | IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6135 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6136 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | memset(&scan, 0, sizeof(scan)); |
| 6140 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6141 | if (priv->config & CFG_SPEED_SCAN) |
| 6142 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 6143 | cpu_to_le16(30); |
| 6144 | else |
| 6145 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 6146 | cpu_to_le16(20); |
| 6147 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6148 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 6149 | cpu_to_le16(20); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6150 | 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] | 6151 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6152 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6153 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6154 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6155 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6156 | u8 channel; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6157 | u8 band = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6158 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 6159 | switch (ipw_is_valid_channel(priv->ieee, priv->channel)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6160 | case IEEE80211_52GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6161 | band = (u8) (IPW_A_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6162 | channel = priv->channel; |
| 6163 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6164 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6165 | case IEEE80211_24GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6166 | band = (u8) (IPW_B_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6167 | channel = priv->channel; |
| 6168 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6169 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6170 | default: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6171 | band = (u8) (IPW_B_MODE << 6) | 1; |
| 6172 | channel = 9; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6173 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6174 | } |
| 6175 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6176 | scan.channels_list[0] = band; |
| 6177 | scan.channels_list[1] = channel; |
| 6178 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6179 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6180 | /* NOTE: The card will sit on this channel for this time |
| 6181 | * period. Scan aborts are timing sensitive and frequently |
| 6182 | * result in firmware restarts. As such, it is best to |
| 6183 | * set a small dwell_time here and just keep re-issuing |
| 6184 | * scans. Otherwise fast channel hopping will not actually |
| 6185 | * hop channels. |
| 6186 | * |
| 6187 | * TODO: Move SPEED SCAN support to all modes and bands */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6188 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
| 6189 | cpu_to_le16(2000); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6190 | } else { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6191 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 6192 | /* If we are roaming, then make this a directed scan for the |
| 6193 | * current network. Otherwise, ensure that every other scan |
| 6194 | * is a fast channel hop scan */ |
| 6195 | if ((priv->status & STATUS_ROAMING) |
| 6196 | || (!(priv->status & STATUS_ASSOCIATED) |
| 6197 | && (priv->config & CFG_STATIC_ESSID) |
| 6198 | && (le32_to_cpu(scan.full_scan_index) % 2))) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6199 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 6200 | if (err) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6201 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6202 | "failed.\n"); |
| 6203 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6207 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6208 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6209 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6210 | ipw_add_scan_channels(priv, &scan, scan_type); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6211 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6212 | } |
| 6213 | #endif |
| 6214 | |
| 6215 | err = ipw_send_scan_request_ext(priv, &scan); |
| 6216 | if (err) { |
| 6217 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6218 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6219 | } |
| 6220 | |
| 6221 | priv->status |= STATUS_SCANNING; |
| 6222 | priv->status &= ~STATUS_SCAN_PENDING; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6223 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6224 | IPW_SCAN_CHECK_WATCHDOG); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6225 | done: |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6226 | up(&priv->sem); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6227 | return err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | static void ipw_bg_abort_scan(void *data) |
| 6231 | { |
| 6232 | struct ipw_priv *priv = data; |
| 6233 | down(&priv->sem); |
| 6234 | ipw_abort_scan(data); |
| 6235 | up(&priv->sem); |
| 6236 | } |
| 6237 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6238 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
| 6239 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6240 | /* This is called when wpa_supplicant loads and closes the driver |
| 6241 | * interface. */ |
Hong Liu | cdd1fa1 | 2005-08-31 18:14:27 +0800 | [diff] [blame] | 6242 | priv->ieee->wpa_enabled = value; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6243 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6244 | } |
| 6245 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6246 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
| 6247 | { |
| 6248 | struct ieee80211_device *ieee = priv->ieee; |
| 6249 | struct ieee80211_security sec = { |
| 6250 | .flags = SEC_AUTH_MODE, |
| 6251 | }; |
| 6252 | int ret = 0; |
| 6253 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6254 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6255 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
| 6256 | ieee->open_wep = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6257 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6258 | sec.auth_mode = WLAN_AUTH_OPEN; |
| 6259 | ieee->open_wep = 1; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 6260 | } else if (value & IW_AUTH_ALG_LEAP) { |
| 6261 | sec.auth_mode = WLAN_AUTH_LEAP; |
| 6262 | ieee->open_wep = 1; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6263 | } else |
| 6264 | return -EINVAL; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6265 | |
| 6266 | if (ieee->set_security) |
| 6267 | ieee->set_security(ieee->dev, &sec); |
| 6268 | else |
| 6269 | ret = -EOPNOTSUPP; |
| 6270 | |
| 6271 | return ret; |
| 6272 | } |
| 6273 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 6274 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
| 6275 | int wpa_ie_len) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6276 | { |
| 6277 | /* make sure WPA is enabled */ |
| 6278 | ipw_wpa_enable(priv, 1); |
| 6279 | |
| 6280 | ipw_disassociate(priv); |
| 6281 | } |
| 6282 | |
| 6283 | static int ipw_set_rsn_capa(struct ipw_priv *priv, |
| 6284 | char *capabilities, int length) |
| 6285 | { |
| 6286 | struct host_cmd cmd = { |
| 6287 | .cmd = IPW_CMD_RSN_CAPABILITIES, |
| 6288 | .len = length, |
| 6289 | }; |
| 6290 | |
| 6291 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
| 6292 | |
| 6293 | memcpy(cmd.param, capabilities, length); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 6294 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6295 | } |
| 6296 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6297 | /* |
| 6298 | * WE-18 support |
| 6299 | */ |
| 6300 | |
| 6301 | /* SIOCSIWGENIE */ |
| 6302 | static int ipw_wx_set_genie(struct net_device *dev, |
| 6303 | struct iw_request_info *info, |
| 6304 | union iwreq_data *wrqu, char *extra) |
| 6305 | { |
| 6306 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6307 | struct ieee80211_device *ieee = priv->ieee; |
| 6308 | u8 *buf; |
| 6309 | int err = 0; |
| 6310 | |
| 6311 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
| 6312 | (wrqu->data.length && extra == NULL)) |
| 6313 | return -EINVAL; |
| 6314 | |
| 6315 | //down(&priv->sem); |
| 6316 | |
| 6317 | //if (!ieee->wpa_enabled) { |
| 6318 | // err = -EOPNOTSUPP; |
| 6319 | // goto out; |
| 6320 | //} |
| 6321 | |
| 6322 | if (wrqu->data.length) { |
| 6323 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 6324 | if (buf == NULL) { |
| 6325 | err = -ENOMEM; |
| 6326 | goto out; |
| 6327 | } |
| 6328 | |
| 6329 | memcpy(buf, extra, wrqu->data.length); |
| 6330 | kfree(ieee->wpa_ie); |
| 6331 | ieee->wpa_ie = buf; |
| 6332 | ieee->wpa_ie_len = wrqu->data.length; |
| 6333 | } else { |
| 6334 | kfree(ieee->wpa_ie); |
| 6335 | ieee->wpa_ie = NULL; |
| 6336 | ieee->wpa_ie_len = 0; |
| 6337 | } |
| 6338 | |
| 6339 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6340 | out: |
| 6341 | //up(&priv->sem); |
| 6342 | return err; |
| 6343 | } |
| 6344 | |
| 6345 | /* SIOCGIWGENIE */ |
| 6346 | static int ipw_wx_get_genie(struct net_device *dev, |
| 6347 | struct iw_request_info *info, |
| 6348 | union iwreq_data *wrqu, char *extra) |
| 6349 | { |
| 6350 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6351 | struct ieee80211_device *ieee = priv->ieee; |
| 6352 | int err = 0; |
| 6353 | |
| 6354 | //down(&priv->sem); |
| 6355 | |
| 6356 | //if (!ieee->wpa_enabled) { |
| 6357 | // err = -EOPNOTSUPP; |
| 6358 | // goto out; |
| 6359 | //} |
| 6360 | |
| 6361 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
| 6362 | wrqu->data.length = 0; |
| 6363 | goto out; |
| 6364 | } |
| 6365 | |
| 6366 | if (wrqu->data.length < ieee->wpa_ie_len) { |
| 6367 | err = -E2BIG; |
| 6368 | goto out; |
| 6369 | } |
| 6370 | |
| 6371 | wrqu->data.length = ieee->wpa_ie_len; |
| 6372 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6373 | |
| 6374 | out: |
| 6375 | //up(&priv->sem); |
| 6376 | return err; |
| 6377 | } |
| 6378 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6379 | static int wext_cipher2level(int cipher) |
| 6380 | { |
| 6381 | switch (cipher) { |
| 6382 | case IW_AUTH_CIPHER_NONE: |
| 6383 | return SEC_LEVEL_0; |
| 6384 | case IW_AUTH_CIPHER_WEP40: |
| 6385 | case IW_AUTH_CIPHER_WEP104: |
| 6386 | return SEC_LEVEL_1; |
| 6387 | case IW_AUTH_CIPHER_TKIP: |
| 6388 | return SEC_LEVEL_2; |
| 6389 | case IW_AUTH_CIPHER_CCMP: |
| 6390 | return SEC_LEVEL_3; |
| 6391 | default: |
| 6392 | return -1; |
| 6393 | } |
| 6394 | } |
| 6395 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6396 | /* SIOCSIWAUTH */ |
| 6397 | static int ipw_wx_set_auth(struct net_device *dev, |
| 6398 | struct iw_request_info *info, |
| 6399 | union iwreq_data *wrqu, char *extra) |
| 6400 | { |
| 6401 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6402 | struct ieee80211_device *ieee = priv->ieee; |
| 6403 | struct iw_param *param = &wrqu->param; |
| 6404 | struct ieee80211_crypt_data *crypt; |
| 6405 | unsigned long flags; |
| 6406 | int ret = 0; |
| 6407 | |
| 6408 | switch (param->flags & IW_AUTH_INDEX) { |
| 6409 | case IW_AUTH_WPA_VERSION: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6410 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6411 | case IW_AUTH_CIPHER_PAIRWISE: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6412 | ipw_set_hw_decrypt_unicast(priv, |
| 6413 | wext_cipher2level(param->value)); |
| 6414 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6415 | case IW_AUTH_CIPHER_GROUP: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6416 | ipw_set_hw_decrypt_multicast(priv, |
| 6417 | wext_cipher2level(param->value)); |
| 6418 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6419 | case IW_AUTH_KEY_MGMT: |
| 6420 | /* |
| 6421 | * ipw2200 does not use these parameters |
| 6422 | */ |
| 6423 | break; |
| 6424 | |
| 6425 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6426 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6427 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6428 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6429 | |
| 6430 | flags = crypt->ops->get_flags(crypt->priv); |
| 6431 | |
| 6432 | if (param->value) |
| 6433 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6434 | else |
| 6435 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6436 | |
| 6437 | crypt->ops->set_flags(flags, crypt->priv); |
| 6438 | |
| 6439 | break; |
| 6440 | |
| 6441 | case IW_AUTH_DROP_UNENCRYPTED:{ |
| 6442 | /* HACK: |
| 6443 | * |
| 6444 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6445 | * is loaded and unloaded, regardless of if WPA is being |
| 6446 | * used. No other calls are made which can be used to |
| 6447 | * determine if encryption will be used or not prior to |
| 6448 | * association being expected. If encryption is not being |
| 6449 | * used, drop_unencrypted is set to false, else true -- we |
| 6450 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6451 | * be set. |
| 6452 | */ |
| 6453 | struct ieee80211_security sec = { |
| 6454 | .flags = SEC_ENABLED, |
| 6455 | .enabled = param->value, |
| 6456 | }; |
| 6457 | priv->ieee->drop_unencrypted = param->value; |
| 6458 | /* We only change SEC_LEVEL for open mode. Others |
| 6459 | * are set by ipw_wpa_set_encryption. |
| 6460 | */ |
| 6461 | if (!param->value) { |
| 6462 | sec.flags |= SEC_LEVEL; |
| 6463 | sec.level = SEC_LEVEL_0; |
| 6464 | } else { |
| 6465 | sec.flags |= SEC_LEVEL; |
| 6466 | sec.level = SEC_LEVEL_1; |
| 6467 | } |
| 6468 | if (priv->ieee->set_security) |
| 6469 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6470 | break; |
| 6471 | } |
| 6472 | |
| 6473 | case IW_AUTH_80211_AUTH_ALG: |
| 6474 | ret = ipw_wpa_set_auth_algs(priv, param->value); |
| 6475 | break; |
| 6476 | |
| 6477 | case IW_AUTH_WPA_ENABLED: |
| 6478 | ret = ipw_wpa_enable(priv, param->value); |
| 6479 | break; |
| 6480 | |
| 6481 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6482 | ieee->ieee802_1x = param->value; |
| 6483 | break; |
| 6484 | |
| 6485 | //case IW_AUTH_ROAMING_CONTROL: |
| 6486 | case IW_AUTH_PRIVACY_INVOKED: |
| 6487 | ieee->privacy_invoked = param->value; |
| 6488 | break; |
| 6489 | |
| 6490 | default: |
| 6491 | return -EOPNOTSUPP; |
| 6492 | } |
| 6493 | return ret; |
| 6494 | } |
| 6495 | |
| 6496 | /* SIOCGIWAUTH */ |
| 6497 | static int ipw_wx_get_auth(struct net_device *dev, |
| 6498 | struct iw_request_info *info, |
| 6499 | union iwreq_data *wrqu, char *extra) |
| 6500 | { |
| 6501 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6502 | struct ieee80211_device *ieee = priv->ieee; |
| 6503 | struct ieee80211_crypt_data *crypt; |
| 6504 | struct iw_param *param = &wrqu->param; |
| 6505 | int ret = 0; |
| 6506 | |
| 6507 | switch (param->flags & IW_AUTH_INDEX) { |
| 6508 | case IW_AUTH_WPA_VERSION: |
| 6509 | case IW_AUTH_CIPHER_PAIRWISE: |
| 6510 | case IW_AUTH_CIPHER_GROUP: |
| 6511 | case IW_AUTH_KEY_MGMT: |
| 6512 | /* |
| 6513 | * wpa_supplicant will control these internally |
| 6514 | */ |
| 6515 | ret = -EOPNOTSUPP; |
| 6516 | break; |
| 6517 | |
| 6518 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6519 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
James Ketrenos | 991d1cc | 2005-10-13 09:26:48 +0000 | [diff] [blame] | 6520 | if (!crypt || !crypt->ops->get_flags) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6521 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6522 | |
| 6523 | param->value = (crypt->ops->get_flags(crypt->priv) & |
| 6524 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; |
| 6525 | |
| 6526 | break; |
| 6527 | |
| 6528 | case IW_AUTH_DROP_UNENCRYPTED: |
| 6529 | param->value = ieee->drop_unencrypted; |
| 6530 | break; |
| 6531 | |
| 6532 | case IW_AUTH_80211_AUTH_ALG: |
| 6533 | param->value = ieee->sec.auth_mode; |
| 6534 | break; |
| 6535 | |
| 6536 | case IW_AUTH_WPA_ENABLED: |
| 6537 | param->value = ieee->wpa_enabled; |
| 6538 | break; |
| 6539 | |
| 6540 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6541 | param->value = ieee->ieee802_1x; |
| 6542 | break; |
| 6543 | |
| 6544 | case IW_AUTH_ROAMING_CONTROL: |
| 6545 | case IW_AUTH_PRIVACY_INVOKED: |
| 6546 | param->value = ieee->privacy_invoked; |
| 6547 | break; |
| 6548 | |
| 6549 | default: |
| 6550 | return -EOPNOTSUPP; |
| 6551 | } |
| 6552 | return 0; |
| 6553 | } |
| 6554 | |
| 6555 | /* SIOCSIWENCODEEXT */ |
| 6556 | static int ipw_wx_set_encodeext(struct net_device *dev, |
| 6557 | struct iw_request_info *info, |
| 6558 | union iwreq_data *wrqu, char *extra) |
| 6559 | { |
| 6560 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6561 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 6562 | |
| 6563 | if (hwcrypto) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6564 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6565 | /* IPW HW can't build TKIP MIC, |
| 6566 | host decryption still needed */ |
| 6567 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) |
| 6568 | priv->ieee->host_mc_decrypt = 1; |
| 6569 | else { |
| 6570 | priv->ieee->host_encrypt = 0; |
| 6571 | priv->ieee->host_encrypt_msdu = 1; |
| 6572 | priv->ieee->host_decrypt = 1; |
| 6573 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6574 | } else { |
| 6575 | priv->ieee->host_encrypt = 0; |
| 6576 | priv->ieee->host_encrypt_msdu = 0; |
| 6577 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 6578 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6579 | } |
| 6580 | } |
| 6581 | |
| 6582 | return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
| 6583 | } |
| 6584 | |
| 6585 | /* SIOCGIWENCODEEXT */ |
| 6586 | static int ipw_wx_get_encodeext(struct net_device *dev, |
| 6587 | struct iw_request_info *info, |
| 6588 | union iwreq_data *wrqu, char *extra) |
| 6589 | { |
| 6590 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6591 | return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); |
| 6592 | } |
| 6593 | |
| 6594 | /* SIOCSIWMLME */ |
| 6595 | static int ipw_wx_set_mlme(struct net_device *dev, |
| 6596 | struct iw_request_info *info, |
| 6597 | union iwreq_data *wrqu, char *extra) |
| 6598 | { |
| 6599 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6600 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 6601 | u16 reason; |
| 6602 | |
| 6603 | reason = cpu_to_le16(mlme->reason_code); |
| 6604 | |
| 6605 | switch (mlme->cmd) { |
| 6606 | case IW_MLME_DEAUTH: |
| 6607 | // silently ignore |
| 6608 | break; |
| 6609 | |
| 6610 | case IW_MLME_DISASSOC: |
| 6611 | ipw_disassociate(priv); |
| 6612 | break; |
| 6613 | |
| 6614 | default: |
| 6615 | return -EOPNOTSUPP; |
| 6616 | } |
| 6617 | return 0; |
| 6618 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6619 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6620 | #ifdef CONFIG_IPW_QOS |
| 6621 | |
| 6622 | /* QoS */ |
| 6623 | /* |
| 6624 | * get the modulation type of the current network or |
| 6625 | * the card current mode |
| 6626 | */ |
| 6627 | u8 ipw_qos_current_mode(struct ipw_priv * priv) |
| 6628 | { |
| 6629 | u8 mode = 0; |
| 6630 | |
| 6631 | if (priv->status & STATUS_ASSOCIATED) { |
| 6632 | unsigned long flags; |
| 6633 | |
| 6634 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6635 | mode = priv->assoc_network->mode; |
| 6636 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6637 | } else { |
| 6638 | mode = priv->ieee->mode; |
| 6639 | } |
| 6640 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); |
| 6641 | return mode; |
| 6642 | } |
| 6643 | |
| 6644 | /* |
| 6645 | * Handle management frame beacon and probe response |
| 6646 | */ |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 6647 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
| 6648 | int active_network, |
| 6649 | struct ieee80211_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6650 | { |
| 6651 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6652 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6653 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6654 | network->qos_data.active = network->qos_data.supported; |
| 6655 | |
| 6656 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6657 | if (active_network && |
| 6658 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6659 | network->qos_data.active = network->qos_data.supported; |
| 6660 | |
| 6661 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 6662 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 6663 | (network->qos_data.old_param_count != |
| 6664 | network->qos_data.param_count)) { |
| 6665 | network->qos_data.old_param_count = |
| 6666 | network->qos_data.param_count; |
| 6667 | schedule_work(&priv->qos_activate); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6668 | IPW_DEBUG_QOS("QoS parameters change call " |
| 6669 | "qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6670 | } |
| 6671 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6672 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
| 6673 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6674 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6675 | else |
| 6676 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6677 | &def_parameters_OFDM, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6678 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6679 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
| 6680 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); |
| 6681 | schedule_work(&priv->qos_activate); |
| 6682 | } |
| 6683 | |
| 6684 | network->qos_data.active = 0; |
| 6685 | network->qos_data.supported = 0; |
| 6686 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6687 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6688 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { |
| 6689 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) |
| 6690 | if ((network->capability & WLAN_CAPABILITY_IBSS) && |
| 6691 | !(network->flags & NETWORK_EMPTY_ESSID)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6692 | if ((network->ssid_len == |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6693 | priv->assoc_network->ssid_len) && |
| 6694 | !memcmp(network->ssid, |
| 6695 | priv->assoc_network->ssid, |
| 6696 | network->ssid_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6697 | queue_work(priv->workqueue, |
| 6698 | &priv->merge_networks); |
| 6699 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6700 | } |
| 6701 | |
| 6702 | return 0; |
| 6703 | } |
| 6704 | |
| 6705 | /* |
| 6706 | * This function set up the firmware to support QoS. It sends |
| 6707 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO |
| 6708 | */ |
| 6709 | static int ipw_qos_activate(struct ipw_priv *priv, |
| 6710 | struct ieee80211_qos_data *qos_network_data) |
| 6711 | { |
| 6712 | int err; |
| 6713 | struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS]; |
| 6714 | struct ieee80211_qos_parameters *active_one = NULL; |
| 6715 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6716 | u32 burst_duration; |
| 6717 | int i; |
| 6718 | u8 type; |
| 6719 | |
| 6720 | type = ipw_qos_current_mode(priv); |
| 6721 | |
| 6722 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); |
| 6723 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); |
| 6724 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); |
| 6725 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); |
| 6726 | |
| 6727 | if (qos_network_data == NULL) { |
| 6728 | if (type == IEEE_B) { |
| 6729 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); |
| 6730 | active_one = &def_parameters_CCK; |
| 6731 | } else |
| 6732 | active_one = &def_parameters_OFDM; |
| 6733 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6734 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6735 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6736 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6737 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
| 6738 | (u16) burst_duration; |
| 6739 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6740 | if (type == IEEE_B) { |
| 6741 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", |
| 6742 | type); |
| 6743 | if (priv->qos_data.qos_enable == 0) |
| 6744 | active_one = &def_parameters_CCK; |
| 6745 | else |
| 6746 | active_one = priv->qos_data.def_qos_parm_CCK; |
| 6747 | } else { |
| 6748 | if (priv->qos_data.qos_enable == 0) |
| 6749 | active_one = &def_parameters_OFDM; |
| 6750 | else |
| 6751 | active_one = priv->qos_data.def_qos_parm_OFDM; |
| 6752 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6753 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6754 | } else { |
| 6755 | unsigned long flags; |
| 6756 | int active; |
| 6757 | |
| 6758 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6759 | active_one = &(qos_network_data->parameters); |
| 6760 | qos_network_data->old_param_count = |
| 6761 | qos_network_data->param_count; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6762 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6763 | active = qos_network_data->supported; |
| 6764 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6765 | |
| 6766 | if (active == 0) { |
| 6767 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 6768 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
| 6769 | qos_parameters[QOS_PARAM_SET_ACTIVE]. |
| 6770 | tx_op_limit[i] = (u16) burst_duration; |
| 6771 | } |
| 6772 | } |
| 6773 | |
| 6774 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6775 | err = ipw_send_qos_params_command(priv, |
| 6776 | (struct ieee80211_qos_parameters *) |
| 6777 | &(qos_parameters[0])); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6778 | if (err) |
| 6779 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); |
| 6780 | |
| 6781 | return err; |
| 6782 | } |
| 6783 | |
| 6784 | /* |
| 6785 | * send IPW_CMD_WME_INFO to the firmware |
| 6786 | */ |
| 6787 | static int ipw_qos_set_info_element(struct ipw_priv *priv) |
| 6788 | { |
| 6789 | int ret = 0; |
| 6790 | struct ieee80211_qos_information_element qos_info; |
| 6791 | |
| 6792 | if (priv == NULL) |
| 6793 | return -1; |
| 6794 | |
| 6795 | qos_info.elementID = QOS_ELEMENT_ID; |
| 6796 | qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2; |
| 6797 | |
| 6798 | qos_info.version = QOS_VERSION_1; |
| 6799 | qos_info.ac_info = 0; |
| 6800 | |
| 6801 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); |
| 6802 | qos_info.qui_type = QOS_OUI_TYPE; |
| 6803 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; |
| 6804 | |
| 6805 | ret = ipw_send_qos_info_command(priv, &qos_info); |
| 6806 | if (ret != 0) { |
| 6807 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); |
| 6808 | } |
| 6809 | return ret; |
| 6810 | } |
| 6811 | |
| 6812 | /* |
| 6813 | * Set the QoS parameter with the association request structure |
| 6814 | */ |
| 6815 | static int ipw_qos_association(struct ipw_priv *priv, |
| 6816 | struct ieee80211_network *network) |
| 6817 | { |
| 6818 | int err = 0; |
| 6819 | struct ieee80211_qos_data *qos_data = NULL; |
| 6820 | struct ieee80211_qos_data ibss_data = { |
| 6821 | .supported = 1, |
| 6822 | .active = 1, |
| 6823 | }; |
| 6824 | |
| 6825 | switch (priv->ieee->iw_mode) { |
| 6826 | case IW_MODE_ADHOC: |
| 6827 | if (!(network->capability & WLAN_CAPABILITY_IBSS)) |
| 6828 | BUG(); |
| 6829 | |
| 6830 | qos_data = &ibss_data; |
| 6831 | break; |
| 6832 | |
| 6833 | case IW_MODE_INFRA: |
| 6834 | qos_data = &network->qos_data; |
| 6835 | break; |
| 6836 | |
| 6837 | default: |
| 6838 | BUG(); |
| 6839 | break; |
| 6840 | } |
| 6841 | |
| 6842 | err = ipw_qos_activate(priv, qos_data); |
| 6843 | if (err) { |
| 6844 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; |
| 6845 | return err; |
| 6846 | } |
| 6847 | |
| 6848 | if (priv->qos_data.qos_enable && qos_data->supported) { |
| 6849 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); |
| 6850 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; |
| 6851 | return ipw_qos_set_info_element(priv); |
| 6852 | } |
| 6853 | |
| 6854 | return 0; |
| 6855 | } |
| 6856 | |
| 6857 | /* |
| 6858 | * handling the beaconing responces. if we get different QoS setting |
| 6859 | * of the network from the the associated setting adjust the QoS |
| 6860 | * setting |
| 6861 | */ |
| 6862 | static int ipw_qos_association_resp(struct ipw_priv *priv, |
| 6863 | struct ieee80211_network *network) |
| 6864 | { |
| 6865 | int ret = 0; |
| 6866 | unsigned long flags; |
| 6867 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6868 | int set_qos_param = 0; |
| 6869 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6870 | if ((priv == NULL) || (network == NULL) || |
| 6871 | (priv->assoc_network == NULL)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6872 | return ret; |
| 6873 | |
| 6874 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 6875 | return ret; |
| 6876 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6877 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6878 | return ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6879 | |
| 6880 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6881 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6882 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6883 | sizeof(struct ieee80211_qos_data)); |
| 6884 | priv->assoc_network->qos_data.active = 1; |
| 6885 | if ((network->qos_data.old_param_count != |
| 6886 | network->qos_data.param_count)) { |
| 6887 | set_qos_param = 1; |
| 6888 | network->qos_data.old_param_count = |
| 6889 | network->qos_data.param_count; |
| 6890 | } |
| 6891 | |
| 6892 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6893 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
| 6894 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6895 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6896 | else |
| 6897 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6898 | &def_parameters_OFDM, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6899 | priv->assoc_network->qos_data.active = 0; |
| 6900 | priv->assoc_network->qos_data.supported = 0; |
| 6901 | set_qos_param = 1; |
| 6902 | } |
| 6903 | |
| 6904 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6905 | |
| 6906 | if (set_qos_param == 1) |
| 6907 | schedule_work(&priv->qos_activate); |
| 6908 | |
| 6909 | return ret; |
| 6910 | } |
| 6911 | |
| 6912 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) |
| 6913 | { |
| 6914 | u32 ret = 0; |
| 6915 | |
| 6916 | if ((priv == NULL)) |
| 6917 | return 0; |
| 6918 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6919 | if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6920 | ret = priv->qos_data.burst_duration_CCK; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6921 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6922 | ret = priv->qos_data.burst_duration_OFDM; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6923 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6924 | return ret; |
| 6925 | } |
| 6926 | |
| 6927 | /* |
| 6928 | * Initialize the setting of QoS global |
| 6929 | */ |
| 6930 | static void ipw_qos_init(struct ipw_priv *priv, int enable, |
| 6931 | int burst_enable, u32 burst_duration_CCK, |
| 6932 | u32 burst_duration_OFDM) |
| 6933 | { |
| 6934 | priv->qos_data.qos_enable = enable; |
| 6935 | |
| 6936 | if (priv->qos_data.qos_enable) { |
| 6937 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; |
| 6938 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; |
| 6939 | IPW_DEBUG_QOS("QoS is enabled\n"); |
| 6940 | } else { |
| 6941 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; |
| 6942 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; |
| 6943 | IPW_DEBUG_QOS("QoS is not enabled\n"); |
| 6944 | } |
| 6945 | |
| 6946 | priv->qos_data.burst_enable = burst_enable; |
| 6947 | |
| 6948 | if (burst_enable) { |
| 6949 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; |
| 6950 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; |
| 6951 | } else { |
| 6952 | priv->qos_data.burst_duration_CCK = 0; |
| 6953 | priv->qos_data.burst_duration_OFDM = 0; |
| 6954 | } |
| 6955 | } |
| 6956 | |
| 6957 | /* |
| 6958 | * map the packet priority to the right TX Queue |
| 6959 | */ |
| 6960 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) |
| 6961 | { |
| 6962 | if (priority > 7 || !priv->qos_data.qos_enable) |
| 6963 | priority = 0; |
| 6964 | |
| 6965 | return from_priority_to_tx_queue[priority] - 1; |
| 6966 | } |
| 6967 | |
| 6968 | /* |
| 6969 | * add QoS parameter to the TX command |
| 6970 | */ |
| 6971 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, |
| 6972 | u16 priority, |
| 6973 | struct tfd_data *tfd, u8 unicast) |
| 6974 | { |
| 6975 | int ret = 0; |
| 6976 | int tx_queue_id = 0; |
| 6977 | struct ieee80211_qos_data *qos_data = NULL; |
| 6978 | int active, supported; |
| 6979 | unsigned long flags; |
| 6980 | |
| 6981 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 6982 | return 0; |
| 6983 | |
| 6984 | qos_data = &priv->assoc_network->qos_data; |
| 6985 | |
| 6986 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6987 | |
| 6988 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 6989 | if (unicast == 0) |
| 6990 | qos_data->active = 0; |
| 6991 | else |
| 6992 | qos_data->active = qos_data->supported; |
| 6993 | } |
| 6994 | |
| 6995 | active = qos_data->active; |
| 6996 | supported = qos_data->supported; |
| 6997 | |
| 6998 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6999 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7000 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
| 7001 | "unicast %d\n", |
| 7002 | priv->qos_data.qos_enable, active, supported, unicast); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7003 | if (active && priv->qos_data.qos_enable) { |
| 7004 | ret = from_priority_to_tx_queue[priority]; |
| 7005 | tx_queue_id = ret - 1; |
| 7006 | IPW_DEBUG_QOS("QoS packet priority is %d \n", priority); |
| 7007 | if (priority <= 7) { |
| 7008 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; |
| 7009 | tfd->tfd.tfd_26.mchdr.qos_ctrl = priority; |
| 7010 | tfd->tfd.tfd_26.mchdr.frame_ctl |= |
| 7011 | IEEE80211_STYPE_QOS_DATA; |
| 7012 | |
| 7013 | if (priv->qos_data.qos_no_ack_mask & |
| 7014 | (1UL << tx_queue_id)) { |
| 7015 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; |
| 7016 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= |
| 7017 | CTRL_QOS_NO_ACK; |
| 7018 | } |
| 7019 | } |
| 7020 | } |
| 7021 | |
| 7022 | return ret; |
| 7023 | } |
| 7024 | |
| 7025 | /* |
| 7026 | * background support to run QoS activate functionality |
| 7027 | */ |
| 7028 | static void ipw_bg_qos_activate(void *data) |
| 7029 | { |
| 7030 | struct ipw_priv *priv = data; |
| 7031 | |
| 7032 | if (priv == NULL) |
| 7033 | return; |
| 7034 | |
| 7035 | down(&priv->sem); |
| 7036 | |
| 7037 | if (priv->status & STATUS_ASSOCIATED) |
| 7038 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); |
| 7039 | |
| 7040 | up(&priv->sem); |
| 7041 | } |
| 7042 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7043 | static int ipw_handle_probe_response(struct net_device *dev, |
| 7044 | struct ieee80211_probe_response *resp, |
| 7045 | struct ieee80211_network *network) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7046 | { |
| 7047 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7048 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7049 | (network == priv->assoc_network)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7050 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7051 | ipw_qos_handle_probe_response(priv, active_network, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7052 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7053 | return 0; |
| 7054 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7055 | |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 7056 | static int ipw_handle_beacon(struct net_device *dev, |
| 7057 | struct ieee80211_beacon *resp, |
| 7058 | struct ieee80211_network *network) |
| 7059 | { |
| 7060 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 7061 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
| 7062 | (network == priv->assoc_network)); |
| 7063 | |
| 7064 | ipw_qos_handle_probe_response(priv, active_network, network); |
| 7065 | |
| 7066 | return 0; |
| 7067 | } |
| 7068 | |
| 7069 | static int ipw_handle_assoc_response(struct net_device *dev, |
| 7070 | struct ieee80211_assoc_response *resp, |
| 7071 | struct ieee80211_network *network) |
| 7072 | { |
| 7073 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 7074 | ipw_qos_association_resp(priv, network); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7075 | return 0; |
| 7076 | } |
| 7077 | |
| 7078 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
| 7079 | *qos_param) |
| 7080 | { |
| 7081 | struct host_cmd cmd = { |
| 7082 | .cmd = IPW_CMD_QOS_PARAMETERS, |
| 7083 | .len = (sizeof(struct ieee80211_qos_parameters) * 3) |
| 7084 | }; |
| 7085 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7086 | memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 7087 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7088 | } |
| 7089 | |
| 7090 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element |
| 7091 | *qos_param) |
| 7092 | { |
| 7093 | struct host_cmd cmd = { |
| 7094 | .cmd = IPW_CMD_WME_INFO, |
| 7095 | .len = sizeof(*qos_param) |
| 7096 | }; |
| 7097 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7098 | memcpy(cmd.param, qos_param, sizeof(*qos_param)); |
James Ketrenos | 9ddf84f | 2005-08-16 17:07:11 -0500 | [diff] [blame] | 7099 | return ipw_send_cmd(priv, &cmd); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | #endif /* CONFIG_IPW_QOS */ |
| 7103 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7104 | static int ipw_associate_network(struct ipw_priv *priv, |
| 7105 | struct ieee80211_network *network, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7106 | struct ipw_supported_rates *rates, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7107 | { |
| 7108 | int err; |
| 7109 | |
| 7110 | if (priv->config & CFG_FIXED_RATE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7111 | ipw_set_fixed_rate(priv, network->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7112 | |
| 7113 | if (!(priv->config & CFG_STATIC_ESSID)) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7114 | priv->essid_len = min(network->ssid_len, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7115 | (u8) IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7116 | memcpy(priv->essid, network->ssid, priv->essid_len); |
| 7117 | } |
| 7118 | |
| 7119 | network->last_associate = jiffies; |
| 7120 | |
| 7121 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); |
| 7122 | priv->assoc_request.channel = network->channel; |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7123 | priv->assoc_request.auth_key = 0; |
| 7124 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7125 | if ((priv->capability & CAP_PRIVACY_ON) && |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7126 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7127 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7128 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
| 7129 | |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7130 | if ((priv->ieee->sec.level == SEC_LEVEL_1) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7131 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 7132 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
Zhu Yi | 3e234b4 | 2006-01-24 16:36:52 +0800 | [diff] [blame] | 7133 | |
| 7134 | } else if ((priv->capability & CAP_PRIVACY_ON) && |
| 7135 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) |
| 7136 | priv->assoc_request.auth_type = AUTH_LEAP; |
| 7137 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7138 | priv->assoc_request.auth_type = AUTH_OPEN; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7139 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7140 | if (priv->ieee->wpa_ie_len) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7141 | priv->assoc_request.policy_support = 0x02; /* RSN active */ |
| 7142 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
| 7143 | priv->ieee->wpa_ie_len); |
| 7144 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7145 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7146 | /* |
| 7147 | * It is valid for our ieee device to support multiple modes, but |
| 7148 | * 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] | 7149 | * just one mode. |
| 7150 | */ |
| 7151 | if (network->mode & priv->ieee->mode & IEEE_A) |
| 7152 | priv->assoc_request.ieee_mode = IPW_A_MODE; |
| 7153 | else if (network->mode & priv->ieee->mode & IEEE_G) |
| 7154 | priv->assoc_request.ieee_mode = IPW_G_MODE; |
| 7155 | else if (network->mode & priv->ieee->mode & IEEE_B) |
| 7156 | priv->assoc_request.ieee_mode = IPW_B_MODE; |
| 7157 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7158 | priv->assoc_request.capability = network->capability; |
| 7159 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7160 | && !(priv->config & CFG_PREAMBLE_LONG)) { |
| 7161 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; |
| 7162 | } else { |
| 7163 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; |
| 7164 | |
| 7165 | /* Clear the short preamble if we won't be supporting it */ |
| 7166 | priv->assoc_request.capability &= |
| 7167 | ~WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 7168 | } |
| 7169 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7170 | /* Clear capability bits that aren't used in Ad Hoc */ |
| 7171 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7172 | priv->assoc_request.capability &= |
| 7173 | ~WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 7174 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7175 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7176 | "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] | 7177 | roaming ? "Rea" : "A", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7178 | escape_essid(priv->essid, priv->essid_len), |
| 7179 | network->channel, |
| 7180 | ipw_modes[priv->assoc_request.ieee_mode], |
| 7181 | rates->num_rates, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7182 | (priv->assoc_request.preamble_length == |
| 7183 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", |
| 7184 | network->capability & |
| 7185 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7186 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7187 | priv->capability & CAP_PRIVACY_ON ? |
| 7188 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7189 | "(open)") : "", |
| 7190 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7191 | priv->capability & CAP_PRIVACY_ON ? |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7192 | '1' + priv->ieee->sec.active_key : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7193 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7194 | |
| 7195 | priv->assoc_request.beacon_interval = network->beacon_interval; |
| 7196 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7197 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7198 | priv->assoc_request.assoc_type = HC_IBSS_START; |
| 7199 | priv->assoc_request.assoc_tsf_msw = 0; |
| 7200 | priv->assoc_request.assoc_tsf_lsw = 0; |
| 7201 | } else { |
| 7202 | if (unlikely(roaming)) |
| 7203 | priv->assoc_request.assoc_type = HC_REASSOCIATE; |
| 7204 | else |
| 7205 | priv->assoc_request.assoc_type = HC_ASSOCIATE; |
| 7206 | priv->assoc_request.assoc_tsf_msw = network->time_stamp[1]; |
| 7207 | priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0]; |
| 7208 | } |
| 7209 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7210 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7211 | |
| 7212 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7213 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); |
| 7214 | priv->assoc_request.atim_window = network->atim_window; |
| 7215 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7216 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7217 | priv->assoc_request.atim_window = 0; |
| 7218 | } |
| 7219 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7220 | priv->assoc_request.listen_interval = network->listen_interval; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7221 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7222 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 7223 | if (err) { |
| 7224 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); |
| 7225 | return err; |
| 7226 | } |
| 7227 | |
| 7228 | rates->ieee_mode = priv->assoc_request.ieee_mode; |
| 7229 | rates->purpose = IPW_RATE_CONNECT; |
| 7230 | ipw_send_supported_rates(priv, rates); |
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->assoc_request.ieee_mode == IPW_G_MODE) |
| 7233 | priv->sys_config.dot11g_auto_detection = 1; |
| 7234 | else |
| 7235 | priv->sys_config.dot11g_auto_detection = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7236 | |
| 7237 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7238 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 7239 | else |
| 7240 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 7241 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7242 | err = ipw_send_system_config(priv, &priv->sys_config); |
| 7243 | if (err) { |
| 7244 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); |
| 7245 | return err; |
| 7246 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7247 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7248 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7249 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7250 | if (err) { |
| 7251 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7252 | return err; |
| 7253 | } |
| 7254 | |
| 7255 | /* |
| 7256 | * If preemption is enabled, it is possible for the association |
| 7257 | * to complete before we return from ipw_send_associate. Therefore |
| 7258 | * we have to be sure and update our priviate data first. |
| 7259 | */ |
| 7260 | priv->channel = network->channel; |
| 7261 | memcpy(priv->bssid, network->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7262 | priv->status |= STATUS_ASSOCIATING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7263 | priv->status &= ~STATUS_SECURITY_UPDATED; |
| 7264 | |
| 7265 | priv->assoc_network = network; |
| 7266 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7267 | #ifdef CONFIG_IPW_QOS |
| 7268 | ipw_qos_association(priv, network); |
| 7269 | #endif |
| 7270 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7271 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 7272 | if (err) { |
| 7273 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7274 | return err; |
| 7275 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7276 | |
| 7277 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7278 | escape_essid(priv->essid, priv->essid_len), |
| 7279 | MAC_ARG(priv->bssid)); |
| 7280 | |
| 7281 | return 0; |
| 7282 | } |
| 7283 | |
| 7284 | static void ipw_roam(void *data) |
| 7285 | { |
| 7286 | struct ipw_priv *priv = data; |
| 7287 | struct ieee80211_network *network = NULL; |
| 7288 | struct ipw_network_match match = { |
| 7289 | .network = priv->assoc_network |
| 7290 | }; |
| 7291 | |
| 7292 | /* The roaming process is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7293 | * |
| 7294 | * 1. Missed beacon threshold triggers the roaming process by |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7295 | * setting the status ROAM bit and requesting a scan. |
| 7296 | * 2. When the scan completes, it schedules the ROAM work |
| 7297 | * 3. The ROAM work looks at all of the known networks for one that |
| 7298 | * is a better network than the currently associated. If none |
| 7299 | * found, the ROAM process is over (ROAM bit cleared) |
| 7300 | * 4. If a better network is found, a disassociation request is |
| 7301 | * sent. |
| 7302 | * 5. When the disassociation completes, the roam work is again |
| 7303 | * scheduled. The second time through, the driver is no longer |
| 7304 | * associated, and the newly selected network is sent an |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7305 | * association request. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7306 | * 6. At this point ,the roaming process is complete and the ROAM |
| 7307 | * status bit is cleared. |
| 7308 | */ |
| 7309 | |
| 7310 | /* If we are no longer associated, and the roaming bit is no longer |
| 7311 | * set, then we are not actively roaming, so just return */ |
| 7312 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) |
| 7313 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7314 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7315 | if (priv->status & STATUS_ASSOCIATED) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7316 | /* First pass through ROAM process -- look for a better |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7317 | * network */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7318 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7319 | u8 rssi = priv->assoc_network->stats.rssi; |
| 7320 | priv->assoc_network->stats.rssi = -128; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7321 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7322 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 7323 | if (network != priv->assoc_network) |
| 7324 | ipw_best_network(priv, &match, network, 1); |
| 7325 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7326 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7327 | priv->assoc_network->stats.rssi = rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7328 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7329 | if (match.network == priv->assoc_network) { |
| 7330 | IPW_DEBUG_ASSOC("No better APs in this network to " |
| 7331 | "roam to.\n"); |
| 7332 | priv->status &= ~STATUS_ROAMING; |
| 7333 | ipw_debug_config(priv); |
| 7334 | return; |
| 7335 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7336 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7337 | ipw_send_disassociate(priv, 1); |
| 7338 | priv->assoc_network = match.network; |
| 7339 | |
| 7340 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7341 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7342 | |
| 7343 | /* Second pass through ROAM process -- request association */ |
| 7344 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); |
| 7345 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); |
| 7346 | priv->status &= ~STATUS_ROAMING; |
| 7347 | } |
| 7348 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7349 | static void ipw_bg_roam(void *data) |
| 7350 | { |
| 7351 | struct ipw_priv *priv = data; |
| 7352 | down(&priv->sem); |
| 7353 | ipw_roam(data); |
| 7354 | up(&priv->sem); |
| 7355 | } |
| 7356 | |
| 7357 | static int ipw_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7358 | { |
| 7359 | struct ipw_priv *priv = data; |
| 7360 | |
| 7361 | struct ieee80211_network *network = NULL; |
| 7362 | struct ipw_network_match match = { |
| 7363 | .network = NULL |
| 7364 | }; |
| 7365 | struct ipw_supported_rates *rates; |
| 7366 | struct list_head *element; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7367 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7368 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7369 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 7370 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); |
| 7371 | return 0; |
| 7372 | } |
| 7373 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7374 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7375 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
| 7376 | "progress)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7377 | return 0; |
| 7378 | } |
| 7379 | |
Hong Liu | e632472 | 2005-09-14 21:04:15 -0500 | [diff] [blame] | 7380 | if (priv->status & STATUS_DISASSOCIATING) { |
| 7381 | IPW_DEBUG_ASSOC("Not attempting association (in " |
| 7382 | "disassociating)\n "); |
| 7383 | queue_work(priv->workqueue, &priv->associate); |
| 7384 | return 0; |
| 7385 | } |
| 7386 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7387 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7388 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
| 7389 | "initialized)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7390 | return 0; |
| 7391 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7392 | |
| 7393 | if (!(priv->config & CFG_ASSOCIATE) && |
| 7394 | !(priv->config & (CFG_STATIC_ESSID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7395 | CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7396 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7397 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7398 | } |
| 7399 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7400 | /* Protect our use of the network_list */ |
| 7401 | spin_lock_irqsave(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7402 | list_for_each_entry(network, &priv->ieee->network_list, list) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7403 | ipw_best_network(priv, &match, network, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7404 | |
| 7405 | network = match.network; |
| 7406 | rates = &match.rates; |
| 7407 | |
| 7408 | if (network == NULL && |
| 7409 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7410 | priv->config & CFG_ADHOC_CREATE && |
| 7411 | priv->config & CFG_STATIC_ESSID && |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7412 | priv->config & CFG_STATIC_CHANNEL && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7413 | !list_empty(&priv->ieee->network_free_list)) { |
| 7414 | element = priv->ieee->network_free_list.next; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7415 | network = list_entry(element, struct ieee80211_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7416 | ipw_adhoc_create(priv, network); |
| 7417 | rates = &priv->rates; |
| 7418 | list_del(element); |
| 7419 | list_add_tail(&network->list, &priv->ieee->network_list); |
| 7420 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7421 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7422 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7423 | /* If we reached the end of the list, then we don't have any valid |
| 7424 | * matching APs */ |
| 7425 | if (!network) { |
| 7426 | ipw_debug_config(priv); |
| 7427 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7428 | if (!(priv->status & STATUS_SCANNING)) { |
| 7429 | if (!(priv->config & CFG_SPEED_SCAN)) |
| 7430 | queue_delayed_work(priv->workqueue, |
| 7431 | &priv->request_scan, |
| 7432 | SCAN_INTERVAL); |
| 7433 | else |
| 7434 | queue_work(priv->workqueue, |
| 7435 | &priv->request_scan); |
| 7436 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7437 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7438 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7439 | } |
| 7440 | |
| 7441 | ipw_associate_network(priv, network, rates, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7442 | |
| 7443 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7444 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7445 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7446 | static void ipw_bg_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7447 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7448 | struct ipw_priv *priv = data; |
| 7449 | down(&priv->sem); |
| 7450 | ipw_associate(data); |
| 7451 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7452 | } |
| 7453 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7454 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
| 7455 | struct sk_buff *skb) |
| 7456 | { |
| 7457 | struct ieee80211_hdr *hdr; |
| 7458 | u16 fc; |
| 7459 | |
| 7460 | hdr = (struct ieee80211_hdr *)skb->data; |
| 7461 | fc = le16_to_cpu(hdr->frame_ctl); |
| 7462 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 7463 | return; |
| 7464 | |
| 7465 | fc &= ~IEEE80211_FCTL_PROTECTED; |
| 7466 | hdr->frame_ctl = cpu_to_le16(fc); |
| 7467 | switch (priv->ieee->sec.level) { |
| 7468 | case SEC_LEVEL_3: |
| 7469 | /* Remove CCMP HDR */ |
| 7470 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7471 | skb->data + IEEE80211_3ADDR_LEN + 8, |
| 7472 | skb->len - IEEE80211_3ADDR_LEN - 8); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7473 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7474 | break; |
| 7475 | case SEC_LEVEL_2: |
| 7476 | break; |
| 7477 | case SEC_LEVEL_1: |
| 7478 | /* Remove IV */ |
| 7479 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7480 | skb->data + IEEE80211_3ADDR_LEN + 4, |
| 7481 | skb->len - IEEE80211_3ADDR_LEN - 4); |
Zhu Yi | f4ff497 | 2005-09-12 10:48:48 -0500 | [diff] [blame] | 7482 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7483 | break; |
| 7484 | case SEC_LEVEL_0: |
| 7485 | break; |
| 7486 | default: |
| 7487 | printk(KERN_ERR "Unknow security level %d\n", |
| 7488 | priv->ieee->sec.level); |
| 7489 | break; |
| 7490 | } |
| 7491 | } |
| 7492 | |
| 7493 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
| 7494 | struct ipw_rx_mem_buffer *rxb, |
| 7495 | struct ieee80211_rx_stats *stats) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7496 | { |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7497 | struct ieee80211_hdr_4addr *hdr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7498 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7499 | |
| 7500 | /* We received data from the HW, so stop the watchdog */ |
| 7501 | priv->net_dev->trans_start = jiffies; |
| 7502 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7503 | /* We only process data packets if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7504 | * interface is open */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7505 | 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] | 7506 | skb_tailroom(rxb->skb))) { |
| 7507 | priv->ieee->stats.rx_errors++; |
| 7508 | priv->wstats.discard.misc++; |
| 7509 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7510 | return; |
| 7511 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7512 | priv->ieee->stats.rx_dropped++; |
| 7513 | priv->wstats.discard.misc++; |
| 7514 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7515 | return; |
| 7516 | } |
| 7517 | |
| 7518 | /* Advance skb->data to the start of the actual payload */ |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 7519 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7520 | |
| 7521 | /* Set the size of the skb to the size of the frame */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7522 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7523 | |
| 7524 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7525 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7526 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7527 | hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data; |
| 7528 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7529 | (is_multicast_ether_addr(hdr->addr1) ? |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 7530 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7531 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
| 7532 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7533 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7534 | priv->ieee->stats.rx_errors++; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7535 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7536 | rxb->skb = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7537 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7538 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7539 | } |
| 7540 | |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7541 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 7542 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, |
| 7543 | struct ipw_rx_mem_buffer *rxb, |
| 7544 | struct ieee80211_rx_stats *stats) |
| 7545 | { |
| 7546 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7547 | struct ipw_rx_frame *frame = &pkt->u.frame; |
| 7548 | |
| 7549 | /* initial pull of some data */ |
| 7550 | u16 received_channel = frame->received_channel; |
| 7551 | u8 antennaAndPhy = frame->antennaAndPhy; |
| 7552 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ |
| 7553 | u16 pktrate = frame->rate; |
| 7554 | |
| 7555 | /* Magic struct that slots into the radiotap header -- no reason |
| 7556 | * to build this manually element by element, we can write it much |
| 7557 | * more efficiently than we can parse it. ORDER MATTERS HERE */ |
| 7558 | struct ipw_rt_hdr { |
| 7559 | struct ieee80211_radiotap_header rt_hdr; |
| 7560 | u8 rt_flags; /* radiotap packet flags */ |
| 7561 | u8 rt_rate; /* rate in 500kb/s */ |
| 7562 | u16 rt_channel; /* channel in mhz */ |
| 7563 | u16 rt_chbitmask; /* channel bitfield */ |
| 7564 | s8 rt_dbmsignal; /* signal in dbM, kluged to signed */ |
| 7565 | u8 rt_antenna; /* antenna number */ |
| 7566 | } *ipw_rt; |
| 7567 | |
| 7568 | short len = le16_to_cpu(pkt->u.frame.length); |
| 7569 | |
| 7570 | /* We received data from the HW, so stop the watchdog */ |
| 7571 | priv->net_dev->trans_start = jiffies; |
| 7572 | |
| 7573 | /* We only process data packets if the |
| 7574 | * interface is open */ |
| 7575 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
| 7576 | skb_tailroom(rxb->skb))) { |
| 7577 | priv->ieee->stats.rx_errors++; |
| 7578 | priv->wstats.discard.misc++; |
| 7579 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7580 | return; |
| 7581 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7582 | priv->ieee->stats.rx_dropped++; |
| 7583 | priv->wstats.discard.misc++; |
| 7584 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7585 | return; |
| 7586 | } |
| 7587 | |
| 7588 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use |
| 7589 | * that now */ |
| 7590 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { |
| 7591 | /* FIXME: Should alloc bigger skb instead */ |
| 7592 | priv->ieee->stats.rx_dropped++; |
| 7593 | priv->wstats.discard.misc++; |
| 7594 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 7595 | return; |
| 7596 | } |
| 7597 | |
| 7598 | /* copy the frame itself */ |
| 7599 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), |
| 7600 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); |
| 7601 | |
| 7602 | /* Zero the radiotap static buffer ... We only need to zero the bytes NOT |
| 7603 | * part of our real header, saves a little time. |
| 7604 | * |
| 7605 | * No longer necessary since we fill in all our data. Purge before merging |
| 7606 | * patch officially. |
| 7607 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, |
| 7608 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); |
| 7609 | */ |
| 7610 | |
| 7611 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; |
| 7612 | |
| 7613 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 7614 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
| 7615 | ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */ |
| 7616 | |
| 7617 | /* Big bitfield of all the fields we provide in radiotap */ |
| 7618 | ipw_rt->rt_hdr.it_present = |
| 7619 | ((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 7620 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 7621 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 7622 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 7623 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 7624 | |
| 7625 | /* Zero the flags, we'll add to them as we go */ |
| 7626 | ipw_rt->rt_flags = 0; |
| 7627 | |
| 7628 | /* Convert signal to DBM */ |
| 7629 | ipw_rt->rt_dbmsignal = antsignal; |
| 7630 | |
| 7631 | /* Convert the channel data and set the flags */ |
| 7632 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); |
| 7633 | if (received_channel > 14) { /* 802.11a */ |
| 7634 | ipw_rt->rt_chbitmask = |
| 7635 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 7636 | } else if (antennaAndPhy & 32) { /* 802.11b */ |
| 7637 | ipw_rt->rt_chbitmask = |
| 7638 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 7639 | } else { /* 802.11g */ |
| 7640 | ipw_rt->rt_chbitmask = |
| 7641 | (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
| 7642 | } |
| 7643 | |
| 7644 | /* set the rate in multiples of 500k/s */ |
| 7645 | switch (pktrate) { |
| 7646 | case IPW_TX_RATE_1MB: |
| 7647 | ipw_rt->rt_rate = 2; |
| 7648 | break; |
| 7649 | case IPW_TX_RATE_2MB: |
| 7650 | ipw_rt->rt_rate = 4; |
| 7651 | break; |
| 7652 | case IPW_TX_RATE_5MB: |
| 7653 | ipw_rt->rt_rate = 10; |
| 7654 | break; |
| 7655 | case IPW_TX_RATE_6MB: |
| 7656 | ipw_rt->rt_rate = 12; |
| 7657 | break; |
| 7658 | case IPW_TX_RATE_9MB: |
| 7659 | ipw_rt->rt_rate = 18; |
| 7660 | break; |
| 7661 | case IPW_TX_RATE_11MB: |
| 7662 | ipw_rt->rt_rate = 22; |
| 7663 | break; |
| 7664 | case IPW_TX_RATE_12MB: |
| 7665 | ipw_rt->rt_rate = 24; |
| 7666 | break; |
| 7667 | case IPW_TX_RATE_18MB: |
| 7668 | ipw_rt->rt_rate = 36; |
| 7669 | break; |
| 7670 | case IPW_TX_RATE_24MB: |
| 7671 | ipw_rt->rt_rate = 48; |
| 7672 | break; |
| 7673 | case IPW_TX_RATE_36MB: |
| 7674 | ipw_rt->rt_rate = 72; |
| 7675 | break; |
| 7676 | case IPW_TX_RATE_48MB: |
| 7677 | ipw_rt->rt_rate = 96; |
| 7678 | break; |
| 7679 | case IPW_TX_RATE_54MB: |
| 7680 | ipw_rt->rt_rate = 108; |
| 7681 | break; |
| 7682 | default: |
| 7683 | ipw_rt->rt_rate = 0; |
| 7684 | break; |
| 7685 | } |
| 7686 | |
| 7687 | /* antenna number */ |
| 7688 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ |
| 7689 | |
| 7690 | /* set the preamble flag if we have it */ |
| 7691 | if ((antennaAndPhy & 64)) |
| 7692 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 7693 | |
| 7694 | /* Set the size of the skb to the size of the frame */ |
| 7695 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7696 | |
| 7697 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7698 | |
| 7699 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
| 7700 | priv->ieee->stats.rx_errors++; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7701 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7702 | rxb->skb = NULL; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7703 | /* no LED during capture */ |
| 7704 | } |
| 7705 | } |
| 7706 | #endif |
| 7707 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 7708 | static int is_network_packet(struct ipw_priv *priv, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7709 | struct ieee80211_hdr_4addr *header) |
| 7710 | { |
| 7711 | /* Filter incoming packets to determine if they are targetted toward |
| 7712 | * this network, discarding packets coming from ourselves */ |
| 7713 | switch (priv->ieee->iw_mode) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7714 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7715 | /* packets from our adapter are dropped (echo) */ |
| 7716 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7717 | return 0; |
| 7718 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7719 | /* {broad,multi}cast packets to our BSSID go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7720 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7721 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7722 | |
| 7723 | /* packets to our adapter go through */ |
| 7724 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7725 | ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7726 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7727 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7728 | /* packets from our adapter are dropped (echo) */ |
| 7729 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7730 | return 0; |
| 7731 | |
Peter Jones | 90700fd | 2005-08-26 16:51:06 -0500 | [diff] [blame] | 7732 | /* {broad,multi}cast packets to our BSS go through */ |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 7733 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7734 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
| 7735 | |
| 7736 | /* packets to our adapter go through */ |
| 7737 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7738 | ETH_ALEN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7739 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7740 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7741 | return 1; |
| 7742 | } |
| 7743 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7744 | #define IPW_PACKET_RETRY_TIME HZ |
| 7745 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 7746 | static int is_duplicate_packet(struct ipw_priv *priv, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7747 | struct ieee80211_hdr_4addr *header) |
| 7748 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7749 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 7750 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 7751 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 7752 | u16 *last_seq, *last_frag; |
| 7753 | unsigned long *last_time; |
| 7754 | |
| 7755 | switch (priv->ieee->iw_mode) { |
| 7756 | case IW_MODE_ADHOC: |
| 7757 | { |
| 7758 | struct list_head *p; |
| 7759 | struct ipw_ibss_seq *entry = NULL; |
| 7760 | u8 *mac = header->addr2; |
| 7761 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; |
| 7762 | |
| 7763 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 7764 | entry = |
| 7765 | list_entry(p, struct ipw_ibss_seq, list); |
| 7766 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 7767 | break; |
| 7768 | } |
| 7769 | if (p == &priv->ibss_mac_hash[index]) { |
| 7770 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 7771 | if (!entry) { |
| 7772 | IPW_ERROR |
| 7773 | ("Cannot malloc new mac entry\n"); |
| 7774 | return 0; |
| 7775 | } |
| 7776 | memcpy(entry->mac, mac, ETH_ALEN); |
| 7777 | entry->seq_num = seq; |
| 7778 | entry->frag_num = frag; |
| 7779 | entry->packet_time = jiffies; |
| 7780 | list_add(&entry->list, |
| 7781 | &priv->ibss_mac_hash[index]); |
| 7782 | return 0; |
| 7783 | } |
| 7784 | last_seq = &entry->seq_num; |
| 7785 | last_frag = &entry->frag_num; |
| 7786 | last_time = &entry->packet_time; |
| 7787 | break; |
| 7788 | } |
| 7789 | case IW_MODE_INFRA: |
| 7790 | last_seq = &priv->last_seq_num; |
| 7791 | last_frag = &priv->last_frag_num; |
| 7792 | last_time = &priv->last_packet_time; |
| 7793 | break; |
| 7794 | default: |
| 7795 | return 0; |
| 7796 | } |
| 7797 | if ((*last_seq == seq) && |
| 7798 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { |
| 7799 | if (*last_frag == frag) |
| 7800 | goto drop; |
| 7801 | if (*last_frag + 1 != frag) |
| 7802 | /* out-of-order fragment */ |
| 7803 | goto drop; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7804 | } else |
| 7805 | *last_seq = seq; |
| 7806 | |
Zhu Yi | f57ce7c | 2005-07-13 12:22:15 -0500 | [diff] [blame] | 7807 | *last_frag = frag; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7808 | *last_time = jiffies; |
| 7809 | return 0; |
| 7810 | |
| 7811 | drop: |
Zhu Yi | 87b016c | 2005-08-05 17:17:35 +0800 | [diff] [blame] | 7812 | /* Comment this line now since we observed the card receives |
| 7813 | * duplicate packets but the FCTL_RETRY bit is not set in the |
| 7814 | * IBSS mode with fragmentation enabled. |
| 7815 | BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7816 | return 1; |
| 7817 | } |
| 7818 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7819 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
| 7820 | struct ipw_rx_mem_buffer *rxb, |
| 7821 | struct ieee80211_rx_stats *stats) |
| 7822 | { |
| 7823 | struct sk_buff *skb = rxb->skb; |
| 7824 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; |
| 7825 | struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *) |
| 7826 | (skb->data + IPW_RX_FRAME_SIZE); |
| 7827 | |
| 7828 | ieee80211_rx_mgt(priv->ieee, header, stats); |
| 7829 | |
| 7830 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7831 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 7832 | IEEE80211_STYPE_PROBE_RESP) || |
| 7833 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 7834 | IEEE80211_STYPE_BEACON))) { |
| 7835 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) |
| 7836 | ipw_add_station(priv, header->addr2); |
| 7837 | } |
| 7838 | |
| 7839 | if (priv->config & CFG_NET_STATS) { |
| 7840 | IPW_DEBUG_HC("sending stat packet\n"); |
| 7841 | |
| 7842 | /* Set the size of the skb to the size of the full |
| 7843 | * ipw header and 802.11 frame */ |
| 7844 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + |
| 7845 | IPW_RX_FRAME_SIZE); |
| 7846 | |
| 7847 | /* Advance past the ipw packet header to the 802.11 frame */ |
| 7848 | skb_pull(skb, IPW_RX_FRAME_SIZE); |
| 7849 | |
| 7850 | /* Push the ieee80211_rx_stats before the 802.11 frame */ |
| 7851 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
| 7852 | |
| 7853 | skb->dev = priv->ieee->dev; |
| 7854 | |
| 7855 | /* Point raw at the ieee80211_stats */ |
| 7856 | skb->mac.raw = skb->data; |
| 7857 | |
| 7858 | skb->pkt_type = PACKET_OTHERHOST; |
| 7859 | skb->protocol = __constant_htons(ETH_P_80211_STATS); |
| 7860 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
| 7861 | netif_rx(skb); |
| 7862 | rxb->skb = NULL; |
| 7863 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7864 | } |
| 7865 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7866 | /* |
| 7867 | * Main entry function for recieving a packet with 80211 headers. This |
| 7868 | * should be called when ever the FW has notified us that there is a new |
| 7869 | * skb in the recieve queue. |
| 7870 | */ |
| 7871 | static void ipw_rx(struct ipw_priv *priv) |
| 7872 | { |
| 7873 | struct ipw_rx_mem_buffer *rxb; |
| 7874 | struct ipw_rx_packet *pkt; |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 7875 | struct ieee80211_hdr_4addr *header; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7876 | u32 r, w, i; |
| 7877 | u8 network_packet; |
| 7878 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7879 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
| 7880 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7881 | i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE; |
| 7882 | |
| 7883 | while (i != r) { |
| 7884 | rxb = priv->rxq->queue[i]; |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 7885 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7886 | if (unlikely(rxb == NULL)) { |
| 7887 | printk(KERN_CRIT "Queue not allocated!\n"); |
| 7888 | break; |
| 7889 | } |
| 7890 | #endif |
| 7891 | priv->rxq->queue[i] = NULL; |
| 7892 | |
| 7893 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7894 | IPW_RX_BUF_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7895 | PCI_DMA_FROMDEVICE); |
| 7896 | |
| 7897 | pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7898 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", |
| 7899 | pkt->header.message_type, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7900 | pkt->header.rx_seq_num, pkt->header.control_bits); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7901 | |
| 7902 | switch (pkt->header.message_type) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7903 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
| 7904 | struct ieee80211_rx_stats stats = { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7905 | .rssi = |
| 7906 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7907 | IPW_RSSI_TO_DBM, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7908 | .signal = |
| 7909 | le16_to_cpu(pkt->u.frame.signal), |
| 7910 | .noise = |
| 7911 | le16_to_cpu(pkt->u.frame.noise), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7912 | .rate = pkt->u.frame.rate, |
| 7913 | .mac_time = jiffies, |
| 7914 | .received_channel = |
| 7915 | pkt->u.frame.received_channel, |
| 7916 | .freq = |
| 7917 | (pkt->u.frame. |
| 7918 | control & (1 << 0)) ? |
| 7919 | IEEE80211_24GHZ_BAND : |
| 7920 | IEEE80211_52GHZ_BAND, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7921 | .len = le16_to_cpu(pkt->u.frame.length), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7922 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7923 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7924 | if (stats.rssi != 0) |
| 7925 | stats.mask |= IEEE80211_STATMASK_RSSI; |
| 7926 | if (stats.signal != 0) |
| 7927 | stats.mask |= IEEE80211_STATMASK_SIGNAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7928 | if (stats.noise != 0) |
| 7929 | stats.mask |= IEEE80211_STATMASK_NOISE; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7930 | if (stats.rate != 0) |
| 7931 | stats.mask |= IEEE80211_STATMASK_RATE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7932 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7933 | priv->rx_packets++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7934 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7935 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7936 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7937 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 7938 | ipw_handle_data_packet_monitor(priv, |
| 7939 | rxb, |
| 7940 | &stats); |
| 7941 | #else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7942 | ipw_handle_data_packet(priv, rxb, |
| 7943 | &stats); |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 7944 | #endif |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7945 | break; |
| 7946 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7947 | #endif |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7948 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7949 | header = |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 7950 | (struct ieee80211_hdr_4addr *)(rxb->skb-> |
| 7951 | data + |
| 7952 | IPW_RX_FRAME_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7953 | /* TODO: Check Ad-Hoc dest/source and make sure |
| 7954 | * that we are actually parsing these packets |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7955 | * correctly -- we should probably use the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7956 | * frame control of the packet and disregard |
| 7957 | * the current iw_mode */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7958 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7959 | network_packet = |
| 7960 | is_network_packet(priv, header); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7961 | if (network_packet && priv->assoc_network) { |
| 7962 | priv->assoc_network->stats.rssi = |
| 7963 | stats.rssi; |
| 7964 | average_add(&priv->average_rssi, |
| 7965 | stats.rssi); |
| 7966 | priv->last_rx_rssi = stats.rssi; |
| 7967 | } |
| 7968 | |
| 7969 | IPW_DEBUG_RX("Frame: len=%u\n", |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7970 | le16_to_cpu(pkt->u.frame.length)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7971 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7972 | if (le16_to_cpu(pkt->u.frame.length) < |
| 7973 | frame_hdr_len(header)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7974 | IPW_DEBUG_DROP |
| 7975 | ("Received packet is too small. " |
| 7976 | "Dropping.\n"); |
| 7977 | priv->ieee->stats.rx_errors++; |
| 7978 | priv->wstats.discard.misc++; |
| 7979 | break; |
| 7980 | } |
| 7981 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7982 | switch (WLAN_FC_GET_TYPE |
| 7983 | (le16_to_cpu(header->frame_ctl))) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7984 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7985 | case IEEE80211_FTYPE_MGMT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7986 | ipw_handle_mgmt_packet(priv, rxb, |
| 7987 | &stats); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7988 | break; |
| 7989 | |
| 7990 | case IEEE80211_FTYPE_CTL: |
| 7991 | break; |
| 7992 | |
| 7993 | case IEEE80211_FTYPE_DATA: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7994 | if (unlikely(!network_packet || |
| 7995 | is_duplicate_packet(priv, |
| 7996 | header))) |
| 7997 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7998 | IPW_DEBUG_DROP("Dropping: " |
| 7999 | MAC_FMT ", " |
| 8000 | MAC_FMT ", " |
| 8001 | MAC_FMT "\n", |
| 8002 | MAC_ARG(header-> |
| 8003 | addr1), |
| 8004 | MAC_ARG(header-> |
| 8005 | addr2), |
| 8006 | MAC_ARG(header-> |
| 8007 | addr3)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8008 | break; |
| 8009 | } |
| 8010 | |
| 8011 | ipw_handle_data_packet(priv, rxb, |
| 8012 | &stats); |
| 8013 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8014 | break; |
| 8015 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8016 | break; |
| 8017 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8018 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8019 | case RX_HOST_NOTIFICATION_TYPE:{ |
| 8020 | IPW_DEBUG_RX |
| 8021 | ("Notification: subtype=%02X flags=%02X size=%d\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8022 | pkt->u.notification.subtype, |
| 8023 | pkt->u.notification.flags, |
| 8024 | pkt->u.notification.size); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8025 | ipw_rx_notification(priv, &pkt->u.notification); |
| 8026 | break; |
| 8027 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8028 | |
| 8029 | default: |
| 8030 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", |
| 8031 | pkt->header.message_type); |
| 8032 | break; |
| 8033 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8034 | |
| 8035 | /* For now we just don't re-use anything. We can tweak this |
| 8036 | * later to try and re-use notification packets and SKBs that |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8037 | * fail to Rx correctly */ |
| 8038 | if (rxb->skb != NULL) { |
| 8039 | dev_kfree_skb_any(rxb->skb); |
| 8040 | rxb->skb = NULL; |
| 8041 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8042 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8043 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8044 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8045 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8046 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8047 | i = (i + 1) % RX_QUEUE_SIZE; |
| 8048 | } |
| 8049 | |
| 8050 | /* Backtrack one entry */ |
| 8051 | priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1; |
| 8052 | |
| 8053 | ipw_rx_queue_restock(priv); |
| 8054 | } |
| 8055 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8056 | #define DEFAULT_RTS_THRESHOLD 2304U |
| 8057 | #define MIN_RTS_THRESHOLD 1U |
| 8058 | #define MAX_RTS_THRESHOLD 2304U |
| 8059 | #define DEFAULT_BEACON_INTERVAL 100U |
| 8060 | #define DEFAULT_SHORT_RETRY_LIMIT 7U |
| 8061 | #define DEFAULT_LONG_RETRY_LIMIT 4U |
| 8062 | |
| 8063 | static int ipw_sw_reset(struct ipw_priv *priv, int init) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8064 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8065 | int band, modulation; |
| 8066 | int old_mode = priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8067 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8068 | /* Initialize module parameter values here */ |
| 8069 | priv->config = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8070 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8071 | /* We default to disabling the LED code as right now it causes |
| 8072 | * too many systems to lock up... */ |
| 8073 | if (!led) |
| 8074 | priv->config |= CFG_NO_LED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8075 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8076 | if (associate) |
| 8077 | priv->config |= CFG_ASSOCIATE; |
| 8078 | else |
| 8079 | IPW_DEBUG_INFO("Auto associate disabled.\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8080 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8081 | if (auto_create) |
| 8082 | priv->config |= CFG_ADHOC_CREATE; |
| 8083 | else |
| 8084 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); |
| 8085 | |
Zhu Yi | 17ed081 | 2006-01-24 16:36:31 +0800 | [diff] [blame] | 8086 | priv->config &= ~CFG_STATIC_ESSID; |
| 8087 | priv->essid_len = 0; |
| 8088 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 8089 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8090 | if (disable) { |
| 8091 | priv->status |= STATUS_RF_KILL_SW; |
| 8092 | IPW_DEBUG_INFO("Radio disabled.\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8093 | } |
| 8094 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8095 | if (channel != 0) { |
| 8096 | priv->config |= CFG_STATIC_CHANNEL; |
| 8097 | priv->channel = channel; |
| 8098 | IPW_DEBUG_INFO("Bind to static channel %d\n", channel); |
| 8099 | /* TODO: Validate that provided channel is in range */ |
| 8100 | } |
| 8101 | #ifdef CONFIG_IPW_QOS |
| 8102 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
| 8103 | burst_duration_CCK, burst_duration_OFDM); |
| 8104 | #endif /* CONFIG_IPW_QOS */ |
| 8105 | |
| 8106 | switch (mode) { |
| 8107 | case 1: |
| 8108 | priv->ieee->iw_mode = IW_MODE_ADHOC; |
| 8109 | priv->net_dev->type = ARPHRD_ETHER; |
| 8110 | |
| 8111 | break; |
| 8112 | #ifdef CONFIG_IPW2200_MONITOR |
| 8113 | case 2: |
| 8114 | priv->ieee->iw_mode = IW_MODE_MONITOR; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8115 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 8116 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8117 | #else |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8118 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8119 | #endif |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8120 | break; |
| 8121 | #endif |
| 8122 | default: |
| 8123 | case 0: |
| 8124 | priv->net_dev->type = ARPHRD_ETHER; |
| 8125 | priv->ieee->iw_mode = IW_MODE_INFRA; |
| 8126 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8127 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8128 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8129 | if (hwcrypto) { |
| 8130 | priv->ieee->host_encrypt = 0; |
| 8131 | priv->ieee->host_encrypt_msdu = 0; |
| 8132 | priv->ieee->host_decrypt = 0; |
Hong Liu | 567deaf | 2005-08-31 18:07:22 +0800 | [diff] [blame] | 8133 | priv->ieee->host_mc_decrypt = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8134 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8135 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8136 | |
Zhu Yi | e402c93 | 2005-08-05 17:20:40 +0800 | [diff] [blame] | 8137 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
| 8138 | priv->ieee->host_open_frag = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8139 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8140 | if ((priv->pci_dev->device == 0x4223) || |
| 8141 | (priv->pci_dev->device == 0x4224)) { |
| 8142 | if (init) |
| 8143 | printk(KERN_INFO DRV_NAME |
| 8144 | ": Detected Intel PRO/Wireless 2915ABG Network " |
| 8145 | "Connection\n"); |
| 8146 | priv->ieee->abg_true = 1; |
| 8147 | band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; |
| 8148 | modulation = IEEE80211_OFDM_MODULATION | |
| 8149 | IEEE80211_CCK_MODULATION; |
| 8150 | priv->adapter = IPW_2915ABG; |
| 8151 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8152 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8153 | if (init) |
| 8154 | printk(KERN_INFO DRV_NAME |
| 8155 | ": Detected Intel PRO/Wireless 2200BG Network " |
| 8156 | "Connection\n"); |
| 8157 | |
| 8158 | priv->ieee->abg_true = 0; |
| 8159 | band = IEEE80211_24GHZ_BAND; |
| 8160 | modulation = IEEE80211_OFDM_MODULATION | |
| 8161 | IEEE80211_CCK_MODULATION; |
| 8162 | priv->adapter = IPW_2200BG; |
| 8163 | priv->ieee->mode = IEEE_G | IEEE_B; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8164 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8165 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8166 | priv->ieee->freq_band = band; |
| 8167 | priv->ieee->modulation = modulation; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8168 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8169 | priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8170 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8171 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8172 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8173 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8174 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8175 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; |
| 8176 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8177 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8178 | /* If power management is turned on, default to AC mode */ |
| 8179 | priv->power_mode = IPW_POWER_AC; |
| 8180 | priv->tx_power = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8181 | |
Zhu Yi | 0ece35b | 2005-08-05 17:26:51 +0800 | [diff] [blame] | 8182 | return old_mode == priv->ieee->iw_mode; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8183 | } |
| 8184 | |
| 8185 | /* |
| 8186 | * This file defines the Wireless Extension handlers. It does not |
| 8187 | * define any methods of hardware manipulation and relies on the |
| 8188 | * functions defined in ipw_main to provide the HW interaction. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8189 | * |
| 8190 | * The exception to this is the use of the ipw_get_ordinal() |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8191 | * function used to poll the hardware vs. making unecessary calls. |
| 8192 | * |
| 8193 | */ |
| 8194 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8195 | static int ipw_wx_get_name(struct net_device *dev, |
| 8196 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8197 | union iwreq_data *wrqu, char *extra) |
| 8198 | { |
| 8199 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8200 | down(&priv->sem); |
| 8201 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8202 | strcpy(wrqu->name, "radio off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8203 | else if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8204 | strcpy(wrqu->name, "unassociated"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8205 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8206 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c", |
| 8207 | ipw_modes[priv->assoc_request.ieee_mode]); |
| 8208 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8209 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8210 | return 0; |
| 8211 | } |
| 8212 | |
| 8213 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
| 8214 | { |
| 8215 | if (channel == 0) { |
| 8216 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); |
| 8217 | priv->config &= ~CFG_STATIC_CHANNEL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8218 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8219 | "parameters.\n"); |
| 8220 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8221 | return 0; |
| 8222 | } |
| 8223 | |
| 8224 | priv->config |= CFG_STATIC_CHANNEL; |
| 8225 | |
| 8226 | if (priv->channel == channel) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8227 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
| 8228 | channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8229 | return 0; |
| 8230 | } |
| 8231 | |
| 8232 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); |
| 8233 | priv->channel = channel; |
| 8234 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8235 | #ifdef CONFIG_IPW2200_MONITOR |
| 8236 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8237 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8238 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8239 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8240 | "channel change.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8241 | ipw_abort_scan(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8242 | } |
| 8243 | |
| 8244 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) |
| 8245 | udelay(10); |
| 8246 | |
| 8247 | if (priv->status & STATUS_SCANNING) |
| 8248 | IPW_DEBUG_SCAN("Still scanning...\n"); |
| 8249 | else |
| 8250 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", |
| 8251 | 1000 - i); |
| 8252 | |
| 8253 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8254 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8255 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 8256 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8257 | /* Network configuration changed -- force [re]association */ |
| 8258 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); |
| 8259 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8260 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8261 | |
| 8262 | return 0; |
| 8263 | } |
| 8264 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8265 | static int ipw_wx_set_freq(struct net_device *dev, |
| 8266 | struct iw_request_info *info, |
| 8267 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8268 | { |
| 8269 | struct ipw_priv *priv = ieee80211_priv(dev); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8270 | const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8271 | struct iw_freq *fwrq = &wrqu->freq; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8272 | int ret = 0, i; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8273 | u8 channel, flags; |
| 8274 | int band; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8275 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8276 | if (fwrq->m == 0) { |
| 8277 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); |
| 8278 | down(&priv->sem); |
| 8279 | ret = ipw_set_channel(priv, 0); |
| 8280 | up(&priv->sem); |
| 8281 | return ret; |
| 8282 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8283 | /* if setting by freq convert to channel */ |
| 8284 | if (fwrq->e == 1) { |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8285 | channel = ipw_freq_to_channel(priv->ieee, fwrq->m); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8286 | if (channel == 0) |
| 8287 | return -EINVAL; |
| 8288 | } else |
| 8289 | channel = fwrq->m; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8290 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8291 | if (!(band = ipw_is_valid_channel(priv->ieee, channel))) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8292 | return -EINVAL; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8293 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8294 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 8295 | i = ipw_channel_to_index(priv->ieee, channel); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8296 | if (i == -1) |
| 8297 | return -EINVAL; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8298 | |
| 8299 | flags = (band == IEEE80211_24GHZ_BAND) ? |
| 8300 | geo->bg[i].flags : geo->a[i].flags; |
| 8301 | if (flags & IEEE80211_CH_PASSIVE_ONLY) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8302 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
| 8303 | return -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8304 | } |
| 8305 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8306 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8307 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8308 | down(&priv->sem); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8309 | ret = ipw_set_channel(priv, channel); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8310 | up(&priv->sem); |
| 8311 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8312 | } |
| 8313 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8314 | static int ipw_wx_get_freq(struct net_device *dev, |
| 8315 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8316 | union iwreq_data *wrqu, char *extra) |
| 8317 | { |
| 8318 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8319 | |
| 8320 | wrqu->freq.e = 0; |
| 8321 | |
| 8322 | /* If we are associated, trying to associate, or have a statically |
| 8323 | * configured CHANNEL then return that; otherwise return ANY */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8324 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8325 | if (priv->config & CFG_STATIC_CHANNEL || |
| 8326 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) |
| 8327 | wrqu->freq.m = priv->channel; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8328 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8329 | wrqu->freq.m = 0; |
| 8330 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8331 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8332 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
| 8333 | return 0; |
| 8334 | } |
| 8335 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8336 | static int ipw_wx_set_mode(struct net_device *dev, |
| 8337 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8338 | union iwreq_data *wrqu, char *extra) |
| 8339 | { |
| 8340 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8341 | int err = 0; |
| 8342 | |
| 8343 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); |
| 8344 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8345 | switch (wrqu->mode) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8346 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8347 | case IW_MODE_MONITOR: |
| 8348 | #endif |
| 8349 | case IW_MODE_ADHOC: |
| 8350 | case IW_MODE_INFRA: |
| 8351 | break; |
| 8352 | case IW_MODE_AUTO: |
| 8353 | wrqu->mode = IW_MODE_INFRA; |
| 8354 | break; |
| 8355 | default: |
| 8356 | return -EINVAL; |
| 8357 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8358 | if (wrqu->mode == priv->ieee->iw_mode) |
| 8359 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8360 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8361 | down(&priv->sem); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8362 | |
| 8363 | ipw_sw_reset(priv, 0); |
| 8364 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8365 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8366 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8367 | priv->net_dev->type = ARPHRD_ETHER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8368 | |
| 8369 | if (wrqu->mode == IW_MODE_MONITOR) |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8370 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 8371 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 8372 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8373 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 8374 | #endif |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8375 | #endif /* CONFIG_IPW2200_MONITOR */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8376 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8377 | /* Free the existing firmware and reset the fw_loaded |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8378 | * flag so ipw_load() will bring in the new firmawre */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8379 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8380 | |
| 8381 | priv->ieee->iw_mode = wrqu->mode; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8382 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8383 | queue_work(priv->workqueue, &priv->adapter_restart); |
| 8384 | up(&priv->sem); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8385 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8386 | } |
| 8387 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8388 | static int ipw_wx_get_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8389 | struct iw_request_info *info, |
| 8390 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8391 | { |
| 8392 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8393 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8394 | wrqu->mode = priv->ieee->iw_mode; |
| 8395 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8396 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8397 | return 0; |
| 8398 | } |
| 8399 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8400 | /* Values are in microsecond */ |
| 8401 | static const s32 timeout_duration[] = { |
| 8402 | 350000, |
| 8403 | 250000, |
| 8404 | 75000, |
| 8405 | 37000, |
| 8406 | 25000, |
| 8407 | }; |
| 8408 | |
| 8409 | static const s32 period_duration[] = { |
| 8410 | 400000, |
| 8411 | 700000, |
| 8412 | 1000000, |
| 8413 | 1000000, |
| 8414 | 1000000 |
| 8415 | }; |
| 8416 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8417 | static int ipw_wx_get_range(struct net_device *dev, |
| 8418 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8419 | union iwreq_data *wrqu, char *extra) |
| 8420 | { |
| 8421 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8422 | struct iw_range *range = (struct iw_range *)extra; |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 8423 | const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8424 | int i = 0, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8425 | |
| 8426 | wrqu->data.length = sizeof(*range); |
| 8427 | memset(range, 0, sizeof(*range)); |
| 8428 | |
| 8429 | /* 54Mbs == ~27 Mb/s real (802.11g) */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8430 | range->throughput = 27 * 1000 * 1000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8431 | |
| 8432 | range->max_qual.qual = 100; |
| 8433 | /* TODO: Find real max RSSI and stick here */ |
| 8434 | range->max_qual.level = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8435 | range->max_qual.noise = priv->ieee->worst_rssi + 0x100; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8436 | range->max_qual.updated = 7; /* Updated all three */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8437 | |
| 8438 | range->avg_qual.qual = 70; |
| 8439 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8440 | range->avg_qual.level = 0; /* FIXME to real average level */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8441 | range->avg_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8442 | range->avg_qual.updated = 7; /* Updated all three */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8443 | down(&priv->sem); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8444 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8445 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8446 | for (i = 0; i < range->num_bitrates; i++) |
| 8447 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8448 | 500000; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8449 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8450 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
| 8451 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 8452 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 8453 | |
| 8454 | range->encoding_size[0] = 5; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8455 | range->encoding_size[1] = 13; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8456 | range->num_encoding_sizes = 2; |
| 8457 | range->max_encoding_tokens = WEP_KEYS; |
| 8458 | |
| 8459 | /* Set the Wireless Extension versions */ |
| 8460 | range->we_version_compiled = WIRELESS_EXT; |
| 8461 | range->we_version_source = 16; |
| 8462 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8463 | i = 0; |
| 8464 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { |
| 8465 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; |
| 8466 | i++, j++) { |
| 8467 | range->freq[i].i = geo->bg[j].channel; |
| 8468 | range->freq[i].m = geo->bg[j].freq * 100000; |
| 8469 | range->freq[i].e = 1; |
| 8470 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8471 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8472 | |
| 8473 | if (priv->ieee->mode & IEEE_A) { |
| 8474 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; |
| 8475 | i++, j++) { |
| 8476 | range->freq[i].i = geo->a[j].channel; |
| 8477 | range->freq[i].m = geo->a[j].freq * 100000; |
| 8478 | range->freq[i].e = 1; |
| 8479 | } |
| 8480 | } |
| 8481 | |
| 8482 | range->num_channels = i; |
| 8483 | range->num_frequency = i; |
| 8484 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8485 | up(&priv->sem); |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 8486 | |
| 8487 | /* Event capability (kernel + driver) */ |
| 8488 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 8489 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
| 8490 | IW_EVENT_CAPA_MASK(SIOCGIWAP)); |
| 8491 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8492 | |
| 8493 | IPW_DEBUG_WX("GET Range\n"); |
| 8494 | return 0; |
| 8495 | } |
| 8496 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8497 | static int ipw_wx_set_wap(struct net_device *dev, |
| 8498 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8499 | union iwreq_data *wrqu, char *extra) |
| 8500 | { |
| 8501 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8502 | |
| 8503 | static const unsigned char any[] = { |
| 8504 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 8505 | }; |
| 8506 | static const unsigned char off[] = { |
| 8507 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 8508 | }; |
| 8509 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8510 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8511 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8512 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8513 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
| 8514 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8515 | /* we disable mandatory BSSID association */ |
| 8516 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); |
| 8517 | priv->config &= ~CFG_STATIC_BSSID; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8518 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8519 | "parameters.\n"); |
| 8520 | ipw_associate(priv); |
| 8521 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8522 | return 0; |
| 8523 | } |
| 8524 | |
| 8525 | priv->config |= CFG_STATIC_BSSID; |
| 8526 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8527 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8528 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8529 | return 0; |
| 8530 | } |
| 8531 | |
| 8532 | IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n", |
| 8533 | MAC_ARG(wrqu->ap_addr.sa_data)); |
| 8534 | |
| 8535 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); |
| 8536 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8537 | /* Network configuration changed -- force [re]association */ |
| 8538 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); |
| 8539 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8540 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8541 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8542 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8543 | return 0; |
| 8544 | } |
| 8545 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8546 | static int ipw_wx_get_wap(struct net_device *dev, |
| 8547 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8548 | union iwreq_data *wrqu, char *extra) |
| 8549 | { |
| 8550 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8551 | /* If we are associated, trying to associate, or have a statically |
| 8552 | * configured BSSID then return that; otherwise return ANY */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8553 | down(&priv->sem); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8554 | if (priv->config & CFG_STATIC_BSSID || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8555 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8556 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8557 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8558 | } else |
| 8559 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 8560 | |
| 8561 | IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", |
| 8562 | MAC_ARG(wrqu->ap_addr.sa_data)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8563 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8564 | return 0; |
| 8565 | } |
| 8566 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8567 | static int ipw_wx_set_essid(struct net_device *dev, |
| 8568 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8569 | union iwreq_data *wrqu, char *extra) |
| 8570 | { |
| 8571 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8572 | char *essid = ""; /* ANY */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8573 | int length = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8574 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8575 | if (wrqu->essid.flags && wrqu->essid.length) { |
| 8576 | length = wrqu->essid.length - 1; |
| 8577 | essid = extra; |
| 8578 | } |
| 8579 | if (length == 0) { |
| 8580 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8581 | if ((priv->config & CFG_STATIC_ESSID) && |
| 8582 | !(priv->status & (STATUS_ASSOCIATED | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8583 | STATUS_ASSOCIATING))) { |
| 8584 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8585 | "parameters.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8586 | priv->config &= ~CFG_STATIC_ESSID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8587 | ipw_associate(priv); |
| 8588 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8589 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8590 | return 0; |
| 8591 | } |
| 8592 | |
| 8593 | length = min(length, IW_ESSID_MAX_SIZE); |
| 8594 | |
| 8595 | priv->config |= CFG_STATIC_ESSID; |
| 8596 | |
| 8597 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { |
| 8598 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8599 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8600 | return 0; |
| 8601 | } |
| 8602 | |
| 8603 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length), |
| 8604 | length); |
| 8605 | |
| 8606 | priv->essid_len = length; |
| 8607 | memcpy(priv->essid, essid, priv->essid_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8608 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8609 | /* Network configuration changed -- force [re]association */ |
| 8610 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); |
| 8611 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8612 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8613 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8614 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8615 | return 0; |
| 8616 | } |
| 8617 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8618 | static int ipw_wx_get_essid(struct net_device *dev, |
| 8619 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8620 | union iwreq_data *wrqu, char *extra) |
| 8621 | { |
| 8622 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8623 | |
| 8624 | /* If we are associated, trying to associate, or have a statically |
| 8625 | * configured ESSID then return that; otherwise return ANY */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8626 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8627 | if (priv->config & CFG_STATIC_ESSID || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8628 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8629 | IPW_DEBUG_WX("Getting essid: '%s'\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8630 | escape_essid(priv->essid, priv->essid_len)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8631 | memcpy(extra, priv->essid, priv->essid_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8632 | wrqu->essid.length = priv->essid_len; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8633 | wrqu->essid.flags = 1; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8634 | } else { |
| 8635 | IPW_DEBUG_WX("Getting essid: ANY\n"); |
| 8636 | wrqu->essid.length = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8637 | wrqu->essid.flags = 0; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8638 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8639 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8640 | return 0; |
| 8641 | } |
| 8642 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8643 | static int ipw_wx_set_nick(struct net_device *dev, |
| 8644 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8645 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8646 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8647 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8648 | |
| 8649 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); |
| 8650 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) |
| 8651 | return -E2BIG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8652 | down(&priv->sem); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8653 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8654 | memset(priv->nick, 0, sizeof(priv->nick)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8655 | memcpy(priv->nick, extra, wrqu->data.length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8656 | IPW_DEBUG_TRACE("<<\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8657 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8658 | return 0; |
| 8659 | |
| 8660 | } |
| 8661 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8662 | static int ipw_wx_get_nick(struct net_device *dev, |
| 8663 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8664 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8665 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8666 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8667 | IPW_DEBUG_WX("Getting nick\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8668 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8669 | wrqu->data.length = strlen(priv->nick) + 1; |
| 8670 | memcpy(extra, priv->nick, wrqu->data.length); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8671 | wrqu->data.flags = 1; /* active */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8672 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8673 | return 0; |
| 8674 | } |
| 8675 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8676 | static int ipw_wx_set_rate(struct net_device *dev, |
| 8677 | struct iw_request_info *info, |
| 8678 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8679 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8680 | /* TODO: We should use semaphores or locks for access to priv */ |
| 8681 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8682 | u32 target_rate = wrqu->bitrate.value; |
| 8683 | u32 fixed, mask; |
| 8684 | |
| 8685 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ |
| 8686 | /* value = X, fixed = 1 means only rate X */ |
| 8687 | /* value = X, fixed = 0 means all rates lower equal X */ |
| 8688 | |
| 8689 | if (target_rate == -1) { |
| 8690 | fixed = 0; |
| 8691 | mask = IEEE80211_DEFAULT_RATES_MASK; |
| 8692 | /* Now we should reassociate */ |
| 8693 | goto apply; |
| 8694 | } |
| 8695 | |
| 8696 | mask = 0; |
| 8697 | fixed = wrqu->bitrate.fixed; |
| 8698 | |
| 8699 | if (target_rate == 1000000 || !fixed) |
| 8700 | mask |= IEEE80211_CCK_RATE_1MB_MASK; |
| 8701 | if (target_rate == 1000000) |
| 8702 | goto apply; |
| 8703 | |
| 8704 | if (target_rate == 2000000 || !fixed) |
| 8705 | mask |= IEEE80211_CCK_RATE_2MB_MASK; |
| 8706 | if (target_rate == 2000000) |
| 8707 | goto apply; |
| 8708 | |
| 8709 | if (target_rate == 5500000 || !fixed) |
| 8710 | mask |= IEEE80211_CCK_RATE_5MB_MASK; |
| 8711 | if (target_rate == 5500000) |
| 8712 | goto apply; |
| 8713 | |
| 8714 | if (target_rate == 6000000 || !fixed) |
| 8715 | mask |= IEEE80211_OFDM_RATE_6MB_MASK; |
| 8716 | if (target_rate == 6000000) |
| 8717 | goto apply; |
| 8718 | |
| 8719 | if (target_rate == 9000000 || !fixed) |
| 8720 | mask |= IEEE80211_OFDM_RATE_9MB_MASK; |
| 8721 | if (target_rate == 9000000) |
| 8722 | goto apply; |
| 8723 | |
| 8724 | if (target_rate == 11000000 || !fixed) |
| 8725 | mask |= IEEE80211_CCK_RATE_11MB_MASK; |
| 8726 | if (target_rate == 11000000) |
| 8727 | goto apply; |
| 8728 | |
| 8729 | if (target_rate == 12000000 || !fixed) |
| 8730 | mask |= IEEE80211_OFDM_RATE_12MB_MASK; |
| 8731 | if (target_rate == 12000000) |
| 8732 | goto apply; |
| 8733 | |
| 8734 | if (target_rate == 18000000 || !fixed) |
| 8735 | mask |= IEEE80211_OFDM_RATE_18MB_MASK; |
| 8736 | if (target_rate == 18000000) |
| 8737 | goto apply; |
| 8738 | |
| 8739 | if (target_rate == 24000000 || !fixed) |
| 8740 | mask |= IEEE80211_OFDM_RATE_24MB_MASK; |
| 8741 | if (target_rate == 24000000) |
| 8742 | goto apply; |
| 8743 | |
| 8744 | if (target_rate == 36000000 || !fixed) |
| 8745 | mask |= IEEE80211_OFDM_RATE_36MB_MASK; |
| 8746 | if (target_rate == 36000000) |
| 8747 | goto apply; |
| 8748 | |
| 8749 | if (target_rate == 48000000 || !fixed) |
| 8750 | mask |= IEEE80211_OFDM_RATE_48MB_MASK; |
| 8751 | if (target_rate == 48000000) |
| 8752 | goto apply; |
| 8753 | |
| 8754 | if (target_rate == 54000000 || !fixed) |
| 8755 | mask |= IEEE80211_OFDM_RATE_54MB_MASK; |
| 8756 | if (target_rate == 54000000) |
| 8757 | goto apply; |
| 8758 | |
| 8759 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); |
| 8760 | return -EINVAL; |
| 8761 | |
| 8762 | apply: |
| 8763 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", |
| 8764 | mask, fixed ? "fixed" : "sub-rates"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8765 | down(&priv->sem); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8766 | if (mask == IEEE80211_DEFAULT_RATES_MASK) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8767 | priv->config &= ~CFG_FIXED_RATE; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8768 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
| 8769 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8770 | priv->config |= CFG_FIXED_RATE; |
| 8771 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8772 | if (priv->rates_mask == mask) { |
| 8773 | IPW_DEBUG_WX("Mask set to current mask.\n"); |
| 8774 | up(&priv->sem); |
| 8775 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8776 | } |
| 8777 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8778 | priv->rates_mask = mask; |
| 8779 | |
| 8780 | /* Network configuration changed -- force [re]association */ |
| 8781 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); |
| 8782 | if (!ipw_disassociate(priv)) |
| 8783 | ipw_associate(priv); |
| 8784 | |
| 8785 | up(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8786 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8787 | } |
| 8788 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8789 | static int ipw_wx_get_rate(struct net_device *dev, |
| 8790 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8791 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8792 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8793 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8794 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8795 | wrqu->bitrate.value = priv->last_rate; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8796 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8797 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
| 8798 | return 0; |
| 8799 | } |
| 8800 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8801 | static int ipw_wx_set_rts(struct net_device *dev, |
| 8802 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8803 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8804 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8805 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8806 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8807 | if (wrqu->rts.disabled) |
| 8808 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8809 | else { |
| 8810 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8811 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
| 8812 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8813 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8814 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8815 | priv->rts_threshold = wrqu->rts.value; |
| 8816 | } |
| 8817 | |
| 8818 | ipw_send_rts_threshold(priv, priv->rts_threshold); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8819 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8820 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
| 8821 | return 0; |
| 8822 | } |
| 8823 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8824 | static int ipw_wx_get_rts(struct net_device *dev, |
| 8825 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8826 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8827 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8828 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8829 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8830 | wrqu->rts.value = priv->rts_threshold; |
| 8831 | wrqu->rts.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8832 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8833 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8834 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
| 8835 | return 0; |
| 8836 | } |
| 8837 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8838 | static int ipw_wx_set_txpow(struct net_device *dev, |
| 8839 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8840 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8841 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8842 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8843 | int err = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8844 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8845 | down(&priv->sem); |
| 8846 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8847 | err = -EINPROGRESS; |
| 8848 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8849 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8850 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8851 | if (!wrqu->power.fixed) |
| 8852 | wrqu->power.value = IPW_TX_POWER_DEFAULT; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8853 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8854 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8855 | err = -EINVAL; |
| 8856 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8857 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8858 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8859 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8860 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8861 | err = -EINVAL; |
| 8862 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8863 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8864 | |
| 8865 | priv->tx_power = wrqu->power.value; |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8866 | err = ipw_set_tx_power(priv); |
| 8867 | out: |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8868 | up(&priv->sem); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8869 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8870 | } |
| 8871 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8872 | static int ipw_wx_get_txpow(struct net_device *dev, |
| 8873 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8874 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8875 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8876 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8877 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8878 | wrqu->power.value = priv->tx_power; |
| 8879 | wrqu->power.fixed = 1; |
| 8880 | wrqu->power.flags = IW_TXPOW_DBM; |
| 8881 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8882 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8883 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8884 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
Zhu Yi | 22501c8 | 2005-08-11 10:49:17 +0800 | [diff] [blame] | 8885 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8886 | |
| 8887 | return 0; |
| 8888 | } |
| 8889 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8890 | static int ipw_wx_set_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8891 | struct iw_request_info *info, |
| 8892 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8893 | { |
| 8894 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8895 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8896 | if (wrqu->frag.disabled) |
| 8897 | priv->ieee->fts = DEFAULT_FTS; |
| 8898 | else { |
| 8899 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8900 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
| 8901 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8902 | return -EINVAL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8903 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8904 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8905 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
| 8906 | } |
| 8907 | |
| 8908 | ipw_send_frag_threshold(priv, wrqu->frag.value); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8909 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8910 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
| 8911 | return 0; |
| 8912 | } |
| 8913 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8914 | static int ipw_wx_get_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8915 | struct iw_request_info *info, |
| 8916 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8917 | { |
| 8918 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8919 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8920 | wrqu->frag.value = priv->ieee->fts; |
| 8921 | wrqu->frag.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8922 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8923 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8924 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
| 8925 | |
| 8926 | return 0; |
| 8927 | } |
| 8928 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8929 | static int ipw_wx_set_retry(struct net_device *dev, |
| 8930 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8931 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8932 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8933 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8934 | |
| 8935 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) |
| 8936 | return -EINVAL; |
| 8937 | |
| 8938 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) |
| 8939 | return 0; |
| 8940 | |
| 8941 | if (wrqu->retry.value < 0 || wrqu->retry.value > 255) |
| 8942 | return -EINVAL; |
| 8943 | |
| 8944 | down(&priv->sem); |
| 8945 | if (wrqu->retry.flags & IW_RETRY_MIN) |
| 8946 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 8947 | else if (wrqu->retry.flags & IW_RETRY_MAX) |
| 8948 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 8949 | else { |
| 8950 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 8951 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 8952 | } |
| 8953 | |
| 8954 | ipw_send_retry_limit(priv, priv->short_retry_limit, |
| 8955 | priv->long_retry_limit); |
| 8956 | up(&priv->sem); |
| 8957 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
| 8958 | priv->short_retry_limit, priv->long_retry_limit); |
| 8959 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8960 | } |
| 8961 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8962 | static int ipw_wx_get_retry(struct net_device *dev, |
| 8963 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8964 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8965 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8966 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8967 | |
| 8968 | down(&priv->sem); |
| 8969 | wrqu->retry.disabled = 0; |
| 8970 | |
| 8971 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
| 8972 | up(&priv->sem); |
| 8973 | return -EINVAL; |
| 8974 | } |
| 8975 | |
| 8976 | if (wrqu->retry.flags & IW_RETRY_MAX) { |
| 8977 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 8978 | wrqu->retry.value = priv->long_retry_limit; |
| 8979 | } else if (wrqu->retry.flags & IW_RETRY_MIN) { |
| 8980 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; |
| 8981 | wrqu->retry.value = priv->short_retry_limit; |
| 8982 | } else { |
| 8983 | wrqu->retry.flags = IW_RETRY_LIMIT; |
| 8984 | wrqu->retry.value = priv->short_retry_limit; |
| 8985 | } |
| 8986 | up(&priv->sem); |
| 8987 | |
| 8988 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); |
| 8989 | |
| 8990 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8991 | } |
| 8992 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8993 | static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid, |
| 8994 | int essid_len) |
| 8995 | { |
| 8996 | struct ipw_scan_request_ext scan; |
| 8997 | int err = 0, scan_type; |
| 8998 | |
Pekka Enberg | efb3442 | 2005-11-16 21:55:05 +0200 | [diff] [blame] | 8999 | if (!(priv->status & STATUS_INIT) || |
| 9000 | (priv->status & STATUS_EXIT_PENDING)) |
| 9001 | return 0; |
| 9002 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9003 | down(&priv->sem); |
| 9004 | |
| 9005 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 9006 | IPW_DEBUG_HC("Aborting scan due to RF kill activation\n"); |
| 9007 | priv->status |= STATUS_SCAN_PENDING; |
| 9008 | goto done; |
| 9009 | } |
| 9010 | |
| 9011 | IPW_DEBUG_HC("starting request direct scan!\n"); |
| 9012 | |
| 9013 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
Olaf Kirch | d834a41 | 2006-01-09 17:00:37 +0100 | [diff] [blame] | 9014 | /* We should not sleep here; otherwise we will block most |
| 9015 | * of the system (for instance, we hold rtnl_lock when we |
| 9016 | * get here). |
| 9017 | */ |
| 9018 | err = -EAGAIN; |
| 9019 | goto done; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9020 | } |
| 9021 | memset(&scan, 0, sizeof(scan)); |
| 9022 | |
| 9023 | if (priv->config & CFG_SPEED_SCAN) |
| 9024 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 9025 | cpu_to_le16(30); |
| 9026 | else |
| 9027 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 9028 | cpu_to_le16(20); |
| 9029 | |
| 9030 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 9031 | cpu_to_le16(20); |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 9032 | 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] | 9033 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
| 9034 | |
| 9035 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
| 9036 | |
| 9037 | err = ipw_send_ssid(priv, essid, essid_len); |
| 9038 | if (err) { |
| 9039 | IPW_DEBUG_HC("Attempt to send SSID command failed\n"); |
| 9040 | goto done; |
| 9041 | } |
| 9042 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
| 9043 | |
| 9044 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 9045 | |
| 9046 | err = ipw_send_scan_request_ext(priv, &scan); |
| 9047 | if (err) { |
| 9048 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
| 9049 | goto done; |
| 9050 | } |
| 9051 | |
| 9052 | priv->status |= STATUS_SCANNING; |
| 9053 | |
| 9054 | done: |
| 9055 | up(&priv->sem); |
| 9056 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9057 | } |
| 9058 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9059 | static int ipw_wx_set_scan(struct net_device *dev, |
| 9060 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9061 | union iwreq_data *wrqu, char *extra) |
| 9062 | { |
| 9063 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9064 | struct iw_scan_req *req = NULL; |
| 9065 | if (wrqu->data.length |
| 9066 | && wrqu->data.length == sizeof(struct iw_scan_req)) { |
| 9067 | req = (struct iw_scan_req *)extra; |
| 9068 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
| 9069 | ipw_request_direct_scan(priv, req->essid, |
| 9070 | req->essid_len); |
| 9071 | return 0; |
| 9072 | } |
| 9073 | } |
James Ketrenos | 8935f39 | 2005-10-05 15:59:08 -0500 | [diff] [blame] | 9074 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9075 | IPW_DEBUG_WX("Start scan\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9076 | |
| 9077 | queue_work(priv->workqueue, &priv->request_scan); |
| 9078 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9079 | return 0; |
| 9080 | } |
| 9081 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9082 | static int ipw_wx_get_scan(struct net_device *dev, |
| 9083 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9084 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9085 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9086 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9087 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); |
| 9088 | } |
| 9089 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9090 | static int ipw_wx_set_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9091 | struct iw_request_info *info, |
| 9092 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9093 | { |
| 9094 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9095 | int ret; |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9096 | u32 cap = priv->capability; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9097 | |
| 9098 | down(&priv->sem); |
| 9099 | ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9100 | |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9101 | /* In IBSS mode, we need to notify the firmware to update |
| 9102 | * the beacon info after we changed the capability. */ |
| 9103 | if (cap != priv->capability && |
| 9104 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 9105 | priv->status & STATUS_ASSOCIATED) |
| 9106 | ipw_disassociate(priv); |
| 9107 | |
| 9108 | up(&priv->sem); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9109 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9110 | } |
| 9111 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9112 | static int ipw_wx_get_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9113 | struct iw_request_info *info, |
| 9114 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9115 | { |
| 9116 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9117 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); |
| 9118 | } |
| 9119 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9120 | static int ipw_wx_set_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9121 | struct iw_request_info *info, |
| 9122 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9123 | { |
| 9124 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9125 | int err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9126 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9127 | if (wrqu->power.disabled) { |
| 9128 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); |
| 9129 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); |
| 9130 | if (err) { |
| 9131 | IPW_DEBUG_WX("failed setting power mode.\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9132 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9133 | return err; |
| 9134 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9135 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9136 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9137 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9138 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9139 | |
| 9140 | switch (wrqu->power.flags & IW_POWER_MODE) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9141 | case IW_POWER_ON: /* If not specified */ |
| 9142 | case IW_POWER_MODE: /* If set all mask */ |
| 9143 | case IW_POWER_ALL_R: /* If explicitely state all */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9144 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9145 | default: /* Otherwise we don't support it */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9146 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
| 9147 | wrqu->power.flags); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9148 | up(&priv->sem); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9149 | return -EOPNOTSUPP; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9150 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9151 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9152 | /* If the user hasn't specified a power management mode yet, default |
| 9153 | * to BATTERY */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9154 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9155 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9156 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9157 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
| 9158 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
| 9159 | if (err) { |
| 9160 | IPW_DEBUG_WX("failed setting power mode.\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9161 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9162 | return err; |
| 9163 | } |
| 9164 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9165 | IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9166 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9167 | return 0; |
| 9168 | } |
| 9169 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9170 | static int ipw_wx_get_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9171 | struct iw_request_info *info, |
| 9172 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9173 | { |
| 9174 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9175 | down(&priv->sem); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9176 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9177 | wrqu->power.disabled = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9178 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9179 | wrqu->power.disabled = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9180 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9181 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9182 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9183 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9184 | return 0; |
| 9185 | } |
| 9186 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9187 | static int ipw_wx_set_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9188 | struct iw_request_info *info, |
| 9189 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9190 | { |
| 9191 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9192 | int mode = *(int *)extra; |
| 9193 | int err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9194 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9195 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) { |
| 9196 | mode = IPW_POWER_AC; |
| 9197 | priv->power_mode = mode; |
| 9198 | } else { |
| 9199 | priv->power_mode = IPW_POWER_ENABLED | mode; |
| 9200 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9201 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9202 | if (priv->power_mode != mode) { |
| 9203 | err = ipw_send_power_mode(priv, mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9204 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9205 | if (err) { |
| 9206 | IPW_DEBUG_WX("failed setting power mode.\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9207 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9208 | return err; |
| 9209 | } |
| 9210 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9211 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9212 | return 0; |
| 9213 | } |
| 9214 | |
| 9215 | #define MAX_WX_STRING 80 |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9216 | static int ipw_wx_get_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9217 | struct iw_request_info *info, |
| 9218 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9219 | { |
| 9220 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9221 | int level = IPW_POWER_LEVEL(priv->power_mode); |
| 9222 | char *p = extra; |
| 9223 | |
| 9224 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); |
| 9225 | |
| 9226 | switch (level) { |
| 9227 | case IPW_POWER_AC: |
| 9228 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); |
| 9229 | break; |
| 9230 | case IPW_POWER_BATTERY: |
| 9231 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); |
| 9232 | break; |
| 9233 | default: |
| 9234 | p += snprintf(p, MAX_WX_STRING - (p - extra), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9235 | "(Timeout %dms, Period %dms)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9236 | timeout_duration[level - 1] / 1000, |
| 9237 | period_duration[level - 1] / 1000); |
| 9238 | } |
| 9239 | |
| 9240 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9241 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9242 | |
| 9243 | wrqu->data.length = p - extra + 1; |
| 9244 | |
| 9245 | return 0; |
| 9246 | } |
| 9247 | |
| 9248 | static int ipw_wx_set_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9249 | struct iw_request_info *info, |
| 9250 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9251 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9252 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9253 | int mode = *(int *)extra; |
| 9254 | u8 band = 0, modulation = 0; |
| 9255 | |
| 9256 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9257 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9258 | return -EINVAL; |
| 9259 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9260 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9261 | if (priv->adapter == IPW_2915ABG) { |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9262 | priv->ieee->abg_true = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9263 | if (mode & IEEE_A) { |
| 9264 | band |= IEEE80211_52GHZ_BAND; |
| 9265 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9266 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9267 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9268 | } else { |
| 9269 | if (mode & IEEE_A) { |
| 9270 | IPW_WARNING("Attempt to set 2200BG into " |
| 9271 | "802.11a mode\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9272 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9273 | return -EINVAL; |
| 9274 | } |
| 9275 | |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9276 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9277 | } |
| 9278 | |
| 9279 | if (mode & IEEE_B) { |
| 9280 | band |= IEEE80211_24GHZ_BAND; |
| 9281 | modulation |= IEEE80211_CCK_MODULATION; |
| 9282 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9283 | priv->ieee->abg_true = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9284 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9285 | if (mode & IEEE_G) { |
| 9286 | band |= IEEE80211_24GHZ_BAND; |
| 9287 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9288 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9289 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9290 | |
| 9291 | priv->ieee->mode = mode; |
| 9292 | priv->ieee->freq_band = band; |
| 9293 | priv->ieee->modulation = modulation; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9294 | init_supported_rates(priv, &priv->rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9295 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9296 | /* Network configuration changed -- force [re]association */ |
| 9297 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); |
| 9298 | if (!ipw_disassociate(priv)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9299 | ipw_send_supported_rates(priv, &priv->rates); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9300 | ipw_associate(priv); |
| 9301 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9302 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9303 | /* Update the band LEDs */ |
| 9304 | ipw_led_band_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9305 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9306 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9307 | mode & IEEE_A ? 'a' : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9308 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9309 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9310 | return 0; |
| 9311 | } |
| 9312 | |
| 9313 | static int ipw_wx_get_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9314 | struct iw_request_info *info, |
| 9315 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9316 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9317 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9318 | down(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9319 | switch (priv->ieee->mode) { |
| 9320 | case IEEE_A: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9321 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
| 9322 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9323 | case IEEE_B: |
| 9324 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); |
| 9325 | break; |
| 9326 | case IEEE_A | IEEE_B: |
| 9327 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); |
| 9328 | break; |
| 9329 | case IEEE_G: |
| 9330 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); |
| 9331 | break; |
| 9332 | case IEEE_A | IEEE_G: |
| 9333 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); |
| 9334 | break; |
| 9335 | case IEEE_B | IEEE_G: |
| 9336 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); |
| 9337 | break; |
| 9338 | case IEEE_A | IEEE_B | IEEE_G: |
| 9339 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); |
| 9340 | break; |
| 9341 | default: |
| 9342 | strncpy(extra, "unknown", MAX_WX_STRING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9343 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9344 | } |
| 9345 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9346 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
| 9347 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9348 | wrqu->data.length = strlen(extra) + 1; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9349 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9350 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9351 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9352 | } |
| 9353 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9354 | static int ipw_wx_set_preamble(struct net_device *dev, |
| 9355 | struct iw_request_info *info, |
| 9356 | union iwreq_data *wrqu, char *extra) |
| 9357 | { |
| 9358 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9359 | int mode = *(int *)extra; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9360 | down(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9361 | /* Switching from SHORT -> LONG requires a disassociation */ |
| 9362 | if (mode == 1) { |
| 9363 | if (!(priv->config & CFG_PREAMBLE_LONG)) { |
| 9364 | priv->config |= CFG_PREAMBLE_LONG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9365 | |
| 9366 | /* Network configuration changed -- force [re]association */ |
| 9367 | IPW_DEBUG_ASSOC |
| 9368 | ("[re]association triggered due to preamble change.\n"); |
| 9369 | if (!ipw_disassociate(priv)) |
| 9370 | ipw_associate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9371 | } |
| 9372 | goto done; |
| 9373 | } |
| 9374 | |
| 9375 | if (mode == 0) { |
| 9376 | priv->config &= ~CFG_PREAMBLE_LONG; |
| 9377 | goto done; |
| 9378 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9379 | up(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9380 | return -EINVAL; |
| 9381 | |
| 9382 | done: |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9383 | up(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9384 | return 0; |
| 9385 | } |
| 9386 | |
| 9387 | static int ipw_wx_get_preamble(struct net_device *dev, |
| 9388 | struct iw_request_info *info, |
| 9389 | union iwreq_data *wrqu, char *extra) |
| 9390 | { |
| 9391 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9392 | down(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9393 | if (priv->config & CFG_PREAMBLE_LONG) |
| 9394 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); |
| 9395 | else |
| 9396 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9397 | up(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9398 | return 0; |
| 9399 | } |
| 9400 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9401 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9402 | static int ipw_wx_set_monitor(struct net_device *dev, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9403 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9404 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9405 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9406 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9407 | int *parms = (int *)extra; |
| 9408 | int enable = (parms[0] > 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9409 | down(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9410 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9411 | if (enable) { |
| 9412 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9413 | #ifdef CONFIG_IEEE80211_RADIOTAP |
| 9414 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 9415 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9416 | priv->net_dev->type = ARPHRD_IEEE80211; |
Mike Kershaw | 24a47db | 2005-08-26 00:41:54 -0500 | [diff] [blame] | 9417 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9418 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9419 | } |
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 | ipw_set_channel(priv, parms[1]); |
| 9422 | } else { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9423 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 9424 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9425 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9426 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9427 | priv->net_dev->type = ARPHRD_ETHER; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9428 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9429 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9430 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9431 | return 0; |
| 9432 | } |
| 9433 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9434 | #endif // CONFIG_IPW2200_MONITOR |
| 9435 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9436 | static int ipw_wx_reset(struct net_device *dev, |
| 9437 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9438 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9439 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9440 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9441 | IPW_DEBUG_WX("RESET\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9442 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9443 | return 0; |
| 9444 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9445 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9446 | static int ipw_wx_sw_reset(struct net_device *dev, |
| 9447 | struct iw_request_info *info, |
| 9448 | union iwreq_data *wrqu, char *extra) |
| 9449 | { |
| 9450 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9451 | union iwreq_data wrqu_sec = { |
| 9452 | .encoding = { |
| 9453 | .flags = IW_ENCODE_DISABLED, |
| 9454 | }, |
| 9455 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9456 | int ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9457 | |
| 9458 | IPW_DEBUG_WX("SW_RESET\n"); |
| 9459 | |
| 9460 | down(&priv->sem); |
| 9461 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9462 | ret = ipw_sw_reset(priv, 0); |
| 9463 | if (!ret) { |
| 9464 | free_firmware(); |
| 9465 | ipw_adapter_restart(priv); |
| 9466 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9467 | |
| 9468 | /* The SW reset bit might have been toggled on by the 'disable' |
| 9469 | * module parameter, so take appropriate action */ |
| 9470 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); |
| 9471 | |
| 9472 | up(&priv->sem); |
| 9473 | ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
| 9474 | down(&priv->sem); |
| 9475 | |
| 9476 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 9477 | /* Configuration likely changed -- force [re]association */ |
| 9478 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " |
| 9479 | "reset.\n"); |
| 9480 | if (!ipw_disassociate(priv)) |
| 9481 | ipw_associate(priv); |
| 9482 | } |
| 9483 | |
| 9484 | up(&priv->sem); |
| 9485 | |
| 9486 | return 0; |
| 9487 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9488 | |
| 9489 | /* Rebase the WE IOCTLs to zero for the handler array */ |
| 9490 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9491 | static iw_handler ipw_wx_handlers[] = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9492 | IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, |
| 9493 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, |
| 9494 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, |
| 9495 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, |
| 9496 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, |
| 9497 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
| 9498 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, |
| 9499 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, |
| 9500 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, |
| 9501 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, |
| 9502 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, |
| 9503 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, |
| 9504 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, |
| 9505 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, |
| 9506 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, |
| 9507 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, |
| 9508 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, |
| 9509 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, |
| 9510 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, |
| 9511 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, |
| 9512 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, |
| 9513 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, |
| 9514 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, |
| 9515 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, |
| 9516 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, |
| 9517 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, |
| 9518 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, |
| 9519 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9520 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
| 9521 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, |
| 9522 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, |
| 9523 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9524 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
| 9525 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, |
| 9526 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, |
| 9527 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, |
| 9528 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, |
| 9529 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, |
| 9530 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9531 | }; |
| 9532 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9533 | enum { |
| 9534 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, |
| 9535 | IPW_PRIV_GET_POWER, |
| 9536 | IPW_PRIV_SET_MODE, |
| 9537 | IPW_PRIV_GET_MODE, |
| 9538 | IPW_PRIV_SET_PREAMBLE, |
| 9539 | IPW_PRIV_GET_PREAMBLE, |
| 9540 | IPW_PRIV_RESET, |
| 9541 | IPW_PRIV_SW_RESET, |
| 9542 | #ifdef CONFIG_IPW2200_MONITOR |
| 9543 | IPW_PRIV_SET_MONITOR, |
| 9544 | #endif |
| 9545 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9546 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9547 | static struct iw_priv_args ipw_priv_args[] = { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9548 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9549 | .cmd = IPW_PRIV_SET_POWER, |
| 9550 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9551 | .name = "set_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9552 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9553 | .cmd = IPW_PRIV_GET_POWER, |
| 9554 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9555 | .name = "get_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9556 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9557 | .cmd = IPW_PRIV_SET_MODE, |
| 9558 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9559 | .name = "set_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9560 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9561 | .cmd = IPW_PRIV_GET_MODE, |
| 9562 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9563 | .name = "get_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9564 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9565 | .cmd = IPW_PRIV_SET_PREAMBLE, |
| 9566 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9567 | .name = "set_preamble"}, |
| 9568 | { |
| 9569 | .cmd = IPW_PRIV_GET_PREAMBLE, |
| 9570 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, |
| 9571 | .name = "get_preamble"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9572 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9573 | IPW_PRIV_RESET, |
| 9574 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9575 | { |
| 9576 | IPW_PRIV_SW_RESET, |
| 9577 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, |
| 9578 | #ifdef CONFIG_IPW2200_MONITOR |
| 9579 | { |
| 9580 | IPW_PRIV_SET_MONITOR, |
| 9581 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, |
| 9582 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9583 | }; |
| 9584 | |
| 9585 | static iw_handler ipw_priv_handler[] = { |
| 9586 | ipw_wx_set_powermode, |
| 9587 | ipw_wx_get_powermode, |
| 9588 | ipw_wx_set_wireless_mode, |
| 9589 | ipw_wx_get_wireless_mode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9590 | ipw_wx_set_preamble, |
| 9591 | ipw_wx_get_preamble, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9592 | ipw_wx_reset, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9593 | ipw_wx_sw_reset, |
| 9594 | #ifdef CONFIG_IPW2200_MONITOR |
| 9595 | ipw_wx_set_monitor, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9596 | #endif |
| 9597 | }; |
| 9598 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9599 | static struct iw_handler_def ipw_wx_handler_def = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9600 | .standard = ipw_wx_handlers, |
| 9601 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), |
| 9602 | .num_private = ARRAY_SIZE(ipw_priv_handler), |
| 9603 | .num_private_args = ARRAY_SIZE(ipw_priv_args), |
| 9604 | .private = ipw_priv_handler, |
| 9605 | .private_args = ipw_priv_args, |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 9606 | .get_wireless_stats = ipw_get_wireless_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9607 | }; |
| 9608 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9609 | /* |
| 9610 | * Get wireless statistics. |
| 9611 | * Called by /proc/net/wireless |
| 9612 | * Also called by SIOCGIWSTATS |
| 9613 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9614 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9615 | { |
| 9616 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9617 | struct iw_statistics *wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9618 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9619 | wstats = &priv->wstats; |
| 9620 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9621 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9622 | * netdev->get_wireless_stats seems to be called before fw is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9623 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
| 9624 | * and associated; if not associcated, the values are all meaningless |
| 9625 | * anyway, so set them all to NULL and INVALID */ |
| 9626 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 9627 | wstats->miss.beacon = 0; |
| 9628 | wstats->discard.retries = 0; |
| 9629 | wstats->qual.qual = 0; |
| 9630 | wstats->qual.level = 0; |
| 9631 | wstats->qual.noise = 0; |
| 9632 | wstats->qual.updated = 7; |
| 9633 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9634 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9635 | return wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9636 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9637 | |
| 9638 | wstats->qual.qual = priv->quality; |
| 9639 | wstats->qual.level = average_value(&priv->average_rssi); |
| 9640 | wstats->qual.noise = average_value(&priv->average_noise); |
| 9641 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9642 | IW_QUAL_NOISE_UPDATED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9643 | |
| 9644 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); |
| 9645 | wstats->discard.retries = priv->last_tx_failures; |
| 9646 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9647 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9648 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
| 9649 | goto fail_get_ordinal; |
| 9650 | wstats->discard.retries += tx_retry; */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9651 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9652 | return wstats; |
| 9653 | } |
| 9654 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9655 | /* net device stuff */ |
| 9656 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 9657 | static void init_sys_config(struct ipw_sys_config *sys_config) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9658 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9659 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame^] | 9660 | sys_config->bt_coexistence = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9661 | sys_config->answer_broadcast_ssid_probe = 0; |
| 9662 | sys_config->accept_all_data_frames = 0; |
| 9663 | sys_config->accept_non_directed_frames = 1; |
| 9664 | sys_config->exclude_unicast_unencrypted = 0; |
| 9665 | sys_config->disable_unicast_decryption = 1; |
| 9666 | sys_config->exclude_multicast_unencrypted = 0; |
| 9667 | sys_config->disable_multicast_decryption = 1; |
| 9668 | sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9669 | 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] | 9670 | sys_config->dot11g_auto_detection = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9671 | sys_config->enable_cts_to_self = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9672 | sys_config->bt_coexist_collision_thr = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9673 | sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256 |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9674 | } |
| 9675 | |
| 9676 | static int ipw_net_open(struct net_device *dev) |
| 9677 | { |
| 9678 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9679 | IPW_DEBUG_INFO("dev->open\n"); |
| 9680 | /* we should be verifying the device is ready to be opened */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9681 | down(&priv->sem); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9682 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 9683 | (priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9684 | netif_start_queue(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9685 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9686 | return 0; |
| 9687 | } |
| 9688 | |
| 9689 | static int ipw_net_stop(struct net_device *dev) |
| 9690 | { |
| 9691 | IPW_DEBUG_INFO("dev->close\n"); |
| 9692 | netif_stop_queue(dev); |
| 9693 | return 0; |
| 9694 | } |
| 9695 | |
| 9696 | /* |
| 9697 | todo: |
| 9698 | |
| 9699 | modify to send one tfd per fragment instead of using chunking. otherwise |
| 9700 | we need to heavily modify the ieee80211_skb_to_txb. |
| 9701 | */ |
| 9702 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 9703 | 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] | 9704 | int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9705 | { |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 9706 | struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9707 | txb->fragments[0]->data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9708 | int i = 0; |
| 9709 | struct tfd_frame *tfd; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9710 | #ifdef CONFIG_IPW_QOS |
| 9711 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 9712 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 9713 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9714 | struct clx2_tx_queue *txq = &priv->txq[0]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9715 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9716 | struct clx2_queue *q = &txq->q; |
| 9717 | u8 id, hdr_len, unicast; |
| 9718 | u16 remaining_bytes; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9719 | int fc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9720 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9721 | /* If there isn't room in the queue, we return busy and let the |
| 9722 | * network stack requeue the packet for us */ |
| 9723 | if (ipw_queue_space(q) < q->high_mark) |
| 9724 | return NETDEV_TX_BUSY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9725 | |
| 9726 | switch (priv->ieee->iw_mode) { |
| 9727 | case IW_MODE_ADHOC: |
| 9728 | hdr_len = IEEE80211_3ADDR_LEN; |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 9729 | unicast = !is_multicast_ether_addr(hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9730 | id = ipw_find_station(priv, hdr->addr1); |
| 9731 | if (id == IPW_INVALID_STATION) { |
| 9732 | id = ipw_add_station(priv, hdr->addr1); |
| 9733 | if (id == IPW_INVALID_STATION) { |
| 9734 | IPW_WARNING("Attempt to send data to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9735 | "invalid cell: " MAC_FMT "\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9736 | MAC_ARG(hdr->addr1)); |
| 9737 | goto drop; |
| 9738 | } |
| 9739 | } |
| 9740 | break; |
| 9741 | |
| 9742 | case IW_MODE_INFRA: |
| 9743 | default: |
Stephen Hemminger | 3c19065 | 2006-01-03 15:27:38 -0800 | [diff] [blame] | 9744 | unicast = !is_multicast_ether_addr(hdr->addr3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9745 | hdr_len = IEEE80211_3ADDR_LEN; |
| 9746 | id = 0; |
| 9747 | break; |
| 9748 | } |
| 9749 | |
| 9750 | tfd = &txq->bd[q->first_empty]; |
| 9751 | txq->txb[q->first_empty] = txb; |
| 9752 | memset(tfd, 0, sizeof(*tfd)); |
| 9753 | tfd->u.data.station_number = id; |
| 9754 | |
| 9755 | tfd->control_flags.message_type = TX_FRAME_TYPE; |
| 9756 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 9757 | |
| 9758 | tfd->u.data.cmd_id = DINO_CMD_TX; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9759 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9760 | remaining_bytes = txb->payload_size; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9761 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9762 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9763 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9764 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9765 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9766 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9767 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
| 9768 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9769 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9770 | fc = le16_to_cpu(hdr->frame_ctl); |
| 9771 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9772 | |
| 9773 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); |
| 9774 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9775 | if (likely(unicast)) |
| 9776 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 9777 | |
| 9778 | if (txb->encrypted && !priv->ieee->host_encrypt) { |
| 9779 | switch (priv->ieee->sec.level) { |
| 9780 | case SEC_LEVEL_3: |
| 9781 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9782 | IEEE80211_FCTL_PROTECTED; |
| 9783 | /* XXX: ACK flag must be set for CCMP even if it |
| 9784 | * is a multicast/broadcast packet, because CCMP |
| 9785 | * group communication encrypted by GTK is |
| 9786 | * actually done by the AP. */ |
| 9787 | if (!unicast) |
| 9788 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 9789 | |
| 9790 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 9791 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; |
| 9792 | tfd->u.data.key_index = 0; |
| 9793 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; |
| 9794 | break; |
| 9795 | case SEC_LEVEL_2: |
| 9796 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9797 | IEEE80211_FCTL_PROTECTED; |
| 9798 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 9799 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; |
| 9800 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; |
| 9801 | break; |
| 9802 | case SEC_LEVEL_1: |
| 9803 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9804 | IEEE80211_FCTL_PROTECTED; |
| 9805 | tfd->u.data.key_index = priv->ieee->tx_keyidx; |
| 9806 | if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <= |
| 9807 | 40) |
| 9808 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; |
| 9809 | else |
| 9810 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; |
| 9811 | break; |
| 9812 | case SEC_LEVEL_0: |
| 9813 | break; |
| 9814 | default: |
| 9815 | printk(KERN_ERR "Unknow security level %d\n", |
| 9816 | priv->ieee->sec.level); |
| 9817 | break; |
| 9818 | } |
| 9819 | } else |
| 9820 | /* No hardware encryption */ |
| 9821 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; |
| 9822 | |
| 9823 | #ifdef CONFIG_IPW_QOS |
| 9824 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast); |
| 9825 | #endif /* CONFIG_IPW_QOS */ |
| 9826 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9827 | /* payload */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9828 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
| 9829 | txb->nr_frags)); |
| 9830 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", |
| 9831 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); |
| 9832 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { |
| 9833 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", |
| 9834 | i, le32_to_cpu(tfd->u.data.num_chunks), |
| 9835 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9836 | 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] | 9837 | i, tfd->u.data.num_chunks, |
| 9838 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9839 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9840 | txb->fragments[i]->len - hdr_len); |
| 9841 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9842 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9843 | cpu_to_le32(pci_map_single |
| 9844 | (priv->pci_dev, |
| 9845 | txb->fragments[i]->data + hdr_len, |
| 9846 | txb->fragments[i]->len - hdr_len, |
| 9847 | PCI_DMA_TODEVICE)); |
| 9848 | tfd->u.data.chunk_len[i] = |
| 9849 | cpu_to_le16(txb->fragments[i]->len - hdr_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9850 | } |
| 9851 | |
| 9852 | if (i != txb->nr_frags) { |
| 9853 | struct sk_buff *skb; |
| 9854 | u16 remaining_bytes = 0; |
| 9855 | int j; |
| 9856 | |
| 9857 | for (j = i; j < txb->nr_frags; j++) |
| 9858 | remaining_bytes += txb->fragments[j]->len - hdr_len; |
| 9859 | |
| 9860 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", |
| 9861 | remaining_bytes); |
| 9862 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); |
| 9863 | if (skb != NULL) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9864 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9865 | for (j = i; j < txb->nr_frags; j++) { |
| 9866 | int size = txb->fragments[j]->len - hdr_len; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9867 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9868 | printk(KERN_INFO "Adding frag %d %d...\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9869 | j, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9870 | memcpy(skb_put(skb, size), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9871 | txb->fragments[j]->data + hdr_len, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9872 | } |
| 9873 | dev_kfree_skb_any(txb->fragments[i]); |
| 9874 | txb->fragments[i] = skb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9875 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9876 | cpu_to_le32(pci_map_single |
| 9877 | (priv->pci_dev, skb->data, |
| 9878 | tfd->u.data.chunk_len[i], |
| 9879 | PCI_DMA_TODEVICE)); |
| 9880 | |
| 9881 | tfd->u.data.num_chunks = |
| 9882 | cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) + |
| 9883 | 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9884 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9885 | } |
| 9886 | |
| 9887 | /* kick DMA */ |
| 9888 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 9889 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 9890 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9891 | return NETDEV_TX_OK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9892 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9893 | drop: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9894 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
| 9895 | ieee80211_txb_free(txb); |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9896 | return NETDEV_TX_OK; |
| 9897 | } |
| 9898 | |
| 9899 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) |
| 9900 | { |
| 9901 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9902 | #ifdef CONFIG_IPW_QOS |
| 9903 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 9904 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 9905 | #else |
| 9906 | struct clx2_tx_queue *txq = &priv->txq[0]; |
| 9907 | #endif /* CONFIG_IPW_QOS */ |
| 9908 | |
| 9909 | if (ipw_queue_space(&txq->q) < txq->q.high_mark) |
| 9910 | return 1; |
| 9911 | |
| 9912 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9913 | } |
| 9914 | |
| 9915 | static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, |
James Ketrenos | c8d42d1 | 2005-09-21 12:23:43 -0500 | [diff] [blame] | 9916 | struct net_device *dev, int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9917 | { |
| 9918 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9919 | unsigned long flags; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9920 | int ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9921 | |
| 9922 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9923 | spin_lock_irqsave(&priv->lock, flags); |
| 9924 | |
| 9925 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 9926 | IPW_DEBUG_INFO("Tx attempt while not associated.\n"); |
| 9927 | priv->ieee->stats.tx_carrier_errors++; |
| 9928 | netif_stop_queue(dev); |
| 9929 | goto fail_unlock; |
| 9930 | } |
| 9931 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9932 | ret = ipw_tx_skb(priv, txb, pri); |
| 9933 | if (ret == NETDEV_TX_OK) |
| 9934 | __ipw_led_activity_on(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9935 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9936 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9937 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9938 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9939 | fail_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9940 | spin_unlock_irqrestore(&priv->lock, flags); |
| 9941 | return 1; |
| 9942 | } |
| 9943 | |
| 9944 | static struct net_device_stats *ipw_net_get_stats(struct net_device *dev) |
| 9945 | { |
| 9946 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9947 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9948 | priv->ieee->stats.tx_packets = priv->tx_packets; |
| 9949 | priv->ieee->stats.rx_packets = priv->rx_packets; |
| 9950 | return &priv->ieee->stats; |
| 9951 | } |
| 9952 | |
| 9953 | static void ipw_net_set_multicast_list(struct net_device *dev) |
| 9954 | { |
| 9955 | |
| 9956 | } |
| 9957 | |
| 9958 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) |
| 9959 | { |
| 9960 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9961 | struct sockaddr *addr = p; |
| 9962 | if (!is_valid_ether_addr(addr->sa_data)) |
| 9963 | return -EADDRNOTAVAIL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9964 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9965 | priv->config |= CFG_CUSTOM_MAC; |
| 9966 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
| 9967 | printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n", |
| 9968 | priv->net_dev->name, MAC_ARG(priv->mac_addr)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9969 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9970 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9971 | return 0; |
| 9972 | } |
| 9973 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9974 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9975 | struct ethtool_drvinfo *info) |
| 9976 | { |
| 9977 | struct ipw_priv *p = ieee80211_priv(dev); |
| 9978 | char vers[64]; |
| 9979 | char date[32]; |
| 9980 | u32 len; |
| 9981 | |
| 9982 | strcpy(info->driver, DRV_NAME); |
| 9983 | strcpy(info->version, DRV_VERSION); |
| 9984 | |
| 9985 | len = sizeof(vers); |
| 9986 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); |
| 9987 | len = sizeof(date); |
| 9988 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); |
| 9989 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9990 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9991 | vers, date); |
| 9992 | strcpy(info->bus_info, pci_name(p->pci_dev)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9993 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9994 | } |
| 9995 | |
| 9996 | static u32 ipw_ethtool_get_link(struct net_device *dev) |
| 9997 | { |
| 9998 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9999 | return (priv->status & STATUS_ASSOCIATED) != 0; |
| 10000 | } |
| 10001 | |
| 10002 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) |
| 10003 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10004 | return IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10005 | } |
| 10006 | |
| 10007 | static int ipw_ethtool_get_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10008 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10009 | { |
| 10010 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10011 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10012 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10013 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10014 | down(&p->sem); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10015 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10016 | up(&p->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10017 | return 0; |
| 10018 | } |
| 10019 | |
| 10020 | static int ipw_ethtool_set_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10021 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10022 | { |
| 10023 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10024 | int i; |
| 10025 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10026 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10027 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10028 | down(&p->sem); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10029 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10030 | for (i = IPW_EEPROM_DATA; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10031 | i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10032 | ipw_write8(p, i, p->eeprom[i]); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10033 | up(&p->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10034 | return 0; |
| 10035 | } |
| 10036 | |
| 10037 | static struct ethtool_ops ipw_ethtool_ops = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10038 | .get_link = ipw_ethtool_get_link, |
| 10039 | .get_drvinfo = ipw_ethtool_get_drvinfo, |
| 10040 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, |
| 10041 | .get_eeprom = ipw_ethtool_get_eeprom, |
| 10042 | .set_eeprom = ipw_ethtool_set_eeprom, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10043 | }; |
| 10044 | |
| 10045 | static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs) |
| 10046 | { |
| 10047 | struct ipw_priv *priv = data; |
| 10048 | u32 inta, inta_mask; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10049 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10050 | if (!priv) |
| 10051 | return IRQ_NONE; |
| 10052 | |
| 10053 | spin_lock(&priv->lock); |
| 10054 | |
| 10055 | if (!(priv->status & STATUS_INT_ENABLED)) { |
| 10056 | /* Shared IRQ */ |
| 10057 | goto none; |
| 10058 | } |
| 10059 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10060 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 10061 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
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 | if (inta == 0xFFFFFFFF) { |
| 10064 | /* Hardware disappeared */ |
| 10065 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); |
| 10066 | goto none; |
| 10067 | } |
| 10068 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10069 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10070 | /* Shared interrupt */ |
| 10071 | goto none; |
| 10072 | } |
| 10073 | |
| 10074 | /* tell the device to stop sending interrupts */ |
| 10075 | ipw_disable_interrupts(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10076 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10077 | /* ack current interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10078 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
| 10079 | ipw_write32(priv, IPW_INTA_RW, inta); |
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 | /* Cache INTA value for our tasklet */ |
| 10082 | priv->isr_inta = inta; |
| 10083 | |
| 10084 | tasklet_schedule(&priv->irq_tasklet); |
| 10085 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10086 | spin_unlock(&priv->lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10087 | |
| 10088 | return IRQ_HANDLED; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10089 | none: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10090 | spin_unlock(&priv->lock); |
| 10091 | return IRQ_NONE; |
| 10092 | } |
| 10093 | |
| 10094 | static void ipw_rf_kill(void *adapter) |
| 10095 | { |
| 10096 | struct ipw_priv *priv = adapter; |
| 10097 | unsigned long flags; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10098 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10099 | spin_lock_irqsave(&priv->lock, flags); |
| 10100 | |
| 10101 | if (rf_kill_active(priv)) { |
| 10102 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); |
| 10103 | if (priv->workqueue) |
| 10104 | queue_delayed_work(priv->workqueue, |
| 10105 | &priv->rf_kill, 2 * HZ); |
| 10106 | goto exit_unlock; |
| 10107 | } |
| 10108 | |
| 10109 | /* RF Kill is now disabled, so bring the device back up */ |
| 10110 | |
| 10111 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 10112 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " |
| 10113 | "device\n"); |
| 10114 | |
| 10115 | /* we can not do an adapter restart while inside an irq lock */ |
| 10116 | queue_work(priv->workqueue, &priv->adapter_restart); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10117 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10118 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
| 10119 | "enabled\n"); |
| 10120 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10121 | exit_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10122 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10123 | } |
| 10124 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10125 | static void ipw_bg_rf_kill(void *data) |
| 10126 | { |
| 10127 | struct ipw_priv *priv = data; |
| 10128 | down(&priv->sem); |
| 10129 | ipw_rf_kill(data); |
| 10130 | up(&priv->sem); |
| 10131 | } |
| 10132 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10133 | static void ipw_link_up(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10134 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10135 | priv->last_seq_num = -1; |
| 10136 | priv->last_frag_num = -1; |
| 10137 | priv->last_packet_time = 0; |
| 10138 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10139 | netif_carrier_on(priv->net_dev); |
| 10140 | if (netif_queue_stopped(priv->net_dev)) { |
| 10141 | IPW_DEBUG_NOTIF("waking queue\n"); |
| 10142 | netif_wake_queue(priv->net_dev); |
| 10143 | } else { |
| 10144 | IPW_DEBUG_NOTIF("starting queue\n"); |
| 10145 | netif_start_queue(priv->net_dev); |
| 10146 | } |
| 10147 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10148 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10149 | ipw_reset_stats(priv); |
| 10150 | /* Ensure the rate is updated immediately */ |
| 10151 | priv->last_rate = ipw_get_current_rate(priv); |
| 10152 | ipw_gather_stats(priv); |
| 10153 | ipw_led_link_up(priv); |
| 10154 | notify_wx_assoc_event(priv); |
| 10155 | |
| 10156 | if (priv->config & CFG_BACKGROUND_SCAN) |
| 10157 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); |
| 10158 | } |
| 10159 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10160 | static void ipw_bg_link_up(void *data) |
| 10161 | { |
| 10162 | struct ipw_priv *priv = data; |
| 10163 | down(&priv->sem); |
| 10164 | ipw_link_up(data); |
| 10165 | up(&priv->sem); |
| 10166 | } |
| 10167 | |
Adrian Bunk | a73e22b | 2006-01-21 01:39:42 +0100 | [diff] [blame] | 10168 | static void ipw_link_down(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10169 | { |
| 10170 | ipw_led_link_down(priv); |
| 10171 | netif_carrier_off(priv->net_dev); |
| 10172 | netif_stop_queue(priv->net_dev); |
| 10173 | notify_wx_assoc_event(priv); |
| 10174 | |
| 10175 | /* Cancel any queued work ... */ |
| 10176 | cancel_delayed_work(&priv->request_scan); |
| 10177 | cancel_delayed_work(&priv->adhoc_check); |
| 10178 | cancel_delayed_work(&priv->gather_stats); |
| 10179 | |
| 10180 | ipw_reset_stats(priv); |
| 10181 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10182 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
| 10183 | /* Queue up another scan... */ |
| 10184 | queue_work(priv->workqueue, &priv->request_scan); |
| 10185 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10186 | } |
| 10187 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10188 | static void ipw_bg_link_down(void *data) |
| 10189 | { |
| 10190 | struct ipw_priv *priv = data; |
| 10191 | down(&priv->sem); |
| 10192 | ipw_link_down(data); |
| 10193 | up(&priv->sem); |
| 10194 | } |
| 10195 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10196 | static int ipw_setup_deferred_work(struct ipw_priv *priv) |
| 10197 | { |
| 10198 | int ret = 0; |
| 10199 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10200 | priv->workqueue = create_workqueue(DRV_NAME); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10201 | init_waitqueue_head(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10202 | init_waitqueue_head(&priv->wait_state); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10203 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10204 | INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv); |
| 10205 | INIT_WORK(&priv->associate, ipw_bg_associate, priv); |
| 10206 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv); |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 10207 | INIT_WORK(&priv->system_config, ipw_system_config, priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10208 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv); |
| 10209 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv); |
| 10210 | INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv); |
| 10211 | INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv); |
| 10212 | INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10213 | INIT_WORK(&priv->request_scan, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10214 | (void (*)(void *))ipw_request_scan, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10215 | INIT_WORK(&priv->gather_stats, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10216 | (void (*)(void *))ipw_bg_gather_stats, priv); |
| 10217 | INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv); |
| 10218 | INIT_WORK(&priv->roam, ipw_bg_roam, priv); |
| 10219 | INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv); |
| 10220 | INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv); |
| 10221 | INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv); |
| 10222 | 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] | 10223 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10224 | 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] | 10225 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10226 | INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off, |
| 10227 | priv); |
| 10228 | INIT_WORK(&priv->merge_networks, |
| 10229 | (void (*)(void *))ipw_merge_adhoc_network, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10230 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10231 | #ifdef CONFIG_IPW_QOS |
| 10232 | INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate, |
| 10233 | priv); |
| 10234 | #endif /* CONFIG_IPW_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10235 | |
| 10236 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 10237 | ipw_irq_tasklet, (unsigned long)priv); |
| 10238 | |
| 10239 | return ret; |
| 10240 | } |
| 10241 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10242 | static void shim__set_security(struct net_device *dev, |
| 10243 | struct ieee80211_security *sec) |
| 10244 | { |
| 10245 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10246 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10247 | for (i = 0; i < 4; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10248 | if (sec->flags & (1 << i)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10249 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10250 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10251 | if (sec->key_sizes[i] == 0) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10252 | priv->ieee->sec.flags &= ~(1 << i); |
| 10253 | else { |
| 10254 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10255 | sec->key_sizes[i]); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10256 | priv->ieee->sec.flags |= (1 << i); |
| 10257 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10258 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10259 | } else if (sec->level != SEC_LEVEL_1) |
| 10260 | priv->ieee->sec.flags &= ~(1 << i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10261 | } |
| 10262 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10263 | if (sec->flags & SEC_ACTIVE_KEY) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10264 | if (sec->active_key <= 3) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10265 | priv->ieee->sec.active_key = sec->active_key; |
| 10266 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10267 | } else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10268 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10269 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10270 | } else |
| 10271 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10272 | |
| 10273 | if ((sec->flags & SEC_AUTH_MODE) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10274 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
| 10275 | priv->ieee->sec.auth_mode = sec->auth_mode; |
| 10276 | priv->ieee->sec.flags |= SEC_AUTH_MODE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10277 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
| 10278 | priv->capability |= CAP_SHARED_KEY; |
| 10279 | else |
| 10280 | priv->capability &= ~CAP_SHARED_KEY; |
| 10281 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10282 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10283 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10284 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
| 10285 | priv->ieee->sec.flags |= SEC_ENABLED; |
| 10286 | priv->ieee->sec.enabled = sec->enabled; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10287 | priv->status |= STATUS_SECURITY_UPDATED; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10288 | if (sec->enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10289 | priv->capability |= CAP_PRIVACY_ON; |
| 10290 | else |
| 10291 | priv->capability &= ~CAP_PRIVACY_ON; |
| 10292 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10293 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10294 | if (sec->flags & SEC_ENCRYPT) |
| 10295 | priv->ieee->sec.encrypt = sec->encrypt; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10296 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10297 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
| 10298 | priv->ieee->sec.level = sec->level; |
| 10299 | priv->ieee->sec.flags |= SEC_LEVEL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10300 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10301 | } |
| 10302 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 10303 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
| 10304 | ipw_set_hwcrypto_keys(priv); |
| 10305 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10306 | /* To match current functionality of ipw2100 (which works well w/ |
| 10307 | * various supplicants, we don't force a disassociate if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10308 | * privacy capability changes ... */ |
| 10309 | #if 0 |
| 10310 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10311 | (((priv->assoc_request.capability & |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10312 | WLAN_CAPABILITY_PRIVACY) && !sec->enabled) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10313 | (!(priv->assoc_request.capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10314 | WLAN_CAPABILITY_PRIVACY) && sec->enabled))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10315 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
| 10316 | "change.\n"); |
| 10317 | ipw_disassociate(priv); |
| 10318 | } |
| 10319 | #endif |
| 10320 | } |
| 10321 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10322 | static int init_supported_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10323 | struct ipw_supported_rates *rates) |
| 10324 | { |
| 10325 | /* TODO: Mask out rates based on priv->rates_mask */ |
| 10326 | |
| 10327 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10328 | /* configure supported rates */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10329 | switch (priv->ieee->freq_band) { |
| 10330 | case IEEE80211_52GHZ_BAND: |
| 10331 | rates->ieee_mode = IPW_A_MODE; |
| 10332 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10333 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10334 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10335 | break; |
| 10336 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10337 | default: /* Mixed or 2.4Ghz */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10338 | rates->ieee_mode = IPW_G_MODE; |
| 10339 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10340 | ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10341 | IEEE80211_CCK_DEFAULT_RATES_MASK); |
| 10342 | if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) { |
| 10343 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10344 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10345 | } |
| 10346 | break; |
| 10347 | } |
| 10348 | |
| 10349 | return 0; |
| 10350 | } |
| 10351 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10352 | static int ipw_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10353 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10354 | /* This is only called from ipw_up, which resets/reloads the firmware |
| 10355 | so, we don't need to first disable the card before we configure |
| 10356 | it */ |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 10357 | if (ipw_set_tx_power(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10358 | goto error; |
| 10359 | |
| 10360 | /* initialize adapter address */ |
| 10361 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) |
| 10362 | goto error; |
| 10363 | |
| 10364 | /* set basic system config settings */ |
| 10365 | init_sys_config(&priv->sys_config); |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame^] | 10366 | |
| 10367 | /* Support Bluetooth if we have BT h/w on board, and user wants to. |
| 10368 | * Does not support BT priority yet (don't abort or defer our Tx) */ |
| 10369 | if (bt_coexist) { |
| 10370 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
| 10371 | |
| 10372 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) |
| 10373 | priv->sys_config.bt_coexistence |
| 10374 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
| 10375 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
| 10376 | priv->sys_config.bt_coexistence |
| 10377 | |= CFG_BT_COEXISTENCE_OOB; |
| 10378 | } |
| 10379 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10380 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 10381 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 10382 | else |
| 10383 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 10384 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10385 | if (ipw_send_system_config(priv, &priv->sys_config)) |
| 10386 | goto error; |
| 10387 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10388 | init_supported_rates(priv, &priv->rates); |
| 10389 | if (ipw_send_supported_rates(priv, &priv->rates)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10390 | goto error; |
| 10391 | |
| 10392 | /* Set request-to-send threshold */ |
| 10393 | if (priv->rts_threshold) { |
| 10394 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) |
| 10395 | goto error; |
| 10396 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10397 | #ifdef CONFIG_IPW_QOS |
| 10398 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
| 10399 | ipw_qos_activate(priv, NULL); |
| 10400 | #endif /* CONFIG_IPW_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10401 | |
| 10402 | if (ipw_set_random_seed(priv)) |
| 10403 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10404 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10405 | /* final state transition to the RUN state */ |
| 10406 | if (ipw_send_host_complete(priv)) |
| 10407 | goto error; |
| 10408 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10409 | priv->status |= STATUS_INIT; |
| 10410 | |
| 10411 | ipw_led_init(priv); |
| 10412 | ipw_led_radio_on(priv); |
| 10413 | priv->notif_missed_beacons = 0; |
| 10414 | |
| 10415 | /* Set hardware WEP key if it is configured. */ |
| 10416 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 10417 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 10418 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 10419 | ipw_set_hwcrypto_keys(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10420 | |
| 10421 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10422 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10423 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10424 | return -EIO; |
| 10425 | } |
| 10426 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10427 | /* |
| 10428 | * NOTE: |
| 10429 | * |
| 10430 | * These tables have been tested in conjunction with the |
| 10431 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. |
| 10432 | * |
| 10433 | * Altering this values, using it on other hardware, or in geographies |
| 10434 | * not intended for resale of the above mentioned Intel adapters has |
| 10435 | * not been tested. |
| 10436 | * |
| 10437 | */ |
| 10438 | static const struct ieee80211_geo ipw_geos[] = { |
| 10439 | { /* Restricted */ |
| 10440 | "---", |
| 10441 | .bg_channels = 11, |
| 10442 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10443 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10444 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10445 | {2457, 10}, {2462, 11}}, |
| 10446 | }, |
| 10447 | |
| 10448 | { /* Custom US/Canada */ |
| 10449 | "ZZF", |
| 10450 | .bg_channels = 11, |
| 10451 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10452 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10453 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10454 | {2457, 10}, {2462, 11}}, |
| 10455 | .a_channels = 8, |
| 10456 | .a = {{5180, 36}, |
| 10457 | {5200, 40}, |
| 10458 | {5220, 44}, |
| 10459 | {5240, 48}, |
| 10460 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10461 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10462 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10463 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10464 | }, |
| 10465 | |
| 10466 | { /* Rest of World */ |
| 10467 | "ZZD", |
| 10468 | .bg_channels = 13, |
| 10469 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10470 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10471 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10472 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10473 | {2472, 13}}, |
| 10474 | }, |
| 10475 | |
| 10476 | { /* Custom USA & Europe & High */ |
| 10477 | "ZZA", |
| 10478 | .bg_channels = 11, |
| 10479 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10480 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10481 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10482 | {2457, 10}, {2462, 11}}, |
| 10483 | .a_channels = 13, |
| 10484 | .a = {{5180, 36}, |
| 10485 | {5200, 40}, |
| 10486 | {5220, 44}, |
| 10487 | {5240, 48}, |
| 10488 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10489 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10490 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10491 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10492 | {5745, 149}, |
| 10493 | {5765, 153}, |
| 10494 | {5785, 157}, |
| 10495 | {5805, 161}, |
| 10496 | {5825, 165}}, |
| 10497 | }, |
| 10498 | |
| 10499 | { /* Custom NA & Europe */ |
| 10500 | "ZZB", |
| 10501 | .bg_channels = 11, |
| 10502 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10503 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10504 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10505 | {2457, 10}, {2462, 11}}, |
| 10506 | .a_channels = 13, |
| 10507 | .a = {{5180, 36}, |
| 10508 | {5200, 40}, |
| 10509 | {5220, 44}, |
| 10510 | {5240, 48}, |
| 10511 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10512 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10513 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10514 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10515 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10516 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10517 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10518 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10519 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10520 | }, |
| 10521 | |
| 10522 | { /* Custom Japan */ |
| 10523 | "ZZC", |
| 10524 | .bg_channels = 11, |
| 10525 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10526 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10527 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10528 | {2457, 10}, {2462, 11}}, |
| 10529 | .a_channels = 4, |
| 10530 | .a = {{5170, 34}, {5190, 38}, |
| 10531 | {5210, 42}, {5230, 46}}, |
| 10532 | }, |
| 10533 | |
| 10534 | { /* Custom */ |
| 10535 | "ZZM", |
| 10536 | .bg_channels = 11, |
| 10537 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10538 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10539 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10540 | {2457, 10}, {2462, 11}}, |
| 10541 | }, |
| 10542 | |
| 10543 | { /* Europe */ |
| 10544 | "ZZE", |
| 10545 | .bg_channels = 13, |
| 10546 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10547 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10548 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10549 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10550 | {2472, 13}}, |
| 10551 | .a_channels = 19, |
| 10552 | .a = {{5180, 36}, |
| 10553 | {5200, 40}, |
| 10554 | {5220, 44}, |
| 10555 | {5240, 48}, |
| 10556 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10557 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10558 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10559 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10560 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 10561 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 10562 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 10563 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 10564 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 10565 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 10566 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 10567 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 10568 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 10569 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 10570 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10571 | }, |
| 10572 | |
| 10573 | { /* Custom Japan */ |
| 10574 | "ZZJ", |
| 10575 | .bg_channels = 14, |
| 10576 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10577 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10578 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10579 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10580 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}}, |
| 10581 | .a_channels = 4, |
| 10582 | .a = {{5170, 34}, {5190, 38}, |
| 10583 | {5210, 42}, {5230, 46}}, |
| 10584 | }, |
| 10585 | |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 10586 | { /* Rest of World */ |
| 10587 | "ZZR", |
| 10588 | .bg_channels = 14, |
| 10589 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10590 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10591 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10592 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10593 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY | |
| 10594 | IEEE80211_CH_PASSIVE_ONLY}}, |
| 10595 | }, |
| 10596 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10597 | { /* High Band */ |
| 10598 | "ZZH", |
| 10599 | .bg_channels = 13, |
| 10600 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10601 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10602 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10603 | {2457, 10}, {2462, 11}, |
| 10604 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 10605 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10606 | .a_channels = 4, |
| 10607 | .a = {{5745, 149}, {5765, 153}, |
| 10608 | {5785, 157}, {5805, 161}}, |
| 10609 | }, |
| 10610 | |
| 10611 | { /* Custom Europe */ |
| 10612 | "ZZG", |
| 10613 | .bg_channels = 13, |
| 10614 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10615 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10616 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10617 | {2457, 10}, {2462, 11}, |
| 10618 | {2467, 12}, {2472, 13}}, |
| 10619 | .a_channels = 4, |
| 10620 | .a = {{5180, 36}, {5200, 40}, |
| 10621 | {5220, 44}, {5240, 48}}, |
| 10622 | }, |
| 10623 | |
| 10624 | { /* Europe */ |
| 10625 | "ZZK", |
| 10626 | .bg_channels = 13, |
| 10627 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10628 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10629 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10630 | {2457, 10}, {2462, 11}, |
| 10631 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 10632 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10633 | .a_channels = 24, |
| 10634 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 10635 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 10636 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 10637 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 10638 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10639 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10640 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10641 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10642 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 10643 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 10644 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 10645 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 10646 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 10647 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 10648 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 10649 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 10650 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 10651 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 10652 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}, |
| 10653 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10654 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10655 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10656 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10657 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10658 | }, |
| 10659 | |
| 10660 | { /* Europe */ |
| 10661 | "ZZL", |
| 10662 | .bg_channels = 11, |
| 10663 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10664 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10665 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10666 | {2457, 10}, {2462, 11}}, |
| 10667 | .a_channels = 13, |
| 10668 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 10669 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 10670 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 10671 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 10672 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10673 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10674 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10675 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10676 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10677 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10678 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10679 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10680 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10681 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10682 | }; |
| 10683 | |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 10684 | /* GEO code borrowed from ieee80211_geo.c */ |
| 10685 | static int ipw_is_valid_channel(struct ieee80211_device *ieee, u8 channel) |
| 10686 | { |
| 10687 | int i; |
| 10688 | |
| 10689 | /* Driver needs to initialize the geography map before using |
| 10690 | * these helper functions */ |
| 10691 | BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0); |
| 10692 | |
| 10693 | if (ieee->freq_band & IEEE80211_24GHZ_BAND) |
| 10694 | for (i = 0; i < ieee->geo.bg_channels; i++) |
| 10695 | /* NOTE: If G mode is currently supported but |
| 10696 | * this is a B only channel, we don't see it |
| 10697 | * as valid. */ |
| 10698 | if ((ieee->geo.bg[i].channel == channel) && |
| 10699 | (!(ieee->mode & IEEE_G) || |
| 10700 | !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY))) |
| 10701 | return IEEE80211_24GHZ_BAND; |
| 10702 | |
| 10703 | if (ieee->freq_band & IEEE80211_52GHZ_BAND) |
| 10704 | for (i = 0; i < ieee->geo.a_channels; i++) |
| 10705 | if (ieee->geo.a[i].channel == channel) |
| 10706 | return IEEE80211_52GHZ_BAND; |
| 10707 | |
| 10708 | return 0; |
| 10709 | } |
| 10710 | |
| 10711 | static int ipw_channel_to_index(struct ieee80211_device *ieee, u8 channel) |
| 10712 | { |
| 10713 | int i; |
| 10714 | |
| 10715 | /* Driver needs to initialize the geography map before using |
| 10716 | * these helper functions */ |
| 10717 | BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0); |
| 10718 | |
| 10719 | if (ieee->freq_band & IEEE80211_24GHZ_BAND) |
| 10720 | for (i = 0; i < ieee->geo.bg_channels; i++) |
| 10721 | if (ieee->geo.bg[i].channel == channel) |
| 10722 | return i; |
| 10723 | |
| 10724 | if (ieee->freq_band & IEEE80211_52GHZ_BAND) |
| 10725 | for (i = 0; i < ieee->geo.a_channels; i++) |
| 10726 | if (ieee->geo.a[i].channel == channel) |
| 10727 | return i; |
| 10728 | |
| 10729 | return -1; |
| 10730 | } |
| 10731 | |
| 10732 | static u8 ipw_freq_to_channel(struct ieee80211_device *ieee, u32 freq) |
| 10733 | { |
| 10734 | int i; |
| 10735 | |
| 10736 | /* Driver needs to initialize the geography map before using |
| 10737 | * these helper functions */ |
| 10738 | BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0); |
| 10739 | |
| 10740 | freq /= 100000; |
| 10741 | |
| 10742 | if (ieee->freq_band & IEEE80211_24GHZ_BAND) |
| 10743 | for (i = 0; i < ieee->geo.bg_channels; i++) |
| 10744 | if (ieee->geo.bg[i].freq == freq) |
| 10745 | return ieee->geo.bg[i].channel; |
| 10746 | |
| 10747 | if (ieee->freq_band & IEEE80211_52GHZ_BAND) |
| 10748 | for (i = 0; i < ieee->geo.a_channels; i++) |
| 10749 | if (ieee->geo.a[i].freq == freq) |
| 10750 | return ieee->geo.a[i].channel; |
| 10751 | |
| 10752 | return 0; |
| 10753 | } |
| 10754 | |
| 10755 | static int ipw_set_geo(struct ieee80211_device *ieee, |
| 10756 | const struct ieee80211_geo *geo) |
| 10757 | { |
| 10758 | memcpy(ieee->geo.name, geo->name, 3); |
| 10759 | ieee->geo.name[3] = '\0'; |
| 10760 | ieee->geo.bg_channels = geo->bg_channels; |
| 10761 | ieee->geo.a_channels = geo->a_channels; |
| 10762 | memcpy(ieee->geo.bg, geo->bg, geo->bg_channels * |
| 10763 | sizeof(struct ieee80211_channel)); |
| 10764 | memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels * |
| 10765 | sizeof(struct ieee80211_channel)); |
| 10766 | return 0; |
| 10767 | } |
| 10768 | |
| 10769 | static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *ieee) |
| 10770 | { |
| 10771 | return &ieee->geo; |
| 10772 | } |
| 10773 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10774 | #define MAX_HW_RESTARTS 5 |
| 10775 | static int ipw_up(struct ipw_priv *priv) |
| 10776 | { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10777 | int rc, i, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10778 | |
| 10779 | if (priv->status & STATUS_EXIT_PENDING) |
| 10780 | return -EIO; |
| 10781 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 10782 | if (cmdlog && !priv->cmdlog) { |
| 10783 | priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog, |
| 10784 | GFP_KERNEL); |
| 10785 | if (priv->cmdlog == NULL) { |
| 10786 | IPW_ERROR("Error allocating %d command log entries.\n", |
| 10787 | cmdlog); |
| 10788 | } else { |
| 10789 | memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog); |
| 10790 | priv->cmdlog_len = cmdlog; |
| 10791 | } |
| 10792 | } |
| 10793 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10794 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10795 | /* Load the microcode, firmware, and eeprom. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10796 | * Also start the clocks. */ |
| 10797 | rc = ipw_load(priv); |
| 10798 | if (rc) { |
Peter Jones | a4f6bbb | 2005-08-26 00:33:34 -0500 | [diff] [blame] | 10799 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10800 | return rc; |
| 10801 | } |
| 10802 | |
| 10803 | ipw_init_ordinals(priv); |
| 10804 | if (!(priv->config & CFG_CUSTOM_MAC)) |
| 10805 | eeprom_parse_mac(priv, priv->mac_addr); |
| 10806 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
| 10807 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10808 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
| 10809 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], |
| 10810 | ipw_geos[j].name, 3)) |
| 10811 | break; |
| 10812 | } |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 10813 | if (j == ARRAY_SIZE(ipw_geos)) { |
| 10814 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", |
| 10815 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], |
| 10816 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], |
| 10817 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10818 | j = 0; |
James Ketrenos | 0352057 | 2005-10-19 16:12:31 -0500 | [diff] [blame] | 10819 | } |
Liu Hong | 1fe0adb | 2005-08-19 09:33:10 -0500 | [diff] [blame] | 10820 | if (ipw_set_geo(priv->ieee, &ipw_geos[j])) { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10821 | IPW_WARNING("Could not set geography."); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10822 | return 0; |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10823 | } |
| 10824 | |
| 10825 | IPW_DEBUG_INFO("Geography %03d [%s] detected.\n", |
| 10826 | j, priv->ieee->geo.name); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10827 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10828 | if (priv->status & STATUS_RF_KILL_SW) { |
| 10829 | IPW_WARNING("Radio disabled by module parameter.\n"); |
| 10830 | return 0; |
| 10831 | } else if (rf_kill_active(priv)) { |
| 10832 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" |
| 10833 | "Kill switch must be turned off for " |
| 10834 | "wireless networking to work.\n"); |
| 10835 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
| 10836 | 2 * HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10837 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10838 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10839 | |
| 10840 | rc = ipw_config(priv); |
| 10841 | if (!rc) { |
| 10842 | IPW_DEBUG_INFO("Configured device on count %i\n", i); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10843 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame] | 10844 | /* If configure to try and auto-associate, kick |
| 10845 | * off a scan. */ |
| 10846 | queue_work(priv->workqueue, &priv->request_scan); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10847 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10848 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10849 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10850 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10851 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10852 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
| 10853 | i, MAX_HW_RESTARTS); |
| 10854 | |
| 10855 | /* We had an error bringing up the hardware, so take it |
| 10856 | * all the way back down so we can try again */ |
| 10857 | ipw_down(priv); |
| 10858 | } |
| 10859 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10860 | /* tried to restart and config the device for as long as our |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10861 | * patience could withstand */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10862 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10863 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10864 | return -EIO; |
| 10865 | } |
| 10866 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10867 | static void ipw_bg_up(void *data) |
| 10868 | { |
| 10869 | struct ipw_priv *priv = data; |
| 10870 | down(&priv->sem); |
| 10871 | ipw_up(data); |
| 10872 | up(&priv->sem); |
| 10873 | } |
| 10874 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10875 | static void ipw_deinit(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10876 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10877 | int i; |
| 10878 | |
| 10879 | if (priv->status & STATUS_SCANNING) { |
| 10880 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); |
| 10881 | ipw_abort_scan(priv); |
| 10882 | } |
| 10883 | |
| 10884 | if (priv->status & STATUS_ASSOCIATED) { |
| 10885 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); |
| 10886 | ipw_disassociate(priv); |
| 10887 | } |
| 10888 | |
| 10889 | ipw_led_shutdown(priv); |
| 10890 | |
| 10891 | /* Wait up to 1s for status to change to not scanning and not |
| 10892 | * associated (disassociation can take a while for a ful 802.11 |
| 10893 | * exchange */ |
| 10894 | for (i = 1000; i && (priv->status & |
| 10895 | (STATUS_DISASSOCIATING | |
| 10896 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) |
| 10897 | udelay(10); |
| 10898 | |
| 10899 | if (priv->status & (STATUS_DISASSOCIATING | |
| 10900 | STATUS_ASSOCIATED | STATUS_SCANNING)) |
| 10901 | IPW_DEBUG_INFO("Still associated or scanning...\n"); |
| 10902 | else |
| 10903 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); |
| 10904 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10905 | /* Attempt to disable the card */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10906 | ipw_send_card_disable(priv, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10907 | |
| 10908 | priv->status &= ~STATUS_INIT; |
| 10909 | } |
| 10910 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10911 | static void ipw_down(struct ipw_priv *priv) |
| 10912 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10913 | int exit_pending = priv->status & STATUS_EXIT_PENDING; |
| 10914 | |
| 10915 | priv->status |= STATUS_EXIT_PENDING; |
| 10916 | |
| 10917 | if (ipw_is_init(priv)) |
| 10918 | ipw_deinit(priv); |
| 10919 | |
| 10920 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 10921 | * exiting the module */ |
| 10922 | if (!exit_pending) |
| 10923 | priv->status &= ~STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10924 | |
| 10925 | /* tell the device to stop sending interrupts */ |
| 10926 | ipw_disable_interrupts(priv); |
| 10927 | |
| 10928 | /* Clear all bits but the RF Kill */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10929 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10930 | netif_carrier_off(priv->net_dev); |
| 10931 | netif_stop_queue(priv->net_dev); |
| 10932 | |
| 10933 | ipw_stop_nic(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10934 | |
| 10935 | ipw_led_radio_off(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10936 | } |
| 10937 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10938 | static void ipw_bg_down(void *data) |
| 10939 | { |
| 10940 | struct ipw_priv *priv = data; |
| 10941 | down(&priv->sem); |
| 10942 | ipw_down(data); |
| 10943 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10944 | } |
| 10945 | |
| 10946 | /* Called by register_netdev() */ |
| 10947 | static int ipw_net_init(struct net_device *dev) |
| 10948 | { |
| 10949 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10950 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10951 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10952 | if (ipw_up(priv)) { |
| 10953 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10954 | return -EIO; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10955 | } |
| 10956 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10957 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10958 | return 0; |
| 10959 | } |
| 10960 | |
| 10961 | /* PCI driver stuff */ |
| 10962 | static struct pci_device_id card_ids[] = { |
| 10963 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
| 10964 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, |
| 10965 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, |
| 10966 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, |
| 10967 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, |
| 10968 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, |
| 10969 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, |
| 10970 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, |
| 10971 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, |
| 10972 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, |
| 10973 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, |
| 10974 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, |
| 10975 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, |
| 10976 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, |
| 10977 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, |
| 10978 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, |
| 10979 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, |
| 10980 | {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] | 10981 | {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] | 10982 | {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] | 10983 | {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ |
| 10984 | {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] | 10985 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10986 | /* required last entry */ |
| 10987 | {0,} |
| 10988 | }; |
| 10989 | |
| 10990 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 10991 | |
| 10992 | static struct attribute *ipw_sysfs_entries[] = { |
| 10993 | &dev_attr_rf_kill.attr, |
| 10994 | &dev_attr_direct_dword.attr, |
| 10995 | &dev_attr_indirect_byte.attr, |
| 10996 | &dev_attr_indirect_dword.attr, |
| 10997 | &dev_attr_mem_gpio_reg.attr, |
| 10998 | &dev_attr_command_event_reg.attr, |
| 10999 | &dev_attr_nic_type.attr, |
| 11000 | &dev_attr_status.attr, |
| 11001 | &dev_attr_cfg.attr, |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 11002 | &dev_attr_error.attr, |
| 11003 | &dev_attr_event_log.attr, |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11004 | &dev_attr_cmd_log.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11005 | &dev_attr_eeprom_delay.attr, |
| 11006 | &dev_attr_ucode_version.attr, |
| 11007 | &dev_attr_rtc.attr, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11008 | &dev_attr_scan_age.attr, |
| 11009 | &dev_attr_led.attr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11010 | &dev_attr_speed_scan.attr, |
| 11011 | &dev_attr_net_stats.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11012 | NULL |
| 11013 | }; |
| 11014 | |
| 11015 | static struct attribute_group ipw_attribute_group = { |
| 11016 | .name = NULL, /* put in device directory */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11017 | .attrs = ipw_sysfs_entries, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11018 | }; |
| 11019 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11020 | 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] | 11021 | { |
| 11022 | int err = 0; |
| 11023 | struct net_device *net_dev; |
| 11024 | void __iomem *base; |
| 11025 | u32 length, val; |
| 11026 | struct ipw_priv *priv; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11027 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11028 | |
| 11029 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv)); |
| 11030 | if (net_dev == NULL) { |
| 11031 | err = -ENOMEM; |
| 11032 | goto out; |
| 11033 | } |
| 11034 | |
| 11035 | priv = ieee80211_priv(net_dev); |
| 11036 | priv->ieee = netdev_priv(net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11037 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11038 | priv->net_dev = net_dev; |
| 11039 | priv->pci_dev = pdev; |
Brice Goglin | 0f52bf9 | 2005-12-01 01:41:46 -0800 | [diff] [blame] | 11040 | #ifdef CONFIG_IPW2200_DEBUG |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11041 | ipw_debug_level = debug; |
| 11042 | #endif |
| 11043 | spin_lock_init(&priv->lock); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11044 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
| 11045 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11046 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11047 | init_MUTEX(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11048 | if (pci_enable_device(pdev)) { |
| 11049 | err = -ENODEV; |
| 11050 | goto out_free_ieee80211; |
| 11051 | } |
| 11052 | |
| 11053 | pci_set_master(pdev); |
| 11054 | |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 11055 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11056 | if (!err) |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 11057 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11058 | if (err) { |
| 11059 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 11060 | goto out_pci_disable_device; |
| 11061 | } |
| 11062 | |
| 11063 | pci_set_drvdata(pdev, priv); |
| 11064 | |
| 11065 | err = pci_request_regions(pdev, DRV_NAME); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11066 | if (err) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11067 | goto out_pci_disable_device; |
| 11068 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11069 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11070 | * PCI Tx retries from interfering with C3 CPU state */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11071 | pci_read_config_dword(pdev, 0x40, &val); |
| 11072 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11073 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11074 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11075 | length = pci_resource_len(pdev, 0); |
| 11076 | priv->hw_len = length; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11077 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11078 | base = ioremap_nocache(pci_resource_start(pdev, 0), length); |
| 11079 | if (!base) { |
| 11080 | err = -ENODEV; |
| 11081 | goto out_pci_release_regions; |
| 11082 | } |
| 11083 | |
| 11084 | priv->hw_base = base; |
| 11085 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); |
| 11086 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); |
| 11087 | |
| 11088 | err = ipw_setup_deferred_work(priv); |
| 11089 | if (err) { |
| 11090 | IPW_ERROR("Unable to setup deferred work\n"); |
| 11091 | goto out_iounmap; |
| 11092 | } |
| 11093 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11094 | ipw_sw_reset(priv, 1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11095 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11096 | err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11097 | if (err) { |
| 11098 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 11099 | goto out_destroy_workqueue; |
| 11100 | } |
| 11101 | |
| 11102 | SET_MODULE_OWNER(net_dev); |
| 11103 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
| 11104 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11105 | down(&priv->sem); |
| 11106 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11107 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
| 11108 | priv->ieee->set_security = shim__set_security; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 11109 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11110 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11111 | #ifdef CONFIG_IPW_QOS |
James Ketrenos | 3b9990c | 2005-08-19 13:18:55 -0500 | [diff] [blame] | 11112 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
| 11113 | priv->ieee->handle_beacon = ipw_handle_probe_response; |
| 11114 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11115 | #endif /* CONFIG_IPW_QOS */ |
| 11116 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11117 | priv->ieee->perfect_rssi = -20; |
| 11118 | priv->ieee->worst_rssi = -85; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11119 | |
| 11120 | net_dev->open = ipw_net_open; |
| 11121 | net_dev->stop = ipw_net_stop; |
| 11122 | net_dev->init = ipw_net_init; |
| 11123 | net_dev->get_stats = ipw_net_get_stats; |
| 11124 | net_dev->set_multicast_list = ipw_net_set_multicast_list; |
| 11125 | net_dev->set_mac_address = ipw_net_set_mac_address; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11126 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
Benoit Boissinot | 97a78ca | 2005-09-15 17:30:28 +0000 | [diff] [blame] | 11127 | net_dev->wireless_data = &priv->wireless_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11128 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
| 11129 | net_dev->ethtool_ops = &ipw_ethtool_ops; |
| 11130 | net_dev->irq = pdev->irq; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11131 | net_dev->base_addr = (unsigned long)priv->hw_base; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11132 | net_dev->mem_start = pci_resource_start(pdev, 0); |
| 11133 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; |
| 11134 | |
| 11135 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11136 | if (err) { |
| 11137 | IPW_ERROR("failed to create sysfs device attributes\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11138 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11139 | goto out_release_irq; |
| 11140 | } |
| 11141 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11142 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11143 | err = register_netdev(net_dev); |
| 11144 | if (err) { |
| 11145 | IPW_ERROR("failed to register network device\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11146 | goto out_remove_sysfs; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11147 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11148 | return 0; |
| 11149 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11150 | out_remove_sysfs: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11151 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11152 | out_release_irq: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11153 | free_irq(pdev->irq, priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11154 | out_destroy_workqueue: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11155 | destroy_workqueue(priv->workqueue); |
| 11156 | priv->workqueue = NULL; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11157 | out_iounmap: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11158 | iounmap(priv->hw_base); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11159 | out_pci_release_regions: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11160 | pci_release_regions(pdev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11161 | out_pci_disable_device: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11162 | pci_disable_device(pdev); |
| 11163 | pci_set_drvdata(pdev, NULL); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11164 | out_free_ieee80211: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11165 | free_ieee80211(priv->net_dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11166 | out: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11167 | return err; |
| 11168 | } |
| 11169 | |
| 11170 | static void ipw_pci_remove(struct pci_dev *pdev) |
| 11171 | { |
| 11172 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11173 | struct list_head *p, *q; |
| 11174 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11175 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11176 | if (!priv) |
| 11177 | return; |
| 11178 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11179 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11180 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11181 | priv->status |= STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11182 | ipw_down(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11183 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11184 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11185 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11186 | |
| 11187 | unregister_netdev(priv->net_dev); |
| 11188 | |
| 11189 | if (priv->rxq) { |
| 11190 | ipw_rx_queue_free(priv, priv->rxq); |
| 11191 | priv->rxq = NULL; |
| 11192 | } |
| 11193 | ipw_tx_queue_free(priv); |
| 11194 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11195 | if (priv->cmdlog) { |
| 11196 | kfree(priv->cmdlog); |
| 11197 | priv->cmdlog = NULL; |
| 11198 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11199 | /* ipw_down will ensure that there is no more pending work |
| 11200 | * in the workqueue's, so we can safely remove them now. */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11201 | cancel_delayed_work(&priv->adhoc_check); |
| 11202 | cancel_delayed_work(&priv->gather_stats); |
| 11203 | cancel_delayed_work(&priv->request_scan); |
| 11204 | cancel_delayed_work(&priv->rf_kill); |
| 11205 | cancel_delayed_work(&priv->scan_check); |
| 11206 | destroy_workqueue(priv->workqueue); |
| 11207 | priv->workqueue = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11208 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11209 | /* Free MAC hash list for ADHOC */ |
| 11210 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { |
| 11211 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11212 | list_del(p); |
Zhu Yi | 489f445 | 2006-01-24 16:37:41 +0800 | [diff] [blame] | 11213 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11214 | } |
| 11215 | } |
| 11216 | |
James Ketrenos | b39860c | 2005-08-12 09:36:32 -0500 | [diff] [blame] | 11217 | if (priv->error) { |
| 11218 | ipw_free_error_log(priv->error); |
| 11219 | priv->error = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11220 | } |
| 11221 | |
| 11222 | free_irq(pdev->irq, priv); |
| 11223 | iounmap(priv->hw_base); |
| 11224 | pci_release_regions(pdev); |
| 11225 | pci_disable_device(pdev); |
| 11226 | pci_set_drvdata(pdev, NULL); |
| 11227 | free_ieee80211(priv->net_dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11228 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11229 | } |
| 11230 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11231 | #ifdef CONFIG_PM |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11232 | 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] | 11233 | { |
| 11234 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11235 | struct net_device *dev = priv->net_dev; |
| 11236 | |
| 11237 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); |
| 11238 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11239 | /* Take down the device; powers it off, etc. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11240 | ipw_down(priv); |
| 11241 | |
| 11242 | /* Remove the PRESENT state of the device */ |
| 11243 | netif_device_detach(dev); |
| 11244 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11245 | pci_save_state(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11246 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11247 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11248 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11249 | return 0; |
| 11250 | } |
| 11251 | |
| 11252 | static int ipw_pci_resume(struct pci_dev *pdev) |
| 11253 | { |
| 11254 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11255 | struct net_device *dev = priv->net_dev; |
| 11256 | u32 val; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11257 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11258 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
| 11259 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11260 | pci_set_power_state(pdev, PCI_D0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11261 | pci_enable_device(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11262 | pci_restore_state(pdev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11263 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11264 | /* |
| 11265 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 11266 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 11267 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 11268 | * here since it only restores the first 64 bytes pci config header. |
| 11269 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11270 | pci_read_config_dword(pdev, 0x40, &val); |
| 11271 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11272 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 11273 | |
| 11274 | /* Set the device back into the PRESENT state; this will also wake |
| 11275 | * the queue of needed */ |
| 11276 | netif_device_attach(dev); |
| 11277 | |
| 11278 | /* Bring the device back up */ |
| 11279 | queue_work(priv->workqueue, &priv->up); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11280 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11281 | return 0; |
| 11282 | } |
| 11283 | #endif |
| 11284 | |
| 11285 | /* driver initialization stuff */ |
| 11286 | static struct pci_driver ipw_driver = { |
| 11287 | .name = DRV_NAME, |
| 11288 | .id_table = card_ids, |
| 11289 | .probe = ipw_pci_probe, |
| 11290 | .remove = __devexit_p(ipw_pci_remove), |
| 11291 | #ifdef CONFIG_PM |
| 11292 | .suspend = ipw_pci_suspend, |
| 11293 | .resume = ipw_pci_resume, |
| 11294 | #endif |
| 11295 | }; |
| 11296 | |
| 11297 | static int __init ipw_init(void) |
| 11298 | { |
| 11299 | int ret; |
| 11300 | |
| 11301 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 11302 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 11303 | |
| 11304 | ret = pci_module_init(&ipw_driver); |
| 11305 | if (ret) { |
| 11306 | IPW_ERROR("Unable to initialize PCI module\n"); |
| 11307 | return ret; |
| 11308 | } |
| 11309 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11310 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11311 | if (ret) { |
| 11312 | IPW_ERROR("Unable to create driver sysfs file\n"); |
| 11313 | pci_unregister_driver(&ipw_driver); |
| 11314 | return ret; |
| 11315 | } |
| 11316 | |
| 11317 | return ret; |
| 11318 | } |
| 11319 | |
| 11320 | static void __exit ipw_exit(void) |
| 11321 | { |
| 11322 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); |
| 11323 | pci_unregister_driver(&ipw_driver); |
| 11324 | } |
| 11325 | |
| 11326 | module_param(disable, int, 0444); |
| 11327 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 11328 | |
| 11329 | module_param(associate, int, 0444); |
| 11330 | MODULE_PARM_DESC(associate, "auto associate when scanning (default on)"); |
| 11331 | |
| 11332 | module_param(auto_create, int, 0444); |
| 11333 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); |
| 11334 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11335 | module_param(led, int, 0444); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11336 | 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] | 11337 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11338 | module_param(debug, int, 0444); |
| 11339 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 11340 | |
| 11341 | module_param(channel, int, 0444); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11342 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11343 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11344 | #ifdef CONFIG_IPW_QOS |
| 11345 | module_param(qos_enable, int, 0444); |
| 11346 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11347 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11348 | module_param(qos_burst_enable, int, 0444); |
| 11349 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); |
| 11350 | |
| 11351 | module_param(qos_no_ack_mask, int, 0444); |
| 11352 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); |
| 11353 | |
| 11354 | module_param(burst_duration_CCK, int, 0444); |
| 11355 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); |
| 11356 | |
| 11357 | module_param(burst_duration_OFDM, int, 0444); |
| 11358 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); |
| 11359 | #endif /* CONFIG_IPW_QOS */ |
| 11360 | |
| 11361 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11362 | module_param(mode, int, 0444); |
| 11363 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); |
| 11364 | #else |
| 11365 | module_param(mode, int, 0444); |
| 11366 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
| 11367 | #endif |
| 11368 | |
Zhu Yi | 810dabd | 2006-01-24 16:36:59 +0800 | [diff] [blame^] | 11369 | module_param(bt_coexist, int, 0444); |
| 11370 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); |
| 11371 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11372 | module_param(hwcrypto, int, 0444); |
| 11373 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)"); |
| 11374 | |
James Ketrenos | f6c5cb7 | 2005-08-25 00:39:09 -0500 | [diff] [blame] | 11375 | module_param(cmdlog, int, 0444); |
| 11376 | MODULE_PARM_DESC(cmdlog, |
| 11377 | "allocate a ring buffer for logging firmware commands"); |
| 11378 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11379 | module_exit(ipw_exit); |
| 11380 | module_init(ipw_init); |