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" |
| 34 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 35 | #define IPW2200_VERSION "1.0.5" |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 36 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 37 | #define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation" |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 38 | #define DRV_VERSION IPW2200_VERSION |
| 39 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 40 | #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1) |
| 41 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 42 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 43 | MODULE_VERSION(DRV_VERSION); |
| 44 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 45 | MODULE_LICENSE("GPL"); |
| 46 | |
| 47 | static int debug = 0; |
| 48 | static int channel = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 49 | static int mode = 0; |
| 50 | |
| 51 | static u32 ipw_debug_level; |
| 52 | static int associate = 1; |
| 53 | static int auto_create = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 54 | static int led = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 55 | static int disable = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 56 | static int hwcrypto = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 57 | static const char ipw_modes[] = { |
| 58 | 'a', 'b', 'g', '?' |
| 59 | }; |
| 60 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 61 | #ifdef CONFIG_IPW_QOS |
| 62 | static int qos_enable = 0; |
| 63 | static int qos_burst_enable = 0; |
| 64 | static int qos_no_ack_mask = 0; |
| 65 | static int burst_duration_CCK = 0; |
| 66 | static int burst_duration_OFDM = 0; |
| 67 | |
| 68 | static struct ieee80211_qos_parameters def_qos_parameters_OFDM = { |
| 69 | {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, |
| 70 | QOS_TX3_CW_MIN_OFDM}, |
| 71 | {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, |
| 72 | QOS_TX3_CW_MAX_OFDM}, |
| 73 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 74 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 75 | {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, |
| 76 | QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} |
| 77 | }; |
| 78 | |
| 79 | static struct ieee80211_qos_parameters def_qos_parameters_CCK = { |
| 80 | {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, |
| 81 | QOS_TX3_CW_MIN_CCK}, |
| 82 | {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, |
| 83 | QOS_TX3_CW_MAX_CCK}, |
| 84 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, |
| 85 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, |
| 86 | {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, |
| 87 | QOS_TX3_TXOP_LIMIT_CCK} |
| 88 | }; |
| 89 | |
| 90 | static struct ieee80211_qos_parameters def_parameters_OFDM = { |
| 91 | {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, |
| 92 | DEF_TX3_CW_MIN_OFDM}, |
| 93 | {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, |
| 94 | DEF_TX3_CW_MAX_OFDM}, |
| 95 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 96 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 97 | {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, |
| 98 | DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} |
| 99 | }; |
| 100 | |
| 101 | static struct ieee80211_qos_parameters def_parameters_CCK = { |
| 102 | {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, |
| 103 | DEF_TX3_CW_MIN_CCK}, |
| 104 | {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, |
| 105 | DEF_TX3_CW_MAX_CCK}, |
| 106 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, |
| 107 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, |
| 108 | {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, |
| 109 | DEF_TX3_TXOP_LIMIT_CCK} |
| 110 | }; |
| 111 | |
| 112 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; |
| 113 | |
| 114 | static int from_priority_to_tx_queue[] = { |
| 115 | IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, |
| 116 | IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 |
| 117 | }; |
| 118 | |
| 119 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); |
| 120 | |
| 121 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
| 122 | *qos_param); |
| 123 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element |
| 124 | *qos_param); |
| 125 | #endif /* CONFIG_IPW_QOS */ |
| 126 | |
| 127 | static void ipw_remove_current_network(struct ipw_priv *priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 128 | static void ipw_rx(struct ipw_priv *priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 129 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 130 | struct clx2_tx_queue *txq, int qindex); |
| 131 | static int ipw_queue_reset(struct ipw_priv *priv); |
| 132 | |
| 133 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 134 | int len, int sync); |
| 135 | |
| 136 | static void ipw_tx_queue_free(struct ipw_priv *); |
| 137 | |
| 138 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); |
| 139 | static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); |
| 140 | static void ipw_rx_queue_replenish(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 141 | static int ipw_up(struct ipw_priv *); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 142 | static void ipw_bg_up(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 143 | static void ipw_down(struct ipw_priv *); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 144 | static void ipw_bg_down(void *); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 145 | static int ipw_config(struct ipw_priv *); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 146 | static int init_supported_rates(struct ipw_priv *priv, |
| 147 | struct ipw_supported_rates *prates); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 148 | static void ipw_set_hwcrypto_keys(struct ipw_priv *); |
| 149 | static void ipw_send_wep_keys(struct ipw_priv *, int); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 150 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 151 | static char *snprint_line(char *buf, size_t count, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 152 | const u8 * data, u32 len, u32 ofs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 153 | { |
| 154 | int out, i, j, l; |
| 155 | char c; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 156 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 157 | out = snprintf(buf, count, "%08X", ofs); |
| 158 | |
| 159 | for (l = 0, i = 0; i < 2; i++) { |
| 160 | out += snprintf(buf + out, count - out, " "); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 161 | for (j = 0; j < 8 && l < len; j++, l++) |
| 162 | out += snprintf(buf + out, count - out, "%02X ", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 163 | data[(i * 8 + j)]); |
| 164 | for (; j < 8; j++) |
| 165 | out += snprintf(buf + out, count - out, " "); |
| 166 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 167 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 168 | out += snprintf(buf + out, count - out, " "); |
| 169 | for (l = 0, i = 0; i < 2; i++) { |
| 170 | out += snprintf(buf + out, count - out, " "); |
| 171 | for (j = 0; j < 8 && l < len; j++, l++) { |
| 172 | c = data[(i * 8 + j)]; |
| 173 | if (!isascii(c) || !isprint(c)) |
| 174 | c = '.'; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 175 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 176 | out += snprintf(buf + out, count - out, "%c", c); |
| 177 | } |
| 178 | |
| 179 | for (; j < 8; j++) |
| 180 | out += snprintf(buf + out, count - out, " "); |
| 181 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 182 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 183 | return buf; |
| 184 | } |
| 185 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 186 | static void printk_buf(int level, const u8 * data, u32 len) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 187 | { |
| 188 | char line[81]; |
| 189 | u32 ofs = 0; |
| 190 | if (!(ipw_debug_level & level)) |
| 191 | return; |
| 192 | |
| 193 | while (len) { |
| 194 | printk(KERN_DEBUG "%s\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 195 | snprint_line(line, sizeof(line), &data[ofs], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 196 | min(len, 16U), ofs)); |
| 197 | ofs += 16; |
| 198 | len -= min(len, 16U); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); |
| 203 | #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) |
| 204 | |
| 205 | static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); |
| 206 | #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) |
| 207 | |
| 208 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); |
| 209 | static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) |
| 210 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 211 | IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, |
| 212 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 213 | _ipw_write_reg8(a, b, c); |
| 214 | } |
| 215 | |
| 216 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); |
| 217 | static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) |
| 218 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 219 | IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, |
| 220 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 221 | _ipw_write_reg16(a, b, c); |
| 222 | } |
| 223 | |
| 224 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); |
| 225 | static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) |
| 226 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 227 | IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, |
| 228 | __LINE__, (u32) (b), (u32) (c)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 229 | _ipw_write_reg32(a, b, c); |
| 230 | } |
| 231 | |
| 232 | #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs)) |
| 233 | #define ipw_write8(ipw, ofs, val) \ |
| 234 | IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 235 | _ipw_write8(ipw, ofs, val) |
| 236 | |
| 237 | #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs)) |
| 238 | #define ipw_write16(ipw, ofs, val) \ |
| 239 | IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 240 | _ipw_write16(ipw, ofs, val) |
| 241 | |
| 242 | #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs)) |
| 243 | #define ipw_write32(ipw, ofs, val) \ |
| 244 | IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ |
| 245 | _ipw_write32(ipw, ofs, val) |
| 246 | |
| 247 | #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 248 | static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 249 | { |
| 250 | 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] | 251 | return _ipw_read8(ipw, ofs); |
| 252 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 253 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 254 | #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs) |
| 255 | |
| 256 | #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 257 | static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 258 | { |
| 259 | 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] | 260 | return _ipw_read16(ipw, ofs); |
| 261 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 262 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 263 | #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs) |
| 264 | |
| 265 | #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 266 | static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
| 267 | { |
| 268 | 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] | 269 | return _ipw_read32(ipw, ofs); |
| 270 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 271 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 272 | #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs) |
| 273 | |
| 274 | static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); |
| 275 | #define ipw_read_indirect(a, b, c, d) \ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 276 | IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 277 | _ipw_read_indirect(a, b, c, d) |
| 278 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 279 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, |
| 280 | int num); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 281 | #define ipw_write_indirect(a, b, c, d) \ |
| 282 | 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] | 283 | _ipw_write_indirect(a, b, c, d) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 284 | |
| 285 | /* indirect write s */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 286 | 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] | 287 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 288 | 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] | 289 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 290 | _ipw_write32(priv, IPW_INDIRECT_DATA, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 291 | } |
| 292 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 293 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) |
| 294 | { |
| 295 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 296 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
| 297 | _ipw_write8(priv, IPW_INDIRECT_DATA, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 298 | } |
| 299 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 300 | 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] | 301 | { |
| 302 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 303 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
| 304 | _ipw_write16(priv, IPW_INDIRECT_DATA, value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /* indirect read s */ |
| 308 | |
| 309 | static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) |
| 310 | { |
| 311 | u32 word; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 312 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 313 | IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 314 | word = _ipw_read32(priv, IPW_INDIRECT_DATA); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 315 | return (word >> ((reg & 0x3) * 8)) & 0xff; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) |
| 319 | { |
| 320 | u32 value; |
| 321 | |
| 322 | IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); |
| 323 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 324 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
| 325 | value = _ipw_read32(priv, IPW_INDIRECT_DATA); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 326 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); |
| 327 | return value; |
| 328 | } |
| 329 | |
| 330 | /* iterative/auto-increment 32 bit reads and writes */ |
| 331 | static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
| 332 | int num) |
| 333 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 334 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 335 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 336 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 337 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 338 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
| 339 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 340 | if (num <= 0) { |
| 341 | return; |
| 342 | } |
| 343 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 344 | /* Read the first nibble byte by byte */ |
| 345 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 346 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 347 | /* Start reading at aligned_addr + dif_len */ |
| 348 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 349 | *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 350 | aligned_addr += 4; |
| 351 | } |
| 352 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 353 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 354 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 355 | *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 356 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 357 | /* Copy the last nibble */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 358 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 359 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 360 | for (i = 0; num > 0; i++, num--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 361 | *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 362 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 363 | } |
| 364 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 365 | 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] | 366 | int num) |
| 367 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 368 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 369 | u32 dif_len = addr - aligned_addr; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 370 | u32 i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 371 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 372 | 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] | 373 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 374 | if (num <= 0) { |
| 375 | return; |
| 376 | } |
| 377 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 378 | /* Write the first nibble byte by byte */ |
| 379 | if (unlikely(dif_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 380 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 381 | /* Start reading at aligned_addr + dif_len */ |
| 382 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 383 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 384 | aligned_addr += 4; |
| 385 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 386 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 387 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 388 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 389 | _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 390 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 391 | /* Copy the last nibble */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 392 | if (unlikely(num)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 393 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 394 | for (i = 0; num > 0; i++, num--, buf++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 395 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 396 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 397 | } |
| 398 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 399 | 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] | 400 | int num) |
| 401 | { |
| 402 | memcpy_toio((priv->hw_base + addr), buf, num); |
| 403 | } |
| 404 | |
| 405 | static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 406 | { |
| 407 | ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); |
| 408 | } |
| 409 | |
| 410 | static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
| 411 | { |
| 412 | ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); |
| 413 | } |
| 414 | |
| 415 | static inline void ipw_enable_interrupts(struct ipw_priv *priv) |
| 416 | { |
| 417 | if (priv->status & STATUS_INT_ENABLED) |
| 418 | return; |
| 419 | priv->status |= STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 420 | ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static inline void ipw_disable_interrupts(struct ipw_priv *priv) |
| 424 | { |
| 425 | if (!(priv->status & STATUS_INT_ENABLED)) |
| 426 | return; |
| 427 | priv->status &= ~STATUS_INT_ENABLED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 428 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static char *ipw_error_desc(u32 val) |
| 432 | { |
| 433 | switch (val) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 434 | case IPW_FW_ERROR_OK: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 435 | return "ERROR_OK"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 436 | case IPW_FW_ERROR_FAIL: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 437 | return "ERROR_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 438 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 439 | return "MEMORY_UNDERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 440 | case IPW_FW_ERROR_MEMORY_OVERFLOW: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 441 | return "MEMORY_OVERFLOW"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 442 | case IPW_FW_ERROR_BAD_PARAM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 443 | return "BAD_PARAM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 444 | case IPW_FW_ERROR_BAD_CHECKSUM: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 445 | return "BAD_CHECKSUM"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 446 | case IPW_FW_ERROR_NMI_INTERRUPT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 447 | return "NMI_INTERRUPT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 448 | case IPW_FW_ERROR_BAD_DATABASE: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 449 | return "BAD_DATABASE"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 450 | case IPW_FW_ERROR_ALLOC_FAIL: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 451 | return "ALLOC_FAIL"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 452 | case IPW_FW_ERROR_DMA_UNDERRUN: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 453 | return "DMA_UNDERRUN"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 454 | case IPW_FW_ERROR_DMA_STATUS: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 455 | return "DMA_STATUS"; |
| 456 | case IPW_FW_ERROR_DINO_ERROR: |
| 457 | return "DINO_ERROR"; |
| 458 | case IPW_FW_ERROR_EEPROM_ERROR: |
| 459 | return "EEPROM_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 460 | case IPW_FW_ERROR_SYSASSERT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 461 | return "SYSASSERT"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 462 | case IPW_FW_ERROR_FATAL_ERROR: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 463 | return "FATAL_ERROR"; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 464 | default: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 465 | return "UNKNOWN_ERROR"; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
| 469 | static void ipw_dump_nic_error_log(struct ipw_priv *priv) |
| 470 | { |
| 471 | u32 desc, time, blink1, blink2, ilink1, ilink2, idata, i, count, base; |
| 472 | |
| 473 | base = ipw_read32(priv, IPWSTATUS_ERROR_LOG); |
| 474 | count = ipw_read_reg32(priv, base); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 475 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 476 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 477 | IPW_ERROR("Start IPW Error Log Dump:\n"); |
| 478 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", |
| 479 | priv->status, priv->config); |
| 480 | } |
| 481 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 482 | for (i = ERROR_START_OFFSET; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 483 | i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) { |
| 484 | desc = ipw_read_reg32(priv, base + i); |
| 485 | time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32)); |
| 486 | blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32)); |
| 487 | blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32)); |
| 488 | ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32)); |
| 489 | ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32)); |
| 490 | idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 491 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 492 | IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", |
| 493 | ipw_error_desc(desc), time, blink1, blink2, |
| 494 | ilink1, ilink2, idata); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
| 498 | static void ipw_dump_nic_event_log(struct ipw_priv *priv) |
| 499 | { |
| 500 | u32 ev, time, data, i, count, base; |
| 501 | |
| 502 | base = ipw_read32(priv, IPW_EVENT_LOG); |
| 503 | count = ipw_read_reg32(priv, base); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 504 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 505 | if (EVENT_START_OFFSET <= count * EVENT_ELEM_SIZE) |
| 506 | IPW_ERROR("Start IPW Event Log Dump:\n"); |
| 507 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 508 | for (i = EVENT_START_OFFSET; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 509 | i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 510 | ev = ipw_read_reg32(priv, base + i); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 511 | time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32)); |
| 512 | data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 513 | |
| 514 | #ifdef CONFIG_IPW_DEBUG |
| 515 | IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev); |
| 516 | #endif |
| 517 | } |
| 518 | } |
| 519 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 520 | static inline int ipw_is_init(struct ipw_priv *priv) |
| 521 | { |
| 522 | return (priv->status & STATUS_INIT) ? 1 : 0; |
| 523 | } |
| 524 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 525 | 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] | 526 | { |
| 527 | u32 addr, field_info, field_len, field_count, total_len; |
| 528 | |
| 529 | IPW_DEBUG_ORD("ordinal = %i\n", ord); |
| 530 | |
| 531 | if (!priv || !val || !len) { |
| 532 | IPW_DEBUG_ORD("Invalid argument\n"); |
| 533 | return -EINVAL; |
| 534 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 535 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 536 | /* verify device ordinal tables have been initialized */ |
| 537 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { |
| 538 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); |
| 539 | return -EINVAL; |
| 540 | } |
| 541 | |
| 542 | switch (IPW_ORD_TABLE_ID_MASK & ord) { |
| 543 | case IPW_ORD_TABLE_0_MASK: |
| 544 | /* |
| 545 | * TABLE 0: Direct access to a table of 32 bit values |
| 546 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 547 | * This is a very simple table with the data directly |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 548 | * read from the table |
| 549 | */ |
| 550 | |
| 551 | /* remove the table id from the ordinal */ |
| 552 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 553 | |
| 554 | /* boundary check */ |
| 555 | if (ord > priv->table0_len) { |
| 556 | IPW_DEBUG_ORD("ordinal value (%i) longer then " |
| 557 | "max (%i)\n", ord, priv->table0_len); |
| 558 | return -EINVAL; |
| 559 | } |
| 560 | |
| 561 | /* verify we have enough room to store the value */ |
| 562 | if (*len < sizeof(u32)) { |
| 563 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 564 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 565 | return -EINVAL; |
| 566 | } |
| 567 | |
| 568 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 569 | ord, priv->table0_addr + (ord << 2)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 570 | |
| 571 | *len = sizeof(u32); |
| 572 | ord <<= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 573 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 574 | break; |
| 575 | |
| 576 | case IPW_ORD_TABLE_1_MASK: |
| 577 | /* |
| 578 | * TABLE 1: Indirect access to a table of 32 bit values |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 579 | * |
| 580 | * This is a fairly large table of u32 values each |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 581 | * representing starting addr for the data (which is |
| 582 | * also a u32) |
| 583 | */ |
| 584 | |
| 585 | /* remove the table id from the ordinal */ |
| 586 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 587 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 588 | /* boundary check */ |
| 589 | if (ord > priv->table1_len) { |
| 590 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 591 | return -EINVAL; |
| 592 | } |
| 593 | |
| 594 | /* verify we have enough room to store the value */ |
| 595 | if (*len < sizeof(u32)) { |
| 596 | IPW_DEBUG_ORD("ordinal buffer length too small, " |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 597 | "need %zd\n", sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 598 | return -EINVAL; |
| 599 | } |
| 600 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 601 | *((u32 *) val) = |
| 602 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 603 | *len = sizeof(u32); |
| 604 | break; |
| 605 | |
| 606 | case IPW_ORD_TABLE_2_MASK: |
| 607 | /* |
| 608 | * TABLE 2: Indirect access to a table of variable sized values |
| 609 | * |
| 610 | * This table consist of six values, each containing |
| 611 | * - dword containing the starting offset of the data |
| 612 | * - dword containing the lengh in the first 16bits |
| 613 | * and the count in the second 16bits |
| 614 | */ |
| 615 | |
| 616 | /* remove the table id from the ordinal */ |
| 617 | ord &= IPW_ORD_TABLE_VALUE_MASK; |
| 618 | |
| 619 | /* boundary check */ |
| 620 | if (ord > priv->table2_len) { |
| 621 | IPW_DEBUG_ORD("ordinal value too long\n"); |
| 622 | return -EINVAL; |
| 623 | } |
| 624 | |
| 625 | /* get the address of statistic */ |
| 626 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 627 | |
| 628 | /* get the second DW of statistics ; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 629 | * two 16-bit words - first is length, second is count */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 630 | field_info = |
| 631 | ipw_read_reg32(priv, |
| 632 | priv->table2_addr + (ord << 3) + |
| 633 | sizeof(u32)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 634 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 635 | /* get each entry length */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 636 | field_len = *((u16 *) & field_info); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 637 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 638 | /* get number of entries */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 639 | field_count = *(((u16 *) & field_info) + 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 640 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 641 | /* abort if not enought memory */ |
| 642 | total_len = field_len * field_count; |
| 643 | if (total_len > *len) { |
| 644 | *len = total_len; |
| 645 | return -EINVAL; |
| 646 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 647 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 648 | *len = total_len; |
| 649 | if (!total_len) |
| 650 | return 0; |
| 651 | |
| 652 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 653 | "field_info = 0x%08x\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 654 | addr, total_len, field_info); |
| 655 | ipw_read_indirect(priv, addr, val, total_len); |
| 656 | break; |
| 657 | |
| 658 | default: |
| 659 | IPW_DEBUG_ORD("Invalid ordinal!\n"); |
| 660 | return -EINVAL; |
| 661 | |
| 662 | } |
| 663 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static void ipw_init_ordinals(struct ipw_priv *priv) |
| 668 | { |
| 669 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 670 | priv->table0_len = ipw_read32(priv, priv->table0_addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 671 | |
| 672 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", |
| 673 | priv->table0_addr, priv->table0_len); |
| 674 | |
| 675 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); |
| 676 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); |
| 677 | |
| 678 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", |
| 679 | priv->table1_addr, priv->table1_len); |
| 680 | |
| 681 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); |
| 682 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 683 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 684 | |
| 685 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", |
| 686 | priv->table2_addr, priv->table2_len); |
| 687 | |
| 688 | } |
| 689 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 690 | u32 ipw_register_toggle(u32 reg) |
| 691 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 692 | reg &= ~IPW_START_STANDBY; |
| 693 | if (reg & IPW_GATE_ODMA) |
| 694 | reg &= ~IPW_GATE_ODMA; |
| 695 | if (reg & IPW_GATE_IDMA) |
| 696 | reg &= ~IPW_GATE_IDMA; |
| 697 | if (reg & IPW_GATE_ADMA) |
| 698 | reg &= ~IPW_GATE_ADMA; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 699 | return reg; |
| 700 | } |
| 701 | |
| 702 | /* |
| 703 | * LED behavior: |
| 704 | * - On radio ON, turn on any LEDs that require to be on during start |
| 705 | * - On initialization, start unassociated blink |
| 706 | * - On association, disable unassociated blink |
| 707 | * - On disassociation, start unassociated blink |
| 708 | * - On radio OFF, turn off any LEDs started during radio on |
| 709 | * |
| 710 | */ |
| 711 | #define LD_TIME_LINK_ON 300 |
| 712 | #define LD_TIME_LINK_OFF 2700 |
| 713 | #define LD_TIME_ACT_ON 250 |
| 714 | |
| 715 | void ipw_led_link_on(struct ipw_priv *priv) |
| 716 | { |
| 717 | unsigned long flags; |
| 718 | u32 led; |
| 719 | |
| 720 | /* If configured to not use LEDs, or nic_type is 1, |
| 721 | * then we don't toggle a LINK led */ |
| 722 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 723 | return; |
| 724 | |
| 725 | spin_lock_irqsave(&priv->lock, flags); |
| 726 | |
| 727 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 728 | !(priv->status & STATUS_LED_LINK_ON)) { |
| 729 | IPW_DEBUG_LED("Link LED On\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 730 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 731 | led |= priv->led_association_on; |
| 732 | |
| 733 | led = ipw_register_toggle(led); |
| 734 | |
| 735 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 736 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 737 | |
| 738 | priv->status |= STATUS_LED_LINK_ON; |
| 739 | |
| 740 | /* If we aren't associated, schedule turning the LED off */ |
| 741 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 742 | queue_delayed_work(priv->workqueue, |
| 743 | &priv->led_link_off, |
| 744 | LD_TIME_LINK_ON); |
| 745 | } |
| 746 | |
| 747 | spin_unlock_irqrestore(&priv->lock, flags); |
| 748 | } |
| 749 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 750 | static void ipw_bg_led_link_on(void *data) |
| 751 | { |
| 752 | struct ipw_priv *priv = data; |
| 753 | down(&priv->sem); |
| 754 | ipw_led_link_on(data); |
| 755 | up(&priv->sem); |
| 756 | } |
| 757 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 758 | void ipw_led_link_off(struct ipw_priv *priv) |
| 759 | { |
| 760 | unsigned long flags; |
| 761 | u32 led; |
| 762 | |
| 763 | /* If configured not to use LEDs, or nic type is 1, |
| 764 | * then we don't goggle the LINK led. */ |
| 765 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) |
| 766 | return; |
| 767 | |
| 768 | spin_lock_irqsave(&priv->lock, flags); |
| 769 | |
| 770 | if (priv->status & STATUS_LED_LINK_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 771 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 772 | led &= priv->led_association_off; |
| 773 | led = ipw_register_toggle(led); |
| 774 | |
| 775 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 776 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 777 | |
| 778 | IPW_DEBUG_LED("Link LED Off\n"); |
| 779 | |
| 780 | priv->status &= ~STATUS_LED_LINK_ON; |
| 781 | |
| 782 | /* If we aren't associated and the radio is on, schedule |
| 783 | * turning the LED on (blink while unassociated) */ |
| 784 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 785 | !(priv->status & STATUS_ASSOCIATED)) |
| 786 | queue_delayed_work(priv->workqueue, &priv->led_link_on, |
| 787 | LD_TIME_LINK_OFF); |
| 788 | |
| 789 | } |
| 790 | |
| 791 | spin_unlock_irqrestore(&priv->lock, flags); |
| 792 | } |
| 793 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 794 | static void ipw_bg_led_link_off(void *data) |
| 795 | { |
| 796 | struct ipw_priv *priv = data; |
| 797 | down(&priv->sem); |
| 798 | ipw_led_link_off(data); |
| 799 | up(&priv->sem); |
| 800 | } |
| 801 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 802 | static inline void __ipw_led_activity_on(struct ipw_priv *priv) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 803 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 804 | u32 led; |
| 805 | |
| 806 | if (priv->config & CFG_NO_LED) |
| 807 | return; |
| 808 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 809 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 810 | return; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 811 | |
| 812 | if (!(priv->status & STATUS_LED_ACT_ON)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 813 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 814 | led |= priv->led_activity_on; |
| 815 | |
| 816 | led = ipw_register_toggle(led); |
| 817 | |
| 818 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 819 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 820 | |
| 821 | IPW_DEBUG_LED("Activity LED On\n"); |
| 822 | |
| 823 | priv->status |= STATUS_LED_ACT_ON; |
| 824 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 825 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 826 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 827 | LD_TIME_ACT_ON); |
| 828 | } else { |
| 829 | /* Reschedule LED off for full time period */ |
| 830 | cancel_delayed_work(&priv->led_act_off); |
| 831 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
| 832 | LD_TIME_ACT_ON); |
| 833 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 834 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 835 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 836 | void ipw_led_activity_on(struct ipw_priv *priv) |
| 837 | { |
| 838 | unsigned long flags; |
| 839 | spin_lock_irqsave(&priv->lock, flags); |
| 840 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 841 | spin_unlock_irqrestore(&priv->lock, flags); |
| 842 | } |
| 843 | |
| 844 | void ipw_led_activity_off(struct ipw_priv *priv) |
| 845 | { |
| 846 | unsigned long flags; |
| 847 | u32 led; |
| 848 | |
| 849 | if (priv->config & CFG_NO_LED) |
| 850 | return; |
| 851 | |
| 852 | spin_lock_irqsave(&priv->lock, flags); |
| 853 | |
| 854 | if (priv->status & STATUS_LED_ACT_ON) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 855 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 856 | led &= priv->led_activity_off; |
| 857 | |
| 858 | led = ipw_register_toggle(led); |
| 859 | |
| 860 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 861 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 862 | |
| 863 | IPW_DEBUG_LED("Activity LED Off\n"); |
| 864 | |
| 865 | priv->status &= ~STATUS_LED_ACT_ON; |
| 866 | } |
| 867 | |
| 868 | spin_unlock_irqrestore(&priv->lock, flags); |
| 869 | } |
| 870 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 871 | static void ipw_bg_led_activity_off(void *data) |
| 872 | { |
| 873 | struct ipw_priv *priv = data; |
| 874 | down(&priv->sem); |
| 875 | ipw_led_activity_off(data); |
| 876 | up(&priv->sem); |
| 877 | } |
| 878 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 879 | void ipw_led_band_on(struct ipw_priv *priv) |
| 880 | { |
| 881 | unsigned long flags; |
| 882 | u32 led; |
| 883 | |
| 884 | /* Only nic type 1 supports mode LEDs */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 885 | if (priv->config & CFG_NO_LED || |
| 886 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 887 | return; |
| 888 | |
| 889 | spin_lock_irqsave(&priv->lock, flags); |
| 890 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 891 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 892 | if (priv->assoc_network->mode == IEEE_A) { |
| 893 | led |= priv->led_ofdm_on; |
| 894 | led &= priv->led_association_off; |
| 895 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); |
| 896 | } else if (priv->assoc_network->mode == IEEE_G) { |
| 897 | led |= priv->led_ofdm_on; |
| 898 | led |= priv->led_association_on; |
| 899 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); |
| 900 | } else { |
| 901 | led &= priv->led_ofdm_off; |
| 902 | led |= priv->led_association_on; |
| 903 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); |
| 904 | } |
| 905 | |
| 906 | led = ipw_register_toggle(led); |
| 907 | |
| 908 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 909 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 910 | |
| 911 | spin_unlock_irqrestore(&priv->lock, flags); |
| 912 | } |
| 913 | |
| 914 | void ipw_led_band_off(struct ipw_priv *priv) |
| 915 | { |
| 916 | unsigned long flags; |
| 917 | u32 led; |
| 918 | |
| 919 | /* Only nic type 1 supports mode LEDs */ |
| 920 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) |
| 921 | return; |
| 922 | |
| 923 | spin_lock_irqsave(&priv->lock, flags); |
| 924 | |
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_ofdm_off; |
| 927 | led &= priv->led_association_off; |
| 928 | |
| 929 | led = ipw_register_toggle(led); |
| 930 | |
| 931 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 932 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 933 | |
| 934 | spin_unlock_irqrestore(&priv->lock, flags); |
| 935 | } |
| 936 | |
| 937 | void ipw_led_radio_on(struct ipw_priv *priv) |
| 938 | { |
| 939 | ipw_led_link_on(priv); |
| 940 | } |
| 941 | |
| 942 | void ipw_led_radio_off(struct ipw_priv *priv) |
| 943 | { |
| 944 | ipw_led_activity_off(priv); |
| 945 | ipw_led_link_off(priv); |
| 946 | } |
| 947 | |
| 948 | void ipw_led_link_up(struct ipw_priv *priv) |
| 949 | { |
| 950 | /* Set the Link Led on for all nic types */ |
| 951 | ipw_led_link_on(priv); |
| 952 | } |
| 953 | |
| 954 | void ipw_led_link_down(struct ipw_priv *priv) |
| 955 | { |
| 956 | ipw_led_activity_off(priv); |
| 957 | ipw_led_link_off(priv); |
| 958 | |
| 959 | if (priv->status & STATUS_RF_KILL_MASK) |
| 960 | ipw_led_radio_off(priv); |
| 961 | } |
| 962 | |
| 963 | void ipw_led_init(struct ipw_priv *priv) |
| 964 | { |
| 965 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; |
| 966 | |
| 967 | /* Set the default PINs for the link and activity leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 968 | priv->led_activity_on = IPW_ACTIVITY_LED; |
| 969 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 970 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 971 | priv->led_association_on = IPW_ASSOCIATED_LED; |
| 972 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 973 | |
| 974 | /* Set the default PINs for the OFDM leds */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 975 | priv->led_ofdm_on = IPW_OFDM_LED; |
| 976 | priv->led_ofdm_off = ~(IPW_OFDM_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 977 | |
| 978 | switch (priv->nic_type) { |
| 979 | case EEPROM_NIC_TYPE_1: |
| 980 | /* In this NIC type, the LEDs are reversed.... */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 981 | priv->led_activity_on = IPW_ASSOCIATED_LED; |
| 982 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); |
| 983 | priv->led_association_on = IPW_ACTIVITY_LED; |
| 984 | priv->led_association_off = ~(IPW_ACTIVITY_LED); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 985 | |
| 986 | if (!(priv->config & CFG_NO_LED)) |
| 987 | ipw_led_band_on(priv); |
| 988 | |
| 989 | /* And we don't blink link LEDs for this nic, so |
| 990 | * just return here */ |
| 991 | return; |
| 992 | |
| 993 | case EEPROM_NIC_TYPE_3: |
| 994 | case EEPROM_NIC_TYPE_2: |
| 995 | case EEPROM_NIC_TYPE_4: |
| 996 | case EEPROM_NIC_TYPE_0: |
| 997 | break; |
| 998 | |
| 999 | default: |
| 1000 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", |
| 1001 | priv->nic_type); |
| 1002 | priv->nic_type = EEPROM_NIC_TYPE_0; |
| 1003 | break; |
| 1004 | } |
| 1005 | |
| 1006 | if (!(priv->config & CFG_NO_LED)) { |
| 1007 | if (priv->status & STATUS_ASSOCIATED) |
| 1008 | ipw_led_link_on(priv); |
| 1009 | else |
| 1010 | ipw_led_link_off(priv); |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | void ipw_led_shutdown(struct ipw_priv *priv) |
| 1015 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1016 | ipw_led_activity_off(priv); |
| 1017 | ipw_led_link_off(priv); |
| 1018 | ipw_led_band_off(priv); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1019 | cancel_delayed_work(&priv->led_link_on); |
| 1020 | cancel_delayed_work(&priv->led_link_off); |
| 1021 | cancel_delayed_work(&priv->led_act_off); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1022 | } |
| 1023 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1024 | /* |
| 1025 | * The following adds a new attribute to the sysfs representation |
| 1026 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) |
| 1027 | * used for controling the debug level. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1028 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1029 | * See the level definitions in ipw for details. |
| 1030 | */ |
| 1031 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 1032 | { |
| 1033 | return sprintf(buf, "0x%08X\n", ipw_debug_level); |
| 1034 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1035 | |
| 1036 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, |
| 1037 | size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1038 | { |
| 1039 | char *p = (char *)buf; |
| 1040 | u32 val; |
| 1041 | |
| 1042 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1043 | p++; |
| 1044 | if (p[0] == 'x' || p[0] == 'X') |
| 1045 | p++; |
| 1046 | val = simple_strtoul(p, &p, 16); |
| 1047 | } else |
| 1048 | val = simple_strtoul(p, &p, 10); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1049 | if (p == buf) |
| 1050 | printk(KERN_INFO DRV_NAME |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1051 | ": %s is not in hex or decimal form.\n", buf); |
| 1052 | else |
| 1053 | ipw_debug_level = val; |
| 1054 | |
| 1055 | return strnlen(buf, count); |
| 1056 | } |
| 1057 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1058 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1059 | show_debug_level, store_debug_level); |
| 1060 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1061 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
| 1062 | char *buf) |
| 1063 | { |
| 1064 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1065 | return sprintf(buf, "%d\n", priv->ieee->scan_age); |
| 1066 | } |
| 1067 | |
| 1068 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, |
| 1069 | const char *buf, size_t count) |
| 1070 | { |
| 1071 | struct ipw_priv *priv = dev_get_drvdata(d); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1072 | #ifdef CONFIG_IPW_DEBUG |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1073 | struct net_device *dev = priv->net_dev; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1074 | #endif |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1075 | char buffer[] = "00000000"; |
| 1076 | unsigned long len = |
| 1077 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; |
| 1078 | unsigned long val; |
| 1079 | char *p = buffer; |
| 1080 | |
| 1081 | IPW_DEBUG_INFO("enter\n"); |
| 1082 | |
| 1083 | strncpy(buffer, buf, len); |
| 1084 | buffer[len] = 0; |
| 1085 | |
| 1086 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { |
| 1087 | p++; |
| 1088 | if (p[0] == 'x' || p[0] == 'X') |
| 1089 | p++; |
| 1090 | val = simple_strtoul(p, &p, 16); |
| 1091 | } else |
| 1092 | val = simple_strtoul(p, &p, 10); |
| 1093 | if (p == buffer) { |
| 1094 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); |
| 1095 | } else { |
| 1096 | priv->ieee->scan_age = val; |
| 1097 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); |
| 1098 | } |
| 1099 | |
| 1100 | IPW_DEBUG_INFO("exit\n"); |
| 1101 | return len; |
| 1102 | } |
| 1103 | |
| 1104 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); |
| 1105 | |
| 1106 | static ssize_t show_led(struct device *d, struct device_attribute *attr, |
| 1107 | char *buf) |
| 1108 | { |
| 1109 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1110 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); |
| 1111 | } |
| 1112 | |
| 1113 | static ssize_t store_led(struct device *d, struct device_attribute *attr, |
| 1114 | const char *buf, size_t count) |
| 1115 | { |
| 1116 | struct ipw_priv *priv = dev_get_drvdata(d); |
| 1117 | |
| 1118 | IPW_DEBUG_INFO("enter\n"); |
| 1119 | |
| 1120 | if (count == 0) |
| 1121 | return 0; |
| 1122 | |
| 1123 | if (*buf == 0) { |
| 1124 | IPW_DEBUG_LED("Disabling LED control.\n"); |
| 1125 | priv->config |= CFG_NO_LED; |
| 1126 | ipw_led_shutdown(priv); |
| 1127 | } else { |
| 1128 | IPW_DEBUG_LED("Enabling LED control.\n"); |
| 1129 | priv->config &= ~CFG_NO_LED; |
| 1130 | ipw_led_init(priv); |
| 1131 | } |
| 1132 | |
| 1133 | IPW_DEBUG_INFO("exit\n"); |
| 1134 | return count; |
| 1135 | } |
| 1136 | |
| 1137 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); |
| 1138 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1139 | static ssize_t show_status(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1140 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1141 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1142 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1143 | return sprintf(buf, "0x%08x\n", (int)p->status); |
| 1144 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1145 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1146 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 1147 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1148 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
| 1149 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1150 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1151 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1152 | return sprintf(buf, "0x%08x\n", (int)p->config); |
| 1153 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1154 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1155 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); |
| 1156 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1157 | static ssize_t show_nic_type(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1158 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1159 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1160 | struct ipw_priv *priv = d->driver_data; |
| 1161 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1162 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1163 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1164 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); |
| 1165 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1166 | static ssize_t dump_error_log(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1167 | struct device_attribute *attr, const char *buf, |
| 1168 | size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1169 | { |
| 1170 | char *p = (char *)buf; |
| 1171 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1172 | if (p[0] == '1') |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1173 | ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1174 | |
| 1175 | return strnlen(buf, count); |
| 1176 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1177 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1178 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 1179 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1180 | static ssize_t dump_event_log(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1181 | struct device_attribute *attr, const char *buf, |
| 1182 | size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1183 | { |
| 1184 | char *p = (char *)buf; |
| 1185 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1186 | if (p[0] == '1') |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1187 | ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1188 | |
| 1189 | return strnlen(buf, count); |
| 1190 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1191 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1192 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 1193 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1194 | static ssize_t show_ucode_version(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1195 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1196 | { |
| 1197 | u32 len = sizeof(u32), tmp = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1198 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1199 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1200 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1201 | return 0; |
| 1202 | |
| 1203 | return sprintf(buf, "0x%08x\n", tmp); |
| 1204 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1205 | |
| 1206 | 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] | 1207 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1208 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, |
| 1209 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1210 | { |
| 1211 | u32 len = sizeof(u32), tmp = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1212 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1213 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1214 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1215 | return 0; |
| 1216 | |
| 1217 | return sprintf(buf, "0x%08x\n", tmp); |
| 1218 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1219 | |
| 1220 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1221 | |
| 1222 | /* |
| 1223 | * Add a device attribute to view/control the delay between eeprom |
| 1224 | * operations. |
| 1225 | */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1226 | static ssize_t show_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1227 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1228 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1229 | int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1230 | return sprintf(buf, "%i\n", n); |
| 1231 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1232 | static ssize_t store_eeprom_delay(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1233 | struct device_attribute *attr, |
| 1234 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1235 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1236 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1237 | sscanf(buf, "%i", &p->eeprom_delay); |
| 1238 | return strnlen(buf, count); |
| 1239 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1240 | |
| 1241 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, |
| 1242 | show_eeprom_delay, store_eeprom_delay); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1243 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1244 | static ssize_t show_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1245 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1246 | { |
| 1247 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1248 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1249 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1250 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1251 | return sprintf(buf, "0x%08x\n", reg); |
| 1252 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1253 | static ssize_t store_command_event_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1254 | struct device_attribute *attr, |
| 1255 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1256 | { |
| 1257 | u32 reg; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1258 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1259 | |
| 1260 | sscanf(buf, "%x", ®); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1261 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1262 | return strnlen(buf, count); |
| 1263 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1264 | |
| 1265 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, |
| 1266 | show_command_event_reg, store_command_event_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1267 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1268 | static ssize_t show_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1269 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1270 | { |
| 1271 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1272 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1273 | |
| 1274 | reg = ipw_read_reg32(p, 0x301100); |
| 1275 | return sprintf(buf, "0x%08x\n", reg); |
| 1276 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1277 | static ssize_t store_mem_gpio_reg(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1278 | struct device_attribute *attr, |
| 1279 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1280 | { |
| 1281 | u32 reg; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1282 | struct ipw_priv *p = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1283 | |
| 1284 | sscanf(buf, "%x", ®); |
| 1285 | ipw_write_reg32(p, 0x301100, reg); |
| 1286 | return strnlen(buf, count); |
| 1287 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1288 | |
| 1289 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, |
| 1290 | show_mem_gpio_reg, store_mem_gpio_reg); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1291 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1292 | static ssize_t show_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1293 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1294 | { |
| 1295 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1296 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1297 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1298 | if (priv->status & STATUS_INDIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1299 | reg = ipw_read_reg32(priv, priv->indirect_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1300 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1301 | reg = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1302 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1303 | return sprintf(buf, "0x%08x\n", reg); |
| 1304 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1305 | static ssize_t store_indirect_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1306 | struct device_attribute *attr, |
| 1307 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1308 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1309 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1310 | |
| 1311 | sscanf(buf, "%x", &priv->indirect_dword); |
| 1312 | priv->status |= STATUS_INDIRECT_DWORD; |
| 1313 | return strnlen(buf, count); |
| 1314 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1315 | |
| 1316 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, |
| 1317 | show_indirect_dword, store_indirect_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1318 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1319 | static ssize_t show_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1320 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1321 | { |
| 1322 | u8 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1323 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1324 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1325 | if (priv->status & STATUS_INDIRECT_BYTE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1326 | reg = ipw_read_reg8(priv, priv->indirect_byte); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1327 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1328 | reg = 0; |
| 1329 | |
| 1330 | return sprintf(buf, "0x%02x\n", reg); |
| 1331 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1332 | static ssize_t store_indirect_byte(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1333 | struct device_attribute *attr, |
| 1334 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1335 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1336 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1337 | |
| 1338 | sscanf(buf, "%x", &priv->indirect_byte); |
| 1339 | priv->status |= STATUS_INDIRECT_BYTE; |
| 1340 | return strnlen(buf, count); |
| 1341 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1342 | |
| 1343 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1344 | show_indirect_byte, store_indirect_byte); |
| 1345 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1346 | static ssize_t show_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1347 | struct device_attribute *attr, char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1348 | { |
| 1349 | u32 reg = 0; |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1350 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1351 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1352 | if (priv->status & STATUS_DIRECT_DWORD) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1353 | reg = ipw_read32(priv, priv->direct_dword); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1354 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1355 | reg = 0; |
| 1356 | |
| 1357 | return sprintf(buf, "0x%08x\n", reg); |
| 1358 | } |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1359 | static ssize_t store_direct_dword(struct device *d, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1360 | struct device_attribute *attr, |
| 1361 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1362 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1363 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1364 | |
| 1365 | sscanf(buf, "%x", &priv->direct_dword); |
| 1366 | priv->status |= STATUS_DIRECT_DWORD; |
| 1367 | return strnlen(buf, count); |
| 1368 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1369 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1370 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, |
| 1371 | show_direct_dword, store_direct_dword); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1372 | |
| 1373 | static inline int rf_kill_active(struct ipw_priv *priv) |
| 1374 | { |
| 1375 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) |
| 1376 | priv->status |= STATUS_RF_KILL_HW; |
| 1377 | else |
| 1378 | priv->status &= ~STATUS_RF_KILL_HW; |
| 1379 | |
| 1380 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; |
| 1381 | } |
| 1382 | |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1383 | 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] | 1384 | char *buf) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1385 | { |
| 1386 | /* 0 - RF kill not enabled |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1387 | 1 - SW based RF kill active (sysfs) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1388 | 2 - HW based RF kill active |
| 1389 | 3 - Both HW and SW baed RF kill active */ |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1390 | struct ipw_priv *priv = d->driver_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1391 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1392 | (rf_kill_active(priv) ? 0x2 : 0x0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1393 | return sprintf(buf, "%i\n", val); |
| 1394 | } |
| 1395 | |
| 1396 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) |
| 1397 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1398 | if ((disable_radio ? 1 : 0) == |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1399 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1400 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1401 | |
| 1402 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", |
| 1403 | disable_radio ? "OFF" : "ON"); |
| 1404 | |
| 1405 | if (disable_radio) { |
| 1406 | priv->status |= STATUS_RF_KILL_SW; |
| 1407 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1408 | if (priv->workqueue) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1409 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1410 | queue_work(priv->workqueue, &priv->down); |
| 1411 | } else { |
| 1412 | priv->status &= ~STATUS_RF_KILL_SW; |
| 1413 | if (rf_kill_active(priv)) { |
| 1414 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1415 | "disabled by HW switch\n"); |
| 1416 | /* Make sure the RF_KILL check timer is running */ |
| 1417 | cancel_delayed_work(&priv->rf_kill); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1418 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1419 | 2 * HZ); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1420 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1421 | queue_work(priv->workqueue, &priv->up); |
| 1422 | } |
| 1423 | |
| 1424 | return 1; |
| 1425 | } |
| 1426 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1427 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
| 1428 | const char *buf, size_t count) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1429 | { |
Andrew Morton | ad3fee5 | 2005-06-20 14:30:36 -0700 | [diff] [blame] | 1430 | struct ipw_priv *priv = d->driver_data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1431 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1432 | ipw_radio_kill_sw(priv, buf[0] == '1'); |
| 1433 | |
| 1434 | return count; |
| 1435 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1436 | |
| 1437 | 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] | 1438 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1439 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, |
| 1440 | char *buf) |
| 1441 | { |
| 1442 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1443 | int pos = 0, len = 0; |
| 1444 | if (priv->config & CFG_SPEED_SCAN) { |
| 1445 | while (priv->speed_scan[pos] != 0) |
| 1446 | len += sprintf(&buf[len], "%d ", |
| 1447 | priv->speed_scan[pos++]); |
| 1448 | return len + sprintf(&buf[len], "\n"); |
| 1449 | } |
| 1450 | |
| 1451 | return sprintf(buf, "0\n"); |
| 1452 | } |
| 1453 | |
| 1454 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, |
| 1455 | const char *buf, size_t count) |
| 1456 | { |
| 1457 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1458 | int channel, pos = 0; |
| 1459 | const char *p = buf; |
| 1460 | |
| 1461 | /* list of space separated channels to scan, optionally ending with 0 */ |
| 1462 | while ((channel = simple_strtol(p, NULL, 0))) { |
| 1463 | if (pos == MAX_SPEED_SCAN - 1) { |
| 1464 | priv->speed_scan[pos] = 0; |
| 1465 | break; |
| 1466 | } |
| 1467 | |
| 1468 | if (ieee80211_is_valid_channel(priv->ieee, channel)) |
| 1469 | priv->speed_scan[pos++] = channel; |
| 1470 | else |
| 1471 | IPW_WARNING("Skipping invalid channel request: %d\n", |
| 1472 | channel); |
| 1473 | p = strchr(p, ' '); |
| 1474 | if (!p) |
| 1475 | break; |
| 1476 | while (*p == ' ' || *p == '\t') |
| 1477 | p++; |
| 1478 | } |
| 1479 | |
| 1480 | if (pos == 0) |
| 1481 | priv->config &= ~CFG_SPEED_SCAN; |
| 1482 | else { |
| 1483 | priv->speed_scan_pos = 0; |
| 1484 | priv->config |= CFG_SPEED_SCAN; |
| 1485 | } |
| 1486 | |
| 1487 | return count; |
| 1488 | } |
| 1489 | |
| 1490 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, |
| 1491 | store_speed_scan); |
| 1492 | |
| 1493 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, |
| 1494 | char *buf) |
| 1495 | { |
| 1496 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1497 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); |
| 1498 | } |
| 1499 | |
| 1500 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, |
| 1501 | const char *buf, size_t count) |
| 1502 | { |
| 1503 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; |
| 1504 | if (buf[0] == '1') |
| 1505 | priv->config |= CFG_NET_STATS; |
| 1506 | else |
| 1507 | priv->config &= ~CFG_NET_STATS; |
| 1508 | |
| 1509 | return count; |
| 1510 | } |
| 1511 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1512 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, |
| 1513 | show_net_stats, store_net_stats); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1514 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1515 | static void notify_wx_assoc_event(struct ipw_priv *priv) |
| 1516 | { |
| 1517 | union iwreq_data wrqu; |
| 1518 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1519 | if (priv->status & STATUS_ASSOCIATED) |
| 1520 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); |
| 1521 | else |
| 1522 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 1523 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); |
| 1524 | } |
| 1525 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1526 | static void ipw_irq_tasklet(struct ipw_priv *priv) |
| 1527 | { |
| 1528 | u32 inta, inta_mask, handled = 0; |
| 1529 | unsigned long flags; |
| 1530 | int rc = 0; |
| 1531 | |
| 1532 | spin_lock_irqsave(&priv->lock, flags); |
| 1533 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1534 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 1535 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
| 1536 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1537 | |
| 1538 | /* Add any cached INTA values that need to be handled */ |
| 1539 | inta |= priv->isr_inta; |
| 1540 | |
| 1541 | /* handle all the justifications for the interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1542 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1543 | ipw_rx(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1544 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1545 | } |
| 1546 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1547 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1548 | IPW_DEBUG_HC("Command completed.\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1549 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1550 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1551 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1552 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1553 | } |
| 1554 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1555 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1556 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1557 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1558 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1559 | } |
| 1560 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1561 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1562 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1563 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1564 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1565 | } |
| 1566 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1567 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1568 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1569 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1570 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1571 | } |
| 1572 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1573 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1574 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1575 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1576 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1577 | } |
| 1578 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1579 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1580 | IPW_WARNING("STATUS_CHANGE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1581 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1582 | } |
| 1583 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1584 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1585 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1586 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1587 | } |
| 1588 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1589 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1590 | IPW_WARNING("HOST_CMD_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1591 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1592 | } |
| 1593 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1594 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1595 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1596 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1597 | } |
| 1598 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1599 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1600 | IPW_WARNING("PHY_OFF_DONE\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1601 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1602 | } |
| 1603 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1604 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1605 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
| 1606 | priv->status |= STATUS_RF_KILL_HW; |
| 1607 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1608 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1609 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1610 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1611 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1612 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1613 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1614 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1615 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1616 | IPW_ERROR("Firmware error detected. Restarting.\n"); |
| 1617 | #ifdef CONFIG_IPW_DEBUG |
| 1618 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
| 1619 | ipw_dump_nic_error_log(priv); |
| 1620 | ipw_dump_nic_event_log(priv); |
| 1621 | } |
| 1622 | #endif |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1623 | /* XXX: If hardware encryption is for WPA/WPA2, |
| 1624 | * we have to notify the supplicant. */ |
| 1625 | if (priv->ieee->sec.encrypt) { |
| 1626 | priv->status &= ~STATUS_ASSOCIATED; |
| 1627 | notify_wx_assoc_event(priv); |
| 1628 | } |
| 1629 | |
| 1630 | /* Keep the restart process from trying to send host |
| 1631 | * commands by clearing the INIT status bit */ |
| 1632 | priv->status &= ~STATUS_INIT; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1633 | |
| 1634 | /* Cancel currently queued command. */ |
| 1635 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1636 | wake_up_interruptible(&priv->wait_command_queue); |
| 1637 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1638 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1639 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1640 | } |
| 1641 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1642 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1643 | IPW_ERROR("Parity error\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1644 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | if (handled != inta) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1648 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | /* enable all interrupts */ |
| 1652 | ipw_enable_interrupts(priv); |
| 1653 | |
| 1654 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1655 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1656 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1657 | #ifdef CONFIG_IPW_DEBUG |
| 1658 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
| 1659 | static char *get_cmd_string(u8 cmd) |
| 1660 | { |
| 1661 | switch (cmd) { |
| 1662 | IPW_CMD(HOST_COMPLETE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1663 | IPW_CMD(POWER_DOWN); |
| 1664 | IPW_CMD(SYSTEM_CONFIG); |
| 1665 | IPW_CMD(MULTICAST_ADDRESS); |
| 1666 | IPW_CMD(SSID); |
| 1667 | IPW_CMD(ADAPTER_ADDRESS); |
| 1668 | IPW_CMD(PORT_TYPE); |
| 1669 | IPW_CMD(RTS_THRESHOLD); |
| 1670 | IPW_CMD(FRAG_THRESHOLD); |
| 1671 | IPW_CMD(POWER_MODE); |
| 1672 | IPW_CMD(WEP_KEY); |
| 1673 | IPW_CMD(TGI_TX_KEY); |
| 1674 | IPW_CMD(SCAN_REQUEST); |
| 1675 | IPW_CMD(SCAN_REQUEST_EXT); |
| 1676 | IPW_CMD(ASSOCIATE); |
| 1677 | IPW_CMD(SUPPORTED_RATES); |
| 1678 | IPW_CMD(SCAN_ABORT); |
| 1679 | IPW_CMD(TX_FLUSH); |
| 1680 | IPW_CMD(QOS_PARAMETERS); |
| 1681 | IPW_CMD(DINO_CONFIG); |
| 1682 | IPW_CMD(RSN_CAPABILITIES); |
| 1683 | IPW_CMD(RX_KEY); |
| 1684 | IPW_CMD(CARD_DISABLE); |
| 1685 | IPW_CMD(SEED_NUMBER); |
| 1686 | IPW_CMD(TX_POWER); |
| 1687 | IPW_CMD(COUNTRY_INFO); |
| 1688 | IPW_CMD(AIRONET_INFO); |
| 1689 | IPW_CMD(AP_TX_POWER); |
| 1690 | IPW_CMD(CCKM_INFO); |
| 1691 | IPW_CMD(CCX_VER_INFO); |
| 1692 | IPW_CMD(SET_CALIBRATION); |
| 1693 | IPW_CMD(SENSITIVITY_CALIB); |
| 1694 | IPW_CMD(RETRY_LIMIT); |
| 1695 | IPW_CMD(IPW_PRE_POWER_DOWN); |
| 1696 | IPW_CMD(VAP_BEACON_TEMPLATE); |
| 1697 | IPW_CMD(VAP_DTIM_PERIOD); |
| 1698 | IPW_CMD(EXT_SUPPORTED_RATES); |
| 1699 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); |
| 1700 | IPW_CMD(VAP_QUIET_INTERVALS); |
| 1701 | IPW_CMD(VAP_CHANNEL_SWITCH); |
| 1702 | IPW_CMD(VAP_MANDATORY_CHANNELS); |
| 1703 | IPW_CMD(VAP_CELL_PWR_LIMIT); |
| 1704 | IPW_CMD(VAP_CF_PARAM_SET); |
| 1705 | IPW_CMD(VAP_SET_BEACONING_STATE); |
| 1706 | IPW_CMD(MEASUREMENT); |
| 1707 | IPW_CMD(POWER_CAPABILITY); |
| 1708 | IPW_CMD(SUPPORTED_CHANNELS); |
| 1709 | IPW_CMD(TPC_REPORT); |
| 1710 | IPW_CMD(WME_INFO); |
| 1711 | IPW_CMD(PRODUCTION_COMMAND); |
| 1712 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1713 | return "UNKNOWN"; |
| 1714 | } |
| 1715 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 1716 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1717 | |
| 1718 | #define HOST_COMPLETE_TIMEOUT HZ |
| 1719 | static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd) |
| 1720 | { |
| 1721 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1722 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1723 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1724 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1725 | if (priv->status & STATUS_HCMD_ACTIVE) { |
| 1726 | IPW_ERROR("Already sending a command\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1727 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1728 | return -1; |
| 1729 | } |
| 1730 | |
| 1731 | priv->status |= STATUS_HCMD_ACTIVE; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1732 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1733 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
| 1734 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, |
| 1735 | priv->status); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1736 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1737 | |
| 1738 | 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] | 1739 | if (rc) { |
| 1740 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1741 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1742 | return rc; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1743 | } |
| 1744 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1745 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1746 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 1747 | !(priv-> |
| 1748 | status & STATUS_HCMD_ACTIVE), |
| 1749 | HOST_COMPLETE_TIMEOUT); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1750 | if (rc == 0) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1751 | spin_lock_irqsave(&priv->lock, flags); |
| 1752 | if (priv->status & STATUS_HCMD_ACTIVE) { |
| 1753 | IPW_DEBUG_INFO("Command completion failed out after " |
| 1754 | "%dms.\n", |
| 1755 | 1000 * (HOST_COMPLETE_TIMEOUT / HZ)); |
| 1756 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 1757 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1758 | return -EIO; |
| 1759 | } |
| 1760 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1761 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1762 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1763 | if (priv->status & STATUS_RF_KILL_HW) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1764 | IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n"); |
| 1765 | return -EIO; |
| 1766 | } |
| 1767 | |
| 1768 | return 0; |
| 1769 | } |
| 1770 | |
| 1771 | static int ipw_send_host_complete(struct ipw_priv *priv) |
| 1772 | { |
| 1773 | struct host_cmd cmd = { |
| 1774 | .cmd = IPW_CMD_HOST_COMPLETE, |
| 1775 | .len = 0 |
| 1776 | }; |
| 1777 | |
| 1778 | if (!priv) { |
| 1779 | IPW_ERROR("Invalid args\n"); |
| 1780 | return -1; |
| 1781 | } |
| 1782 | |
| 1783 | if (ipw_send_cmd(priv, &cmd)) { |
| 1784 | IPW_ERROR("failed to send HOST_COMPLETE command\n"); |
| 1785 | return -1; |
| 1786 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1787 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1788 | return 0; |
| 1789 | } |
| 1790 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1791 | static int ipw_send_system_config(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1792 | struct ipw_sys_config *config) |
| 1793 | { |
| 1794 | struct host_cmd cmd = { |
| 1795 | .cmd = IPW_CMD_SYSTEM_CONFIG, |
| 1796 | .len = sizeof(*config) |
| 1797 | }; |
| 1798 | |
| 1799 | if (!priv || !config) { |
| 1800 | IPW_ERROR("Invalid args\n"); |
| 1801 | return -1; |
| 1802 | } |
| 1803 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1804 | memcpy(cmd.param, config, sizeof(*config)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1805 | if (ipw_send_cmd(priv, &cmd)) { |
| 1806 | IPW_ERROR("failed to send SYSTEM_CONFIG command\n"); |
| 1807 | return -1; |
| 1808 | } |
| 1809 | |
| 1810 | return 0; |
| 1811 | } |
| 1812 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1813 | 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] | 1814 | { |
| 1815 | struct host_cmd cmd = { |
| 1816 | .cmd = IPW_CMD_SSID, |
| 1817 | .len = min(len, IW_ESSID_MAX_SIZE) |
| 1818 | }; |
| 1819 | |
| 1820 | if (!priv || !ssid) { |
| 1821 | IPW_ERROR("Invalid args\n"); |
| 1822 | return -1; |
| 1823 | } |
| 1824 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1825 | memcpy(cmd.param, ssid, cmd.len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1826 | if (ipw_send_cmd(priv, &cmd)) { |
| 1827 | IPW_ERROR("failed to send SSID command\n"); |
| 1828 | return -1; |
| 1829 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1830 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1831 | return 0; |
| 1832 | } |
| 1833 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1834 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1835 | { |
| 1836 | struct host_cmd cmd = { |
| 1837 | .cmd = IPW_CMD_ADAPTER_ADDRESS, |
| 1838 | .len = ETH_ALEN |
| 1839 | }; |
| 1840 | |
| 1841 | if (!priv || !mac) { |
| 1842 | IPW_ERROR("Invalid args\n"); |
| 1843 | return -1; |
| 1844 | } |
| 1845 | |
| 1846 | IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n", |
| 1847 | priv->net_dev->name, MAC_ARG(mac)); |
| 1848 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1849 | memcpy(cmd.param, mac, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1850 | if (ipw_send_cmd(priv, &cmd)) { |
| 1851 | IPW_ERROR("failed to send ADAPTER_ADDRESS command\n"); |
| 1852 | return -1; |
| 1853 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1854 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1855 | return 0; |
| 1856 | } |
| 1857 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1858 | /* |
| 1859 | * NOTE: This must be executed from our workqueue as it results in udelay |
| 1860 | * being called which may corrupt the keyboard if executed on default |
| 1861 | * workqueue |
| 1862 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1863 | static void ipw_adapter_restart(void *adapter) |
| 1864 | { |
| 1865 | struct ipw_priv *priv = adapter; |
| 1866 | |
| 1867 | if (priv->status & STATUS_RF_KILL_MASK) |
| 1868 | return; |
| 1869 | |
| 1870 | ipw_down(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 1871 | |
| 1872 | if (priv->assoc_network && |
| 1873 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) |
| 1874 | ipw_remove_current_network(priv); |
| 1875 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1876 | if (ipw_up(priv)) { |
| 1877 | IPW_ERROR("Failed to up device\n"); |
| 1878 | return; |
| 1879 | } |
| 1880 | } |
| 1881 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1882 | static void ipw_bg_adapter_restart(void *data) |
| 1883 | { |
| 1884 | struct ipw_priv *priv = data; |
| 1885 | down(&priv->sem); |
| 1886 | ipw_adapter_restart(data); |
| 1887 | up(&priv->sem); |
| 1888 | } |
| 1889 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1890 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
| 1891 | |
| 1892 | static void ipw_scan_check(void *data) |
| 1893 | { |
| 1894 | struct ipw_priv *priv = data; |
| 1895 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
| 1896 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1897 | "adapter (%dms).\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1898 | IPW_SCAN_CHECK_WATCHDOG / 100); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1899 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 1903 | static void ipw_bg_scan_check(void *data) |
| 1904 | { |
| 1905 | struct ipw_priv *priv = data; |
| 1906 | down(&priv->sem); |
| 1907 | ipw_scan_check(data); |
| 1908 | up(&priv->sem); |
| 1909 | } |
| 1910 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1911 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
| 1912 | struct ipw_scan_request_ext *request) |
| 1913 | { |
| 1914 | struct host_cmd cmd = { |
| 1915 | .cmd = IPW_CMD_SCAN_REQUEST_EXT, |
| 1916 | .len = sizeof(*request) |
| 1917 | }; |
| 1918 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1919 | memcpy(cmd.param, request, sizeof(*request)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1920 | if (ipw_send_cmd(priv, &cmd)) { |
| 1921 | IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n"); |
| 1922 | return -1; |
| 1923 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1924 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1925 | return 0; |
| 1926 | } |
| 1927 | |
| 1928 | static int ipw_send_scan_abort(struct ipw_priv *priv) |
| 1929 | { |
| 1930 | struct host_cmd cmd = { |
| 1931 | .cmd = IPW_CMD_SCAN_ABORT, |
| 1932 | .len = 0 |
| 1933 | }; |
| 1934 | |
| 1935 | if (!priv) { |
| 1936 | IPW_ERROR("Invalid args\n"); |
| 1937 | return -1; |
| 1938 | } |
| 1939 | |
| 1940 | if (ipw_send_cmd(priv, &cmd)) { |
| 1941 | IPW_ERROR("failed to send SCAN_ABORT command\n"); |
| 1942 | return -1; |
| 1943 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1944 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1945 | return 0; |
| 1946 | } |
| 1947 | |
| 1948 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) |
| 1949 | { |
| 1950 | struct host_cmd cmd = { |
| 1951 | .cmd = IPW_CMD_SENSITIVITY_CALIB, |
| 1952 | .len = sizeof(struct ipw_sensitivity_calib) |
| 1953 | }; |
| 1954 | struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 1955 | &cmd.param; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1956 | calib->beacon_rssi_raw = sens; |
| 1957 | if (ipw_send_cmd(priv, &cmd)) { |
| 1958 | IPW_ERROR("failed to send SENSITIVITY CALIB command\n"); |
| 1959 | return -1; |
| 1960 | } |
| 1961 | |
| 1962 | return 0; |
| 1963 | } |
| 1964 | |
| 1965 | static int ipw_send_associate(struct ipw_priv *priv, |
| 1966 | struct ipw_associate *associate) |
| 1967 | { |
| 1968 | struct host_cmd cmd = { |
| 1969 | .cmd = IPW_CMD_ASSOCIATE, |
| 1970 | .len = sizeof(*associate) |
| 1971 | }; |
| 1972 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 1973 | struct ipw_associate tmp_associate; |
| 1974 | memcpy(&tmp_associate, associate, sizeof(*associate)); |
| 1975 | tmp_associate.policy_support = |
| 1976 | cpu_to_le16(tmp_associate.policy_support); |
| 1977 | tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw); |
| 1978 | tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw); |
| 1979 | tmp_associate.capability = cpu_to_le16(tmp_associate.capability); |
| 1980 | tmp_associate.listen_interval = |
| 1981 | cpu_to_le16(tmp_associate.listen_interval); |
| 1982 | tmp_associate.beacon_interval = |
| 1983 | cpu_to_le16(tmp_associate.beacon_interval); |
| 1984 | tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window); |
| 1985 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1986 | if (!priv || !associate) { |
| 1987 | IPW_ERROR("Invalid args\n"); |
| 1988 | return -1; |
| 1989 | } |
| 1990 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 1991 | memcpy(cmd.param, &tmp_associate, sizeof(*associate)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1992 | if (ipw_send_cmd(priv, &cmd)) { |
| 1993 | IPW_ERROR("failed to send ASSOCIATE command\n"); |
| 1994 | return -1; |
| 1995 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 1996 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 1997 | return 0; |
| 1998 | } |
| 1999 | |
| 2000 | static int ipw_send_supported_rates(struct ipw_priv *priv, |
| 2001 | struct ipw_supported_rates *rates) |
| 2002 | { |
| 2003 | struct host_cmd cmd = { |
| 2004 | .cmd = IPW_CMD_SUPPORTED_RATES, |
| 2005 | .len = sizeof(*rates) |
| 2006 | }; |
| 2007 | |
| 2008 | if (!priv || !rates) { |
| 2009 | IPW_ERROR("Invalid args\n"); |
| 2010 | return -1; |
| 2011 | } |
| 2012 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2013 | memcpy(cmd.param, rates, sizeof(*rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2014 | if (ipw_send_cmd(priv, &cmd)) { |
| 2015 | IPW_ERROR("failed to send SUPPORTED_RATES command\n"); |
| 2016 | return -1; |
| 2017 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2018 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2019 | return 0; |
| 2020 | } |
| 2021 | |
| 2022 | static int ipw_set_random_seed(struct ipw_priv *priv) |
| 2023 | { |
| 2024 | struct host_cmd cmd = { |
| 2025 | .cmd = IPW_CMD_SEED_NUMBER, |
| 2026 | .len = sizeof(u32) |
| 2027 | }; |
| 2028 | |
| 2029 | if (!priv) { |
| 2030 | IPW_ERROR("Invalid args\n"); |
| 2031 | return -1; |
| 2032 | } |
| 2033 | |
| 2034 | get_random_bytes(&cmd.param, sizeof(u32)); |
| 2035 | |
| 2036 | if (ipw_send_cmd(priv, &cmd)) { |
| 2037 | IPW_ERROR("failed to send SEED_NUMBER command\n"); |
| 2038 | return -1; |
| 2039 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2040 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2041 | return 0; |
| 2042 | } |
| 2043 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2044 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
| 2045 | { |
| 2046 | struct host_cmd cmd = { |
| 2047 | .cmd = IPW_CMD_CARD_DISABLE, |
| 2048 | .len = sizeof(u32) |
| 2049 | }; |
| 2050 | |
| 2051 | if (!priv) { |
| 2052 | IPW_ERROR("Invalid args\n"); |
| 2053 | return -1; |
| 2054 | } |
| 2055 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2056 | *((u32 *) & cmd.param) = phy_off; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2057 | |
| 2058 | if (ipw_send_cmd(priv, &cmd)) { |
| 2059 | IPW_ERROR("failed to send CARD_DISABLE command\n"); |
| 2060 | return -1; |
| 2061 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2062 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2063 | return 0; |
| 2064 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2065 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2066 | 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] | 2067 | { |
| 2068 | struct host_cmd cmd = { |
| 2069 | .cmd = IPW_CMD_TX_POWER, |
| 2070 | .len = sizeof(*power) |
| 2071 | }; |
| 2072 | |
| 2073 | if (!priv || !power) { |
| 2074 | IPW_ERROR("Invalid args\n"); |
| 2075 | return -1; |
| 2076 | } |
| 2077 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2078 | memcpy(cmd.param, power, sizeof(*power)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2079 | if (ipw_send_cmd(priv, &cmd)) { |
| 2080 | IPW_ERROR("failed to send TX_POWER command\n"); |
| 2081 | return -1; |
| 2082 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2083 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2084 | return 0; |
| 2085 | } |
| 2086 | |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 2087 | static int ipw_set_tx_power(struct ipw_priv *priv) |
| 2088 | { |
| 2089 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
| 2090 | struct ipw_tx_power tx_power; |
| 2091 | s8 max_power; |
| 2092 | int i; |
| 2093 | |
| 2094 | memset(&tx_power, 0, sizeof(tx_power)); |
| 2095 | |
| 2096 | /* configure device for 'G' band */ |
| 2097 | tx_power.ieee_mode = IPW_G_MODE; |
| 2098 | tx_power.num_channels = geo->bg_channels; |
| 2099 | for (i = 0; i < geo->bg_channels; i++) { |
| 2100 | max_power = geo->bg[i].max_power; |
| 2101 | tx_power.channels_tx_power[i].channel_number = |
| 2102 | geo->bg[i].channel; |
| 2103 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2104 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2105 | } |
| 2106 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2107 | return -EIO; |
| 2108 | |
| 2109 | /* configure device to also handle 'B' band */ |
| 2110 | tx_power.ieee_mode = IPW_B_MODE; |
| 2111 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2112 | return -EIO; |
| 2113 | |
| 2114 | /* configure device to also handle 'A' band */ |
| 2115 | if (priv->ieee->abg_true) { |
| 2116 | tx_power.ieee_mode = IPW_A_MODE; |
| 2117 | tx_power.num_channels = geo->a_channels; |
| 2118 | for (i = 0; i < tx_power.num_channels; i++) { |
| 2119 | max_power = geo->a[i].max_power; |
| 2120 | tx_power.channels_tx_power[i].channel_number = |
| 2121 | geo->a[i].channel; |
| 2122 | tx_power.channels_tx_power[i].tx_power = max_power ? |
| 2123 | min(max_power, priv->tx_power) : priv->tx_power; |
| 2124 | } |
| 2125 | if (ipw_send_tx_power(priv, &tx_power)) |
| 2126 | return -EIO; |
| 2127 | } |
| 2128 | return 0; |
| 2129 | } |
| 2130 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2131 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) |
| 2132 | { |
| 2133 | struct ipw_rts_threshold rts_threshold = { |
| 2134 | .rts_threshold = rts, |
| 2135 | }; |
| 2136 | struct host_cmd cmd = { |
| 2137 | .cmd = IPW_CMD_RTS_THRESHOLD, |
| 2138 | .len = sizeof(rts_threshold) |
| 2139 | }; |
| 2140 | |
| 2141 | if (!priv) { |
| 2142 | IPW_ERROR("Invalid args\n"); |
| 2143 | return -1; |
| 2144 | } |
| 2145 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2146 | memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2147 | if (ipw_send_cmd(priv, &cmd)) { |
| 2148 | IPW_ERROR("failed to send RTS_THRESHOLD command\n"); |
| 2149 | return -1; |
| 2150 | } |
| 2151 | |
| 2152 | return 0; |
| 2153 | } |
| 2154 | |
| 2155 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) |
| 2156 | { |
| 2157 | struct ipw_frag_threshold frag_threshold = { |
| 2158 | .frag_threshold = frag, |
| 2159 | }; |
| 2160 | struct host_cmd cmd = { |
| 2161 | .cmd = IPW_CMD_FRAG_THRESHOLD, |
| 2162 | .len = sizeof(frag_threshold) |
| 2163 | }; |
| 2164 | |
| 2165 | if (!priv) { |
| 2166 | IPW_ERROR("Invalid args\n"); |
| 2167 | return -1; |
| 2168 | } |
| 2169 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2170 | memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2171 | if (ipw_send_cmd(priv, &cmd)) { |
| 2172 | IPW_ERROR("failed to send FRAG_THRESHOLD command\n"); |
| 2173 | return -1; |
| 2174 | } |
| 2175 | |
| 2176 | return 0; |
| 2177 | } |
| 2178 | |
| 2179 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) |
| 2180 | { |
| 2181 | struct host_cmd cmd = { |
| 2182 | .cmd = IPW_CMD_POWER_MODE, |
| 2183 | .len = sizeof(u32) |
| 2184 | }; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2185 | u32 *param = (u32 *) (&cmd.param); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2186 | |
| 2187 | if (!priv) { |
| 2188 | IPW_ERROR("Invalid args\n"); |
| 2189 | return -1; |
| 2190 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2191 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2192 | /* If on battery, set to 3, if AC set to CAM, else user |
| 2193 | * level */ |
| 2194 | switch (mode) { |
| 2195 | case IPW_POWER_BATTERY: |
| 2196 | *param = IPW_POWER_INDEX_3; |
| 2197 | break; |
| 2198 | case IPW_POWER_AC: |
| 2199 | *param = IPW_POWER_MODE_CAM; |
| 2200 | break; |
| 2201 | default: |
| 2202 | *param = mode; |
| 2203 | break; |
| 2204 | } |
| 2205 | |
| 2206 | if (ipw_send_cmd(priv, &cmd)) { |
| 2207 | IPW_ERROR("failed to send POWER_MODE command\n"); |
| 2208 | return -1; |
| 2209 | } |
| 2210 | |
| 2211 | return 0; |
| 2212 | } |
| 2213 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2214 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
| 2215 | { |
| 2216 | struct ipw_retry_limit retry_limit = { |
| 2217 | .short_retry_limit = slimit, |
| 2218 | .long_retry_limit = llimit |
| 2219 | }; |
| 2220 | struct host_cmd cmd = { |
| 2221 | .cmd = IPW_CMD_RETRY_LIMIT, |
| 2222 | .len = sizeof(retry_limit) |
| 2223 | }; |
| 2224 | |
| 2225 | if (!priv) { |
| 2226 | IPW_ERROR("Invalid args\n"); |
| 2227 | return -1; |
| 2228 | } |
| 2229 | |
| 2230 | memcpy(cmd.param, &retry_limit, sizeof(retry_limit)); |
| 2231 | if (ipw_send_cmd(priv, &cmd)) { |
| 2232 | IPW_ERROR("failed to send RETRY_LIMIT command\n"); |
| 2233 | return -1; |
| 2234 | } |
| 2235 | |
| 2236 | return 0; |
| 2237 | } |
| 2238 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2239 | /* |
| 2240 | * The IPW device contains a Microwire compatible EEPROM that stores |
| 2241 | * various data like the MAC address. Usually the firmware has exclusive |
| 2242 | * access to the eeprom, but during device initialization (before the |
| 2243 | * device driver has sent the HostComplete command to the firmware) the |
| 2244 | * device driver has read access to the EEPROM by way of indirect addressing |
| 2245 | * through a couple of memory mapped registers. |
| 2246 | * |
| 2247 | * The following is a simplified implementation for pulling data out of the |
| 2248 | * the eeprom, along with some helper functions to find information in |
| 2249 | * the per device private data's copy of the eeprom. |
| 2250 | * |
| 2251 | * NOTE: To better understand how these functions work (i.e what is a chip |
| 2252 | * select and why do have to keep driving the eeprom clock?), read |
| 2253 | * just about any data sheet for a Microwire compatible EEPROM. |
| 2254 | */ |
| 2255 | |
| 2256 | /* write a 32 bit value into the indirect accessor register */ |
| 2257 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) |
| 2258 | { |
| 2259 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2260 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2261 | /* the eeprom requires some time to complete the operation */ |
| 2262 | udelay(p->eeprom_delay); |
| 2263 | |
| 2264 | return; |
| 2265 | } |
| 2266 | |
| 2267 | /* perform a chip select operation */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2268 | static inline void eeprom_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2269 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2270 | eeprom_write_reg(priv, 0); |
| 2271 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2272 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2273 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | /* perform a chip select operation */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2277 | static inline void eeprom_disable_cs(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2278 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2279 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2280 | eeprom_write_reg(priv, 0); |
| 2281 | eeprom_write_reg(priv, EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | /* push a single bit down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2285 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2286 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2287 | int d = (bit ? EEPROM_BIT_DI : 0); |
| 2288 | eeprom_write_reg(p, EEPROM_BIT_CS | d); |
| 2289 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | /* push an opcode followed by an address down to the eeprom */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2293 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2294 | { |
| 2295 | int i; |
| 2296 | |
| 2297 | eeprom_cs(priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2298 | eeprom_write_bit(priv, 1); |
| 2299 | eeprom_write_bit(priv, op & 2); |
| 2300 | eeprom_write_bit(priv, op & 1); |
| 2301 | for (i = 7; i >= 0; i--) { |
| 2302 | eeprom_write_bit(priv, addr & (1 << i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | /* pull 16 bits off the eeprom, one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2307 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2308 | { |
| 2309 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2310 | u16 r = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2311 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2312 | /* Send READ Opcode */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2313 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2314 | |
| 2315 | /* Send dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2316 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2317 | |
| 2318 | /* Read the byte off the eeprom one bit at a time */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2319 | for (i = 0; i < 16; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2320 | u32 data = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2321 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
| 2322 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
| 2323 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); |
| 2324 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2325 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2326 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2327 | /* Send another dummy bit */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2328 | eeprom_write_reg(priv, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2329 | eeprom_disable_cs(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2330 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2331 | return r; |
| 2332 | } |
| 2333 | |
| 2334 | /* helper function for pulling the mac address out of the private */ |
| 2335 | /* data's copy of the eeprom data */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2336 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2337 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2338 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | /* |
| 2342 | * Either the device driver (i.e. the host) or the firmware can |
| 2343 | * load eeprom data into the designated region in SRAM. If neither |
| 2344 | * happens then the FW will shutdown with a fatal error. |
| 2345 | * |
| 2346 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE |
| 2347 | * bit needs region of shared SRAM needs to be non-zero. |
| 2348 | */ |
| 2349 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) |
| 2350 | { |
| 2351 | int i; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2352 | u16 *eeprom = (u16 *) priv->eeprom; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2353 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2354 | IPW_DEBUG_TRACE(">>\n"); |
| 2355 | |
| 2356 | /* read entire contents of eeprom into private buffer */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2357 | for (i = 0; i < 128; i++) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2358 | eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2359 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2360 | /* |
| 2361 | If the data looks correct, then copy it to our private |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2362 | copy. Otherwise let the firmware know to perform the operation |
| 2363 | on it's own |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2364 | */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2365 | if ((priv->eeprom + EEPROM_VERSION) != 0) { |
| 2366 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
| 2367 | |
| 2368 | /* write the eeprom data to sram */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2369 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2370 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2371 | |
| 2372 | /* Do not load eeprom data on fatal error or suspend */ |
| 2373 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 2374 | } else { |
| 2375 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); |
| 2376 | |
| 2377 | /* Load eeprom data on fatal error or suspend */ |
| 2378 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); |
| 2379 | } |
| 2380 | |
| 2381 | IPW_DEBUG_TRACE("<<\n"); |
| 2382 | } |
| 2383 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2384 | static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count) |
| 2385 | { |
| 2386 | count >>= 2; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2387 | if (!count) |
| 2388 | return; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2389 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2390 | while (count--) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2391 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) |
| 2395 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2396 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2397 | CB_NUMBER_OF_ELEMENTS_SMALL * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2398 | sizeof(struct command_block)); |
| 2399 | } |
| 2400 | |
| 2401 | static int ipw_fw_dma_enable(struct ipw_priv *priv) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2402 | { /* start dma engine but no transfers yet */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2403 | |
| 2404 | IPW_DEBUG_FW(">> : \n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2405 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2406 | /* Start the dma */ |
| 2407 | ipw_fw_dma_reset_command_blocks(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2408 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2409 | /* Write CB base address */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2410 | 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] | 2411 | |
| 2412 | IPW_DEBUG_FW("<< : \n"); |
| 2413 | return 0; |
| 2414 | } |
| 2415 | |
| 2416 | static void ipw_fw_dma_abort(struct ipw_priv *priv) |
| 2417 | { |
| 2418 | u32 control = 0; |
| 2419 | |
| 2420 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2421 | |
| 2422 | //set the Stop and Abort bit |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2423 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2424 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2425 | priv->sram_desc.last_cb_index = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2426 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2427 | IPW_DEBUG_FW("<< \n"); |
| 2428 | } |
| 2429 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2430 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
| 2431 | struct command_block *cb) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2432 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2433 | u32 address = |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2434 | IPW_SHARED_SRAM_DMA_CONTROL + |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2435 | (sizeof(struct command_block) * index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2436 | IPW_DEBUG_FW(">> :\n"); |
| 2437 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2438 | ipw_write_indirect(priv, address, (u8 *) cb, |
| 2439 | (int)sizeof(struct command_block)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2440 | |
| 2441 | IPW_DEBUG_FW("<< :\n"); |
| 2442 | return 0; |
| 2443 | |
| 2444 | } |
| 2445 | |
| 2446 | static int ipw_fw_dma_kick(struct ipw_priv *priv) |
| 2447 | { |
| 2448 | u32 control = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2449 | u32 index = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2450 | |
| 2451 | IPW_DEBUG_FW(">> :\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2452 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2453 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2454 | ipw_fw_dma_write_command_block(priv, index, |
| 2455 | &priv->sram_desc.cb_list[index]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2456 | |
| 2457 | /* Enable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2458 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 2459 | IPW_RESET_REG_MASTER_DISABLED | |
| 2460 | IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2461 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2462 | /* Set the Start bit. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2463 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2464 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2465 | |
| 2466 | IPW_DEBUG_FW("<< :\n"); |
| 2467 | return 0; |
| 2468 | } |
| 2469 | |
| 2470 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) |
| 2471 | { |
| 2472 | u32 address; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2473 | u32 register_value = 0; |
| 2474 | u32 cb_fields_address = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2475 | |
| 2476 | IPW_DEBUG_FW(">> :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2477 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2478 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2479 | |
| 2480 | /* Read the DMA Controlor register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2481 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
| 2482 | 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] | 2483 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2484 | /* Print the CB values */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2485 | cb_fields_address = address; |
| 2486 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2487 | 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] | 2488 | |
| 2489 | cb_fields_address += sizeof(u32); |
| 2490 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2491 | 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] | 2492 | |
| 2493 | cb_fields_address += sizeof(u32); |
| 2494 | register_value = ipw_read_reg32(priv, cb_fields_address); |
| 2495 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", |
| 2496 | register_value); |
| 2497 | |
| 2498 | cb_fields_address += sizeof(u32); |
| 2499 | register_value = ipw_read_reg32(priv, cb_fields_address); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2500 | 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] | 2501 | |
| 2502 | IPW_DEBUG_FW(">> :\n"); |
| 2503 | } |
| 2504 | |
| 2505 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) |
| 2506 | { |
| 2507 | u32 current_cb_address = 0; |
| 2508 | u32 current_cb_index = 0; |
| 2509 | |
| 2510 | IPW_DEBUG_FW("<< :\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2511 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2512 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2513 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2514 | sizeof(struct command_block); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2515 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2516 | 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] | 2517 | current_cb_index, current_cb_address); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2518 | |
| 2519 | IPW_DEBUG_FW(">> :\n"); |
| 2520 | return current_cb_index; |
| 2521 | |
| 2522 | } |
| 2523 | |
| 2524 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, |
| 2525 | u32 src_address, |
| 2526 | u32 dest_address, |
| 2527 | u32 length, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2528 | int interrupt_enabled, int is_last) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2529 | { |
| 2530 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2531 | 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] | 2532 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
| 2533 | CB_DEST_SIZE_LONG; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2534 | struct command_block *cb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2535 | u32 last_cb_element = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2536 | |
| 2537 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", |
| 2538 | src_address, dest_address, length); |
| 2539 | |
| 2540 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) |
| 2541 | return -1; |
| 2542 | |
| 2543 | last_cb_element = priv->sram_desc.last_cb_index; |
| 2544 | cb = &priv->sram_desc.cb_list[last_cb_element]; |
| 2545 | priv->sram_desc.last_cb_index++; |
| 2546 | |
| 2547 | /* Calculate the new CB control word */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2548 | if (interrupt_enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2549 | control |= CB_INT_ENABLED; |
| 2550 | |
| 2551 | if (is_last) |
| 2552 | control |= CB_LAST_VALID; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2553 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2554 | control |= length; |
| 2555 | |
| 2556 | /* Calculate the CB Element's checksum value */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2557 | cb->status = control ^ src_address ^ dest_address; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2558 | |
| 2559 | /* Copy the Source and Destination addresses */ |
| 2560 | cb->dest_addr = dest_address; |
| 2561 | cb->source_addr = src_address; |
| 2562 | |
| 2563 | /* Copy the Control Word last */ |
| 2564 | cb->control = control; |
| 2565 | |
| 2566 | return 0; |
| 2567 | } |
| 2568 | |
| 2569 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2570 | u32 src_phys, u32 dest_address, u32 length) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2571 | { |
| 2572 | u32 bytes_left = length; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2573 | u32 src_offset = 0; |
| 2574 | u32 dest_offset = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2575 | int status = 0; |
| 2576 | IPW_DEBUG_FW(">> \n"); |
| 2577 | IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n", |
| 2578 | src_phys, dest_address, length); |
| 2579 | while (bytes_left > CB_MAX_LENGTH) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2580 | status = ipw_fw_dma_add_command_block(priv, |
| 2581 | src_phys + src_offset, |
| 2582 | dest_address + |
| 2583 | dest_offset, |
| 2584 | CB_MAX_LENGTH, 0, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2585 | if (status) { |
| 2586 | IPW_DEBUG_FW_INFO(": Failed\n"); |
| 2587 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2588 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2589 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
| 2590 | |
| 2591 | src_offset += CB_MAX_LENGTH; |
| 2592 | dest_offset += CB_MAX_LENGTH; |
| 2593 | bytes_left -= CB_MAX_LENGTH; |
| 2594 | } |
| 2595 | |
| 2596 | /* add the buffer tail */ |
| 2597 | if (bytes_left > 0) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2598 | status = |
| 2599 | ipw_fw_dma_add_command_block(priv, src_phys + src_offset, |
| 2600 | dest_address + dest_offset, |
| 2601 | bytes_left, 0, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2602 | if (status) { |
| 2603 | IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n"); |
| 2604 | return -1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2605 | } else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2606 | IPW_DEBUG_FW_INFO |
| 2607 | (": Adding new cb - the buffer tail\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2608 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2609 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2610 | IPW_DEBUG_FW("<< \n"); |
| 2611 | return 0; |
| 2612 | } |
| 2613 | |
| 2614 | static int ipw_fw_dma_wait(struct ipw_priv *priv) |
| 2615 | { |
| 2616 | u32 current_index = 0; |
| 2617 | u32 watchdog = 0; |
| 2618 | |
| 2619 | IPW_DEBUG_FW(">> : \n"); |
| 2620 | |
| 2621 | current_index = ipw_fw_dma_command_block_index(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2622 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2623 | (int)priv->sram_desc.last_cb_index); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2624 | |
| 2625 | while (current_index < priv->sram_desc.last_cb_index) { |
| 2626 | udelay(50); |
| 2627 | current_index = ipw_fw_dma_command_block_index(priv); |
| 2628 | |
| 2629 | watchdog++; |
| 2630 | |
| 2631 | if (watchdog > 400) { |
| 2632 | IPW_DEBUG_FW_INFO("Timeout\n"); |
| 2633 | ipw_fw_dma_dump_command_block(priv); |
| 2634 | ipw_fw_dma_abort(priv); |
| 2635 | return -1; |
| 2636 | } |
| 2637 | } |
| 2638 | |
| 2639 | ipw_fw_dma_abort(priv); |
| 2640 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2641 | /*Disable the DMA in the CSR register */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2642 | ipw_set_bit(priv, IPW_RESET_REG, |
| 2643 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2644 | |
| 2645 | IPW_DEBUG_FW("<< dmaWaitSync \n"); |
| 2646 | return 0; |
| 2647 | } |
| 2648 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2649 | static void ipw_remove_current_network(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2650 | { |
| 2651 | struct list_head *element, *safe; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2652 | struct ieee80211_network *network = NULL; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2653 | unsigned long flags; |
| 2654 | |
| 2655 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2656 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
| 2657 | network = list_entry(element, struct ieee80211_network, list); |
| 2658 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 2659 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2660 | list_add_tail(&network->list, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2661 | &priv->ieee->network_free_list); |
| 2662 | } |
| 2663 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2664 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | /** |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2668 | * Check that card is still alive. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2669 | * Reads debug register from domain0. |
| 2670 | * If card is present, pre-defined value should |
| 2671 | * be found there. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2672 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2673 | * @param priv |
| 2674 | * @return 1 if card is present, 0 otherwise |
| 2675 | */ |
| 2676 | static inline int ipw_alive(struct ipw_priv *priv) |
| 2677 | { |
| 2678 | return ipw_read32(priv, 0x90) == 0xd55555d5; |
| 2679 | } |
| 2680 | |
| 2681 | static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask, |
| 2682 | int timeout) |
| 2683 | { |
| 2684 | int i = 0; |
| 2685 | |
| 2686 | do { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2687 | if ((ipw_read32(priv, addr) & mask) == mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2688 | return i; |
| 2689 | mdelay(10); |
| 2690 | i += 10; |
| 2691 | } while (i < timeout); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2692 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2693 | return -ETIME; |
| 2694 | } |
| 2695 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2696 | /* These functions load the firmware and micro code for the operation of |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2697 | * the ipw hardware. It assumes the buffer has all the bits for the |
| 2698 | * image and the caller is handling the memory allocation and clean up. |
| 2699 | */ |
| 2700 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2701 | static int ipw_stop_master(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2702 | { |
| 2703 | int rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2704 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2705 | IPW_DEBUG_TRACE(">> \n"); |
| 2706 | /* stop master. typical delay - 0 */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2707 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2708 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2709 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 2710 | IPW_RESET_REG_MASTER_DISABLED, 100); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2711 | if (rc < 0) { |
| 2712 | IPW_ERROR("stop master failed in 10ms\n"); |
| 2713 | return -1; |
| 2714 | } |
| 2715 | |
| 2716 | IPW_DEBUG_INFO("stop master %dms\n", rc); |
| 2717 | |
| 2718 | return rc; |
| 2719 | } |
| 2720 | |
| 2721 | static void ipw_arc_release(struct ipw_priv *priv) |
| 2722 | { |
| 2723 | IPW_DEBUG_TRACE(">> \n"); |
| 2724 | mdelay(5); |
| 2725 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2726 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2727 | |
| 2728 | /* no one knows timing, for safety add some delay */ |
| 2729 | mdelay(5); |
| 2730 | } |
| 2731 | |
| 2732 | struct fw_header { |
| 2733 | u32 version; |
| 2734 | u32 mode; |
| 2735 | }; |
| 2736 | |
| 2737 | struct fw_chunk { |
| 2738 | u32 address; |
| 2739 | u32 length; |
| 2740 | }; |
| 2741 | |
| 2742 | #define IPW_FW_MAJOR_VERSION 2 |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2743 | #define IPW_FW_MINOR_VERSION 3 |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2744 | |
| 2745 | #define IPW_FW_MINOR(x) ((x & 0xff) >> 8) |
| 2746 | #define IPW_FW_MAJOR(x) (x & 0xff) |
| 2747 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 2748 | #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] | 2749 | |
| 2750 | #define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \ |
| 2751 | "." __stringify(IPW_FW_MINOR_VERSION) "-" |
| 2752 | |
| 2753 | #if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0 |
| 2754 | #define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw" |
| 2755 | #else |
| 2756 | #define IPW_FW_NAME(x) "ipw2200_" x ".fw" |
| 2757 | #endif |
| 2758 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2759 | 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] | 2760 | { |
| 2761 | int rc = 0, i, addr; |
| 2762 | u8 cr = 0; |
| 2763 | u16 *image; |
| 2764 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2765 | image = (u16 *) data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2766 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2767 | IPW_DEBUG_TRACE(">> \n"); |
| 2768 | |
| 2769 | rc = ipw_stop_master(priv); |
| 2770 | |
| 2771 | if (rc < 0) |
| 2772 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2773 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2774 | // spin_lock_irqsave(&priv->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2775 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2776 | for (addr = IPW_SHARED_LOWER_BOUND; |
| 2777 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2778 | ipw_write32(priv, addr, 0); |
| 2779 | } |
| 2780 | |
| 2781 | /* no ucode (yet) */ |
| 2782 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); |
| 2783 | /* destroy DMA queues */ |
| 2784 | /* reset sequence */ |
| 2785 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2786 | 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] | 2787 | ipw_arc_release(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2788 | 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] | 2789 | mdelay(1); |
| 2790 | |
| 2791 | /* reset PHY */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2792 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2793 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2794 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2795 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2796 | mdelay(1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2797 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2798 | /* enable ucode store */ |
| 2799 | ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0); |
| 2800 | ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS); |
| 2801 | mdelay(1); |
| 2802 | |
| 2803 | /* write ucode */ |
| 2804 | /** |
| 2805 | * @bug |
| 2806 | * Do NOT set indirect address register once and then |
| 2807 | * store data to indirect data register in the loop. |
| 2808 | * It seems very reasonable, but in this case DINO do not |
| 2809 | * accept ucode. It is essential to set address each time. |
| 2810 | */ |
| 2811 | /* load new ipw uCode */ |
| 2812 | for (i = 0; i < len / 2; i++) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2813 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2814 | cpu_to_le16(image[i])); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2815 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2816 | /* enable DINO */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2817 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
| 2818 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2819 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2820 | /* this is where the igx / win driver deveates from the VAP driver. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2821 | |
| 2822 | /* wait for alive response */ |
| 2823 | for (i = 0; i < 100; i++) { |
| 2824 | /* poll for incoming data */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2825 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2826 | if (cr & DINO_RXFIFO_DATA) |
| 2827 | break; |
| 2828 | mdelay(1); |
| 2829 | } |
| 2830 | |
| 2831 | if (cr & DINO_RXFIFO_DATA) { |
| 2832 | /* alive_command_responce size is NOT multiple of 4 */ |
| 2833 | u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2834 | |
| 2835 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2836 | response_buffer[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2837 | le32_to_cpu(ipw_read_reg32(priv, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2838 | IPW_BASEBAND_RX_FIFO_READ)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2839 | memcpy(&priv->dino_alive, response_buffer, |
| 2840 | sizeof(priv->dino_alive)); |
| 2841 | if (priv->dino_alive.alive_command == 1 |
| 2842 | && priv->dino_alive.ucode_valid == 1) { |
| 2843 | rc = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2844 | IPW_DEBUG_INFO |
| 2845 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " |
| 2846 | "of %02d/%02d/%02d %02d:%02d\n", |
| 2847 | priv->dino_alive.software_revision, |
| 2848 | priv->dino_alive.software_revision, |
| 2849 | priv->dino_alive.device_identifier, |
| 2850 | priv->dino_alive.device_identifier, |
| 2851 | priv->dino_alive.time_stamp[0], |
| 2852 | priv->dino_alive.time_stamp[1], |
| 2853 | priv->dino_alive.time_stamp[2], |
| 2854 | priv->dino_alive.time_stamp[3], |
| 2855 | priv->dino_alive.time_stamp[4]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2856 | } else { |
| 2857 | IPW_DEBUG_INFO("Microcode is not alive\n"); |
| 2858 | rc = -EINVAL; |
| 2859 | } |
| 2860 | } else { |
| 2861 | IPW_DEBUG_INFO("No alive response from DINO\n"); |
| 2862 | rc = -ETIME; |
| 2863 | } |
| 2864 | |
| 2865 | /* disable DINO, otherwise for some reason |
| 2866 | firmware have problem getting alive resp. */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2867 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2868 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2869 | // spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2870 | |
| 2871 | return rc; |
| 2872 | } |
| 2873 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2874 | 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] | 2875 | { |
| 2876 | int rc = -1; |
| 2877 | int offset = 0; |
| 2878 | struct fw_chunk *chunk; |
| 2879 | dma_addr_t shared_phys; |
| 2880 | u8 *shared_virt; |
| 2881 | |
| 2882 | IPW_DEBUG_TRACE("<< : \n"); |
| 2883 | shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys); |
| 2884 | |
| 2885 | if (!shared_virt) |
| 2886 | return -ENOMEM; |
| 2887 | |
| 2888 | memmove(shared_virt, data, len); |
| 2889 | |
| 2890 | /* Start the Dma */ |
| 2891 | rc = ipw_fw_dma_enable(priv); |
| 2892 | |
| 2893 | if (priv->sram_desc.last_cb_index > 0) { |
| 2894 | /* the DMA is already ready this would be a bug. */ |
| 2895 | BUG(); |
| 2896 | goto out; |
| 2897 | } |
| 2898 | |
| 2899 | do { |
| 2900 | chunk = (struct fw_chunk *)(data + offset); |
| 2901 | offset += sizeof(struct fw_chunk); |
| 2902 | /* build DMA packet and queue up for sending */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2903 | /* dma to chunk->address, the chunk->length bytes from data + |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2904 | * offeset*/ |
| 2905 | /* Dma loading */ |
| 2906 | rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2907 | le32_to_cpu(chunk->address), |
| 2908 | le32_to_cpu(chunk->length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2909 | if (rc) { |
| 2910 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
| 2911 | goto out; |
| 2912 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2913 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 2914 | offset += le32_to_cpu(chunk->length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2915 | } while (offset < len); |
| 2916 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2917 | /* Run the DMA and wait for the answer */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2918 | rc = ipw_fw_dma_kick(priv); |
| 2919 | if (rc) { |
| 2920 | IPW_ERROR("dmaKick Failed\n"); |
| 2921 | goto out; |
| 2922 | } |
| 2923 | |
| 2924 | rc = ipw_fw_dma_wait(priv); |
| 2925 | if (rc) { |
| 2926 | IPW_ERROR("dmaWaitSync Failed\n"); |
| 2927 | goto out; |
| 2928 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2929 | out: |
| 2930 | pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2931 | return rc; |
| 2932 | } |
| 2933 | |
| 2934 | /* stop nic */ |
| 2935 | static int ipw_stop_nic(struct ipw_priv *priv) |
| 2936 | { |
| 2937 | int rc = 0; |
| 2938 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2939 | /* stop */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2940 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2941 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2942 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
| 2943 | IPW_RESET_REG_MASTER_DISABLED, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2944 | if (rc < 0) { |
| 2945 | IPW_ERROR("wait for reg master disabled failed\n"); |
| 2946 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2947 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2948 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2949 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2950 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2951 | return rc; |
| 2952 | } |
| 2953 | |
| 2954 | static void ipw_start_nic(struct ipw_priv *priv) |
| 2955 | { |
| 2956 | IPW_DEBUG_TRACE(">>\n"); |
| 2957 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2958 | /* prvHwStartNic release ARC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2959 | ipw_clear_bit(priv, IPW_RESET_REG, |
| 2960 | IPW_RESET_REG_MASTER_DISABLED | |
| 2961 | IPW_RESET_REG_STOP_MASTER | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2962 | CBD_RESET_REG_PRINCETON_RESET); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2963 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2964 | /* enable power management */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2965 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
| 2966 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2967 | |
| 2968 | IPW_DEBUG_TRACE("<<\n"); |
| 2969 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2970 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2971 | static int ipw_init_nic(struct ipw_priv *priv) |
| 2972 | { |
| 2973 | int rc; |
| 2974 | |
| 2975 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 2976 | /* reset */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2977 | /*prvHwInitNic */ |
| 2978 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2979 | 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] | 2980 | |
| 2981 | /* low-level PLL activation */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2982 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
| 2983 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2984 | |
| 2985 | /* wait for clock stabilization */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2986 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
| 2987 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 2988 | if (rc < 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2989 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
| 2990 | |
| 2991 | /* assert SW reset */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2992 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 2993 | |
| 2994 | udelay(10); |
| 2995 | |
| 2996 | /* set "initialization complete" bit to move adapter to D0 state */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 2997 | 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] | 2998 | |
| 2999 | IPW_DEBUG_TRACE(">>\n"); |
| 3000 | return 0; |
| 3001 | } |
| 3002 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3003 | /* Call this function from process context, it will sleep in request_firmware. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3004 | * Probe is an ok place to call this from. |
| 3005 | */ |
| 3006 | static int ipw_reset_nic(struct ipw_priv *priv) |
| 3007 | { |
| 3008 | int rc = 0; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3009 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3010 | |
| 3011 | IPW_DEBUG_TRACE(">>\n"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3012 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3013 | rc = ipw_init_nic(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3014 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3015 | spin_lock_irqsave(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3016 | /* Clear the 'host command active' bit... */ |
| 3017 | priv->status &= ~STATUS_HCMD_ACTIVE; |
| 3018 | wake_up_interruptible(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3019 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 3020 | wake_up_interruptible(&priv->wait_state); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3021 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3022 | |
| 3023 | IPW_DEBUG_TRACE("<<\n"); |
| 3024 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3025 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3026 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3027 | static int ipw_get_fw(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3028 | const struct firmware **fw, const char *name) |
| 3029 | { |
| 3030 | struct fw_header *header; |
| 3031 | int rc; |
| 3032 | |
| 3033 | /* ask firmware_class module to get the boot firmware off disk */ |
| 3034 | rc = request_firmware(fw, name, &priv->pci_dev->dev); |
| 3035 | if (rc < 0) { |
| 3036 | IPW_ERROR("%s load failed: Reason %d\n", name, rc); |
| 3037 | return rc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3038 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3039 | |
| 3040 | header = (struct fw_header *)(*fw)->data; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3041 | 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] | 3042 | IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n", |
| 3043 | name, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3044 | IPW_FW_MAJOR(le32_to_cpu(header->version)), |
| 3045 | IPW_FW_MAJOR_VERSION); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3046 | return -EINVAL; |
| 3047 | } |
| 3048 | |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3049 | 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] | 3050 | name, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3051 | IPW_FW_MAJOR(le32_to_cpu(header->version)), |
| 3052 | IPW_FW_MINOR(le32_to_cpu(header->version)), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3053 | (*fw)->size - sizeof(struct fw_header)); |
| 3054 | return 0; |
| 3055 | } |
| 3056 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3057 | #define IPW_RX_BUF_SIZE (3000) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3058 | |
| 3059 | static inline void ipw_rx_queue_reset(struct ipw_priv *priv, |
| 3060 | struct ipw_rx_queue *rxq) |
| 3061 | { |
| 3062 | unsigned long flags; |
| 3063 | int i; |
| 3064 | |
| 3065 | spin_lock_irqsave(&rxq->lock, flags); |
| 3066 | |
| 3067 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3068 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3069 | |
| 3070 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3071 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3072 | /* In the reset function, these buffers may have been allocated |
| 3073 | * to an SKB, so we need to unmap and free potential storage */ |
| 3074 | if (rxq->pool[i].skb != NULL) { |
| 3075 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3076 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3077 | dev_kfree_skb(rxq->pool[i].skb); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3078 | rxq->pool[i].skb = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3079 | } |
| 3080 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3081 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3082 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3083 | /* Set us so that we have processed and used all buffers, but have |
| 3084 | * not restocked the Rx queue with fresh buffers */ |
| 3085 | rxq->read = rxq->write = 0; |
| 3086 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 3087 | rxq->free_count = 0; |
| 3088 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3089 | } |
| 3090 | |
| 3091 | #ifdef CONFIG_PM |
| 3092 | static int fw_loaded = 0; |
| 3093 | static const struct firmware *bootfw = NULL; |
| 3094 | static const struct firmware *firmware = NULL; |
| 3095 | static const struct firmware *ucode = NULL; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 3096 | |
| 3097 | static void free_firmware(void) |
| 3098 | { |
| 3099 | if (fw_loaded) { |
| 3100 | release_firmware(bootfw); |
| 3101 | release_firmware(ucode); |
| 3102 | release_firmware(firmware); |
| 3103 | bootfw = ucode = firmware = NULL; |
| 3104 | fw_loaded = 0; |
| 3105 | } |
| 3106 | } |
| 3107 | #else |
| 3108 | #define free_firmware() do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3109 | #endif |
| 3110 | |
| 3111 | static int ipw_load(struct ipw_priv *priv) |
| 3112 | { |
| 3113 | #ifndef CONFIG_PM |
| 3114 | const struct firmware *bootfw = NULL; |
| 3115 | const struct firmware *firmware = NULL; |
| 3116 | const struct firmware *ucode = NULL; |
| 3117 | #endif |
| 3118 | int rc = 0, retries = 3; |
| 3119 | |
| 3120 | #ifdef CONFIG_PM |
| 3121 | if (!fw_loaded) { |
| 3122 | #endif |
| 3123 | rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot")); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3124 | if (rc) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3125 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3126 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3127 | switch (priv->ieee->iw_mode) { |
| 3128 | case IW_MODE_ADHOC: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3129 | rc = ipw_get_fw(priv, &ucode, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3130 | IPW_FW_NAME("ibss_ucode")); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3131 | if (rc) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3132 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3133 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3134 | rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss")); |
| 3135 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3136 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3137 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3138 | case IW_MODE_MONITOR: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3139 | rc = ipw_get_fw(priv, &ucode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3140 | IPW_FW_NAME("sniffer_ucode")); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3141 | if (rc) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3142 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3143 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3144 | rc = ipw_get_fw(priv, &firmware, |
| 3145 | IPW_FW_NAME("sniffer")); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3146 | break; |
| 3147 | #endif |
| 3148 | case IW_MODE_INFRA: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3149 | rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode")); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3150 | if (rc) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3151 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3152 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3153 | rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss")); |
| 3154 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3155 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3156 | default: |
| 3157 | rc = -EINVAL; |
| 3158 | } |
| 3159 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3160 | if (rc) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3161 | goto error; |
| 3162 | |
| 3163 | #ifdef CONFIG_PM |
| 3164 | fw_loaded = 1; |
| 3165 | } |
| 3166 | #endif |
| 3167 | |
| 3168 | if (!priv->rxq) |
| 3169 | priv->rxq = ipw_rx_queue_alloc(priv); |
| 3170 | else |
| 3171 | ipw_rx_queue_reset(priv, priv->rxq); |
| 3172 | if (!priv->rxq) { |
| 3173 | IPW_ERROR("Unable to initialize Rx queue\n"); |
| 3174 | goto error; |
| 3175 | } |
| 3176 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3177 | retry: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3178 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3179 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3180 | priv->status &= ~STATUS_INT_ENABLED; |
| 3181 | |
| 3182 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3183 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3184 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3185 | ipw_stop_nic(priv); |
| 3186 | |
| 3187 | rc = ipw_reset_nic(priv); |
| 3188 | if (rc) { |
| 3189 | IPW_ERROR("Unable to reset NIC\n"); |
| 3190 | goto error; |
| 3191 | } |
| 3192 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3193 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
| 3194 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3195 | |
| 3196 | /* DMA the initial boot firmware into the device */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3197 | rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3198 | bootfw->size - sizeof(struct fw_header)); |
| 3199 | if (rc < 0) { |
| 3200 | IPW_ERROR("Unable to load boot firmware\n"); |
| 3201 | goto error; |
| 3202 | } |
| 3203 | |
| 3204 | /* kick start the device */ |
| 3205 | ipw_start_nic(priv); |
| 3206 | |
| 3207 | /* wait for the device to finish it's initial startup sequence */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3208 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3209 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3210 | if (rc < 0) { |
| 3211 | IPW_ERROR("device failed to boot initial fw image\n"); |
| 3212 | goto error; |
| 3213 | } |
| 3214 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); |
| 3215 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3216 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3217 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3218 | |
| 3219 | /* DMA the ucode into the device */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3220 | rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3221 | ucode->size - sizeof(struct fw_header)); |
| 3222 | if (rc < 0) { |
| 3223 | IPW_ERROR("Unable to load ucode\n"); |
| 3224 | goto error; |
| 3225 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3226 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3227 | /* stop nic */ |
| 3228 | ipw_stop_nic(priv); |
| 3229 | |
| 3230 | /* DMA bss firmware into the device */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3231 | rc = ipw_load_firmware(priv, firmware->data + |
| 3232 | sizeof(struct fw_header), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3233 | firmware->size - sizeof(struct fw_header)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3234 | if (rc < 0) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3235 | IPW_ERROR("Unable to load firmware\n"); |
| 3236 | goto error; |
| 3237 | } |
| 3238 | |
| 3239 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
| 3240 | |
| 3241 | rc = ipw_queue_reset(priv); |
| 3242 | if (rc) { |
| 3243 | IPW_ERROR("Unable to initialize queues\n"); |
| 3244 | goto error; |
| 3245 | } |
| 3246 | |
| 3247 | /* Ensure interrupts are disabled */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3248 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3249 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3250 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3251 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3252 | /* kick start the device */ |
| 3253 | ipw_start_nic(priv); |
| 3254 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3255 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3256 | if (retries > 0) { |
| 3257 | IPW_WARNING("Parity error. Retrying init.\n"); |
| 3258 | retries--; |
| 3259 | goto retry; |
| 3260 | } |
| 3261 | |
| 3262 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); |
| 3263 | rc = -EIO; |
| 3264 | goto error; |
| 3265 | } |
| 3266 | |
| 3267 | /* wait for the device */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3268 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
| 3269 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3270 | if (rc < 0) { |
| 3271 | IPW_ERROR("device failed to start after 500ms\n"); |
| 3272 | goto error; |
| 3273 | } |
| 3274 | IPW_DEBUG_INFO("device response after %dms\n", rc); |
| 3275 | |
| 3276 | /* ack fw init done interrupt */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3277 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3278 | |
| 3279 | /* read eeprom data and initialize the eeprom region of sram */ |
| 3280 | priv->eeprom_delay = 1; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3281 | ipw_eeprom_init_sram(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3282 | |
| 3283 | /* enable interrupts */ |
| 3284 | ipw_enable_interrupts(priv); |
| 3285 | |
| 3286 | /* Ensure our queue has valid packets */ |
| 3287 | ipw_rx_queue_replenish(priv); |
| 3288 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3289 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3290 | |
| 3291 | /* ack pending interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 3292 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3293 | |
| 3294 | #ifndef CONFIG_PM |
| 3295 | release_firmware(bootfw); |
| 3296 | release_firmware(ucode); |
| 3297 | release_firmware(firmware); |
| 3298 | #endif |
| 3299 | return 0; |
| 3300 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3301 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3302 | if (priv->rxq) { |
| 3303 | ipw_rx_queue_free(priv, priv->rxq); |
| 3304 | priv->rxq = NULL; |
| 3305 | } |
| 3306 | ipw_tx_queue_free(priv); |
| 3307 | if (bootfw) |
| 3308 | release_firmware(bootfw); |
| 3309 | if (ucode) |
| 3310 | release_firmware(ucode); |
| 3311 | if (firmware) |
| 3312 | release_firmware(firmware); |
| 3313 | #ifdef CONFIG_PM |
| 3314 | fw_loaded = 0; |
| 3315 | bootfw = ucode = firmware = NULL; |
| 3316 | #endif |
| 3317 | |
| 3318 | return rc; |
| 3319 | } |
| 3320 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3321 | /** |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3322 | * DMA services |
| 3323 | * |
| 3324 | * Theory of operation |
| 3325 | * |
| 3326 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 3327 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 3328 | * |
| 3329 | * 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] | 3330 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 3331 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3332 | * Tx queue resumed. |
| 3333 | * |
| 3334 | * The IPW operates with six queues, one receive queue in the device's |
| 3335 | * sram, one transmit queue for sending commands to the device firmware, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3336 | * and four transmit queues for data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3337 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3338 | * The four transmit queues allow for performing quality of service (qos) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3339 | * transmissions as per the 802.11 protocol. Currently Linux does not |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3340 | * provide a mechanism to the user for utilizing prioritized queues, so |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3341 | * we only utilize the first data transmit queue (queue1). |
| 3342 | */ |
| 3343 | |
| 3344 | /** |
| 3345 | * Driver allocates buffers of this size for Rx |
| 3346 | */ |
| 3347 | |
| 3348 | static inline int ipw_queue_space(const struct clx2_queue *q) |
| 3349 | { |
| 3350 | int s = q->last_used - q->first_empty; |
| 3351 | if (s <= 0) |
| 3352 | s += q->n_bd; |
| 3353 | s -= 2; /* keep some reserve to not confuse empty and full situations */ |
| 3354 | if (s < 0) |
| 3355 | s = 0; |
| 3356 | return s; |
| 3357 | } |
| 3358 | |
| 3359 | static inline int ipw_queue_inc_wrap(int index, int n_bd) |
| 3360 | { |
| 3361 | return (++index == n_bd) ? 0 : index; |
| 3362 | } |
| 3363 | |
| 3364 | /** |
| 3365 | * Initialize common DMA queue structure |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3366 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3367 | * @param q queue to init |
| 3368 | * @param count Number of BD's to allocate. Should be power of 2 |
| 3369 | * @param read_register Address for 'read' register |
| 3370 | * (not offset within BAR, full address) |
| 3371 | * @param write_register Address for 'write' register |
| 3372 | * (not offset within BAR, full address) |
| 3373 | * @param base_register Address for 'base' register |
| 3374 | * (not offset within BAR, full address) |
| 3375 | * @param size Address for 'size' register |
| 3376 | * (not offset within BAR, full address) |
| 3377 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3378 | 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] | 3379 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3380 | { |
| 3381 | q->n_bd = count; |
| 3382 | |
| 3383 | q->low_mark = q->n_bd / 4; |
| 3384 | if (q->low_mark < 4) |
| 3385 | q->low_mark = 4; |
| 3386 | |
| 3387 | q->high_mark = q->n_bd / 8; |
| 3388 | if (q->high_mark < 2) |
| 3389 | q->high_mark = 2; |
| 3390 | |
| 3391 | q->first_empty = q->last_used = 0; |
| 3392 | q->reg_r = read; |
| 3393 | q->reg_w = write; |
| 3394 | |
| 3395 | ipw_write32(priv, base, q->dma_addr); |
| 3396 | ipw_write32(priv, size, count); |
| 3397 | ipw_write32(priv, read, 0); |
| 3398 | ipw_write32(priv, write, 0); |
| 3399 | |
| 3400 | _ipw_read32(priv, 0x90); |
| 3401 | } |
| 3402 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3403 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3404 | struct clx2_tx_queue *q, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3405 | int count, u32 read, u32 write, u32 base, u32 size) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3406 | { |
| 3407 | struct pci_dev *dev = priv->pci_dev; |
| 3408 | |
| 3409 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); |
| 3410 | if (!q->txb) { |
| 3411 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); |
| 3412 | return -ENOMEM; |
| 3413 | } |
| 3414 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3415 | q->bd = |
| 3416 | 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] | 3417 | if (!q->bd) { |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 3418 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3419 | sizeof(q->bd[0]) * count); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3420 | kfree(q->txb); |
| 3421 | q->txb = NULL; |
| 3422 | return -ENOMEM; |
| 3423 | } |
| 3424 | |
| 3425 | ipw_queue_init(priv, &q->q, count, read, write, base, size); |
| 3426 | return 0; |
| 3427 | } |
| 3428 | |
| 3429 | /** |
| 3430 | * Free one TFD, those at index [txq->q.last_used]. |
| 3431 | * Do NOT advance any indexes |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3432 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3433 | * @param dev |
| 3434 | * @param txq |
| 3435 | */ |
| 3436 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, |
| 3437 | struct clx2_tx_queue *txq) |
| 3438 | { |
| 3439 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; |
| 3440 | struct pci_dev *dev = priv->pci_dev; |
| 3441 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3442 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3443 | /* classify bd */ |
| 3444 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) |
| 3445 | /* nothing to cleanup after for host commands */ |
| 3446 | return; |
| 3447 | |
| 3448 | /* sanity check */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3449 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
| 3450 | IPW_ERROR("Too many chunks: %i\n", |
| 3451 | le32_to_cpu(bd->u.data.num_chunks)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3452 | /** @todo issue fatal error, it is quite serious situation */ |
| 3453 | return; |
| 3454 | } |
| 3455 | |
| 3456 | /* unmap chunks if any */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3457 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
| 3458 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), |
| 3459 | le16_to_cpu(bd->u.data.chunk_len[i]), |
| 3460 | PCI_DMA_TODEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3461 | if (txq->txb[txq->q.last_used]) { |
| 3462 | ieee80211_txb_free(txq->txb[txq->q.last_used]); |
| 3463 | txq->txb[txq->q.last_used] = NULL; |
| 3464 | } |
| 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | /** |
| 3469 | * Deallocate DMA queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3470 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3471 | * Empty queue by removing and destroying all BD's. |
| 3472 | * Free all buffers. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3473 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3474 | * @param dev |
| 3475 | * @param q |
| 3476 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3477 | 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] | 3478 | { |
| 3479 | struct clx2_queue *q = &txq->q; |
| 3480 | struct pci_dev *dev = priv->pci_dev; |
| 3481 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3482 | if (q->n_bd == 0) |
| 3483 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3484 | |
| 3485 | /* first, empty all BD's */ |
| 3486 | for (; q->first_empty != q->last_used; |
| 3487 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3488 | ipw_queue_tx_free_tfd(priv, txq); |
| 3489 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3490 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3491 | /* free buffers belonging to queue itself */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3492 | 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] | 3493 | q->dma_addr); |
| 3494 | kfree(txq->txb); |
| 3495 | |
| 3496 | /* 0 fill whole structure */ |
| 3497 | memset(txq, 0, sizeof(*txq)); |
| 3498 | } |
| 3499 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3500 | /** |
| 3501 | * Destroy all DMA queues and structures |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3502 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3503 | * @param priv |
| 3504 | */ |
| 3505 | static void ipw_tx_queue_free(struct ipw_priv *priv) |
| 3506 | { |
| 3507 | /* Tx CMD queue */ |
| 3508 | ipw_queue_tx_free(priv, &priv->txq_cmd); |
| 3509 | |
| 3510 | /* Tx queues */ |
| 3511 | ipw_queue_tx_free(priv, &priv->txq[0]); |
| 3512 | ipw_queue_tx_free(priv, &priv->txq[1]); |
| 3513 | ipw_queue_tx_free(priv, &priv->txq[2]); |
| 3514 | ipw_queue_tx_free(priv, &priv->txq[3]); |
| 3515 | } |
| 3516 | |
| 3517 | static void inline __maybe_wake_tx(struct ipw_priv *priv) |
| 3518 | { |
| 3519 | if (netif_running(priv->net_dev)) { |
| 3520 | switch (priv->port_type) { |
| 3521 | case DCR_TYPE_MU_BSS: |
| 3522 | case DCR_TYPE_MU_IBSS: |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 3523 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3524 | return; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3525 | } |
| 3526 | netif_wake_queue(priv->net_dev); |
| 3527 | } |
| 3528 | |
| 3529 | } |
| 3530 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3531 | static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3532 | { |
| 3533 | /* First 3 bytes are manufacturer */ |
| 3534 | bssid[0] = priv->mac_addr[0]; |
| 3535 | bssid[1] = priv->mac_addr[1]; |
| 3536 | bssid[2] = priv->mac_addr[2]; |
| 3537 | |
| 3538 | /* Last bytes are random */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3539 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3540 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3541 | bssid[0] &= 0xfe; /* clear multicast bit */ |
| 3542 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3543 | } |
| 3544 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3545 | static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3546 | { |
| 3547 | struct ipw_station_entry entry; |
| 3548 | int i; |
| 3549 | |
| 3550 | for (i = 0; i < priv->num_stations; i++) { |
| 3551 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { |
| 3552 | /* Another node is active in network */ |
| 3553 | priv->missed_adhoc_beacons = 0; |
| 3554 | if (!(priv->config & CFG_STATIC_CHANNEL)) |
| 3555 | /* when other nodes drop out, we drop out */ |
| 3556 | priv->config &= ~CFG_ADHOC_PERSIST; |
| 3557 | |
| 3558 | return i; |
| 3559 | } |
| 3560 | } |
| 3561 | |
| 3562 | if (i == MAX_STATIONS) |
| 3563 | return IPW_INVALID_STATION; |
| 3564 | |
| 3565 | IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid)); |
| 3566 | |
| 3567 | entry.reserved = 0; |
| 3568 | entry.support_mode = 0; |
| 3569 | memcpy(entry.mac_addr, bssid, ETH_ALEN); |
| 3570 | memcpy(priv->stations[i], bssid, ETH_ALEN); |
| 3571 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3572 | &entry, sizeof(entry)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3573 | priv->num_stations++; |
| 3574 | |
| 3575 | return i; |
| 3576 | } |
| 3577 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3578 | static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3579 | { |
| 3580 | int i; |
| 3581 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3582 | for (i = 0; i < priv->num_stations; i++) |
| 3583 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3584 | return i; |
| 3585 | |
| 3586 | return IPW_INVALID_STATION; |
| 3587 | } |
| 3588 | |
| 3589 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) |
| 3590 | { |
| 3591 | int err; |
| 3592 | |
| 3593 | if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) { |
| 3594 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
| 3595 | return; |
| 3596 | } |
| 3597 | |
| 3598 | IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " " |
| 3599 | "on channel %d.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3600 | MAC_ARG(priv->assoc_request.bssid), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3601 | priv->assoc_request.channel); |
| 3602 | |
| 3603 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); |
| 3604 | priv->status |= STATUS_DISASSOCIATING; |
| 3605 | |
| 3606 | if (quiet) |
| 3607 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; |
| 3608 | else |
| 3609 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; |
| 3610 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 3611 | if (err) { |
| 3612 | IPW_DEBUG_HC("Attempt to send [dis]associate command " |
| 3613 | "failed.\n"); |
| 3614 | return; |
| 3615 | } |
| 3616 | |
| 3617 | } |
| 3618 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3619 | static int ipw_disassociate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3620 | { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3621 | struct ipw_priv *priv = data; |
| 3622 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) |
| 3623 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3624 | ipw_send_disassociate(data, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3625 | return 1; |
| 3626 | } |
| 3627 | |
| 3628 | static void ipw_bg_disassociate(void *data) |
| 3629 | { |
| 3630 | struct ipw_priv *priv = data; |
| 3631 | down(&priv->sem); |
| 3632 | ipw_disassociate(data); |
| 3633 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3634 | } |
| 3635 | |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 3636 | static void ipw_system_config(void *data) |
| 3637 | { |
| 3638 | struct ipw_priv *priv = data; |
| 3639 | ipw_send_system_config(priv, &priv->sys_config); |
| 3640 | } |
| 3641 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3642 | struct ipw_status_code { |
| 3643 | u16 status; |
| 3644 | const char *reason; |
| 3645 | }; |
| 3646 | |
| 3647 | static const struct ipw_status_code ipw_status_codes[] = { |
| 3648 | {0x00, "Successful"}, |
| 3649 | {0x01, "Unspecified failure"}, |
| 3650 | {0x0A, "Cannot support all requested capabilities in the " |
| 3651 | "Capability information field"}, |
| 3652 | {0x0B, "Reassociation denied due to inability to confirm that " |
| 3653 | "association exists"}, |
| 3654 | {0x0C, "Association denied due to reason outside the scope of this " |
| 3655 | "standard"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3656 | {0x0D, |
| 3657 | "Responding station does not support the specified authentication " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3658 | "algorithm"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3659 | {0x0E, |
| 3660 | "Received an Authentication frame with authentication sequence " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3661 | "transaction sequence number out of expected sequence"}, |
| 3662 | {0x0F, "Authentication rejected because of challenge failure"}, |
| 3663 | {0x10, "Authentication rejected due to timeout waiting for next " |
| 3664 | "frame in sequence"}, |
| 3665 | {0x11, "Association denied because AP is unable to handle additional " |
| 3666 | "associated stations"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3667 | {0x12, |
| 3668 | "Association denied due to requesting station not supporting all " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3669 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3670 | {0x13, |
| 3671 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3672 | "short preamble operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3673 | {0x14, |
| 3674 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3675 | "PBCC encoding"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3676 | {0x15, |
| 3677 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3678 | "channel agility"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3679 | {0x19, |
| 3680 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3681 | "short slot operation"}, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3682 | {0x1A, |
| 3683 | "Association denied due to requesting station not supporting " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3684 | "DSSS-OFDM operation"}, |
| 3685 | {0x28, "Invalid Information Element"}, |
| 3686 | {0x29, "Group Cipher is not valid"}, |
| 3687 | {0x2A, "Pairwise Cipher is not valid"}, |
| 3688 | {0x2B, "AKMP is not valid"}, |
| 3689 | {0x2C, "Unsupported RSN IE version"}, |
| 3690 | {0x2D, "Invalid RSN IE Capabilities"}, |
| 3691 | {0x2E, "Cipher suite is rejected per security policy"}, |
| 3692 | }; |
| 3693 | |
| 3694 | #ifdef CONFIG_IPW_DEBUG |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3695 | static const char *ipw_get_status_code(u16 status) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3696 | { |
| 3697 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3698 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3699 | if (ipw_status_codes[i].status == (status & 0xff)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3700 | return ipw_status_codes[i].reason; |
| 3701 | return "Unknown status value."; |
| 3702 | } |
| 3703 | #endif |
| 3704 | |
| 3705 | static void inline average_init(struct average *avg) |
| 3706 | { |
| 3707 | memset(avg, 0, sizeof(*avg)); |
| 3708 | } |
| 3709 | |
| 3710 | static void inline average_add(struct average *avg, s16 val) |
| 3711 | { |
| 3712 | avg->sum -= avg->entries[avg->pos]; |
| 3713 | avg->sum += val; |
| 3714 | avg->entries[avg->pos++] = val; |
| 3715 | if (unlikely(avg->pos == AVG_ENTRIES)) { |
| 3716 | avg->init = 1; |
| 3717 | avg->pos = 0; |
| 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | static s16 inline average_value(struct average *avg) |
| 3722 | { |
| 3723 | if (!unlikely(avg->init)) { |
| 3724 | if (avg->pos) |
| 3725 | return avg->sum / avg->pos; |
| 3726 | return 0; |
| 3727 | } |
| 3728 | |
| 3729 | return avg->sum / AVG_ENTRIES; |
| 3730 | } |
| 3731 | |
| 3732 | static void ipw_reset_stats(struct ipw_priv *priv) |
| 3733 | { |
| 3734 | u32 len = sizeof(u32); |
| 3735 | |
| 3736 | priv->quality = 0; |
| 3737 | |
| 3738 | average_init(&priv->average_missed_beacons); |
| 3739 | average_init(&priv->average_rssi); |
| 3740 | average_init(&priv->average_noise); |
| 3741 | |
| 3742 | priv->last_rate = 0; |
| 3743 | priv->last_missed_beacons = 0; |
| 3744 | priv->last_rx_packets = 0; |
| 3745 | priv->last_tx_packets = 0; |
| 3746 | priv->last_tx_failures = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3747 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3748 | /* Firmware managed, reset only when NIC is restarted, so we have to |
| 3749 | * normalize on the current value */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3750 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3751 | &priv->last_rx_err, &len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3752 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3753 | &priv->last_tx_failures, &len); |
| 3754 | |
| 3755 | /* Driver managed, reset with each association */ |
| 3756 | priv->missed_adhoc_beacons = 0; |
| 3757 | priv->missed_beacons = 0; |
| 3758 | priv->tx_packets = 0; |
| 3759 | priv->rx_packets = 0; |
| 3760 | |
| 3761 | } |
| 3762 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3763 | static inline u32 ipw_get_max_rate(struct ipw_priv *priv) |
| 3764 | { |
| 3765 | u32 i = 0x80000000; |
| 3766 | u32 mask = priv->rates_mask; |
| 3767 | /* If currently associated in B mode, restrict the maximum |
| 3768 | * rate match to B rates */ |
| 3769 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
| 3770 | mask &= IEEE80211_CCK_RATES_MASK; |
| 3771 | |
| 3772 | /* TODO: Verify that the rate is supported by the current rates |
| 3773 | * list. */ |
| 3774 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3775 | while (i && !(mask & i)) |
| 3776 | i >>= 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3777 | switch (i) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3778 | case IEEE80211_CCK_RATE_1MB_MASK: |
| 3779 | return 1000000; |
| 3780 | case IEEE80211_CCK_RATE_2MB_MASK: |
| 3781 | return 2000000; |
| 3782 | case IEEE80211_CCK_RATE_5MB_MASK: |
| 3783 | return 5500000; |
| 3784 | case IEEE80211_OFDM_RATE_6MB_MASK: |
| 3785 | return 6000000; |
| 3786 | case IEEE80211_OFDM_RATE_9MB_MASK: |
| 3787 | return 9000000; |
| 3788 | case IEEE80211_CCK_RATE_11MB_MASK: |
| 3789 | return 11000000; |
| 3790 | case IEEE80211_OFDM_RATE_12MB_MASK: |
| 3791 | return 12000000; |
| 3792 | case IEEE80211_OFDM_RATE_18MB_MASK: |
| 3793 | return 18000000; |
| 3794 | case IEEE80211_OFDM_RATE_24MB_MASK: |
| 3795 | return 24000000; |
| 3796 | case IEEE80211_OFDM_RATE_36MB_MASK: |
| 3797 | return 36000000; |
| 3798 | case IEEE80211_OFDM_RATE_48MB_MASK: |
| 3799 | return 48000000; |
| 3800 | case IEEE80211_OFDM_RATE_54MB_MASK: |
| 3801 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3802 | } |
| 3803 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3804 | if (priv->ieee->mode == IEEE_B) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3805 | return 11000000; |
| 3806 | else |
| 3807 | return 54000000; |
| 3808 | } |
| 3809 | |
| 3810 | static u32 ipw_get_current_rate(struct ipw_priv *priv) |
| 3811 | { |
| 3812 | u32 rate, len = sizeof(rate); |
| 3813 | int err; |
| 3814 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3815 | if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3816 | return 0; |
| 3817 | |
| 3818 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3819 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3820 | &len); |
| 3821 | if (err) { |
| 3822 | IPW_DEBUG_INFO("failed querying ordinals.\n"); |
| 3823 | return 0; |
| 3824 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3825 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3826 | return ipw_get_max_rate(priv); |
| 3827 | |
| 3828 | switch (rate) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3829 | case IPW_TX_RATE_1MB: |
| 3830 | return 1000000; |
| 3831 | case IPW_TX_RATE_2MB: |
| 3832 | return 2000000; |
| 3833 | case IPW_TX_RATE_5MB: |
| 3834 | return 5500000; |
| 3835 | case IPW_TX_RATE_6MB: |
| 3836 | return 6000000; |
| 3837 | case IPW_TX_RATE_9MB: |
| 3838 | return 9000000; |
| 3839 | case IPW_TX_RATE_11MB: |
| 3840 | return 11000000; |
| 3841 | case IPW_TX_RATE_12MB: |
| 3842 | return 12000000; |
| 3843 | case IPW_TX_RATE_18MB: |
| 3844 | return 18000000; |
| 3845 | case IPW_TX_RATE_24MB: |
| 3846 | return 24000000; |
| 3847 | case IPW_TX_RATE_36MB: |
| 3848 | return 36000000; |
| 3849 | case IPW_TX_RATE_48MB: |
| 3850 | return 48000000; |
| 3851 | case IPW_TX_RATE_54MB: |
| 3852 | return 54000000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | return 0; |
| 3856 | } |
| 3857 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3858 | #define IPW_STATS_INTERVAL (2 * HZ) |
| 3859 | static void ipw_gather_stats(struct ipw_priv *priv) |
| 3860 | { |
| 3861 | u32 rx_err, rx_err_delta, rx_packets_delta; |
| 3862 | u32 tx_failures, tx_failures_delta, tx_packets_delta; |
| 3863 | u32 missed_beacons_percent, missed_beacons_delta; |
| 3864 | u32 quality = 0; |
| 3865 | u32 len = sizeof(u32); |
| 3866 | s16 rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3867 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3868 | rate_quality; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3869 | u32 max_rate; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3870 | |
| 3871 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 3872 | priv->quality = 0; |
| 3873 | return; |
| 3874 | } |
| 3875 | |
| 3876 | /* Update the statistics */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3877 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3878 | &priv->missed_beacons, &len); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3879 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3880 | priv->last_missed_beacons = priv->missed_beacons; |
| 3881 | if (priv->assoc_request.beacon_interval) { |
| 3882 | missed_beacons_percent = missed_beacons_delta * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3883 | (HZ * priv->assoc_request.beacon_interval) / |
| 3884 | (IPW_STATS_INTERVAL * 10); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3885 | } else { |
| 3886 | missed_beacons_percent = 0; |
| 3887 | } |
| 3888 | average_add(&priv->average_missed_beacons, missed_beacons_percent); |
| 3889 | |
| 3890 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); |
| 3891 | rx_err_delta = rx_err - priv->last_rx_err; |
| 3892 | priv->last_rx_err = rx_err; |
| 3893 | |
| 3894 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); |
| 3895 | tx_failures_delta = tx_failures - priv->last_tx_failures; |
| 3896 | priv->last_tx_failures = tx_failures; |
| 3897 | |
| 3898 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; |
| 3899 | priv->last_rx_packets = priv->rx_packets; |
| 3900 | |
| 3901 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; |
| 3902 | priv->last_tx_packets = priv->tx_packets; |
| 3903 | |
| 3904 | /* Calculate quality based on the following: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3905 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3906 | * Missed beacon: 100% = 0, 0% = 70% missed |
| 3907 | * Rate: 60% = 1Mbs, 100% = Max |
| 3908 | * Rx and Tx errors represent a straight % of total Rx/Tx |
| 3909 | * RSSI: 100% = > -50, 0% = < -80 |
| 3910 | * Rx errors: 100% = 0, 0% = 50% missed |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3911 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3912 | * The lowest computed quality is used. |
| 3913 | * |
| 3914 | */ |
| 3915 | #define BEACON_THRESHOLD 5 |
| 3916 | beacon_quality = 100 - missed_beacons_percent; |
| 3917 | if (beacon_quality < BEACON_THRESHOLD) |
| 3918 | beacon_quality = 0; |
| 3919 | else |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3920 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3921 | (100 - BEACON_THRESHOLD); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3922 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3923 | beacon_quality, missed_beacons_percent); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3924 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3925 | priv->last_rate = ipw_get_current_rate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3926 | max_rate = ipw_get_max_rate(priv); |
| 3927 | rate_quality = priv->last_rate * 40 / max_rate + 60; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3928 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
| 3929 | rate_quality, priv->last_rate / 1000000); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3930 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3931 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3932 | rx_quality = 100 - (rx_err_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3933 | (rx_packets_delta + rx_err_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3934 | else |
| 3935 | rx_quality = 100; |
| 3936 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", |
| 3937 | rx_quality, rx_err_delta, rx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3938 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3939 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3940 | tx_quality = 100 - (tx_failures_delta * 100) / |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3941 | (tx_packets_delta + tx_failures_delta); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3942 | else |
| 3943 | tx_quality = 100; |
| 3944 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", |
| 3945 | tx_quality, tx_failures_delta, tx_packets_delta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3946 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3947 | rssi = average_value(&priv->average_rssi); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3948 | signal_quality = |
| 3949 | (100 * |
| 3950 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 3951 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - |
| 3952 | (priv->ieee->perfect_rssi - rssi) * |
| 3953 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + |
| 3954 | 62 * (priv->ieee->perfect_rssi - rssi))) / |
| 3955 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * |
| 3956 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); |
| 3957 | if (signal_quality > 100) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3958 | signal_quality = 100; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3959 | else if (signal_quality < 1) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3960 | signal_quality = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3961 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3962 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
| 3963 | signal_quality, rssi); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3964 | |
| 3965 | quality = min(beacon_quality, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3966 | min(rate_quality, |
| 3967 | min(tx_quality, min(rx_quality, signal_quality)))); |
| 3968 | if (quality == beacon_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3969 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
| 3970 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3971 | if (quality == rate_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3972 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
| 3973 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3974 | if (quality == tx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3975 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
| 3976 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3977 | if (quality == rx_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3978 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
| 3979 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3980 | if (quality == signal_quality) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 3981 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
| 3982 | quality); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3983 | |
| 3984 | priv->quality = quality; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 3985 | |
| 3986 | queue_delayed_work(priv->workqueue, &priv->gather_stats, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 3987 | IPW_STATS_INTERVAL); |
| 3988 | } |
| 3989 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 3990 | static void ipw_bg_gather_stats(void *data) |
| 3991 | { |
| 3992 | struct ipw_priv *priv = data; |
| 3993 | down(&priv->sem); |
| 3994 | ipw_gather_stats(data); |
| 3995 | up(&priv->sem); |
| 3996 | } |
| 3997 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 3998 | static inline void ipw_handle_missed_beacon(struct ipw_priv *priv, |
| 3999 | int missed_count) |
| 4000 | { |
| 4001 | priv->notif_missed_beacons = missed_count; |
| 4002 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4003 | if (missed_count > priv->disassociate_threshold && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4004 | priv->status & STATUS_ASSOCIATED) { |
| 4005 | /* If associated and we've hit the missed |
| 4006 | * beacon threshold, disassociate, turn |
| 4007 | * off roaming, and abort any active scans */ |
| 4008 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4009 | IPW_DL_STATE | IPW_DL_ASSOC, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4010 | "Missed beacon: %d - disassociate\n", missed_count); |
| 4011 | priv->status &= ~STATUS_ROAMING; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4012 | if (priv->status & STATUS_SCANNING) { |
| 4013 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 4014 | IPW_DL_STATE, |
| 4015 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4016 | queue_work(priv->workqueue, &priv->abort_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4017 | } |
| 4018 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4019 | queue_work(priv->workqueue, &priv->disassociate); |
| 4020 | return; |
| 4021 | } |
| 4022 | |
| 4023 | if (priv->status & STATUS_ROAMING) { |
| 4024 | /* If we are currently roaming, then just |
| 4025 | * print a debug statement... */ |
| 4026 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4027 | "Missed beacon: %d - roam in progress\n", |
| 4028 | missed_count); |
| 4029 | return; |
| 4030 | } |
| 4031 | |
| 4032 | if (missed_count > priv->roaming_threshold) { |
| 4033 | /* If we are not already roaming, set the ROAM |
| 4034 | * bit in the status and kick off a scan */ |
| 4035 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4036 | "Missed beacon: %d - initiate " |
| 4037 | "roaming\n", missed_count); |
| 4038 | if (!(priv->status & STATUS_ROAMING)) { |
| 4039 | priv->status |= STATUS_ROAMING; |
| 4040 | if (!(priv->status & STATUS_SCANNING)) |
| 4041 | queue_work(priv->workqueue, |
| 4042 | &priv->request_scan); |
| 4043 | } |
| 4044 | return; |
| 4045 | } |
| 4046 | |
| 4047 | if (priv->status & STATUS_SCANNING) { |
| 4048 | /* Stop scan to keep fw from getting |
| 4049 | * stuck (only if we aren't roaming -- |
| 4050 | * otherwise we'll never scan more than 2 or 3 |
| 4051 | * channels..) */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4052 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
| 4053 | "Aborting scan with missed beacon.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4054 | queue_work(priv->workqueue, &priv->abort_scan); |
| 4055 | } |
| 4056 | |
| 4057 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); |
| 4058 | |
| 4059 | } |
| 4060 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4061 | /** |
| 4062 | * Handle host notification packet. |
| 4063 | * Called from interrupt routine |
| 4064 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4065 | static inline void ipw_rx_notification(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4066 | struct ipw_rx_notification *notif) |
| 4067 | { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4068 | notif->size = le16_to_cpu(notif->size); |
| 4069 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4070 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4071 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4072 | switch (notif->subtype) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4073 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
| 4074 | struct notif_association *assoc = ¬if->u.assoc; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4075 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4076 | switch (assoc->state) { |
| 4077 | case CMAS_ASSOCIATED:{ |
| 4078 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4079 | IPW_DL_ASSOC, |
| 4080 | "associated: '%s' " MAC_FMT |
| 4081 | " \n", |
| 4082 | escape_essid(priv->essid, |
| 4083 | priv->essid_len), |
| 4084 | MAC_ARG(priv->bssid)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4085 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4086 | switch (priv->ieee->iw_mode) { |
| 4087 | case IW_MODE_INFRA: |
| 4088 | memcpy(priv->ieee->bssid, |
| 4089 | priv->bssid, ETH_ALEN); |
| 4090 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4091 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4092 | case IW_MODE_ADHOC: |
| 4093 | memcpy(priv->ieee->bssid, |
| 4094 | priv->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4095 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4096 | /* clear out the station table */ |
| 4097 | priv->num_stations = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4098 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4099 | IPW_DEBUG_ASSOC |
| 4100 | ("queueing adhoc check\n"); |
| 4101 | queue_delayed_work(priv-> |
| 4102 | workqueue, |
| 4103 | &priv-> |
| 4104 | adhoc_check, |
| 4105 | priv-> |
| 4106 | assoc_request. |
| 4107 | beacon_interval); |
| 4108 | break; |
| 4109 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4110 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4111 | priv->status &= ~STATUS_ASSOCIATING; |
| 4112 | priv->status |= STATUS_ASSOCIATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 4113 | queue_work(priv->workqueue, |
| 4114 | &priv->system_config); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4115 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4116 | #ifdef CONFIG_IPW_QOS |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4117 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
| 4118 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl)) |
| 4119 | if ((priv->status & STATUS_AUTH) && |
| 4120 | (IPW_GET_PACKET_STYPE(¬if->u.raw) |
| 4121 | == IEEE80211_STYPE_ASSOC_RESP)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4122 | if ((sizeof |
| 4123 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4124 | ieee80211_assoc_response) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4125 | <= notif->size) |
| 4126 | && (notif->size <= 2314)) { |
| 4127 | struct |
| 4128 | ieee80211_rx_stats |
| 4129 | stats = { |
| 4130 | .len = |
| 4131 | notif-> |
| 4132 | size - 1, |
| 4133 | }; |
| 4134 | |
| 4135 | IPW_DEBUG_QOS |
| 4136 | ("QoS Associate " |
| 4137 | "size %d\n", |
| 4138 | notif->size); |
| 4139 | ieee80211_rx_mgt(priv-> |
| 4140 | ieee, |
| 4141 | (struct |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 4142 | ieee80211_hdr_4addr |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4143 | *) |
| 4144 | ¬if->u.raw, &stats); |
| 4145 | } |
| 4146 | } |
| 4147 | #endif |
| 4148 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4149 | schedule_work(&priv->link_up); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4150 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4151 | break; |
| 4152 | } |
| 4153 | |
| 4154 | case CMAS_AUTHENTICATED:{ |
| 4155 | if (priv-> |
| 4156 | status & (STATUS_ASSOCIATED | |
| 4157 | STATUS_AUTH)) { |
| 4158 | #ifdef CONFIG_IPW_DEBUG |
| 4159 | struct notif_authenticate *auth |
| 4160 | = ¬if->u.auth; |
| 4161 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4162 | IPW_DL_STATE | |
| 4163 | IPW_DL_ASSOC, |
| 4164 | "deauthenticated: '%s' " |
| 4165 | MAC_FMT |
| 4166 | ": (0x%04X) - %s \n", |
| 4167 | escape_essid(priv-> |
| 4168 | essid, |
| 4169 | priv-> |
| 4170 | essid_len), |
| 4171 | MAC_ARG(priv->bssid), |
| 4172 | ntohs(auth->status), |
| 4173 | ipw_get_status_code |
| 4174 | (ntohs |
| 4175 | (auth->status))); |
| 4176 | #endif |
| 4177 | |
| 4178 | priv->status &= |
| 4179 | ~(STATUS_ASSOCIATING | |
| 4180 | STATUS_AUTH | |
| 4181 | STATUS_ASSOCIATED); |
| 4182 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4183 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4184 | break; |
| 4185 | } |
| 4186 | |
| 4187 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4188 | IPW_DL_ASSOC, |
| 4189 | "authenticated: '%s' " MAC_FMT |
| 4190 | "\n", |
| 4191 | escape_essid(priv->essid, |
| 4192 | priv->essid_len), |
| 4193 | MAC_ARG(priv->bssid)); |
| 4194 | break; |
| 4195 | } |
| 4196 | |
| 4197 | case CMAS_INIT:{ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4198 | if (priv->status & STATUS_AUTH) { |
| 4199 | struct |
| 4200 | ieee80211_assoc_response |
| 4201 | *resp; |
| 4202 | resp = |
| 4203 | (struct |
| 4204 | ieee80211_assoc_response |
| 4205 | *)¬if->u.raw; |
| 4206 | IPW_DEBUG(IPW_DL_NOTIF | |
| 4207 | IPW_DL_STATE | |
| 4208 | IPW_DL_ASSOC, |
| 4209 | "association failed (0x%04X): %s\n", |
| 4210 | ntohs(resp->status), |
| 4211 | ipw_get_status_code |
| 4212 | (ntohs |
| 4213 | (resp->status))); |
| 4214 | } |
| 4215 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4216 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4217 | IPW_DL_ASSOC, |
| 4218 | "disassociated: '%s' " MAC_FMT |
| 4219 | " \n", |
| 4220 | escape_essid(priv->essid, |
| 4221 | priv->essid_len), |
| 4222 | MAC_ARG(priv->bssid)); |
| 4223 | |
| 4224 | priv->status &= |
| 4225 | ~(STATUS_DISASSOCIATING | |
| 4226 | STATUS_ASSOCIATING | |
| 4227 | STATUS_ASSOCIATED | STATUS_AUTH); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4228 | if (priv->assoc_network |
| 4229 | && (priv->assoc_network-> |
| 4230 | capability & |
| 4231 | WLAN_CAPABILITY_IBSS)) |
| 4232 | ipw_remove_current_network |
| 4233 | (priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4234 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4235 | schedule_work(&priv->link_down); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4236 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4237 | break; |
| 4238 | } |
| 4239 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4240 | case CMAS_RX_ASSOC_RESP: |
| 4241 | break; |
| 4242 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4243 | default: |
| 4244 | IPW_ERROR("assoc: unknown (%d)\n", |
| 4245 | assoc->state); |
| 4246 | break; |
| 4247 | } |
| 4248 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4249 | break; |
| 4250 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4251 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4252 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
| 4253 | struct notif_authenticate *auth = ¬if->u.auth; |
| 4254 | switch (auth->state) { |
| 4255 | case CMAS_AUTHENTICATED: |
| 4256 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4257 | "authenticated: '%s' " MAC_FMT " \n", |
| 4258 | escape_essid(priv->essid, |
| 4259 | priv->essid_len), |
| 4260 | MAC_ARG(priv->bssid)); |
| 4261 | priv->status |= STATUS_AUTH; |
| 4262 | break; |
| 4263 | |
| 4264 | case CMAS_INIT: |
| 4265 | if (priv->status & STATUS_AUTH) { |
| 4266 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4267 | IPW_DL_ASSOC, |
| 4268 | "authentication failed (0x%04X): %s\n", |
| 4269 | ntohs(auth->status), |
| 4270 | ipw_get_status_code(ntohs |
| 4271 | (auth-> |
| 4272 | status))); |
| 4273 | } |
| 4274 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4275 | IPW_DL_ASSOC, |
| 4276 | "deauthenticated: '%s' " MAC_FMT "\n", |
| 4277 | escape_essid(priv->essid, |
| 4278 | priv->essid_len), |
| 4279 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4280 | |
| 4281 | priv->status &= ~(STATUS_ASSOCIATING | |
| 4282 | STATUS_AUTH | |
| 4283 | STATUS_ASSOCIATED); |
| 4284 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4285 | schedule_work(&priv->link_down); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4286 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4287 | |
| 4288 | case CMAS_TX_AUTH_SEQ_1: |
| 4289 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4290 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); |
| 4291 | break; |
| 4292 | case CMAS_RX_AUTH_SEQ_2: |
| 4293 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4294 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); |
| 4295 | break; |
| 4296 | case CMAS_AUTH_SEQ_1_PASS: |
| 4297 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4298 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); |
| 4299 | break; |
| 4300 | case CMAS_AUTH_SEQ_1_FAIL: |
| 4301 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4302 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); |
| 4303 | break; |
| 4304 | case CMAS_TX_AUTH_SEQ_3: |
| 4305 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4306 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); |
| 4307 | break; |
| 4308 | case CMAS_RX_AUTH_SEQ_4: |
| 4309 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4310 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); |
| 4311 | break; |
| 4312 | case CMAS_AUTH_SEQ_2_PASS: |
| 4313 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4314 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); |
| 4315 | break; |
| 4316 | case CMAS_AUTH_SEQ_2_FAIL: |
| 4317 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4318 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); |
| 4319 | break; |
| 4320 | case CMAS_TX_ASSOC: |
| 4321 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4322 | IPW_DL_ASSOC, "TX_ASSOC\n"); |
| 4323 | break; |
| 4324 | case CMAS_RX_ASSOC_RESP: |
| 4325 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4326 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4327 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4328 | break; |
| 4329 | case CMAS_ASSOCIATED: |
| 4330 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
| 4331 | IPW_DL_ASSOC, "ASSOCIATED\n"); |
| 4332 | break; |
| 4333 | default: |
| 4334 | IPW_DEBUG_NOTIF("auth: failure - %d\n", |
| 4335 | auth->state); |
| 4336 | break; |
| 4337 | } |
| 4338 | break; |
| 4339 | } |
| 4340 | |
| 4341 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
| 4342 | struct notif_channel_result *x = |
| 4343 | ¬if->u.channel_result; |
| 4344 | |
| 4345 | if (notif->size == sizeof(*x)) { |
| 4346 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
| 4347 | x->channel_num); |
| 4348 | } else { |
| 4349 | IPW_DEBUG_SCAN("Scan result of wrong size %d " |
| 4350 | "(should be %zd)\n", |
| 4351 | notif->size, sizeof(*x)); |
| 4352 | } |
| 4353 | break; |
| 4354 | } |
| 4355 | |
| 4356 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
| 4357 | struct notif_scan_complete *x = ¬if->u.scan_complete; |
| 4358 | if (notif->size == sizeof(*x)) { |
| 4359 | IPW_DEBUG_SCAN |
| 4360 | ("Scan completed: type %d, %d channels, " |
| 4361 | "%d status\n", x->scan_type, |
| 4362 | x->num_channels, x->status); |
| 4363 | } else { |
| 4364 | IPW_ERROR("Scan completed of wrong size %d " |
| 4365 | "(should be %zd)\n", |
| 4366 | notif->size, sizeof(*x)); |
| 4367 | } |
| 4368 | |
| 4369 | priv->status &= |
| 4370 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
| 4371 | |
| 4372 | cancel_delayed_work(&priv->scan_check); |
| 4373 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4374 | if (priv->status & STATUS_EXIT_PENDING) |
| 4375 | break; |
| 4376 | |
| 4377 | priv->ieee->scans++; |
| 4378 | |
| 4379 | #ifdef CONFIG_IPW2200_MONITOR |
| 4380 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4381 | priv->status |= STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4382 | queue_work(priv->workqueue, |
| 4383 | &priv->request_scan); |
| 4384 | break; |
| 4385 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4386 | priv->status &= ~STATUS_SCAN_FORCED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4387 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 4388 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4389 | if (!(priv->status & (STATUS_ASSOCIATED | |
| 4390 | STATUS_ASSOCIATING | |
| 4391 | STATUS_ROAMING | |
| 4392 | STATUS_DISASSOCIATING))) |
| 4393 | queue_work(priv->workqueue, &priv->associate); |
| 4394 | else if (priv->status & STATUS_ROAMING) { |
| 4395 | /* If a scan completed and we are in roam mode, then |
| 4396 | * the scan that completed was the one requested as a |
| 4397 | * result of entering roam... so, schedule the |
| 4398 | * roam work */ |
| 4399 | queue_work(priv->workqueue, &priv->roam); |
| 4400 | } else if (priv->status & STATUS_SCAN_PENDING) |
| 4401 | queue_work(priv->workqueue, |
| 4402 | &priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4403 | else if (priv->config & CFG_BACKGROUND_SCAN |
| 4404 | && priv->status & STATUS_ASSOCIATED) |
| 4405 | queue_delayed_work(priv->workqueue, |
| 4406 | &priv->request_scan, HZ); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4407 | break; |
| 4408 | } |
| 4409 | |
| 4410 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
| 4411 | struct notif_frag_length *x = ¬if->u.frag_len; |
| 4412 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4413 | if (notif->size == sizeof(*x)) |
| 4414 | IPW_ERROR("Frag length: %d\n", |
| 4415 | le16_to_cpu(x->frag_length)); |
| 4416 | else |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4417 | IPW_ERROR("Frag length of wrong size %d " |
| 4418 | "(should be %zd)\n", |
| 4419 | notif->size, sizeof(*x)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4420 | break; |
| 4421 | } |
| 4422 | |
| 4423 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
| 4424 | struct notif_link_deterioration *x = |
| 4425 | ¬if->u.link_deterioration; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 4426 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4427 | if (notif->size == sizeof(*x)) { |
| 4428 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
| 4429 | "link deterioration: '%s' " MAC_FMT |
| 4430 | " \n", escape_essid(priv->essid, |
| 4431 | priv->essid_len), |
| 4432 | MAC_ARG(priv->bssid)); |
| 4433 | memcpy(&priv->last_link_deterioration, x, |
| 4434 | sizeof(*x)); |
| 4435 | } else { |
| 4436 | IPW_ERROR("Link Deterioration of wrong size %d " |
| 4437 | "(should be %zd)\n", |
| 4438 | notif->size, sizeof(*x)); |
| 4439 | } |
| 4440 | break; |
| 4441 | } |
| 4442 | |
| 4443 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
| 4444 | IPW_ERROR("Dino config\n"); |
| 4445 | if (priv->hcmd |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4446 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4447 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4448 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4449 | break; |
| 4450 | } |
| 4451 | |
| 4452 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
| 4453 | struct notif_beacon_state *x = ¬if->u.beacon_state; |
| 4454 | if (notif->size != sizeof(*x)) { |
| 4455 | IPW_ERROR |
| 4456 | ("Beacon state of wrong size %d (should " |
| 4457 | "be %zd)\n", notif->size, sizeof(*x)); |
| 4458 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4459 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4460 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4461 | if (le32_to_cpu(x->state) == |
| 4462 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) |
| 4463 | ipw_handle_missed_beacon(priv, |
| 4464 | le32_to_cpu(x-> |
| 4465 | number)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4466 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4467 | break; |
| 4468 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4469 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4470 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
| 4471 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; |
| 4472 | if (notif->size == sizeof(*x)) { |
| 4473 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
| 4474 | "0x%02x station %d\n", |
| 4475 | x->key_state, x->security_type, |
| 4476 | x->station_index); |
| 4477 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4478 | } |
| 4479 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4480 | IPW_ERROR |
| 4481 | ("TGi Tx Key of wrong size %d (should be %zd)\n", |
| 4482 | notif->size, sizeof(*x)); |
| 4483 | break; |
| 4484 | } |
| 4485 | |
| 4486 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
| 4487 | struct notif_calibration *x = ¬if->u.calibration; |
| 4488 | |
| 4489 | if (notif->size == sizeof(*x)) { |
| 4490 | memcpy(&priv->calib, x, sizeof(*x)); |
| 4491 | IPW_DEBUG_INFO("TODO: Calibration\n"); |
| 4492 | break; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4493 | } |
| 4494 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4495 | IPW_ERROR |
| 4496 | ("Calibration of wrong size %d (should be %zd)\n", |
| 4497 | notif->size, sizeof(*x)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4498 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4499 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4500 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4501 | case HOST_NOTIFICATION_NOISE_STATS:{ |
| 4502 | if (notif->size == sizeof(u32)) { |
| 4503 | priv->last_noise = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4504 | (u8) (le32_to_cpu(notif->u.noise.value) & |
| 4505 | 0xff); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4506 | average_add(&priv->average_noise, |
| 4507 | priv->last_noise); |
| 4508 | break; |
| 4509 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4510 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4511 | IPW_ERROR |
| 4512 | ("Noise stat is wrong size %d (should be %zd)\n", |
| 4513 | notif->size, sizeof(u32)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4514 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4515 | } |
| 4516 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4517 | default: |
| 4518 | IPW_ERROR("Unknown notification: " |
| 4519 | "subtype=%d,flags=0x%2x,size=%d\n", |
| 4520 | notif->subtype, notif->flags, notif->size); |
| 4521 | } |
| 4522 | } |
| 4523 | |
| 4524 | /** |
| 4525 | * Destroys all DMA structures and initialise them again |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4526 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4527 | * @param priv |
| 4528 | * @return error code |
| 4529 | */ |
| 4530 | static int ipw_queue_reset(struct ipw_priv *priv) |
| 4531 | { |
| 4532 | int rc = 0; |
| 4533 | /** @todo customize queue sizes */ |
| 4534 | int nTx = 64, nTxCmd = 8; |
| 4535 | ipw_tx_queue_free(priv); |
| 4536 | /* Tx CMD queue */ |
| 4537 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4538 | IPW_TX_CMD_QUEUE_READ_INDEX, |
| 4539 | IPW_TX_CMD_QUEUE_WRITE_INDEX, |
| 4540 | IPW_TX_CMD_QUEUE_BD_BASE, |
| 4541 | IPW_TX_CMD_QUEUE_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4542 | if (rc) { |
| 4543 | IPW_ERROR("Tx Cmd queue init failed\n"); |
| 4544 | goto error; |
| 4545 | } |
| 4546 | /* Tx queue(s) */ |
| 4547 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4548 | IPW_TX_QUEUE_0_READ_INDEX, |
| 4549 | IPW_TX_QUEUE_0_WRITE_INDEX, |
| 4550 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4551 | if (rc) { |
| 4552 | IPW_ERROR("Tx 0 queue init failed\n"); |
| 4553 | goto error; |
| 4554 | } |
| 4555 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4556 | IPW_TX_QUEUE_1_READ_INDEX, |
| 4557 | IPW_TX_QUEUE_1_WRITE_INDEX, |
| 4558 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4559 | if (rc) { |
| 4560 | IPW_ERROR("Tx 1 queue init failed\n"); |
| 4561 | goto error; |
| 4562 | } |
| 4563 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4564 | IPW_TX_QUEUE_2_READ_INDEX, |
| 4565 | IPW_TX_QUEUE_2_WRITE_INDEX, |
| 4566 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4567 | if (rc) { |
| 4568 | IPW_ERROR("Tx 2 queue init failed\n"); |
| 4569 | goto error; |
| 4570 | } |
| 4571 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4572 | IPW_TX_QUEUE_3_READ_INDEX, |
| 4573 | IPW_TX_QUEUE_3_WRITE_INDEX, |
| 4574 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4575 | if (rc) { |
| 4576 | IPW_ERROR("Tx 3 queue init failed\n"); |
| 4577 | goto error; |
| 4578 | } |
| 4579 | /* statistics */ |
| 4580 | priv->rx_bufs_min = 0; |
| 4581 | priv->rx_pend_max = 0; |
| 4582 | return rc; |
| 4583 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4584 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4585 | ipw_tx_queue_free(priv); |
| 4586 | return rc; |
| 4587 | } |
| 4588 | |
| 4589 | /** |
| 4590 | * Reclaim Tx queue entries no more used by NIC. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4591 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4592 | * When FW adwances 'R' index, all entries between old and |
| 4593 | * new 'R' index need to be reclaimed. As result, some free space |
| 4594 | * forms. If there is enough free space (> low mark), wake Tx queue. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4595 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4596 | * @note Need to protect against garbage in 'R' index |
| 4597 | * @param priv |
| 4598 | * @param txq |
| 4599 | * @param qindex |
| 4600 | * @return Number of used entries remains in the queue |
| 4601 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4602 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4603 | struct clx2_tx_queue *txq, int qindex) |
| 4604 | { |
| 4605 | u32 hw_tail; |
| 4606 | int used; |
| 4607 | struct clx2_queue *q = &txq->q; |
| 4608 | |
| 4609 | hw_tail = ipw_read32(priv, q->reg_r); |
| 4610 | if (hw_tail >= q->n_bd) { |
| 4611 | IPW_ERROR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4612 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
| 4613 | hw_tail, q->n_bd); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4614 | goto done; |
| 4615 | } |
| 4616 | for (; q->last_used != hw_tail; |
| 4617 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 4618 | ipw_queue_tx_free_tfd(priv, txq); |
| 4619 | priv->tx_packets++; |
| 4620 | } |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4621 | done: |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4622 | if (ipw_queue_space(q) > q->low_mark && qindex >= 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4623 | __maybe_wake_tx(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4624 | used = q->first_empty - q->last_used; |
| 4625 | if (used < 0) |
| 4626 | used += q->n_bd; |
| 4627 | |
| 4628 | return used; |
| 4629 | } |
| 4630 | |
| 4631 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, |
| 4632 | int len, int sync) |
| 4633 | { |
| 4634 | struct clx2_tx_queue *txq = &priv->txq_cmd; |
| 4635 | struct clx2_queue *q = &txq->q; |
| 4636 | struct tfd_frame *tfd; |
| 4637 | |
| 4638 | if (ipw_queue_space(q) < (sync ? 1 : 2)) { |
| 4639 | IPW_ERROR("No space for Tx\n"); |
| 4640 | return -EBUSY; |
| 4641 | } |
| 4642 | |
| 4643 | tfd = &txq->bd[q->first_empty]; |
| 4644 | txq->txb[q->first_empty] = NULL; |
| 4645 | |
| 4646 | memset(tfd, 0, sizeof(*tfd)); |
| 4647 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; |
| 4648 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 4649 | priv->hcmd_seq++; |
| 4650 | tfd->u.cmd.index = hcmd; |
| 4651 | tfd->u.cmd.length = len; |
| 4652 | memcpy(tfd->u.cmd.payload, buf, len); |
| 4653 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 4654 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 4655 | _ipw_read32(priv, 0x90); |
| 4656 | |
| 4657 | return 0; |
| 4658 | } |
| 4659 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4660 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4661 | * Rx theory of operation |
| 4662 | * |
| 4663 | * The host allocates 32 DMA target addresses and passes the host address |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4664 | * 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] | 4665 | * 0 to 31 |
| 4666 | * |
| 4667 | * Rx Queue Indexes |
| 4668 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4669 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4670 | * The READ index maps to the first position that the firmware may be writing |
| 4671 | * to -- the driver can read up to (but not including) this position and get |
| 4672 | * good data. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4673 | * The READ index is managed by the firmware once the card is enabled. |
| 4674 | * |
| 4675 | * The WRITE index maps to the last position the driver has read from -- the |
| 4676 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4677 | * |
| 4678 | * 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] | 4679 | * WRITE = READ. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4680 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4681 | * 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] | 4682 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4683 | * |
| 4684 | * When the firmware places a packet in a buffer it will advance the READ index |
| 4685 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4686 | * process as many packets as possible, moving the WRITE index forward as it |
| 4687 | * resets the Rx queue buffers with new memory. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4688 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4689 | * The management in the driver is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4690 | * + 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] | 4691 | * 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] | 4692 | * to replensish the ipw->rxq->rx_free. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4693 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
| 4694 | * ipw->rxq is replenished and the READ INDEX is updated (updating the |
| 4695 | * 'processed' and 'read' driver indexes as well) |
| 4696 | * + A received packet is processed and handed to the kernel network stack, |
| 4697 | * detached from the ipw->rxq. The driver 'processed' index is updated. |
| 4698 | * + 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] | 4699 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
| 4700 | * 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] | 4701 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4702 | * |
| 4703 | * |
| 4704 | * Driver sequence: |
| 4705 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4706 | * ipw_rx_queue_alloc() Allocates rx_free |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4707 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
| 4708 | * ipw_rx_queue_restock |
| 4709 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 4710 | * queue, updates firmware pointers, and updates |
| 4711 | * the WRITE index. If insufficient rx_free buffers |
| 4712 | * are available, schedules ipw_rx_queue_replenish |
| 4713 | * |
| 4714 | * -- enable interrupts -- |
| 4715 | * 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] | 4716 | * READ INDEX, detaching the SKB from the pool. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4717 | * Moves the packet buffer from queue to rx_used. |
| 4718 | * Calls ipw_rx_queue_restock to refill any empty |
| 4719 | * slots. |
| 4720 | * ... |
| 4721 | * |
| 4722 | */ |
| 4723 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4724 | /* |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4725 | * If there are slots in the RX queue that need to be restocked, |
| 4726 | * and we have free pre-allocated buffers, fill the ranks as much |
| 4727 | * as we can pulling from rx_free. |
| 4728 | * |
| 4729 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4730 | * also updates the memory address in the firmware to reference the new |
| 4731 | * target buffer. |
| 4732 | */ |
| 4733 | static void ipw_rx_queue_restock(struct ipw_priv *priv) |
| 4734 | { |
| 4735 | struct ipw_rx_queue *rxq = priv->rxq; |
| 4736 | struct list_head *element; |
| 4737 | struct ipw_rx_mem_buffer *rxb; |
| 4738 | unsigned long flags; |
| 4739 | int write; |
| 4740 | |
| 4741 | spin_lock_irqsave(&rxq->lock, flags); |
| 4742 | write = rxq->write; |
| 4743 | while ((rxq->write != rxq->processed) && (rxq->free_count)) { |
| 4744 | element = rxq->rx_free.next; |
| 4745 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
| 4746 | list_del(element); |
| 4747 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4748 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4749 | rxb->dma_addr); |
| 4750 | rxq->queue[rxq->write] = rxb; |
| 4751 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; |
| 4752 | rxq->free_count--; |
| 4753 | } |
| 4754 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4755 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4756 | /* If the pre-allocated buffer pool is dropping low, schedule to |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4757 | * refill it */ |
| 4758 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4759 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4760 | |
| 4761 | /* 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] | 4762 | if (write != rxq->write) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4763 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4764 | } |
| 4765 | |
| 4766 | /* |
| 4767 | * 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] | 4768 | * Also restock the Rx queue via ipw_rx_queue_restock. |
| 4769 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4770 | * This is called as a scheduled work item (except for during intialization) |
| 4771 | */ |
| 4772 | static void ipw_rx_queue_replenish(void *data) |
| 4773 | { |
| 4774 | struct ipw_priv *priv = data; |
| 4775 | struct ipw_rx_queue *rxq = priv->rxq; |
| 4776 | struct list_head *element; |
| 4777 | struct ipw_rx_mem_buffer *rxb; |
| 4778 | unsigned long flags; |
| 4779 | |
| 4780 | spin_lock_irqsave(&rxq->lock, flags); |
| 4781 | while (!list_empty(&rxq->rx_used)) { |
| 4782 | element = rxq->rx_used.next; |
| 4783 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4784 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4785 | if (!rxb->skb) { |
| 4786 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", |
| 4787 | priv->net_dev->name); |
| 4788 | /* We don't reschedule replenish work here -- we will |
| 4789 | * call the restock method and if it still needs |
| 4790 | * more buffers it will schedule replenish */ |
| 4791 | break; |
| 4792 | } |
| 4793 | list_del(element); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4794 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4795 | rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4796 | rxb->dma_addr = |
| 4797 | pci_map_single(priv->pci_dev, rxb->skb->data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4798 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4799 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4800 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4801 | rxq->free_count++; |
| 4802 | } |
| 4803 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4804 | |
| 4805 | ipw_rx_queue_restock(priv); |
| 4806 | } |
| 4807 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 4808 | static void ipw_bg_rx_queue_replenish(void *data) |
| 4809 | { |
| 4810 | struct ipw_priv *priv = data; |
| 4811 | down(&priv->sem); |
| 4812 | ipw_rx_queue_replenish(data); |
| 4813 | up(&priv->sem); |
| 4814 | } |
| 4815 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4816 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
| 4817 | * 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] | 4818 | * 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] | 4819 | * non NULL it is unmapped and freed |
| 4820 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4821 | 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] | 4822 | { |
| 4823 | int i; |
| 4824 | |
| 4825 | if (!rxq) |
| 4826 | return; |
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 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4829 | if (rxq->pool[i].skb != NULL) { |
| 4830 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 4831 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4832 | dev_kfree_skb(rxq->pool[i].skb); |
| 4833 | } |
| 4834 | } |
| 4835 | |
| 4836 | kfree(rxq); |
| 4837 | } |
| 4838 | |
| 4839 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) |
| 4840 | { |
| 4841 | struct ipw_rx_queue *rxq; |
| 4842 | int i; |
| 4843 | |
| 4844 | rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL); |
Panagiotis Issaris | ad18b0e | 2005-09-05 04:14:10 +0200 | [diff] [blame] | 4845 | if (unlikely(!rxq)) { |
| 4846 | IPW_ERROR("memory allocation failed\n"); |
| 4847 | return NULL; |
| 4848 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4849 | memset(rxq, 0, sizeof(*rxq)); |
| 4850 | spin_lock_init(&rxq->lock); |
| 4851 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4852 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4853 | |
| 4854 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4855 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4856 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4857 | |
| 4858 | /* Set us so that we have processed and used all buffers, but have |
| 4859 | * not restocked the Rx queue with fresh buffers */ |
| 4860 | rxq->read = rxq->write = 0; |
| 4861 | rxq->processed = RX_QUEUE_SIZE - 1; |
| 4862 | rxq->free_count = 0; |
| 4863 | |
| 4864 | return rxq; |
| 4865 | } |
| 4866 | |
| 4867 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) |
| 4868 | { |
| 4869 | rate &= ~IEEE80211_BASIC_RATE_MASK; |
| 4870 | if (ieee_mode == IEEE_A) { |
| 4871 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4872 | case IEEE80211_OFDM_RATE_6MB: |
| 4873 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4874 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4875 | case IEEE80211_OFDM_RATE_9MB: |
| 4876 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4877 | 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4878 | case IEEE80211_OFDM_RATE_12MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4879 | return priv-> |
| 4880 | rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4881 | case IEEE80211_OFDM_RATE_18MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4882 | return priv-> |
| 4883 | rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4884 | case IEEE80211_OFDM_RATE_24MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4885 | return priv-> |
| 4886 | rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4887 | case IEEE80211_OFDM_RATE_36MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4888 | return priv-> |
| 4889 | rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4890 | case IEEE80211_OFDM_RATE_48MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4891 | return priv-> |
| 4892 | rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4893 | case IEEE80211_OFDM_RATE_54MB: |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4894 | return priv-> |
| 4895 | rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4896 | default: |
| 4897 | return 0; |
| 4898 | } |
| 4899 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4900 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4901 | /* B and G mixed */ |
| 4902 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4903 | case IEEE80211_CCK_RATE_1MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4904 | return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4905 | case IEEE80211_CCK_RATE_2MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4906 | return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4907 | case IEEE80211_CCK_RATE_5MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4908 | return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4909 | case IEEE80211_CCK_RATE_11MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4910 | return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0; |
| 4911 | } |
| 4912 | |
| 4913 | /* If we are limited to B modulations, bail at this point */ |
| 4914 | if (ieee_mode == IEEE_B) |
| 4915 | return 0; |
| 4916 | |
| 4917 | /* G */ |
| 4918 | switch (rate) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4919 | case IEEE80211_OFDM_RATE_6MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4920 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4921 | case IEEE80211_OFDM_RATE_9MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4922 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4923 | case IEEE80211_OFDM_RATE_12MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4924 | return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4925 | case IEEE80211_OFDM_RATE_18MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4926 | return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4927 | case IEEE80211_OFDM_RATE_24MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4928 | return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4929 | case IEEE80211_OFDM_RATE_36MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4930 | return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4931 | case IEEE80211_OFDM_RATE_48MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4932 | return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4933 | case IEEE80211_OFDM_RATE_54MB: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4934 | return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
| 4935 | } |
| 4936 | |
| 4937 | return 0; |
| 4938 | } |
| 4939 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4940 | static int ipw_compatible_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4941 | const struct ieee80211_network *network, |
| 4942 | struct ipw_supported_rates *rates) |
| 4943 | { |
| 4944 | int num_rates, i; |
| 4945 | |
| 4946 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4947 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4948 | rates->num_rates = 0; |
| 4949 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4950 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 4951 | network->rates[i])) { |
| 4952 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4953 | if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4954 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 4955 | "rate %02X\n", |
| 4956 | network->rates[i]); |
| 4957 | rates->supported_rates[rates->num_rates++] = |
| 4958 | network->rates[i]; |
| 4959 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4960 | } |
| 4961 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4962 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 4963 | network->rates[i], priv->rates_mask); |
| 4964 | continue; |
| 4965 | } |
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 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
| 4968 | } |
| 4969 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4970 | num_rates = min(network->rates_ex_len, |
| 4971 | (u8) (IPW_MAX_RATES - num_rates)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4972 | for (i = 0; i < num_rates; i++) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4973 | if (!ipw_is_rate_in_mask(priv, network->mode, |
| 4974 | network->rates_ex[i])) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4975 | if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 4976 | IPW_DEBUG_SCAN("Adding masked mandatory " |
| 4977 | "rate %02X\n", |
| 4978 | network->rates_ex[i]); |
| 4979 | rates->supported_rates[rates->num_rates++] = |
| 4980 | network->rates[i]; |
| 4981 | continue; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4982 | } |
| 4983 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4984 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
| 4985 | network->rates_ex[i], priv->rates_mask); |
| 4986 | continue; |
| 4987 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 4988 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 4989 | rates->supported_rates[rates->num_rates++] = |
| 4990 | network->rates_ex[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4991 | } |
| 4992 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 4993 | return 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | static inline void ipw_copy_rates(struct ipw_supported_rates *dest, |
| 4997 | const struct ipw_supported_rates *src) |
| 4998 | { |
| 4999 | u8 i; |
| 5000 | for (i = 0; i < src->num_rates; i++) |
| 5001 | dest->supported_rates[i] = src->supported_rates[i]; |
| 5002 | dest->num_rates = src->num_rates; |
| 5003 | } |
| 5004 | |
| 5005 | /* TODO: Look at sniffed packets in the air to determine if the basic rate |
| 5006 | * mask should ever be used -- right now all callers to add the scan rates are |
| 5007 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ |
| 5008 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5009 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5010 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5011 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5012 | IEEE80211_BASIC_RATE_MASK : 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5013 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5014 | if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5015 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5016 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5017 | |
| 5018 | if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5019 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5020 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5021 | |
| 5022 | if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5023 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5024 | IEEE80211_CCK_RATE_5MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5025 | |
| 5026 | if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5027 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5028 | IEEE80211_CCK_RATE_11MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5032 | u8 modulation, u32 rate_mask) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5033 | { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5034 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5035 | IEEE80211_BASIC_RATE_MASK : 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5036 | |
| 5037 | if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5038 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5039 | IEEE80211_OFDM_RATE_6MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5040 | |
| 5041 | if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5042 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5043 | IEEE80211_OFDM_RATE_9MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5044 | |
| 5045 | if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5046 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5047 | IEEE80211_OFDM_RATE_12MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5048 | |
| 5049 | if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5050 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5051 | IEEE80211_OFDM_RATE_18MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5052 | |
| 5053 | if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5054 | rates->supported_rates[rates->num_rates++] = basic_mask | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5055 | IEEE80211_OFDM_RATE_24MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5056 | |
| 5057 | if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5058 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5059 | IEEE80211_OFDM_RATE_36MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5060 | |
| 5061 | if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5062 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5063 | IEEE80211_OFDM_RATE_48MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5064 | |
| 5065 | if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5066 | rates->supported_rates[rates->num_rates++] = |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5067 | IEEE80211_OFDM_RATE_54MB; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5068 | } |
| 5069 | |
| 5070 | struct ipw_network_match { |
| 5071 | struct ieee80211_network *network; |
| 5072 | struct ipw_supported_rates rates; |
| 5073 | }; |
| 5074 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5075 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
| 5076 | struct ipw_network_match *match, |
| 5077 | struct ieee80211_network *network, |
| 5078 | int roaming) |
| 5079 | { |
| 5080 | struct ipw_supported_rates rates; |
| 5081 | |
| 5082 | /* Verify that this network's capability is compatible with the |
| 5083 | * current mode (AdHoc or Infrastructure) */ |
| 5084 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5085 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5086 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to " |
| 5087 | "capability mismatch.\n", |
| 5088 | escape_essid(network->ssid, network->ssid_len), |
| 5089 | MAC_ARG(network->bssid)); |
| 5090 | return 0; |
| 5091 | } |
| 5092 | |
| 5093 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5094 | * it */ |
| 5095 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5096 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5097 | "because of hidden ESSID.\n", |
| 5098 | escape_essid(network->ssid, network->ssid_len), |
| 5099 | MAC_ARG(network->bssid)); |
| 5100 | return 0; |
| 5101 | } |
| 5102 | |
| 5103 | if (unlikely(roaming)) { |
| 5104 | /* If we are roaming, then ensure check if this is a valid |
| 5105 | * network to try and roam to */ |
| 5106 | if ((network->ssid_len != match->network->ssid_len) || |
| 5107 | memcmp(network->ssid, match->network->ssid, |
| 5108 | network->ssid_len)) { |
| 5109 | IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5110 | "because of non-network ESSID.\n", |
| 5111 | escape_essid(network->ssid, |
| 5112 | network->ssid_len), |
| 5113 | MAC_ARG(network->bssid)); |
| 5114 | return 0; |
| 5115 | } |
| 5116 | } else { |
| 5117 | /* If an ESSID has been configured then compare the broadcast |
| 5118 | * ESSID to ours */ |
| 5119 | if ((priv->config & CFG_STATIC_ESSID) && |
| 5120 | ((network->ssid_len != priv->essid_len) || |
| 5121 | memcmp(network->ssid, priv->essid, |
| 5122 | min(network->ssid_len, priv->essid_len)))) { |
| 5123 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5124 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5125 | strncpy(escaped, |
| 5126 | escape_essid(network->ssid, network->ssid_len), |
| 5127 | sizeof(escaped)); |
| 5128 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5129 | "because of ESSID mismatch: '%s'.\n", |
| 5130 | escaped, MAC_ARG(network->bssid), |
| 5131 | escape_essid(priv->essid, |
| 5132 | priv->essid_len)); |
| 5133 | return 0; |
| 5134 | } |
| 5135 | } |
| 5136 | |
| 5137 | /* If the old network rate is better than this one, don't bother |
| 5138 | * testing everything else. */ |
| 5139 | |
| 5140 | if (network->time_stamp[0] < match->network->time_stamp[0]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5141 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5142 | "current network.\n", |
| 5143 | escape_essid(match->network->ssid, |
| 5144 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5145 | return 0; |
| 5146 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5147 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
| 5148 | "current network.\n", |
| 5149 | escape_essid(match->network->ssid, |
| 5150 | match->network->ssid_len)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5151 | return 0; |
| 5152 | } |
| 5153 | |
| 5154 | /* Now go through and see if the requested network is valid... */ |
| 5155 | if (priv->ieee->scan_age != 0 && |
| 5156 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
| 5157 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5158 | "because of age: %lums.\n", |
| 5159 | escape_essid(network->ssid, network->ssid_len), |
| 5160 | MAC_ARG(network->bssid), |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5161 | 1000 * (jiffies - network->last_scanned) / HZ); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5162 | return 0; |
| 5163 | } |
| 5164 | |
| 5165 | if ((priv->config & CFG_STATIC_CHANNEL) && |
| 5166 | (network->channel != priv->channel)) { |
| 5167 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5168 | "because of channel mismatch: %d != %d.\n", |
| 5169 | escape_essid(network->ssid, network->ssid_len), |
| 5170 | MAC_ARG(network->bssid), |
| 5171 | network->channel, priv->channel); |
| 5172 | return 0; |
| 5173 | } |
| 5174 | |
| 5175 | /* Verify privacy compatability */ |
| 5176 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
| 5177 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5178 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5179 | "because of privacy mismatch: %s != %s.\n", |
| 5180 | escape_essid(network->ssid, network->ssid_len), |
| 5181 | MAC_ARG(network->bssid), |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5182 | priv-> |
| 5183 | capability & CAP_PRIVACY_ON ? "on" : "off", |
| 5184 | network-> |
| 5185 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : |
| 5186 | "off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5187 | return 0; |
| 5188 | } |
| 5189 | |
| 5190 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5191 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5192 | "because of the same BSSID match: " MAC_FMT |
| 5193 | ".\n", escape_essid(network->ssid, |
| 5194 | network->ssid_len), |
| 5195 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
| 5196 | return 0; |
| 5197 | } |
| 5198 | |
| 5199 | /* Filter out any incompatible freq / mode combinations */ |
| 5200 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5201 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5202 | "because of invalid frequency/mode " |
| 5203 | "combination.\n", |
| 5204 | escape_essid(network->ssid, network->ssid_len), |
| 5205 | MAC_ARG(network->bssid)); |
| 5206 | return 0; |
| 5207 | } |
| 5208 | |
| 5209 | /* Ensure that the rates supported by the driver are compatible with |
| 5210 | * this AP, including verification of basic rates (mandatory) */ |
| 5211 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5212 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5213 | "because configured rate mask excludes " |
| 5214 | "AP mandatory rate.\n", |
| 5215 | escape_essid(network->ssid, network->ssid_len), |
| 5216 | MAC_ARG(network->bssid)); |
| 5217 | return 0; |
| 5218 | } |
| 5219 | |
| 5220 | if (rates.num_rates == 0) { |
| 5221 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
| 5222 | "because of no compatible rates.\n", |
| 5223 | escape_essid(network->ssid, network->ssid_len), |
| 5224 | MAC_ARG(network->bssid)); |
| 5225 | return 0; |
| 5226 | } |
| 5227 | |
| 5228 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5229 | * want to put too much policy logic here; intelligent scan selection |
| 5230 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5231 | |
| 5232 | /* Set up 'new' AP to this network */ |
| 5233 | ipw_copy_rates(&match->rates, &rates); |
| 5234 | match->network = network; |
| 5235 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5236 | escape_essid(network->ssid, network->ssid_len), |
| 5237 | MAC_ARG(network->bssid)); |
| 5238 | |
| 5239 | return 1; |
| 5240 | } |
| 5241 | |
| 5242 | static void ipw_merge_adhoc_network(void *data) |
| 5243 | { |
| 5244 | struct ipw_priv *priv = data; |
| 5245 | struct ieee80211_network *network = NULL; |
| 5246 | struct ipw_network_match match = { |
| 5247 | .network = priv->assoc_network |
| 5248 | }; |
| 5249 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5250 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5251 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5252 | /* First pass through ROAM process -- look for a better |
| 5253 | * network */ |
| 5254 | unsigned long flags; |
| 5255 | |
| 5256 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 5257 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 5258 | if (network != priv->assoc_network) |
| 5259 | ipw_find_adhoc_network(priv, &match, network, |
| 5260 | 1); |
| 5261 | } |
| 5262 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 5263 | |
| 5264 | if (match.network == priv->assoc_network) { |
| 5265 | IPW_DEBUG_MERGE("No better ADHOC in this network to " |
| 5266 | "merge to.\n"); |
| 5267 | return; |
| 5268 | } |
| 5269 | |
| 5270 | down(&priv->sem); |
| 5271 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
| 5272 | IPW_DEBUG_MERGE("remove network %s\n", |
| 5273 | escape_essid(priv->essid, |
| 5274 | priv->essid_len)); |
| 5275 | ipw_remove_current_network(priv); |
| 5276 | } |
| 5277 | |
| 5278 | ipw_disassociate(priv); |
| 5279 | priv->assoc_network = match.network; |
| 5280 | up(&priv->sem); |
| 5281 | return; |
| 5282 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5283 | } |
| 5284 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5285 | static int ipw_best_network(struct ipw_priv *priv, |
| 5286 | struct ipw_network_match *match, |
| 5287 | struct ieee80211_network *network, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5288 | { |
| 5289 | struct ipw_supported_rates rates; |
| 5290 | |
| 5291 | /* Verify that this network's capability is compatible with the |
| 5292 | * current mode (AdHoc or Infrastructure) */ |
| 5293 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && |
Jouni Malinen | 2474385 | 2005-08-14 20:59:59 -0700 | [diff] [blame] | 5294 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5295 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 5296 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
| 5297 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5298 | "capability mismatch.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5299 | escape_essid(network->ssid, network->ssid_len), |
| 5300 | MAC_ARG(network->bssid)); |
| 5301 | return 0; |
| 5302 | } |
| 5303 | |
| 5304 | /* If we do not have an ESSID for this AP, we can not associate with |
| 5305 | * it */ |
| 5306 | if (network->flags & NETWORK_EMPTY_ESSID) { |
| 5307 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5308 | "because of hidden ESSID.\n", |
| 5309 | escape_essid(network->ssid, network->ssid_len), |
| 5310 | MAC_ARG(network->bssid)); |
| 5311 | return 0; |
| 5312 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5313 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5314 | if (unlikely(roaming)) { |
| 5315 | /* If we are roaming, then ensure check if this is a valid |
| 5316 | * network to try and roam to */ |
| 5317 | if ((network->ssid_len != match->network->ssid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5318 | memcmp(network->ssid, match->network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5319 | network->ssid_len)) { |
| 5320 | IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded " |
| 5321 | "because of non-network ESSID.\n", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5322 | escape_essid(network->ssid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5323 | network->ssid_len), |
| 5324 | MAC_ARG(network->bssid)); |
| 5325 | return 0; |
| 5326 | } |
| 5327 | } else { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5328 | /* If an ESSID has been configured then compare the broadcast |
| 5329 | * ESSID to ours */ |
| 5330 | if ((priv->config & CFG_STATIC_ESSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5331 | ((network->ssid_len != priv->essid_len) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5332 | memcmp(network->ssid, priv->essid, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5333 | min(network->ssid_len, priv->essid_len)))) { |
| 5334 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5335 | strncpy(escaped, |
| 5336 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5337 | sizeof(escaped)); |
| 5338 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5339 | "because of ESSID mismatch: '%s'.\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5340 | escaped, MAC_ARG(network->bssid), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5341 | escape_essid(priv->essid, |
| 5342 | priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5343 | return 0; |
| 5344 | } |
| 5345 | } |
| 5346 | |
| 5347 | /* If the old network rate is better than this one, don't bother |
| 5348 | * testing everything else. */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5349 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5350 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5351 | strncpy(escaped, |
| 5352 | escape_essid(network->ssid, network->ssid_len), |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5353 | sizeof(escaped)); |
| 5354 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because " |
| 5355 | "'%s (" MAC_FMT ")' has a stronger signal.\n", |
| 5356 | escaped, MAC_ARG(network->bssid), |
| 5357 | escape_essid(match->network->ssid, |
| 5358 | match->network->ssid_len), |
| 5359 | MAC_ARG(match->network->bssid)); |
| 5360 | return 0; |
| 5361 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5362 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5363 | /* If this network has already had an association attempt within the |
| 5364 | * last 3 seconds, do not try and associate again... */ |
| 5365 | if (network->last_associate && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5366 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5367 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5368 | "because of storming (%lus since last " |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5369 | "assoc attempt).\n", |
| 5370 | escape_essid(network->ssid, network->ssid_len), |
| 5371 | MAC_ARG(network->bssid), |
| 5372 | (jiffies - network->last_associate) / HZ); |
| 5373 | return 0; |
| 5374 | } |
| 5375 | |
| 5376 | /* Now go through and see if the requested network is valid... */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5377 | if (priv->ieee->scan_age != 0 && |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5378 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5379 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5380 | "because of age: %lums.\n", |
| 5381 | escape_essid(network->ssid, network->ssid_len), |
| 5382 | MAC_ARG(network->bssid), |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5383 | 1000 * (jiffies - network->last_scanned) / HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5384 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5385 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5386 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5387 | if ((priv->config & CFG_STATIC_CHANNEL) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5388 | (network->channel != priv->channel)) { |
| 5389 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5390 | "because of channel mismatch: %d != %d.\n", |
| 5391 | escape_essid(network->ssid, network->ssid_len), |
| 5392 | MAC_ARG(network->bssid), |
| 5393 | network->channel, priv->channel); |
| 5394 | return 0; |
| 5395 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5396 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5397 | /* Verify privacy compatability */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5398 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5399 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
| 5400 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5401 | "because of privacy mismatch: %s != %s.\n", |
| 5402 | escape_essid(network->ssid, network->ssid_len), |
| 5403 | MAC_ARG(network->bssid), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5404 | priv->capability & CAP_PRIVACY_ON ? "on" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5405 | "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5406 | network->capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5407 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5408 | return 0; |
| 5409 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5410 | |
| 5411 | if ((priv->config & CFG_STATIC_BSSID) && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5412 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
| 5413 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5414 | "because of BSSID mismatch: " MAC_FMT ".\n", |
| 5415 | escape_essid(network->ssid, network->ssid_len), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5416 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5417 | return 0; |
| 5418 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5419 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5420 | /* Filter out any incompatible freq / mode combinations */ |
| 5421 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { |
| 5422 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5423 | "because of invalid frequency/mode " |
| 5424 | "combination.\n", |
| 5425 | escape_essid(network->ssid, network->ssid_len), |
| 5426 | MAC_ARG(network->bssid)); |
| 5427 | return 0; |
| 5428 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5429 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5430 | /* Ensure that the rates supported by the driver are compatible with |
| 5431 | * this AP, including verification of basic rates (mandatory) */ |
| 5432 | if (!ipw_compatible_rates(priv, network, &rates)) { |
| 5433 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5434 | "because configured rate mask excludes " |
| 5435 | "AP mandatory rate.\n", |
| 5436 | escape_essid(network->ssid, network->ssid_len), |
| 5437 | MAC_ARG(network->bssid)); |
| 5438 | return 0; |
| 5439 | } |
| 5440 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5441 | if (rates.num_rates == 0) { |
| 5442 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
| 5443 | "because of no compatible rates.\n", |
| 5444 | escape_essid(network->ssid, network->ssid_len), |
| 5445 | MAC_ARG(network->bssid)); |
| 5446 | return 0; |
| 5447 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5448 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5449 | /* TODO: Perform any further minimal comparititive tests. We do not |
| 5450 | * want to put too much policy logic here; intelligent scan selection |
| 5451 | * should occur within a generic IEEE 802.11 user space tool. */ |
| 5452 | |
| 5453 | /* Set up 'new' AP to this network */ |
| 5454 | ipw_copy_rates(&match->rates, &rates); |
| 5455 | match->network = network; |
| 5456 | |
| 5457 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n", |
| 5458 | escape_essid(network->ssid, network->ssid_len), |
| 5459 | MAC_ARG(network->bssid)); |
| 5460 | |
| 5461 | return 1; |
| 5462 | } |
| 5463 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5464 | static void ipw_adhoc_create(struct ipw_priv *priv, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5465 | struct ieee80211_network *network) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5466 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5467 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
| 5468 | int i; |
| 5469 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5470 | /* |
| 5471 | * For the purposes of scanning, we can set our wireless mode |
| 5472 | * to trigger scans across combinations of bands, but when it |
| 5473 | * comes to creating a new ad-hoc network, we have tell the FW |
| 5474 | * exactly which band to use. |
| 5475 | * |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5476 | * We also have the possibility of an invalid channel for the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5477 | * chossen band. Attempting to create a new ad-hoc network |
| 5478 | * with an invalid channel for wireless mode will trigger a |
| 5479 | * FW fatal error. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5480 | * |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5481 | */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5482 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
| 5483 | case IEEE80211_52GHZ_BAND: |
| 5484 | network->mode = IEEE_A; |
| 5485 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
| 5486 | if (i == -1) |
| 5487 | BUG(); |
| 5488 | if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 5489 | IPW_WARNING("Overriding invalid channel\n"); |
| 5490 | priv->channel = geo->a[0].channel; |
| 5491 | } |
| 5492 | break; |
| 5493 | |
| 5494 | case IEEE80211_24GHZ_BAND: |
| 5495 | if (priv->ieee->mode & IEEE_G) |
| 5496 | network->mode = IEEE_G; |
| 5497 | else |
| 5498 | network->mode = IEEE_B; |
| 5499 | break; |
| 5500 | |
| 5501 | default: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5502 | IPW_WARNING("Overriding invalid channel\n"); |
| 5503 | if (priv->ieee->mode & IEEE_A) { |
| 5504 | network->mode = IEEE_A; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5505 | priv->channel = geo->a[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5506 | } else if (priv->ieee->mode & IEEE_G) { |
| 5507 | network->mode = IEEE_G; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5508 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5509 | } else { |
| 5510 | network->mode = IEEE_B; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5511 | priv->channel = geo->bg[0].channel; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5512 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5513 | break; |
| 5514 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5515 | |
| 5516 | network->channel = priv->channel; |
| 5517 | priv->config |= CFG_ADHOC_PERSIST; |
| 5518 | ipw_create_bssid(priv, network->bssid); |
| 5519 | network->ssid_len = priv->essid_len; |
| 5520 | memcpy(network->ssid, priv->essid, priv->essid_len); |
| 5521 | memset(&network->stats, 0, sizeof(network->stats)); |
| 5522 | network->capability = WLAN_CAPABILITY_IBSS; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5523 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
| 5524 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5525 | if (priv->capability & CAP_PRIVACY_ON) |
| 5526 | network->capability |= WLAN_CAPABILITY_PRIVACY; |
| 5527 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5528 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5529 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5530 | memcpy(network->rates_ex, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5531 | &priv->rates.supported_rates[network->rates_len], |
| 5532 | network->rates_ex_len); |
| 5533 | network->last_scanned = 0; |
| 5534 | network->flags = 0; |
| 5535 | network->last_associate = 0; |
| 5536 | network->time_stamp[0] = 0; |
| 5537 | network->time_stamp[1] = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5538 | network->beacon_interval = 100; /* Default */ |
| 5539 | network->listen_interval = 10; /* Default */ |
| 5540 | network->atim_window = 0; /* Default */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5541 | network->wpa_ie_len = 0; |
| 5542 | network->rsn_ie_len = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5543 | } |
| 5544 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5545 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
| 5546 | { |
| 5547 | struct ipw_tgi_tx_key *key; |
| 5548 | struct host_cmd cmd = { |
| 5549 | .cmd = IPW_CMD_TGI_TX_KEY, |
| 5550 | .len = sizeof(*key) |
| 5551 | }; |
| 5552 | |
| 5553 | if (!(priv->ieee->sec.flags & (1 << index))) |
| 5554 | return; |
| 5555 | |
| 5556 | key = (struct ipw_tgi_tx_key *)&cmd.param; |
| 5557 | key->key_id = index; |
| 5558 | memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); |
| 5559 | key->security_type = type; |
| 5560 | key->station_index = 0; /* always 0 for BSS */ |
| 5561 | key->flags = 0; |
| 5562 | /* 0 for new key; previous value of counter (after fatal error) */ |
| 5563 | key->tx_counter[0] = 0; |
| 5564 | key->tx_counter[1] = 0; |
| 5565 | |
| 5566 | if (ipw_send_cmd(priv, &cmd)) { |
| 5567 | IPW_ERROR("failed to send TGI_TX_KEY command\n"); |
| 5568 | return; |
| 5569 | } |
| 5570 | } |
| 5571 | |
| 5572 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5573 | { |
| 5574 | struct ipw_wep_key *key; |
| 5575 | int i; |
| 5576 | struct host_cmd cmd = { |
| 5577 | .cmd = IPW_CMD_WEP_KEY, |
| 5578 | .len = sizeof(*key) |
| 5579 | }; |
| 5580 | |
| 5581 | key = (struct ipw_wep_key *)&cmd.param; |
| 5582 | key->cmd_id = DINO_CMD_WEP_KEY; |
| 5583 | key->seq_num = 0; |
| 5584 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5585 | /* Note: AES keys cannot be set for multiple times. |
| 5586 | * Only set it at the first time. */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5587 | for (i = 0; i < 4; i++) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5588 | key->key_index = i | type; |
| 5589 | if (!(priv->ieee->sec.flags & (1 << i))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5590 | key->key_size = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5591 | continue; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5592 | } |
| 5593 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5594 | key->key_size = priv->ieee->sec.key_sizes[i]; |
| 5595 | memcpy(key->key, priv->ieee->sec.keys[i], key->key_size); |
| 5596 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5597 | if (ipw_send_cmd(priv, &cmd)) { |
| 5598 | IPW_ERROR("failed to send WEP_KEY command\n"); |
| 5599 | return; |
| 5600 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5601 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5602 | } |
| 5603 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 5604 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
| 5605 | { |
| 5606 | if (priv->ieee->host_encrypt) |
| 5607 | return; |
| 5608 | |
| 5609 | switch (level) { |
| 5610 | case SEC_LEVEL_3: |
| 5611 | priv->sys_config.disable_unicast_decryption = 0; |
| 5612 | priv->ieee->host_decrypt = 0; |
| 5613 | break; |
| 5614 | case SEC_LEVEL_2: |
| 5615 | priv->sys_config.disable_unicast_decryption = 1; |
| 5616 | priv->ieee->host_decrypt = 1; |
| 5617 | break; |
| 5618 | case SEC_LEVEL_1: |
| 5619 | priv->sys_config.disable_unicast_decryption = 0; |
| 5620 | priv->ieee->host_decrypt = 0; |
| 5621 | break; |
| 5622 | case SEC_LEVEL_0: |
| 5623 | priv->sys_config.disable_unicast_decryption = 1; |
| 5624 | break; |
| 5625 | default: |
| 5626 | break; |
| 5627 | } |
| 5628 | } |
| 5629 | |
| 5630 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) |
| 5631 | { |
| 5632 | if (priv->ieee->host_encrypt) |
| 5633 | return; |
| 5634 | |
| 5635 | switch (level) { |
| 5636 | case SEC_LEVEL_3: |
| 5637 | priv->sys_config.disable_multicast_decryption = 0; |
| 5638 | break; |
| 5639 | case SEC_LEVEL_2: |
| 5640 | priv->sys_config.disable_multicast_decryption = 1; |
| 5641 | break; |
| 5642 | case SEC_LEVEL_1: |
| 5643 | priv->sys_config.disable_multicast_decryption = 0; |
| 5644 | break; |
| 5645 | case SEC_LEVEL_0: |
| 5646 | priv->sys_config.disable_multicast_decryption = 1; |
| 5647 | break; |
| 5648 | default: |
| 5649 | break; |
| 5650 | } |
| 5651 | } |
| 5652 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5653 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
| 5654 | { |
| 5655 | switch (priv->ieee->sec.level) { |
| 5656 | case SEC_LEVEL_3: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5657 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5658 | ipw_send_tgi_tx_key(priv, |
| 5659 | DCT_FLAG_EXT_SECURITY_CCM, |
| 5660 | priv->ieee->sec.active_key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5661 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5662 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5663 | break; |
| 5664 | case SEC_LEVEL_2: |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 5665 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
| 5666 | ipw_send_tgi_tx_key(priv, |
| 5667 | DCT_FLAG_EXT_SECURITY_TKIP, |
| 5668 | priv->ieee->sec.active_key); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5669 | break; |
| 5670 | case SEC_LEVEL_1: |
| 5671 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5672 | break; |
| 5673 | case SEC_LEVEL_0: |
| 5674 | default: |
| 5675 | break; |
| 5676 | } |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 5677 | |
| 5678 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
| 5679 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5680 | } |
| 5681 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5682 | static void ipw_adhoc_check(void *data) |
| 5683 | { |
| 5684 | struct ipw_priv *priv = data; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5685 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5686 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5687 | !(priv->config & CFG_ADHOC_PERSIST)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5688 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
| 5689 | IPW_DL_STATE | IPW_DL_ASSOC, |
| 5690 | "Missed beacon: %d - disassociate\n", |
| 5691 | priv->missed_adhoc_beacons); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5692 | ipw_remove_current_network(priv); |
| 5693 | ipw_disassociate(priv); |
| 5694 | return; |
| 5695 | } |
| 5696 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5697 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5698 | priv->assoc_request.beacon_interval); |
| 5699 | } |
| 5700 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 5701 | static void ipw_bg_adhoc_check(void *data) |
| 5702 | { |
| 5703 | struct ipw_priv *priv = data; |
| 5704 | down(&priv->sem); |
| 5705 | ipw_adhoc_check(data); |
| 5706 | up(&priv->sem); |
| 5707 | } |
| 5708 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5709 | #ifdef CONFIG_IPW_DEBUG |
| 5710 | static void ipw_debug_config(struct ipw_priv *priv) |
| 5711 | { |
| 5712 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
| 5713 | "[CFG 0x%08X]\n", priv->config); |
| 5714 | if (priv->config & CFG_STATIC_CHANNEL) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5715 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5716 | else |
| 5717 | IPW_DEBUG_INFO("Channel unlocked.\n"); |
| 5718 | if (priv->config & CFG_STATIC_ESSID) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5719 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5720 | escape_essid(priv->essid, priv->essid_len)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5721 | else |
| 5722 | IPW_DEBUG_INFO("ESSID unlocked.\n"); |
| 5723 | if (priv->config & CFG_STATIC_BSSID) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5724 | IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n", |
| 5725 | MAC_ARG(priv->bssid)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5726 | else |
| 5727 | IPW_DEBUG_INFO("BSSID unlocked.\n"); |
| 5728 | if (priv->capability & CAP_PRIVACY_ON) |
| 5729 | IPW_DEBUG_INFO("PRIVACY on\n"); |
| 5730 | else |
| 5731 | IPW_DEBUG_INFO("PRIVACY off\n"); |
| 5732 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); |
| 5733 | } |
| 5734 | #else |
Jiri Benc | 8d45ff7 | 2005-08-25 20:09:39 -0400 | [diff] [blame] | 5735 | #define ipw_debug_config(x) do {} while (0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5736 | #endif |
| 5737 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5738 | static inline void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5739 | { |
| 5740 | /* TODO: Verify that this works... */ |
| 5741 | struct ipw_fixed_rate fr = { |
| 5742 | .tx_rates = priv->rates_mask |
| 5743 | }; |
| 5744 | u32 reg; |
| 5745 | u16 mask = 0; |
| 5746 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5747 | /* Identify 'current FW band' and match it with the fixed |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5748 | * Tx rates */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5749 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5750 | switch (priv->ieee->freq_band) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5751 | case IEEE80211_52GHZ_BAND: /* A only */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5752 | /* IEEE_A */ |
| 5753 | if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { |
| 5754 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5755 | IPW_DEBUG_WX |
| 5756 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5757 | fr.tx_rates = 0; |
| 5758 | break; |
| 5759 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5760 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5761 | fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A; |
| 5762 | break; |
| 5763 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5764 | default: /* 2.4Ghz or Mixed */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5765 | /* IEEE_B */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5766 | if (mode == IEEE_B) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5767 | if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { |
| 5768 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5769 | IPW_DEBUG_WX |
| 5770 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5771 | fr.tx_rates = 0; |
| 5772 | } |
| 5773 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5774 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5775 | |
| 5776 | /* IEEE_G */ |
| 5777 | if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK | |
| 5778 | IEEE80211_OFDM_RATES_MASK)) { |
| 5779 | /* Invalid fixed rate mask */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5780 | IPW_DEBUG_WX |
| 5781 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5782 | fr.tx_rates = 0; |
| 5783 | break; |
| 5784 | } |
| 5785 | |
| 5786 | if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) { |
| 5787 | mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1); |
| 5788 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK; |
| 5789 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5790 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5791 | if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) { |
| 5792 | mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1); |
| 5793 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK; |
| 5794 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5795 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5796 | if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) { |
| 5797 | mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1); |
| 5798 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK; |
| 5799 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 5800 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5801 | fr.tx_rates |= mask; |
| 5802 | break; |
| 5803 | } |
| 5804 | |
| 5805 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 5806 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 5807 | } |
| 5808 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5809 | static void ipw_abort_scan(struct ipw_priv *priv) |
| 5810 | { |
| 5811 | int err; |
| 5812 | |
| 5813 | if (priv->status & STATUS_SCAN_ABORTING) { |
| 5814 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); |
| 5815 | return; |
| 5816 | } |
| 5817 | priv->status |= STATUS_SCAN_ABORTING; |
| 5818 | |
| 5819 | err = ipw_send_scan_abort(priv); |
| 5820 | if (err) |
| 5821 | IPW_DEBUG_HC("Request to abort scan failed.\n"); |
| 5822 | } |
| 5823 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5824 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
| 5825 | struct ipw_scan_request_ext *scan, |
| 5826 | int scan_type) |
| 5827 | { |
| 5828 | int channel_index = 0; |
| 5829 | const struct ieee80211_geo *geo; |
| 5830 | int i; |
| 5831 | |
| 5832 | geo = ieee80211_get_geo(priv->ieee); |
| 5833 | |
| 5834 | if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { |
| 5835 | int start = channel_index; |
| 5836 | for (i = 0; i < geo->a_channels; i++) { |
| 5837 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5838 | geo->a[i].channel == priv->channel) |
| 5839 | continue; |
| 5840 | channel_index++; |
| 5841 | scan->channels_list[channel_index] = geo->a[i].channel; |
| 5842 | ipw_set_scan_type(scan, channel_index, scan_type); |
| 5843 | } |
| 5844 | |
| 5845 | if (start != channel_index) { |
| 5846 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | |
| 5847 | (channel_index - start); |
| 5848 | channel_index++; |
| 5849 | } |
| 5850 | } |
| 5851 | |
| 5852 | if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { |
| 5853 | int start = channel_index; |
| 5854 | if (priv->config & CFG_SPEED_SCAN) { |
| 5855 | u8 channels[IEEE80211_24GHZ_CHANNELS] = { |
| 5856 | /* nop out the list */ |
| 5857 | [0] = 0 |
| 5858 | }; |
| 5859 | |
| 5860 | u8 channel; |
| 5861 | while (channel_index < IPW_SCAN_CHANNELS) { |
| 5862 | channel = |
| 5863 | priv->speed_scan[priv->speed_scan_pos]; |
| 5864 | if (channel == 0) { |
| 5865 | priv->speed_scan_pos = 0; |
| 5866 | channel = priv->speed_scan[0]; |
| 5867 | } |
| 5868 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5869 | channel == priv->channel) { |
| 5870 | priv->speed_scan_pos++; |
| 5871 | continue; |
| 5872 | } |
| 5873 | |
| 5874 | /* If this channel has already been |
| 5875 | * added in scan, break from loop |
| 5876 | * and this will be the first channel |
| 5877 | * in the next scan. |
| 5878 | */ |
| 5879 | if (channels[channel - 1] != 0) |
| 5880 | break; |
| 5881 | |
| 5882 | channels[channel - 1] = 1; |
| 5883 | priv->speed_scan_pos++; |
| 5884 | channel_index++; |
| 5885 | scan->channels_list[channel_index] = channel; |
| 5886 | ipw_set_scan_type(scan, channel_index, |
| 5887 | scan_type); |
| 5888 | } |
| 5889 | } else { |
| 5890 | for (i = 0; i < geo->bg_channels; i++) { |
| 5891 | if ((priv->status & STATUS_ASSOCIATED) && |
| 5892 | geo->bg[i].channel == priv->channel) |
| 5893 | continue; |
| 5894 | channel_index++; |
| 5895 | scan->channels_list[channel_index] = |
| 5896 | geo->bg[i].channel; |
| 5897 | ipw_set_scan_type(scan, channel_index, |
| 5898 | scan_type); |
| 5899 | } |
| 5900 | } |
| 5901 | |
| 5902 | if (start != channel_index) { |
| 5903 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | |
| 5904 | (channel_index - start); |
| 5905 | } |
| 5906 | } |
| 5907 | } |
| 5908 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5909 | static int ipw_request_scan(struct ipw_priv *priv) |
| 5910 | { |
| 5911 | struct ipw_scan_request_ext scan; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5912 | int err = 0, scan_type; |
| 5913 | |
| 5914 | if (!(priv->status & STATUS_INIT) || |
| 5915 | (priv->status & STATUS_EXIT_PENDING)) |
| 5916 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5917 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5918 | down(&priv->sem); |
| 5919 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5920 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5921 | IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n"); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5922 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5923 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5924 | } |
| 5925 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5926 | if (!(priv->status & STATUS_SCAN_FORCED) && |
| 5927 | priv->status & STATUS_SCAN_ABORTING) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5928 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 5929 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5930 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5931 | } |
| 5932 | |
| 5933 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 5934 | IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 5935 | priv->status |= STATUS_SCAN_PENDING; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5936 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | memset(&scan, 0, sizeof(scan)); |
| 5940 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5941 | if (priv->config & CFG_SPEED_SCAN) |
| 5942 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 5943 | cpu_to_le16(30); |
| 5944 | else |
| 5945 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 5946 | cpu_to_le16(20); |
| 5947 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5948 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 5949 | cpu_to_le16(20); |
| 5950 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5951 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5952 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5953 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5954 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5955 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 5956 | u8 channel; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5957 | u8 band = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5958 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5959 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
| 5960 | case IEEE80211_52GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5961 | band = (u8) (IPW_A_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5962 | channel = priv->channel; |
| 5963 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5964 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5965 | case IEEE80211_24GHZ_BAND: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5966 | band = (u8) (IPW_B_MODE << 6) | 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5967 | channel = priv->channel; |
| 5968 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5969 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5970 | default: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5971 | band = (u8) (IPW_B_MODE << 6) | 1; |
| 5972 | channel = 9; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5973 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5974 | } |
| 5975 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5976 | scan.channels_list[0] = band; |
| 5977 | scan.channels_list[1] = channel; |
| 5978 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5979 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5980 | /* NOTE: The card will sit on this channel for this time |
| 5981 | * period. Scan aborts are timing sensitive and frequently |
| 5982 | * result in firmware restarts. As such, it is best to |
| 5983 | * set a small dwell_time here and just keep re-issuing |
| 5984 | * scans. Otherwise fast channel hopping will not actually |
| 5985 | * hop channels. |
| 5986 | * |
| 5987 | * TODO: Move SPEED SCAN support to all modes and bands */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 5988 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
| 5989 | cpu_to_le16(2000); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5990 | } else { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 5991 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 5992 | /* If we are roaming, then make this a directed scan for the |
| 5993 | * current network. Otherwise, ensure that every other scan |
| 5994 | * is a fast channel hop scan */ |
| 5995 | if ((priv->status & STATUS_ROAMING) |
| 5996 | || (!(priv->status & STATUS_ASSOCIATED) |
| 5997 | && (priv->config & CFG_STATIC_ESSID) |
| 5998 | && (le32_to_cpu(scan.full_scan_index) % 2))) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 5999 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 6000 | if (err) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6001 | IPW_DEBUG_HC("Attempt to send SSID command " |
| 6002 | "failed.\n"); |
| 6003 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6007 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6008 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6009 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6010 | ipw_add_scan_channels(priv, &scan, scan_type); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6011 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6012 | } |
| 6013 | #endif |
| 6014 | |
| 6015 | err = ipw_send_scan_request_ext(priv, &scan); |
| 6016 | if (err) { |
| 6017 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6018 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | priv->status |= STATUS_SCANNING; |
| 6022 | priv->status &= ~STATUS_SCAN_PENDING; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6023 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6024 | IPW_SCAN_CHECK_WATCHDOG); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6025 | done: |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6026 | up(&priv->sem); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6027 | return err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 6028 | } |
| 6029 | |
| 6030 | static void ipw_bg_abort_scan(void *data) |
| 6031 | { |
| 6032 | struct ipw_priv *priv = data; |
| 6033 | down(&priv->sem); |
| 6034 | ipw_abort_scan(data); |
| 6035 | up(&priv->sem); |
| 6036 | } |
| 6037 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6038 | #if WIRELESS_EXT < 18 |
| 6039 | /* Support for wpa_supplicant before WE-18, deprecated. */ |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6040 | |
| 6041 | /* following definitions must match definitions in driver_ipw.c */ |
| 6042 | |
| 6043 | #define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30 |
| 6044 | |
| 6045 | #define IPW_CMD_SET_WPA_PARAM 1 |
| 6046 | #define IPW_CMD_SET_WPA_IE 2 |
| 6047 | #define IPW_CMD_SET_ENCRYPTION 3 |
| 6048 | #define IPW_CMD_MLME 4 |
| 6049 | |
| 6050 | #define IPW_PARAM_WPA_ENABLED 1 |
| 6051 | #define IPW_PARAM_TKIP_COUNTERMEASURES 2 |
| 6052 | #define IPW_PARAM_DROP_UNENCRYPTED 3 |
| 6053 | #define IPW_PARAM_PRIVACY_INVOKED 4 |
| 6054 | #define IPW_PARAM_AUTH_ALGS 5 |
| 6055 | #define IPW_PARAM_IEEE_802_1X 6 |
| 6056 | |
| 6057 | #define IPW_MLME_STA_DEAUTH 1 |
| 6058 | #define IPW_MLME_STA_DISASSOC 2 |
| 6059 | |
| 6060 | #define IPW_CRYPT_ERR_UNKNOWN_ALG 2 |
| 6061 | #define IPW_CRYPT_ERR_UNKNOWN_ADDR 3 |
| 6062 | #define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4 |
| 6063 | #define IPW_CRYPT_ERR_KEY_SET_FAILED 5 |
| 6064 | #define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6 |
| 6065 | #define IPW_CRYPT_ERR_CARD_CONF_FAILED 7 |
| 6066 | |
| 6067 | #define IPW_CRYPT_ALG_NAME_LEN 16 |
| 6068 | |
| 6069 | struct ipw_param { |
| 6070 | u32 cmd; |
| 6071 | u8 sta_addr[ETH_ALEN]; |
| 6072 | union { |
| 6073 | struct { |
| 6074 | u8 name; |
| 6075 | u32 value; |
| 6076 | } wpa_param; |
| 6077 | struct { |
| 6078 | u32 len; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6079 | u8 reserved[32]; |
| 6080 | u8 data[0]; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6081 | } wpa_ie; |
| 6082 | struct { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6083 | u32 command; |
| 6084 | u32 reason_code; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6085 | } mlme; |
| 6086 | struct { |
| 6087 | u8 alg[IPW_CRYPT_ALG_NAME_LEN]; |
| 6088 | u8 set_tx; |
| 6089 | u32 err; |
| 6090 | u8 idx; |
| 6091 | u8 seq[8]; /* sequence counter (set: RX, get: TX) */ |
| 6092 | u16 key_len; |
| 6093 | u8 key[0]; |
| 6094 | } crypt; |
| 6095 | |
| 6096 | } u; |
| 6097 | }; |
| 6098 | |
| 6099 | /* end of driver_ipw.c code */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6100 | #endif |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6101 | |
| 6102 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
| 6103 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6104 | /* This is called when wpa_supplicant loads and closes the driver |
| 6105 | * interface. */ |
| 6106 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6107 | } |
| 6108 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6109 | #if WIRELESS_EXT < 18 |
| 6110 | #define IW_AUTH_ALG_OPEN_SYSTEM 0x1 |
| 6111 | #define IW_AUTH_ALG_SHARED_KEY 0x2 |
| 6112 | #endif |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6113 | |
| 6114 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
| 6115 | { |
| 6116 | struct ieee80211_device *ieee = priv->ieee; |
| 6117 | struct ieee80211_security sec = { |
| 6118 | .flags = SEC_AUTH_MODE, |
| 6119 | }; |
| 6120 | int ret = 0; |
| 6121 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6122 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6123 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
| 6124 | ieee->open_wep = 0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6125 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6126 | sec.auth_mode = WLAN_AUTH_OPEN; |
| 6127 | ieee->open_wep = 1; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6128 | } else |
| 6129 | return -EINVAL; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6130 | |
| 6131 | if (ieee->set_security) |
| 6132 | ieee->set_security(ieee->dev, &sec); |
| 6133 | else |
| 6134 | ret = -EOPNOTSUPP; |
| 6135 | |
| 6136 | return ret; |
| 6137 | } |
| 6138 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6139 | void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len) |
| 6140 | { |
| 6141 | /* make sure WPA is enabled */ |
| 6142 | ipw_wpa_enable(priv, 1); |
| 6143 | |
| 6144 | ipw_disassociate(priv); |
| 6145 | } |
| 6146 | |
| 6147 | static int ipw_set_rsn_capa(struct ipw_priv *priv, |
| 6148 | char *capabilities, int length) |
| 6149 | { |
| 6150 | struct host_cmd cmd = { |
| 6151 | .cmd = IPW_CMD_RSN_CAPABILITIES, |
| 6152 | .len = length, |
| 6153 | }; |
| 6154 | |
| 6155 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
| 6156 | |
| 6157 | memcpy(cmd.param, capabilities, length); |
| 6158 | if (ipw_send_cmd(priv, &cmd)) { |
| 6159 | IPW_ERROR("failed to send HOST_CMD_RSN_CAPABILITIES command\n"); |
| 6160 | return -1; |
| 6161 | } |
| 6162 | return 0; |
| 6163 | } |
| 6164 | |
| 6165 | #if WIRELESS_EXT < 18 |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6166 | static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value) |
| 6167 | { |
| 6168 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6169 | struct ieee80211_crypt_data *crypt; |
| 6170 | unsigned long flags; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6171 | int ret = 0; |
| 6172 | |
| 6173 | switch (name) { |
| 6174 | case IPW_PARAM_WPA_ENABLED: |
| 6175 | ret = ipw_wpa_enable(priv, value); |
| 6176 | break; |
| 6177 | |
| 6178 | case IPW_PARAM_TKIP_COUNTERMEASURES: |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 6179 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
| 6180 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) { |
| 6181 | IPW_WARNING("Can't set TKIP countermeasures: " |
| 6182 | "crypt not set!\n"); |
| 6183 | break; |
| 6184 | } |
| 6185 | |
| 6186 | flags = crypt->ops->get_flags(crypt->priv); |
| 6187 | |
| 6188 | if (value) |
| 6189 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6190 | else |
| 6191 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6192 | |
| 6193 | crypt->ops->set_flags(flags, crypt->priv); |
| 6194 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6195 | break; |
| 6196 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6197 | case IPW_PARAM_DROP_UNENCRYPTED:{ |
| 6198 | /* HACK: |
| 6199 | * |
| 6200 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6201 | * is loaded and unloaded, regardless of if WPA is being |
| 6202 | * used. No other calls are made which can be used to |
| 6203 | * determine if encryption will be used or not prior to |
| 6204 | * association being expected. If encryption is not being |
| 6205 | * used, drop_unencrypted is set to false, else true -- we |
| 6206 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6207 | * be set. |
| 6208 | */ |
| 6209 | struct ieee80211_security sec = { |
| 6210 | .flags = SEC_ENABLED, |
| 6211 | .enabled = value, |
| 6212 | }; |
| 6213 | priv->ieee->drop_unencrypted = value; |
| 6214 | /* We only change SEC_LEVEL for open mode. Others |
| 6215 | * are set by ipw_wpa_set_encryption. |
| 6216 | */ |
| 6217 | if (!value) { |
| 6218 | sec.flags |= SEC_LEVEL; |
| 6219 | sec.level = SEC_LEVEL_0; |
| 6220 | } else { |
| 6221 | sec.flags |= SEC_LEVEL; |
| 6222 | sec.level = SEC_LEVEL_1; |
| 6223 | } |
| 6224 | if (priv->ieee->set_security) |
| 6225 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6226 | break; |
| 6227 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6228 | |
| 6229 | case IPW_PARAM_PRIVACY_INVOKED: |
| 6230 | priv->ieee->privacy_invoked = value; |
| 6231 | break; |
| 6232 | |
| 6233 | case IPW_PARAM_AUTH_ALGS: |
| 6234 | ret = ipw_wpa_set_auth_algs(priv, value); |
| 6235 | break; |
| 6236 | |
| 6237 | case IPW_PARAM_IEEE_802_1X: |
| 6238 | priv->ieee->ieee802_1x = value; |
| 6239 | break; |
| 6240 | |
| 6241 | default: |
| 6242 | IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name); |
| 6243 | ret = -EOPNOTSUPP; |
| 6244 | } |
| 6245 | |
| 6246 | return ret; |
| 6247 | } |
| 6248 | |
| 6249 | static int ipw_wpa_mlme(struct net_device *dev, int command, int reason) |
| 6250 | { |
| 6251 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6252 | int ret = 0; |
| 6253 | |
| 6254 | switch (command) { |
| 6255 | case IPW_MLME_STA_DEAUTH: |
| 6256 | // silently ignore |
| 6257 | break; |
| 6258 | |
| 6259 | case IPW_MLME_STA_DISASSOC: |
| 6260 | ipw_disassociate(priv); |
| 6261 | break; |
| 6262 | |
| 6263 | default: |
| 6264 | IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command); |
| 6265 | ret = -EOPNOTSUPP; |
| 6266 | } |
| 6267 | |
| 6268 | return ret; |
| 6269 | } |
| 6270 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6271 | static int ipw_wpa_ie_cipher2level(u8 cipher) |
| 6272 | { |
| 6273 | switch (cipher) { |
| 6274 | case 4: /* CCMP */ |
| 6275 | return SEC_LEVEL_3; |
| 6276 | case 2: /* TKIP */ |
| 6277 | return SEC_LEVEL_2; |
| 6278 | case 5: /* WEP104 */ |
| 6279 | case 1: /* WEP40 */ |
| 6280 | return SEC_LEVEL_1; |
| 6281 | case 0: /* NONE */ |
| 6282 | return SEC_LEVEL_0; |
| 6283 | default: |
| 6284 | return -1; |
| 6285 | } |
| 6286 | } |
| 6287 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6288 | static int ipw_wpa_set_wpa_ie(struct net_device *dev, |
| 6289 | struct ipw_param *param, int plen) |
| 6290 | { |
| 6291 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6292 | struct ieee80211_device *ieee = priv->ieee; |
| 6293 | u8 *buf; |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6294 | u8 *ptk, *gtk; |
| 6295 | int level; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6296 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6297 | if (param->u.wpa_ie.len > MAX_WPA_IE_LEN || |
| 6298 | (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL)) |
| 6299 | return -EINVAL; |
| 6300 | |
| 6301 | if (param->u.wpa_ie.len) { |
| 6302 | buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL); |
| 6303 | if (buf == NULL) |
| 6304 | return -ENOMEM; |
| 6305 | |
| 6306 | memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len); |
| 6307 | kfree(ieee->wpa_ie); |
| 6308 | ieee->wpa_ie = buf; |
| 6309 | ieee->wpa_ie_len = param->u.wpa_ie.len; |
| 6310 | } else { |
| 6311 | kfree(ieee->wpa_ie); |
| 6312 | ieee->wpa_ie = NULL; |
| 6313 | ieee->wpa_ie_len = 0; |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6314 | goto done; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6315 | } |
| 6316 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6317 | if (priv->ieee->host_encrypt) |
| 6318 | goto done; |
| 6319 | |
| 6320 | /* HACK: Parse wpa_ie here to get pairwise suite, otherwise |
| 6321 | * we need to change driver_ipw.c from wpa_supplicant. This |
| 6322 | * is OK since -Dipw is deprecated. The -Dwext driver has a |
| 6323 | * clean way to handle this. */ |
| 6324 | gtk = ptk = (u8 *) ieee->wpa_ie; |
| 6325 | if (ieee->wpa_ie[0] == 0x30) { /* RSN IE */ |
| 6326 | gtk += 4 + 3; |
| 6327 | ptk += 4 + 4 + 2 + 3; |
| 6328 | } else { /* WPA IE */ |
| 6329 | gtk += 8 + 3; |
| 6330 | ptk += 8 + 4 + 2 + 3; |
| 6331 | } |
| 6332 | |
| 6333 | if (ptk - (u8 *) ieee->wpa_ie > ieee->wpa_ie_len) |
| 6334 | return -EINVAL; |
| 6335 | |
| 6336 | level = ipw_wpa_ie_cipher2level(*gtk); |
| 6337 | ipw_set_hw_decrypt_multicast(priv, level); |
| 6338 | |
| 6339 | level = ipw_wpa_ie_cipher2level(*ptk); |
| 6340 | ipw_set_hw_decrypt_unicast(priv, level); |
| 6341 | |
| 6342 | done: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6343 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6344 | return 0; |
| 6345 | } |
| 6346 | |
| 6347 | /* implementation borrowed from hostap driver */ |
| 6348 | |
| 6349 | static int ipw_wpa_set_encryption(struct net_device *dev, |
| 6350 | struct ipw_param *param, int param_len) |
| 6351 | { |
| 6352 | int ret = 0; |
| 6353 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6354 | struct ieee80211_device *ieee = priv->ieee; |
| 6355 | struct ieee80211_crypto_ops *ops; |
| 6356 | struct ieee80211_crypt_data **crypt; |
| 6357 | |
| 6358 | struct ieee80211_security sec = { |
| 6359 | .flags = 0, |
| 6360 | }; |
| 6361 | |
| 6362 | param->u.crypt.err = 0; |
| 6363 | param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0'; |
| 6364 | |
| 6365 | if (param_len != |
| 6366 | (int)((char *)param->u.crypt.key - (char *)param) + |
| 6367 | param->u.crypt.key_len) { |
| 6368 | IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len, |
| 6369 | param->u.crypt.key_len); |
| 6370 | return -EINVAL; |
| 6371 | } |
| 6372 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && |
| 6373 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && |
| 6374 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) { |
| 6375 | if (param->u.crypt.idx >= WEP_KEYS) |
| 6376 | return -EINVAL; |
| 6377 | crypt = &ieee->crypt[param->u.crypt.idx]; |
| 6378 | } else { |
| 6379 | return -EINVAL; |
| 6380 | } |
| 6381 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6382 | sec.flags |= SEC_ENABLED | SEC_ENCRYPT; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6383 | if (strcmp(param->u.crypt.alg, "none") == 0) { |
| 6384 | if (crypt) { |
| 6385 | sec.enabled = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6386 | sec.encrypt = 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6387 | sec.level = SEC_LEVEL_0; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6388 | sec.flags |= SEC_LEVEL; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6389 | ieee80211_crypt_delayed_deinit(ieee, crypt); |
| 6390 | } |
| 6391 | goto done; |
| 6392 | } |
| 6393 | sec.enabled = 1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6394 | sec.encrypt = 1; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6395 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6396 | /* IPW HW cannot build TKIP MIC, host decryption still needed. */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6397 | if (strcmp(param->u.crypt.alg, "TKIP") == 0) |
| 6398 | ieee->host_encrypt_msdu = 1; |
| 6399 | |
| 6400 | if (!(ieee->host_encrypt || ieee->host_encrypt_msdu || |
| 6401 | ieee->host_decrypt)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6402 | goto skip_host_crypt; |
| 6403 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6404 | ops = ieee80211_get_crypto_ops(param->u.crypt.alg); |
| 6405 | if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) { |
| 6406 | request_module("ieee80211_crypt_wep"); |
| 6407 | ops = ieee80211_get_crypto_ops(param->u.crypt.alg); |
| 6408 | } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) { |
| 6409 | request_module("ieee80211_crypt_tkip"); |
| 6410 | ops = ieee80211_get_crypto_ops(param->u.crypt.alg); |
| 6411 | } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) { |
| 6412 | request_module("ieee80211_crypt_ccmp"); |
| 6413 | ops = ieee80211_get_crypto_ops(param->u.crypt.alg); |
| 6414 | } |
| 6415 | if (ops == NULL) { |
| 6416 | IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n", |
| 6417 | dev->name, param->u.crypt.alg); |
| 6418 | param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG; |
| 6419 | ret = -EINVAL; |
| 6420 | goto done; |
| 6421 | } |
| 6422 | |
| 6423 | if (*crypt == NULL || (*crypt)->ops != ops) { |
| 6424 | struct ieee80211_crypt_data *new_crypt; |
| 6425 | |
| 6426 | ieee80211_crypt_delayed_deinit(ieee, crypt); |
| 6427 | |
| 6428 | new_crypt = (struct ieee80211_crypt_data *) |
| 6429 | kmalloc(sizeof(*new_crypt), GFP_KERNEL); |
| 6430 | if (new_crypt == NULL) { |
| 6431 | ret = -ENOMEM; |
| 6432 | goto done; |
| 6433 | } |
| 6434 | memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data)); |
| 6435 | new_crypt->ops = ops; |
| 6436 | if (new_crypt->ops && try_module_get(new_crypt->ops->owner)) |
| 6437 | new_crypt->priv = |
| 6438 | new_crypt->ops->init(param->u.crypt.idx); |
| 6439 | |
| 6440 | if (new_crypt->priv == NULL) { |
| 6441 | kfree(new_crypt); |
| 6442 | param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED; |
| 6443 | ret = -EINVAL; |
| 6444 | goto done; |
| 6445 | } |
| 6446 | |
| 6447 | *crypt = new_crypt; |
| 6448 | } |
| 6449 | |
| 6450 | if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key && |
| 6451 | (*crypt)->ops->set_key(param->u.crypt.key, |
| 6452 | param->u.crypt.key_len, param->u.crypt.seq, |
| 6453 | (*crypt)->priv) < 0) { |
| 6454 | IPW_DEBUG_INFO("%s: key setting failed\n", dev->name); |
| 6455 | param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED; |
| 6456 | ret = -EINVAL; |
| 6457 | goto done; |
| 6458 | } |
| 6459 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6460 | skip_host_crypt: |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6461 | if (param->u.crypt.set_tx) { |
| 6462 | ieee->tx_keyidx = param->u.crypt.idx; |
| 6463 | sec.active_key = param->u.crypt.idx; |
| 6464 | sec.flags |= SEC_ACTIVE_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6465 | } else |
| 6466 | sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6467 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6468 | if (param->u.crypt.alg != NULL) { |
| 6469 | memcpy(sec.keys[param->u.crypt.idx], |
| 6470 | param->u.crypt.key, param->u.crypt.key_len); |
| 6471 | sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len; |
| 6472 | sec.flags |= (1 << param->u.crypt.idx); |
| 6473 | |
| 6474 | if (strcmp(param->u.crypt.alg, "WEP") == 0) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6475 | sec.flags |= SEC_LEVEL; |
| 6476 | sec.level = SEC_LEVEL_1; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6477 | } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6478 | sec.flags |= SEC_LEVEL; |
| 6479 | sec.level = SEC_LEVEL_2; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6480 | } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6481 | sec.flags |= SEC_LEVEL; |
| 6482 | sec.level = SEC_LEVEL_3; |
| 6483 | } |
| 6484 | } |
| 6485 | done: |
| 6486 | if (ieee->set_security) |
| 6487 | ieee->set_security(ieee->dev, &sec); |
| 6488 | |
| 6489 | /* Do not reset port if card is in Managed mode since resetting will |
| 6490 | * generate new IEEE 802.11 authentication which may end up in looping |
| 6491 | * with IEEE 802.1X. If your hardware requires a reset after WEP |
| 6492 | * configuration (for example... Prism2), implement the reset_port in |
| 6493 | * the callbacks structures used to initialize the 802.11 stack. */ |
| 6494 | if (ieee->reset_on_keychange && |
| 6495 | ieee->iw_mode != IW_MODE_INFRA && |
| 6496 | ieee->reset_port && ieee->reset_port(dev)) { |
| 6497 | IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name); |
| 6498 | param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED; |
| 6499 | return -EINVAL; |
| 6500 | } |
| 6501 | |
| 6502 | return ret; |
| 6503 | } |
| 6504 | |
| 6505 | static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p) |
| 6506 | { |
| 6507 | struct ipw_param *param; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6508 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6509 | int ret = 0; |
| 6510 | |
| 6511 | IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length); |
| 6512 | |
| 6513 | if (p->length < sizeof(struct ipw_param) || !p->pointer) |
| 6514 | return -EINVAL; |
| 6515 | |
| 6516 | param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL); |
| 6517 | if (param == NULL) |
| 6518 | return -ENOMEM; |
| 6519 | |
| 6520 | if (copy_from_user(param, p->pointer, p->length)) { |
| 6521 | kfree(param); |
| 6522 | return -EFAULT; |
| 6523 | } |
| 6524 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6525 | down(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6526 | switch (param->cmd) { |
| 6527 | |
| 6528 | case IPW_CMD_SET_WPA_PARAM: |
| 6529 | ret = ipw_wpa_set_param(dev, param->u.wpa_param.name, |
| 6530 | param->u.wpa_param.value); |
| 6531 | break; |
| 6532 | |
| 6533 | case IPW_CMD_SET_WPA_IE: |
| 6534 | ret = ipw_wpa_set_wpa_ie(dev, param, p->length); |
| 6535 | break; |
| 6536 | |
| 6537 | case IPW_CMD_SET_ENCRYPTION: |
| 6538 | ret = ipw_wpa_set_encryption(dev, param, p->length); |
| 6539 | break; |
| 6540 | |
| 6541 | case IPW_CMD_MLME: |
| 6542 | ret = ipw_wpa_mlme(dev, param->u.mlme.command, |
| 6543 | param->u.mlme.reason_code); |
| 6544 | break; |
| 6545 | |
| 6546 | default: |
| 6547 | IPW_ERROR("%s: Unknown WPA supplicant request: %d\n", |
| 6548 | dev->name, param->cmd); |
| 6549 | ret = -EOPNOTSUPP; |
| 6550 | } |
| 6551 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6552 | up(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6553 | if (ret == 0 && copy_to_user(p->pointer, param, p->length)) |
| 6554 | ret = -EFAULT; |
| 6555 | |
| 6556 | kfree(param); |
| 6557 | return ret; |
| 6558 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6559 | #else |
| 6560 | /* |
| 6561 | * WE-18 support |
| 6562 | */ |
| 6563 | |
| 6564 | /* SIOCSIWGENIE */ |
| 6565 | static int ipw_wx_set_genie(struct net_device *dev, |
| 6566 | struct iw_request_info *info, |
| 6567 | union iwreq_data *wrqu, char *extra) |
| 6568 | { |
| 6569 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6570 | struct ieee80211_device *ieee = priv->ieee; |
| 6571 | u8 *buf; |
| 6572 | int err = 0; |
| 6573 | |
| 6574 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
| 6575 | (wrqu->data.length && extra == NULL)) |
| 6576 | return -EINVAL; |
| 6577 | |
| 6578 | //down(&priv->sem); |
| 6579 | |
| 6580 | //if (!ieee->wpa_enabled) { |
| 6581 | // err = -EOPNOTSUPP; |
| 6582 | // goto out; |
| 6583 | //} |
| 6584 | |
| 6585 | if (wrqu->data.length) { |
| 6586 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 6587 | if (buf == NULL) { |
| 6588 | err = -ENOMEM; |
| 6589 | goto out; |
| 6590 | } |
| 6591 | |
| 6592 | memcpy(buf, extra, wrqu->data.length); |
| 6593 | kfree(ieee->wpa_ie); |
| 6594 | ieee->wpa_ie = buf; |
| 6595 | ieee->wpa_ie_len = wrqu->data.length; |
| 6596 | } else { |
| 6597 | kfree(ieee->wpa_ie); |
| 6598 | ieee->wpa_ie = NULL; |
| 6599 | ieee->wpa_ie_len = 0; |
| 6600 | } |
| 6601 | |
| 6602 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6603 | out: |
| 6604 | //up(&priv->sem); |
| 6605 | return err; |
| 6606 | } |
| 6607 | |
| 6608 | /* SIOCGIWGENIE */ |
| 6609 | static int ipw_wx_get_genie(struct net_device *dev, |
| 6610 | struct iw_request_info *info, |
| 6611 | union iwreq_data *wrqu, char *extra) |
| 6612 | { |
| 6613 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6614 | struct ieee80211_device *ieee = priv->ieee; |
| 6615 | int err = 0; |
| 6616 | |
| 6617 | //down(&priv->sem); |
| 6618 | |
| 6619 | //if (!ieee->wpa_enabled) { |
| 6620 | // err = -EOPNOTSUPP; |
| 6621 | // goto out; |
| 6622 | //} |
| 6623 | |
| 6624 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
| 6625 | wrqu->data.length = 0; |
| 6626 | goto out; |
| 6627 | } |
| 6628 | |
| 6629 | if (wrqu->data.length < ieee->wpa_ie_len) { |
| 6630 | err = -E2BIG; |
| 6631 | goto out; |
| 6632 | } |
| 6633 | |
| 6634 | wrqu->data.length = ieee->wpa_ie_len; |
| 6635 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); |
| 6636 | |
| 6637 | out: |
| 6638 | //up(&priv->sem); |
| 6639 | return err; |
| 6640 | } |
| 6641 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6642 | static int wext_cipher2level(int cipher) |
| 6643 | { |
| 6644 | switch (cipher) { |
| 6645 | case IW_AUTH_CIPHER_NONE: |
| 6646 | return SEC_LEVEL_0; |
| 6647 | case IW_AUTH_CIPHER_WEP40: |
| 6648 | case IW_AUTH_CIPHER_WEP104: |
| 6649 | return SEC_LEVEL_1; |
| 6650 | case IW_AUTH_CIPHER_TKIP: |
| 6651 | return SEC_LEVEL_2; |
| 6652 | case IW_AUTH_CIPHER_CCMP: |
| 6653 | return SEC_LEVEL_3; |
| 6654 | default: |
| 6655 | return -1; |
| 6656 | } |
| 6657 | } |
| 6658 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6659 | /* SIOCSIWAUTH */ |
| 6660 | static int ipw_wx_set_auth(struct net_device *dev, |
| 6661 | struct iw_request_info *info, |
| 6662 | union iwreq_data *wrqu, char *extra) |
| 6663 | { |
| 6664 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6665 | struct ieee80211_device *ieee = priv->ieee; |
| 6666 | struct iw_param *param = &wrqu->param; |
| 6667 | struct ieee80211_crypt_data *crypt; |
| 6668 | unsigned long flags; |
| 6669 | int ret = 0; |
| 6670 | |
| 6671 | switch (param->flags & IW_AUTH_INDEX) { |
| 6672 | case IW_AUTH_WPA_VERSION: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6673 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6674 | case IW_AUTH_CIPHER_PAIRWISE: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6675 | ipw_set_hw_decrypt_unicast(priv, |
| 6676 | wext_cipher2level(param->value)); |
| 6677 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6678 | case IW_AUTH_CIPHER_GROUP: |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 6679 | ipw_set_hw_decrypt_multicast(priv, |
| 6680 | wext_cipher2level(param->value)); |
| 6681 | break; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6682 | case IW_AUTH_KEY_MGMT: |
| 6683 | /* |
| 6684 | * ipw2200 does not use these parameters |
| 6685 | */ |
| 6686 | break; |
| 6687 | |
| 6688 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6689 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
| 6690 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) { |
| 6691 | IPW_WARNING("Can't set TKIP countermeasures: " |
| 6692 | "crypt not set!\n"); |
| 6693 | break; |
| 6694 | } |
| 6695 | |
| 6696 | flags = crypt->ops->get_flags(crypt->priv); |
| 6697 | |
| 6698 | if (param->value) |
| 6699 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6700 | else |
| 6701 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; |
| 6702 | |
| 6703 | crypt->ops->set_flags(flags, crypt->priv); |
| 6704 | |
| 6705 | break; |
| 6706 | |
| 6707 | case IW_AUTH_DROP_UNENCRYPTED:{ |
| 6708 | /* HACK: |
| 6709 | * |
| 6710 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 6711 | * is loaded and unloaded, regardless of if WPA is being |
| 6712 | * used. No other calls are made which can be used to |
| 6713 | * determine if encryption will be used or not prior to |
| 6714 | * association being expected. If encryption is not being |
| 6715 | * used, drop_unencrypted is set to false, else true -- we |
| 6716 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 6717 | * be set. |
| 6718 | */ |
| 6719 | struct ieee80211_security sec = { |
| 6720 | .flags = SEC_ENABLED, |
| 6721 | .enabled = param->value, |
| 6722 | }; |
| 6723 | priv->ieee->drop_unencrypted = param->value; |
| 6724 | /* We only change SEC_LEVEL for open mode. Others |
| 6725 | * are set by ipw_wpa_set_encryption. |
| 6726 | */ |
| 6727 | if (!param->value) { |
| 6728 | sec.flags |= SEC_LEVEL; |
| 6729 | sec.level = SEC_LEVEL_0; |
| 6730 | } else { |
| 6731 | sec.flags |= SEC_LEVEL; |
| 6732 | sec.level = SEC_LEVEL_1; |
| 6733 | } |
| 6734 | if (priv->ieee->set_security) |
| 6735 | priv->ieee->set_security(priv->ieee->dev, &sec); |
| 6736 | break; |
| 6737 | } |
| 6738 | |
| 6739 | case IW_AUTH_80211_AUTH_ALG: |
| 6740 | ret = ipw_wpa_set_auth_algs(priv, param->value); |
| 6741 | break; |
| 6742 | |
| 6743 | case IW_AUTH_WPA_ENABLED: |
| 6744 | ret = ipw_wpa_enable(priv, param->value); |
| 6745 | break; |
| 6746 | |
| 6747 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6748 | ieee->ieee802_1x = param->value; |
| 6749 | break; |
| 6750 | |
| 6751 | //case IW_AUTH_ROAMING_CONTROL: |
| 6752 | case IW_AUTH_PRIVACY_INVOKED: |
| 6753 | ieee->privacy_invoked = param->value; |
| 6754 | break; |
| 6755 | |
| 6756 | default: |
| 6757 | return -EOPNOTSUPP; |
| 6758 | } |
| 6759 | return ret; |
| 6760 | } |
| 6761 | |
| 6762 | /* SIOCGIWAUTH */ |
| 6763 | static int ipw_wx_get_auth(struct net_device *dev, |
| 6764 | struct iw_request_info *info, |
| 6765 | union iwreq_data *wrqu, char *extra) |
| 6766 | { |
| 6767 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6768 | struct ieee80211_device *ieee = priv->ieee; |
| 6769 | struct ieee80211_crypt_data *crypt; |
| 6770 | struct iw_param *param = &wrqu->param; |
| 6771 | int ret = 0; |
| 6772 | |
| 6773 | switch (param->flags & IW_AUTH_INDEX) { |
| 6774 | case IW_AUTH_WPA_VERSION: |
| 6775 | case IW_AUTH_CIPHER_PAIRWISE: |
| 6776 | case IW_AUTH_CIPHER_GROUP: |
| 6777 | case IW_AUTH_KEY_MGMT: |
| 6778 | /* |
| 6779 | * wpa_supplicant will control these internally |
| 6780 | */ |
| 6781 | ret = -EOPNOTSUPP; |
| 6782 | break; |
| 6783 | |
| 6784 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 6785 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; |
| 6786 | if (!crypt || !crypt->ops->get_flags) { |
| 6787 | IPW_WARNING("Can't get TKIP countermeasures: " |
| 6788 | "crypt not set!\n"); |
| 6789 | break; |
| 6790 | } |
| 6791 | |
| 6792 | param->value = (crypt->ops->get_flags(crypt->priv) & |
| 6793 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; |
| 6794 | |
| 6795 | break; |
| 6796 | |
| 6797 | case IW_AUTH_DROP_UNENCRYPTED: |
| 6798 | param->value = ieee->drop_unencrypted; |
| 6799 | break; |
| 6800 | |
| 6801 | case IW_AUTH_80211_AUTH_ALG: |
| 6802 | param->value = ieee->sec.auth_mode; |
| 6803 | break; |
| 6804 | |
| 6805 | case IW_AUTH_WPA_ENABLED: |
| 6806 | param->value = ieee->wpa_enabled; |
| 6807 | break; |
| 6808 | |
| 6809 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 6810 | param->value = ieee->ieee802_1x; |
| 6811 | break; |
| 6812 | |
| 6813 | case IW_AUTH_ROAMING_CONTROL: |
| 6814 | case IW_AUTH_PRIVACY_INVOKED: |
| 6815 | param->value = ieee->privacy_invoked; |
| 6816 | break; |
| 6817 | |
| 6818 | default: |
| 6819 | return -EOPNOTSUPP; |
| 6820 | } |
| 6821 | return 0; |
| 6822 | } |
| 6823 | |
| 6824 | /* SIOCSIWENCODEEXT */ |
| 6825 | static int ipw_wx_set_encodeext(struct net_device *dev, |
| 6826 | struct iw_request_info *info, |
| 6827 | union iwreq_data *wrqu, char *extra) |
| 6828 | { |
| 6829 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6830 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 6831 | |
| 6832 | if (hwcrypto) { |
| 6833 | /* IPW HW can't build TKIP MIC, host decryption still needed */ |
| 6834 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
| 6835 | priv->ieee->host_encrypt = 0; |
| 6836 | priv->ieee->host_encrypt_msdu = 1; |
| 6837 | priv->ieee->host_decrypt = 1; |
| 6838 | } else { |
| 6839 | priv->ieee->host_encrypt = 0; |
| 6840 | priv->ieee->host_encrypt_msdu = 0; |
| 6841 | priv->ieee->host_decrypt = 0; |
| 6842 | } |
| 6843 | } |
| 6844 | |
| 6845 | return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
| 6846 | } |
| 6847 | |
| 6848 | /* SIOCGIWENCODEEXT */ |
| 6849 | static int ipw_wx_get_encodeext(struct net_device *dev, |
| 6850 | struct iw_request_info *info, |
| 6851 | union iwreq_data *wrqu, char *extra) |
| 6852 | { |
| 6853 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6854 | return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); |
| 6855 | } |
| 6856 | |
| 6857 | /* SIOCSIWMLME */ |
| 6858 | static int ipw_wx_set_mlme(struct net_device *dev, |
| 6859 | struct iw_request_info *info, |
| 6860 | union iwreq_data *wrqu, char *extra) |
| 6861 | { |
| 6862 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 6863 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 6864 | u16 reason; |
| 6865 | |
| 6866 | reason = cpu_to_le16(mlme->reason_code); |
| 6867 | |
| 6868 | switch (mlme->cmd) { |
| 6869 | case IW_MLME_DEAUTH: |
| 6870 | // silently ignore |
| 6871 | break; |
| 6872 | |
| 6873 | case IW_MLME_DISASSOC: |
| 6874 | ipw_disassociate(priv); |
| 6875 | break; |
| 6876 | |
| 6877 | default: |
| 6878 | return -EOPNOTSUPP; |
| 6879 | } |
| 6880 | return 0; |
| 6881 | } |
| 6882 | #endif |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 6883 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6884 | #ifdef CONFIG_IPW_QOS |
| 6885 | |
| 6886 | /* QoS */ |
| 6887 | /* |
| 6888 | * get the modulation type of the current network or |
| 6889 | * the card current mode |
| 6890 | */ |
| 6891 | u8 ipw_qos_current_mode(struct ipw_priv * priv) |
| 6892 | { |
| 6893 | u8 mode = 0; |
| 6894 | |
| 6895 | if (priv->status & STATUS_ASSOCIATED) { |
| 6896 | unsigned long flags; |
| 6897 | |
| 6898 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 6899 | mode = priv->assoc_network->mode; |
| 6900 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 6901 | } else { |
| 6902 | mode = priv->ieee->mode; |
| 6903 | } |
| 6904 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); |
| 6905 | return mode; |
| 6906 | } |
| 6907 | |
| 6908 | /* |
| 6909 | * Handle management frame beacon and probe response |
| 6910 | */ |
| 6911 | static int ipw_qos_handle_probe_reponse(struct ipw_priv *priv, |
| 6912 | int active_network, |
| 6913 | struct ieee80211_network *network) |
| 6914 | { |
| 6915 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6916 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6917 | if (network->capability & WLAN_CAPABILITY_IBSS) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6918 | network->qos_data.active = network->qos_data.supported; |
| 6919 | |
| 6920 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6921 | if (active_network && |
| 6922 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6923 | network->qos_data.active = network->qos_data.supported; |
| 6924 | |
| 6925 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 6926 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 6927 | (network->qos_data.old_param_count != |
| 6928 | network->qos_data.param_count)) { |
| 6929 | network->qos_data.old_param_count = |
| 6930 | network->qos_data.param_count; |
| 6931 | schedule_work(&priv->qos_activate); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6932 | IPW_DEBUG_QOS("QoS parameters change call " |
| 6933 | "qos_activate\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6934 | } |
| 6935 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6936 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
| 6937 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6938 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6939 | else |
| 6940 | memcpy(&network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6941 | &def_parameters_OFDM, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6942 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6943 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
| 6944 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); |
| 6945 | schedule_work(&priv->qos_activate); |
| 6946 | } |
| 6947 | |
| 6948 | network->qos_data.active = 0; |
| 6949 | network->qos_data.supported = 0; |
| 6950 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6951 | if ((priv->status & STATUS_ASSOCIATED) && |
| 6952 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { |
| 6953 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) |
| 6954 | if ((network->capability & WLAN_CAPABILITY_IBSS) && |
| 6955 | !(network->flags & NETWORK_EMPTY_ESSID)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6956 | if ((network->ssid_len == |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6957 | priv->assoc_network->ssid_len) && |
| 6958 | !memcmp(network->ssid, |
| 6959 | priv->assoc_network->ssid, |
| 6960 | network->ssid_len)) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6961 | queue_work(priv->workqueue, |
| 6962 | &priv->merge_networks); |
| 6963 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6964 | } |
| 6965 | |
| 6966 | return 0; |
| 6967 | } |
| 6968 | |
| 6969 | /* |
| 6970 | * This function set up the firmware to support QoS. It sends |
| 6971 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO |
| 6972 | */ |
| 6973 | static int ipw_qos_activate(struct ipw_priv *priv, |
| 6974 | struct ieee80211_qos_data *qos_network_data) |
| 6975 | { |
| 6976 | int err; |
| 6977 | struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS]; |
| 6978 | struct ieee80211_qos_parameters *active_one = NULL; |
| 6979 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 6980 | u32 burst_duration; |
| 6981 | int i; |
| 6982 | u8 type; |
| 6983 | |
| 6984 | type = ipw_qos_current_mode(priv); |
| 6985 | |
| 6986 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); |
| 6987 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); |
| 6988 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); |
| 6989 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); |
| 6990 | |
| 6991 | if (qos_network_data == NULL) { |
| 6992 | if (type == IEEE_B) { |
| 6993 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); |
| 6994 | active_one = &def_parameters_CCK; |
| 6995 | } else |
| 6996 | active_one = &def_parameters_OFDM; |
| 6997 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 6998 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 6999 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 7000 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7001 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
| 7002 | (u16) burst_duration; |
| 7003 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7004 | if (type == IEEE_B) { |
| 7005 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", |
| 7006 | type); |
| 7007 | if (priv->qos_data.qos_enable == 0) |
| 7008 | active_one = &def_parameters_CCK; |
| 7009 | else |
| 7010 | active_one = priv->qos_data.def_qos_parm_CCK; |
| 7011 | } else { |
| 7012 | if (priv->qos_data.qos_enable == 0) |
| 7013 | active_one = &def_parameters_OFDM; |
| 7014 | else |
| 7015 | active_one = priv->qos_data.def_qos_parm_OFDM; |
| 7016 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7017 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7018 | } else { |
| 7019 | unsigned long flags; |
| 7020 | int active; |
| 7021 | |
| 7022 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7023 | active_one = &(qos_network_data->parameters); |
| 7024 | qos_network_data->old_param_count = |
| 7025 | qos_network_data->param_count; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7026 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7027 | active = qos_network_data->supported; |
| 7028 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7029 | |
| 7030 | if (active == 0) { |
| 7031 | burst_duration = ipw_qos_get_burst_duration(priv); |
| 7032 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
| 7033 | qos_parameters[QOS_PARAM_SET_ACTIVE]. |
| 7034 | tx_op_limit[i] = (u16) burst_duration; |
| 7035 | } |
| 7036 | } |
| 7037 | |
| 7038 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7039 | err = ipw_send_qos_params_command(priv, |
| 7040 | (struct ieee80211_qos_parameters *) |
| 7041 | &(qos_parameters[0])); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7042 | if (err) |
| 7043 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); |
| 7044 | |
| 7045 | return err; |
| 7046 | } |
| 7047 | |
| 7048 | /* |
| 7049 | * send IPW_CMD_WME_INFO to the firmware |
| 7050 | */ |
| 7051 | static int ipw_qos_set_info_element(struct ipw_priv *priv) |
| 7052 | { |
| 7053 | int ret = 0; |
| 7054 | struct ieee80211_qos_information_element qos_info; |
| 7055 | |
| 7056 | if (priv == NULL) |
| 7057 | return -1; |
| 7058 | |
| 7059 | qos_info.elementID = QOS_ELEMENT_ID; |
| 7060 | qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2; |
| 7061 | |
| 7062 | qos_info.version = QOS_VERSION_1; |
| 7063 | qos_info.ac_info = 0; |
| 7064 | |
| 7065 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); |
| 7066 | qos_info.qui_type = QOS_OUI_TYPE; |
| 7067 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; |
| 7068 | |
| 7069 | ret = ipw_send_qos_info_command(priv, &qos_info); |
| 7070 | if (ret != 0) { |
| 7071 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); |
| 7072 | } |
| 7073 | return ret; |
| 7074 | } |
| 7075 | |
| 7076 | /* |
| 7077 | * Set the QoS parameter with the association request structure |
| 7078 | */ |
| 7079 | static int ipw_qos_association(struct ipw_priv *priv, |
| 7080 | struct ieee80211_network *network) |
| 7081 | { |
| 7082 | int err = 0; |
| 7083 | struct ieee80211_qos_data *qos_data = NULL; |
| 7084 | struct ieee80211_qos_data ibss_data = { |
| 7085 | .supported = 1, |
| 7086 | .active = 1, |
| 7087 | }; |
| 7088 | |
| 7089 | switch (priv->ieee->iw_mode) { |
| 7090 | case IW_MODE_ADHOC: |
| 7091 | if (!(network->capability & WLAN_CAPABILITY_IBSS)) |
| 7092 | BUG(); |
| 7093 | |
| 7094 | qos_data = &ibss_data; |
| 7095 | break; |
| 7096 | |
| 7097 | case IW_MODE_INFRA: |
| 7098 | qos_data = &network->qos_data; |
| 7099 | break; |
| 7100 | |
| 7101 | default: |
| 7102 | BUG(); |
| 7103 | break; |
| 7104 | } |
| 7105 | |
| 7106 | err = ipw_qos_activate(priv, qos_data); |
| 7107 | if (err) { |
| 7108 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; |
| 7109 | return err; |
| 7110 | } |
| 7111 | |
| 7112 | if (priv->qos_data.qos_enable && qos_data->supported) { |
| 7113 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); |
| 7114 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; |
| 7115 | return ipw_qos_set_info_element(priv); |
| 7116 | } |
| 7117 | |
| 7118 | return 0; |
| 7119 | } |
| 7120 | |
| 7121 | /* |
| 7122 | * handling the beaconing responces. if we get different QoS setting |
| 7123 | * of the network from the the associated setting adjust the QoS |
| 7124 | * setting |
| 7125 | */ |
| 7126 | static int ipw_qos_association_resp(struct ipw_priv *priv, |
| 7127 | struct ieee80211_network *network) |
| 7128 | { |
| 7129 | int ret = 0; |
| 7130 | unsigned long flags; |
| 7131 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 7132 | int set_qos_param = 0; |
| 7133 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7134 | if ((priv == NULL) || (network == NULL) || |
| 7135 | (priv->assoc_network == NULL)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7136 | return ret; |
| 7137 | |
| 7138 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7139 | return ret; |
| 7140 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7141 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7142 | return ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7143 | |
| 7144 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7145 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7146 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7147 | sizeof(struct ieee80211_qos_data)); |
| 7148 | priv->assoc_network->qos_data.active = 1; |
| 7149 | if ((network->qos_data.old_param_count != |
| 7150 | network->qos_data.param_count)) { |
| 7151 | set_qos_param = 1; |
| 7152 | network->qos_data.old_param_count = |
| 7153 | network->qos_data.param_count; |
| 7154 | } |
| 7155 | |
| 7156 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7157 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
| 7158 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7159 | &def_parameters_CCK, size); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7160 | else |
| 7161 | memcpy(&priv->assoc_network->qos_data.parameters, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7162 | &def_parameters_OFDM, size); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7163 | priv->assoc_network->qos_data.active = 0; |
| 7164 | priv->assoc_network->qos_data.supported = 0; |
| 7165 | set_qos_param = 1; |
| 7166 | } |
| 7167 | |
| 7168 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7169 | |
| 7170 | if (set_qos_param == 1) |
| 7171 | schedule_work(&priv->qos_activate); |
| 7172 | |
| 7173 | return ret; |
| 7174 | } |
| 7175 | |
| 7176 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) |
| 7177 | { |
| 7178 | u32 ret = 0; |
| 7179 | |
| 7180 | if ((priv == NULL)) |
| 7181 | return 0; |
| 7182 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7183 | if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION)) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7184 | ret = priv->qos_data.burst_duration_CCK; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7185 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7186 | ret = priv->qos_data.burst_duration_OFDM; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7187 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7188 | return ret; |
| 7189 | } |
| 7190 | |
| 7191 | /* |
| 7192 | * Initialize the setting of QoS global |
| 7193 | */ |
| 7194 | static void ipw_qos_init(struct ipw_priv *priv, int enable, |
| 7195 | int burst_enable, u32 burst_duration_CCK, |
| 7196 | u32 burst_duration_OFDM) |
| 7197 | { |
| 7198 | priv->qos_data.qos_enable = enable; |
| 7199 | |
| 7200 | if (priv->qos_data.qos_enable) { |
| 7201 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; |
| 7202 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; |
| 7203 | IPW_DEBUG_QOS("QoS is enabled\n"); |
| 7204 | } else { |
| 7205 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; |
| 7206 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; |
| 7207 | IPW_DEBUG_QOS("QoS is not enabled\n"); |
| 7208 | } |
| 7209 | |
| 7210 | priv->qos_data.burst_enable = burst_enable; |
| 7211 | |
| 7212 | if (burst_enable) { |
| 7213 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; |
| 7214 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; |
| 7215 | } else { |
| 7216 | priv->qos_data.burst_duration_CCK = 0; |
| 7217 | priv->qos_data.burst_duration_OFDM = 0; |
| 7218 | } |
| 7219 | } |
| 7220 | |
| 7221 | /* |
| 7222 | * map the packet priority to the right TX Queue |
| 7223 | */ |
| 7224 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) |
| 7225 | { |
| 7226 | if (priority > 7 || !priv->qos_data.qos_enable) |
| 7227 | priority = 0; |
| 7228 | |
| 7229 | return from_priority_to_tx_queue[priority] - 1; |
| 7230 | } |
| 7231 | |
| 7232 | /* |
| 7233 | * add QoS parameter to the TX command |
| 7234 | */ |
| 7235 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, |
| 7236 | u16 priority, |
| 7237 | struct tfd_data *tfd, u8 unicast) |
| 7238 | { |
| 7239 | int ret = 0; |
| 7240 | int tx_queue_id = 0; |
| 7241 | struct ieee80211_qos_data *qos_data = NULL; |
| 7242 | int active, supported; |
| 7243 | unsigned long flags; |
| 7244 | |
| 7245 | if (!(priv->status & STATUS_ASSOCIATED)) |
| 7246 | return 0; |
| 7247 | |
| 7248 | qos_data = &priv->assoc_network->qos_data; |
| 7249 | |
| 7250 | spin_lock_irqsave(&priv->ieee->lock, flags); |
| 7251 | |
| 7252 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7253 | if (unicast == 0) |
| 7254 | qos_data->active = 0; |
| 7255 | else |
| 7256 | qos_data->active = qos_data->supported; |
| 7257 | } |
| 7258 | |
| 7259 | active = qos_data->active; |
| 7260 | supported = qos_data->supported; |
| 7261 | |
| 7262 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
| 7263 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7264 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
| 7265 | "unicast %d\n", |
| 7266 | priv->qos_data.qos_enable, active, supported, unicast); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7267 | if (active && priv->qos_data.qos_enable) { |
| 7268 | ret = from_priority_to_tx_queue[priority]; |
| 7269 | tx_queue_id = ret - 1; |
| 7270 | IPW_DEBUG_QOS("QoS packet priority is %d \n", priority); |
| 7271 | if (priority <= 7) { |
| 7272 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; |
| 7273 | tfd->tfd.tfd_26.mchdr.qos_ctrl = priority; |
| 7274 | tfd->tfd.tfd_26.mchdr.frame_ctl |= |
| 7275 | IEEE80211_STYPE_QOS_DATA; |
| 7276 | |
| 7277 | if (priv->qos_data.qos_no_ack_mask & |
| 7278 | (1UL << tx_queue_id)) { |
| 7279 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; |
| 7280 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= |
| 7281 | CTRL_QOS_NO_ACK; |
| 7282 | } |
| 7283 | } |
| 7284 | } |
| 7285 | |
| 7286 | return ret; |
| 7287 | } |
| 7288 | |
| 7289 | /* |
| 7290 | * background support to run QoS activate functionality |
| 7291 | */ |
| 7292 | static void ipw_bg_qos_activate(void *data) |
| 7293 | { |
| 7294 | struct ipw_priv *priv = data; |
| 7295 | |
| 7296 | if (priv == NULL) |
| 7297 | return; |
| 7298 | |
| 7299 | down(&priv->sem); |
| 7300 | |
| 7301 | if (priv->status & STATUS_ASSOCIATED) |
| 7302 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); |
| 7303 | |
| 7304 | up(&priv->sem); |
| 7305 | } |
| 7306 | |
| 7307 | /* |
| 7308 | * Handler for probe responce and beacon frame |
| 7309 | */ |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 7310 | static int ipw_handle_management(struct net_device *dev, |
| 7311 | struct ieee80211_network *network, u16 type) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7312 | { |
| 7313 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 7314 | int active_network; |
| 7315 | |
| 7316 | if (priv->status & STATUS_ASSOCIATED && network == priv->assoc_network) |
| 7317 | active_network = 1; |
| 7318 | else |
| 7319 | active_network = 0; |
| 7320 | |
| 7321 | switch (type) { |
| 7322 | case IEEE80211_STYPE_PROBE_RESP: |
| 7323 | case IEEE80211_STYPE_BEACON: |
| 7324 | ipw_qos_handle_probe_reponse(priv, active_network, network); |
| 7325 | break; |
| 7326 | case IEEE80211_STYPE_ASSOC_RESP: |
| 7327 | ipw_qos_association_resp(priv, network); |
| 7328 | break; |
| 7329 | default: |
| 7330 | break; |
| 7331 | } |
| 7332 | |
| 7333 | return 0; |
| 7334 | } |
| 7335 | |
| 7336 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
| 7337 | *qos_param) |
| 7338 | { |
| 7339 | struct host_cmd cmd = { |
| 7340 | .cmd = IPW_CMD_QOS_PARAMETERS, |
| 7341 | .len = (sizeof(struct ieee80211_qos_parameters) * 3) |
| 7342 | }; |
| 7343 | |
| 7344 | if (!priv || !qos_param) { |
| 7345 | IPW_ERROR("Invalid args\n"); |
| 7346 | return -1; |
| 7347 | } |
| 7348 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7349 | memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7350 | if (ipw_send_cmd(priv, &cmd)) { |
| 7351 | IPW_ERROR("failed to send IPW_CMD_QOS_PARAMETERS command\n"); |
| 7352 | return -1; |
| 7353 | } |
| 7354 | |
| 7355 | return 0; |
| 7356 | } |
| 7357 | |
| 7358 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element |
| 7359 | *qos_param) |
| 7360 | { |
| 7361 | struct host_cmd cmd = { |
| 7362 | .cmd = IPW_CMD_WME_INFO, |
| 7363 | .len = sizeof(*qos_param) |
| 7364 | }; |
| 7365 | |
| 7366 | if (!priv || !qos_param) { |
| 7367 | IPW_ERROR("Invalid args\n"); |
| 7368 | return -1; |
| 7369 | } |
| 7370 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7371 | memcpy(cmd.param, qos_param, sizeof(*qos_param)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7372 | if (ipw_send_cmd(priv, &cmd)) { |
| 7373 | IPW_ERROR("failed to send CMD_QOS_INFO command\n"); |
| 7374 | return -1; |
| 7375 | } |
| 7376 | |
| 7377 | return 0; |
| 7378 | } |
| 7379 | |
| 7380 | #endif /* CONFIG_IPW_QOS */ |
| 7381 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7382 | static int ipw_associate_network(struct ipw_priv *priv, |
| 7383 | struct ieee80211_network *network, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7384 | struct ipw_supported_rates *rates, int roaming) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7385 | { |
| 7386 | int err; |
| 7387 | |
| 7388 | if (priv->config & CFG_FIXED_RATE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7389 | ipw_set_fixed_rate(priv, network->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7390 | |
| 7391 | if (!(priv->config & CFG_STATIC_ESSID)) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7392 | priv->essid_len = min(network->ssid_len, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7393 | (u8) IW_ESSID_MAX_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7394 | memcpy(priv->essid, network->ssid, priv->essid_len); |
| 7395 | } |
| 7396 | |
| 7397 | network->last_associate = jiffies; |
| 7398 | |
| 7399 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); |
| 7400 | priv->assoc_request.channel = network->channel; |
| 7401 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 7402 | (priv->capability & CAP_SHARED_KEY)) { |
| 7403 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7404 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
| 7405 | |
| 7406 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 7407 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 7408 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 7409 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7410 | } else { |
| 7411 | priv->assoc_request.auth_type = AUTH_OPEN; |
| 7412 | priv->assoc_request.auth_key = 0; |
| 7413 | } |
| 7414 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7415 | if (priv->ieee->wpa_ie_len) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7416 | priv->assoc_request.policy_support = 0x02; /* RSN active */ |
| 7417 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
| 7418 | priv->ieee->wpa_ie_len); |
| 7419 | } |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7420 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7421 | /* |
| 7422 | * It is valid for our ieee device to support multiple modes, but |
| 7423 | * 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] | 7424 | * just one mode. |
| 7425 | */ |
| 7426 | if (network->mode & priv->ieee->mode & IEEE_A) |
| 7427 | priv->assoc_request.ieee_mode = IPW_A_MODE; |
| 7428 | else if (network->mode & priv->ieee->mode & IEEE_G) |
| 7429 | priv->assoc_request.ieee_mode = IPW_G_MODE; |
| 7430 | else if (network->mode & priv->ieee->mode & IEEE_B) |
| 7431 | priv->assoc_request.ieee_mode = IPW_B_MODE; |
| 7432 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7433 | priv->assoc_request.capability = network->capability; |
| 7434 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7435 | && !(priv->config & CFG_PREAMBLE_LONG)) { |
| 7436 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; |
| 7437 | } else { |
| 7438 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; |
| 7439 | |
| 7440 | /* Clear the short preamble if we won't be supporting it */ |
| 7441 | priv->assoc_request.capability &= |
| 7442 | ~WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 7443 | } |
| 7444 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7445 | /* Clear capability bits that aren't used in Ad Hoc */ |
| 7446 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7447 | priv->assoc_request.capability &= |
| 7448 | ~WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 7449 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7450 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7451 | "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] | 7452 | roaming ? "Rea" : "A", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7453 | escape_essid(priv->essid, priv->essid_len), |
| 7454 | network->channel, |
| 7455 | ipw_modes[priv->assoc_request.ieee_mode], |
| 7456 | rates->num_rates, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7457 | (priv->assoc_request.preamble_length == |
| 7458 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", |
| 7459 | network->capability & |
| 7460 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7461 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7462 | priv->capability & CAP_PRIVACY_ON ? |
| 7463 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7464 | "(open)") : "", |
| 7465 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7466 | priv->capability & CAP_PRIVACY_ON ? |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7467 | '1' + priv->ieee->sec.active_key : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7468 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7469 | |
| 7470 | priv->assoc_request.beacon_interval = network->beacon_interval; |
| 7471 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7472 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7473 | priv->assoc_request.assoc_type = HC_IBSS_START; |
| 7474 | priv->assoc_request.assoc_tsf_msw = 0; |
| 7475 | priv->assoc_request.assoc_tsf_lsw = 0; |
| 7476 | } else { |
| 7477 | if (unlikely(roaming)) |
| 7478 | priv->assoc_request.assoc_type = HC_REASSOCIATE; |
| 7479 | else |
| 7480 | priv->assoc_request.assoc_type = HC_ASSOCIATE; |
| 7481 | priv->assoc_request.assoc_tsf_msw = network->time_stamp[1]; |
| 7482 | priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0]; |
| 7483 | } |
| 7484 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7485 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7486 | |
| 7487 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
| 7488 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); |
| 7489 | priv->assoc_request.atim_window = network->atim_window; |
| 7490 | } else { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7491 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7492 | priv->assoc_request.atim_window = 0; |
| 7493 | } |
| 7494 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7495 | priv->assoc_request.listen_interval = network->listen_interval; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7496 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7497 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
| 7498 | if (err) { |
| 7499 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); |
| 7500 | return err; |
| 7501 | } |
| 7502 | |
| 7503 | rates->ieee_mode = priv->assoc_request.ieee_mode; |
| 7504 | rates->purpose = IPW_RATE_CONNECT; |
| 7505 | ipw_send_supported_rates(priv, rates); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7506 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7507 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
| 7508 | priv->sys_config.dot11g_auto_detection = 1; |
| 7509 | else |
| 7510 | priv->sys_config.dot11g_auto_detection = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7511 | |
| 7512 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 7513 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 7514 | else |
| 7515 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 7516 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7517 | err = ipw_send_system_config(priv, &priv->sys_config); |
| 7518 | if (err) { |
| 7519 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); |
| 7520 | return err; |
| 7521 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7522 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7523 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7524 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7525 | if (err) { |
| 7526 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7527 | return err; |
| 7528 | } |
| 7529 | |
| 7530 | /* |
| 7531 | * If preemption is enabled, it is possible for the association |
| 7532 | * to complete before we return from ipw_send_associate. Therefore |
| 7533 | * we have to be sure and update our priviate data first. |
| 7534 | */ |
| 7535 | priv->channel = network->channel; |
| 7536 | memcpy(priv->bssid, network->bssid, ETH_ALEN); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7537 | priv->status |= STATUS_ASSOCIATING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7538 | priv->status &= ~STATUS_SECURITY_UPDATED; |
| 7539 | |
| 7540 | priv->assoc_network = network; |
| 7541 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7542 | #ifdef CONFIG_IPW_QOS |
| 7543 | ipw_qos_association(priv, network); |
| 7544 | #endif |
| 7545 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7546 | err = ipw_send_associate(priv, &priv->assoc_request); |
| 7547 | if (err) { |
| 7548 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); |
| 7549 | return err; |
| 7550 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7551 | |
| 7552 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7553 | escape_essid(priv->essid, priv->essid_len), |
| 7554 | MAC_ARG(priv->bssid)); |
| 7555 | |
| 7556 | return 0; |
| 7557 | } |
| 7558 | |
| 7559 | static void ipw_roam(void *data) |
| 7560 | { |
| 7561 | struct ipw_priv *priv = data; |
| 7562 | struct ieee80211_network *network = NULL; |
| 7563 | struct ipw_network_match match = { |
| 7564 | .network = priv->assoc_network |
| 7565 | }; |
| 7566 | |
| 7567 | /* The roaming process is as follows: |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7568 | * |
| 7569 | * 1. Missed beacon threshold triggers the roaming process by |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7570 | * setting the status ROAM bit and requesting a scan. |
| 7571 | * 2. When the scan completes, it schedules the ROAM work |
| 7572 | * 3. The ROAM work looks at all of the known networks for one that |
| 7573 | * is a better network than the currently associated. If none |
| 7574 | * found, the ROAM process is over (ROAM bit cleared) |
| 7575 | * 4. If a better network is found, a disassociation request is |
| 7576 | * sent. |
| 7577 | * 5. When the disassociation completes, the roam work is again |
| 7578 | * scheduled. The second time through, the driver is no longer |
| 7579 | * associated, and the newly selected network is sent an |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7580 | * association request. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7581 | * 6. At this point ,the roaming process is complete and the ROAM |
| 7582 | * status bit is cleared. |
| 7583 | */ |
| 7584 | |
| 7585 | /* If we are no longer associated, and the roaming bit is no longer |
| 7586 | * set, then we are not actively roaming, so just return */ |
| 7587 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) |
| 7588 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7589 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7590 | if (priv->status & STATUS_ASSOCIATED) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7591 | /* First pass through ROAM process -- look for a better |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7592 | * network */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7593 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7594 | u8 rssi = priv->assoc_network->stats.rssi; |
| 7595 | priv->assoc_network->stats.rssi = -128; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7596 | spin_lock_irqsave(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7597 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
| 7598 | if (network != priv->assoc_network) |
| 7599 | ipw_best_network(priv, &match, network, 1); |
| 7600 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7601 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7602 | priv->assoc_network->stats.rssi = rssi; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7603 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7604 | if (match.network == priv->assoc_network) { |
| 7605 | IPW_DEBUG_ASSOC("No better APs in this network to " |
| 7606 | "roam to.\n"); |
| 7607 | priv->status &= ~STATUS_ROAMING; |
| 7608 | ipw_debug_config(priv); |
| 7609 | return; |
| 7610 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7611 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7612 | ipw_send_disassociate(priv, 1); |
| 7613 | priv->assoc_network = match.network; |
| 7614 | |
| 7615 | return; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7616 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7617 | |
| 7618 | /* Second pass through ROAM process -- request association */ |
| 7619 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); |
| 7620 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); |
| 7621 | priv->status &= ~STATUS_ROAMING; |
| 7622 | } |
| 7623 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7624 | static void ipw_bg_roam(void *data) |
| 7625 | { |
| 7626 | struct ipw_priv *priv = data; |
| 7627 | down(&priv->sem); |
| 7628 | ipw_roam(data); |
| 7629 | up(&priv->sem); |
| 7630 | } |
| 7631 | |
| 7632 | static int ipw_associate(void *data) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7633 | { |
| 7634 | struct ipw_priv *priv = data; |
| 7635 | |
| 7636 | struct ieee80211_network *network = NULL; |
| 7637 | struct ipw_network_match match = { |
| 7638 | .network = NULL |
| 7639 | }; |
| 7640 | struct ipw_supported_rates *rates; |
| 7641 | struct list_head *element; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7642 | unsigned long flags; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7643 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7644 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 7645 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); |
| 7646 | return 0; |
| 7647 | } |
| 7648 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7649 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7650 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
| 7651 | "progress)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7652 | return 0; |
| 7653 | } |
| 7654 | |
| 7655 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7656 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
| 7657 | "initialized)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7658 | return 0; |
| 7659 | } |
| 7660 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7661 | if (!(priv->config & CFG_ASSOCIATE) && |
| 7662 | !(priv->config & (CFG_STATIC_ESSID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7663 | CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7664 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7665 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7666 | } |
| 7667 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7668 | /* Protect our use of the network_list */ |
| 7669 | spin_lock_irqsave(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7670 | list_for_each_entry(network, &priv->ieee->network_list, list) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7671 | ipw_best_network(priv, &match, network, 0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7672 | |
| 7673 | network = match.network; |
| 7674 | rates = &match.rates; |
| 7675 | |
| 7676 | if (network == NULL && |
| 7677 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7678 | priv->config & CFG_ADHOC_CREATE && |
| 7679 | priv->config & CFG_STATIC_ESSID && |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7680 | priv->config & CFG_STATIC_CHANNEL && |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7681 | !list_empty(&priv->ieee->network_free_list)) { |
| 7682 | element = priv->ieee->network_free_list.next; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 7683 | network = list_entry(element, struct ieee80211_network, list); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7684 | ipw_adhoc_create(priv, network); |
| 7685 | rates = &priv->rates; |
| 7686 | list_del(element); |
| 7687 | list_add_tail(&network->list, &priv->ieee->network_list); |
| 7688 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7689 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7690 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7691 | /* If we reached the end of the list, then we don't have any valid |
| 7692 | * matching APs */ |
| 7693 | if (!network) { |
| 7694 | ipw_debug_config(priv); |
| 7695 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7696 | if (!(priv->status & STATUS_SCANNING)) { |
| 7697 | if (!(priv->config & CFG_SPEED_SCAN)) |
| 7698 | queue_delayed_work(priv->workqueue, |
| 7699 | &priv->request_scan, |
| 7700 | SCAN_INTERVAL); |
| 7701 | else |
| 7702 | queue_work(priv->workqueue, |
| 7703 | &priv->request_scan); |
| 7704 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7705 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7706 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7707 | } |
| 7708 | |
| 7709 | ipw_associate_network(priv, network, rates, 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7710 | |
| 7711 | return 1; |
| 7712 | } |
| 7713 | |
| 7714 | static void ipw_bg_associate(void *data) |
| 7715 | { |
| 7716 | struct ipw_priv *priv = data; |
| 7717 | down(&priv->sem); |
| 7718 | ipw_associate(data); |
| 7719 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7720 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7721 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7722 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
| 7723 | struct sk_buff *skb) |
| 7724 | { |
| 7725 | struct ieee80211_hdr *hdr; |
| 7726 | u16 fc; |
| 7727 | |
| 7728 | hdr = (struct ieee80211_hdr *)skb->data; |
| 7729 | fc = le16_to_cpu(hdr->frame_ctl); |
| 7730 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 7731 | return; |
| 7732 | |
| 7733 | fc &= ~IEEE80211_FCTL_PROTECTED; |
| 7734 | hdr->frame_ctl = cpu_to_le16(fc); |
| 7735 | switch (priv->ieee->sec.level) { |
| 7736 | case SEC_LEVEL_3: |
| 7737 | /* Remove CCMP HDR */ |
| 7738 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7739 | skb->data + IEEE80211_3ADDR_LEN + 8, |
| 7740 | skb->len - IEEE80211_3ADDR_LEN - 8); |
Zhu Yi | a2d73e6 | 2005-07-13 12:24:51 -0500 | [diff] [blame] | 7741 | if (fc & IEEE80211_FCTL_MOREFRAGS) |
| 7742 | skb_trim(skb, skb->len - 16); /* 2*MIC */ |
| 7743 | else |
| 7744 | skb_trim(skb, skb->len - 8); /* MIC */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7745 | break; |
| 7746 | case SEC_LEVEL_2: |
| 7747 | break; |
| 7748 | case SEC_LEVEL_1: |
| 7749 | /* Remove IV */ |
| 7750 | memmove(skb->data + IEEE80211_3ADDR_LEN, |
| 7751 | skb->data + IEEE80211_3ADDR_LEN + 4, |
| 7752 | skb->len - IEEE80211_3ADDR_LEN - 4); |
Zhu Yi | a2d73e6 | 2005-07-13 12:24:51 -0500 | [diff] [blame] | 7753 | if (fc & IEEE80211_FCTL_MOREFRAGS) |
| 7754 | skb_trim(skb, skb->len - 8); /* 2*ICV */ |
| 7755 | else |
| 7756 | skb_trim(skb, skb->len - 4); /* ICV */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7757 | break; |
| 7758 | case SEC_LEVEL_0: |
| 7759 | break; |
| 7760 | default: |
| 7761 | printk(KERN_ERR "Unknow security level %d\n", |
| 7762 | priv->ieee->sec.level); |
| 7763 | break; |
| 7764 | } |
| 7765 | } |
| 7766 | |
| 7767 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
| 7768 | struct ipw_rx_mem_buffer *rxb, |
| 7769 | struct ieee80211_rx_stats *stats) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7770 | { |
| 7771 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 7772 | |
| 7773 | /* We received data from the HW, so stop the watchdog */ |
| 7774 | priv->net_dev->trans_start = jiffies; |
| 7775 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7776 | /* We only process data packets if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7777 | * interface is open */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7778 | 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] | 7779 | skb_tailroom(rxb->skb))) { |
| 7780 | priv->ieee->stats.rx_errors++; |
| 7781 | priv->wstats.discard.misc++; |
| 7782 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
| 7783 | return; |
| 7784 | } else if (unlikely(!netif_running(priv->net_dev))) { |
| 7785 | priv->ieee->stats.rx_dropped++; |
| 7786 | priv->wstats.discard.misc++; |
| 7787 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
| 7788 | return; |
| 7789 | } |
| 7790 | |
| 7791 | /* Advance skb->data to the start of the actual payload */ |
Jiri Benc | aaa4d30 | 2005-06-07 14:58:41 +0200 | [diff] [blame] | 7792 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7793 | |
| 7794 | /* Set the size of the skb to the size of the frame */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7795 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7796 | |
| 7797 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 7798 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7799 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
| 7800 | if (!priv->ieee->host_decrypt) |
| 7801 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
| 7802 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 7803 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7804 | priv->ieee->stats.rx_errors++; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7805 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7806 | rxb->skb = NULL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7807 | __ipw_led_activity_on(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7808 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7809 | } |
| 7810 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7811 | static inline int is_network_packet(struct ipw_priv *priv, |
| 7812 | struct ieee80211_hdr_4addr *header) |
| 7813 | { |
| 7814 | /* Filter incoming packets to determine if they are targetted toward |
| 7815 | * this network, discarding packets coming from ourselves */ |
| 7816 | switch (priv->ieee->iw_mode) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7817 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7818 | /* packets from our adapter are dropped (echo) */ |
| 7819 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7820 | return 0; |
| 7821 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7822 | /* multicast packets to our IBSS go through */ |
| 7823 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7824 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7825 | |
| 7826 | /* packets to our adapter go through */ |
| 7827 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7828 | ETH_ALEN); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7829 | |
| 7830 | case IW_MODE_INFRA: /* Header: Dest. | AP{BSSID} | Source */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 7831 | /* packets from our adapter are dropped (echo) */ |
| 7832 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) |
| 7833 | return 0; |
| 7834 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7835 | /* {broad,multi}cast packets to our IBSS go through */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7836 | if (is_multicast_ether_addr(header->addr1)) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7837 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
| 7838 | |
| 7839 | /* packets to our adapter go through */ |
| 7840 | return !memcmp(header->addr1, priv->net_dev->dev_addr, |
| 7841 | ETH_ALEN); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7842 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 7843 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 7844 | return 1; |
| 7845 | } |
| 7846 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7847 | #define IPW_PACKET_RETRY_TIME HZ |
| 7848 | |
| 7849 | static inline int is_duplicate_packet(struct ipw_priv *priv, |
| 7850 | struct ieee80211_hdr_4addr *header) |
| 7851 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7852 | u16 sc = le16_to_cpu(header->seq_ctl); |
| 7853 | u16 seq = WLAN_GET_SEQ_SEQ(sc); |
| 7854 | u16 frag = WLAN_GET_SEQ_FRAG(sc); |
| 7855 | u16 *last_seq, *last_frag; |
| 7856 | unsigned long *last_time; |
| 7857 | |
| 7858 | switch (priv->ieee->iw_mode) { |
| 7859 | case IW_MODE_ADHOC: |
| 7860 | { |
| 7861 | struct list_head *p; |
| 7862 | struct ipw_ibss_seq *entry = NULL; |
| 7863 | u8 *mac = header->addr2; |
| 7864 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; |
| 7865 | |
| 7866 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 7867 | entry = |
| 7868 | list_entry(p, struct ipw_ibss_seq, list); |
| 7869 | if (!memcmp(entry->mac, mac, ETH_ALEN)) |
| 7870 | break; |
| 7871 | } |
| 7872 | if (p == &priv->ibss_mac_hash[index]) { |
| 7873 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 7874 | if (!entry) { |
| 7875 | IPW_ERROR |
| 7876 | ("Cannot malloc new mac entry\n"); |
| 7877 | return 0; |
| 7878 | } |
| 7879 | memcpy(entry->mac, mac, ETH_ALEN); |
| 7880 | entry->seq_num = seq; |
| 7881 | entry->frag_num = frag; |
| 7882 | entry->packet_time = jiffies; |
| 7883 | list_add(&entry->list, |
| 7884 | &priv->ibss_mac_hash[index]); |
| 7885 | return 0; |
| 7886 | } |
| 7887 | last_seq = &entry->seq_num; |
| 7888 | last_frag = &entry->frag_num; |
| 7889 | last_time = &entry->packet_time; |
| 7890 | break; |
| 7891 | } |
| 7892 | case IW_MODE_INFRA: |
| 7893 | last_seq = &priv->last_seq_num; |
| 7894 | last_frag = &priv->last_frag_num; |
| 7895 | last_time = &priv->last_packet_time; |
| 7896 | break; |
| 7897 | default: |
| 7898 | return 0; |
| 7899 | } |
| 7900 | if ((*last_seq == seq) && |
| 7901 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { |
| 7902 | if (*last_frag == frag) |
| 7903 | goto drop; |
| 7904 | if (*last_frag + 1 != frag) |
| 7905 | /* out-of-order fragment */ |
| 7906 | goto drop; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7907 | } else |
| 7908 | *last_seq = seq; |
| 7909 | |
Zhu Yi | f57ce7c | 2005-07-13 12:22:15 -0500 | [diff] [blame] | 7910 | *last_frag = frag; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7911 | *last_time = jiffies; |
| 7912 | return 0; |
| 7913 | |
| 7914 | drop: |
Zhu Yi | 87b016c | 2005-08-05 17:17:35 +0800 | [diff] [blame] | 7915 | /* Comment this line now since we observed the card receives |
| 7916 | * duplicate packets but the FCTL_RETRY bit is not set in the |
| 7917 | * IBSS mode with fragmentation enabled. |
| 7918 | BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 7919 | return 1; |
| 7920 | } |
| 7921 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7922 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
| 7923 | struct ipw_rx_mem_buffer *rxb, |
| 7924 | struct ieee80211_rx_stats *stats) |
| 7925 | { |
| 7926 | struct sk_buff *skb = rxb->skb; |
| 7927 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; |
| 7928 | struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *) |
| 7929 | (skb->data + IPW_RX_FRAME_SIZE); |
| 7930 | |
| 7931 | ieee80211_rx_mgt(priv->ieee, header, stats); |
| 7932 | |
| 7933 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 7934 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 7935 | IEEE80211_STYPE_PROBE_RESP) || |
| 7936 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == |
| 7937 | IEEE80211_STYPE_BEACON))) { |
| 7938 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) |
| 7939 | ipw_add_station(priv, header->addr2); |
| 7940 | } |
| 7941 | |
| 7942 | if (priv->config & CFG_NET_STATS) { |
| 7943 | IPW_DEBUG_HC("sending stat packet\n"); |
| 7944 | |
| 7945 | /* Set the size of the skb to the size of the full |
| 7946 | * ipw header and 802.11 frame */ |
| 7947 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + |
| 7948 | IPW_RX_FRAME_SIZE); |
| 7949 | |
| 7950 | /* Advance past the ipw packet header to the 802.11 frame */ |
| 7951 | skb_pull(skb, IPW_RX_FRAME_SIZE); |
| 7952 | |
| 7953 | /* Push the ieee80211_rx_stats before the 802.11 frame */ |
| 7954 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
| 7955 | |
| 7956 | skb->dev = priv->ieee->dev; |
| 7957 | |
| 7958 | /* Point raw at the ieee80211_stats */ |
| 7959 | skb->mac.raw = skb->data; |
| 7960 | |
| 7961 | skb->pkt_type = PACKET_OTHERHOST; |
| 7962 | skb->protocol = __constant_htons(ETH_P_80211_STATS); |
| 7963 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
| 7964 | netif_rx(skb); |
| 7965 | rxb->skb = NULL; |
| 7966 | } |
| 7967 | } |
| 7968 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7969 | /* |
| 7970 | * Main entry function for recieving a packet with 80211 headers. This |
| 7971 | * should be called when ever the FW has notified us that there is a new |
| 7972 | * skb in the recieve queue. |
| 7973 | */ |
| 7974 | static void ipw_rx(struct ipw_priv *priv) |
| 7975 | { |
| 7976 | struct ipw_rx_mem_buffer *rxb; |
| 7977 | struct ipw_rx_packet *pkt; |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 7978 | struct ieee80211_hdr_4addr *header; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7979 | u32 r, w, i; |
| 7980 | u8 network_packet; |
| 7981 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7982 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
| 7983 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7984 | i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE; |
| 7985 | |
| 7986 | while (i != r) { |
| 7987 | rxb = priv->rxq->queue[i]; |
| 7988 | #ifdef CONFIG_IPW_DEBUG |
| 7989 | if (unlikely(rxb == NULL)) { |
| 7990 | printk(KERN_CRIT "Queue not allocated!\n"); |
| 7991 | break; |
| 7992 | } |
| 7993 | #endif |
| 7994 | priv->rxq->queue[i] = NULL; |
| 7995 | |
| 7996 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 7997 | IPW_RX_BUF_SIZE, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 7998 | PCI_DMA_FROMDEVICE); |
| 7999 | |
| 8000 | pkt = (struct ipw_rx_packet *)rxb->skb->data; |
| 8001 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", |
| 8002 | pkt->header.message_type, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8003 | pkt->header.rx_seq_num, pkt->header.control_bits); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8004 | |
| 8005 | switch (pkt->header.message_type) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8006 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
| 8007 | struct ieee80211_rx_stats stats = { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8008 | .rssi = |
| 8009 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8010 | IPW_RSSI_TO_DBM, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8011 | .signal = |
| 8012 | le16_to_cpu(pkt->u.frame.signal), |
| 8013 | .noise = |
| 8014 | le16_to_cpu(pkt->u.frame.noise), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8015 | .rate = pkt->u.frame.rate, |
| 8016 | .mac_time = jiffies, |
| 8017 | .received_channel = |
| 8018 | pkt->u.frame.received_channel, |
| 8019 | .freq = |
| 8020 | (pkt->u.frame. |
| 8021 | control & (1 << 0)) ? |
| 8022 | IEEE80211_24GHZ_BAND : |
| 8023 | IEEE80211_52GHZ_BAND, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8024 | .len = le16_to_cpu(pkt->u.frame.length), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8025 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8026 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8027 | if (stats.rssi != 0) |
| 8028 | stats.mask |= IEEE80211_STATMASK_RSSI; |
| 8029 | if (stats.signal != 0) |
| 8030 | stats.mask |= IEEE80211_STATMASK_SIGNAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8031 | if (stats.noise != 0) |
| 8032 | stats.mask |= IEEE80211_STATMASK_NOISE; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8033 | if (stats.rate != 0) |
| 8034 | stats.mask |= IEEE80211_STATMASK_RATE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8035 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8036 | priv->rx_packets++; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8037 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8038 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8039 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
| 8040 | ipw_handle_data_packet(priv, rxb, |
| 8041 | &stats); |
| 8042 | break; |
| 8043 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8044 | #endif |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8045 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8046 | header = |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 8047 | (struct ieee80211_hdr_4addr *)(rxb->skb-> |
| 8048 | data + |
| 8049 | IPW_RX_FRAME_SIZE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8050 | /* TODO: Check Ad-Hoc dest/source and make sure |
| 8051 | * that we are actually parsing these packets |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8052 | * correctly -- we should probably use the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8053 | * frame control of the packet and disregard |
| 8054 | * the current iw_mode */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8055 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8056 | network_packet = |
| 8057 | is_network_packet(priv, header); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8058 | if (network_packet && priv->assoc_network) { |
| 8059 | priv->assoc_network->stats.rssi = |
| 8060 | stats.rssi; |
| 8061 | average_add(&priv->average_rssi, |
| 8062 | stats.rssi); |
| 8063 | priv->last_rx_rssi = stats.rssi; |
| 8064 | } |
| 8065 | |
| 8066 | IPW_DEBUG_RX("Frame: len=%u\n", |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8067 | le16_to_cpu(pkt->u.frame.length)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8068 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8069 | if (le16_to_cpu(pkt->u.frame.length) < |
| 8070 | frame_hdr_len(header)) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8071 | IPW_DEBUG_DROP |
| 8072 | ("Received packet is too small. " |
| 8073 | "Dropping.\n"); |
| 8074 | priv->ieee->stats.rx_errors++; |
| 8075 | priv->wstats.discard.misc++; |
| 8076 | break; |
| 8077 | } |
| 8078 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8079 | switch (WLAN_FC_GET_TYPE |
| 8080 | (le16_to_cpu(header->frame_ctl))) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8081 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8082 | case IEEE80211_FTYPE_MGMT: |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8083 | ipw_handle_mgmt_packet(priv, rxb, |
| 8084 | &stats); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8085 | break; |
| 8086 | |
| 8087 | case IEEE80211_FTYPE_CTL: |
| 8088 | break; |
| 8089 | |
| 8090 | case IEEE80211_FTYPE_DATA: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8091 | if (unlikely(!network_packet || |
| 8092 | is_duplicate_packet(priv, |
| 8093 | header))) |
| 8094 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8095 | IPW_DEBUG_DROP("Dropping: " |
| 8096 | MAC_FMT ", " |
| 8097 | MAC_FMT ", " |
| 8098 | MAC_FMT "\n", |
| 8099 | MAC_ARG(header-> |
| 8100 | addr1), |
| 8101 | MAC_ARG(header-> |
| 8102 | addr2), |
| 8103 | MAC_ARG(header-> |
| 8104 | addr3)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8105 | break; |
| 8106 | } |
| 8107 | |
| 8108 | ipw_handle_data_packet(priv, rxb, |
| 8109 | &stats); |
| 8110 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8111 | break; |
| 8112 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8113 | break; |
| 8114 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8115 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8116 | case RX_HOST_NOTIFICATION_TYPE:{ |
| 8117 | IPW_DEBUG_RX |
| 8118 | ("Notification: subtype=%02X flags=%02X size=%d\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8119 | pkt->u.notification.subtype, |
| 8120 | pkt->u.notification.flags, |
| 8121 | pkt->u.notification.size); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8122 | ipw_rx_notification(priv, &pkt->u.notification); |
| 8123 | break; |
| 8124 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8125 | |
| 8126 | default: |
| 8127 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", |
| 8128 | pkt->header.message_type); |
| 8129 | break; |
| 8130 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8131 | |
| 8132 | /* For now we just don't re-use anything. We can tweak this |
| 8133 | * later to try and re-use notification packets and SKBs that |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8134 | * fail to Rx correctly */ |
| 8135 | if (rxb->skb != NULL) { |
| 8136 | dev_kfree_skb_any(rxb->skb); |
| 8137 | rxb->skb = NULL; |
| 8138 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8139 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8140 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8141 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8142 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8143 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8144 | i = (i + 1) % RX_QUEUE_SIZE; |
| 8145 | } |
| 8146 | |
| 8147 | /* Backtrack one entry */ |
| 8148 | priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1; |
| 8149 | |
| 8150 | ipw_rx_queue_restock(priv); |
| 8151 | } |
| 8152 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8153 | #define DEFAULT_RTS_THRESHOLD 2304U |
| 8154 | #define MIN_RTS_THRESHOLD 1U |
| 8155 | #define MAX_RTS_THRESHOLD 2304U |
| 8156 | #define DEFAULT_BEACON_INTERVAL 100U |
| 8157 | #define DEFAULT_SHORT_RETRY_LIMIT 7U |
| 8158 | #define DEFAULT_LONG_RETRY_LIMIT 4U |
| 8159 | |
| 8160 | static int ipw_sw_reset(struct ipw_priv *priv, int init) |
| 8161 | { |
| 8162 | int band, modulation; |
| 8163 | int old_mode = priv->ieee->iw_mode; |
| 8164 | |
| 8165 | /* Initialize module parameter values here */ |
| 8166 | priv->config = 0; |
| 8167 | |
| 8168 | /* We default to disabling the LED code as right now it causes |
| 8169 | * too many systems to lock up... */ |
| 8170 | if (!led) |
| 8171 | priv->config |= CFG_NO_LED; |
| 8172 | |
| 8173 | if (associate) |
| 8174 | priv->config |= CFG_ASSOCIATE; |
| 8175 | else |
| 8176 | IPW_DEBUG_INFO("Auto associate disabled.\n"); |
| 8177 | |
| 8178 | if (auto_create) |
| 8179 | priv->config |= CFG_ADHOC_CREATE; |
| 8180 | else |
| 8181 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); |
| 8182 | |
| 8183 | if (disable) { |
| 8184 | priv->status |= STATUS_RF_KILL_SW; |
| 8185 | IPW_DEBUG_INFO("Radio disabled.\n"); |
| 8186 | } |
| 8187 | |
| 8188 | if (channel != 0) { |
| 8189 | priv->config |= CFG_STATIC_CHANNEL; |
| 8190 | priv->channel = channel; |
| 8191 | IPW_DEBUG_INFO("Bind to static channel %d\n", channel); |
| 8192 | /* TODO: Validate that provided channel is in range */ |
| 8193 | } |
| 8194 | #ifdef CONFIG_IPW_QOS |
| 8195 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
| 8196 | burst_duration_CCK, burst_duration_OFDM); |
| 8197 | #endif /* CONFIG_IPW_QOS */ |
| 8198 | |
| 8199 | switch (mode) { |
| 8200 | case 1: |
| 8201 | priv->ieee->iw_mode = IW_MODE_ADHOC; |
| 8202 | priv->net_dev->type = ARPHRD_ETHER; |
| 8203 | |
| 8204 | break; |
| 8205 | #ifdef CONFIG_IPW2200_MONITOR |
| 8206 | case 2: |
| 8207 | priv->ieee->iw_mode = IW_MODE_MONITOR; |
| 8208 | priv->net_dev->type = ARPHRD_IEEE80211; |
| 8209 | break; |
| 8210 | #endif |
| 8211 | default: |
| 8212 | case 0: |
| 8213 | priv->net_dev->type = ARPHRD_ETHER; |
| 8214 | priv->ieee->iw_mode = IW_MODE_INFRA; |
| 8215 | break; |
| 8216 | } |
| 8217 | |
| 8218 | if (hwcrypto) { |
| 8219 | priv->ieee->host_encrypt = 0; |
| 8220 | priv->ieee->host_encrypt_msdu = 0; |
| 8221 | priv->ieee->host_decrypt = 0; |
| 8222 | } |
| 8223 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); |
| 8224 | |
Zhu Yi | e402c93 | 2005-08-05 17:20:40 +0800 | [diff] [blame] | 8225 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
| 8226 | priv->ieee->host_open_frag = 0; |
| 8227 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8228 | if ((priv->pci_dev->device == 0x4223) || |
| 8229 | (priv->pci_dev->device == 0x4224)) { |
| 8230 | if (init) |
| 8231 | printk(KERN_INFO DRV_NAME |
| 8232 | ": Detected Intel PRO/Wireless 2915ABG Network " |
| 8233 | "Connection\n"); |
| 8234 | priv->ieee->abg_true = 1; |
| 8235 | band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; |
| 8236 | modulation = IEEE80211_OFDM_MODULATION | |
| 8237 | IEEE80211_CCK_MODULATION; |
| 8238 | priv->adapter = IPW_2915ABG; |
| 8239 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; |
| 8240 | } else { |
| 8241 | if (init) |
| 8242 | printk(KERN_INFO DRV_NAME |
| 8243 | ": Detected Intel PRO/Wireless 2200BG Network " |
| 8244 | "Connection\n"); |
| 8245 | |
| 8246 | priv->ieee->abg_true = 0; |
| 8247 | band = IEEE80211_24GHZ_BAND; |
| 8248 | modulation = IEEE80211_OFDM_MODULATION | |
| 8249 | IEEE80211_CCK_MODULATION; |
| 8250 | priv->adapter = IPW_2200BG; |
| 8251 | priv->ieee->mode = IEEE_G | IEEE_B; |
| 8252 | } |
| 8253 | |
| 8254 | priv->ieee->freq_band = band; |
| 8255 | priv->ieee->modulation = modulation; |
| 8256 | |
| 8257 | priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK; |
| 8258 | |
| 8259 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
| 8260 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; |
| 8261 | |
| 8262 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8263 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; |
| 8264 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; |
| 8265 | |
| 8266 | /* If power management is turned on, default to AC mode */ |
| 8267 | priv->power_mode = IPW_POWER_AC; |
| 8268 | priv->tx_power = IPW_TX_POWER_DEFAULT; |
| 8269 | |
Zhu Yi | 0ece35b | 2005-08-05 17:26:51 +0800 | [diff] [blame] | 8270 | return old_mode == priv->ieee->iw_mode; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8271 | } |
| 8272 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8273 | /* |
| 8274 | * This file defines the Wireless Extension handlers. It does not |
| 8275 | * define any methods of hardware manipulation and relies on the |
| 8276 | * functions defined in ipw_main to provide the HW interaction. |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8277 | * |
| 8278 | * The exception to this is the use of the ipw_get_ordinal() |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8279 | * function used to poll the hardware vs. making unecessary calls. |
| 8280 | * |
| 8281 | */ |
| 8282 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8283 | static int ipw_wx_get_name(struct net_device *dev, |
| 8284 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8285 | union iwreq_data *wrqu, char *extra) |
| 8286 | { |
| 8287 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8288 | down(&priv->sem); |
| 8289 | if (priv->status & STATUS_RF_KILL_MASK) |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 8290 | strcpy(wrqu->name, "radio off"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8291 | else if (!(priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8292 | strcpy(wrqu->name, "unassociated"); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8293 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8294 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c", |
| 8295 | ipw_modes[priv->assoc_request.ieee_mode]); |
| 8296 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8297 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8298 | return 0; |
| 8299 | } |
| 8300 | |
| 8301 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
| 8302 | { |
| 8303 | if (channel == 0) { |
| 8304 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); |
| 8305 | priv->config &= ~CFG_STATIC_CHANNEL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8306 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8307 | "parameters.\n"); |
| 8308 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8309 | return 0; |
| 8310 | } |
| 8311 | |
| 8312 | priv->config |= CFG_STATIC_CHANNEL; |
| 8313 | |
| 8314 | if (priv->channel == channel) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8315 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
| 8316 | channel); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8317 | return 0; |
| 8318 | } |
| 8319 | |
| 8320 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); |
| 8321 | priv->channel = channel; |
| 8322 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8323 | #ifdef CONFIG_IPW2200_MONITOR |
| 8324 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8325 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8326 | if (priv->status & STATUS_SCANNING) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8327 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8328 | "channel change.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8329 | ipw_abort_scan(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8330 | } |
| 8331 | |
| 8332 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) |
| 8333 | udelay(10); |
| 8334 | |
| 8335 | if (priv->status & STATUS_SCANNING) |
| 8336 | IPW_DEBUG_SCAN("Still scanning...\n"); |
| 8337 | else |
| 8338 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", |
| 8339 | 1000 - i); |
| 8340 | |
| 8341 | return 0; |
| 8342 | } |
| 8343 | #endif /* CONFIG_IPW2200_MONITOR */ |
| 8344 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8345 | /* Network configuration changed -- force [re]association */ |
| 8346 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); |
| 8347 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8348 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8349 | |
| 8350 | return 0; |
| 8351 | } |
| 8352 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8353 | static int ipw_wx_set_freq(struct net_device *dev, |
| 8354 | struct iw_request_info *info, |
| 8355 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8356 | { |
| 8357 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8358 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8359 | struct iw_freq *fwrq = &wrqu->freq; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8360 | int ret = 0, i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8361 | u8 channel; |
| 8362 | |
| 8363 | if (fwrq->m == 0) { |
| 8364 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); |
| 8365 | down(&priv->sem); |
| 8366 | ret = ipw_set_channel(priv, 0); |
| 8367 | up(&priv->sem); |
| 8368 | return ret; |
| 8369 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8370 | /* if setting by freq convert to channel */ |
| 8371 | if (fwrq->e == 1) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8372 | channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m); |
| 8373 | if (channel == 0) |
| 8374 | return -EINVAL; |
| 8375 | } else |
| 8376 | channel = fwrq->m; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8377 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8378 | if (!ieee80211_is_valid_channel(priv->ieee, channel)) |
| 8379 | return -EINVAL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8380 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8381 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && priv->ieee->mode & IEEE_A) { |
| 8382 | i = ieee80211_channel_to_index(priv->ieee, channel); |
| 8383 | if (i == -1) |
| 8384 | return -EINVAL; |
| 8385 | if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { |
| 8386 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
| 8387 | return -EINVAL; |
| 8388 | } |
| 8389 | } |
| 8390 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8391 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8392 | down(&priv->sem); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8393 | ret = ipw_set_channel(priv, channel); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8394 | up(&priv->sem); |
| 8395 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8396 | } |
| 8397 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8398 | static int ipw_wx_get_freq(struct net_device *dev, |
| 8399 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8400 | union iwreq_data *wrqu, char *extra) |
| 8401 | { |
| 8402 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8403 | |
| 8404 | wrqu->freq.e = 0; |
| 8405 | |
| 8406 | /* If we are associated, trying to associate, or have a statically |
| 8407 | * configured CHANNEL then return that; otherwise return ANY */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8408 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8409 | if (priv->config & CFG_STATIC_CHANNEL || |
| 8410 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) |
| 8411 | wrqu->freq.m = priv->channel; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8412 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8413 | wrqu->freq.m = 0; |
| 8414 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8415 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8416 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
| 8417 | return 0; |
| 8418 | } |
| 8419 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8420 | static int ipw_wx_set_mode(struct net_device *dev, |
| 8421 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8422 | union iwreq_data *wrqu, char *extra) |
| 8423 | { |
| 8424 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8425 | int err = 0; |
| 8426 | |
| 8427 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8428 | |
| 8429 | switch (wrqu->mode) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8430 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8431 | case IW_MODE_MONITOR: |
| 8432 | #endif |
| 8433 | case IW_MODE_ADHOC: |
| 8434 | case IW_MODE_INFRA: |
| 8435 | break; |
| 8436 | case IW_MODE_AUTO: |
| 8437 | wrqu->mode = IW_MODE_INFRA; |
| 8438 | break; |
| 8439 | default: |
| 8440 | return -EINVAL; |
| 8441 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8442 | if (wrqu->mode == priv->ieee->iw_mode) |
| 8443 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8444 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8445 | down(&priv->sem); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8446 | |
| 8447 | ipw_sw_reset(priv, 0); |
| 8448 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8449 | #ifdef CONFIG_IPW2200_MONITOR |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8450 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8451 | priv->net_dev->type = ARPHRD_ETHER; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8452 | |
| 8453 | if (wrqu->mode == IW_MODE_MONITOR) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8454 | priv->net_dev->type = ARPHRD_IEEE80211; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8455 | #endif /* CONFIG_IPW2200_MONITOR */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8456 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8457 | /* Free the existing firmware and reset the fw_loaded |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8458 | * flag so ipw_load() will bring in the new firmawre */ |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8459 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8460 | |
| 8461 | priv->ieee->iw_mode = wrqu->mode; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8462 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8463 | queue_work(priv->workqueue, &priv->adapter_restart); |
| 8464 | up(&priv->sem); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8465 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8466 | } |
| 8467 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8468 | static int ipw_wx_get_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8469 | struct iw_request_info *info, |
| 8470 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8471 | { |
| 8472 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8473 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8474 | wrqu->mode = priv->ieee->iw_mode; |
| 8475 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8476 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8477 | return 0; |
| 8478 | } |
| 8479 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8480 | /* Values are in microsecond */ |
| 8481 | static const s32 timeout_duration[] = { |
| 8482 | 350000, |
| 8483 | 250000, |
| 8484 | 75000, |
| 8485 | 37000, |
| 8486 | 25000, |
| 8487 | }; |
| 8488 | |
| 8489 | static const s32 period_duration[] = { |
| 8490 | 400000, |
| 8491 | 700000, |
| 8492 | 1000000, |
| 8493 | 1000000, |
| 8494 | 1000000 |
| 8495 | }; |
| 8496 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8497 | static int ipw_wx_get_range(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 | struct iw_range *range = (struct iw_range *)extra; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8503 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
| 8504 | int i = 0, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8505 | |
| 8506 | wrqu->data.length = sizeof(*range); |
| 8507 | memset(range, 0, sizeof(*range)); |
| 8508 | |
| 8509 | /* 54Mbs == ~27 Mb/s real (802.11g) */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8510 | range->throughput = 27 * 1000 * 1000; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8511 | |
| 8512 | range->max_qual.qual = 100; |
| 8513 | /* TODO: Find real max RSSI and stick here */ |
| 8514 | range->max_qual.level = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8515 | range->max_qual.noise = priv->ieee->worst_rssi + 0x100; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8516 | range->max_qual.updated = 7; /* Updated all three */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8517 | |
| 8518 | range->avg_qual.qual = 70; |
| 8519 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8520 | range->avg_qual.level = 0; /* FIXME to real average level */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8521 | range->avg_qual.noise = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8522 | range->avg_qual.updated = 7; /* Updated all three */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8523 | down(&priv->sem); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8524 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8525 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8526 | for (i = 0; i < range->num_bitrates; i++) |
| 8527 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8528 | 500000; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8529 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8530 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
| 8531 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 8532 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 8533 | |
| 8534 | range->encoding_size[0] = 5; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8535 | range->encoding_size[1] = 13; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8536 | range->num_encoding_sizes = 2; |
| 8537 | range->max_encoding_tokens = WEP_KEYS; |
| 8538 | |
| 8539 | /* Set the Wireless Extension versions */ |
| 8540 | range->we_version_compiled = WIRELESS_EXT; |
| 8541 | range->we_version_source = 16; |
| 8542 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8543 | i = 0; |
| 8544 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { |
| 8545 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; |
| 8546 | i++, j++) { |
| 8547 | range->freq[i].i = geo->bg[j].channel; |
| 8548 | range->freq[i].m = geo->bg[j].freq * 100000; |
| 8549 | range->freq[i].e = 1; |
| 8550 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8551 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8552 | |
| 8553 | if (priv->ieee->mode & IEEE_A) { |
| 8554 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; |
| 8555 | i++, j++) { |
| 8556 | range->freq[i].i = geo->a[j].channel; |
| 8557 | range->freq[i].m = geo->a[j].freq * 100000; |
| 8558 | range->freq[i].e = 1; |
| 8559 | } |
| 8560 | } |
| 8561 | |
| 8562 | range->num_channels = i; |
| 8563 | range->num_frequency = i; |
| 8564 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8565 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8566 | IPW_DEBUG_WX("GET Range\n"); |
| 8567 | return 0; |
| 8568 | } |
| 8569 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8570 | static int ipw_wx_set_wap(struct net_device *dev, |
| 8571 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8572 | union iwreq_data *wrqu, char *extra) |
| 8573 | { |
| 8574 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8575 | |
| 8576 | static const unsigned char any[] = { |
| 8577 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 8578 | }; |
| 8579 | static const unsigned char off[] = { |
| 8580 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 8581 | }; |
| 8582 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8583 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8584 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8585 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8586 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
| 8587 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8588 | /* we disable mandatory BSSID association */ |
| 8589 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); |
| 8590 | priv->config &= ~CFG_STATIC_BSSID; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8591 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8592 | "parameters.\n"); |
| 8593 | ipw_associate(priv); |
| 8594 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8595 | return 0; |
| 8596 | } |
| 8597 | |
| 8598 | priv->config |= CFG_STATIC_BSSID; |
| 8599 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { |
| 8600 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8601 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8602 | return 0; |
| 8603 | } |
| 8604 | |
| 8605 | IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n", |
| 8606 | MAC_ARG(wrqu->ap_addr.sa_data)); |
| 8607 | |
| 8608 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); |
| 8609 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8610 | /* Network configuration changed -- force [re]association */ |
| 8611 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); |
| 8612 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8613 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8614 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8615 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8616 | return 0; |
| 8617 | } |
| 8618 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8619 | static int ipw_wx_get_wap(struct net_device *dev, |
| 8620 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8621 | union iwreq_data *wrqu, char *extra) |
| 8622 | { |
| 8623 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8624 | /* If we are associated, trying to associate, or have a statically |
| 8625 | * configured BSSID then return that; otherwise return ANY */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8626 | down(&priv->sem); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8627 | if (priv->config & CFG_STATIC_BSSID || |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8628 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8629 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8630 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8631 | } else |
| 8632 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 8633 | |
| 8634 | IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", |
| 8635 | MAC_ARG(wrqu->ap_addr.sa_data)); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8636 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8637 | return 0; |
| 8638 | } |
| 8639 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8640 | static int ipw_wx_set_essid(struct net_device *dev, |
| 8641 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8642 | union iwreq_data *wrqu, char *extra) |
| 8643 | { |
| 8644 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8645 | char *essid = ""; /* ANY */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8646 | int length = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8647 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8648 | if (wrqu->essid.flags && wrqu->essid.length) { |
| 8649 | length = wrqu->essid.length - 1; |
| 8650 | essid = extra; |
| 8651 | } |
| 8652 | if (length == 0) { |
| 8653 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8654 | if ((priv->config & CFG_STATIC_ESSID) && |
| 8655 | !(priv->status & (STATUS_ASSOCIATED | |
| 8656 | STATUS_ASSOCIATING))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8657 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
| 8658 | "parameters.\n"); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8659 | priv->config &= ~CFG_STATIC_ESSID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8660 | ipw_associate(priv); |
| 8661 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8662 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8663 | return 0; |
| 8664 | } |
| 8665 | |
| 8666 | length = min(length, IW_ESSID_MAX_SIZE); |
| 8667 | |
| 8668 | priv->config |= CFG_STATIC_ESSID; |
| 8669 | |
| 8670 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { |
| 8671 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
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 | |
| 8676 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length), |
| 8677 | length); |
| 8678 | |
| 8679 | priv->essid_len = length; |
| 8680 | memcpy(priv->essid, essid, priv->essid_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8681 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8682 | /* Network configuration changed -- force [re]association */ |
| 8683 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); |
| 8684 | if (!ipw_disassociate(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8685 | ipw_associate(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8686 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8687 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8688 | return 0; |
| 8689 | } |
| 8690 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8691 | static int ipw_wx_get_essid(struct net_device *dev, |
| 8692 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8693 | union iwreq_data *wrqu, char *extra) |
| 8694 | { |
| 8695 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8696 | |
| 8697 | /* If we are associated, trying to associate, or have a statically |
| 8698 | * configured ESSID then return that; otherwise return ANY */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8699 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8700 | if (priv->config & CFG_STATIC_ESSID || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8701 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
| 8702 | IPW_DEBUG_WX("Getting essid: '%s'\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8703 | escape_essid(priv->essid, priv->essid_len)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8704 | memcpy(extra, priv->essid, priv->essid_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8705 | wrqu->essid.length = priv->essid_len; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8706 | wrqu->essid.flags = 1; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8707 | } else { |
| 8708 | IPW_DEBUG_WX("Getting essid: ANY\n"); |
| 8709 | wrqu->essid.length = 0; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8710 | wrqu->essid.flags = 0; /* active */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8711 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8712 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8713 | return 0; |
| 8714 | } |
| 8715 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8716 | static int ipw_wx_set_nick(struct net_device *dev, |
| 8717 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8718 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8719 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8720 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8721 | |
| 8722 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); |
| 8723 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) |
| 8724 | return -E2BIG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8725 | down(&priv->sem); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8726 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8727 | memset(priv->nick, 0, sizeof(priv->nick)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8728 | memcpy(priv->nick, extra, wrqu->data.length); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8729 | IPW_DEBUG_TRACE("<<\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8730 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8731 | return 0; |
| 8732 | |
| 8733 | } |
| 8734 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8735 | static int ipw_wx_get_nick(struct net_device *dev, |
| 8736 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8737 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8738 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8739 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8740 | IPW_DEBUG_WX("Getting nick\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8741 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8742 | wrqu->data.length = strlen(priv->nick) + 1; |
| 8743 | memcpy(extra, priv->nick, wrqu->data.length); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8744 | wrqu->data.flags = 1; /* active */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8745 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8746 | return 0; |
| 8747 | } |
| 8748 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8749 | static int ipw_wx_set_rate(struct net_device *dev, |
| 8750 | struct iw_request_info *info, |
| 8751 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8752 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8753 | /* TODO: We should use semaphores or locks for access to priv */ |
| 8754 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 8755 | u32 target_rate = wrqu->bitrate.value; |
| 8756 | u32 fixed, mask; |
| 8757 | |
| 8758 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ |
| 8759 | /* value = X, fixed = 1 means only rate X */ |
| 8760 | /* value = X, fixed = 0 means all rates lower equal X */ |
| 8761 | |
| 8762 | if (target_rate == -1) { |
| 8763 | fixed = 0; |
| 8764 | mask = IEEE80211_DEFAULT_RATES_MASK; |
| 8765 | /* Now we should reassociate */ |
| 8766 | goto apply; |
| 8767 | } |
| 8768 | |
| 8769 | mask = 0; |
| 8770 | fixed = wrqu->bitrate.fixed; |
| 8771 | |
| 8772 | if (target_rate == 1000000 || !fixed) |
| 8773 | mask |= IEEE80211_CCK_RATE_1MB_MASK; |
| 8774 | if (target_rate == 1000000) |
| 8775 | goto apply; |
| 8776 | |
| 8777 | if (target_rate == 2000000 || !fixed) |
| 8778 | mask |= IEEE80211_CCK_RATE_2MB_MASK; |
| 8779 | if (target_rate == 2000000) |
| 8780 | goto apply; |
| 8781 | |
| 8782 | if (target_rate == 5500000 || !fixed) |
| 8783 | mask |= IEEE80211_CCK_RATE_5MB_MASK; |
| 8784 | if (target_rate == 5500000) |
| 8785 | goto apply; |
| 8786 | |
| 8787 | if (target_rate == 6000000 || !fixed) |
| 8788 | mask |= IEEE80211_OFDM_RATE_6MB_MASK; |
| 8789 | if (target_rate == 6000000) |
| 8790 | goto apply; |
| 8791 | |
| 8792 | if (target_rate == 9000000 || !fixed) |
| 8793 | mask |= IEEE80211_OFDM_RATE_9MB_MASK; |
| 8794 | if (target_rate == 9000000) |
| 8795 | goto apply; |
| 8796 | |
| 8797 | if (target_rate == 11000000 || !fixed) |
| 8798 | mask |= IEEE80211_CCK_RATE_11MB_MASK; |
| 8799 | if (target_rate == 11000000) |
| 8800 | goto apply; |
| 8801 | |
| 8802 | if (target_rate == 12000000 || !fixed) |
| 8803 | mask |= IEEE80211_OFDM_RATE_12MB_MASK; |
| 8804 | if (target_rate == 12000000) |
| 8805 | goto apply; |
| 8806 | |
| 8807 | if (target_rate == 18000000 || !fixed) |
| 8808 | mask |= IEEE80211_OFDM_RATE_18MB_MASK; |
| 8809 | if (target_rate == 18000000) |
| 8810 | goto apply; |
| 8811 | |
| 8812 | if (target_rate == 24000000 || !fixed) |
| 8813 | mask |= IEEE80211_OFDM_RATE_24MB_MASK; |
| 8814 | if (target_rate == 24000000) |
| 8815 | goto apply; |
| 8816 | |
| 8817 | if (target_rate == 36000000 || !fixed) |
| 8818 | mask |= IEEE80211_OFDM_RATE_36MB_MASK; |
| 8819 | if (target_rate == 36000000) |
| 8820 | goto apply; |
| 8821 | |
| 8822 | if (target_rate == 48000000 || !fixed) |
| 8823 | mask |= IEEE80211_OFDM_RATE_48MB_MASK; |
| 8824 | if (target_rate == 48000000) |
| 8825 | goto apply; |
| 8826 | |
| 8827 | if (target_rate == 54000000 || !fixed) |
| 8828 | mask |= IEEE80211_OFDM_RATE_54MB_MASK; |
| 8829 | if (target_rate == 54000000) |
| 8830 | goto apply; |
| 8831 | |
| 8832 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); |
| 8833 | return -EINVAL; |
| 8834 | |
| 8835 | apply: |
| 8836 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", |
| 8837 | mask, fixed ? "fixed" : "sub-rates"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8838 | down(&priv->sem); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8839 | if (mask == IEEE80211_DEFAULT_RATES_MASK) { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8840 | priv->config &= ~CFG_FIXED_RATE; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8841 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
| 8842 | } else |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8843 | priv->config |= CFG_FIXED_RATE; |
| 8844 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8845 | if (priv->rates_mask == mask) { |
| 8846 | IPW_DEBUG_WX("Mask set to current mask.\n"); |
| 8847 | up(&priv->sem); |
| 8848 | return 0; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8849 | } |
| 8850 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8851 | priv->rates_mask = mask; |
| 8852 | |
| 8853 | /* Network configuration changed -- force [re]association */ |
| 8854 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); |
| 8855 | if (!ipw_disassociate(priv)) |
| 8856 | ipw_associate(priv); |
| 8857 | |
| 8858 | up(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 8859 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8860 | } |
| 8861 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8862 | static int ipw_wx_get_rate(struct net_device *dev, |
| 8863 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8864 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8865 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8866 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8867 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8868 | wrqu->bitrate.value = priv->last_rate; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8869 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8870 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
| 8871 | return 0; |
| 8872 | } |
| 8873 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8874 | static int ipw_wx_set_rts(struct net_device *dev, |
| 8875 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8876 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8877 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8878 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8879 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8880 | if (wrqu->rts.disabled) |
| 8881 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
| 8882 | else { |
| 8883 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8884 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
| 8885 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8886 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8887 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8888 | priv->rts_threshold = wrqu->rts.value; |
| 8889 | } |
| 8890 | |
| 8891 | ipw_send_rts_threshold(priv, priv->rts_threshold); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8892 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8893 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
| 8894 | return 0; |
| 8895 | } |
| 8896 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8897 | static int ipw_wx_get_rts(struct net_device *dev, |
| 8898 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8899 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8900 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8901 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8902 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8903 | wrqu->rts.value = priv->rts_threshold; |
| 8904 | wrqu->rts.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8905 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8906 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8907 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
| 8908 | return 0; |
| 8909 | } |
| 8910 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8911 | static int ipw_wx_set_txpow(struct net_device *dev, |
| 8912 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8913 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8914 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8915 | struct ipw_priv *priv = ieee80211_priv(dev); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8916 | int err = 0; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8917 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8918 | down(&priv->sem); |
| 8919 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8920 | err = -EINPROGRESS; |
| 8921 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8922 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8923 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8924 | if (!wrqu->power.fixed) |
| 8925 | wrqu->power.value = IPW_TX_POWER_DEFAULT; |
| 8926 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8927 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8928 | err = -EINVAL; |
| 8929 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8930 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8931 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8932 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 8933 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8934 | err = -EINVAL; |
| 8935 | goto out; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8936 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8937 | |
| 8938 | priv->tx_power = wrqu->power.value; |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8939 | err = ipw_set_tx_power(priv); |
| 8940 | out: |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8941 | up(&priv->sem); |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 8942 | return err; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8943 | } |
| 8944 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8945 | static int ipw_wx_get_txpow(struct net_device *dev, |
| 8946 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8947 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8948 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8949 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8950 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8951 | wrqu->power.value = priv->tx_power; |
| 8952 | wrqu->power.fixed = 1; |
| 8953 | wrqu->power.flags = IW_TXPOW_DBM; |
| 8954 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8955 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8956 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8957 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
Zhu Yi | 22501c8 | 2005-08-11 10:49:17 +0800 | [diff] [blame] | 8958 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8959 | |
| 8960 | return 0; |
| 8961 | } |
| 8962 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8963 | static int ipw_wx_set_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8964 | struct iw_request_info *info, |
| 8965 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8966 | { |
| 8967 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8968 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8969 | if (wrqu->frag.disabled) |
| 8970 | priv->ieee->fts = DEFAULT_FTS; |
| 8971 | else { |
| 8972 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8973 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
| 8974 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8975 | return -EINVAL; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 8976 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8977 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8978 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
| 8979 | } |
| 8980 | |
| 8981 | ipw_send_frag_threshold(priv, wrqu->frag.value); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8982 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8983 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
| 8984 | return 0; |
| 8985 | } |
| 8986 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 8987 | static int ipw_wx_get_frag(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8988 | struct iw_request_info *info, |
| 8989 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8990 | { |
| 8991 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8992 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8993 | wrqu->frag.value = priv->ieee->fts; |
| 8994 | wrqu->frag.fixed = 0; /* no auto select */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 8995 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 8996 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 8997 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
| 8998 | |
| 8999 | return 0; |
| 9000 | } |
| 9001 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9002 | static int ipw_wx_set_retry(struct net_device *dev, |
| 9003 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9004 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9005 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9006 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9007 | |
| 9008 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) |
| 9009 | return -EINVAL; |
| 9010 | |
| 9011 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) |
| 9012 | return 0; |
| 9013 | |
| 9014 | if (wrqu->retry.value < 0 || wrqu->retry.value > 255) |
| 9015 | return -EINVAL; |
| 9016 | |
| 9017 | down(&priv->sem); |
| 9018 | if (wrqu->retry.flags & IW_RETRY_MIN) |
| 9019 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 9020 | else if (wrqu->retry.flags & IW_RETRY_MAX) |
| 9021 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9022 | else { |
| 9023 | priv->short_retry_limit = (u8) wrqu->retry.value; |
| 9024 | priv->long_retry_limit = (u8) wrqu->retry.value; |
| 9025 | } |
| 9026 | |
| 9027 | ipw_send_retry_limit(priv, priv->short_retry_limit, |
| 9028 | priv->long_retry_limit); |
| 9029 | up(&priv->sem); |
| 9030 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
| 9031 | priv->short_retry_limit, priv->long_retry_limit); |
| 9032 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9033 | } |
| 9034 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9035 | static int ipw_wx_get_retry(struct net_device *dev, |
| 9036 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9037 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9038 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9039 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9040 | |
| 9041 | down(&priv->sem); |
| 9042 | wrqu->retry.disabled = 0; |
| 9043 | |
| 9044 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
| 9045 | up(&priv->sem); |
| 9046 | return -EINVAL; |
| 9047 | } |
| 9048 | |
| 9049 | if (wrqu->retry.flags & IW_RETRY_MAX) { |
| 9050 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 9051 | wrqu->retry.value = priv->long_retry_limit; |
| 9052 | } else if (wrqu->retry.flags & IW_RETRY_MIN) { |
| 9053 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; |
| 9054 | wrqu->retry.value = priv->short_retry_limit; |
| 9055 | } else { |
| 9056 | wrqu->retry.flags = IW_RETRY_LIMIT; |
| 9057 | wrqu->retry.value = priv->short_retry_limit; |
| 9058 | } |
| 9059 | up(&priv->sem); |
| 9060 | |
| 9061 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); |
| 9062 | |
| 9063 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9064 | } |
| 9065 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9066 | #if WIRELESS_EXT > 17 |
| 9067 | static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid, |
| 9068 | int essid_len) |
| 9069 | { |
| 9070 | struct ipw_scan_request_ext scan; |
| 9071 | int err = 0, scan_type; |
| 9072 | |
| 9073 | down(&priv->sem); |
| 9074 | |
| 9075 | if (priv->status & STATUS_RF_KILL_MASK) { |
| 9076 | IPW_DEBUG_HC("Aborting scan due to RF kill activation\n"); |
| 9077 | priv->status |= STATUS_SCAN_PENDING; |
| 9078 | goto done; |
| 9079 | } |
| 9080 | |
| 9081 | IPW_DEBUG_HC("starting request direct scan!\n"); |
| 9082 | |
| 9083 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { |
| 9084 | err = wait_event_interruptible(priv->wait_state, |
| 9085 | !(priv-> |
| 9086 | status & (STATUS_SCANNING | |
| 9087 | STATUS_SCAN_ABORTING))); |
| 9088 | if (err) { |
| 9089 | IPW_DEBUG_HC("aborting direct scan"); |
| 9090 | goto done; |
| 9091 | } |
| 9092 | } |
| 9093 | memset(&scan, 0, sizeof(scan)); |
| 9094 | |
| 9095 | if (priv->config & CFG_SPEED_SCAN) |
| 9096 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 9097 | cpu_to_le16(30); |
| 9098 | else |
| 9099 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
| 9100 | cpu_to_le16(20); |
| 9101 | |
| 9102 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
| 9103 | cpu_to_le16(20); |
| 9104 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20); |
| 9105 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
| 9106 | |
| 9107 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
| 9108 | |
| 9109 | err = ipw_send_ssid(priv, essid, essid_len); |
| 9110 | if (err) { |
| 9111 | IPW_DEBUG_HC("Attempt to send SSID command failed\n"); |
| 9112 | goto done; |
| 9113 | } |
| 9114 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
| 9115 | |
| 9116 | ipw_add_scan_channels(priv, &scan, scan_type); |
| 9117 | |
| 9118 | err = ipw_send_scan_request_ext(priv, &scan); |
| 9119 | if (err) { |
| 9120 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
| 9121 | goto done; |
| 9122 | } |
| 9123 | |
| 9124 | priv->status |= STATUS_SCANNING; |
| 9125 | |
| 9126 | done: |
| 9127 | up(&priv->sem); |
| 9128 | return err; |
| 9129 | } |
| 9130 | #endif /* WIRELESS_EXT > 17 */ |
| 9131 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9132 | static int ipw_wx_set_scan(struct net_device *dev, |
| 9133 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9134 | union iwreq_data *wrqu, char *extra) |
| 9135 | { |
| 9136 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9137 | #if WIRELESS_EXT > 17 |
| 9138 | struct iw_scan_req *req = NULL; |
| 9139 | if (wrqu->data.length |
| 9140 | && wrqu->data.length == sizeof(struct iw_scan_req)) { |
| 9141 | req = (struct iw_scan_req *)extra; |
| 9142 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
| 9143 | ipw_request_direct_scan(priv, req->essid, |
| 9144 | req->essid_len); |
| 9145 | return 0; |
| 9146 | } |
| 9147 | } |
| 9148 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9149 | IPW_DEBUG_WX("Start scan\n"); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9150 | |
| 9151 | queue_work(priv->workqueue, &priv->request_scan); |
| 9152 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9153 | return 0; |
| 9154 | } |
| 9155 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9156 | static int ipw_wx_get_scan(struct net_device *dev, |
| 9157 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9158 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9159 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9160 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9161 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); |
| 9162 | } |
| 9163 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9164 | static int ipw_wx_set_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9165 | struct iw_request_info *info, |
| 9166 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9167 | { |
| 9168 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9169 | int ret; |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9170 | u32 cap = priv->capability; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9171 | |
| 9172 | down(&priv->sem); |
| 9173 | ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9174 | |
Hong Liu | caeff81 | 2005-08-05 17:25:50 +0800 | [diff] [blame] | 9175 | /* In IBSS mode, we need to notify the firmware to update |
| 9176 | * the beacon info after we changed the capability. */ |
| 9177 | if (cap != priv->capability && |
| 9178 | priv->ieee->iw_mode == IW_MODE_ADHOC && |
| 9179 | priv->status & STATUS_ASSOCIATED) |
| 9180 | ipw_disassociate(priv); |
| 9181 | |
| 9182 | up(&priv->sem); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9183 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9184 | } |
| 9185 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9186 | static int ipw_wx_get_encode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9187 | struct iw_request_info *info, |
| 9188 | union iwreq_data *wrqu, char *key) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9189 | { |
| 9190 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9191 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); |
| 9192 | } |
| 9193 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9194 | static int ipw_wx_set_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9195 | struct iw_request_info *info, |
| 9196 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9197 | { |
| 9198 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9199 | int err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9200 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9201 | if (wrqu->power.disabled) { |
| 9202 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); |
| 9203 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); |
| 9204 | if (err) { |
| 9205 | IPW_DEBUG_WX("failed setting power mode.\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9206 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9207 | return err; |
| 9208 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9209 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9210 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9211 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9212 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9213 | |
| 9214 | switch (wrqu->power.flags & IW_POWER_MODE) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9215 | case IW_POWER_ON: /* If not specified */ |
| 9216 | case IW_POWER_MODE: /* If set all mask */ |
| 9217 | case IW_POWER_ALL_R: /* If explicitely state all */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9218 | break; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9219 | default: /* Otherwise we don't support it */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9220 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
| 9221 | wrqu->power.flags); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9222 | up(&priv->sem); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9223 | return -EOPNOTSUPP; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9224 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9225 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9226 | /* If the user hasn't specified a power management mode yet, default |
| 9227 | * to BATTERY */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9228 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9229 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9230 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9231 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
| 9232 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
| 9233 | if (err) { |
| 9234 | IPW_DEBUG_WX("failed setting power mode.\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9235 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9236 | return err; |
| 9237 | } |
| 9238 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9239 | 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] | 9240 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9241 | return 0; |
| 9242 | } |
| 9243 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9244 | static int ipw_wx_get_power(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9245 | struct iw_request_info *info, |
| 9246 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9247 | { |
| 9248 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9249 | down(&priv->sem); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9250 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9251 | wrqu->power.disabled = 1; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9252 | else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9253 | wrqu->power.disabled = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9254 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9255 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9256 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9257 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9258 | return 0; |
| 9259 | } |
| 9260 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9261 | static int ipw_wx_set_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9262 | struct iw_request_info *info, |
| 9263 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9264 | { |
| 9265 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9266 | int mode = *(int *)extra; |
| 9267 | int err; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9268 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9269 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) { |
| 9270 | mode = IPW_POWER_AC; |
| 9271 | priv->power_mode = mode; |
| 9272 | } else { |
| 9273 | priv->power_mode = IPW_POWER_ENABLED | mode; |
| 9274 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9275 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9276 | if (priv->power_mode != mode) { |
| 9277 | err = ipw_send_power_mode(priv, mode); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9278 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9279 | if (err) { |
| 9280 | IPW_DEBUG_WX("failed setting power mode.\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9281 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9282 | return err; |
| 9283 | } |
| 9284 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9285 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9286 | return 0; |
| 9287 | } |
| 9288 | |
| 9289 | #define MAX_WX_STRING 80 |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9290 | static int ipw_wx_get_powermode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9291 | struct iw_request_info *info, |
| 9292 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9293 | { |
| 9294 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9295 | int level = IPW_POWER_LEVEL(priv->power_mode); |
| 9296 | char *p = extra; |
| 9297 | |
| 9298 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); |
| 9299 | |
| 9300 | switch (level) { |
| 9301 | case IPW_POWER_AC: |
| 9302 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); |
| 9303 | break; |
| 9304 | case IPW_POWER_BATTERY: |
| 9305 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); |
| 9306 | break; |
| 9307 | default: |
| 9308 | p += snprintf(p, MAX_WX_STRING - (p - extra), |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9309 | "(Timeout %dms, Period %dms)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9310 | timeout_duration[level - 1] / 1000, |
| 9311 | period_duration[level - 1] / 1000); |
| 9312 | } |
| 9313 | |
| 9314 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9315 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9316 | |
| 9317 | wrqu->data.length = p - extra + 1; |
| 9318 | |
| 9319 | return 0; |
| 9320 | } |
| 9321 | |
| 9322 | static int ipw_wx_set_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9323 | struct iw_request_info *info, |
| 9324 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9325 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9326 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9327 | int mode = *(int *)extra; |
| 9328 | u8 band = 0, modulation = 0; |
| 9329 | |
| 9330 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9331 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9332 | return -EINVAL; |
| 9333 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9334 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9335 | if (priv->adapter == IPW_2915ABG) { |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9336 | priv->ieee->abg_true = 1; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9337 | if (mode & IEEE_A) { |
| 9338 | band |= IEEE80211_52GHZ_BAND; |
| 9339 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9340 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9341 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9342 | } else { |
| 9343 | if (mode & IEEE_A) { |
| 9344 | IPW_WARNING("Attempt to set 2200BG into " |
| 9345 | "802.11a mode\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9346 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9347 | return -EINVAL; |
| 9348 | } |
| 9349 | |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9350 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9351 | } |
| 9352 | |
| 9353 | if (mode & IEEE_B) { |
| 9354 | band |= IEEE80211_24GHZ_BAND; |
| 9355 | modulation |= IEEE80211_CCK_MODULATION; |
| 9356 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9357 | priv->ieee->abg_true = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9358 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9359 | if (mode & IEEE_G) { |
| 9360 | band |= IEEE80211_24GHZ_BAND; |
| 9361 | modulation |= IEEE80211_OFDM_MODULATION; |
| 9362 | } else |
James Ketrenos | a33a198 | 2005-09-14 14:28:59 -0500 | [diff] [blame] | 9363 | priv->ieee->abg_true = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9364 | |
| 9365 | priv->ieee->mode = mode; |
| 9366 | priv->ieee->freq_band = band; |
| 9367 | priv->ieee->modulation = modulation; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9368 | init_supported_rates(priv, &priv->rates); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9369 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9370 | /* Network configuration changed -- force [re]association */ |
| 9371 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); |
| 9372 | if (!ipw_disassociate(priv)) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9373 | ipw_send_supported_rates(priv, &priv->rates); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9374 | ipw_associate(priv); |
| 9375 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9376 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9377 | /* Update the band LEDs */ |
| 9378 | ipw_led_band_on(priv); |
| 9379 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9380 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9381 | mode & IEEE_A ? 'a' : '.', |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9382 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9383 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9384 | return 0; |
| 9385 | } |
| 9386 | |
| 9387 | static int ipw_wx_get_wireless_mode(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9388 | struct iw_request_info *info, |
| 9389 | union iwreq_data *wrqu, char *extra) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9390 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 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 | switch (priv->ieee->mode) { |
| 9394 | case IEEE_A: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9395 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
| 9396 | break; |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9397 | case IEEE_B: |
| 9398 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); |
| 9399 | break; |
| 9400 | case IEEE_A | IEEE_B: |
| 9401 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); |
| 9402 | break; |
| 9403 | case IEEE_G: |
| 9404 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); |
| 9405 | break; |
| 9406 | case IEEE_A | IEEE_G: |
| 9407 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); |
| 9408 | break; |
| 9409 | case IEEE_B | IEEE_G: |
| 9410 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); |
| 9411 | break; |
| 9412 | case IEEE_A | IEEE_B | IEEE_G: |
| 9413 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); |
| 9414 | break; |
| 9415 | default: |
| 9416 | strncpy(extra, "unknown", MAX_WX_STRING); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9417 | break; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9418 | } |
| 9419 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9420 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
| 9421 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9422 | wrqu->data.length = strlen(extra) + 1; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9423 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9424 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9425 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9426 | } |
| 9427 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9428 | static int ipw_wx_set_preamble(struct net_device *dev, |
| 9429 | struct iw_request_info *info, |
| 9430 | union iwreq_data *wrqu, char *extra) |
| 9431 | { |
| 9432 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9433 | int mode = *(int *)extra; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9434 | down(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9435 | /* Switching from SHORT -> LONG requires a disassociation */ |
| 9436 | if (mode == 1) { |
| 9437 | if (!(priv->config & CFG_PREAMBLE_LONG)) { |
| 9438 | priv->config |= CFG_PREAMBLE_LONG; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9439 | |
| 9440 | /* Network configuration changed -- force [re]association */ |
| 9441 | IPW_DEBUG_ASSOC |
| 9442 | ("[re]association triggered due to preamble change.\n"); |
| 9443 | if (!ipw_disassociate(priv)) |
| 9444 | ipw_associate(priv); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9445 | } |
| 9446 | goto done; |
| 9447 | } |
| 9448 | |
| 9449 | if (mode == 0) { |
| 9450 | priv->config &= ~CFG_PREAMBLE_LONG; |
| 9451 | goto done; |
| 9452 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9453 | up(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9454 | return -EINVAL; |
| 9455 | |
| 9456 | done: |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9457 | up(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9458 | return 0; |
| 9459 | } |
| 9460 | |
| 9461 | static int ipw_wx_get_preamble(struct net_device *dev, |
| 9462 | struct iw_request_info *info, |
| 9463 | union iwreq_data *wrqu, char *extra) |
| 9464 | { |
| 9465 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9466 | down(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9467 | if (priv->config & CFG_PREAMBLE_LONG) |
| 9468 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); |
| 9469 | else |
| 9470 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9471 | up(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9472 | return 0; |
| 9473 | } |
| 9474 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9475 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9476 | static int ipw_wx_set_monitor(struct net_device *dev, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9477 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9478 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9479 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9480 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9481 | int *parms = (int *)extra; |
| 9482 | int enable = (parms[0] > 0); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9483 | down(&priv->sem); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9484 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9485 | if (enable) { |
| 9486 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 9487 | priv->net_dev->type = ARPHRD_IEEE80211; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9488 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9489 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9490 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9491 | ipw_set_channel(priv, parms[1]); |
| 9492 | } else { |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9493 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
| 9494 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9495 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9496 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9497 | priv->net_dev->type = ARPHRD_ETHER; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9498 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9499 | } |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9500 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9501 | return 0; |
| 9502 | } |
| 9503 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9504 | #endif // CONFIG_IPW2200_MONITOR |
| 9505 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9506 | static int ipw_wx_reset(struct net_device *dev, |
| 9507 | struct iw_request_info *info, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9508 | union iwreq_data *wrqu, char *extra) |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9509 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9510 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9511 | IPW_DEBUG_WX("RESET\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9512 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9513 | return 0; |
| 9514 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9515 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9516 | static int ipw_wx_sw_reset(struct net_device *dev, |
| 9517 | struct iw_request_info *info, |
| 9518 | union iwreq_data *wrqu, char *extra) |
| 9519 | { |
| 9520 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9521 | union iwreq_data wrqu_sec = { |
| 9522 | .encoding = { |
| 9523 | .flags = IW_ENCODE_DISABLED, |
| 9524 | }, |
| 9525 | }; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9526 | int ret; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9527 | |
| 9528 | IPW_DEBUG_WX("SW_RESET\n"); |
| 9529 | |
| 9530 | down(&priv->sem); |
| 9531 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9532 | ret = ipw_sw_reset(priv, 0); |
| 9533 | if (!ret) { |
| 9534 | free_firmware(); |
| 9535 | ipw_adapter_restart(priv); |
| 9536 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9537 | |
| 9538 | /* The SW reset bit might have been toggled on by the 'disable' |
| 9539 | * module parameter, so take appropriate action */ |
| 9540 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); |
| 9541 | |
| 9542 | up(&priv->sem); |
| 9543 | ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
| 9544 | down(&priv->sem); |
| 9545 | |
| 9546 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 9547 | /* Configuration likely changed -- force [re]association */ |
| 9548 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " |
| 9549 | "reset.\n"); |
| 9550 | if (!ipw_disassociate(priv)) |
| 9551 | ipw_associate(priv); |
| 9552 | } |
| 9553 | |
| 9554 | up(&priv->sem); |
| 9555 | |
| 9556 | return 0; |
| 9557 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9558 | |
| 9559 | /* Rebase the WE IOCTLs to zero for the handler array */ |
| 9560 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9561 | static iw_handler ipw_wx_handlers[] = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9562 | IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, |
| 9563 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, |
| 9564 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, |
| 9565 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, |
| 9566 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, |
| 9567 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
| 9568 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, |
| 9569 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, |
| 9570 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, |
| 9571 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, |
| 9572 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, |
| 9573 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, |
| 9574 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, |
| 9575 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, |
| 9576 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, |
| 9577 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, |
| 9578 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, |
| 9579 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, |
| 9580 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, |
| 9581 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, |
| 9582 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, |
| 9583 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, |
| 9584 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, |
| 9585 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, |
| 9586 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, |
| 9587 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, |
| 9588 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, |
| 9589 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9590 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
| 9591 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, |
| 9592 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, |
| 9593 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9594 | #if WIRELESS_EXT > 17 |
| 9595 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
| 9596 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, |
| 9597 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, |
| 9598 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, |
| 9599 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, |
| 9600 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, |
| 9601 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, |
| 9602 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9603 | }; |
| 9604 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9605 | enum { |
| 9606 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, |
| 9607 | IPW_PRIV_GET_POWER, |
| 9608 | IPW_PRIV_SET_MODE, |
| 9609 | IPW_PRIV_GET_MODE, |
| 9610 | IPW_PRIV_SET_PREAMBLE, |
| 9611 | IPW_PRIV_GET_PREAMBLE, |
| 9612 | IPW_PRIV_RESET, |
| 9613 | IPW_PRIV_SW_RESET, |
| 9614 | #ifdef CONFIG_IPW2200_MONITOR |
| 9615 | IPW_PRIV_SET_MONITOR, |
| 9616 | #endif |
| 9617 | }; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9618 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9619 | static struct iw_priv_args ipw_priv_args[] = { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9620 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9621 | .cmd = IPW_PRIV_SET_POWER, |
| 9622 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9623 | .name = "set_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9624 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9625 | .cmd = IPW_PRIV_GET_POWER, |
| 9626 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9627 | .name = "get_power"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9628 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9629 | .cmd = IPW_PRIV_SET_MODE, |
| 9630 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9631 | .name = "set_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9632 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9633 | .cmd = IPW_PRIV_GET_MODE, |
| 9634 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, |
| 9635 | .name = "get_mode"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9636 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9637 | .cmd = IPW_PRIV_SET_PREAMBLE, |
| 9638 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 9639 | .name = "set_preamble"}, |
| 9640 | { |
| 9641 | .cmd = IPW_PRIV_GET_PREAMBLE, |
| 9642 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, |
| 9643 | .name = "get_preamble"}, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9644 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9645 | IPW_PRIV_RESET, |
| 9646 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9647 | { |
| 9648 | IPW_PRIV_SW_RESET, |
| 9649 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, |
| 9650 | #ifdef CONFIG_IPW2200_MONITOR |
| 9651 | { |
| 9652 | IPW_PRIV_SET_MONITOR, |
| 9653 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, |
| 9654 | #endif /* CONFIG_IPW2200_MONITOR */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9655 | }; |
| 9656 | |
| 9657 | static iw_handler ipw_priv_handler[] = { |
| 9658 | ipw_wx_set_powermode, |
| 9659 | ipw_wx_get_powermode, |
| 9660 | ipw_wx_set_wireless_mode, |
| 9661 | ipw_wx_get_wireless_mode, |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9662 | ipw_wx_set_preamble, |
| 9663 | ipw_wx_get_preamble, |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9664 | ipw_wx_reset, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9665 | ipw_wx_sw_reset, |
| 9666 | #ifdef CONFIG_IPW2200_MONITOR |
| 9667 | ipw_wx_set_monitor, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9668 | #endif |
| 9669 | }; |
| 9670 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9671 | static struct iw_handler_def ipw_wx_handler_def = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9672 | .standard = ipw_wx_handlers, |
| 9673 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), |
| 9674 | .num_private = ARRAY_SIZE(ipw_priv_handler), |
| 9675 | .num_private_args = ARRAY_SIZE(ipw_priv_args), |
| 9676 | .private = ipw_priv_handler, |
| 9677 | .private_args = ipw_priv_args, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9678 | }; |
| 9679 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9680 | static struct iw_public_data ipw_wx_data; |
| 9681 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9682 | /* |
| 9683 | * Get wireless statistics. |
| 9684 | * Called by /proc/net/wireless |
| 9685 | * Also called by SIOCGIWSTATS |
| 9686 | */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9687 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9688 | { |
| 9689 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9690 | struct iw_statistics *wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9691 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9692 | wstats = &priv->wstats; |
| 9693 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9694 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9695 | * netdev->get_wireless_stats seems to be called before fw is |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9696 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
| 9697 | * and associated; if not associcated, the values are all meaningless |
| 9698 | * anyway, so set them all to NULL and INVALID */ |
| 9699 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 9700 | wstats->miss.beacon = 0; |
| 9701 | wstats->discard.retries = 0; |
| 9702 | wstats->qual.qual = 0; |
| 9703 | wstats->qual.level = 0; |
| 9704 | wstats->qual.noise = 0; |
| 9705 | wstats->qual.updated = 7; |
| 9706 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9707 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9708 | return wstats; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9709 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9710 | |
| 9711 | wstats->qual.qual = priv->quality; |
| 9712 | wstats->qual.level = average_value(&priv->average_rssi); |
| 9713 | wstats->qual.noise = average_value(&priv->average_noise); |
| 9714 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9715 | IW_QUAL_NOISE_UPDATED; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9716 | |
| 9717 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); |
| 9718 | wstats->discard.retries = priv->last_tx_failures; |
| 9719 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9720 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9721 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
| 9722 | goto fail_get_ordinal; |
| 9723 | wstats->discard.retries += tx_retry; */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9724 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9725 | return wstats; |
| 9726 | } |
| 9727 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9728 | /* net device stuff */ |
| 9729 | |
| 9730 | static inline void init_sys_config(struct ipw_sys_config *sys_config) |
| 9731 | { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9732 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
| 9733 | sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9734 | sys_config->answer_broadcast_ssid_probe = 0; |
| 9735 | sys_config->accept_all_data_frames = 0; |
| 9736 | sys_config->accept_non_directed_frames = 1; |
| 9737 | sys_config->exclude_unicast_unencrypted = 0; |
| 9738 | sys_config->disable_unicast_decryption = 1; |
| 9739 | sys_config->exclude_multicast_unencrypted = 0; |
| 9740 | sys_config->disable_multicast_decryption = 1; |
| 9741 | sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9742 | 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] | 9743 | sys_config->dot11g_auto_detection = 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9744 | sys_config->enable_cts_to_self = 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9745 | sys_config->bt_coexist_collision_thr = 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9746 | sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256 |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9747 | } |
| 9748 | |
| 9749 | static int ipw_net_open(struct net_device *dev) |
| 9750 | { |
| 9751 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9752 | IPW_DEBUG_INFO("dev->open\n"); |
| 9753 | /* we should be verifying the device is ready to be opened */ |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9754 | down(&priv->sem); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9755 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
| 9756 | (priv->status & STATUS_ASSOCIATED)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9757 | netif_start_queue(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9758 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9759 | return 0; |
| 9760 | } |
| 9761 | |
| 9762 | static int ipw_net_stop(struct net_device *dev) |
| 9763 | { |
| 9764 | IPW_DEBUG_INFO("dev->close\n"); |
| 9765 | netif_stop_queue(dev); |
| 9766 | return 0; |
| 9767 | } |
| 9768 | |
| 9769 | /* |
| 9770 | todo: |
| 9771 | |
| 9772 | modify to send one tfd per fragment instead of using chunking. otherwise |
| 9773 | we need to heavily modify the ieee80211_skb_to_txb. |
| 9774 | */ |
| 9775 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9776 | static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb, |
| 9777 | int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9778 | { |
James Ketrenos | 0dacca1 | 2005-09-21 12:23:41 -0500 | [diff] [blame] | 9779 | struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9780 | txb->fragments[0]->data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9781 | int i = 0; |
| 9782 | struct tfd_frame *tfd; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9783 | #ifdef CONFIG_IPW_QOS |
| 9784 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 9785 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 9786 | #else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9787 | struct clx2_tx_queue *txq = &priv->txq[0]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9788 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9789 | struct clx2_queue *q = &txq->q; |
| 9790 | u8 id, hdr_len, unicast; |
| 9791 | u16 remaining_bytes; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9792 | int fc; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9793 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9794 | /* If there isn't room in the queue, we return busy and let the |
| 9795 | * network stack requeue the packet for us */ |
| 9796 | if (ipw_queue_space(q) < q->high_mark) |
| 9797 | return NETDEV_TX_BUSY; |
| 9798 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9799 | switch (priv->ieee->iw_mode) { |
| 9800 | case IW_MODE_ADHOC: |
| 9801 | hdr_len = IEEE80211_3ADDR_LEN; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9802 | unicast = !is_multicast_ether_addr(hdr->addr1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9803 | id = ipw_find_station(priv, hdr->addr1); |
| 9804 | if (id == IPW_INVALID_STATION) { |
| 9805 | id = ipw_add_station(priv, hdr->addr1); |
| 9806 | if (id == IPW_INVALID_STATION) { |
| 9807 | IPW_WARNING("Attempt to send data to " |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9808 | "invalid cell: " MAC_FMT "\n", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9809 | MAC_ARG(hdr->addr1)); |
| 9810 | goto drop; |
| 9811 | } |
| 9812 | } |
| 9813 | break; |
| 9814 | |
| 9815 | case IW_MODE_INFRA: |
| 9816 | default: |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9817 | unicast = !is_multicast_ether_addr(hdr->addr3); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9818 | hdr_len = IEEE80211_3ADDR_LEN; |
| 9819 | id = 0; |
| 9820 | break; |
| 9821 | } |
| 9822 | |
| 9823 | tfd = &txq->bd[q->first_empty]; |
| 9824 | txq->txb[q->first_empty] = txb; |
| 9825 | memset(tfd, 0, sizeof(*tfd)); |
| 9826 | tfd->u.data.station_number = id; |
| 9827 | |
| 9828 | tfd->control_flags.message_type = TX_FRAME_TYPE; |
| 9829 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; |
| 9830 | |
| 9831 | tfd->u.data.cmd_id = DINO_CMD_TX; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9832 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9833 | remaining_bytes = txb->payload_size; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9834 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9835 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9836 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9837 | else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9838 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9839 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 9840 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
| 9841 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9842 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 9843 | fc = le16_to_cpu(hdr->frame_ctl); |
| 9844 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); |
| 9845 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9846 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); |
| 9847 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 9848 | if (likely(unicast)) |
| 9849 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 9850 | |
| 9851 | if (txb->encrypted && !priv->ieee->host_encrypt) { |
| 9852 | switch (priv->ieee->sec.level) { |
| 9853 | case SEC_LEVEL_3: |
| 9854 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9855 | IEEE80211_FCTL_PROTECTED; |
| 9856 | /* XXX: ACK flag must be set for CCMP even if it |
| 9857 | * is a multicast/broadcast packet, because CCMP |
| 9858 | * group communication encrypted by GTK is |
| 9859 | * actually done by the AP. */ |
| 9860 | if (!unicast) |
| 9861 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; |
| 9862 | |
| 9863 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 9864 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; |
| 9865 | tfd->u.data.key_index = 0; |
| 9866 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; |
| 9867 | break; |
| 9868 | case SEC_LEVEL_2: |
| 9869 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9870 | IEEE80211_FCTL_PROTECTED; |
| 9871 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
| 9872 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; |
| 9873 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; |
| 9874 | break; |
| 9875 | case SEC_LEVEL_1: |
| 9876 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= |
| 9877 | IEEE80211_FCTL_PROTECTED; |
| 9878 | tfd->u.data.key_index = priv->ieee->tx_keyidx; |
| 9879 | if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <= |
| 9880 | 40) |
| 9881 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; |
| 9882 | else |
| 9883 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; |
| 9884 | break; |
| 9885 | case SEC_LEVEL_0: |
| 9886 | break; |
| 9887 | default: |
| 9888 | printk(KERN_ERR "Unknow security level %d\n", |
| 9889 | priv->ieee->sec.level); |
| 9890 | break; |
| 9891 | } |
| 9892 | } else |
| 9893 | /* No hardware encryption */ |
| 9894 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; |
| 9895 | |
| 9896 | #ifdef CONFIG_IPW_QOS |
| 9897 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast); |
| 9898 | #endif /* CONFIG_IPW_QOS */ |
| 9899 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9900 | /* payload */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9901 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
| 9902 | txb->nr_frags)); |
| 9903 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", |
| 9904 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); |
| 9905 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { |
| 9906 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", |
| 9907 | i, le32_to_cpu(tfd->u.data.num_chunks), |
| 9908 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9909 | 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] | 9910 | i, tfd->u.data.num_chunks, |
| 9911 | txb->fragments[i]->len - hdr_len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9912 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9913 | txb->fragments[i]->len - hdr_len); |
| 9914 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9915 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9916 | cpu_to_le32(pci_map_single |
| 9917 | (priv->pci_dev, |
| 9918 | txb->fragments[i]->data + hdr_len, |
| 9919 | txb->fragments[i]->len - hdr_len, |
| 9920 | PCI_DMA_TODEVICE)); |
| 9921 | tfd->u.data.chunk_len[i] = |
| 9922 | cpu_to_le16(txb->fragments[i]->len - hdr_len); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9923 | } |
| 9924 | |
| 9925 | if (i != txb->nr_frags) { |
| 9926 | struct sk_buff *skb; |
| 9927 | u16 remaining_bytes = 0; |
| 9928 | int j; |
| 9929 | |
| 9930 | for (j = i; j < txb->nr_frags; j++) |
| 9931 | remaining_bytes += txb->fragments[j]->len - hdr_len; |
| 9932 | |
| 9933 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", |
| 9934 | remaining_bytes); |
| 9935 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); |
| 9936 | if (skb != NULL) { |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9937 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9938 | for (j = i; j < txb->nr_frags; j++) { |
| 9939 | int size = txb->fragments[j]->len - hdr_len; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 9940 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9941 | printk(KERN_INFO "Adding frag %d %d...\n", |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9942 | j, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9943 | memcpy(skb_put(skb, size), |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9944 | txb->fragments[j]->data + hdr_len, size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9945 | } |
| 9946 | dev_kfree_skb_any(txb->fragments[i]); |
| 9947 | txb->fragments[i] = skb; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9948 | tfd->u.data.chunk_ptr[i] = |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 9949 | cpu_to_le32(pci_map_single |
| 9950 | (priv->pci_dev, skb->data, |
| 9951 | tfd->u.data.chunk_len[i], |
| 9952 | PCI_DMA_TODEVICE)); |
| 9953 | |
| 9954 | tfd->u.data.num_chunks = |
| 9955 | cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) + |
| 9956 | 1); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 9957 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9958 | } |
| 9959 | |
| 9960 | /* kick DMA */ |
| 9961 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); |
| 9962 | ipw_write32(priv, q->reg_w, q->first_empty); |
| 9963 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9964 | return NETDEV_TX_OK; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9965 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 9966 | drop: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9967 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
| 9968 | ieee80211_txb_free(txb); |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9969 | return NETDEV_TX_OK; |
| 9970 | } |
| 9971 | |
| 9972 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) |
| 9973 | { |
| 9974 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9975 | #ifdef CONFIG_IPW_QOS |
| 9976 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
| 9977 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; |
| 9978 | #else |
| 9979 | struct clx2_tx_queue *txq = &priv->txq[0]; |
| 9980 | #endif /* CONFIG_IPW_QOS */ |
| 9981 | |
| 9982 | if (ipw_queue_space(&txq->q) < txq->q.high_mark) |
| 9983 | return 1; |
| 9984 | |
| 9985 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9986 | } |
| 9987 | |
| 9988 | static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, |
James Ketrenos | c8d42d1 | 2005-09-21 12:23:43 -0500 | [diff] [blame] | 9989 | struct net_device *dev, int pri) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9990 | { |
| 9991 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 9992 | unsigned long flags; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 9993 | int ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9994 | |
| 9995 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 9996 | spin_lock_irqsave(&priv->lock, flags); |
| 9997 | |
| 9998 | if (!(priv->status & STATUS_ASSOCIATED)) { |
| 9999 | IPW_DEBUG_INFO("Tx attempt while not associated.\n"); |
| 10000 | priv->ieee->stats.tx_carrier_errors++; |
| 10001 | netif_stop_queue(dev); |
| 10002 | goto fail_unlock; |
| 10003 | } |
| 10004 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10005 | ret = ipw_tx_skb(priv, txb, pri); |
| 10006 | if (ret == NETDEV_TX_OK) |
| 10007 | __ipw_led_activity_on(priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10008 | spin_unlock_irqrestore(&priv->lock, flags); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10009 | |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 10010 | return ret; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10011 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10012 | fail_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10013 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10014 | return 1; |
| 10015 | } |
| 10016 | |
| 10017 | static struct net_device_stats *ipw_net_get_stats(struct net_device *dev) |
| 10018 | { |
| 10019 | struct ipw_priv *priv = ieee80211_priv(dev); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10020 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10021 | priv->ieee->stats.tx_packets = priv->tx_packets; |
| 10022 | priv->ieee->stats.rx_packets = priv->rx_packets; |
| 10023 | return &priv->ieee->stats; |
| 10024 | } |
| 10025 | |
| 10026 | static void ipw_net_set_multicast_list(struct net_device *dev) |
| 10027 | { |
| 10028 | |
| 10029 | } |
| 10030 | |
| 10031 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) |
| 10032 | { |
| 10033 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10034 | struct sockaddr *addr = p; |
| 10035 | if (!is_valid_ether_addr(addr->sa_data)) |
| 10036 | return -EADDRNOTAVAIL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10037 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10038 | priv->config |= CFG_CUSTOM_MAC; |
| 10039 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); |
| 10040 | printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n", |
| 10041 | priv->net_dev->name, MAC_ARG(priv->mac_addr)); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10042 | queue_work(priv->workqueue, &priv->adapter_restart); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10043 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10044 | return 0; |
| 10045 | } |
| 10046 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10047 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10048 | struct ethtool_drvinfo *info) |
| 10049 | { |
| 10050 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10051 | char vers[64]; |
| 10052 | char date[32]; |
| 10053 | u32 len; |
| 10054 | |
| 10055 | strcpy(info->driver, DRV_NAME); |
| 10056 | strcpy(info->version, DRV_VERSION); |
| 10057 | |
| 10058 | len = sizeof(vers); |
| 10059 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); |
| 10060 | len = sizeof(date); |
| 10061 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); |
| 10062 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10063 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10064 | vers, date); |
| 10065 | strcpy(info->bus_info, pci_name(p->pci_dev)); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10066 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10067 | } |
| 10068 | |
| 10069 | static u32 ipw_ethtool_get_link(struct net_device *dev) |
| 10070 | { |
| 10071 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10072 | return (priv->status & STATUS_ASSOCIATED) != 0; |
| 10073 | } |
| 10074 | |
| 10075 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) |
| 10076 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10077 | return IPW_EEPROM_IMAGE_SIZE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10078 | } |
| 10079 | |
| 10080 | static int ipw_ethtool_get_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10081 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10082 | { |
| 10083 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10084 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10085 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10086 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10087 | down(&p->sem); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10088 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10089 | up(&p->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10090 | return 0; |
| 10091 | } |
| 10092 | |
| 10093 | static int ipw_ethtool_set_eeprom(struct net_device *dev, |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10094 | struct ethtool_eeprom *eeprom, u8 * bytes) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10095 | { |
| 10096 | struct ipw_priv *p = ieee80211_priv(dev); |
| 10097 | int i; |
| 10098 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10099 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10100 | return -EINVAL; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10101 | down(&p->sem); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10102 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10103 | for (i = IPW_EEPROM_DATA; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10104 | i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10105 | ipw_write8(p, i, p->eeprom[i]); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10106 | up(&p->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10107 | return 0; |
| 10108 | } |
| 10109 | |
| 10110 | static struct ethtool_ops ipw_ethtool_ops = { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10111 | .get_link = ipw_ethtool_get_link, |
| 10112 | .get_drvinfo = ipw_ethtool_get_drvinfo, |
| 10113 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, |
| 10114 | .get_eeprom = ipw_ethtool_get_eeprom, |
| 10115 | .set_eeprom = ipw_ethtool_set_eeprom, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10116 | }; |
| 10117 | |
| 10118 | static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs) |
| 10119 | { |
| 10120 | struct ipw_priv *priv = data; |
| 10121 | u32 inta, inta_mask; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10122 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10123 | if (!priv) |
| 10124 | return IRQ_NONE; |
| 10125 | |
| 10126 | spin_lock(&priv->lock); |
| 10127 | |
| 10128 | if (!(priv->status & STATUS_INT_ENABLED)) { |
| 10129 | /* Shared IRQ */ |
| 10130 | goto none; |
| 10131 | } |
| 10132 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10133 | inta = ipw_read32(priv, IPW_INTA_RW); |
| 10134 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10135 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10136 | if (inta == 0xFFFFFFFF) { |
| 10137 | /* Hardware disappeared */ |
| 10138 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); |
| 10139 | goto none; |
| 10140 | } |
| 10141 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10142 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10143 | /* Shared interrupt */ |
| 10144 | goto none; |
| 10145 | } |
| 10146 | |
| 10147 | /* tell the device to stop sending interrupts */ |
| 10148 | ipw_disable_interrupts(priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10149 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10150 | /* ack current interrupts */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10151 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
| 10152 | ipw_write32(priv, IPW_INTA_RW, inta); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10153 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10154 | /* Cache INTA value for our tasklet */ |
| 10155 | priv->isr_inta = inta; |
| 10156 | |
| 10157 | tasklet_schedule(&priv->irq_tasklet); |
| 10158 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10159 | spin_unlock(&priv->lock); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10160 | |
| 10161 | return IRQ_HANDLED; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10162 | none: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10163 | spin_unlock(&priv->lock); |
| 10164 | return IRQ_NONE; |
| 10165 | } |
| 10166 | |
| 10167 | static void ipw_rf_kill(void *adapter) |
| 10168 | { |
| 10169 | struct ipw_priv *priv = adapter; |
| 10170 | unsigned long flags; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10171 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10172 | spin_lock_irqsave(&priv->lock, flags); |
| 10173 | |
| 10174 | if (rf_kill_active(priv)) { |
| 10175 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); |
| 10176 | if (priv->workqueue) |
| 10177 | queue_delayed_work(priv->workqueue, |
| 10178 | &priv->rf_kill, 2 * HZ); |
| 10179 | goto exit_unlock; |
| 10180 | } |
| 10181 | |
| 10182 | /* RF Kill is now disabled, so bring the device back up */ |
| 10183 | |
| 10184 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
| 10185 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " |
| 10186 | "device\n"); |
| 10187 | |
| 10188 | /* we can not do an adapter restart while inside an irq lock */ |
| 10189 | queue_work(priv->workqueue, &priv->adapter_restart); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10190 | } else |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10191 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
| 10192 | "enabled\n"); |
| 10193 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10194 | exit_unlock: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10195 | spin_unlock_irqrestore(&priv->lock, flags); |
| 10196 | } |
| 10197 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10198 | static void ipw_bg_rf_kill(void *data) |
| 10199 | { |
| 10200 | struct ipw_priv *priv = data; |
| 10201 | down(&priv->sem); |
| 10202 | ipw_rf_kill(data); |
| 10203 | up(&priv->sem); |
| 10204 | } |
| 10205 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10206 | void ipw_link_up(struct ipw_priv *priv) |
| 10207 | { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10208 | priv->last_seq_num = -1; |
| 10209 | priv->last_frag_num = -1; |
| 10210 | priv->last_packet_time = 0; |
| 10211 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10212 | netif_carrier_on(priv->net_dev); |
| 10213 | if (netif_queue_stopped(priv->net_dev)) { |
| 10214 | IPW_DEBUG_NOTIF("waking queue\n"); |
| 10215 | netif_wake_queue(priv->net_dev); |
| 10216 | } else { |
| 10217 | IPW_DEBUG_NOTIF("starting queue\n"); |
| 10218 | netif_start_queue(priv->net_dev); |
| 10219 | } |
| 10220 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10221 | cancel_delayed_work(&priv->request_scan); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10222 | ipw_reset_stats(priv); |
| 10223 | /* Ensure the rate is updated immediately */ |
| 10224 | priv->last_rate = ipw_get_current_rate(priv); |
| 10225 | ipw_gather_stats(priv); |
| 10226 | ipw_led_link_up(priv); |
| 10227 | notify_wx_assoc_event(priv); |
| 10228 | |
| 10229 | if (priv->config & CFG_BACKGROUND_SCAN) |
| 10230 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); |
| 10231 | } |
| 10232 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10233 | static void ipw_bg_link_up(void *data) |
| 10234 | { |
| 10235 | struct ipw_priv *priv = data; |
| 10236 | down(&priv->sem); |
| 10237 | ipw_link_up(data); |
| 10238 | up(&priv->sem); |
| 10239 | } |
| 10240 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10241 | void ipw_link_down(struct ipw_priv *priv) |
| 10242 | { |
| 10243 | ipw_led_link_down(priv); |
| 10244 | netif_carrier_off(priv->net_dev); |
| 10245 | netif_stop_queue(priv->net_dev); |
| 10246 | notify_wx_assoc_event(priv); |
| 10247 | |
| 10248 | /* Cancel any queued work ... */ |
| 10249 | cancel_delayed_work(&priv->request_scan); |
| 10250 | cancel_delayed_work(&priv->adhoc_check); |
| 10251 | cancel_delayed_work(&priv->gather_stats); |
| 10252 | |
| 10253 | ipw_reset_stats(priv); |
| 10254 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10255 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
| 10256 | /* Queue up another scan... */ |
| 10257 | queue_work(priv->workqueue, &priv->request_scan); |
| 10258 | } |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10259 | } |
| 10260 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10261 | static void ipw_bg_link_down(void *data) |
| 10262 | { |
| 10263 | struct ipw_priv *priv = data; |
| 10264 | down(&priv->sem); |
| 10265 | ipw_link_down(data); |
| 10266 | up(&priv->sem); |
| 10267 | } |
| 10268 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10269 | static int ipw_setup_deferred_work(struct ipw_priv *priv) |
| 10270 | { |
| 10271 | int ret = 0; |
| 10272 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10273 | priv->workqueue = create_workqueue(DRV_NAME); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10274 | init_waitqueue_head(&priv->wait_command_queue); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10275 | init_waitqueue_head(&priv->wait_state); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10276 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10277 | INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv); |
| 10278 | INIT_WORK(&priv->associate, ipw_bg_associate, priv); |
| 10279 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv); |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 10280 | INIT_WORK(&priv->system_config, ipw_system_config, priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10281 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv); |
| 10282 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv); |
| 10283 | INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv); |
| 10284 | INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv); |
| 10285 | INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10286 | INIT_WORK(&priv->request_scan, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10287 | (void (*)(void *))ipw_request_scan, priv); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10288 | INIT_WORK(&priv->gather_stats, |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10289 | (void (*)(void *))ipw_bg_gather_stats, priv); |
| 10290 | INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv); |
| 10291 | INIT_WORK(&priv->roam, ipw_bg_roam, priv); |
| 10292 | INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv); |
| 10293 | INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv); |
| 10294 | INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv); |
| 10295 | 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] | 10296 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10297 | 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] | 10298 | priv); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10299 | INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off, |
| 10300 | priv); |
| 10301 | INIT_WORK(&priv->merge_networks, |
| 10302 | (void (*)(void *))ipw_merge_adhoc_network, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10303 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10304 | #ifdef CONFIG_IPW_QOS |
| 10305 | INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate, |
| 10306 | priv); |
| 10307 | #endif /* CONFIG_IPW_QOS */ |
| 10308 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10309 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 10310 | ipw_irq_tasklet, (unsigned long)priv); |
| 10311 | |
| 10312 | return ret; |
| 10313 | } |
| 10314 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10315 | static void shim__set_security(struct net_device *dev, |
| 10316 | struct ieee80211_security *sec) |
| 10317 | { |
| 10318 | struct ipw_priv *priv = ieee80211_priv(dev); |
| 10319 | int i; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10320 | for (i = 0; i < 4; i++) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10321 | if (sec->flags & (1 << i)) { |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10322 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10323 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10324 | if (sec->key_sizes[i] == 0) |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10325 | priv->ieee->sec.flags &= ~(1 << i); |
| 10326 | else { |
| 10327 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10328 | sec->key_sizes[i]); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10329 | priv->ieee->sec.flags |= (1 << i); |
| 10330 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10331 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10332 | } else if (sec->level != SEC_LEVEL_1) |
| 10333 | priv->ieee->sec.flags &= ~(1 << i); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10334 | } |
| 10335 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10336 | if (sec->flags & SEC_ACTIVE_KEY) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10337 | if (sec->active_key <= 3) { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10338 | priv->ieee->sec.active_key = sec->active_key; |
| 10339 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10340 | } else |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10341 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10342 | priv->status |= STATUS_SECURITY_UPDATED; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10343 | } else |
| 10344 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10345 | |
| 10346 | if ((sec->flags & SEC_AUTH_MODE) && |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10347 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
| 10348 | priv->ieee->sec.auth_mode = sec->auth_mode; |
| 10349 | priv->ieee->sec.flags |= SEC_AUTH_MODE; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10350 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
| 10351 | priv->capability |= CAP_SHARED_KEY; |
| 10352 | else |
| 10353 | priv->capability &= ~CAP_SHARED_KEY; |
| 10354 | priv->status |= STATUS_SECURITY_UPDATED; |
| 10355 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10356 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10357 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
| 10358 | priv->ieee->sec.flags |= SEC_ENABLED; |
| 10359 | priv->ieee->sec.enabled = sec->enabled; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10360 | priv->status |= STATUS_SECURITY_UPDATED; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10361 | if (sec->enabled) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10362 | priv->capability |= CAP_PRIVACY_ON; |
| 10363 | else |
| 10364 | priv->capability &= ~CAP_PRIVACY_ON; |
| 10365 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10366 | |
| 10367 | if (sec->flags & SEC_ENCRYPT) |
| 10368 | priv->ieee->sec.encrypt = sec->encrypt; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10369 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10370 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
| 10371 | priv->ieee->sec.level = sec->level; |
| 10372 | priv->ieee->sec.flags |= SEC_LEVEL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10373 | priv->status |= STATUS_SECURITY_UPDATED; |
Zhu Yi | d8bad6d | 2005-07-13 12:25:38 -0500 | [diff] [blame] | 10374 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10375 | |
Zhu Yi | 1fbfea5 | 2005-08-05 17:22:56 +0800 | [diff] [blame] | 10376 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
| 10377 | ipw_set_hwcrypto_keys(priv); |
| 10378 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10379 | /* To match current functionality of ipw2100 (which works well w/ |
| 10380 | * various supplicants, we don't force a disassociate if the |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10381 | * privacy capability changes ... */ |
| 10382 | #if 0 |
| 10383 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10384 | (((priv->assoc_request.capability & |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10385 | WLAN_CAPABILITY_PRIVACY) && !sec->enabled) || |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10386 | (!(priv->assoc_request.capability & |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10387 | WLAN_CAPABILITY_PRIVACY) && sec->enabled))) { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10388 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
| 10389 | "change.\n"); |
| 10390 | ipw_disassociate(priv); |
| 10391 | } |
| 10392 | #endif |
| 10393 | } |
| 10394 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10395 | static int init_supported_rates(struct ipw_priv *priv, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10396 | struct ipw_supported_rates *rates) |
| 10397 | { |
| 10398 | /* TODO: Mask out rates based on priv->rates_mask */ |
| 10399 | |
| 10400 | memset(rates, 0, sizeof(*rates)); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10401 | /* configure supported rates */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10402 | switch (priv->ieee->freq_band) { |
| 10403 | case IEEE80211_52GHZ_BAND: |
| 10404 | rates->ieee_mode = IPW_A_MODE; |
| 10405 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10406 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10407 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10408 | break; |
| 10409 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10410 | default: /* Mixed or 2.4Ghz */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10411 | rates->ieee_mode = IPW_G_MODE; |
| 10412 | rates->purpose = IPW_RATE_CAPABILITIES; |
| 10413 | ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10414 | IEEE80211_CCK_DEFAULT_RATES_MASK); |
| 10415 | if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) { |
| 10416 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, |
| 10417 | IEEE80211_OFDM_DEFAULT_RATES_MASK); |
| 10418 | } |
| 10419 | break; |
| 10420 | } |
| 10421 | |
| 10422 | return 0; |
| 10423 | } |
| 10424 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10425 | static int ipw_config(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10426 | { |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10427 | /* This is only called from ipw_up, which resets/reloads the firmware |
| 10428 | so, we don't need to first disable the card before we configure |
| 10429 | it */ |
Zhu Yi | 6de9f7f | 2005-08-11 14:39:33 +0800 | [diff] [blame] | 10430 | if (ipw_set_tx_power(priv)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10431 | goto error; |
| 10432 | |
| 10433 | /* initialize adapter address */ |
| 10434 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) |
| 10435 | goto error; |
| 10436 | |
| 10437 | /* set basic system config settings */ |
| 10438 | init_sys_config(&priv->sys_config); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10439 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
| 10440 | priv->sys_config.answer_broadcast_ssid_probe = 1; |
| 10441 | else |
| 10442 | priv->sys_config.answer_broadcast_ssid_probe = 0; |
| 10443 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10444 | if (ipw_send_system_config(priv, &priv->sys_config)) |
| 10445 | goto error; |
| 10446 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10447 | init_supported_rates(priv, &priv->rates); |
| 10448 | if (ipw_send_supported_rates(priv, &priv->rates)) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10449 | goto error; |
| 10450 | |
| 10451 | /* Set request-to-send threshold */ |
| 10452 | if (priv->rts_threshold) { |
| 10453 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) |
| 10454 | goto error; |
| 10455 | } |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10456 | #ifdef CONFIG_IPW_QOS |
| 10457 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
| 10458 | ipw_qos_activate(priv, NULL); |
| 10459 | #endif /* CONFIG_IPW_QOS */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10460 | |
| 10461 | if (ipw_set_random_seed(priv)) |
| 10462 | goto error; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10463 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10464 | /* final state transition to the RUN state */ |
| 10465 | if (ipw_send_host_complete(priv)) |
| 10466 | goto error; |
| 10467 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame^] | 10468 | priv->status |= STATUS_INIT; |
| 10469 | |
| 10470 | ipw_led_init(priv); |
| 10471 | ipw_led_radio_on(priv); |
| 10472 | priv->notif_missed_beacons = 0; |
| 10473 | |
| 10474 | /* Set hardware WEP key if it is configured. */ |
| 10475 | if ((priv->capability & CAP_PRIVACY_ON) && |
| 10476 | (priv->ieee->sec.level == SEC_LEVEL_1) && |
| 10477 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) |
| 10478 | ipw_set_hwcrypto_keys(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10479 | |
| 10480 | return 0; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10481 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10482 | error: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10483 | return -EIO; |
| 10484 | } |
| 10485 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10486 | /* |
| 10487 | * NOTE: |
| 10488 | * |
| 10489 | * These tables have been tested in conjunction with the |
| 10490 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. |
| 10491 | * |
| 10492 | * Altering this values, using it on other hardware, or in geographies |
| 10493 | * not intended for resale of the above mentioned Intel adapters has |
| 10494 | * not been tested. |
| 10495 | * |
| 10496 | */ |
| 10497 | static const struct ieee80211_geo ipw_geos[] = { |
| 10498 | { /* Restricted */ |
| 10499 | "---", |
| 10500 | .bg_channels = 11, |
| 10501 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10502 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10503 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10504 | {2457, 10}, {2462, 11}}, |
| 10505 | }, |
| 10506 | |
| 10507 | { /* Custom US/Canada */ |
| 10508 | "ZZF", |
| 10509 | .bg_channels = 11, |
| 10510 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10511 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10512 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10513 | {2457, 10}, {2462, 11}}, |
| 10514 | .a_channels = 8, |
| 10515 | .a = {{5180, 36}, |
| 10516 | {5200, 40}, |
| 10517 | {5220, 44}, |
| 10518 | {5240, 48}, |
| 10519 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10520 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10521 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10522 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10523 | }, |
| 10524 | |
| 10525 | { /* Rest of World */ |
| 10526 | "ZZD", |
| 10527 | .bg_channels = 13, |
| 10528 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10529 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10530 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10531 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10532 | {2472, 13}}, |
| 10533 | }, |
| 10534 | |
| 10535 | { /* Custom USA & Europe & High */ |
| 10536 | "ZZA", |
| 10537 | .bg_channels = 11, |
| 10538 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10539 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10540 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10541 | {2457, 10}, {2462, 11}}, |
| 10542 | .a_channels = 13, |
| 10543 | .a = {{5180, 36}, |
| 10544 | {5200, 40}, |
| 10545 | {5220, 44}, |
| 10546 | {5240, 48}, |
| 10547 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10548 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10549 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10550 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10551 | {5745, 149}, |
| 10552 | {5765, 153}, |
| 10553 | {5785, 157}, |
| 10554 | {5805, 161}, |
| 10555 | {5825, 165}}, |
| 10556 | }, |
| 10557 | |
| 10558 | { /* Custom NA & Europe */ |
| 10559 | "ZZB", |
| 10560 | .bg_channels = 11, |
| 10561 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10562 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10563 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10564 | {2457, 10}, {2462, 11}}, |
| 10565 | .a_channels = 13, |
| 10566 | .a = {{5180, 36}, |
| 10567 | {5200, 40}, |
| 10568 | {5220, 44}, |
| 10569 | {5240, 48}, |
| 10570 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10571 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10572 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10573 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10574 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10575 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10576 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10577 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10578 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10579 | }, |
| 10580 | |
| 10581 | { /* Custom Japan */ |
| 10582 | "ZZC", |
| 10583 | .bg_channels = 11, |
| 10584 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10585 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10586 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10587 | {2457, 10}, {2462, 11}}, |
| 10588 | .a_channels = 4, |
| 10589 | .a = {{5170, 34}, {5190, 38}, |
| 10590 | {5210, 42}, {5230, 46}}, |
| 10591 | }, |
| 10592 | |
| 10593 | { /* Custom */ |
| 10594 | "ZZM", |
| 10595 | .bg_channels = 11, |
| 10596 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10597 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10598 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10599 | {2457, 10}, {2462, 11}}, |
| 10600 | }, |
| 10601 | |
| 10602 | { /* Europe */ |
| 10603 | "ZZE", |
| 10604 | .bg_channels = 13, |
| 10605 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10606 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10607 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10608 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10609 | {2472, 13}}, |
| 10610 | .a_channels = 19, |
| 10611 | .a = {{5180, 36}, |
| 10612 | {5200, 40}, |
| 10613 | {5220, 44}, |
| 10614 | {5240, 48}, |
| 10615 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10616 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10617 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10618 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10619 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 10620 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 10621 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 10622 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 10623 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 10624 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 10625 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 10626 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 10627 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 10628 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 10629 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10630 | }, |
| 10631 | |
| 10632 | { /* Custom Japan */ |
| 10633 | "ZZJ", |
| 10634 | .bg_channels = 14, |
| 10635 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10636 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10637 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10638 | {2457, 10}, {2462, 11}, {2467, 12}, |
| 10639 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}}, |
| 10640 | .a_channels = 4, |
| 10641 | .a = {{5170, 34}, {5190, 38}, |
| 10642 | {5210, 42}, {5230, 46}}, |
| 10643 | }, |
| 10644 | |
| 10645 | { /* High Band */ |
| 10646 | "ZZH", |
| 10647 | .bg_channels = 13, |
| 10648 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10649 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10650 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10651 | {2457, 10}, {2462, 11}, |
| 10652 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 10653 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10654 | .a_channels = 4, |
| 10655 | .a = {{5745, 149}, {5765, 153}, |
| 10656 | {5785, 157}, {5805, 161}}, |
| 10657 | }, |
| 10658 | |
| 10659 | { /* Custom Europe */ |
| 10660 | "ZZG", |
| 10661 | .bg_channels = 13, |
| 10662 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10663 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10664 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10665 | {2457, 10}, {2462, 11}, |
| 10666 | {2467, 12}, {2472, 13}}, |
| 10667 | .a_channels = 4, |
| 10668 | .a = {{5180, 36}, {5200, 40}, |
| 10669 | {5220, 44}, {5240, 48}}, |
| 10670 | }, |
| 10671 | |
| 10672 | { /* Europe */ |
| 10673 | "ZZK", |
| 10674 | .bg_channels = 13, |
| 10675 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10676 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10677 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10678 | {2457, 10}, {2462, 11}, |
| 10679 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, |
| 10680 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10681 | .a_channels = 24, |
| 10682 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 10683 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 10684 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 10685 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 10686 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10687 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10688 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10689 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10690 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, |
| 10691 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, |
| 10692 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, |
| 10693 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, |
| 10694 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, |
| 10695 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, |
| 10696 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, |
| 10697 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, |
| 10698 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, |
| 10699 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, |
| 10700 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}, |
| 10701 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10702 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10703 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10704 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10705 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10706 | }, |
| 10707 | |
| 10708 | { /* Europe */ |
| 10709 | "ZZL", |
| 10710 | .bg_channels = 11, |
| 10711 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, |
| 10712 | {2427, 4}, {2432, 5}, {2437, 6}, |
| 10713 | {2442, 7}, {2447, 8}, {2452, 9}, |
| 10714 | {2457, 10}, {2462, 11}}, |
| 10715 | .a_channels = 13, |
| 10716 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, |
| 10717 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, |
| 10718 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, |
| 10719 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, |
| 10720 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, |
| 10721 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, |
| 10722 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, |
| 10723 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, |
| 10724 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, |
| 10725 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, |
| 10726 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, |
| 10727 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, |
| 10728 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, |
| 10729 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10730 | }; |
| 10731 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10732 | #define MAX_HW_RESTARTS 5 |
| 10733 | static int ipw_up(struct ipw_priv *priv) |
| 10734 | { |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10735 | int rc, i, j; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10736 | |
| 10737 | if (priv->status & STATUS_EXIT_PENDING) |
| 10738 | return -EIO; |
| 10739 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10740 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10741 | /* Load the microcode, firmware, and eeprom. |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10742 | * Also start the clocks. */ |
| 10743 | rc = ipw_load(priv); |
| 10744 | if (rc) { |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10745 | IPW_ERROR("Unable to load firmware: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10746 | return rc; |
| 10747 | } |
| 10748 | |
| 10749 | ipw_init_ordinals(priv); |
| 10750 | if (!(priv->config & CFG_CUSTOM_MAC)) |
| 10751 | eeprom_parse_mac(priv, priv->mac_addr); |
| 10752 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
| 10753 | |
James Ketrenos | 4f36f80 | 2005-08-03 20:36:56 -0500 | [diff] [blame] | 10754 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
| 10755 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], |
| 10756 | ipw_geos[j].name, 3)) |
| 10757 | break; |
| 10758 | } |
| 10759 | if (j == ARRAY_SIZE(ipw_geos)) |
| 10760 | j = 0; |
| 10761 | if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) { |
| 10762 | IPW_WARNING("Could not set geography."); |
| 10763 | return 0; |
| 10764 | } |
| 10765 | |
| 10766 | IPW_DEBUG_INFO("Geography %03d [%s] detected.\n", |
| 10767 | j, priv->ieee->geo.name); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10768 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10769 | if (priv->status & STATUS_RF_KILL_SW) { |
| 10770 | IPW_WARNING("Radio disabled by module parameter.\n"); |
| 10771 | return 0; |
| 10772 | } else if (rf_kill_active(priv)) { |
| 10773 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" |
| 10774 | "Kill switch must be turned off for " |
| 10775 | "wireless networking to work.\n"); |
| 10776 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
| 10777 | 2 * HZ); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10778 | return 0; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10779 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10780 | |
| 10781 | rc = ipw_config(priv); |
| 10782 | if (!rc) { |
| 10783 | IPW_DEBUG_INFO("Configured device on count %i\n", i); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10784 | |
James Ketrenos | e666619 | 2005-08-12 09:17:04 -0500 | [diff] [blame^] | 10785 | /* If configure to try and auto-associate, kick |
| 10786 | * off a scan. */ |
| 10787 | queue_work(priv->workqueue, &priv->request_scan); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10788 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10789 | return 0; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10790 | } |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10791 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10792 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10793 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
| 10794 | i, MAX_HW_RESTARTS); |
| 10795 | |
| 10796 | /* We had an error bringing up the hardware, so take it |
| 10797 | * all the way back down so we can try again */ |
| 10798 | ipw_down(priv); |
| 10799 | } |
| 10800 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 10801 | /* tried to restart and config the device for as long as our |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10802 | * patience could withstand */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10803 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10804 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10805 | return -EIO; |
| 10806 | } |
| 10807 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10808 | static void ipw_bg_up(void *data) |
| 10809 | { |
| 10810 | struct ipw_priv *priv = data; |
| 10811 | down(&priv->sem); |
| 10812 | ipw_up(data); |
| 10813 | up(&priv->sem); |
| 10814 | } |
| 10815 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10816 | static void ipw_deinit(struct ipw_priv *priv) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10817 | { |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10818 | int i; |
| 10819 | |
| 10820 | if (priv->status & STATUS_SCANNING) { |
| 10821 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); |
| 10822 | ipw_abort_scan(priv); |
| 10823 | } |
| 10824 | |
| 10825 | if (priv->status & STATUS_ASSOCIATED) { |
| 10826 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); |
| 10827 | ipw_disassociate(priv); |
| 10828 | } |
| 10829 | |
| 10830 | ipw_led_shutdown(priv); |
| 10831 | |
| 10832 | /* Wait up to 1s for status to change to not scanning and not |
| 10833 | * associated (disassociation can take a while for a ful 802.11 |
| 10834 | * exchange */ |
| 10835 | for (i = 1000; i && (priv->status & |
| 10836 | (STATUS_DISASSOCIATING | |
| 10837 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) |
| 10838 | udelay(10); |
| 10839 | |
| 10840 | if (priv->status & (STATUS_DISASSOCIATING | |
| 10841 | STATUS_ASSOCIATED | STATUS_SCANNING)) |
| 10842 | IPW_DEBUG_INFO("Still associated or scanning...\n"); |
| 10843 | else |
| 10844 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); |
| 10845 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10846 | /* Attempt to disable the card */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10847 | ipw_send_card_disable(priv, 0); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10848 | |
| 10849 | priv->status &= ~STATUS_INIT; |
| 10850 | } |
| 10851 | |
| 10852 | static void ipw_down(struct ipw_priv *priv) |
| 10853 | { |
| 10854 | int exit_pending = priv->status & STATUS_EXIT_PENDING; |
| 10855 | |
| 10856 | priv->status |= STATUS_EXIT_PENDING; |
| 10857 | |
| 10858 | if (ipw_is_init(priv)) |
| 10859 | ipw_deinit(priv); |
| 10860 | |
| 10861 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 10862 | * exiting the module */ |
| 10863 | if (!exit_pending) |
| 10864 | priv->status &= ~STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10865 | |
| 10866 | /* tell the device to stop sending interrupts */ |
| 10867 | ipw_disable_interrupts(priv); |
| 10868 | |
| 10869 | /* Clear all bits but the RF Kill */ |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10870 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10871 | netif_carrier_off(priv->net_dev); |
| 10872 | netif_stop_queue(priv->net_dev); |
| 10873 | |
| 10874 | ipw_stop_nic(priv); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10875 | |
| 10876 | ipw_led_radio_off(priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10877 | } |
| 10878 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10879 | static void ipw_bg_down(void *data) |
| 10880 | { |
| 10881 | struct ipw_priv *priv = data; |
| 10882 | down(&priv->sem); |
| 10883 | ipw_down(data); |
| 10884 | up(&priv->sem); |
| 10885 | } |
| 10886 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10887 | #if WIRELESS_EXT < 18 |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10888 | static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 10889 | { |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10890 | struct iwreq *wrq = (struct iwreq *)rq; |
| 10891 | int ret = -1; |
| 10892 | switch (cmd) { |
| 10893 | case IPW_IOCTL_WPA_SUPPLICANT: |
| 10894 | ret = ipw_wpa_supplicant(dev, &wrq->u.data); |
| 10895 | return ret; |
| 10896 | |
| 10897 | default: |
| 10898 | return -EOPNOTSUPP; |
| 10899 | } |
| 10900 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10901 | return -EOPNOTSUPP; |
| 10902 | } |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10903 | #endif |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 10904 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10905 | /* Called by register_netdev() */ |
| 10906 | static int ipw_net_init(struct net_device *dev) |
| 10907 | { |
| 10908 | struct ipw_priv *priv = ieee80211_priv(dev); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10909 | down(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10910 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10911 | if (ipw_up(priv)) { |
| 10912 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10913 | return -EIO; |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10914 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10915 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 10916 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10917 | return 0; |
| 10918 | } |
| 10919 | |
| 10920 | /* PCI driver stuff */ |
| 10921 | static struct pci_device_id card_ids[] = { |
| 10922 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
| 10923 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, |
| 10924 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, |
| 10925 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, |
| 10926 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, |
| 10927 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, |
| 10928 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, |
| 10929 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, |
| 10930 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, |
| 10931 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, |
| 10932 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, |
| 10933 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, |
| 10934 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, |
| 10935 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, |
| 10936 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, |
| 10937 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, |
| 10938 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, |
| 10939 | {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] | 10940 | {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] | 10941 | {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] | 10942 | {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ |
| 10943 | {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] | 10944 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10945 | /* required last entry */ |
| 10946 | {0,} |
| 10947 | }; |
| 10948 | |
| 10949 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 10950 | |
| 10951 | static struct attribute *ipw_sysfs_entries[] = { |
| 10952 | &dev_attr_rf_kill.attr, |
| 10953 | &dev_attr_direct_dword.attr, |
| 10954 | &dev_attr_indirect_byte.attr, |
| 10955 | &dev_attr_indirect_dword.attr, |
| 10956 | &dev_attr_mem_gpio_reg.attr, |
| 10957 | &dev_attr_command_event_reg.attr, |
| 10958 | &dev_attr_nic_type.attr, |
| 10959 | &dev_attr_status.attr, |
| 10960 | &dev_attr_cfg.attr, |
| 10961 | &dev_attr_dump_errors.attr, |
| 10962 | &dev_attr_dump_events.attr, |
| 10963 | &dev_attr_eeprom_delay.attr, |
| 10964 | &dev_attr_ucode_version.attr, |
| 10965 | &dev_attr_rtc.attr, |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10966 | &dev_attr_scan_age.attr, |
| 10967 | &dev_attr_led.attr, |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 10968 | &dev_attr_speed_scan.attr, |
| 10969 | &dev_attr_net_stats.attr, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10970 | NULL |
| 10971 | }; |
| 10972 | |
| 10973 | static struct attribute_group ipw_attribute_group = { |
| 10974 | .name = NULL, /* put in device directory */ |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10975 | .attrs = ipw_sysfs_entries, |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10976 | }; |
| 10977 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 10978 | 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] | 10979 | { |
| 10980 | int err = 0; |
| 10981 | struct net_device *net_dev; |
| 10982 | void __iomem *base; |
| 10983 | u32 length, val; |
| 10984 | struct ipw_priv *priv; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 10985 | int i; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10986 | |
| 10987 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv)); |
| 10988 | if (net_dev == NULL) { |
| 10989 | err = -ENOMEM; |
| 10990 | goto out; |
| 10991 | } |
| 10992 | |
| 10993 | priv = ieee80211_priv(net_dev); |
| 10994 | priv->ieee = netdev_priv(net_dev); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 10995 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 10996 | priv->net_dev = net_dev; |
| 10997 | priv->pci_dev = pdev; |
| 10998 | #ifdef CONFIG_IPW_DEBUG |
| 10999 | ipw_debug_level = debug; |
| 11000 | #endif |
| 11001 | spin_lock_init(&priv->lock); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11002 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
| 11003 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11004 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11005 | init_MUTEX(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11006 | if (pci_enable_device(pdev)) { |
| 11007 | err = -ENODEV; |
| 11008 | goto out_free_ieee80211; |
| 11009 | } |
| 11010 | |
| 11011 | pci_set_master(pdev); |
| 11012 | |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 11013 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11014 | if (!err) |
Tobias Klauser | 0e08b44 | 2005-06-20 14:28:41 -0700 | [diff] [blame] | 11015 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11016 | if (err) { |
| 11017 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 11018 | goto out_pci_disable_device; |
| 11019 | } |
| 11020 | |
| 11021 | pci_set_drvdata(pdev, priv); |
| 11022 | |
| 11023 | err = pci_request_regions(pdev, DRV_NAME); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11024 | if (err) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11025 | goto out_pci_disable_device; |
| 11026 | |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11027 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11028 | * PCI Tx retries from interfering with C3 CPU state */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11029 | pci_read_config_dword(pdev, 0x40, &val); |
| 11030 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11031 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11032 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11033 | length = pci_resource_len(pdev, 0); |
| 11034 | priv->hw_len = length; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11035 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11036 | base = ioremap_nocache(pci_resource_start(pdev, 0), length); |
| 11037 | if (!base) { |
| 11038 | err = -ENODEV; |
| 11039 | goto out_pci_release_regions; |
| 11040 | } |
| 11041 | |
| 11042 | priv->hw_base = base; |
| 11043 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); |
| 11044 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); |
| 11045 | |
| 11046 | err = ipw_setup_deferred_work(priv); |
| 11047 | if (err) { |
| 11048 | IPW_ERROR("Unable to setup deferred work\n"); |
| 11049 | goto out_iounmap; |
| 11050 | } |
| 11051 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11052 | ipw_sw_reset(priv, 1); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11053 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11054 | err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11055 | if (err) { |
| 11056 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 11057 | goto out_destroy_workqueue; |
| 11058 | } |
| 11059 | |
| 11060 | SET_MODULE_OWNER(net_dev); |
| 11061 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
| 11062 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11063 | ipw_wx_data.spy_data = &priv->ieee->spy_data; |
| 11064 | ipw_wx_data.ieee80211 = priv->ieee; |
| 11065 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11066 | down(&priv->sem); |
| 11067 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11068 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
| 11069 | priv->ieee->set_security = shim__set_security; |
James Ketrenos | 227d2dc | 2005-07-28 16:25:55 -0500 | [diff] [blame] | 11070 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11071 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11072 | #ifdef CONFIG_IPW_QOS |
James Ketrenos | 2b184d5 | 2005-08-03 20:33:14 -0500 | [diff] [blame] | 11073 | priv->ieee->handle_management = ipw_handle_management; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11074 | #endif /* CONFIG_IPW_QOS */ |
| 11075 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11076 | priv->ieee->perfect_rssi = -20; |
| 11077 | priv->ieee->worst_rssi = -85; |
| 11078 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11079 | net_dev->open = ipw_net_open; |
| 11080 | net_dev->stop = ipw_net_stop; |
| 11081 | net_dev->init = ipw_net_init; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11082 | #if WIRELESS_EXT < 18 |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11083 | net_dev->do_ioctl = ipw_ioctl; |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11084 | #endif |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11085 | net_dev->get_stats = ipw_net_get_stats; |
| 11086 | net_dev->set_multicast_list = ipw_net_set_multicast_list; |
| 11087 | net_dev->set_mac_address = ipw_net_set_mac_address; |
| 11088 | net_dev->get_wireless_stats = ipw_get_wireless_stats; |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11089 | net_dev->wireless_data = &ipw_wx_data; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11090 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
| 11091 | net_dev->ethtool_ops = &ipw_ethtool_ops; |
| 11092 | net_dev->irq = pdev->irq; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11093 | net_dev->base_addr = (unsigned long)priv->hw_base; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11094 | net_dev->mem_start = pci_resource_start(pdev, 0); |
| 11095 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; |
| 11096 | |
| 11097 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); |
| 11098 | if (err) { |
| 11099 | IPW_ERROR("failed to create sysfs device attributes\n"); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11100 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11101 | goto out_release_irq; |
| 11102 | } |
| 11103 | |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11104 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11105 | err = register_netdev(net_dev); |
| 11106 | if (err) { |
| 11107 | IPW_ERROR("failed to register network device\n"); |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11108 | goto out_remove_sysfs; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11109 | } |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11110 | return 0; |
| 11111 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11112 | out_remove_sysfs: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11113 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11114 | out_release_irq: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11115 | free_irq(pdev->irq, priv); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11116 | out_destroy_workqueue: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11117 | destroy_workqueue(priv->workqueue); |
| 11118 | priv->workqueue = NULL; |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11119 | out_iounmap: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11120 | iounmap(priv->hw_base); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11121 | out_pci_release_regions: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11122 | pci_release_regions(pdev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11123 | out_pci_disable_device: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11124 | pci_disable_device(pdev); |
| 11125 | pci_set_drvdata(pdev, NULL); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11126 | out_free_ieee80211: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11127 | free_ieee80211(priv->net_dev); |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11128 | out: |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11129 | return err; |
| 11130 | } |
| 11131 | |
| 11132 | static void ipw_pci_remove(struct pci_dev *pdev) |
| 11133 | { |
| 11134 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11135 | struct list_head *p, *q; |
| 11136 | int i; |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11137 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11138 | if (!priv) |
| 11139 | return; |
| 11140 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11141 | down(&priv->sem); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11142 | |
| 11143 | priv->status |= STATUS_EXIT_PENDING; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11144 | ipw_down(priv); |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11145 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11146 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11147 | up(&priv->sem); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11148 | |
| 11149 | unregister_netdev(priv->net_dev); |
| 11150 | |
| 11151 | if (priv->rxq) { |
| 11152 | ipw_rx_queue_free(priv, priv->rxq); |
| 11153 | priv->rxq = NULL; |
| 11154 | } |
| 11155 | ipw_tx_queue_free(priv); |
| 11156 | |
| 11157 | /* ipw_down will ensure that there is no more pending work |
| 11158 | * in the workqueue's, so we can safely remove them now. */ |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11159 | cancel_delayed_work(&priv->adhoc_check); |
| 11160 | cancel_delayed_work(&priv->gather_stats); |
| 11161 | cancel_delayed_work(&priv->request_scan); |
| 11162 | cancel_delayed_work(&priv->rf_kill); |
| 11163 | cancel_delayed_work(&priv->scan_check); |
| 11164 | destroy_workqueue(priv->workqueue); |
| 11165 | priv->workqueue = NULL; |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11166 | |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11167 | /* Free MAC hash list for ADHOC */ |
| 11168 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { |
| 11169 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 11170 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
| 11171 | list_del(p); |
| 11172 | } |
| 11173 | } |
| 11174 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11175 | free_irq(pdev->irq, priv); |
| 11176 | iounmap(priv->hw_base); |
| 11177 | pci_release_regions(pdev); |
| 11178 | pci_disable_device(pdev); |
| 11179 | pci_set_drvdata(pdev, NULL); |
| 11180 | free_ieee80211(priv->net_dev); |
James Ketrenos | afbf30a | 2005-08-25 00:05:33 -0500 | [diff] [blame] | 11181 | free_firmware(); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11182 | } |
| 11183 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11184 | #ifdef CONFIG_PM |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11185 | 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] | 11186 | { |
| 11187 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11188 | struct net_device *dev = priv->net_dev; |
| 11189 | |
| 11190 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); |
| 11191 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11192 | /* Take down the device; powers it off, etc. */ |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11193 | ipw_down(priv); |
| 11194 | |
| 11195 | /* Remove the PRESENT state of the device */ |
| 11196 | netif_device_detach(dev); |
| 11197 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11198 | pci_save_state(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11199 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 11200 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11201 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11202 | return 0; |
| 11203 | } |
| 11204 | |
| 11205 | static int ipw_pci_resume(struct pci_dev *pdev) |
| 11206 | { |
| 11207 | struct ipw_priv *priv = pci_get_drvdata(pdev); |
| 11208 | struct net_device *dev = priv->net_dev; |
| 11209 | u32 val; |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11210 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11211 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
| 11212 | |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11213 | pci_set_power_state(pdev, PCI_D0); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11214 | pci_enable_device(pdev); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11215 | pci_restore_state(pdev); |
James Ketrenos | ea2b26e | 2005-08-24 21:25:16 -0500 | [diff] [blame] | 11216 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11217 | /* |
| 11218 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 11219 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 11220 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 11221 | * here since it only restores the first 64 bytes pci config header. |
| 11222 | */ |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11223 | pci_read_config_dword(pdev, 0x40, &val); |
| 11224 | if ((val & 0x0000ff00) != 0) |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11225 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 11226 | |
| 11227 | /* Set the device back into the PRESENT state; this will also wake |
| 11228 | * the queue of needed */ |
| 11229 | netif_device_attach(dev); |
| 11230 | |
| 11231 | /* Bring the device back up */ |
| 11232 | queue_work(priv->workqueue, &priv->up); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11233 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11234 | return 0; |
| 11235 | } |
| 11236 | #endif |
| 11237 | |
| 11238 | /* driver initialization stuff */ |
| 11239 | static struct pci_driver ipw_driver = { |
| 11240 | .name = DRV_NAME, |
| 11241 | .id_table = card_ids, |
| 11242 | .probe = ipw_pci_probe, |
| 11243 | .remove = __devexit_p(ipw_pci_remove), |
| 11244 | #ifdef CONFIG_PM |
| 11245 | .suspend = ipw_pci_suspend, |
| 11246 | .resume = ipw_pci_resume, |
| 11247 | #endif |
| 11248 | }; |
| 11249 | |
| 11250 | static int __init ipw_init(void) |
| 11251 | { |
| 11252 | int ret; |
| 11253 | |
| 11254 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 11255 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 11256 | |
| 11257 | ret = pci_module_init(&ipw_driver); |
| 11258 | if (ret) { |
| 11259 | IPW_ERROR("Unable to initialize PCI module\n"); |
| 11260 | return ret; |
| 11261 | } |
| 11262 | |
Jeff Garzik | 0edd5b4 | 2005-09-07 00:48:31 -0400 | [diff] [blame] | 11263 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11264 | if (ret) { |
| 11265 | IPW_ERROR("Unable to create driver sysfs file\n"); |
| 11266 | pci_unregister_driver(&ipw_driver); |
| 11267 | return ret; |
| 11268 | } |
| 11269 | |
| 11270 | return ret; |
| 11271 | } |
| 11272 | |
| 11273 | static void __exit ipw_exit(void) |
| 11274 | { |
| 11275 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); |
| 11276 | pci_unregister_driver(&ipw_driver); |
| 11277 | } |
| 11278 | |
| 11279 | module_param(disable, int, 0444); |
| 11280 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 11281 | |
| 11282 | module_param(associate, int, 0444); |
| 11283 | MODULE_PARM_DESC(associate, "auto associate when scanning (default on)"); |
| 11284 | |
| 11285 | module_param(auto_create, int, 0444); |
| 11286 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); |
| 11287 | |
James Ketrenos | a613bff | 2005-08-24 21:43:11 -0500 | [diff] [blame] | 11288 | module_param(led, int, 0444); |
James Ketrenos | c848d0a | 2005-08-24 21:56:24 -0500 | [diff] [blame] | 11289 | 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] | 11290 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11291 | module_param(debug, int, 0444); |
| 11292 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 11293 | |
| 11294 | module_param(channel, int, 0444); |
Jeff Garzik | bf79451 | 2005-07-31 13:07:26 -0400 | [diff] [blame] | 11295 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11296 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11297 | #ifdef CONFIG_IPW_QOS |
| 11298 | module_param(qos_enable, int, 0444); |
| 11299 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); |
| 11300 | |
| 11301 | module_param(qos_burst_enable, int, 0444); |
| 11302 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); |
| 11303 | |
| 11304 | module_param(qos_no_ack_mask, int, 0444); |
| 11305 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); |
| 11306 | |
| 11307 | module_param(burst_duration_CCK, int, 0444); |
| 11308 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); |
| 11309 | |
| 11310 | module_param(burst_duration_OFDM, int, 0444); |
| 11311 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); |
| 11312 | #endif /* CONFIG_IPW_QOS */ |
| 11313 | |
| 11314 | #ifdef CONFIG_IPW2200_MONITOR |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11315 | module_param(mode, int, 0444); |
| 11316 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); |
| 11317 | #else |
| 11318 | module_param(mode, int, 0444); |
| 11319 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
| 11320 | #endif |
| 11321 | |
James Ketrenos | b095c38 | 2005-08-24 22:04:42 -0500 | [diff] [blame] | 11322 | module_param(hwcrypto, int, 0444); |
| 11323 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)"); |
| 11324 | |
James Ketrenos | 43f66a6 | 2005-03-25 12:31:53 -0600 | [diff] [blame] | 11325 | module_exit(ipw_exit); |
| 11326 | module_init(ipw_init); |