1 // SPDX-License-Identifier: GPL-2.0-only 2 /****************************************************************************** 3 4 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved. 5 6 802.11 status code portion of this file from ethereal-0.10.6: 7 Copyright 2000, Axis Communications AB 8 Ethereal - Network traffic analyzer 9 By Gerald Combs <gerald@ethereal.com> 10 Copyright 1998 Gerald Combs 11 12 13 Contact Information: 14 Intel Linux Wireless <ilw@linux.intel.com> 15 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 16 17 ******************************************************************************/ 18 19 #include <linux/sched.h> 20 #include <linux/slab.h> 21 #include <net/cfg80211-wext.h> 22 #include "ipw2200.h" 23 #include "ipw.h" 24 25 26 #ifndef KBUILD_EXTMOD 27 #define VK "k" 28 #else 29 #define VK 30 #endif 31 32 #ifdef CONFIG_IPW2200_DEBUG 33 #define VD "d" 34 #else 35 #define VD 36 #endif 37 38 #ifdef CONFIG_IPW2200_MONITOR 39 #define VM "m" 40 #else 41 #define VM 42 #endif 43 44 #ifdef CONFIG_IPW2200_PROMISCUOUS 45 #define VP "p" 46 #else 47 #define VP 48 #endif 49 50 #ifdef CONFIG_IPW2200_RADIOTAP 51 #define VR "r" 52 #else 53 #define VR 54 #endif 55 56 #ifdef CONFIG_IPW2200_QOS 57 #define VQ "q" 58 #else 59 #define VQ 60 #endif 61 62 #define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ 63 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" 64 #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation" 65 #define DRV_VERSION IPW2200_VERSION 66 67 #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1) 68 69 MODULE_DESCRIPTION(DRV_DESCRIPTION); 70 MODULE_VERSION(DRV_VERSION); 71 MODULE_AUTHOR(DRV_COPYRIGHT); 72 MODULE_LICENSE("GPL"); 73 MODULE_FIRMWARE("ipw2200-ibss.fw"); 74 #ifdef CONFIG_IPW2200_MONITOR 75 MODULE_FIRMWARE("ipw2200-sniffer.fw"); 76 #endif 77 MODULE_FIRMWARE("ipw2200-bss.fw"); 78 79 static int cmdlog = 0; 80 static int debug = 0; 81 static int default_channel = 0; 82 static int network_mode = 0; 83 84 static u32 ipw_debug_level; 85 static int associate; 86 static int auto_create = 1; 87 static int led_support = 1; 88 static int disable = 0; 89 static int bt_coexist = 0; 90 static int hwcrypto = 0; 91 static int roaming = 1; 92 static const char ipw_modes[] = { 93 'a', 'b', 'g', '?' 94 }; 95 static int antenna = CFG_SYS_ANTENNA_BOTH; 96 97 #ifdef CONFIG_IPW2200_PROMISCUOUS 98 static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */ 99 #endif 100 101 static struct ieee80211_rate ipw2200_rates[] = { 102 { .bitrate = 10 }, 103 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, 104 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, 105 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, 106 { .bitrate = 60 }, 107 { .bitrate = 90 }, 108 { .bitrate = 120 }, 109 { .bitrate = 180 }, 110 { .bitrate = 240 }, 111 { .bitrate = 360 }, 112 { .bitrate = 480 }, 113 { .bitrate = 540 } 114 }; 115 116 #define ipw2200_a_rates (ipw2200_rates + 4) 117 #define ipw2200_num_a_rates 8 118 #define ipw2200_bg_rates (ipw2200_rates + 0) 119 #define ipw2200_num_bg_rates 12 120 121 /* Ugly macro to convert literal channel numbers into their mhz equivalents 122 * There are certianly some conditions that will break this (like feeding it '30') 123 * but they shouldn't arise since nothing talks on channel 30. */ 124 #define ieee80211chan2mhz(x) \ 125 (((x) <= 14) ? \ 126 (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \ 127 ((x) + 1000) * 5) 128 129 #ifdef CONFIG_IPW2200_QOS 130 static int qos_enable = 0; 131 static int qos_burst_enable = 0; 132 static int qos_no_ack_mask = 0; 133 static int burst_duration_CCK = 0; 134 static int burst_duration_OFDM = 0; 135 136 static struct libipw_qos_parameters def_qos_parameters_OFDM = { 137 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, 138 QOS_TX3_CW_MIN_OFDM}, 139 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, 140 QOS_TX3_CW_MAX_OFDM}, 141 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, 142 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, 143 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, 144 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} 145 }; 146 147 static struct libipw_qos_parameters def_qos_parameters_CCK = { 148 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, 149 QOS_TX3_CW_MIN_CCK}, 150 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, 151 QOS_TX3_CW_MAX_CCK}, 152 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, 153 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, 154 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, 155 QOS_TX3_TXOP_LIMIT_CCK} 156 }; 157 158 static struct libipw_qos_parameters def_parameters_OFDM = { 159 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, 160 DEF_TX3_CW_MIN_OFDM}, 161 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, 162 DEF_TX3_CW_MAX_OFDM}, 163 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, 164 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, 165 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, 166 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} 167 }; 168 169 static struct libipw_qos_parameters def_parameters_CCK = { 170 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, 171 DEF_TX3_CW_MIN_CCK}, 172 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, 173 DEF_TX3_CW_MAX_CCK}, 174 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, 175 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, 176 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, 177 DEF_TX3_TXOP_LIMIT_CCK} 178 }; 179 180 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; 181 182 static int from_priority_to_tx_queue[] = { 183 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, 184 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 185 }; 186 187 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); 188 189 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters 190 *qos_param); 191 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element 192 *qos_param); 193 #endif /* CONFIG_IPW2200_QOS */ 194 195 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev); 196 static void ipw_remove_current_network(struct ipw_priv *priv); 197 static void ipw_rx(struct ipw_priv *priv); 198 static int ipw_queue_tx_reclaim(struct ipw_priv *priv, 199 struct clx2_tx_queue *txq, int qindex); 200 static int ipw_queue_reset(struct ipw_priv *priv); 201 202 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, const void *buf, 203 int len, int sync); 204 205 static void ipw_tx_queue_free(struct ipw_priv *); 206 207 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); 208 static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); 209 static void ipw_rx_queue_replenish(void *); 210 static int ipw_up(struct ipw_priv *); 211 static void ipw_bg_up(struct work_struct *work); 212 static void ipw_down(struct ipw_priv *); 213 static void ipw_bg_down(struct work_struct *work); 214 static int ipw_config(struct ipw_priv *); 215 static int init_supported_rates(struct ipw_priv *priv, 216 struct ipw_supported_rates *prates); 217 static void ipw_set_hwcrypto_keys(struct ipw_priv *); 218 static void ipw_send_wep_keys(struct ipw_priv *, int); 219 220 static int snprint_line(char *buf, size_t count, 221 const u8 * data, u32 len, u32 ofs) 222 { 223 int out, i, j, l; 224 char c; 225 226 out = scnprintf(buf, count, "%08X", ofs); 227 228 for (l = 0, i = 0; i < 2; i++) { 229 out += scnprintf(buf + out, count - out, " "); 230 for (j = 0; j < 8 && l < len; j++, l++) 231 out += scnprintf(buf + out, count - out, "%02X ", 232 data[(i * 8 + j)]); 233 for (; j < 8; j++) 234 out += scnprintf(buf + out, count - out, " "); 235 } 236 237 out += scnprintf(buf + out, count - out, " "); 238 for (l = 0, i = 0; i < 2; i++) { 239 out += scnprintf(buf + out, count - out, " "); 240 for (j = 0; j < 8 && l < len; j++, l++) { 241 c = data[(i * 8 + j)]; 242 if (!isascii(c) || !isprint(c)) 243 c = '.'; 244 245 out += scnprintf(buf + out, count - out, "%c", c); 246 } 247 248 for (; j < 8; j++) 249 out += scnprintf(buf + out, count - out, " "); 250 } 251 252 return out; 253 } 254 255 static void printk_buf(int level, const u8 * data, u32 len) 256 { 257 char line[81]; 258 u32 ofs = 0; 259 if (!(ipw_debug_level & level)) 260 return; 261 262 while (len) { 263 snprint_line(line, sizeof(line), &data[ofs], 264 min(len, 16U), ofs); 265 printk(KERN_DEBUG "%s\n", line); 266 ofs += 16; 267 len -= min(len, 16U); 268 } 269 } 270 271 static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len) 272 { 273 size_t out = size; 274 u32 ofs = 0; 275 int total = 0; 276 277 while (size && len) { 278 out = snprint_line(output, size, &data[ofs], 279 min_t(size_t, len, 16U), ofs); 280 281 ofs += 16; 282 output += out; 283 size -= out; 284 len -= min_t(size_t, len, 16U); 285 total += out; 286 } 287 return total; 288 } 289 290 /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */ 291 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); 292 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) 293 294 /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */ 295 static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); 296 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) 297 298 /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ 299 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); 300 static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) 301 { 302 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, 303 __LINE__, (u32) (b), (u32) (c)); 304 _ipw_write_reg8(a, b, c); 305 } 306 307 /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ 308 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); 309 static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) 310 { 311 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, 312 __LINE__, (u32) (b), (u32) (c)); 313 _ipw_write_reg16(a, b, c); 314 } 315 316 /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ 317 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); 318 static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) 319 { 320 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, 321 __LINE__, (u32) (b), (u32) (c)); 322 _ipw_write_reg32(a, b, c); 323 } 324 325 /* 8-bit direct write (low 4K) */ 326 static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs, 327 u8 val) 328 { 329 writeb(val, ipw->hw_base + ofs); 330 } 331 332 /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ 333 #define ipw_write8(ipw, ofs, val) do { \ 334 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \ 335 __LINE__, (u32)(ofs), (u32)(val)); \ 336 _ipw_write8(ipw, ofs, val); \ 337 } while (0) 338 339 /* 16-bit direct write (low 4K) */ 340 static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs, 341 u16 val) 342 { 343 writew(val, ipw->hw_base + ofs); 344 } 345 346 /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ 347 #define ipw_write16(ipw, ofs, val) do { \ 348 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \ 349 __LINE__, (u32)(ofs), (u32)(val)); \ 350 _ipw_write16(ipw, ofs, val); \ 351 } while (0) 352 353 /* 32-bit direct write (low 4K) */ 354 static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs, 355 u32 val) 356 { 357 writel(val, ipw->hw_base + ofs); 358 } 359 360 /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ 361 #define ipw_write32(ipw, ofs, val) do { \ 362 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \ 363 __LINE__, (u32)(ofs), (u32)(val)); \ 364 _ipw_write32(ipw, ofs, val); \ 365 } while (0) 366 367 /* 8-bit direct read (low 4K) */ 368 static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs) 369 { 370 return readb(ipw->hw_base + ofs); 371 } 372 373 /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */ 374 #define ipw_read8(ipw, ofs) ({ \ 375 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \ 376 (u32)(ofs)); \ 377 _ipw_read8(ipw, ofs); \ 378 }) 379 380 /* 32-bit direct read (low 4K) */ 381 static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs) 382 { 383 return readl(ipw->hw_base + ofs); 384 } 385 386 /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */ 387 #define ipw_read32(ipw, ofs) ({ \ 388 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \ 389 (u32)(ofs)); \ 390 _ipw_read32(ipw, ofs); \ 391 }) 392 393 static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); 394 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ 395 #define ipw_read_indirect(a, b, c, d) ({ \ 396 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \ 397 __LINE__, (u32)(b), (u32)(d)); \ 398 _ipw_read_indirect(a, b, c, d); \ 399 }) 400 401 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ 402 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, 403 int num); 404 #define ipw_write_indirect(a, b, c, d) do { \ 405 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \ 406 __LINE__, (u32)(b), (u32)(d)); \ 407 _ipw_write_indirect(a, b, c, d); \ 408 } while (0) 409 410 /* 32-bit indirect write (above 4K) */ 411 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value) 412 { 413 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value); 414 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); 415 _ipw_write32(priv, IPW_INDIRECT_DATA, value); 416 } 417 418 /* 8-bit indirect write (above 4K) */ 419 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) 420 { 421 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ 422 u32 dif_len = reg - aligned_addr; 423 424 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); 425 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); 426 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value); 427 } 428 429 /* 16-bit indirect write (above 4K) */ 430 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value) 431 { 432 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ 433 u32 dif_len = (reg - aligned_addr) & (~0x1ul); 434 435 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); 436 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); 437 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value); 438 } 439 440 /* 8-bit indirect read (above 4K) */ 441 static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) 442 { 443 u32 word; 444 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); 445 IPW_DEBUG_IO(" reg = 0x%8X :\n", reg); 446 word = _ipw_read32(priv, IPW_INDIRECT_DATA); 447 return (word >> ((reg & 0x3) * 8)) & 0xff; 448 } 449 450 /* 32-bit indirect read (above 4K) */ 451 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) 452 { 453 u32 value; 454 455 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); 456 457 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); 458 value = _ipw_read32(priv, IPW_INDIRECT_DATA); 459 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x\n", reg, value); 460 return value; 461 } 462 463 /* General purpose, no alignment requirement, iterative (multi-byte) read, */ 464 /* for area above 1st 4K of SRAM/reg space */ 465 static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, 466 int num) 467 { 468 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ 469 u32 dif_len = addr - aligned_addr; 470 u32 i; 471 472 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); 473 474 if (num <= 0) { 475 return; 476 } 477 478 /* Read the first dword (or portion) byte by byte */ 479 if (unlikely(dif_len)) { 480 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); 481 /* Start reading at aligned_addr + dif_len */ 482 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) 483 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); 484 aligned_addr += 4; 485 } 486 487 /* Read all of the middle dwords as dwords, with auto-increment */ 488 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); 489 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) 490 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); 491 492 /* Read the last dword (or portion) byte by byte */ 493 if (unlikely(num)) { 494 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); 495 for (i = 0; num > 0; i++, num--) 496 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); 497 } 498 } 499 500 /* General purpose, no alignment requirement, iterative (multi-byte) write, */ 501 /* for area above 1st 4K of SRAM/reg space */ 502 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, 503 int num) 504 { 505 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ 506 u32 dif_len = addr - aligned_addr; 507 u32 i; 508 509 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); 510 511 if (num <= 0) { 512 return; 513 } 514 515 /* Write the first dword (or portion) byte by byte */ 516 if (unlikely(dif_len)) { 517 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); 518 /* Start writing at aligned_addr + dif_len */ 519 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) 520 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); 521 aligned_addr += 4; 522 } 523 524 /* Write all of the middle dwords as dwords, with auto-increment */ 525 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); 526 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) 527 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); 528 529 /* Write the last dword (or portion) byte by byte */ 530 if (unlikely(num)) { 531 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); 532 for (i = 0; num > 0; i++, num--, buf++) 533 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); 534 } 535 } 536 537 /* General purpose, no alignment requirement, iterative (multi-byte) write, */ 538 /* for 1st 4K of SRAM/regs space */ 539 static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf, 540 int num) 541 { 542 memcpy_toio((priv->hw_base + addr), buf, num); 543 } 544 545 /* Set bit(s) in low 4K of SRAM/regs */ 546 static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) 547 { 548 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); 549 } 550 551 /* Clear bit(s) in low 4K of SRAM/regs */ 552 static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) 553 { 554 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); 555 } 556 557 static inline void __ipw_enable_interrupts(struct ipw_priv *priv) 558 { 559 if (priv->status & STATUS_INT_ENABLED) 560 return; 561 priv->status |= STATUS_INT_ENABLED; 562 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); 563 } 564 565 static inline void __ipw_disable_interrupts(struct ipw_priv *priv) 566 { 567 if (!(priv->status & STATUS_INT_ENABLED)) 568 return; 569 priv->status &= ~STATUS_INT_ENABLED; 570 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); 571 } 572 573 static inline void ipw_enable_interrupts(struct ipw_priv *priv) 574 { 575 unsigned long flags; 576 577 spin_lock_irqsave(&priv->irq_lock, flags); 578 __ipw_enable_interrupts(priv); 579 spin_unlock_irqrestore(&priv->irq_lock, flags); 580 } 581 582 static inline void ipw_disable_interrupts(struct ipw_priv *priv) 583 { 584 unsigned long flags; 585 586 spin_lock_irqsave(&priv->irq_lock, flags); 587 __ipw_disable_interrupts(priv); 588 spin_unlock_irqrestore(&priv->irq_lock, flags); 589 } 590 591 static char *ipw_error_desc(u32 val) 592 { 593 switch (val) { 594 case IPW_FW_ERROR_OK: 595 return "ERROR_OK"; 596 case IPW_FW_ERROR_FAIL: 597 return "ERROR_FAIL"; 598 case IPW_FW_ERROR_MEMORY_UNDERFLOW: 599 return "MEMORY_UNDERFLOW"; 600 case IPW_FW_ERROR_MEMORY_OVERFLOW: 601 return "MEMORY_OVERFLOW"; 602 case IPW_FW_ERROR_BAD_PARAM: 603 return "BAD_PARAM"; 604 case IPW_FW_ERROR_BAD_CHECKSUM: 605 return "BAD_CHECKSUM"; 606 case IPW_FW_ERROR_NMI_INTERRUPT: 607 return "NMI_INTERRUPT"; 608 case IPW_FW_ERROR_BAD_DATABASE: 609 return "BAD_DATABASE"; 610 case IPW_FW_ERROR_ALLOC_FAIL: 611 return "ALLOC_FAIL"; 612 case IPW_FW_ERROR_DMA_UNDERRUN: 613 return "DMA_UNDERRUN"; 614 case IPW_FW_ERROR_DMA_STATUS: 615 return "DMA_STATUS"; 616 case IPW_FW_ERROR_DINO_ERROR: 617 return "DINO_ERROR"; 618 case IPW_FW_ERROR_EEPROM_ERROR: 619 return "EEPROM_ERROR"; 620 case IPW_FW_ERROR_SYSASSERT: 621 return "SYSASSERT"; 622 case IPW_FW_ERROR_FATAL_ERROR: 623 return "FATAL_ERROR"; 624 default: 625 return "UNKNOWN_ERROR"; 626 } 627 } 628 629 static void ipw_dump_error_log(struct ipw_priv *priv, 630 struct ipw_fw_error *error) 631 { 632 u32 i; 633 634 if (!error) { 635 IPW_ERROR("Error allocating and capturing error log. " 636 "Nothing to dump.\n"); 637 return; 638 } 639 640 IPW_ERROR("Start IPW Error Log Dump:\n"); 641 IPW_ERROR("Status: 0x%08X, Config: %08X\n", 642 error->status, error->config); 643 644 for (i = 0; i < error->elem_len; i++) 645 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", 646 ipw_error_desc(error->elem[i].desc), 647 error->elem[i].time, 648 error->elem[i].blink1, 649 error->elem[i].blink2, 650 error->elem[i].link1, 651 error->elem[i].link2, error->elem[i].data); 652 for (i = 0; i < error->log_len; i++) 653 IPW_ERROR("%i\t0x%08x\t%i\n", 654 error->log[i].time, 655 error->log[i].data, error->log[i].event); 656 } 657 658 static inline int ipw_is_init(struct ipw_priv *priv) 659 { 660 return (priv->status & STATUS_INIT) ? 1 : 0; 661 } 662 663 static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len) 664 { 665 u32 addr, field_info, field_len, field_count, total_len; 666 667 IPW_DEBUG_ORD("ordinal = %i\n", ord); 668 669 if (!priv || !val || !len) { 670 IPW_DEBUG_ORD("Invalid argument\n"); 671 return -EINVAL; 672 } 673 674 /* verify device ordinal tables have been initialized */ 675 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { 676 IPW_DEBUG_ORD("Access ordinals before initialization\n"); 677 return -EINVAL; 678 } 679 680 switch (IPW_ORD_TABLE_ID_MASK & ord) { 681 case IPW_ORD_TABLE_0_MASK: 682 /* 683 * TABLE 0: Direct access to a table of 32 bit values 684 * 685 * This is a very simple table with the data directly 686 * read from the table 687 */ 688 689 /* remove the table id from the ordinal */ 690 ord &= IPW_ORD_TABLE_VALUE_MASK; 691 692 /* boundary check */ 693 if (ord > priv->table0_len) { 694 IPW_DEBUG_ORD("ordinal value (%i) longer then " 695 "max (%i)\n", ord, priv->table0_len); 696 return -EINVAL; 697 } 698 699 /* verify we have enough room to store the value */ 700 if (*len < sizeof(u32)) { 701 IPW_DEBUG_ORD("ordinal buffer length too small, " 702 "need %zd\n", sizeof(u32)); 703 return -EINVAL; 704 } 705 706 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", 707 ord, priv->table0_addr + (ord << 2)); 708 709 *len = sizeof(u32); 710 ord <<= 2; 711 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); 712 break; 713 714 case IPW_ORD_TABLE_1_MASK: 715 /* 716 * TABLE 1: Indirect access to a table of 32 bit values 717 * 718 * This is a fairly large table of u32 values each 719 * representing starting addr for the data (which is 720 * also a u32) 721 */ 722 723 /* remove the table id from the ordinal */ 724 ord &= IPW_ORD_TABLE_VALUE_MASK; 725 726 /* boundary check */ 727 if (ord > priv->table1_len) { 728 IPW_DEBUG_ORD("ordinal value too long\n"); 729 return -EINVAL; 730 } 731 732 /* verify we have enough room to store the value */ 733 if (*len < sizeof(u32)) { 734 IPW_DEBUG_ORD("ordinal buffer length too small, " 735 "need %zd\n", sizeof(u32)); 736 return -EINVAL; 737 } 738 739 *((u32 *) val) = 740 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); 741 *len = sizeof(u32); 742 break; 743 744 case IPW_ORD_TABLE_2_MASK: 745 /* 746 * TABLE 2: Indirect access to a table of variable sized values 747 * 748 * This table consist of six values, each containing 749 * - dword containing the starting offset of the data 750 * - dword containing the lengh in the first 16bits 751 * and the count in the second 16bits 752 */ 753 754 /* remove the table id from the ordinal */ 755 ord &= IPW_ORD_TABLE_VALUE_MASK; 756 757 /* boundary check */ 758 if (ord > priv->table2_len) { 759 IPW_DEBUG_ORD("ordinal value too long\n"); 760 return -EINVAL; 761 } 762 763 /* get the address of statistic */ 764 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); 765 766 /* get the second DW of statistics ; 767 * two 16-bit words - first is length, second is count */ 768 field_info = 769 ipw_read_reg32(priv, 770 priv->table2_addr + (ord << 3) + 771 sizeof(u32)); 772 773 /* get each entry length */ 774 field_len = *((u16 *) & field_info); 775 776 /* get number of entries */ 777 field_count = *(((u16 *) & field_info) + 1); 778 779 /* abort if not enough memory */ 780 total_len = field_len * field_count; 781 if (total_len > *len) { 782 *len = total_len; 783 return -EINVAL; 784 } 785 786 *len = total_len; 787 if (!total_len) 788 return 0; 789 790 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " 791 "field_info = 0x%08x\n", 792 addr, total_len, field_info); 793 ipw_read_indirect(priv, addr, val, total_len); 794 break; 795 796 default: 797 IPW_DEBUG_ORD("Invalid ordinal!\n"); 798 return -EINVAL; 799 800 } 801 802 return 0; 803 } 804 805 static void ipw_init_ordinals(struct ipw_priv *priv) 806 { 807 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; 808 priv->table0_len = ipw_read32(priv, priv->table0_addr); 809 810 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", 811 priv->table0_addr, priv->table0_len); 812 813 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); 814 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); 815 816 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", 817 priv->table1_addr, priv->table1_len); 818 819 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); 820 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); 821 priv->table2_len &= 0x0000ffff; /* use first two bytes */ 822 823 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", 824 priv->table2_addr, priv->table2_len); 825 826 } 827 828 static u32 ipw_register_toggle(u32 reg) 829 { 830 reg &= ~IPW_START_STANDBY; 831 if (reg & IPW_GATE_ODMA) 832 reg &= ~IPW_GATE_ODMA; 833 if (reg & IPW_GATE_IDMA) 834 reg &= ~IPW_GATE_IDMA; 835 if (reg & IPW_GATE_ADMA) 836 reg &= ~IPW_GATE_ADMA; 837 return reg; 838 } 839 840 /* 841 * LED behavior: 842 * - On radio ON, turn on any LEDs that require to be on during start 843 * - On initialization, start unassociated blink 844 * - On association, disable unassociated blink 845 * - On disassociation, start unassociated blink 846 * - On radio OFF, turn off any LEDs started during radio on 847 * 848 */ 849 #define LD_TIME_LINK_ON msecs_to_jiffies(300) 850 #define LD_TIME_LINK_OFF msecs_to_jiffies(2700) 851 #define LD_TIME_ACT_ON msecs_to_jiffies(250) 852 853 static void ipw_led_link_on(struct ipw_priv *priv) 854 { 855 unsigned long flags; 856 u32 led; 857 858 /* If configured to not use LEDs, or nic_type is 1, 859 * then we don't toggle a LINK led */ 860 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) 861 return; 862 863 spin_lock_irqsave(&priv->lock, flags); 864 865 if (!(priv->status & STATUS_RF_KILL_MASK) && 866 !(priv->status & STATUS_LED_LINK_ON)) { 867 IPW_DEBUG_LED("Link LED On\n"); 868 led = ipw_read_reg32(priv, IPW_EVENT_REG); 869 led |= priv->led_association_on; 870 871 led = ipw_register_toggle(led); 872 873 IPW_DEBUG_LED("Reg: 0x%08X\n", led); 874 ipw_write_reg32(priv, IPW_EVENT_REG, led); 875 876 priv->status |= STATUS_LED_LINK_ON; 877 878 /* If we aren't associated, schedule turning the LED off */ 879 if (!(priv->status & STATUS_ASSOCIATED)) 880 schedule_delayed_work(&priv->led_link_off, 881 LD_TIME_LINK_ON); 882 } 883 884 spin_unlock_irqrestore(&priv->lock, flags); 885 } 886 887 static void ipw_bg_led_link_on(struct work_struct *work) 888 { 889 struct ipw_priv *priv = 890 container_of(work, struct ipw_priv, led_link_on.work); 891 mutex_lock(&priv->mutex); 892 ipw_led_link_on(priv); 893 mutex_unlock(&priv->mutex); 894 } 895 896 static void ipw_led_link_off(struct ipw_priv *priv) 897 { 898 unsigned long flags; 899 u32 led; 900 901 /* If configured not to use LEDs, or nic type is 1, 902 * then we don't goggle the LINK led. */ 903 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) 904 return; 905 906 spin_lock_irqsave(&priv->lock, flags); 907 908 if (priv->status & STATUS_LED_LINK_ON) { 909 led = ipw_read_reg32(priv, IPW_EVENT_REG); 910 led &= priv->led_association_off; 911 led = ipw_register_toggle(led); 912 913 IPW_DEBUG_LED("Reg: 0x%08X\n", led); 914 ipw_write_reg32(priv, IPW_EVENT_REG, led); 915 916 IPW_DEBUG_LED("Link LED Off\n"); 917 918 priv->status &= ~STATUS_LED_LINK_ON; 919 920 /* If we aren't associated and the radio is on, schedule 921 * turning the LED on (blink while unassociated) */ 922 if (!(priv->status & STATUS_RF_KILL_MASK) && 923 !(priv->status & STATUS_ASSOCIATED)) 924 schedule_delayed_work(&priv->led_link_on, 925 LD_TIME_LINK_OFF); 926 927 } 928 929 spin_unlock_irqrestore(&priv->lock, flags); 930 } 931 932 static void ipw_bg_led_link_off(struct work_struct *work) 933 { 934 struct ipw_priv *priv = 935 container_of(work, struct ipw_priv, led_link_off.work); 936 mutex_lock(&priv->mutex); 937 ipw_led_link_off(priv); 938 mutex_unlock(&priv->mutex); 939 } 940 941 static void __ipw_led_activity_on(struct ipw_priv *priv) 942 { 943 u32 led; 944 945 if (priv->config & CFG_NO_LED) 946 return; 947 948 if (priv->status & STATUS_RF_KILL_MASK) 949 return; 950 951 if (!(priv->status & STATUS_LED_ACT_ON)) { 952 led = ipw_read_reg32(priv, IPW_EVENT_REG); 953 led |= priv->led_activity_on; 954 955 led = ipw_register_toggle(led); 956 957 IPW_DEBUG_LED("Reg: 0x%08X\n", led); 958 ipw_write_reg32(priv, IPW_EVENT_REG, led); 959 960 IPW_DEBUG_LED("Activity LED On\n"); 961 962 priv->status |= STATUS_LED_ACT_ON; 963 964 cancel_delayed_work(&priv->led_act_off); 965 schedule_delayed_work(&priv->led_act_off, LD_TIME_ACT_ON); 966 } else { 967 /* Reschedule LED off for full time period */ 968 cancel_delayed_work(&priv->led_act_off); 969 schedule_delayed_work(&priv->led_act_off, LD_TIME_ACT_ON); 970 } 971 } 972 973 #if 0 974 void ipw_led_activity_on(struct ipw_priv *priv) 975 { 976 unsigned long flags; 977 spin_lock_irqsave(&priv->lock, flags); 978 __ipw_led_activity_on(priv); 979 spin_unlock_irqrestore(&priv->lock, flags); 980 } 981 #endif /* 0 */ 982 983 static void ipw_led_activity_off(struct ipw_priv *priv) 984 { 985 unsigned long flags; 986 u32 led; 987 988 if (priv->config & CFG_NO_LED) 989 return; 990 991 spin_lock_irqsave(&priv->lock, flags); 992 993 if (priv->status & STATUS_LED_ACT_ON) { 994 led = ipw_read_reg32(priv, IPW_EVENT_REG); 995 led &= priv->led_activity_off; 996 997 led = ipw_register_toggle(led); 998 999 IPW_DEBUG_LED("Reg: 0x%08X\n", led); 1000 ipw_write_reg32(priv, IPW_EVENT_REG, led); 1001 1002 IPW_DEBUG_LED("Activity LED Off\n"); 1003 1004 priv->status &= ~STATUS_LED_ACT_ON; 1005 } 1006 1007 spin_unlock_irqrestore(&priv->lock, flags); 1008 } 1009 1010 static void ipw_bg_led_activity_off(struct work_struct *work) 1011 { 1012 struct ipw_priv *priv = 1013 container_of(work, struct ipw_priv, led_act_off.work); 1014 mutex_lock(&priv->mutex); 1015 ipw_led_activity_off(priv); 1016 mutex_unlock(&priv->mutex); 1017 } 1018 1019 static void ipw_led_band_on(struct ipw_priv *priv) 1020 { 1021 unsigned long flags; 1022 u32 led; 1023 1024 /* Only nic type 1 supports mode LEDs */ 1025 if (priv->config & CFG_NO_LED || 1026 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) 1027 return; 1028 1029 spin_lock_irqsave(&priv->lock, flags); 1030 1031 led = ipw_read_reg32(priv, IPW_EVENT_REG); 1032 if (priv->assoc_network->mode == IEEE_A) { 1033 led |= priv->led_ofdm_on; 1034 led &= priv->led_association_off; 1035 IPW_DEBUG_LED("Mode LED On: 802.11a\n"); 1036 } else if (priv->assoc_network->mode == IEEE_G) { 1037 led |= priv->led_ofdm_on; 1038 led |= priv->led_association_on; 1039 IPW_DEBUG_LED("Mode LED On: 802.11g\n"); 1040 } else { 1041 led &= priv->led_ofdm_off; 1042 led |= priv->led_association_on; 1043 IPW_DEBUG_LED("Mode LED On: 802.11b\n"); 1044 } 1045 1046 led = ipw_register_toggle(led); 1047 1048 IPW_DEBUG_LED("Reg: 0x%08X\n", led); 1049 ipw_write_reg32(priv, IPW_EVENT_REG, led); 1050 1051 spin_unlock_irqrestore(&priv->lock, flags); 1052 } 1053 1054 static void ipw_led_band_off(struct ipw_priv *priv) 1055 { 1056 unsigned long flags; 1057 u32 led; 1058 1059 /* Only nic type 1 supports mode LEDs */ 1060 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) 1061 return; 1062 1063 spin_lock_irqsave(&priv->lock, flags); 1064 1065 led = ipw_read_reg32(priv, IPW_EVENT_REG); 1066 led &= priv->led_ofdm_off; 1067 led &= priv->led_association_off; 1068 1069 led = ipw_register_toggle(led); 1070 1071 IPW_DEBUG_LED("Reg: 0x%08X\n", led); 1072 ipw_write_reg32(priv, IPW_EVENT_REG, led); 1073 1074 spin_unlock_irqrestore(&priv->lock, flags); 1075 } 1076 1077 static void ipw_led_radio_on(struct ipw_priv *priv) 1078 { 1079 ipw_led_link_on(priv); 1080 } 1081 1082 static void ipw_led_radio_off(struct ipw_priv *priv) 1083 { 1084 ipw_led_activity_off(priv); 1085 ipw_led_link_off(priv); 1086 } 1087 1088 static void ipw_led_link_up(struct ipw_priv *priv) 1089 { 1090 /* Set the Link Led on for all nic types */ 1091 ipw_led_link_on(priv); 1092 } 1093 1094 static void ipw_led_link_down(struct ipw_priv *priv) 1095 { 1096 ipw_led_activity_off(priv); 1097 ipw_led_link_off(priv); 1098 1099 if (priv->status & STATUS_RF_KILL_MASK) 1100 ipw_led_radio_off(priv); 1101 } 1102 1103 static void ipw_led_init(struct ipw_priv *priv) 1104 { 1105 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; 1106 1107 /* Set the default PINs for the link and activity leds */ 1108 priv->led_activity_on = IPW_ACTIVITY_LED; 1109 priv->led_activity_off = ~(IPW_ACTIVITY_LED); 1110 1111 priv->led_association_on = IPW_ASSOCIATED_LED; 1112 priv->led_association_off = ~(IPW_ASSOCIATED_LED); 1113 1114 /* Set the default PINs for the OFDM leds */ 1115 priv->led_ofdm_on = IPW_OFDM_LED; 1116 priv->led_ofdm_off = ~(IPW_OFDM_LED); 1117 1118 switch (priv->nic_type) { 1119 case EEPROM_NIC_TYPE_1: 1120 /* In this NIC type, the LEDs are reversed.... */ 1121 priv->led_activity_on = IPW_ASSOCIATED_LED; 1122 priv->led_activity_off = ~(IPW_ASSOCIATED_LED); 1123 priv->led_association_on = IPW_ACTIVITY_LED; 1124 priv->led_association_off = ~(IPW_ACTIVITY_LED); 1125 1126 if (!(priv->config & CFG_NO_LED)) 1127 ipw_led_band_on(priv); 1128 1129 /* And we don't blink link LEDs for this nic, so 1130 * just return here */ 1131 return; 1132 1133 case EEPROM_NIC_TYPE_3: 1134 case EEPROM_NIC_TYPE_2: 1135 case EEPROM_NIC_TYPE_4: 1136 case EEPROM_NIC_TYPE_0: 1137 break; 1138 1139 default: 1140 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", 1141 priv->nic_type); 1142 priv->nic_type = EEPROM_NIC_TYPE_0; 1143 break; 1144 } 1145 1146 if (!(priv->config & CFG_NO_LED)) { 1147 if (priv->status & STATUS_ASSOCIATED) 1148 ipw_led_link_on(priv); 1149 else 1150 ipw_led_link_off(priv); 1151 } 1152 } 1153 1154 static void ipw_led_shutdown(struct ipw_priv *priv) 1155 { 1156 ipw_led_activity_off(priv); 1157 ipw_led_link_off(priv); 1158 ipw_led_band_off(priv); 1159 cancel_delayed_work(&priv->led_link_on); 1160 cancel_delayed_work(&priv->led_link_off); 1161 cancel_delayed_work(&priv->led_act_off); 1162 } 1163 1164 /* 1165 * The following adds a new attribute to the sysfs representation 1166 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) 1167 * used for controlling the debug level. 1168 * 1169 * See the level definitions in ipw for details. 1170 */ 1171 static ssize_t debug_level_show(struct device_driver *d, char *buf) 1172 { 1173 return sprintf(buf, "0x%08X\n", ipw_debug_level); 1174 } 1175 1176 static ssize_t debug_level_store(struct device_driver *d, const char *buf, 1177 size_t count) 1178 { 1179 unsigned long val; 1180 1181 int result = kstrtoul(buf, 0, &val); 1182 1183 if (result == -EINVAL) 1184 printk(KERN_INFO DRV_NAME 1185 ": %s is not in hex or decimal form.\n", buf); 1186 else if (result == -ERANGE) 1187 printk(KERN_INFO DRV_NAME 1188 ": %s has overflowed.\n", buf); 1189 else 1190 ipw_debug_level = val; 1191 1192 return count; 1193 } 1194 static DRIVER_ATTR_RW(debug_level); 1195 1196 static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) 1197 { 1198 /* length = 1st dword in log */ 1199 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); 1200 } 1201 1202 static void ipw_capture_event_log(struct ipw_priv *priv, 1203 u32 log_len, struct ipw_event *log) 1204 { 1205 u32 base; 1206 1207 if (log_len) { 1208 base = ipw_read32(priv, IPW_EVENT_LOG); 1209 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), 1210 (u8 *) log, sizeof(*log) * log_len); 1211 } 1212 } 1213 1214 static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) 1215 { 1216 struct ipw_fw_error *error; 1217 u32 log_len = ipw_get_event_log_len(priv); 1218 u32 base = ipw_read32(priv, IPW_ERROR_LOG); 1219 u32 elem_len = ipw_read_reg32(priv, base); 1220 1221 error = kmalloc(size_add(struct_size(error, elem, elem_len), 1222 array_size(sizeof(*error->log), log_len)), 1223 GFP_ATOMIC); 1224 if (!error) { 1225 IPW_ERROR("Memory allocation for firmware error log " 1226 "failed.\n"); 1227 return NULL; 1228 } 1229 error->jiffies = jiffies; 1230 error->status = priv->status; 1231 error->config = priv->config; 1232 error->elem_len = elem_len; 1233 error->log_len = log_len; 1234 error->log = (struct ipw_event *)(error->elem + elem_len); 1235 1236 ipw_capture_event_log(priv, log_len, error->log); 1237 1238 if (elem_len) 1239 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, 1240 sizeof(*error->elem) * elem_len); 1241 1242 return error; 1243 } 1244 1245 static ssize_t event_log_show(struct device *d, 1246 struct device_attribute *attr, char *buf) 1247 { 1248 struct ipw_priv *priv = dev_get_drvdata(d); 1249 u32 log_len = ipw_get_event_log_len(priv); 1250 u32 log_size; 1251 struct ipw_event *log; 1252 u32 len = 0, i; 1253 1254 /* not using min() because of its strict type checking */ 1255 log_size = PAGE_SIZE / sizeof(*log) > log_len ? 1256 sizeof(*log) * log_len : PAGE_SIZE; 1257 log = kzalloc(log_size, GFP_KERNEL); 1258 if (!log) { 1259 IPW_ERROR("Unable to allocate memory for log\n"); 1260 return 0; 1261 } 1262 log_len = log_size / sizeof(*log); 1263 ipw_capture_event_log(priv, log_len, log); 1264 1265 len += scnprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); 1266 for (i = 0; i < log_len; i++) 1267 len += scnprintf(buf + len, PAGE_SIZE - len, 1268 "\n%08X%08X%08X", 1269 log[i].time, log[i].event, log[i].data); 1270 len += scnprintf(buf + len, PAGE_SIZE - len, "\n"); 1271 kfree(log); 1272 return len; 1273 } 1274 1275 static DEVICE_ATTR_RO(event_log); 1276 1277 static ssize_t error_show(struct device *d, 1278 struct device_attribute *attr, char *buf) 1279 { 1280 struct ipw_priv *priv = dev_get_drvdata(d); 1281 u32 len = 0, i; 1282 if (!priv->error) 1283 return 0; 1284 len += scnprintf(buf + len, PAGE_SIZE - len, 1285 "%08lX%08X%08X%08X", 1286 priv->error->jiffies, 1287 priv->error->status, 1288 priv->error->config, priv->error->elem_len); 1289 for (i = 0; i < priv->error->elem_len; i++) 1290 len += scnprintf(buf + len, PAGE_SIZE - len, 1291 "\n%08X%08X%08X%08X%08X%08X%08X", 1292 priv->error->elem[i].time, 1293 priv->error->elem[i].desc, 1294 priv->error->elem[i].blink1, 1295 priv->error->elem[i].blink2, 1296 priv->error->elem[i].link1, 1297 priv->error->elem[i].link2, 1298 priv->error->elem[i].data); 1299 1300 len += scnprintf(buf + len, PAGE_SIZE - len, 1301 "\n%08X", priv->error->log_len); 1302 for (i = 0; i < priv->error->log_len; i++) 1303 len += scnprintf(buf + len, PAGE_SIZE - len, 1304 "\n%08X%08X%08X", 1305 priv->error->log[i].time, 1306 priv->error->log[i].event, 1307 priv->error->log[i].data); 1308 len += scnprintf(buf + len, PAGE_SIZE - len, "\n"); 1309 return len; 1310 } 1311 1312 static ssize_t error_store(struct device *d, 1313 struct device_attribute *attr, 1314 const char *buf, size_t count) 1315 { 1316 struct ipw_priv *priv = dev_get_drvdata(d); 1317 1318 kfree(priv->error); 1319 priv->error = NULL; 1320 return count; 1321 } 1322 1323 static DEVICE_ATTR_RW(error); 1324 1325 static ssize_t cmd_log_show(struct device *d, 1326 struct device_attribute *attr, char *buf) 1327 { 1328 struct ipw_priv *priv = dev_get_drvdata(d); 1329 u32 len = 0, i; 1330 if (!priv->cmdlog) 1331 return 0; 1332 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; 1333 (i != priv->cmdlog_pos) && (len < PAGE_SIZE); 1334 i = (i + 1) % priv->cmdlog_len) { 1335 len += 1336 scnprintf(buf + len, PAGE_SIZE - len, 1337 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, 1338 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, 1339 priv->cmdlog[i].cmd.len); 1340 len += 1341 snprintk_buf(buf + len, PAGE_SIZE - len, 1342 (u8 *) priv->cmdlog[i].cmd.param, 1343 priv->cmdlog[i].cmd.len); 1344 len += scnprintf(buf + len, PAGE_SIZE - len, "\n"); 1345 } 1346 len += scnprintf(buf + len, PAGE_SIZE - len, "\n"); 1347 return len; 1348 } 1349 1350 static DEVICE_ATTR_RO(cmd_log); 1351 1352 #ifdef CONFIG_IPW2200_PROMISCUOUS 1353 static void ipw_prom_free(struct ipw_priv *priv); 1354 static int ipw_prom_alloc(struct ipw_priv *priv); 1355 static ssize_t rtap_iface_store(struct device *d, 1356 struct device_attribute *attr, 1357 const char *buf, size_t count) 1358 { 1359 struct ipw_priv *priv = dev_get_drvdata(d); 1360 int rc = 0; 1361 1362 if (count < 1) 1363 return -EINVAL; 1364 1365 switch (buf[0]) { 1366 case '0': 1367 if (!rtap_iface) 1368 return count; 1369 1370 if (netif_running(priv->prom_net_dev)) { 1371 IPW_WARNING("Interface is up. Cannot unregister.\n"); 1372 return count; 1373 } 1374 1375 ipw_prom_free(priv); 1376 rtap_iface = 0; 1377 break; 1378 1379 case '1': 1380 if (rtap_iface) 1381 return count; 1382 1383 rc = ipw_prom_alloc(priv); 1384 if (!rc) 1385 rtap_iface = 1; 1386 break; 1387 1388 default: 1389 return -EINVAL; 1390 } 1391 1392 if (rc) { 1393 IPW_ERROR("Failed to register promiscuous network " 1394 "device (error %d).\n", rc); 1395 } 1396 1397 return count; 1398 } 1399 1400 static ssize_t rtap_iface_show(struct device *d, 1401 struct device_attribute *attr, 1402 char *buf) 1403 { 1404 struct ipw_priv *priv = dev_get_drvdata(d); 1405 if (rtap_iface) 1406 return sprintf(buf, "%s", priv->prom_net_dev->name); 1407 else { 1408 buf[0] = '-'; 1409 buf[1] = '1'; 1410 buf[2] = '\0'; 1411 return 3; 1412 } 1413 } 1414 1415 static DEVICE_ATTR_ADMIN_RW(rtap_iface); 1416 1417 static ssize_t rtap_filter_store(struct device *d, 1418 struct device_attribute *attr, 1419 const char *buf, size_t count) 1420 { 1421 struct ipw_priv *priv = dev_get_drvdata(d); 1422 1423 if (!priv->prom_priv) { 1424 IPW_ERROR("Attempting to set filter without " 1425 "rtap_iface enabled.\n"); 1426 return -EPERM; 1427 } 1428 1429 priv->prom_priv->filter = simple_strtol(buf, NULL, 0); 1430 1431 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n", 1432 BIT_ARG16(priv->prom_priv->filter)); 1433 1434 return count; 1435 } 1436 1437 static ssize_t rtap_filter_show(struct device *d, 1438 struct device_attribute *attr, 1439 char *buf) 1440 { 1441 struct ipw_priv *priv = dev_get_drvdata(d); 1442 return sprintf(buf, "0x%04X", 1443 priv->prom_priv ? priv->prom_priv->filter : 0); 1444 } 1445 1446 static DEVICE_ATTR_ADMIN_RW(rtap_filter); 1447 #endif 1448 1449 static ssize_t scan_age_show(struct device *d, struct device_attribute *attr, 1450 char *buf) 1451 { 1452 struct ipw_priv *priv = dev_get_drvdata(d); 1453 return sprintf(buf, "%d\n", priv->ieee->scan_age); 1454 } 1455 1456 static ssize_t scan_age_store(struct device *d, struct device_attribute *attr, 1457 const char *buf, size_t count) 1458 { 1459 struct ipw_priv *priv = dev_get_drvdata(d); 1460 struct net_device *dev = priv->net_dev; 1461 1462 IPW_DEBUG_INFO("enter\n"); 1463 1464 unsigned long val; 1465 int result = kstrtoul(buf, 0, &val); 1466 1467 if (result == -EINVAL || result == -ERANGE) { 1468 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); 1469 } else { 1470 priv->ieee->scan_age = val; 1471 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); 1472 } 1473 1474 IPW_DEBUG_INFO("exit\n"); 1475 return count; 1476 } 1477 1478 static DEVICE_ATTR_RW(scan_age); 1479 1480 static ssize_t led_show(struct device *d, struct device_attribute *attr, 1481 char *buf) 1482 { 1483 struct ipw_priv *priv = dev_get_drvdata(d); 1484 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); 1485 } 1486 1487 static ssize_t led_store(struct device *d, struct device_attribute *attr, 1488 const char *buf, size_t count) 1489 { 1490 struct ipw_priv *priv = dev_get_drvdata(d); 1491 1492 IPW_DEBUG_INFO("enter\n"); 1493 1494 if (count == 0) 1495 return 0; 1496 1497 if (*buf == 0) { 1498 IPW_DEBUG_LED("Disabling LED control.\n"); 1499 priv->config |= CFG_NO_LED; 1500 ipw_led_shutdown(priv); 1501 } else { 1502 IPW_DEBUG_LED("Enabling LED control.\n"); 1503 priv->config &= ~CFG_NO_LED; 1504 ipw_led_init(priv); 1505 } 1506 1507 IPW_DEBUG_INFO("exit\n"); 1508 return count; 1509 } 1510 1511 static DEVICE_ATTR_RW(led); 1512 1513 static ssize_t status_show(struct device *d, 1514 struct device_attribute *attr, char *buf) 1515 { 1516 struct ipw_priv *p = dev_get_drvdata(d); 1517 return sprintf(buf, "0x%08x\n", (int)p->status); 1518 } 1519 1520 static DEVICE_ATTR_RO(status); 1521 1522 static ssize_t cfg_show(struct device *d, struct device_attribute *attr, 1523 char *buf) 1524 { 1525 struct ipw_priv *p = dev_get_drvdata(d); 1526 return sprintf(buf, "0x%08x\n", (int)p->config); 1527 } 1528 1529 static DEVICE_ATTR_RO(cfg); 1530 1531 static ssize_t nic_type_show(struct device *d, 1532 struct device_attribute *attr, char *buf) 1533 { 1534 struct ipw_priv *priv = dev_get_drvdata(d); 1535 return sprintf(buf, "TYPE: %d\n", priv->nic_type); 1536 } 1537 1538 static DEVICE_ATTR_RO(nic_type); 1539 1540 static ssize_t ucode_version_show(struct device *d, 1541 struct device_attribute *attr, char *buf) 1542 { 1543 u32 len = sizeof(u32), tmp = 0; 1544 struct ipw_priv *p = dev_get_drvdata(d); 1545 1546 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) 1547 return 0; 1548 1549 return sprintf(buf, "0x%08x\n", tmp); 1550 } 1551 1552 static DEVICE_ATTR_RO(ucode_version); 1553 1554 static ssize_t rtc_show(struct device *d, struct device_attribute *attr, 1555 char *buf) 1556 { 1557 u32 len = sizeof(u32), tmp = 0; 1558 struct ipw_priv *p = dev_get_drvdata(d); 1559 1560 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) 1561 return 0; 1562 1563 return sprintf(buf, "0x%08x\n", tmp); 1564 } 1565 1566 static DEVICE_ATTR_RO(rtc); 1567 1568 /* 1569 * Add a device attribute to view/control the delay between eeprom 1570 * operations. 1571 */ 1572 static ssize_t eeprom_delay_show(struct device *d, 1573 struct device_attribute *attr, char *buf) 1574 { 1575 struct ipw_priv *p = dev_get_drvdata(d); 1576 int n = p->eeprom_delay; 1577 return sprintf(buf, "%i\n", n); 1578 } 1579 static ssize_t eeprom_delay_store(struct device *d, 1580 struct device_attribute *attr, 1581 const char *buf, size_t count) 1582 { 1583 struct ipw_priv *p = dev_get_drvdata(d); 1584 sscanf(buf, "%i", &p->eeprom_delay); 1585 return strnlen(buf, count); 1586 } 1587 1588 static DEVICE_ATTR_RW(eeprom_delay); 1589 1590 static ssize_t command_event_reg_show(struct device *d, 1591 struct device_attribute *attr, char *buf) 1592 { 1593 u32 reg = 0; 1594 struct ipw_priv *p = dev_get_drvdata(d); 1595 1596 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); 1597 return sprintf(buf, "0x%08x\n", reg); 1598 } 1599 static ssize_t command_event_reg_store(struct device *d, 1600 struct device_attribute *attr, 1601 const char *buf, size_t count) 1602 { 1603 u32 reg; 1604 struct ipw_priv *p = dev_get_drvdata(d); 1605 1606 sscanf(buf, "%x", ®); 1607 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); 1608 return strnlen(buf, count); 1609 } 1610 1611 static DEVICE_ATTR_RW(command_event_reg); 1612 1613 static ssize_t mem_gpio_reg_show(struct device *d, 1614 struct device_attribute *attr, char *buf) 1615 { 1616 u32 reg = 0; 1617 struct ipw_priv *p = dev_get_drvdata(d); 1618 1619 reg = ipw_read_reg32(p, 0x301100); 1620 return sprintf(buf, "0x%08x\n", reg); 1621 } 1622 static ssize_t mem_gpio_reg_store(struct device *d, 1623 struct device_attribute *attr, 1624 const char *buf, size_t count) 1625 { 1626 u32 reg; 1627 struct ipw_priv *p = dev_get_drvdata(d); 1628 1629 sscanf(buf, "%x", ®); 1630 ipw_write_reg32(p, 0x301100, reg); 1631 return strnlen(buf, count); 1632 } 1633 1634 static DEVICE_ATTR_RW(mem_gpio_reg); 1635 1636 static ssize_t indirect_dword_show(struct device *d, 1637 struct device_attribute *attr, char *buf) 1638 { 1639 u32 reg = 0; 1640 struct ipw_priv *priv = dev_get_drvdata(d); 1641 1642 if (priv->status & STATUS_INDIRECT_DWORD) 1643 reg = ipw_read_reg32(priv, priv->indirect_dword); 1644 else 1645 reg = 0; 1646 1647 return sprintf(buf, "0x%08x\n", reg); 1648 } 1649 static ssize_t indirect_dword_store(struct device *d, 1650 struct device_attribute *attr, 1651 const char *buf, size_t count) 1652 { 1653 struct ipw_priv *priv = dev_get_drvdata(d); 1654 1655 sscanf(buf, "%x", &priv->indirect_dword); 1656 priv->status |= STATUS_INDIRECT_DWORD; 1657 return strnlen(buf, count); 1658 } 1659 1660 static DEVICE_ATTR_RW(indirect_dword); 1661 1662 static ssize_t indirect_byte_show(struct device *d, 1663 struct device_attribute *attr, char *buf) 1664 { 1665 u8 reg = 0; 1666 struct ipw_priv *priv = dev_get_drvdata(d); 1667 1668 if (priv->status & STATUS_INDIRECT_BYTE) 1669 reg = ipw_read_reg8(priv, priv->indirect_byte); 1670 else 1671 reg = 0; 1672 1673 return sprintf(buf, "0x%02x\n", reg); 1674 } 1675 static ssize_t indirect_byte_store(struct device *d, 1676 struct device_attribute *attr, 1677 const char *buf, size_t count) 1678 { 1679 struct ipw_priv *priv = dev_get_drvdata(d); 1680 1681 sscanf(buf, "%x", &priv->indirect_byte); 1682 priv->status |= STATUS_INDIRECT_BYTE; 1683 return strnlen(buf, count); 1684 } 1685 1686 static DEVICE_ATTR_RW(indirect_byte); 1687 1688 static ssize_t direct_dword_show(struct device *d, 1689 struct device_attribute *attr, char *buf) 1690 { 1691 u32 reg = 0; 1692 struct ipw_priv *priv = dev_get_drvdata(d); 1693 1694 if (priv->status & STATUS_DIRECT_DWORD) 1695 reg = ipw_read32(priv, priv->direct_dword); 1696 else 1697 reg = 0; 1698 1699 return sprintf(buf, "0x%08x\n", reg); 1700 } 1701 static ssize_t direct_dword_store(struct device *d, 1702 struct device_attribute *attr, 1703 const char *buf, size_t count) 1704 { 1705 struct ipw_priv *priv = dev_get_drvdata(d); 1706 1707 sscanf(buf, "%x", &priv->direct_dword); 1708 priv->status |= STATUS_DIRECT_DWORD; 1709 return strnlen(buf, count); 1710 } 1711 1712 static DEVICE_ATTR_RW(direct_dword); 1713 1714 static int rf_kill_active(struct ipw_priv *priv) 1715 { 1716 if (0 == (ipw_read32(priv, 0x30) & 0x10000)) { 1717 priv->status |= STATUS_RF_KILL_HW; 1718 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true); 1719 } else { 1720 priv->status &= ~STATUS_RF_KILL_HW; 1721 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false); 1722 } 1723 1724 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; 1725 } 1726 1727 static ssize_t rf_kill_show(struct device *d, struct device_attribute *attr, 1728 char *buf) 1729 { 1730 /* 0 - RF kill not enabled 1731 1 - SW based RF kill active (sysfs) 1732 2 - HW based RF kill active 1733 3 - Both HW and SW baed RF kill active */ 1734 struct ipw_priv *priv = dev_get_drvdata(d); 1735 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | 1736 (rf_kill_active(priv) ? 0x2 : 0x0); 1737 return sprintf(buf, "%i\n", val); 1738 } 1739 1740 static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) 1741 { 1742 if ((disable_radio ? 1 : 0) == 1743 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) 1744 return 0; 1745 1746 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", 1747 disable_radio ? "OFF" : "ON"); 1748 1749 if (disable_radio) { 1750 priv->status |= STATUS_RF_KILL_SW; 1751 1752 cancel_delayed_work(&priv->request_scan); 1753 cancel_delayed_work(&priv->request_direct_scan); 1754 cancel_delayed_work(&priv->request_passive_scan); 1755 cancel_delayed_work(&priv->scan_event); 1756 schedule_work(&priv->down); 1757 } else { 1758 priv->status &= ~STATUS_RF_KILL_SW; 1759 if (rf_kill_active(priv)) { 1760 IPW_DEBUG_RF_KILL("Can not turn radio back on - " 1761 "disabled by HW switch\n"); 1762 /* Make sure the RF_KILL check timer is running */ 1763 cancel_delayed_work(&priv->rf_kill); 1764 schedule_delayed_work(&priv->rf_kill, 1765 round_jiffies_relative(2 * HZ)); 1766 } else 1767 schedule_work(&priv->up); 1768 } 1769 1770 return 1; 1771 } 1772 1773 static ssize_t rf_kill_store(struct device *d, struct device_attribute *attr, 1774 const char *buf, size_t count) 1775 { 1776 struct ipw_priv *priv = dev_get_drvdata(d); 1777 1778 ipw_radio_kill_sw(priv, buf[0] == '1'); 1779 1780 return count; 1781 } 1782 1783 static DEVICE_ATTR_RW(rf_kill); 1784 1785 static ssize_t speed_scan_show(struct device *d, struct device_attribute *attr, 1786 char *buf) 1787 { 1788 struct ipw_priv *priv = dev_get_drvdata(d); 1789 int pos = 0, len = 0; 1790 if (priv->config & CFG_SPEED_SCAN) { 1791 while (priv->speed_scan[pos] != 0) 1792 len += sprintf(&buf[len], "%d ", 1793 priv->speed_scan[pos++]); 1794 return len + sprintf(&buf[len], "\n"); 1795 } 1796 1797 return sprintf(buf, "0\n"); 1798 } 1799 1800 static ssize_t speed_scan_store(struct device *d, struct device_attribute *attr, 1801 const char *buf, size_t count) 1802 { 1803 struct ipw_priv *priv = dev_get_drvdata(d); 1804 int channel, pos = 0; 1805 const char *p = buf; 1806 1807 /* list of space separated channels to scan, optionally ending with 0 */ 1808 while ((channel = simple_strtol(p, NULL, 0))) { 1809 if (pos == MAX_SPEED_SCAN - 1) { 1810 priv->speed_scan[pos] = 0; 1811 break; 1812 } 1813 1814 if (libipw_is_valid_channel(priv->ieee, channel)) 1815 priv->speed_scan[pos++] = channel; 1816 else 1817 IPW_WARNING("Skipping invalid channel request: %d\n", 1818 channel); 1819 p = strchr(p, ' '); 1820 if (!p) 1821 break; 1822 while (*p == ' ' || *p == '\t') 1823 p++; 1824 } 1825 1826 if (pos == 0) 1827 priv->config &= ~CFG_SPEED_SCAN; 1828 else { 1829 priv->speed_scan_pos = 0; 1830 priv->config |= CFG_SPEED_SCAN; 1831 } 1832 1833 return count; 1834 } 1835 1836 static DEVICE_ATTR_RW(speed_scan); 1837 1838 static ssize_t net_stats_show(struct device *d, struct device_attribute *attr, 1839 char *buf) 1840 { 1841 struct ipw_priv *priv = dev_get_drvdata(d); 1842 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); 1843 } 1844 1845 static ssize_t net_stats_store(struct device *d, struct device_attribute *attr, 1846 const char *buf, size_t count) 1847 { 1848 struct ipw_priv *priv = dev_get_drvdata(d); 1849 if (buf[0] == '1') 1850 priv->config |= CFG_NET_STATS; 1851 else 1852 priv->config &= ~CFG_NET_STATS; 1853 1854 return count; 1855 } 1856 1857 static DEVICE_ATTR_RW(net_stats); 1858 1859 static ssize_t channels_show(struct device *d, 1860 struct device_attribute *attr, 1861 char *buf) 1862 { 1863 struct ipw_priv *priv = dev_get_drvdata(d); 1864 const struct libipw_geo *geo = libipw_get_geo(priv->ieee); 1865 int len = 0, i; 1866 1867 len = sprintf(&buf[len], 1868 "Displaying %d channels in 2.4Ghz band " 1869 "(802.11bg):\n", geo->bg_channels); 1870 1871 for (i = 0; i < geo->bg_channels; i++) { 1872 len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n", 1873 geo->bg[i].channel, 1874 geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ? 1875 " (radar spectrum)" : "", 1876 ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) || 1877 (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)) 1878 ? "" : ", IBSS", 1879 geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ? 1880 "passive only" : "active/passive", 1881 geo->bg[i].flags & LIBIPW_CH_B_ONLY ? 1882 "B" : "B/G"); 1883 } 1884 1885 len += sprintf(&buf[len], 1886 "Displaying %d channels in 5.2Ghz band " 1887 "(802.11a):\n", geo->a_channels); 1888 for (i = 0; i < geo->a_channels; i++) { 1889 len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n", 1890 geo->a[i].channel, 1891 geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ? 1892 " (radar spectrum)" : "", 1893 ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) || 1894 (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)) 1895 ? "" : ", IBSS", 1896 geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ? 1897 "passive only" : "active/passive"); 1898 } 1899 1900 return len; 1901 } 1902 1903 static DEVICE_ATTR_ADMIN_RO(channels); 1904 1905 static void notify_wx_assoc_event(struct ipw_priv *priv) 1906 { 1907 union iwreq_data wrqu; 1908 wrqu.ap_addr.sa_family = ARPHRD_ETHER; 1909 if (priv->status & STATUS_ASSOCIATED) 1910 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); 1911 else 1912 eth_zero_addr(wrqu.ap_addr.sa_data); 1913 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); 1914 } 1915 1916 static void ipw_irq_tasklet(struct tasklet_struct *t) 1917 { 1918 struct ipw_priv *priv = from_tasklet(priv, t, irq_tasklet); 1919 u32 inta, inta_mask, handled = 0; 1920 unsigned long flags; 1921 1922 spin_lock_irqsave(&priv->irq_lock, flags); 1923 1924 inta = ipw_read32(priv, IPW_INTA_RW); 1925 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); 1926 1927 if (inta == 0xFFFFFFFF) { 1928 /* Hardware disappeared */ 1929 IPW_WARNING("TASKLET INTA == 0xFFFFFFFF\n"); 1930 /* Only handle the cached INTA values */ 1931 inta = 0; 1932 } 1933 inta &= (IPW_INTA_MASK_ALL & inta_mask); 1934 1935 /* Add any cached INTA values that need to be handled */ 1936 inta |= priv->isr_inta; 1937 1938 spin_unlock_irqrestore(&priv->irq_lock, flags); 1939 1940 spin_lock_irqsave(&priv->lock, flags); 1941 1942 /* handle all the justifications for the interrupt */ 1943 if (inta & IPW_INTA_BIT_RX_TRANSFER) { 1944 ipw_rx(priv); 1945 handled |= IPW_INTA_BIT_RX_TRANSFER; 1946 } 1947 1948 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { 1949 IPW_DEBUG_HC("Command completed.\n"); 1950 ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); 1951 priv->status &= ~STATUS_HCMD_ACTIVE; 1952 wake_up_interruptible(&priv->wait_command_queue); 1953 handled |= IPW_INTA_BIT_TX_CMD_QUEUE; 1954 } 1955 1956 if (inta & IPW_INTA_BIT_TX_QUEUE_1) { 1957 IPW_DEBUG_TX("TX_QUEUE_1\n"); 1958 ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); 1959 handled |= IPW_INTA_BIT_TX_QUEUE_1; 1960 } 1961 1962 if (inta & IPW_INTA_BIT_TX_QUEUE_2) { 1963 IPW_DEBUG_TX("TX_QUEUE_2\n"); 1964 ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); 1965 handled |= IPW_INTA_BIT_TX_QUEUE_2; 1966 } 1967 1968 if (inta & IPW_INTA_BIT_TX_QUEUE_3) { 1969 IPW_DEBUG_TX("TX_QUEUE_3\n"); 1970 ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); 1971 handled |= IPW_INTA_BIT_TX_QUEUE_3; 1972 } 1973 1974 if (inta & IPW_INTA_BIT_TX_QUEUE_4) { 1975 IPW_DEBUG_TX("TX_QUEUE_4\n"); 1976 ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); 1977 handled |= IPW_INTA_BIT_TX_QUEUE_4; 1978 } 1979 1980 if (inta & IPW_INTA_BIT_STATUS_CHANGE) { 1981 IPW_WARNING("STATUS_CHANGE\n"); 1982 handled |= IPW_INTA_BIT_STATUS_CHANGE; 1983 } 1984 1985 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { 1986 IPW_WARNING("TX_PERIOD_EXPIRED\n"); 1987 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; 1988 } 1989 1990 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { 1991 IPW_WARNING("HOST_CMD_DONE\n"); 1992 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; 1993 } 1994 1995 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { 1996 IPW_WARNING("FW_INITIALIZATION_DONE\n"); 1997 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; 1998 } 1999 2000 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { 2001 IPW_WARNING("PHY_OFF_DONE\n"); 2002 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; 2003 } 2004 2005 if (inta & IPW_INTA_BIT_RF_KILL_DONE) { 2006 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); 2007 priv->status |= STATUS_RF_KILL_HW; 2008 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true); 2009 wake_up_interruptible(&priv->wait_command_queue); 2010 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); 2011 cancel_delayed_work(&priv->request_scan); 2012 cancel_delayed_work(&priv->request_direct_scan); 2013 cancel_delayed_work(&priv->request_passive_scan); 2014 cancel_delayed_work(&priv->scan_event); 2015 schedule_work(&priv->link_down); 2016 schedule_delayed_work(&priv->rf_kill, 2 * HZ); 2017 handled |= IPW_INTA_BIT_RF_KILL_DONE; 2018 } 2019 2020 if (inta & IPW_INTA_BIT_FATAL_ERROR) { 2021 IPW_WARNING("Firmware error detected. Restarting.\n"); 2022 if (priv->error) { 2023 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); 2024 if (ipw_debug_level & IPW_DL_FW_ERRORS) { 2025 struct ipw_fw_error *error = 2026 ipw_alloc_error_log(priv); 2027 ipw_dump_error_log(priv, error); 2028 kfree(error); 2029 } 2030 } else { 2031 priv->error = ipw_alloc_error_log(priv); 2032 if (priv->error) 2033 IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); 2034 else 2035 IPW_DEBUG_FW("Error allocating sysfs 'error' " 2036 "log.\n"); 2037 if (ipw_debug_level & IPW_DL_FW_ERRORS) 2038 ipw_dump_error_log(priv, priv->error); 2039 } 2040 2041 /* XXX: If hardware encryption is for WPA/WPA2, 2042 * we have to notify the supplicant. */ 2043 if (priv->ieee->sec.encrypt) { 2044 priv->status &= ~STATUS_ASSOCIATED; 2045 notify_wx_assoc_event(priv); 2046 } 2047 2048 /* Keep the restart process from trying to send host 2049 * commands by clearing the INIT status bit */ 2050 priv->status &= ~STATUS_INIT; 2051 2052 /* Cancel currently queued command. */ 2053 priv->status &= ~STATUS_HCMD_ACTIVE; 2054 wake_up_interruptible(&priv->wait_command_queue); 2055 2056 schedule_work(&priv->adapter_restart); 2057 handled |= IPW_INTA_BIT_FATAL_ERROR; 2058 } 2059 2060 if (inta & IPW_INTA_BIT_PARITY_ERROR) { 2061 IPW_ERROR("Parity error\n"); 2062 handled |= IPW_INTA_BIT_PARITY_ERROR; 2063 } 2064 2065 if (handled != inta) { 2066 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); 2067 } 2068 2069 spin_unlock_irqrestore(&priv->lock, flags); 2070 2071 /* enable all interrupts */ 2072 ipw_enable_interrupts(priv); 2073 } 2074 2075 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x 2076 static char *get_cmd_string(u8 cmd) 2077 { 2078 switch (cmd) { 2079 IPW_CMD(HOST_COMPLETE); 2080 IPW_CMD(POWER_DOWN); 2081 IPW_CMD(SYSTEM_CONFIG); 2082 IPW_CMD(MULTICAST_ADDRESS); 2083 IPW_CMD(SSID); 2084 IPW_CMD(ADAPTER_ADDRESS); 2085 IPW_CMD(PORT_TYPE); 2086 IPW_CMD(RTS_THRESHOLD); 2087 IPW_CMD(FRAG_THRESHOLD); 2088 IPW_CMD(POWER_MODE); 2089 IPW_CMD(WEP_KEY); 2090 IPW_CMD(TGI_TX_KEY); 2091 IPW_CMD(SCAN_REQUEST); 2092 IPW_CMD(SCAN_REQUEST_EXT); 2093 IPW_CMD(ASSOCIATE); 2094 IPW_CMD(SUPPORTED_RATES); 2095 IPW_CMD(SCAN_ABORT); 2096 IPW_CMD(TX_FLUSH); 2097 IPW_CMD(QOS_PARAMETERS); 2098 IPW_CMD(DINO_CONFIG); 2099 IPW_CMD(RSN_CAPABILITIES); 2100 IPW_CMD(RX_KEY); 2101 IPW_CMD(CARD_DISABLE); 2102 IPW_CMD(SEED_NUMBER); 2103 IPW_CMD(TX_POWER); 2104 IPW_CMD(COUNTRY_INFO); 2105 IPW_CMD(AIRONET_INFO); 2106 IPW_CMD(AP_TX_POWER); 2107 IPW_CMD(CCKM_INFO); 2108 IPW_CMD(CCX_VER_INFO); 2109 IPW_CMD(SET_CALIBRATION); 2110 IPW_CMD(SENSITIVITY_CALIB); 2111 IPW_CMD(RETRY_LIMIT); 2112 IPW_CMD(IPW_PRE_POWER_DOWN); 2113 IPW_CMD(VAP_BEACON_TEMPLATE); 2114 IPW_CMD(VAP_DTIM_PERIOD); 2115 IPW_CMD(EXT_SUPPORTED_RATES); 2116 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); 2117 IPW_CMD(VAP_QUIET_INTERVALS); 2118 IPW_CMD(VAP_CHANNEL_SWITCH); 2119 IPW_CMD(VAP_MANDATORY_CHANNELS); 2120 IPW_CMD(VAP_CELL_PWR_LIMIT); 2121 IPW_CMD(VAP_CF_PARAM_SET); 2122 IPW_CMD(VAP_SET_BEACONING_STATE); 2123 IPW_CMD(MEASUREMENT); 2124 IPW_CMD(POWER_CAPABILITY); 2125 IPW_CMD(SUPPORTED_CHANNELS); 2126 IPW_CMD(TPC_REPORT); 2127 IPW_CMD(WME_INFO); 2128 IPW_CMD(PRODUCTION_COMMAND); 2129 default: 2130 return "UNKNOWN"; 2131 } 2132 } 2133 2134 #define HOST_COMPLETE_TIMEOUT HZ 2135 2136 static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd) 2137 { 2138 int rc = 0; 2139 unsigned long flags; 2140 unsigned long now, end; 2141 2142 spin_lock_irqsave(&priv->lock, flags); 2143 if (priv->status & STATUS_HCMD_ACTIVE) { 2144 IPW_ERROR("Failed to send %s: Already sending a command.\n", 2145 get_cmd_string(cmd->cmd)); 2146 spin_unlock_irqrestore(&priv->lock, flags); 2147 return -EAGAIN; 2148 } 2149 2150 priv->status |= STATUS_HCMD_ACTIVE; 2151 2152 if (priv->cmdlog) { 2153 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; 2154 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; 2155 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; 2156 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, 2157 cmd->len); 2158 priv->cmdlog[priv->cmdlog_pos].retcode = -1; 2159 } 2160 2161 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", 2162 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, 2163 priv->status); 2164 2165 #ifndef DEBUG_CMD_WEP_KEY 2166 if (cmd->cmd == IPW_CMD_WEP_KEY) 2167 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); 2168 else 2169 #endif 2170 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); 2171 2172 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0); 2173 if (rc) { 2174 priv->status &= ~STATUS_HCMD_ACTIVE; 2175 IPW_ERROR("Failed to send %s: Reason %d\n", 2176 get_cmd_string(cmd->cmd), rc); 2177 spin_unlock_irqrestore(&priv->lock, flags); 2178 goto exit; 2179 } 2180 spin_unlock_irqrestore(&priv->lock, flags); 2181 2182 now = jiffies; 2183 end = now + HOST_COMPLETE_TIMEOUT; 2184 again: 2185 rc = wait_event_interruptible_timeout(priv->wait_command_queue, 2186 !(priv-> 2187 status & STATUS_HCMD_ACTIVE), 2188 end - now); 2189 if (rc < 0) { 2190 now = jiffies; 2191 if (time_before(now, end)) 2192 goto again; 2193 rc = 0; 2194 } 2195 2196 if (rc == 0) { 2197 spin_lock_irqsave(&priv->lock, flags); 2198 if (priv->status & STATUS_HCMD_ACTIVE) { 2199 IPW_ERROR("Failed to send %s: Command timed out.\n", 2200 get_cmd_string(cmd->cmd)); 2201 priv->status &= ~STATUS_HCMD_ACTIVE; 2202 spin_unlock_irqrestore(&priv->lock, flags); 2203 rc = -EIO; 2204 goto exit; 2205 } 2206 spin_unlock_irqrestore(&priv->lock, flags); 2207 } else 2208 rc = 0; 2209 2210 if (priv->status & STATUS_RF_KILL_HW) { 2211 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", 2212 get_cmd_string(cmd->cmd)); 2213 rc = -EIO; 2214 goto exit; 2215 } 2216 2217 exit: 2218 if (priv->cmdlog) { 2219 priv->cmdlog[priv->cmdlog_pos++].retcode = rc; 2220 priv->cmdlog_pos %= priv->cmdlog_len; 2221 } 2222 return rc; 2223 } 2224 2225 static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) 2226 { 2227 struct host_cmd cmd = { 2228 .cmd = command, 2229 }; 2230 2231 return __ipw_send_cmd(priv, &cmd); 2232 } 2233 2234 static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, 2235 const void *data) 2236 { 2237 struct host_cmd cmd = { 2238 .cmd = command, 2239 .len = len, 2240 .param = data, 2241 }; 2242 2243 return __ipw_send_cmd(priv, &cmd); 2244 } 2245 2246 static int ipw_send_host_complete(struct ipw_priv *priv) 2247 { 2248 if (!priv) { 2249 IPW_ERROR("Invalid args\n"); 2250 return -1; 2251 } 2252 2253 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); 2254 } 2255 2256 static int ipw_send_system_config(struct ipw_priv *priv) 2257 { 2258 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, 2259 sizeof(priv->sys_config), 2260 &priv->sys_config); 2261 } 2262 2263 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len) 2264 { 2265 if (!priv || !ssid) { 2266 IPW_ERROR("Invalid args\n"); 2267 return -1; 2268 } 2269 2270 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE), 2271 ssid); 2272 } 2273 2274 static int ipw_send_adapter_address(struct ipw_priv *priv, const u8 * mac) 2275 { 2276 if (!priv || !mac) { 2277 IPW_ERROR("Invalid args\n"); 2278 return -1; 2279 } 2280 2281 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n", 2282 priv->net_dev->name, mac); 2283 2284 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac); 2285 } 2286 2287 static void ipw_adapter_restart(void *adapter) 2288 { 2289 struct ipw_priv *priv = adapter; 2290 2291 if (priv->status & STATUS_RF_KILL_MASK) 2292 return; 2293 2294 ipw_down(priv); 2295 2296 if (priv->assoc_network && 2297 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) 2298 ipw_remove_current_network(priv); 2299 2300 if (ipw_up(priv)) { 2301 IPW_ERROR("Failed to up device\n"); 2302 return; 2303 } 2304 } 2305 2306 static void ipw_bg_adapter_restart(struct work_struct *work) 2307 { 2308 struct ipw_priv *priv = 2309 container_of(work, struct ipw_priv, adapter_restart); 2310 mutex_lock(&priv->mutex); 2311 ipw_adapter_restart(priv); 2312 mutex_unlock(&priv->mutex); 2313 } 2314 2315 static void ipw_abort_scan(struct ipw_priv *priv); 2316 2317 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) 2318 2319 static void ipw_scan_check(void *data) 2320 { 2321 struct ipw_priv *priv = data; 2322 2323 if (priv->status & STATUS_SCAN_ABORTING) { 2324 IPW_DEBUG_SCAN("Scan completion watchdog resetting " 2325 "adapter after (%dms).\n", 2326 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); 2327 schedule_work(&priv->adapter_restart); 2328 } else if (priv->status & STATUS_SCANNING) { 2329 IPW_DEBUG_SCAN("Scan completion watchdog aborting scan " 2330 "after (%dms).\n", 2331 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); 2332 ipw_abort_scan(priv); 2333 schedule_delayed_work(&priv->scan_check, HZ); 2334 } 2335 } 2336 2337 static void ipw_bg_scan_check(struct work_struct *work) 2338 { 2339 struct ipw_priv *priv = 2340 container_of(work, struct ipw_priv, scan_check.work); 2341 mutex_lock(&priv->mutex); 2342 ipw_scan_check(priv); 2343 mutex_unlock(&priv->mutex); 2344 } 2345 2346 static int ipw_send_scan_request_ext(struct ipw_priv *priv, 2347 struct ipw_scan_request_ext *request) 2348 { 2349 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, 2350 sizeof(*request), request); 2351 } 2352 2353 static int ipw_send_scan_abort(struct ipw_priv *priv) 2354 { 2355 if (!priv) { 2356 IPW_ERROR("Invalid args\n"); 2357 return -1; 2358 } 2359 2360 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); 2361 } 2362 2363 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) 2364 { 2365 struct ipw_sensitivity_calib calib = { 2366 .beacon_rssi_raw = cpu_to_le16(sens), 2367 }; 2368 2369 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), 2370 &calib); 2371 } 2372 2373 static int ipw_send_associate(struct ipw_priv *priv, 2374 struct ipw_associate *associate) 2375 { 2376 if (!priv || !associate) { 2377 IPW_ERROR("Invalid args\n"); 2378 return -1; 2379 } 2380 2381 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate), 2382 associate); 2383 } 2384 2385 static int ipw_send_supported_rates(struct ipw_priv *priv, 2386 struct ipw_supported_rates *rates) 2387 { 2388 if (!priv || !rates) { 2389 IPW_ERROR("Invalid args\n"); 2390 return -1; 2391 } 2392 2393 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), 2394 rates); 2395 } 2396 2397 static int ipw_set_random_seed(struct ipw_priv *priv) 2398 { 2399 u32 val; 2400 2401 if (!priv) { 2402 IPW_ERROR("Invalid args\n"); 2403 return -1; 2404 } 2405 2406 get_random_bytes(&val, sizeof(val)); 2407 2408 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val); 2409 } 2410 2411 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) 2412 { 2413 __le32 v = cpu_to_le32(phy_off); 2414 if (!priv) { 2415 IPW_ERROR("Invalid args\n"); 2416 return -1; 2417 } 2418 2419 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v); 2420 } 2421 2422 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power) 2423 { 2424 if (!priv || !power) { 2425 IPW_ERROR("Invalid args\n"); 2426 return -1; 2427 } 2428 2429 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power); 2430 } 2431 2432 static int ipw_set_tx_power(struct ipw_priv *priv) 2433 { 2434 const struct libipw_geo *geo = libipw_get_geo(priv->ieee); 2435 struct ipw_tx_power tx_power; 2436 s8 max_power; 2437 int i; 2438 2439 memset(&tx_power, 0, sizeof(tx_power)); 2440 2441 /* configure device for 'G' band */ 2442 tx_power.ieee_mode = IPW_G_MODE; 2443 tx_power.num_channels = geo->bg_channels; 2444 for (i = 0; i < geo->bg_channels; i++) { 2445 max_power = geo->bg[i].max_power; 2446 tx_power.channels_tx_power[i].channel_number = 2447 geo->bg[i].channel; 2448 tx_power.channels_tx_power[i].tx_power = max_power ? 2449 min(max_power, priv->tx_power) : priv->tx_power; 2450 } 2451 if (ipw_send_tx_power(priv, &tx_power)) 2452 return -EIO; 2453 2454 /* configure device to also handle 'B' band */ 2455 tx_power.ieee_mode = IPW_B_MODE; 2456 if (ipw_send_tx_power(priv, &tx_power)) 2457 return -EIO; 2458 2459 /* configure device to also handle 'A' band */ 2460 if (priv->ieee->abg_true) { 2461 tx_power.ieee_mode = IPW_A_MODE; 2462 tx_power.num_channels = geo->a_channels; 2463 for (i = 0; i < tx_power.num_channels; i++) { 2464 max_power = geo->a[i].max_power; 2465 tx_power.channels_tx_power[i].channel_number = 2466 geo->a[i].channel; 2467 tx_power.channels_tx_power[i].tx_power = max_power ? 2468 min(max_power, priv->tx_power) : priv->tx_power; 2469 } 2470 if (ipw_send_tx_power(priv, &tx_power)) 2471 return -EIO; 2472 } 2473 return 0; 2474 } 2475 2476 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) 2477 { 2478 struct ipw_rts_threshold rts_threshold = { 2479 .rts_threshold = cpu_to_le16(rts), 2480 }; 2481 2482 if (!priv) { 2483 IPW_ERROR("Invalid args\n"); 2484 return -1; 2485 } 2486 2487 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, 2488 sizeof(rts_threshold), &rts_threshold); 2489 } 2490 2491 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) 2492 { 2493 struct ipw_frag_threshold frag_threshold = { 2494 .frag_threshold = cpu_to_le16(frag), 2495 }; 2496 2497 if (!priv) { 2498 IPW_ERROR("Invalid args\n"); 2499 return -1; 2500 } 2501 2502 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, 2503 sizeof(frag_threshold), &frag_threshold); 2504 } 2505 2506 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) 2507 { 2508 __le32 param; 2509 2510 if (!priv) { 2511 IPW_ERROR("Invalid args\n"); 2512 return -1; 2513 } 2514 2515 /* If on battery, set to 3, if AC set to CAM, else user 2516 * level */ 2517 switch (mode) { 2518 case IPW_POWER_BATTERY: 2519 param = cpu_to_le32(IPW_POWER_INDEX_3); 2520 break; 2521 case IPW_POWER_AC: 2522 param = cpu_to_le32(IPW_POWER_MODE_CAM); 2523 break; 2524 default: 2525 param = cpu_to_le32(mode); 2526 break; 2527 } 2528 2529 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), 2530 ¶m); 2531 } 2532 2533 static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) 2534 { 2535 struct ipw_retry_limit retry_limit = { 2536 .short_retry_limit = slimit, 2537 .long_retry_limit = llimit 2538 }; 2539 2540 if (!priv) { 2541 IPW_ERROR("Invalid args\n"); 2542 return -1; 2543 } 2544 2545 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit), 2546 &retry_limit); 2547 } 2548 2549 /* 2550 * The IPW device contains a Microwire compatible EEPROM that stores 2551 * various data like the MAC address. Usually the firmware has exclusive 2552 * access to the eeprom, but during device initialization (before the 2553 * device driver has sent the HostComplete command to the firmware) the 2554 * device driver has read access to the EEPROM by way of indirect addressing 2555 * through a couple of memory mapped registers. 2556 * 2557 * The following is a simplified implementation for pulling data out of the 2558 * eeprom, along with some helper functions to find information in 2559 * the per device private data's copy of the eeprom. 2560 * 2561 * NOTE: To better understand how these functions work (i.e what is a chip 2562 * select and why do have to keep driving the eeprom clock?), read 2563 * just about any data sheet for a Microwire compatible EEPROM. 2564 */ 2565 2566 /* write a 32 bit value into the indirect accessor register */ 2567 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) 2568 { 2569 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); 2570 2571 /* the eeprom requires some time to complete the operation */ 2572 udelay(p->eeprom_delay); 2573 } 2574 2575 /* perform a chip select operation */ 2576 static void eeprom_cs(struct ipw_priv *priv) 2577 { 2578 eeprom_write_reg(priv, 0); 2579 eeprom_write_reg(priv, EEPROM_BIT_CS); 2580 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); 2581 eeprom_write_reg(priv, EEPROM_BIT_CS); 2582 } 2583 2584 /* perform a chip select operation */ 2585 static void eeprom_disable_cs(struct ipw_priv *priv) 2586 { 2587 eeprom_write_reg(priv, EEPROM_BIT_CS); 2588 eeprom_write_reg(priv, 0); 2589 eeprom_write_reg(priv, EEPROM_BIT_SK); 2590 } 2591 2592 /* push a single bit down to the eeprom */ 2593 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) 2594 { 2595 int d = (bit ? EEPROM_BIT_DI : 0); 2596 eeprom_write_reg(p, EEPROM_BIT_CS | d); 2597 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); 2598 } 2599 2600 /* push an opcode followed by an address down to the eeprom */ 2601 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) 2602 { 2603 int i; 2604 2605 eeprom_cs(priv); 2606 eeprom_write_bit(priv, 1); 2607 eeprom_write_bit(priv, op & 2); 2608 eeprom_write_bit(priv, op & 1); 2609 for (i = 7; i >= 0; i--) { 2610 eeprom_write_bit(priv, addr & (1 << i)); 2611 } 2612 } 2613 2614 /* pull 16 bits off the eeprom, one bit at a time */ 2615 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) 2616 { 2617 int i; 2618 u16 r = 0; 2619 2620 /* Send READ Opcode */ 2621 eeprom_op(priv, EEPROM_CMD_READ, addr); 2622 2623 /* Send dummy bit */ 2624 eeprom_write_reg(priv, EEPROM_BIT_CS); 2625 2626 /* Read the byte off the eeprom one bit at a time */ 2627 for (i = 0; i < 16; i++) { 2628 u32 data = 0; 2629 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); 2630 eeprom_write_reg(priv, EEPROM_BIT_CS); 2631 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); 2632 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); 2633 } 2634 2635 /* Send another dummy bit */ 2636 eeprom_write_reg(priv, 0); 2637 eeprom_disable_cs(priv); 2638 2639 return r; 2640 } 2641 2642 /* helper function for pulling the mac address out of the private */ 2643 /* data's copy of the eeprom data */ 2644 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) 2645 { 2646 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], ETH_ALEN); 2647 } 2648 2649 static void ipw_read_eeprom(struct ipw_priv *priv) 2650 { 2651 int i; 2652 __le16 *eeprom = (__le16 *) priv->eeprom; 2653 2654 IPW_DEBUG_TRACE(">>\n"); 2655 2656 /* read entire contents of eeprom into private buffer */ 2657 for (i = 0; i < 128; i++) 2658 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i)); 2659 2660 IPW_DEBUG_TRACE("<<\n"); 2661 } 2662 2663 /* 2664 * Either the device driver (i.e. the host) or the firmware can 2665 * load eeprom data into the designated region in SRAM. If neither 2666 * happens then the FW will shutdown with a fatal error. 2667 * 2668 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE 2669 * bit needs region of shared SRAM needs to be non-zero. 2670 */ 2671 static void ipw_eeprom_init_sram(struct ipw_priv *priv) 2672 { 2673 int i; 2674 2675 IPW_DEBUG_TRACE(">>\n"); 2676 2677 /* 2678 If the data looks correct, then copy it to our private 2679 copy. Otherwise let the firmware know to perform the operation 2680 on its own. 2681 */ 2682 if (priv->eeprom[EEPROM_VERSION] != 0) { 2683 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); 2684 2685 /* write the eeprom data to sram */ 2686 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) 2687 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); 2688 2689 /* Do not load eeprom data on fatal error or suspend */ 2690 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); 2691 } else { 2692 IPW_DEBUG_INFO("Enabling FW initialization of SRAM\n"); 2693 2694 /* Load eeprom data on fatal error or suspend */ 2695 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); 2696 } 2697 2698 IPW_DEBUG_TRACE("<<\n"); 2699 } 2700 2701 static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count) 2702 { 2703 count >>= 2; 2704 if (!count) 2705 return; 2706 _ipw_write32(priv, IPW_AUTOINC_ADDR, start); 2707 while (count--) 2708 _ipw_write32(priv, IPW_AUTOINC_DATA, 0); 2709 } 2710 2711 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) 2712 { 2713 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, 2714 CB_NUMBER_OF_ELEMENTS_SMALL * 2715 sizeof(struct command_block)); 2716 } 2717 2718 static int ipw_fw_dma_enable(struct ipw_priv *priv) 2719 { /* start dma engine but no transfers yet */ 2720 2721 IPW_DEBUG_FW(">> :\n"); 2722 2723 /* Start the dma */ 2724 ipw_fw_dma_reset_command_blocks(priv); 2725 2726 /* Write CB base address */ 2727 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL); 2728 2729 IPW_DEBUG_FW("<< :\n"); 2730 return 0; 2731 } 2732 2733 static void ipw_fw_dma_abort(struct ipw_priv *priv) 2734 { 2735 u32 control = 0; 2736 2737 IPW_DEBUG_FW(">> :\n"); 2738 2739 /* set the Stop and Abort bit */ 2740 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; 2741 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); 2742 priv->sram_desc.last_cb_index = 0; 2743 2744 IPW_DEBUG_FW("<<\n"); 2745 } 2746 2747 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, 2748 struct command_block *cb) 2749 { 2750 u32 address = 2751 IPW_SHARED_SRAM_DMA_CONTROL + 2752 (sizeof(struct command_block) * index); 2753 IPW_DEBUG_FW(">> :\n"); 2754 2755 ipw_write_indirect(priv, address, (u8 *) cb, 2756 (int)sizeof(struct command_block)); 2757 2758 IPW_DEBUG_FW("<< :\n"); 2759 return 0; 2760 2761 } 2762 2763 static int ipw_fw_dma_kick(struct ipw_priv *priv) 2764 { 2765 u32 control = 0; 2766 u32 index = 0; 2767 2768 IPW_DEBUG_FW(">> :\n"); 2769 2770 for (index = 0; index < priv->sram_desc.last_cb_index; index++) 2771 ipw_fw_dma_write_command_block(priv, index, 2772 &priv->sram_desc.cb_list[index]); 2773 2774 /* Enable the DMA in the CSR register */ 2775 ipw_clear_bit(priv, IPW_RESET_REG, 2776 IPW_RESET_REG_MASTER_DISABLED | 2777 IPW_RESET_REG_STOP_MASTER); 2778 2779 /* Set the Start bit. */ 2780 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; 2781 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); 2782 2783 IPW_DEBUG_FW("<< :\n"); 2784 return 0; 2785 } 2786 2787 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) 2788 { 2789 u32 address; 2790 u32 register_value = 0; 2791 u32 cb_fields_address = 0; 2792 2793 IPW_DEBUG_FW(">> :\n"); 2794 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); 2795 IPW_DEBUG_FW_INFO("Current CB is 0x%x\n", address); 2796 2797 /* Read the DMA Controlor register */ 2798 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); 2799 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x\n", register_value); 2800 2801 /* Print the CB values */ 2802 cb_fields_address = address; 2803 register_value = ipw_read_reg32(priv, cb_fields_address); 2804 IPW_DEBUG_FW_INFO("Current CB Control Field is 0x%x\n", register_value); 2805 2806 cb_fields_address += sizeof(u32); 2807 register_value = ipw_read_reg32(priv, cb_fields_address); 2808 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x\n", register_value); 2809 2810 cb_fields_address += sizeof(u32); 2811 register_value = ipw_read_reg32(priv, cb_fields_address); 2812 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x\n", 2813 register_value); 2814 2815 cb_fields_address += sizeof(u32); 2816 register_value = ipw_read_reg32(priv, cb_fields_address); 2817 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x\n", register_value); 2818 2819 IPW_DEBUG_FW(">> :\n"); 2820 } 2821 2822 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) 2823 { 2824 u32 current_cb_address = 0; 2825 u32 current_cb_index = 0; 2826 2827 IPW_DEBUG_FW("<< :\n"); 2828 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); 2829 2830 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / 2831 sizeof(struct command_block); 2832 2833 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X\n", 2834 current_cb_index, current_cb_address); 2835 2836 IPW_DEBUG_FW(">> :\n"); 2837 return current_cb_index; 2838 2839 } 2840 2841 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, 2842 u32 src_address, 2843 u32 dest_address, 2844 u32 length, 2845 int interrupt_enabled, int is_last) 2846 { 2847 2848 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC | 2849 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | 2850 CB_DEST_SIZE_LONG; 2851 struct command_block *cb; 2852 u32 last_cb_element = 0; 2853 2854 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", 2855 src_address, dest_address, length); 2856 2857 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) 2858 return -1; 2859 2860 last_cb_element = priv->sram_desc.last_cb_index; 2861 cb = &priv->sram_desc.cb_list[last_cb_element]; 2862 priv->sram_desc.last_cb_index++; 2863 2864 /* Calculate the new CB control word */ 2865 if (interrupt_enabled) 2866 control |= CB_INT_ENABLED; 2867 2868 if (is_last) 2869 control |= CB_LAST_VALID; 2870 2871 control |= length; 2872 2873 /* Calculate the CB Element's checksum value */ 2874 cb->status = control ^ src_address ^ dest_address; 2875 2876 /* Copy the Source and Destination addresses */ 2877 cb->dest_addr = dest_address; 2878 cb->source_addr = src_address; 2879 2880 /* Copy the Control Word last */ 2881 cb->control = control; 2882 2883 return 0; 2884 } 2885 2886 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address, 2887 int nr, u32 dest_address, u32 len) 2888 { 2889 int ret, i; 2890 u32 size; 2891 2892 IPW_DEBUG_FW(">>\n"); 2893 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n", 2894 nr, dest_address, len); 2895 2896 for (i = 0; i < nr; i++) { 2897 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH); 2898 ret = ipw_fw_dma_add_command_block(priv, src_address[i], 2899 dest_address + 2900 i * CB_MAX_LENGTH, size, 2901 0, 0); 2902 if (ret) { 2903 IPW_DEBUG_FW_INFO(": Failed\n"); 2904 return -1; 2905 } else 2906 IPW_DEBUG_FW_INFO(": Added new cb\n"); 2907 } 2908 2909 IPW_DEBUG_FW("<<\n"); 2910 return 0; 2911 } 2912 2913 static int ipw_fw_dma_wait(struct ipw_priv *priv) 2914 { 2915 u32 current_index = 0, previous_index; 2916 u32 watchdog = 0; 2917 2918 IPW_DEBUG_FW(">> :\n"); 2919 2920 current_index = ipw_fw_dma_command_block_index(priv); 2921 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", 2922 (int)priv->sram_desc.last_cb_index); 2923 2924 while (current_index < priv->sram_desc.last_cb_index) { 2925 udelay(50); 2926 previous_index = current_index; 2927 current_index = ipw_fw_dma_command_block_index(priv); 2928 2929 if (previous_index < current_index) { 2930 watchdog = 0; 2931 continue; 2932 } 2933 if (++watchdog > 400) { 2934 IPW_DEBUG_FW_INFO("Timeout\n"); 2935 ipw_fw_dma_dump_command_block(priv); 2936 ipw_fw_dma_abort(priv); 2937 return -1; 2938 } 2939 } 2940 2941 ipw_fw_dma_abort(priv); 2942 2943 /*Disable the DMA in the CSR register */ 2944 ipw_set_bit(priv, IPW_RESET_REG, 2945 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); 2946 2947 IPW_DEBUG_FW("<< dmaWaitSync\n"); 2948 return 0; 2949 } 2950 2951 static void ipw_remove_current_network(struct ipw_priv *priv) 2952 { 2953 struct list_head *element, *safe; 2954 struct libipw_network *network = NULL; 2955 unsigned long flags; 2956 2957 spin_lock_irqsave(&priv->ieee->lock, flags); 2958 list_for_each_safe(element, safe, &priv->ieee->network_list) { 2959 network = list_entry(element, struct libipw_network, list); 2960 if (ether_addr_equal(network->bssid, priv->bssid)) { 2961 list_del(element); 2962 list_add_tail(&network->list, 2963 &priv->ieee->network_free_list); 2964 } 2965 } 2966 spin_unlock_irqrestore(&priv->ieee->lock, flags); 2967 } 2968 2969 /* timeout in msec, attempted in 10-msec quanta */ 2970 static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask, 2971 int timeout) 2972 { 2973 int i = 0; 2974 2975 do { 2976 if ((ipw_read32(priv, addr) & mask) == mask) 2977 return i; 2978 mdelay(10); 2979 i += 10; 2980 } while (i < timeout); 2981 2982 return -ETIME; 2983 } 2984 2985 /* These functions load the firmware and micro code for the operation of 2986 * the ipw hardware. It assumes the buffer has all the bits for the 2987 * image and the caller is handling the memory allocation and clean up. 2988 */ 2989 2990 static int ipw_stop_master(struct ipw_priv *priv) 2991 { 2992 int rc; 2993 2994 IPW_DEBUG_TRACE(">>\n"); 2995 /* stop master. typical delay - 0 */ 2996 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); 2997 2998 /* timeout is in msec, polled in 10-msec quanta */ 2999 rc = ipw_poll_bit(priv, IPW_RESET_REG, 3000 IPW_RESET_REG_MASTER_DISABLED, 100); 3001 if (rc < 0) { 3002 IPW_ERROR("wait for stop master failed after 100ms\n"); 3003 return -1; 3004 } 3005 3006 IPW_DEBUG_INFO("stop master %dms\n", rc); 3007 3008 return rc; 3009 } 3010 3011 static void ipw_arc_release(struct ipw_priv *priv) 3012 { 3013 IPW_DEBUG_TRACE(">>\n"); 3014 mdelay(5); 3015 3016 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); 3017 3018 /* no one knows timing, for safety add some delay */ 3019 mdelay(5); 3020 } 3021 3022 struct fw_chunk { 3023 __le32 address; 3024 __le32 length; 3025 }; 3026 3027 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len) 3028 { 3029 int rc = 0, i, addr; 3030 u8 cr = 0; 3031 __le16 *image; 3032 3033 image = (__le16 *) data; 3034 3035 IPW_DEBUG_TRACE(">>\n"); 3036 3037 rc = ipw_stop_master(priv); 3038 3039 if (rc < 0) 3040 return rc; 3041 3042 for (addr = IPW_SHARED_LOWER_BOUND; 3043 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { 3044 ipw_write32(priv, addr, 0); 3045 } 3046 3047 /* no ucode (yet) */ 3048 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); 3049 /* destroy DMA queues */ 3050 /* reset sequence */ 3051 3052 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON); 3053 ipw_arc_release(priv); 3054 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF); 3055 mdelay(1); 3056 3057 /* reset PHY */ 3058 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); 3059 mdelay(1); 3060 3061 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); 3062 mdelay(1); 3063 3064 /* enable ucode store */ 3065 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); 3066 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); 3067 mdelay(1); 3068 3069 /* write ucode */ 3070 /* 3071 * @bug 3072 * Do NOT set indirect address register once and then 3073 * store data to indirect data register in the loop. 3074 * It seems very reasonable, but in this case DINO do not 3075 * accept ucode. It is essential to set address each time. 3076 */ 3077 /* load new ipw uCode */ 3078 for (i = 0; i < len / 2; i++) 3079 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, 3080 le16_to_cpu(image[i])); 3081 3082 /* enable DINO */ 3083 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); 3084 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); 3085 3086 /* this is where the igx / win driver deveates from the VAP driver. */ 3087 3088 /* wait for alive response */ 3089 for (i = 0; i < 100; i++) { 3090 /* poll for incoming data */ 3091 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); 3092 if (cr & DINO_RXFIFO_DATA) 3093 break; 3094 mdelay(1); 3095 } 3096 3097 if (cr & DINO_RXFIFO_DATA) { 3098 /* alive_command_responce size is NOT multiple of 4 */ 3099 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; 3100 3101 for (i = 0; i < ARRAY_SIZE(response_buffer); i++) 3102 response_buffer[i] = 3103 cpu_to_le32(ipw_read_reg32(priv, 3104 IPW_BASEBAND_RX_FIFO_READ)); 3105 memcpy(&priv->dino_alive, response_buffer, 3106 sizeof(priv->dino_alive)); 3107 if (priv->dino_alive.alive_command == 1 3108 && priv->dino_alive.ucode_valid == 1) { 3109 rc = 0; 3110 IPW_DEBUG_INFO 3111 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " 3112 "of %02d/%02d/%02d %02d:%02d\n", 3113 priv->dino_alive.software_revision, 3114 priv->dino_alive.software_revision, 3115 priv->dino_alive.device_identifier, 3116 priv->dino_alive.device_identifier, 3117 priv->dino_alive.time_stamp[0], 3118 priv->dino_alive.time_stamp[1], 3119 priv->dino_alive.time_stamp[2], 3120 priv->dino_alive.time_stamp[3], 3121 priv->dino_alive.time_stamp[4]); 3122 } else { 3123 IPW_DEBUG_INFO("Microcode is not alive\n"); 3124 rc = -EINVAL; 3125 } 3126 } else { 3127 IPW_DEBUG_INFO("No alive response from DINO\n"); 3128 rc = -ETIME; 3129 } 3130 3131 /* disable DINO, otherwise for some reason 3132 firmware have problem getting alive resp. */ 3133 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); 3134 3135 return rc; 3136 } 3137 3138 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len) 3139 { 3140 int ret = -1; 3141 int offset = 0; 3142 struct fw_chunk *chunk; 3143 int total_nr = 0; 3144 int i; 3145 struct dma_pool *pool; 3146 void **virts; 3147 dma_addr_t *phys; 3148 3149 IPW_DEBUG_TRACE("<< :\n"); 3150 3151 virts = kmalloc_array(CB_NUMBER_OF_ELEMENTS_SMALL, sizeof(void *), 3152 GFP_KERNEL); 3153 if (!virts) 3154 return -ENOMEM; 3155 3156 phys = kmalloc_objs(dma_addr_t, CB_NUMBER_OF_ELEMENTS_SMALL); 3157 if (!phys) { 3158 kfree(virts); 3159 return -ENOMEM; 3160 } 3161 pool = dma_pool_create("ipw2200", &priv->pci_dev->dev, CB_MAX_LENGTH, 0, 3162 0); 3163 if (!pool) { 3164 IPW_ERROR("dma_pool_create failed\n"); 3165 kfree(phys); 3166 kfree(virts); 3167 return -ENOMEM; 3168 } 3169 3170 /* Start the Dma */ 3171 ret = ipw_fw_dma_enable(priv); 3172 3173 /* the DMA is already ready this would be a bug. */ 3174 BUG_ON(priv->sram_desc.last_cb_index > 0); 3175 3176 do { 3177 u32 chunk_len; 3178 u8 *start; 3179 int size; 3180 int nr = 0; 3181 3182 chunk = (struct fw_chunk *)(data + offset); 3183 offset += sizeof(struct fw_chunk); 3184 chunk_len = le32_to_cpu(chunk->length); 3185 start = data + offset; 3186 3187 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH; 3188 for (i = 0; i < nr; i++) { 3189 virts[total_nr] = dma_pool_alloc(pool, GFP_KERNEL, 3190 &phys[total_nr]); 3191 if (!virts[total_nr]) { 3192 ret = -ENOMEM; 3193 goto out; 3194 } 3195 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH, 3196 CB_MAX_LENGTH); 3197 memcpy(virts[total_nr], start, size); 3198 start += size; 3199 total_nr++; 3200 /* We don't support fw chunk larger than 64*8K */ 3201 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL); 3202 } 3203 3204 /* build DMA packet and queue up for sending */ 3205 /* dma to chunk->address, the chunk->length bytes from data + 3206 * offeset*/ 3207 /* Dma loading */ 3208 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr], 3209 nr, le32_to_cpu(chunk->address), 3210 chunk_len); 3211 if (ret) { 3212 IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); 3213 goto out; 3214 } 3215 3216 offset += chunk_len; 3217 } while (offset < len); 3218 3219 /* Run the DMA and wait for the answer */ 3220 ret = ipw_fw_dma_kick(priv); 3221 if (ret) { 3222 IPW_ERROR("dmaKick Failed\n"); 3223 goto out; 3224 } 3225 3226 ret = ipw_fw_dma_wait(priv); 3227 if (ret) { 3228 IPW_ERROR("dmaWaitSync Failed\n"); 3229 goto out; 3230 } 3231 out: 3232 for (i = 0; i < total_nr; i++) 3233 dma_pool_free(pool, virts[i], phys[i]); 3234 3235 dma_pool_destroy(pool); 3236 kfree(phys); 3237 kfree(virts); 3238 3239 return ret; 3240 } 3241 3242 /* stop nic */ 3243 static int ipw_stop_nic(struct ipw_priv *priv) 3244 { 3245 int rc = 0; 3246 3247 /* stop */ 3248 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); 3249 3250 rc = ipw_poll_bit(priv, IPW_RESET_REG, 3251 IPW_RESET_REG_MASTER_DISABLED, 500); 3252 if (rc < 0) { 3253 IPW_ERROR("wait for reg master disabled failed after 500ms\n"); 3254 return rc; 3255 } 3256 3257 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); 3258 3259 return rc; 3260 } 3261 3262 static void ipw_start_nic(struct ipw_priv *priv) 3263 { 3264 IPW_DEBUG_TRACE(">>\n"); 3265 3266 /* prvHwStartNic release ARC */ 3267 ipw_clear_bit(priv, IPW_RESET_REG, 3268 IPW_RESET_REG_MASTER_DISABLED | 3269 IPW_RESET_REG_STOP_MASTER | 3270 CBD_RESET_REG_PRINCETON_RESET); 3271 3272 /* enable power management */ 3273 ipw_set_bit(priv, IPW_GP_CNTRL_RW, 3274 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); 3275 3276 IPW_DEBUG_TRACE("<<\n"); 3277 } 3278 3279 static int ipw_init_nic(struct ipw_priv *priv) 3280 { 3281 int rc; 3282 3283 IPW_DEBUG_TRACE(">>\n"); 3284 /* reset */ 3285 /*prvHwInitNic */ 3286 /* set "initialization complete" bit to move adapter to D0 state */ 3287 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); 3288 3289 /* low-level PLL activation */ 3290 ipw_write32(priv, IPW_READ_INT_REGISTER, 3291 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); 3292 3293 /* wait for clock stabilization */ 3294 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, 3295 IPW_GP_CNTRL_BIT_CLOCK_READY, 250); 3296 if (rc < 0) 3297 IPW_DEBUG_INFO("FAILED wait for clock stabilization\n"); 3298 3299 /* assert SW reset */ 3300 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); 3301 3302 udelay(10); 3303 3304 /* set "initialization complete" bit to move adapter to D0 state */ 3305 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); 3306 3307 IPW_DEBUG_TRACE(">>\n"); 3308 return 0; 3309 } 3310 3311 /* Call this function from process context, it will sleep in request_firmware. 3312 * Probe is an ok place to call this from. 3313 */ 3314 static int ipw_reset_nic(struct ipw_priv *priv) 3315 { 3316 int rc = 0; 3317 unsigned long flags; 3318 3319 IPW_DEBUG_TRACE(">>\n"); 3320 3321 rc = ipw_init_nic(priv); 3322 3323 spin_lock_irqsave(&priv->lock, flags); 3324 /* Clear the 'host command active' bit... */ 3325 priv->status &= ~STATUS_HCMD_ACTIVE; 3326 wake_up_interruptible(&priv->wait_command_queue); 3327 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); 3328 wake_up_interruptible(&priv->wait_state); 3329 spin_unlock_irqrestore(&priv->lock, flags); 3330 3331 IPW_DEBUG_TRACE("<<\n"); 3332 return rc; 3333 } 3334 3335 3336 struct ipw_fw { 3337 __le32 ver; 3338 __le32 boot_size; 3339 __le32 ucode_size; 3340 __le32 fw_size; 3341 u8 data[]; 3342 }; 3343 3344 static int ipw_get_fw(struct ipw_priv *priv, 3345 const struct firmware **raw, const char *name) 3346 { 3347 struct ipw_fw *fw; 3348 int rc; 3349 3350 /* ask firmware_class module to get the boot firmware off disk */ 3351 rc = request_firmware(raw, name, &priv->pci_dev->dev); 3352 if (rc < 0) { 3353 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); 3354 return rc; 3355 } 3356 3357 if ((*raw)->size < sizeof(*fw)) { 3358 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); 3359 return -EINVAL; 3360 } 3361 3362 fw = (void *)(*raw)->data; 3363 3364 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) + 3365 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) { 3366 IPW_ERROR("%s is too small or corrupt (%zd)\n", 3367 name, (*raw)->size); 3368 return -EINVAL; 3369 } 3370 3371 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n", 3372 name, 3373 le32_to_cpu(fw->ver) >> 16, 3374 le32_to_cpu(fw->ver) & 0xff, 3375 (*raw)->size - sizeof(*fw)); 3376 return 0; 3377 } 3378 3379 #define IPW_RX_BUF_SIZE (3000) 3380 3381 static void ipw_rx_queue_reset(struct ipw_priv *priv, 3382 struct ipw_rx_queue *rxq) 3383 { 3384 unsigned long flags; 3385 int i; 3386 3387 spin_lock_irqsave(&rxq->lock, flags); 3388 3389 INIT_LIST_HEAD(&rxq->rx_free); 3390 INIT_LIST_HEAD(&rxq->rx_used); 3391 3392 /* Fill the rx_used queue with _all_ of the Rx buffers */ 3393 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { 3394 /* In the reset function, these buffers may have been allocated 3395 * to an SKB, so we need to unmap and free potential storage */ 3396 if (rxq->pool[i].skb != NULL) { 3397 dma_unmap_single(&priv->pci_dev->dev, 3398 rxq->pool[i].dma_addr, 3399 IPW_RX_BUF_SIZE, DMA_FROM_DEVICE); 3400 dev_kfree_skb_irq(rxq->pool[i].skb); 3401 rxq->pool[i].skb = NULL; 3402 } 3403 list_add_tail(&rxq->pool[i].list, &rxq->rx_used); 3404 } 3405 3406 /* Set us so that we have processed and used all buffers, but have 3407 * not restocked the Rx queue with fresh buffers */ 3408 rxq->read = rxq->write = 0; 3409 rxq->free_count = 0; 3410 spin_unlock_irqrestore(&rxq->lock, flags); 3411 } 3412 3413 #ifdef CONFIG_PM 3414 static int fw_loaded = 0; 3415 static const struct firmware *raw = NULL; 3416 3417 static void free_firmware(void) 3418 { 3419 if (fw_loaded) { 3420 release_firmware(raw); 3421 raw = NULL; 3422 fw_loaded = 0; 3423 } 3424 } 3425 #else 3426 #define free_firmware() do {} while (0) 3427 #endif 3428 3429 static int ipw_load(struct ipw_priv *priv) 3430 { 3431 #ifndef CONFIG_PM 3432 const struct firmware *raw = NULL; 3433 #endif 3434 struct ipw_fw *fw; 3435 u8 *boot_img, *ucode_img, *fw_img; 3436 u8 *name = NULL; 3437 int rc = 0, retries = 3; 3438 3439 switch (priv->ieee->iw_mode) { 3440 case IW_MODE_ADHOC: 3441 name = "ipw2200-ibss.fw"; 3442 break; 3443 #ifdef CONFIG_IPW2200_MONITOR 3444 case IW_MODE_MONITOR: 3445 name = "ipw2200-sniffer.fw"; 3446 break; 3447 #endif 3448 case IW_MODE_INFRA: 3449 name = "ipw2200-bss.fw"; 3450 break; 3451 } 3452 3453 if (!name) { 3454 rc = -EINVAL; 3455 goto error; 3456 } 3457 3458 #ifdef CONFIG_PM 3459 if (!fw_loaded) { 3460 #endif 3461 rc = ipw_get_fw(priv, &raw, name); 3462 if (rc < 0) 3463 goto error; 3464 #ifdef CONFIG_PM 3465 } 3466 #endif 3467 3468 fw = (void *)raw->data; 3469 boot_img = &fw->data[0]; 3470 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)]; 3471 fw_img = &fw->data[le32_to_cpu(fw->boot_size) + 3472 le32_to_cpu(fw->ucode_size)]; 3473 3474 if (!priv->rxq) 3475 priv->rxq = ipw_rx_queue_alloc(priv); 3476 else 3477 ipw_rx_queue_reset(priv, priv->rxq); 3478 if (!priv->rxq) { 3479 IPW_ERROR("Unable to initialize Rx queue\n"); 3480 rc = -ENOMEM; 3481 goto error; 3482 } 3483 3484 retry: 3485 /* Ensure interrupts are disabled */ 3486 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); 3487 priv->status &= ~STATUS_INT_ENABLED; 3488 3489 /* ack pending interrupts */ 3490 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); 3491 3492 ipw_stop_nic(priv); 3493 3494 rc = ipw_reset_nic(priv); 3495 if (rc < 0) { 3496 IPW_ERROR("Unable to reset NIC\n"); 3497 goto error; 3498 } 3499 3500 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, 3501 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); 3502 3503 /* DMA the initial boot firmware into the device */ 3504 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size)); 3505 if (rc < 0) { 3506 IPW_ERROR("Unable to load boot firmware: %d\n", rc); 3507 goto error; 3508 } 3509 3510 /* kick start the device */ 3511 ipw_start_nic(priv); 3512 3513 /* wait for the device to finish its initial startup sequence */ 3514 rc = ipw_poll_bit(priv, IPW_INTA_RW, 3515 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); 3516 if (rc < 0) { 3517 IPW_ERROR("device failed to boot initial fw image\n"); 3518 goto error; 3519 } 3520 IPW_DEBUG_INFO("initial device response after %dms\n", rc); 3521 3522 /* ack fw init done interrupt */ 3523 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); 3524 3525 /* DMA the ucode into the device */ 3526 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size)); 3527 if (rc < 0) { 3528 IPW_ERROR("Unable to load ucode: %d\n", rc); 3529 goto error; 3530 } 3531 3532 /* stop nic */ 3533 ipw_stop_nic(priv); 3534 3535 /* DMA bss firmware into the device */ 3536 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size)); 3537 if (rc < 0) { 3538 IPW_ERROR("Unable to load firmware: %d\n", rc); 3539 goto error; 3540 } 3541 #ifdef CONFIG_PM 3542 fw_loaded = 1; 3543 #endif 3544 3545 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); 3546 3547 rc = ipw_queue_reset(priv); 3548 if (rc < 0) { 3549 IPW_ERROR("Unable to initialize queues\n"); 3550 goto error; 3551 } 3552 3553 /* Ensure interrupts are disabled */ 3554 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); 3555 /* ack pending interrupts */ 3556 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); 3557 3558 /* kick start the device */ 3559 ipw_start_nic(priv); 3560 3561 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { 3562 if (retries > 0) { 3563 IPW_WARNING("Parity error. Retrying init.\n"); 3564 retries--; 3565 goto retry; 3566 } 3567 3568 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); 3569 rc = -EIO; 3570 goto error; 3571 } 3572 3573 /* wait for the device */ 3574 rc = ipw_poll_bit(priv, IPW_INTA_RW, 3575 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); 3576 if (rc < 0) { 3577 IPW_ERROR("device failed to start within 500ms\n"); 3578 goto error; 3579 } 3580 IPW_DEBUG_INFO("device response after %dms\n", rc); 3581 3582 /* ack fw init done interrupt */ 3583 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); 3584 3585 /* read eeprom data */ 3586 priv->eeprom_delay = 1; 3587 ipw_read_eeprom(priv); 3588 /* initialize the eeprom region of sram */ 3589 ipw_eeprom_init_sram(priv); 3590 3591 /* enable interrupts */ 3592 ipw_enable_interrupts(priv); 3593 3594 /* Ensure our queue has valid packets */ 3595 ipw_rx_queue_replenish(priv); 3596 3597 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); 3598 3599 /* ack pending interrupts */ 3600 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); 3601 3602 #ifndef CONFIG_PM 3603 release_firmware(raw); 3604 #endif 3605 return 0; 3606 3607 error: 3608 if (priv->rxq) { 3609 ipw_rx_queue_free(priv, priv->rxq); 3610 priv->rxq = NULL; 3611 } 3612 ipw_tx_queue_free(priv); 3613 release_firmware(raw); 3614 #ifdef CONFIG_PM 3615 fw_loaded = 0; 3616 raw = NULL; 3617 #endif 3618 3619 return rc; 3620 } 3621 3622 /* 3623 * DMA services 3624 * 3625 * Theory of operation 3626 * 3627 * A queue is a circular buffers with 'Read' and 'Write' pointers. 3628 * 2 empty entries always kept in the buffer to protect from overflow. 3629 * 3630 * For Tx queue, there are low mark and high mark limits. If, after queuing 3631 * the packet for Tx, free space become < low mark, Tx queue stopped. When 3632 * reclaiming packets (on 'tx done IRQ), if free space become > high mark, 3633 * Tx queue resumed. 3634 * 3635 * The IPW operates with six queues, one receive queue in the device's 3636 * sram, one transmit queue for sending commands to the device firmware, 3637 * and four transmit queues for data. 3638 * 3639 * The four transmit queues allow for performing quality of service (qos) 3640 * transmissions as per the 802.11 protocol. Currently Linux does not 3641 * provide a mechanism to the user for utilizing prioritized queues, so 3642 * we only utilize the first data transmit queue (queue1). 3643 */ 3644 3645 /* 3646 * Driver allocates buffers of this size for Rx 3647 */ 3648 3649 /* 3650 * ipw_rx_queue_space - Return number of free slots available in queue. 3651 */ 3652 static int ipw_rx_queue_space(const struct ipw_rx_queue *q) 3653 { 3654 int s = q->read - q->write; 3655 if (s <= 0) 3656 s += RX_QUEUE_SIZE; 3657 /* keep some buffer to not confuse full and empty queue */ 3658 s -= 2; 3659 if (s < 0) 3660 s = 0; 3661 return s; 3662 } 3663 3664 static inline int ipw_tx_queue_space(const struct clx2_queue *q) 3665 { 3666 int s = q->last_used - q->first_empty; 3667 if (s <= 0) 3668 s += q->n_bd; 3669 s -= 2; /* keep some reserve to not confuse empty and full situations */ 3670 if (s < 0) 3671 s = 0; 3672 return s; 3673 } 3674 3675 static inline int ipw_queue_inc_wrap(int index, int n_bd) 3676 { 3677 return (++index == n_bd) ? 0 : index; 3678 } 3679 3680 /* 3681 * Initialize common DMA queue structure 3682 * 3683 * @param q queue to init 3684 * @param count Number of BD's to allocate. Should be power of 2 3685 * @param read_register Address for 'read' register 3686 * (not offset within BAR, full address) 3687 * @param write_register Address for 'write' register 3688 * (not offset within BAR, full address) 3689 * @param base_register Address for 'base' register 3690 * (not offset within BAR, full address) 3691 * @param size Address for 'size' register 3692 * (not offset within BAR, full address) 3693 */ 3694 static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q, 3695 int count, u32 read, u32 write, u32 base, u32 size) 3696 { 3697 q->n_bd = count; 3698 3699 q->low_mark = q->n_bd / 4; 3700 if (q->low_mark < 4) 3701 q->low_mark = 4; 3702 3703 q->high_mark = q->n_bd / 8; 3704 if (q->high_mark < 2) 3705 q->high_mark = 2; 3706 3707 q->first_empty = q->last_used = 0; 3708 q->reg_r = read; 3709 q->reg_w = write; 3710 3711 ipw_write32(priv, base, q->dma_addr); 3712 ipw_write32(priv, size, count); 3713 ipw_write32(priv, read, 0); 3714 ipw_write32(priv, write, 0); 3715 3716 _ipw_read32(priv, 0x90); 3717 } 3718 3719 static int ipw_queue_tx_init(struct ipw_priv *priv, 3720 struct clx2_tx_queue *q, 3721 int count, u32 read, u32 write, u32 base, u32 size) 3722 { 3723 struct pci_dev *dev = priv->pci_dev; 3724 3725 q->txb = kmalloc_objs(q->txb[0], count); 3726 if (!q->txb) 3727 return -ENOMEM; 3728 3729 q->bd = 3730 dma_alloc_coherent(&dev->dev, sizeof(q->bd[0]) * count, 3731 &q->q.dma_addr, GFP_KERNEL); 3732 if (!q->bd) { 3733 IPW_ERROR("dma_alloc_coherent(%zd) failed\n", 3734 sizeof(q->bd[0]) * count); 3735 kfree(q->txb); 3736 q->txb = NULL; 3737 return -ENOMEM; 3738 } 3739 3740 ipw_queue_init(priv, &q->q, count, read, write, base, size); 3741 return 0; 3742 } 3743 3744 /* 3745 * Free one TFD, those at index [txq->q.last_used]. 3746 * Do NOT advance any indexes 3747 * 3748 * @param dev 3749 * @param txq 3750 */ 3751 static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, 3752 struct clx2_tx_queue *txq) 3753 { 3754 struct tfd_frame *bd = &txq->bd[txq->q.last_used]; 3755 struct pci_dev *dev = priv->pci_dev; 3756 int i; 3757 3758 /* classify bd */ 3759 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) 3760 /* nothing to cleanup after for host commands */ 3761 return; 3762 3763 /* sanity check */ 3764 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { 3765 IPW_ERROR("Too many chunks: %i\n", 3766 le32_to_cpu(bd->u.data.num_chunks)); 3767 /* @todo issue fatal error, it is quite serious situation */ 3768 return; 3769 } 3770 3771 /* unmap chunks if any */ 3772 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { 3773 dma_unmap_single(&dev->dev, 3774 le32_to_cpu(bd->u.data.chunk_ptr[i]), 3775 le16_to_cpu(bd->u.data.chunk_len[i]), 3776 DMA_TO_DEVICE); 3777 if (txq->txb[txq->q.last_used]) { 3778 libipw_txb_free(txq->txb[txq->q.last_used]); 3779 txq->txb[txq->q.last_used] = NULL; 3780 } 3781 } 3782 } 3783 3784 /* 3785 * Deallocate DMA queue. 3786 * 3787 * Empty queue by removing and destroying all BD's. 3788 * Free all buffers. 3789 * 3790 * @param dev 3791 * @param q 3792 */ 3793 static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq) 3794 { 3795 struct clx2_queue *q = &txq->q; 3796 struct pci_dev *dev = priv->pci_dev; 3797 3798 if (q->n_bd == 0) 3799 return; 3800 3801 /* first, empty all BD's */ 3802 for (; q->first_empty != q->last_used; 3803 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { 3804 ipw_queue_tx_free_tfd(priv, txq); 3805 } 3806 3807 /* free buffers belonging to queue itself */ 3808 dma_free_coherent(&dev->dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd, 3809 q->dma_addr); 3810 kfree(txq->txb); 3811 3812 /* 0 fill whole structure */ 3813 memset(txq, 0, sizeof(*txq)); 3814 } 3815 3816 /* 3817 * Destroy all DMA queues and structures 3818 * 3819 * @param priv 3820 */ 3821 static void ipw_tx_queue_free(struct ipw_priv *priv) 3822 { 3823 /* Tx CMD queue */ 3824 ipw_queue_tx_free(priv, &priv->txq_cmd); 3825 3826 /* Tx queues */ 3827 ipw_queue_tx_free(priv, &priv->txq[0]); 3828 ipw_queue_tx_free(priv, &priv->txq[1]); 3829 ipw_queue_tx_free(priv, &priv->txq[2]); 3830 ipw_queue_tx_free(priv, &priv->txq[3]); 3831 } 3832 3833 static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) 3834 { 3835 /* First 3 bytes are manufacturer */ 3836 bssid[0] = priv->mac_addr[0]; 3837 bssid[1] = priv->mac_addr[1]; 3838 bssid[2] = priv->mac_addr[2]; 3839 3840 /* Last bytes are random */ 3841 get_random_bytes(&bssid[3], ETH_ALEN - 3); 3842 3843 bssid[0] &= 0xfe; /* clear multicast bit */ 3844 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ 3845 } 3846 3847 static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) 3848 { 3849 struct ipw_station_entry entry; 3850 int i; 3851 3852 for (i = 0; i < priv->num_stations; i++) { 3853 if (ether_addr_equal(priv->stations[i], bssid)) { 3854 /* Another node is active in network */ 3855 priv->missed_adhoc_beacons = 0; 3856 if (!(priv->config & CFG_STATIC_CHANNEL)) 3857 /* when other nodes drop out, we drop out */ 3858 priv->config &= ~CFG_ADHOC_PERSIST; 3859 3860 return i; 3861 } 3862 } 3863 3864 if (i == MAX_STATIONS) 3865 return IPW_INVALID_STATION; 3866 3867 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid); 3868 3869 entry.reserved = 0; 3870 entry.support_mode = 0; 3871 memcpy(entry.mac_addr, bssid, ETH_ALEN); 3872 memcpy(priv->stations[i], bssid, ETH_ALEN); 3873 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), 3874 &entry, sizeof(entry)); 3875 priv->num_stations++; 3876 3877 return i; 3878 } 3879 3880 static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) 3881 { 3882 int i; 3883 3884 for (i = 0; i < priv->num_stations; i++) 3885 if (ether_addr_equal(priv->stations[i], bssid)) 3886 return i; 3887 3888 return IPW_INVALID_STATION; 3889 } 3890 3891 static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) 3892 { 3893 int err; 3894 3895 if (priv->status & STATUS_ASSOCIATING) { 3896 IPW_DEBUG_ASSOC("Disassociating while associating.\n"); 3897 schedule_work(&priv->disassociate); 3898 return; 3899 } 3900 3901 if (!(priv->status & STATUS_ASSOCIATED)) { 3902 IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); 3903 return; 3904 } 3905 3906 IPW_DEBUG_ASSOC("Disassociation attempt from %pM " 3907 "on channel %d.\n", 3908 priv->assoc_request.bssid, 3909 priv->assoc_request.channel); 3910 3911 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); 3912 priv->status |= STATUS_DISASSOCIATING; 3913 3914 if (quiet) 3915 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; 3916 else 3917 priv->assoc_request.assoc_type = HC_DISASSOCIATE; 3918 3919 err = ipw_send_associate(priv, &priv->assoc_request); 3920 if (err) { 3921 IPW_DEBUG_HC("Attempt to send [dis]associate command " 3922 "failed.\n"); 3923 return; 3924 } 3925 3926 } 3927 3928 static int ipw_disassociate(void *data) 3929 { 3930 struct ipw_priv *priv = data; 3931 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) 3932 return 0; 3933 ipw_send_disassociate(data, 0); 3934 netif_carrier_off(priv->net_dev); 3935 return 1; 3936 } 3937 3938 static void ipw_bg_disassociate(struct work_struct *work) 3939 { 3940 struct ipw_priv *priv = 3941 container_of(work, struct ipw_priv, disassociate); 3942 mutex_lock(&priv->mutex); 3943 ipw_disassociate(priv); 3944 mutex_unlock(&priv->mutex); 3945 } 3946 3947 static void ipw_system_config(struct work_struct *work) 3948 { 3949 struct ipw_priv *priv = 3950 container_of(work, struct ipw_priv, system_config); 3951 3952 #ifdef CONFIG_IPW2200_PROMISCUOUS 3953 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { 3954 priv->sys_config.accept_all_data_frames = 1; 3955 priv->sys_config.accept_non_directed_frames = 1; 3956 priv->sys_config.accept_all_mgmt_bcpr = 1; 3957 priv->sys_config.accept_all_mgmt_frames = 1; 3958 } 3959 #endif 3960 3961 ipw_send_system_config(priv); 3962 } 3963 3964 struct ipw_status_code { 3965 u16 status; 3966 const char *reason; 3967 }; 3968 3969 static const struct ipw_status_code ipw_status_codes[] = { 3970 {0x00, "Successful"}, 3971 {0x01, "Unspecified failure"}, 3972 {0x0A, "Cannot support all requested capabilities in the " 3973 "Capability information field"}, 3974 {0x0B, "Reassociation denied due to inability to confirm that " 3975 "association exists"}, 3976 {0x0C, "Association denied due to reason outside the scope of this " 3977 "standard"}, 3978 {0x0D, 3979 "Responding station does not support the specified authentication " 3980 "algorithm"}, 3981 {0x0E, 3982 "Received an Authentication frame with authentication sequence " 3983 "transaction sequence number out of expected sequence"}, 3984 {0x0F, "Authentication rejected because of challenge failure"}, 3985 {0x10, "Authentication rejected due to timeout waiting for next " 3986 "frame in sequence"}, 3987 {0x11, "Association denied because AP is unable to handle additional " 3988 "associated stations"}, 3989 {0x12, 3990 "Association denied due to requesting station not supporting all " 3991 "of the datarates in the BSSBasicServiceSet Parameter"}, 3992 {0x13, 3993 "Association denied due to requesting station not supporting " 3994 "short preamble operation"}, 3995 {0x14, 3996 "Association denied due to requesting station not supporting " 3997 "PBCC encoding"}, 3998 {0x15, 3999 "Association denied due to requesting station not supporting " 4000 "channel agility"}, 4001 {0x19, 4002 "Association denied due to requesting station not supporting " 4003 "short slot operation"}, 4004 {0x1A, 4005 "Association denied due to requesting station not supporting " 4006 "DSSS-OFDM operation"}, 4007 {0x28, "Invalid Information Element"}, 4008 {0x29, "Group Cipher is not valid"}, 4009 {0x2A, "Pairwise Cipher is not valid"}, 4010 {0x2B, "AKMP is not valid"}, 4011 {0x2C, "Unsupported RSN IE version"}, 4012 {0x2D, "Invalid RSN IE Capabilities"}, 4013 {0x2E, "Cipher suite is rejected per security policy"}, 4014 }; 4015 4016 static const char *ipw_get_status_code(u16 status) 4017 { 4018 int i; 4019 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) 4020 if (ipw_status_codes[i].status == (status & 0xff)) 4021 return ipw_status_codes[i].reason; 4022 return "Unknown status value."; 4023 } 4024 4025 static inline void average_init(struct average *avg) 4026 { 4027 memset(avg, 0, sizeof(*avg)); 4028 } 4029 4030 #define DEPTH_RSSI 8 4031 #define DEPTH_NOISE 16 4032 static s16 exponential_average(s16 prev_avg, s16 val, u8 depth) 4033 { 4034 return ((depth-1)*prev_avg + val)/depth; 4035 } 4036 4037 static void average_add(struct average *avg, s16 val) 4038 { 4039 avg->sum -= avg->entries[avg->pos]; 4040 avg->sum += val; 4041 avg->entries[avg->pos++] = val; 4042 if (unlikely(avg->pos == AVG_ENTRIES)) { 4043 avg->init = 1; 4044 avg->pos = 0; 4045 } 4046 } 4047 4048 static s16 average_value(struct average *avg) 4049 { 4050 if (!unlikely(avg->init)) { 4051 if (avg->pos) 4052 return avg->sum / avg->pos; 4053 return 0; 4054 } 4055 4056 return avg->sum / AVG_ENTRIES; 4057 } 4058 4059 static void ipw_reset_stats(struct ipw_priv *priv) 4060 { 4061 u32 len = sizeof(u32); 4062 4063 priv->quality = 0; 4064 4065 average_init(&priv->average_missed_beacons); 4066 priv->exp_avg_rssi = -60; 4067 priv->exp_avg_noise = -85 + 0x100; 4068 4069 priv->last_rate = 0; 4070 priv->last_missed_beacons = 0; 4071 priv->last_rx_packets = 0; 4072 priv->last_tx_packets = 0; 4073 priv->last_tx_failures = 0; 4074 4075 /* Firmware managed, reset only when NIC is restarted, so we have to 4076 * normalize on the current value */ 4077 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, 4078 &priv->last_rx_err, &len); 4079 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, 4080 &priv->last_tx_failures, &len); 4081 4082 /* Driver managed, reset with each association */ 4083 priv->missed_adhoc_beacons = 0; 4084 priv->missed_beacons = 0; 4085 priv->tx_packets = 0; 4086 priv->rx_packets = 0; 4087 4088 } 4089 4090 static u32 ipw_get_max_rate(struct ipw_priv *priv) 4091 { 4092 u32 i = 0x80000000; 4093 u32 mask = priv->rates_mask; 4094 /* If currently associated in B mode, restrict the maximum 4095 * rate match to B rates */ 4096 if (priv->assoc_request.ieee_mode == IPW_B_MODE) 4097 mask &= LIBIPW_CCK_RATES_MASK; 4098 4099 /* TODO: Verify that the rate is supported by the current rates 4100 * list. */ 4101 4102 while (i && !(mask & i)) 4103 i >>= 1; 4104 switch (i) { 4105 case LIBIPW_CCK_RATE_1MB_MASK: 4106 return 1000000; 4107 case LIBIPW_CCK_RATE_2MB_MASK: 4108 return 2000000; 4109 case LIBIPW_CCK_RATE_5MB_MASK: 4110 return 5500000; 4111 case LIBIPW_OFDM_RATE_6MB_MASK: 4112 return 6000000; 4113 case LIBIPW_OFDM_RATE_9MB_MASK: 4114 return 9000000; 4115 case LIBIPW_CCK_RATE_11MB_MASK: 4116 return 11000000; 4117 case LIBIPW_OFDM_RATE_12MB_MASK: 4118 return 12000000; 4119 case LIBIPW_OFDM_RATE_18MB_MASK: 4120 return 18000000; 4121 case LIBIPW_OFDM_RATE_24MB_MASK: 4122 return 24000000; 4123 case LIBIPW_OFDM_RATE_36MB_MASK: 4124 return 36000000; 4125 case LIBIPW_OFDM_RATE_48MB_MASK: 4126 return 48000000; 4127 case LIBIPW_OFDM_RATE_54MB_MASK: 4128 return 54000000; 4129 } 4130 4131 if (priv->ieee->mode == IEEE_B) 4132 return 11000000; 4133 else 4134 return 54000000; 4135 } 4136 4137 static u32 ipw_get_current_rate(struct ipw_priv *priv) 4138 { 4139 u32 rate, len = sizeof(rate); 4140 int err; 4141 4142 if (!(priv->status & STATUS_ASSOCIATED)) 4143 return 0; 4144 4145 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { 4146 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, 4147 &len); 4148 if (err) { 4149 IPW_DEBUG_INFO("failed querying ordinals.\n"); 4150 return 0; 4151 } 4152 } else 4153 return ipw_get_max_rate(priv); 4154 4155 switch (rate) { 4156 case IPW_TX_RATE_1MB: 4157 return 1000000; 4158 case IPW_TX_RATE_2MB: 4159 return 2000000; 4160 case IPW_TX_RATE_5MB: 4161 return 5500000; 4162 case IPW_TX_RATE_6MB: 4163 return 6000000; 4164 case IPW_TX_RATE_9MB: 4165 return 9000000; 4166 case IPW_TX_RATE_11MB: 4167 return 11000000; 4168 case IPW_TX_RATE_12MB: 4169 return 12000000; 4170 case IPW_TX_RATE_18MB: 4171 return 18000000; 4172 case IPW_TX_RATE_24MB: 4173 return 24000000; 4174 case IPW_TX_RATE_36MB: 4175 return 36000000; 4176 case IPW_TX_RATE_48MB: 4177 return 48000000; 4178 case IPW_TX_RATE_54MB: 4179 return 54000000; 4180 } 4181 4182 return 0; 4183 } 4184 4185 #define IPW_STATS_INTERVAL (2 * HZ) 4186 static void ipw_gather_stats(struct ipw_priv *priv) 4187 { 4188 u32 rx_err, rx_err_delta, rx_packets_delta; 4189 u32 tx_failures, tx_failures_delta, tx_packets_delta; 4190 u32 missed_beacons_percent, missed_beacons_delta; 4191 u32 quality = 0; 4192 u32 len = sizeof(u32); 4193 s16 rssi; 4194 u32 beacon_quality, signal_quality, tx_quality, rx_quality, 4195 rate_quality; 4196 u32 max_rate; 4197 4198 if (!(priv->status & STATUS_ASSOCIATED)) { 4199 priv->quality = 0; 4200 return; 4201 } 4202 4203 /* Update the statistics */ 4204 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, 4205 &priv->missed_beacons, &len); 4206 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; 4207 priv->last_missed_beacons = priv->missed_beacons; 4208 if (priv->assoc_request.beacon_interval) { 4209 missed_beacons_percent = missed_beacons_delta * 4210 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) / 4211 (IPW_STATS_INTERVAL * 10); 4212 } else { 4213 missed_beacons_percent = 0; 4214 } 4215 average_add(&priv->average_missed_beacons, missed_beacons_percent); 4216 4217 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); 4218 rx_err_delta = rx_err - priv->last_rx_err; 4219 priv->last_rx_err = rx_err; 4220 4221 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); 4222 tx_failures_delta = tx_failures - priv->last_tx_failures; 4223 priv->last_tx_failures = tx_failures; 4224 4225 rx_packets_delta = priv->rx_packets - priv->last_rx_packets; 4226 priv->last_rx_packets = priv->rx_packets; 4227 4228 tx_packets_delta = priv->tx_packets - priv->last_tx_packets; 4229 priv->last_tx_packets = priv->tx_packets; 4230 4231 /* Calculate quality based on the following: 4232 * 4233 * Missed beacon: 100% = 0, 0% = 70% missed 4234 * Rate: 60% = 1Mbs, 100% = Max 4235 * Rx and Tx errors represent a straight % of total Rx/Tx 4236 * RSSI: 100% = > -50, 0% = < -80 4237 * Rx errors: 100% = 0, 0% = 50% missed 4238 * 4239 * The lowest computed quality is used. 4240 * 4241 */ 4242 #define BEACON_THRESHOLD 5 4243 beacon_quality = 100 - missed_beacons_percent; 4244 if (beacon_quality < BEACON_THRESHOLD) 4245 beacon_quality = 0; 4246 else 4247 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / 4248 (100 - BEACON_THRESHOLD); 4249 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", 4250 beacon_quality, missed_beacons_percent); 4251 4252 priv->last_rate = ipw_get_current_rate(priv); 4253 max_rate = ipw_get_max_rate(priv); 4254 rate_quality = priv->last_rate * 40 / max_rate + 60; 4255 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", 4256 rate_quality, priv->last_rate / 1000000); 4257 4258 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) 4259 rx_quality = 100 - (rx_err_delta * 100) / 4260 (rx_packets_delta + rx_err_delta); 4261 else 4262 rx_quality = 100; 4263 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", 4264 rx_quality, rx_err_delta, rx_packets_delta); 4265 4266 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) 4267 tx_quality = 100 - (tx_failures_delta * 100) / 4268 (tx_packets_delta + tx_failures_delta); 4269 else 4270 tx_quality = 100; 4271 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", 4272 tx_quality, tx_failures_delta, tx_packets_delta); 4273 4274 rssi = priv->exp_avg_rssi; 4275 signal_quality = 4276 (100 * 4277 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * 4278 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - 4279 (priv->ieee->perfect_rssi - rssi) * 4280 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + 4281 62 * (priv->ieee->perfect_rssi - rssi))) / 4282 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * 4283 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); 4284 if (signal_quality > 100) 4285 signal_quality = 100; 4286 else if (signal_quality < 1) 4287 signal_quality = 0; 4288 4289 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", 4290 signal_quality, rssi); 4291 4292 quality = min(rx_quality, signal_quality); 4293 quality = min(tx_quality, quality); 4294 quality = min(rate_quality, quality); 4295 quality = min(beacon_quality, quality); 4296 if (quality == beacon_quality) 4297 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", 4298 quality); 4299 if (quality == rate_quality) 4300 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", 4301 quality); 4302 if (quality == tx_quality) 4303 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", 4304 quality); 4305 if (quality == rx_quality) 4306 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", 4307 quality); 4308 if (quality == signal_quality) 4309 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", 4310 quality); 4311 4312 priv->quality = quality; 4313 4314 schedule_delayed_work(&priv->gather_stats, IPW_STATS_INTERVAL); 4315 } 4316 4317 static void ipw_bg_gather_stats(struct work_struct *work) 4318 { 4319 struct ipw_priv *priv = 4320 container_of(work, struct ipw_priv, gather_stats.work); 4321 mutex_lock(&priv->mutex); 4322 ipw_gather_stats(priv); 4323 mutex_unlock(&priv->mutex); 4324 } 4325 4326 /* Missed beacon behavior: 4327 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. 4328 * roaming_threshold -> disassociate_threshold, scan and roam for better signal. 4329 * Above disassociate threshold, give up and stop scanning. 4330 * Roaming is disabled if disassociate_threshold <= roaming_threshold */ 4331 static void ipw_handle_missed_beacon(struct ipw_priv *priv, 4332 int missed_count) 4333 { 4334 priv->notif_missed_beacons = missed_count; 4335 4336 if (missed_count > priv->disassociate_threshold && 4337 priv->status & STATUS_ASSOCIATED) { 4338 /* If associated and we've hit the missed 4339 * beacon threshold, disassociate, turn 4340 * off roaming, and abort any active scans */ 4341 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | 4342 IPW_DL_STATE | IPW_DL_ASSOC, 4343 "Missed beacon: %d - disassociate\n", missed_count); 4344 priv->status &= ~STATUS_ROAMING; 4345 if (priv->status & STATUS_SCANNING) { 4346 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | 4347 IPW_DL_STATE, 4348 "Aborting scan with missed beacon.\n"); 4349 schedule_work(&priv->abort_scan); 4350 } 4351 4352 schedule_work(&priv->disassociate); 4353 return; 4354 } 4355 4356 if (priv->status & STATUS_ROAMING) { 4357 /* If we are currently roaming, then just 4358 * print a debug statement... */ 4359 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, 4360 "Missed beacon: %d - roam in progress\n", 4361 missed_count); 4362 return; 4363 } 4364 4365 if (roaming && 4366 (missed_count > priv->roaming_threshold && 4367 missed_count <= priv->disassociate_threshold)) { 4368 /* If we are not already roaming, set the ROAM 4369 * bit in the status and kick off a scan. 4370 * This can happen several times before we reach 4371 * disassociate_threshold. */ 4372 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, 4373 "Missed beacon: %d - initiate " 4374 "roaming\n", missed_count); 4375 if (!(priv->status & STATUS_ROAMING)) { 4376 priv->status |= STATUS_ROAMING; 4377 if (!(priv->status & STATUS_SCANNING)) 4378 schedule_delayed_work(&priv->request_scan, 0); 4379 } 4380 return; 4381 } 4382 4383 if (priv->status & STATUS_SCANNING && 4384 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) { 4385 /* Stop scan to keep fw from getting 4386 * stuck (only if we aren't roaming -- 4387 * otherwise we'll never scan more than 2 or 3 4388 * channels..) */ 4389 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, 4390 "Aborting scan with missed beacon.\n"); 4391 schedule_work(&priv->abort_scan); 4392 } 4393 4394 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); 4395 } 4396 4397 static void ipw_scan_event(struct work_struct *work) 4398 { 4399 union iwreq_data wrqu; 4400 4401 struct ipw_priv *priv = 4402 container_of(work, struct ipw_priv, scan_event.work); 4403 4404 wrqu.data.length = 0; 4405 wrqu.data.flags = 0; 4406 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); 4407 } 4408 4409 static void handle_scan_event(struct ipw_priv *priv) 4410 { 4411 /* Only userspace-requested scan completion events go out immediately */ 4412 if (!priv->user_requested_scan) { 4413 schedule_delayed_work(&priv->scan_event, 4414 round_jiffies_relative(msecs_to_jiffies(4000))); 4415 } else { 4416 priv->user_requested_scan = 0; 4417 mod_delayed_work(system_percpu_wq, &priv->scan_event, 0); 4418 } 4419 } 4420 4421 /* 4422 * Handle host notification packet. 4423 * Called from interrupt routine 4424 */ 4425 static void ipw_rx_notification(struct ipw_priv *priv, 4426 struct ipw_rx_notification *notif) 4427 { 4428 u16 size = le16_to_cpu(notif->size); 4429 4430 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size); 4431 4432 switch (notif->subtype) { 4433 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ 4434 struct notif_association *assoc = ¬if->u.assoc; 4435 4436 switch (assoc->state) { 4437 case CMAS_ASSOCIATED:{ 4438 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4439 IPW_DL_ASSOC, 4440 "associated: '%*pE' %pM\n", 4441 priv->essid_len, priv->essid, 4442 priv->bssid); 4443 4444 switch (priv->ieee->iw_mode) { 4445 case IW_MODE_INFRA: 4446 memcpy(priv->ieee->bssid, 4447 priv->bssid, ETH_ALEN); 4448 break; 4449 4450 case IW_MODE_ADHOC: 4451 memcpy(priv->ieee->bssid, 4452 priv->bssid, ETH_ALEN); 4453 4454 /* clear out the station table */ 4455 priv->num_stations = 0; 4456 4457 IPW_DEBUG_ASSOC 4458 ("queueing adhoc check\n"); 4459 schedule_delayed_work( 4460 &priv->adhoc_check, 4461 le16_to_cpu(priv-> 4462 assoc_request. 4463 beacon_interval)); 4464 break; 4465 } 4466 4467 priv->status &= ~STATUS_ASSOCIATING; 4468 priv->status |= STATUS_ASSOCIATED; 4469 schedule_work(&priv->system_config); 4470 4471 #ifdef CONFIG_IPW2200_QOS 4472 #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ 4473 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control)) 4474 if ((priv->status & STATUS_AUTH) && 4475 (IPW_GET_PACKET_STYPE(¬if->u.raw) 4476 == IEEE80211_STYPE_ASSOC_RESP)) { 4477 if ((sizeof 4478 (struct 4479 libipw_assoc_response) 4480 <= size) 4481 && (size <= 2314)) { 4482 struct 4483 libipw_rx_stats 4484 stats = { 4485 .len = size - 1, 4486 }; 4487 4488 IPW_DEBUG_QOS 4489 ("QoS Associate " 4490 "size %d\n", size); 4491 libipw_rx_mgt(priv-> 4492 ieee, 4493 (struct 4494 libipw_hdr_4addr 4495 *) 4496 ¬if->u.raw, &stats); 4497 } 4498 } 4499 #endif 4500 4501 schedule_work(&priv->link_up); 4502 4503 break; 4504 } 4505 4506 case CMAS_AUTHENTICATED:{ 4507 if (priv-> 4508 status & (STATUS_ASSOCIATED | 4509 STATUS_AUTH)) { 4510 struct notif_authenticate *auth 4511 = ¬if->u.auth; 4512 IPW_DEBUG(IPW_DL_NOTIF | 4513 IPW_DL_STATE | 4514 IPW_DL_ASSOC, 4515 "deauthenticated: '%*pE' %pM: (0x%04X) - %s\n", 4516 priv->essid_len, 4517 priv->essid, 4518 priv->bssid, 4519 le16_to_cpu(auth->status), 4520 ipw_get_status_code 4521 (le16_to_cpu 4522 (auth->status))); 4523 4524 priv->status &= 4525 ~(STATUS_ASSOCIATING | 4526 STATUS_AUTH | 4527 STATUS_ASSOCIATED); 4528 4529 schedule_work(&priv->link_down); 4530 break; 4531 } 4532 4533 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4534 IPW_DL_ASSOC, 4535 "authenticated: '%*pE' %pM\n", 4536 priv->essid_len, priv->essid, 4537 priv->bssid); 4538 break; 4539 } 4540 4541 case CMAS_INIT:{ 4542 if (priv->status & STATUS_AUTH) { 4543 struct 4544 libipw_assoc_response 4545 *resp; 4546 resp = 4547 (struct 4548 libipw_assoc_response 4549 *)¬if->u.raw; 4550 IPW_DEBUG(IPW_DL_NOTIF | 4551 IPW_DL_STATE | 4552 IPW_DL_ASSOC, 4553 "association failed (0x%04X): %s\n", 4554 le16_to_cpu(resp->status), 4555 ipw_get_status_code 4556 (le16_to_cpu 4557 (resp->status))); 4558 } 4559 4560 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4561 IPW_DL_ASSOC, 4562 "disassociated: '%*pE' %pM\n", 4563 priv->essid_len, priv->essid, 4564 priv->bssid); 4565 4566 priv->status &= 4567 ~(STATUS_DISASSOCIATING | 4568 STATUS_ASSOCIATING | 4569 STATUS_ASSOCIATED | STATUS_AUTH); 4570 if (priv->assoc_network 4571 && (priv->assoc_network-> 4572 capability & 4573 WLAN_CAPABILITY_IBSS)) 4574 ipw_remove_current_network 4575 (priv); 4576 4577 schedule_work(&priv->link_down); 4578 4579 break; 4580 } 4581 4582 case CMAS_RX_ASSOC_RESP: 4583 break; 4584 4585 default: 4586 IPW_ERROR("assoc: unknown (%d)\n", 4587 assoc->state); 4588 break; 4589 } 4590 4591 break; 4592 } 4593 4594 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ 4595 struct notif_authenticate *auth = ¬if->u.auth; 4596 switch (auth->state) { 4597 case CMAS_AUTHENTICATED: 4598 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, 4599 "authenticated: '%*pE' %pM\n", 4600 priv->essid_len, priv->essid, 4601 priv->bssid); 4602 priv->status |= STATUS_AUTH; 4603 break; 4604 4605 case CMAS_INIT: 4606 if (priv->status & STATUS_AUTH) { 4607 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4608 IPW_DL_ASSOC, 4609 "authentication failed (0x%04X): %s\n", 4610 le16_to_cpu(auth->status), 4611 ipw_get_status_code(le16_to_cpu 4612 (auth-> 4613 status))); 4614 } 4615 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4616 IPW_DL_ASSOC, 4617 "deauthenticated: '%*pE' %pM\n", 4618 priv->essid_len, priv->essid, 4619 priv->bssid); 4620 4621 priv->status &= ~(STATUS_ASSOCIATING | 4622 STATUS_AUTH | 4623 STATUS_ASSOCIATED); 4624 4625 schedule_work(&priv->link_down); 4626 break; 4627 4628 case CMAS_TX_AUTH_SEQ_1: 4629 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4630 IPW_DL_ASSOC, "AUTH_SEQ_1\n"); 4631 break; 4632 case CMAS_RX_AUTH_SEQ_2: 4633 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4634 IPW_DL_ASSOC, "AUTH_SEQ_2\n"); 4635 break; 4636 case CMAS_AUTH_SEQ_1_PASS: 4637 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4638 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); 4639 break; 4640 case CMAS_AUTH_SEQ_1_FAIL: 4641 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4642 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); 4643 break; 4644 case CMAS_TX_AUTH_SEQ_3: 4645 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4646 IPW_DL_ASSOC, "AUTH_SEQ_3\n"); 4647 break; 4648 case CMAS_RX_AUTH_SEQ_4: 4649 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4650 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); 4651 break; 4652 case CMAS_AUTH_SEQ_2_PASS: 4653 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4654 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); 4655 break; 4656 case CMAS_AUTH_SEQ_2_FAIL: 4657 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4658 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); 4659 break; 4660 case CMAS_TX_ASSOC: 4661 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4662 IPW_DL_ASSOC, "TX_ASSOC\n"); 4663 break; 4664 case CMAS_RX_ASSOC_RESP: 4665 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4666 IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); 4667 4668 break; 4669 case CMAS_ASSOCIATED: 4670 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4671 IPW_DL_ASSOC, "ASSOCIATED\n"); 4672 break; 4673 default: 4674 IPW_DEBUG_NOTIF("auth: failure - %d\n", 4675 auth->state); 4676 break; 4677 } 4678 break; 4679 } 4680 4681 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ 4682 struct notif_channel_result *x = 4683 ¬if->u.channel_result; 4684 4685 if (size == sizeof(*x)) { 4686 IPW_DEBUG_SCAN("Scan result for channel %d\n", 4687 x->channel_num); 4688 } else { 4689 IPW_DEBUG_SCAN("Scan result of wrong size %d " 4690 "(should be %zd)\n", 4691 size, sizeof(*x)); 4692 } 4693 break; 4694 } 4695 4696 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ 4697 struct notif_scan_complete *x = ¬if->u.scan_complete; 4698 if (size == sizeof(*x)) { 4699 IPW_DEBUG_SCAN 4700 ("Scan completed: type %d, %d channels, " 4701 "%d status\n", x->scan_type, 4702 x->num_channels, x->status); 4703 } else { 4704 IPW_ERROR("Scan completed of wrong size %d " 4705 "(should be %zd)\n", 4706 size, sizeof(*x)); 4707 } 4708 4709 priv->status &= 4710 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); 4711 4712 wake_up_interruptible(&priv->wait_state); 4713 cancel_delayed_work(&priv->scan_check); 4714 4715 if (priv->status & STATUS_EXIT_PENDING) 4716 break; 4717 4718 priv->ieee->scans++; 4719 4720 #ifdef CONFIG_IPW2200_MONITOR 4721 if (priv->ieee->iw_mode == IW_MODE_MONITOR) { 4722 priv->status |= STATUS_SCAN_FORCED; 4723 schedule_delayed_work(&priv->request_scan, 0); 4724 break; 4725 } 4726 priv->status &= ~STATUS_SCAN_FORCED; 4727 #endif /* CONFIG_IPW2200_MONITOR */ 4728 4729 /* Do queued direct scans first */ 4730 if (priv->status & STATUS_DIRECT_SCAN_PENDING) 4731 schedule_delayed_work(&priv->request_direct_scan, 0); 4732 4733 if (!(priv->status & (STATUS_ASSOCIATED | 4734 STATUS_ASSOCIATING | 4735 STATUS_ROAMING | 4736 STATUS_DISASSOCIATING))) 4737 schedule_work(&priv->associate); 4738 else if (priv->status & STATUS_ROAMING) { 4739 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) 4740 /* If a scan completed and we are in roam mode, then 4741 * the scan that completed was the one requested as a 4742 * result of entering roam... so, schedule the 4743 * roam work */ 4744 schedule_work(&priv->roam); 4745 else 4746 /* Don't schedule if we aborted the scan */ 4747 priv->status &= ~STATUS_ROAMING; 4748 } else if (priv->status & STATUS_SCAN_PENDING) 4749 schedule_delayed_work(&priv->request_scan, 0); 4750 else if (priv->config & CFG_BACKGROUND_SCAN 4751 && priv->status & STATUS_ASSOCIATED) 4752 schedule_delayed_work(&priv->request_scan, 4753 round_jiffies_relative(HZ)); 4754 4755 /* Send an empty event to user space. 4756 * We don't send the received data on the event because 4757 * it would require us to do complex transcoding, and 4758 * we want to minimise the work done in the irq handler 4759 * Use a request to extract the data. 4760 * Also, we generate this even for any scan, regardless 4761 * on how the scan was initiated. User space can just 4762 * sync on periodic scan to get fresh data... 4763 * Jean II */ 4764 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) 4765 handle_scan_event(priv); 4766 break; 4767 } 4768 4769 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ 4770 struct notif_frag_length *x = ¬if->u.frag_len; 4771 4772 if (size == sizeof(*x)) 4773 IPW_ERROR("Frag length: %d\n", 4774 le16_to_cpu(x->frag_length)); 4775 else 4776 IPW_ERROR("Frag length of wrong size %d " 4777 "(should be %zd)\n", 4778 size, sizeof(*x)); 4779 break; 4780 } 4781 4782 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ 4783 struct notif_link_deterioration *x = 4784 ¬if->u.link_deterioration; 4785 4786 if (size == sizeof(*x)) { 4787 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, 4788 "link deterioration: type %d, cnt %d\n", 4789 x->silence_notification_type, 4790 x->silence_count); 4791 memcpy(&priv->last_link_deterioration, x, 4792 sizeof(*x)); 4793 } else { 4794 IPW_ERROR("Link Deterioration of wrong size %d " 4795 "(should be %zd)\n", 4796 size, sizeof(*x)); 4797 } 4798 break; 4799 } 4800 4801 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ 4802 IPW_ERROR("Dino config\n"); 4803 if (priv->hcmd 4804 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) 4805 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); 4806 4807 break; 4808 } 4809 4810 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ 4811 struct notif_beacon_state *x = ¬if->u.beacon_state; 4812 if (size != sizeof(*x)) { 4813 IPW_ERROR 4814 ("Beacon state of wrong size %d (should " 4815 "be %zd)\n", size, sizeof(*x)); 4816 break; 4817 } 4818 4819 if (le32_to_cpu(x->state) == 4820 HOST_NOTIFICATION_STATUS_BEACON_MISSING) 4821 ipw_handle_missed_beacon(priv, 4822 le32_to_cpu(x-> 4823 number)); 4824 4825 break; 4826 } 4827 4828 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ 4829 struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; 4830 if (size == sizeof(*x)) { 4831 IPW_ERROR("TGi Tx Key: state 0x%02x sec type " 4832 "0x%02x station %d\n", 4833 x->key_state, x->security_type, 4834 x->station_index); 4835 break; 4836 } 4837 4838 IPW_ERROR 4839 ("TGi Tx Key of wrong size %d (should be %zd)\n", 4840 size, sizeof(*x)); 4841 break; 4842 } 4843 4844 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ 4845 struct notif_calibration *x = ¬if->u.calibration; 4846 4847 if (size == sizeof(*x)) { 4848 memcpy(&priv->calib, x, sizeof(*x)); 4849 IPW_DEBUG_INFO("TODO: Calibration\n"); 4850 break; 4851 } 4852 4853 IPW_ERROR 4854 ("Calibration of wrong size %d (should be %zd)\n", 4855 size, sizeof(*x)); 4856 break; 4857 } 4858 4859 case HOST_NOTIFICATION_NOISE_STATS:{ 4860 if (size == sizeof(u32)) { 4861 priv->exp_avg_noise = 4862 exponential_average(priv->exp_avg_noise, 4863 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff), 4864 DEPTH_NOISE); 4865 break; 4866 } 4867 4868 IPW_ERROR 4869 ("Noise stat is wrong size %d (should be %zd)\n", 4870 size, sizeof(u32)); 4871 break; 4872 } 4873 4874 default: 4875 IPW_DEBUG_NOTIF("Unknown notification: " 4876 "subtype=%d,flags=0x%2x,size=%d\n", 4877 notif->subtype, notif->flags, size); 4878 } 4879 } 4880 4881 /* 4882 * Destroys all DMA structures and initialise them again 4883 * 4884 * @param priv 4885 * @return error code 4886 */ 4887 static int ipw_queue_reset(struct ipw_priv *priv) 4888 { 4889 int rc = 0; 4890 /* @todo customize queue sizes */ 4891 int nTx = 64, nTxCmd = 8; 4892 ipw_tx_queue_free(priv); 4893 /* Tx CMD queue */ 4894 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, 4895 IPW_TX_CMD_QUEUE_READ_INDEX, 4896 IPW_TX_CMD_QUEUE_WRITE_INDEX, 4897 IPW_TX_CMD_QUEUE_BD_BASE, 4898 IPW_TX_CMD_QUEUE_BD_SIZE); 4899 if (rc) { 4900 IPW_ERROR("Tx Cmd queue init failed\n"); 4901 goto error; 4902 } 4903 /* Tx queue(s) */ 4904 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, 4905 IPW_TX_QUEUE_0_READ_INDEX, 4906 IPW_TX_QUEUE_0_WRITE_INDEX, 4907 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); 4908 if (rc) { 4909 IPW_ERROR("Tx 0 queue init failed\n"); 4910 goto error; 4911 } 4912 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, 4913 IPW_TX_QUEUE_1_READ_INDEX, 4914 IPW_TX_QUEUE_1_WRITE_INDEX, 4915 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); 4916 if (rc) { 4917 IPW_ERROR("Tx 1 queue init failed\n"); 4918 goto error; 4919 } 4920 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, 4921 IPW_TX_QUEUE_2_READ_INDEX, 4922 IPW_TX_QUEUE_2_WRITE_INDEX, 4923 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); 4924 if (rc) { 4925 IPW_ERROR("Tx 2 queue init failed\n"); 4926 goto error; 4927 } 4928 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, 4929 IPW_TX_QUEUE_3_READ_INDEX, 4930 IPW_TX_QUEUE_3_WRITE_INDEX, 4931 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); 4932 if (rc) { 4933 IPW_ERROR("Tx 3 queue init failed\n"); 4934 goto error; 4935 } 4936 /* statistics */ 4937 priv->rx_bufs_min = 0; 4938 priv->rx_pend_max = 0; 4939 return rc; 4940 4941 error: 4942 ipw_tx_queue_free(priv); 4943 return rc; 4944 } 4945 4946 /* 4947 * Reclaim Tx queue entries no more used by NIC. 4948 * 4949 * When FW advances 'R' index, all entries between old and 4950 * new 'R' index need to be reclaimed. As result, some free space 4951 * forms. If there is enough free space (> low mark), wake Tx queue. 4952 * 4953 * @note Need to protect against garbage in 'R' index 4954 * @param priv 4955 * @param txq 4956 * @param qindex 4957 * @return Number of used entries remains in the queue 4958 */ 4959 static int ipw_queue_tx_reclaim(struct ipw_priv *priv, 4960 struct clx2_tx_queue *txq, int qindex) 4961 { 4962 u32 hw_tail; 4963 int used; 4964 struct clx2_queue *q = &txq->q; 4965 4966 hw_tail = ipw_read32(priv, q->reg_r); 4967 if (hw_tail >= q->n_bd) { 4968 IPW_ERROR 4969 ("Read index for DMA queue (%d) is out of range [0-%d)\n", 4970 hw_tail, q->n_bd); 4971 goto done; 4972 } 4973 for (; q->last_used != hw_tail; 4974 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { 4975 ipw_queue_tx_free_tfd(priv, txq); 4976 priv->tx_packets++; 4977 } 4978 done: 4979 if ((ipw_tx_queue_space(q) > q->low_mark) && 4980 (qindex >= 0)) 4981 netif_wake_queue(priv->net_dev); 4982 used = q->first_empty - q->last_used; 4983 if (used < 0) 4984 used += q->n_bd; 4985 4986 return used; 4987 } 4988 4989 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, const void *buf, 4990 int len, int sync) 4991 { 4992 struct clx2_tx_queue *txq = &priv->txq_cmd; 4993 struct clx2_queue *q = &txq->q; 4994 struct tfd_frame *tfd; 4995 4996 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) { 4997 IPW_ERROR("No space for Tx\n"); 4998 return -EBUSY; 4999 } 5000 5001 tfd = &txq->bd[q->first_empty]; 5002 txq->txb[q->first_empty] = NULL; 5003 5004 memset(tfd, 0, sizeof(*tfd)); 5005 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; 5006 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; 5007 priv->hcmd_seq++; 5008 tfd->u.cmd.index = hcmd; 5009 tfd->u.cmd.length = len; 5010 memcpy(tfd->u.cmd.payload, buf, len); 5011 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); 5012 ipw_write32(priv, q->reg_w, q->first_empty); 5013 _ipw_read32(priv, 0x90); 5014 5015 return 0; 5016 } 5017 5018 /* 5019 * Rx theory of operation 5020 * 5021 * The host allocates 32 DMA target addresses and passes the host address 5022 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is 5023 * 0 to 31 5024 * 5025 * Rx Queue Indexes 5026 * The host/firmware share two index registers for managing the Rx buffers. 5027 * 5028 * The READ index maps to the first position that the firmware may be writing 5029 * to -- the driver can read up to (but not including) this position and get 5030 * good data. 5031 * The READ index is managed by the firmware once the card is enabled. 5032 * 5033 * The WRITE index maps to the last position the driver has read from -- the 5034 * position preceding WRITE is the last slot the firmware can place a packet. 5035 * 5036 * The queue is empty (no good data) if WRITE = READ - 1, and is full if 5037 * WRITE = READ. 5038 * 5039 * During initialization the host sets up the READ queue position to the first 5040 * INDEX position, and WRITE to the last (READ - 1 wrapped) 5041 * 5042 * When the firmware places a packet in a buffer it will advance the READ index 5043 * and fire the RX interrupt. The driver can then query the READ index and 5044 * process as many packets as possible, moving the WRITE index forward as it 5045 * resets the Rx queue buffers with new memory. 5046 * 5047 * The management in the driver is as follows: 5048 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When 5049 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled 5050 * to replensish the ipw->rxq->rx_free. 5051 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the 5052 * ipw->rxq is replenished and the READ INDEX is updated (updating the 5053 * 'processed' and 'read' driver indexes as well) 5054 * + A received packet is processed and handed to the kernel network stack, 5055 * detached from the ipw->rxq. The driver 'processed' index is updated. 5056 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free 5057 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ 5058 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there 5059 * were enough free buffers and RX_STALLED is set it is cleared. 5060 * 5061 * 5062 * Driver sequence: 5063 * 5064 * ipw_rx_queue_alloc() Allocates rx_free 5065 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls 5066 * ipw_rx_queue_restock 5067 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx 5068 * queue, updates firmware pointers, and updates 5069 * the WRITE index. If insufficient rx_free buffers 5070 * are available, schedules ipw_rx_queue_replenish 5071 * 5072 * -- enable interrupts -- 5073 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the 5074 * READ INDEX, detaching the SKB from the pool. 5075 * Moves the packet buffer from queue to rx_used. 5076 * Calls ipw_rx_queue_restock to refill any empty 5077 * slots. 5078 * ... 5079 * 5080 */ 5081 5082 /* 5083 * If there are slots in the RX queue that need to be restocked, 5084 * and we have free pre-allocated buffers, fill the ranks as much 5085 * as we can pulling from rx_free. 5086 * 5087 * This moves the 'write' index forward to catch up with 'processed', and 5088 * also updates the memory address in the firmware to reference the new 5089 * target buffer. 5090 */ 5091 static void ipw_rx_queue_restock(struct ipw_priv *priv) 5092 { 5093 struct ipw_rx_queue *rxq = priv->rxq; 5094 struct list_head *element; 5095 struct ipw_rx_mem_buffer *rxb; 5096 unsigned long flags; 5097 int write; 5098 5099 spin_lock_irqsave(&rxq->lock, flags); 5100 write = rxq->write; 5101 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) { 5102 element = rxq->rx_free.next; 5103 rxb = list_entry(element, struct ipw_rx_mem_buffer, list); 5104 list_del(element); 5105 5106 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, 5107 rxb->dma_addr); 5108 rxq->queue[rxq->write] = rxb; 5109 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; 5110 rxq->free_count--; 5111 } 5112 spin_unlock_irqrestore(&rxq->lock, flags); 5113 5114 /* If the pre-allocated buffer pool is dropping low, schedule to 5115 * refill it */ 5116 if (rxq->free_count <= RX_LOW_WATERMARK) 5117 schedule_work(&priv->rx_replenish); 5118 5119 /* If we've added more space for the firmware to place data, tell it */ 5120 if (write != rxq->write) 5121 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); 5122 } 5123 5124 /* 5125 * Move all used packet from rx_used to rx_free, allocating a new SKB for each. 5126 * Also restock the Rx queue via ipw_rx_queue_restock. 5127 * 5128 * This is called as a scheduled work item (except for during initialization) 5129 */ 5130 static void ipw_rx_queue_replenish(void *data) 5131 { 5132 struct ipw_priv *priv = data; 5133 struct ipw_rx_queue *rxq = priv->rxq; 5134 struct list_head *element; 5135 struct ipw_rx_mem_buffer *rxb; 5136 unsigned long flags; 5137 5138 spin_lock_irqsave(&rxq->lock, flags); 5139 while (!list_empty(&rxq->rx_used)) { 5140 element = rxq->rx_used.next; 5141 rxb = list_entry(element, struct ipw_rx_mem_buffer, list); 5142 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); 5143 if (!rxb->skb) { 5144 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", 5145 priv->net_dev->name); 5146 /* We don't reschedule replenish work here -- we will 5147 * call the restock method and if it still needs 5148 * more buffers it will schedule replenish */ 5149 break; 5150 } 5151 list_del(element); 5152 5153 rxb->dma_addr = 5154 dma_map_single(&priv->pci_dev->dev, rxb->skb->data, 5155 IPW_RX_BUF_SIZE, DMA_FROM_DEVICE); 5156 5157 list_add_tail(&rxb->list, &rxq->rx_free); 5158 rxq->free_count++; 5159 } 5160 spin_unlock_irqrestore(&rxq->lock, flags); 5161 5162 ipw_rx_queue_restock(priv); 5163 } 5164 5165 static void ipw_bg_rx_queue_replenish(struct work_struct *work) 5166 { 5167 struct ipw_priv *priv = 5168 container_of(work, struct ipw_priv, rx_replenish); 5169 mutex_lock(&priv->mutex); 5170 ipw_rx_queue_replenish(priv); 5171 mutex_unlock(&priv->mutex); 5172 } 5173 5174 /* Assumes that the skb field of the buffers in 'pool' is kept accurate. 5175 * If an SKB has been detached, the POOL needs to have its SKB set to NULL 5176 * This free routine walks the list of POOL entries and if SKB is set to 5177 * non NULL it is unmapped and freed 5178 */ 5179 static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq) 5180 { 5181 int i; 5182 5183 if (!rxq) 5184 return; 5185 5186 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { 5187 if (rxq->pool[i].skb != NULL) { 5188 dma_unmap_single(&priv->pci_dev->dev, 5189 rxq->pool[i].dma_addr, 5190 IPW_RX_BUF_SIZE, DMA_FROM_DEVICE); 5191 dev_kfree_skb(rxq->pool[i].skb); 5192 } 5193 } 5194 5195 kfree(rxq); 5196 } 5197 5198 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) 5199 { 5200 struct ipw_rx_queue *rxq; 5201 int i; 5202 5203 rxq = kzalloc_obj(*rxq); 5204 if (unlikely(!rxq)) { 5205 IPW_ERROR("memory allocation failed\n"); 5206 return NULL; 5207 } 5208 spin_lock_init(&rxq->lock); 5209 INIT_LIST_HEAD(&rxq->rx_free); 5210 INIT_LIST_HEAD(&rxq->rx_used); 5211 5212 /* Fill the rx_used queue with _all_ of the Rx buffers */ 5213 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) 5214 list_add_tail(&rxq->pool[i].list, &rxq->rx_used); 5215 5216 /* Set us so that we have processed and used all buffers, but have 5217 * not restocked the Rx queue with fresh buffers */ 5218 rxq->read = rxq->write = 0; 5219 rxq->free_count = 0; 5220 5221 return rxq; 5222 } 5223 5224 static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) 5225 { 5226 rate &= ~LIBIPW_BASIC_RATE_MASK; 5227 if (ieee_mode == IEEE_A) { 5228 switch (rate) { 5229 case LIBIPW_OFDM_RATE_6MB: 5230 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 5231 1 : 0; 5232 case LIBIPW_OFDM_RATE_9MB: 5233 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 5234 1 : 0; 5235 case LIBIPW_OFDM_RATE_12MB: 5236 return priv-> 5237 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; 5238 case LIBIPW_OFDM_RATE_18MB: 5239 return priv-> 5240 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; 5241 case LIBIPW_OFDM_RATE_24MB: 5242 return priv-> 5243 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; 5244 case LIBIPW_OFDM_RATE_36MB: 5245 return priv-> 5246 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; 5247 case LIBIPW_OFDM_RATE_48MB: 5248 return priv-> 5249 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; 5250 case LIBIPW_OFDM_RATE_54MB: 5251 return priv-> 5252 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; 5253 default: 5254 return 0; 5255 } 5256 } 5257 5258 /* B and G mixed */ 5259 switch (rate) { 5260 case LIBIPW_CCK_RATE_1MB: 5261 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0; 5262 case LIBIPW_CCK_RATE_2MB: 5263 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0; 5264 case LIBIPW_CCK_RATE_5MB: 5265 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0; 5266 case LIBIPW_CCK_RATE_11MB: 5267 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0; 5268 } 5269 5270 /* If we are limited to B modulations, bail at this point */ 5271 if (ieee_mode == IEEE_B) 5272 return 0; 5273 5274 /* G */ 5275 switch (rate) { 5276 case LIBIPW_OFDM_RATE_6MB: 5277 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0; 5278 case LIBIPW_OFDM_RATE_9MB: 5279 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0; 5280 case LIBIPW_OFDM_RATE_12MB: 5281 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; 5282 case LIBIPW_OFDM_RATE_18MB: 5283 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; 5284 case LIBIPW_OFDM_RATE_24MB: 5285 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; 5286 case LIBIPW_OFDM_RATE_36MB: 5287 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; 5288 case LIBIPW_OFDM_RATE_48MB: 5289 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; 5290 case LIBIPW_OFDM_RATE_54MB: 5291 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; 5292 } 5293 5294 return 0; 5295 } 5296 5297 static int ipw_compatible_rates(struct ipw_priv *priv, 5298 const struct libipw_network *network, 5299 struct ipw_supported_rates *rates) 5300 { 5301 int num_rates, i; 5302 5303 memset(rates, 0, sizeof(*rates)); 5304 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); 5305 rates->num_rates = 0; 5306 for (i = 0; i < num_rates; i++) { 5307 if (!ipw_is_rate_in_mask(priv, network->mode, 5308 network->rates[i])) { 5309 5310 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) { 5311 IPW_DEBUG_SCAN("Adding masked mandatory " 5312 "rate %02X\n", 5313 network->rates[i]); 5314 rates->supported_rates[rates->num_rates++] = 5315 network->rates[i]; 5316 continue; 5317 } 5318 5319 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", 5320 network->rates[i], priv->rates_mask); 5321 continue; 5322 } 5323 5324 rates->supported_rates[rates->num_rates++] = network->rates[i]; 5325 } 5326 5327 num_rates = min(network->rates_ex_len, 5328 (u8) (IPW_MAX_RATES - num_rates)); 5329 for (i = 0; i < num_rates; i++) { 5330 if (!ipw_is_rate_in_mask(priv, network->mode, 5331 network->rates_ex[i])) { 5332 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) { 5333 IPW_DEBUG_SCAN("Adding masked mandatory " 5334 "rate %02X\n", 5335 network->rates_ex[i]); 5336 rates->supported_rates[rates->num_rates++] = 5337 network->rates[i]; 5338 continue; 5339 } 5340 5341 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", 5342 network->rates_ex[i], priv->rates_mask); 5343 continue; 5344 } 5345 5346 rates->supported_rates[rates->num_rates++] = 5347 network->rates_ex[i]; 5348 } 5349 5350 return 1; 5351 } 5352 5353 static void ipw_copy_rates(struct ipw_supported_rates *dest, 5354 const struct ipw_supported_rates *src) 5355 { 5356 u8 i; 5357 for (i = 0; i < src->num_rates; i++) 5358 dest->supported_rates[i] = src->supported_rates[i]; 5359 dest->num_rates = src->num_rates; 5360 } 5361 5362 /* TODO: Look at sniffed packets in the air to determine if the basic rate 5363 * mask should ever be used -- right now all callers to add the scan rates are 5364 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ 5365 static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, 5366 u8 modulation, u32 rate_mask) 5367 { 5368 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? 5369 LIBIPW_BASIC_RATE_MASK : 0; 5370 5371 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK) 5372 rates->supported_rates[rates->num_rates++] = 5373 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB; 5374 5375 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK) 5376 rates->supported_rates[rates->num_rates++] = 5377 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB; 5378 5379 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK) 5380 rates->supported_rates[rates->num_rates++] = basic_mask | 5381 LIBIPW_CCK_RATE_5MB; 5382 5383 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK) 5384 rates->supported_rates[rates->num_rates++] = basic_mask | 5385 LIBIPW_CCK_RATE_11MB; 5386 } 5387 5388 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, 5389 u8 modulation, u32 rate_mask) 5390 { 5391 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? 5392 LIBIPW_BASIC_RATE_MASK : 0; 5393 5394 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK) 5395 rates->supported_rates[rates->num_rates++] = basic_mask | 5396 LIBIPW_OFDM_RATE_6MB; 5397 5398 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK) 5399 rates->supported_rates[rates->num_rates++] = 5400 LIBIPW_OFDM_RATE_9MB; 5401 5402 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK) 5403 rates->supported_rates[rates->num_rates++] = basic_mask | 5404 LIBIPW_OFDM_RATE_12MB; 5405 5406 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK) 5407 rates->supported_rates[rates->num_rates++] = 5408 LIBIPW_OFDM_RATE_18MB; 5409 5410 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK) 5411 rates->supported_rates[rates->num_rates++] = basic_mask | 5412 LIBIPW_OFDM_RATE_24MB; 5413 5414 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK) 5415 rates->supported_rates[rates->num_rates++] = 5416 LIBIPW_OFDM_RATE_36MB; 5417 5418 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK) 5419 rates->supported_rates[rates->num_rates++] = 5420 LIBIPW_OFDM_RATE_48MB; 5421 5422 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK) 5423 rates->supported_rates[rates->num_rates++] = 5424 LIBIPW_OFDM_RATE_54MB; 5425 } 5426 5427 struct ipw_network_match { 5428 struct libipw_network *network; 5429 struct ipw_supported_rates rates; 5430 }; 5431 5432 static int ipw_find_adhoc_network(struct ipw_priv *priv, 5433 struct ipw_network_match *match, 5434 struct libipw_network *network, 5435 int roaming) 5436 { 5437 struct ipw_supported_rates rates; 5438 5439 /* Verify that this network's capability is compatible with the 5440 * current mode (AdHoc or Infrastructure) */ 5441 if ((priv->ieee->iw_mode == IW_MODE_ADHOC && 5442 !(network->capability & WLAN_CAPABILITY_IBSS))) { 5443 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded due to capability mismatch.\n", 5444 network->ssid_len, network->ssid, 5445 network->bssid); 5446 return 0; 5447 } 5448 5449 if (unlikely(roaming)) { 5450 /* If we are roaming, then ensure check if this is a valid 5451 * network to try and roam to */ 5452 if ((network->ssid_len != match->network->ssid_len) || 5453 memcmp(network->ssid, match->network->ssid, 5454 network->ssid_len)) { 5455 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of non-network ESSID.\n", 5456 network->ssid_len, network->ssid, 5457 network->bssid); 5458 return 0; 5459 } 5460 } else { 5461 /* If an ESSID has been configured then compare the broadcast 5462 * ESSID to ours */ 5463 if ((priv->config & CFG_STATIC_ESSID) && 5464 ((network->ssid_len != priv->essid_len) || 5465 memcmp(network->ssid, priv->essid, 5466 min(network->ssid_len, priv->essid_len)))) { 5467 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of ESSID mismatch: '%*pE'.\n", 5468 network->ssid_len, network->ssid, 5469 network->bssid, priv->essid_len, 5470 priv->essid); 5471 return 0; 5472 } 5473 } 5474 5475 /* If the old network rate is better than this one, don't bother 5476 * testing everything else. */ 5477 5478 if (network->time_stamp[0] < match->network->time_stamp[0]) { 5479 IPW_DEBUG_MERGE("Network '%*pE excluded because newer than current network.\n", 5480 match->network->ssid_len, match->network->ssid); 5481 return 0; 5482 } else if (network->time_stamp[1] < match->network->time_stamp[1]) { 5483 IPW_DEBUG_MERGE("Network '%*pE excluded because newer than current network.\n", 5484 match->network->ssid_len, match->network->ssid); 5485 return 0; 5486 } 5487 5488 /* Now go through and see if the requested network is valid... */ 5489 if (priv->ieee->scan_age != 0 && 5490 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { 5491 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of age: %ums.\n", 5492 network->ssid_len, network->ssid, 5493 network->bssid, 5494 jiffies_to_msecs(jiffies - 5495 network->last_scanned)); 5496 return 0; 5497 } 5498 5499 if ((priv->config & CFG_STATIC_CHANNEL) && 5500 (network->channel != priv->channel)) { 5501 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of channel mismatch: %d != %d.\n", 5502 network->ssid_len, network->ssid, 5503 network->bssid, 5504 network->channel, priv->channel); 5505 return 0; 5506 } 5507 5508 /* Verify privacy compatibility */ 5509 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != 5510 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { 5511 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of privacy mismatch: %s != %s.\n", 5512 network->ssid_len, network->ssid, 5513 network->bssid, 5514 priv-> 5515 capability & CAP_PRIVACY_ON ? "on" : "off", 5516 network-> 5517 capability & WLAN_CAPABILITY_PRIVACY ? "on" : 5518 "off"); 5519 return 0; 5520 } 5521 5522 if (ether_addr_equal(network->bssid, priv->bssid)) { 5523 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of the same BSSID match: %pM.\n", 5524 network->ssid_len, network->ssid, 5525 network->bssid, priv->bssid); 5526 return 0; 5527 } 5528 5529 /* Filter out any incompatible freq / mode combinations */ 5530 if (!libipw_is_valid_mode(priv->ieee, network->mode)) { 5531 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of invalid frequency/mode combination.\n", 5532 network->ssid_len, network->ssid, 5533 network->bssid); 5534 return 0; 5535 } 5536 5537 /* Ensure that the rates supported by the driver are compatible with 5538 * this AP, including verification of basic rates (mandatory) */ 5539 if (!ipw_compatible_rates(priv, network, &rates)) { 5540 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because configured rate mask excludes AP mandatory rate.\n", 5541 network->ssid_len, network->ssid, 5542 network->bssid); 5543 return 0; 5544 } 5545 5546 if (rates.num_rates == 0) { 5547 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of no compatible rates.\n", 5548 network->ssid_len, network->ssid, 5549 network->bssid); 5550 return 0; 5551 } 5552 5553 /* TODO: Perform any further minimal comparititive tests. We do not 5554 * want to put too much policy logic here; intelligent scan selection 5555 * should occur within a generic IEEE 802.11 user space tool. */ 5556 5557 /* Set up 'new' AP to this network */ 5558 ipw_copy_rates(&match->rates, &rates); 5559 match->network = network; 5560 IPW_DEBUG_MERGE("Network '%*pE (%pM)' is a viable match.\n", 5561 network->ssid_len, network->ssid, network->bssid); 5562 5563 return 1; 5564 } 5565 5566 static void ipw_merge_adhoc_network(struct work_struct *work) 5567 { 5568 struct ipw_priv *priv = 5569 container_of(work, struct ipw_priv, merge_networks); 5570 struct libipw_network *network = NULL; 5571 struct ipw_network_match match = { 5572 .network = priv->assoc_network 5573 }; 5574 5575 if ((priv->status & STATUS_ASSOCIATED) && 5576 (priv->ieee->iw_mode == IW_MODE_ADHOC)) { 5577 /* First pass through ROAM process -- look for a better 5578 * network */ 5579 unsigned long flags; 5580 5581 spin_lock_irqsave(&priv->ieee->lock, flags); 5582 list_for_each_entry(network, &priv->ieee->network_list, list) { 5583 if (network != priv->assoc_network) 5584 ipw_find_adhoc_network(priv, &match, network, 5585 1); 5586 } 5587 spin_unlock_irqrestore(&priv->ieee->lock, flags); 5588 5589 if (match.network == priv->assoc_network) { 5590 IPW_DEBUG_MERGE("No better ADHOC in this network to " 5591 "merge to.\n"); 5592 return; 5593 } 5594 5595 mutex_lock(&priv->mutex); 5596 if (priv->ieee->iw_mode == IW_MODE_ADHOC) { 5597 IPW_DEBUG_MERGE("remove network %*pE\n", 5598 priv->essid_len, priv->essid); 5599 ipw_remove_current_network(priv); 5600 } 5601 5602 ipw_disassociate(priv); 5603 priv->assoc_network = match.network; 5604 mutex_unlock(&priv->mutex); 5605 return; 5606 } 5607 } 5608 5609 static int ipw_best_network(struct ipw_priv *priv, 5610 struct ipw_network_match *match, 5611 struct libipw_network *network, int roaming) 5612 { 5613 struct ipw_supported_rates rates; 5614 5615 /* Verify that this network's capability is compatible with the 5616 * current mode (AdHoc or Infrastructure) */ 5617 if ((priv->ieee->iw_mode == IW_MODE_INFRA && 5618 !(network->capability & WLAN_CAPABILITY_ESS)) || 5619 (priv->ieee->iw_mode == IW_MODE_ADHOC && 5620 !(network->capability & WLAN_CAPABILITY_IBSS))) { 5621 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded due to capability mismatch.\n", 5622 network->ssid_len, network->ssid, 5623 network->bssid); 5624 return 0; 5625 } 5626 5627 if (unlikely(roaming)) { 5628 /* If we are roaming, then ensure check if this is a valid 5629 * network to try and roam to */ 5630 if ((network->ssid_len != match->network->ssid_len) || 5631 memcmp(network->ssid, match->network->ssid, 5632 network->ssid_len)) { 5633 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of non-network ESSID.\n", 5634 network->ssid_len, network->ssid, 5635 network->bssid); 5636 return 0; 5637 } 5638 } else { 5639 /* If an ESSID has been configured then compare the broadcast 5640 * ESSID to ours */ 5641 if ((priv->config & CFG_STATIC_ESSID) && 5642 ((network->ssid_len != priv->essid_len) || 5643 memcmp(network->ssid, priv->essid, 5644 min(network->ssid_len, priv->essid_len)))) { 5645 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of ESSID mismatch: '%*pE'.\n", 5646 network->ssid_len, network->ssid, 5647 network->bssid, priv->essid_len, 5648 priv->essid); 5649 return 0; 5650 } 5651 } 5652 5653 /* If the old network rate is better than this one, don't bother 5654 * testing everything else. */ 5655 if (match->network && match->network->stats.rssi > network->stats.rssi) { 5656 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because '%*pE (%pM)' has a stronger signal.\n", 5657 network->ssid_len, network->ssid, 5658 network->bssid, match->network->ssid_len, 5659 match->network->ssid, match->network->bssid); 5660 return 0; 5661 } 5662 5663 /* If this network has already had an association attempt within the 5664 * last 3 seconds, do not try and associate again... */ 5665 if (network->last_associate && 5666 time_after(network->last_associate + (HZ * 3UL), jiffies)) { 5667 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of storming (%ums since last assoc attempt).\n", 5668 network->ssid_len, network->ssid, 5669 network->bssid, 5670 jiffies_to_msecs(jiffies - 5671 network->last_associate)); 5672 return 0; 5673 } 5674 5675 /* Now go through and see if the requested network is valid... */ 5676 if (priv->ieee->scan_age != 0 && 5677 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { 5678 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of age: %ums.\n", 5679 network->ssid_len, network->ssid, 5680 network->bssid, 5681 jiffies_to_msecs(jiffies - 5682 network->last_scanned)); 5683 return 0; 5684 } 5685 5686 if ((priv->config & CFG_STATIC_CHANNEL) && 5687 (network->channel != priv->channel)) { 5688 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of channel mismatch: %d != %d.\n", 5689 network->ssid_len, network->ssid, 5690 network->bssid, 5691 network->channel, priv->channel); 5692 return 0; 5693 } 5694 5695 /* Verify privacy compatibility */ 5696 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != 5697 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { 5698 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of privacy mismatch: %s != %s.\n", 5699 network->ssid_len, network->ssid, 5700 network->bssid, 5701 priv->capability & CAP_PRIVACY_ON ? "on" : 5702 "off", 5703 network->capability & 5704 WLAN_CAPABILITY_PRIVACY ? "on" : "off"); 5705 return 0; 5706 } 5707 5708 if ((priv->config & CFG_STATIC_BSSID) && 5709 !ether_addr_equal(network->bssid, priv->bssid)) { 5710 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of BSSID mismatch: %pM.\n", 5711 network->ssid_len, network->ssid, 5712 network->bssid, priv->bssid); 5713 return 0; 5714 } 5715 5716 /* Filter out any incompatible freq / mode combinations */ 5717 if (!libipw_is_valid_mode(priv->ieee, network->mode)) { 5718 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of invalid frequency/mode combination.\n", 5719 network->ssid_len, network->ssid, 5720 network->bssid); 5721 return 0; 5722 } 5723 5724 /* Filter out invalid channel in current GEO */ 5725 if (!libipw_is_valid_channel(priv->ieee, network->channel)) { 5726 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of invalid channel in current GEO\n", 5727 network->ssid_len, network->ssid, 5728 network->bssid); 5729 return 0; 5730 } 5731 5732 /* Ensure that the rates supported by the driver are compatible with 5733 * this AP, including verification of basic rates (mandatory) */ 5734 if (!ipw_compatible_rates(priv, network, &rates)) { 5735 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because configured rate mask excludes AP mandatory rate.\n", 5736 network->ssid_len, network->ssid, 5737 network->bssid); 5738 return 0; 5739 } 5740 5741 if (rates.num_rates == 0) { 5742 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of no compatible rates.\n", 5743 network->ssid_len, network->ssid, 5744 network->bssid); 5745 return 0; 5746 } 5747 5748 /* TODO: Perform any further minimal comparititive tests. We do not 5749 * want to put too much policy logic here; intelligent scan selection 5750 * should occur within a generic IEEE 802.11 user space tool. */ 5751 5752 /* Set up 'new' AP to this network */ 5753 ipw_copy_rates(&match->rates, &rates); 5754 match->network = network; 5755 5756 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' is a viable match.\n", 5757 network->ssid_len, network->ssid, network->bssid); 5758 5759 return 1; 5760 } 5761 5762 static void ipw_adhoc_create(struct ipw_priv *priv, 5763 struct libipw_network *network) 5764 { 5765 const struct libipw_geo *geo = libipw_get_geo(priv->ieee); 5766 int i; 5767 5768 /* 5769 * For the purposes of scanning, we can set our wireless mode 5770 * to trigger scans across combinations of bands, but when it 5771 * comes to creating a new ad-hoc network, we have tell the FW 5772 * exactly which band to use. 5773 * 5774 * We also have the possibility of an invalid channel for the 5775 * chossen band. Attempting to create a new ad-hoc network 5776 * with an invalid channel for wireless mode will trigger a 5777 * FW fatal error. 5778 * 5779 */ 5780 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { 5781 case LIBIPW_52GHZ_BAND: 5782 network->mode = IEEE_A; 5783 i = libipw_channel_to_index(priv->ieee, priv->channel); 5784 BUG_ON(i == -1); 5785 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) { 5786 IPW_WARNING("Overriding invalid channel\n"); 5787 priv->channel = geo->a[0].channel; 5788 } 5789 break; 5790 5791 case LIBIPW_24GHZ_BAND: 5792 if (priv->ieee->mode & IEEE_G) 5793 network->mode = IEEE_G; 5794 else 5795 network->mode = IEEE_B; 5796 i = libipw_channel_to_index(priv->ieee, priv->channel); 5797 BUG_ON(i == -1); 5798 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) { 5799 IPW_WARNING("Overriding invalid channel\n"); 5800 priv->channel = geo->bg[0].channel; 5801 } 5802 break; 5803 5804 default: 5805 IPW_WARNING("Overriding invalid channel\n"); 5806 if (priv->ieee->mode & IEEE_A) { 5807 network->mode = IEEE_A; 5808 priv->channel = geo->a[0].channel; 5809 } else if (priv->ieee->mode & IEEE_G) { 5810 network->mode = IEEE_G; 5811 priv->channel = geo->bg[0].channel; 5812 } else { 5813 network->mode = IEEE_B; 5814 priv->channel = geo->bg[0].channel; 5815 } 5816 break; 5817 } 5818 5819 network->channel = priv->channel; 5820 priv->config |= CFG_ADHOC_PERSIST; 5821 ipw_create_bssid(priv, network->bssid); 5822 network->ssid_len = priv->essid_len; 5823 memcpy(network->ssid, priv->essid, priv->essid_len); 5824 memset(&network->stats, 0, sizeof(network->stats)); 5825 network->capability = WLAN_CAPABILITY_IBSS; 5826 if (!(priv->config & CFG_PREAMBLE_LONG)) 5827 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; 5828 if (priv->capability & CAP_PRIVACY_ON) 5829 network->capability |= WLAN_CAPABILITY_PRIVACY; 5830 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); 5831 memcpy(network->rates, priv->rates.supported_rates, network->rates_len); 5832 network->rates_ex_len = priv->rates.num_rates - network->rates_len; 5833 memcpy(network->rates_ex, 5834 &priv->rates.supported_rates[network->rates_len], 5835 network->rates_ex_len); 5836 network->last_scanned = 0; 5837 network->flags = 0; 5838 network->last_associate = 0; 5839 network->time_stamp[0] = 0; 5840 network->time_stamp[1] = 0; 5841 network->beacon_interval = 100; /* Default */ 5842 network->listen_interval = 10; /* Default */ 5843 network->atim_window = 0; /* Default */ 5844 network->wpa_ie_len = 0; 5845 network->rsn_ie_len = 0; 5846 } 5847 5848 static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) 5849 { 5850 struct ipw_tgi_tx_key key; 5851 5852 if (!(priv->ieee->sec.flags & (1 << index))) 5853 return; 5854 5855 key.key_id = index; 5856 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); 5857 key.security_type = type; 5858 key.station_index = 0; /* always 0 for BSS */ 5859 key.flags = 0; 5860 /* 0 for new key; previous value of counter (after fatal error) */ 5861 key.tx_counter[0] = cpu_to_le32(0); 5862 key.tx_counter[1] = cpu_to_le32(0); 5863 5864 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key); 5865 } 5866 5867 static void ipw_send_wep_keys(struct ipw_priv *priv, int type) 5868 { 5869 struct ipw_wep_key key; 5870 int i; 5871 5872 key.cmd_id = DINO_CMD_WEP_KEY; 5873 key.seq_num = 0; 5874 5875 /* Note: AES keys cannot be set for multiple times. 5876 * Only set it at the first time. */ 5877 for (i = 0; i < 4; i++) { 5878 key.key_index = i | type; 5879 if (!(priv->ieee->sec.flags & (1 << i))) { 5880 key.key_size = 0; 5881 continue; 5882 } 5883 5884 key.key_size = priv->ieee->sec.key_sizes[i]; 5885 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); 5886 5887 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); 5888 } 5889 } 5890 5891 static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) 5892 { 5893 if (priv->ieee->host_encrypt) 5894 return; 5895 5896 switch (level) { 5897 case SEC_LEVEL_3: 5898 priv->sys_config.disable_unicast_decryption = 0; 5899 priv->ieee->host_decrypt = 0; 5900 break; 5901 case SEC_LEVEL_2: 5902 priv->sys_config.disable_unicast_decryption = 1; 5903 priv->ieee->host_decrypt = 1; 5904 break; 5905 case SEC_LEVEL_1: 5906 priv->sys_config.disable_unicast_decryption = 0; 5907 priv->ieee->host_decrypt = 0; 5908 break; 5909 case SEC_LEVEL_0: 5910 priv->sys_config.disable_unicast_decryption = 1; 5911 break; 5912 default: 5913 break; 5914 } 5915 } 5916 5917 static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) 5918 { 5919 if (priv->ieee->host_encrypt) 5920 return; 5921 5922 switch (level) { 5923 case SEC_LEVEL_3: 5924 priv->sys_config.disable_multicast_decryption = 0; 5925 break; 5926 case SEC_LEVEL_2: 5927 priv->sys_config.disable_multicast_decryption = 1; 5928 break; 5929 case SEC_LEVEL_1: 5930 priv->sys_config.disable_multicast_decryption = 0; 5931 break; 5932 case SEC_LEVEL_0: 5933 priv->sys_config.disable_multicast_decryption = 1; 5934 break; 5935 default: 5936 break; 5937 } 5938 } 5939 5940 static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) 5941 { 5942 switch (priv->ieee->sec.level) { 5943 case SEC_LEVEL_3: 5944 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) 5945 ipw_send_tgi_tx_key(priv, 5946 DCT_FLAG_EXT_SECURITY_CCM, 5947 priv->ieee->sec.active_key); 5948 5949 if (!priv->ieee->host_mc_decrypt) 5950 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); 5951 break; 5952 case SEC_LEVEL_2: 5953 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) 5954 ipw_send_tgi_tx_key(priv, 5955 DCT_FLAG_EXT_SECURITY_TKIP, 5956 priv->ieee->sec.active_key); 5957 break; 5958 case SEC_LEVEL_1: 5959 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); 5960 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); 5961 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); 5962 break; 5963 case SEC_LEVEL_0: 5964 default: 5965 break; 5966 } 5967 } 5968 5969 static void ipw_adhoc_check(void *data) 5970 { 5971 struct ipw_priv *priv = data; 5972 5973 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && 5974 !(priv->config & CFG_ADHOC_PERSIST)) { 5975 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | 5976 IPW_DL_STATE | IPW_DL_ASSOC, 5977 "Missed beacon: %d - disassociate\n", 5978 priv->missed_adhoc_beacons); 5979 ipw_remove_current_network(priv); 5980 ipw_disassociate(priv); 5981 return; 5982 } 5983 5984 schedule_delayed_work(&priv->adhoc_check, 5985 le16_to_cpu(priv->assoc_request.beacon_interval)); 5986 } 5987 5988 static void ipw_bg_adhoc_check(struct work_struct *work) 5989 { 5990 struct ipw_priv *priv = 5991 container_of(work, struct ipw_priv, adhoc_check.work); 5992 mutex_lock(&priv->mutex); 5993 ipw_adhoc_check(priv); 5994 mutex_unlock(&priv->mutex); 5995 } 5996 5997 static void ipw_debug_config(struct ipw_priv *priv) 5998 { 5999 IPW_DEBUG_INFO("Scan completed, no valid APs matched " 6000 "[CFG 0x%08X]\n", priv->config); 6001 if (priv->config & CFG_STATIC_CHANNEL) 6002 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); 6003 else 6004 IPW_DEBUG_INFO("Channel unlocked.\n"); 6005 if (priv->config & CFG_STATIC_ESSID) 6006 IPW_DEBUG_INFO("ESSID locked to '%*pE'\n", 6007 priv->essid_len, priv->essid); 6008 else 6009 IPW_DEBUG_INFO("ESSID unlocked.\n"); 6010 if (priv->config & CFG_STATIC_BSSID) 6011 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid); 6012 else 6013 IPW_DEBUG_INFO("BSSID unlocked.\n"); 6014 if (priv->capability & CAP_PRIVACY_ON) 6015 IPW_DEBUG_INFO("PRIVACY on\n"); 6016 else 6017 IPW_DEBUG_INFO("PRIVACY off\n"); 6018 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); 6019 } 6020 6021 static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) 6022 { 6023 /* TODO: Verify that this works... */ 6024 struct ipw_fixed_rate fr; 6025 u32 reg; 6026 u16 mask = 0; 6027 u16 new_tx_rates = priv->rates_mask; 6028 6029 /* Identify 'current FW band' and match it with the fixed 6030 * Tx rates */ 6031 6032 switch (priv->ieee->freq_band) { 6033 case LIBIPW_52GHZ_BAND: /* A only */ 6034 /* IEEE_A */ 6035 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) { 6036 /* Invalid fixed rate mask */ 6037 IPW_DEBUG_WX 6038 ("invalid fixed rate mask in ipw_set_fixed_rate\n"); 6039 new_tx_rates = 0; 6040 break; 6041 } 6042 6043 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A; 6044 break; 6045 6046 default: /* 2.4Ghz or Mixed */ 6047 /* IEEE_B */ 6048 if (mode == IEEE_B) { 6049 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) { 6050 /* Invalid fixed rate mask */ 6051 IPW_DEBUG_WX 6052 ("invalid fixed rate mask in ipw_set_fixed_rate\n"); 6053 new_tx_rates = 0; 6054 } 6055 break; 6056 } 6057 6058 /* IEEE_G */ 6059 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK | 6060 LIBIPW_OFDM_RATES_MASK)) { 6061 /* Invalid fixed rate mask */ 6062 IPW_DEBUG_WX 6063 ("invalid fixed rate mask in ipw_set_fixed_rate\n"); 6064 new_tx_rates = 0; 6065 break; 6066 } 6067 6068 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) { 6069 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1); 6070 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK; 6071 } 6072 6073 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) { 6074 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1); 6075 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK; 6076 } 6077 6078 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) { 6079 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1); 6080 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK; 6081 } 6082 6083 new_tx_rates |= mask; 6084 break; 6085 } 6086 6087 fr.tx_rates = cpu_to_le16(new_tx_rates); 6088 6089 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); 6090 ipw_write_reg32(priv, reg, *(u32 *) & fr); 6091 } 6092 6093 static void ipw_abort_scan(struct ipw_priv *priv) 6094 { 6095 int err; 6096 6097 if (priv->status & STATUS_SCAN_ABORTING) { 6098 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); 6099 return; 6100 } 6101 priv->status |= STATUS_SCAN_ABORTING; 6102 6103 err = ipw_send_scan_abort(priv); 6104 if (err) 6105 IPW_DEBUG_HC("Request to abort scan failed.\n"); 6106 } 6107 6108 static void ipw_add_scan_channels(struct ipw_priv *priv, 6109 struct ipw_scan_request_ext *scan, 6110 int scan_type) 6111 { 6112 int channel_index = 0; 6113 const struct libipw_geo *geo; 6114 int i; 6115 6116 geo = libipw_get_geo(priv->ieee); 6117 6118 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) { 6119 int start = channel_index; 6120 for (i = 0; i < geo->a_channels; i++) { 6121 if ((priv->status & STATUS_ASSOCIATED) && 6122 geo->a[i].channel == priv->channel) 6123 continue; 6124 channel_index++; 6125 scan->channels_list[channel_index] = geo->a[i].channel; 6126 ipw_set_scan_type(scan, channel_index, 6127 geo->a[i]. 6128 flags & LIBIPW_CH_PASSIVE_ONLY ? 6129 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : 6130 scan_type); 6131 } 6132 6133 if (start != channel_index) { 6134 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | 6135 (channel_index - start); 6136 channel_index++; 6137 } 6138 } 6139 6140 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) { 6141 int start = channel_index; 6142 if (priv->config & CFG_SPEED_SCAN) { 6143 int index; 6144 u8 channels[LIBIPW_24GHZ_CHANNELS] = { 6145 /* nop out the list */ 6146 [0] = 0 6147 }; 6148 6149 u8 channel; 6150 while (channel_index < IPW_SCAN_CHANNELS - 1) { 6151 channel = 6152 priv->speed_scan[priv->speed_scan_pos]; 6153 if (channel == 0) { 6154 priv->speed_scan_pos = 0; 6155 channel = priv->speed_scan[0]; 6156 } 6157 if ((priv->status & STATUS_ASSOCIATED) && 6158 channel == priv->channel) { 6159 priv->speed_scan_pos++; 6160 continue; 6161 } 6162 6163 /* If this channel has already been 6164 * added in scan, break from loop 6165 * and this will be the first channel 6166 * in the next scan. 6167 */ 6168 if (channels[channel - 1] != 0) 6169 break; 6170 6171 channels[channel - 1] = 1; 6172 priv->speed_scan_pos++; 6173 channel_index++; 6174 scan->channels_list[channel_index] = channel; 6175 index = 6176 libipw_channel_to_index(priv->ieee, channel); 6177 ipw_set_scan_type(scan, channel_index, 6178 geo->bg[index]. 6179 flags & 6180 LIBIPW_CH_PASSIVE_ONLY ? 6181 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN 6182 : scan_type); 6183 } 6184 } else { 6185 for (i = 0; i < geo->bg_channels; i++) { 6186 if ((priv->status & STATUS_ASSOCIATED) && 6187 geo->bg[i].channel == priv->channel) 6188 continue; 6189 channel_index++; 6190 scan->channels_list[channel_index] = 6191 geo->bg[i].channel; 6192 ipw_set_scan_type(scan, channel_index, 6193 geo->bg[i]. 6194 flags & 6195 LIBIPW_CH_PASSIVE_ONLY ? 6196 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN 6197 : scan_type); 6198 } 6199 } 6200 6201 if (start != channel_index) { 6202 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | 6203 (channel_index - start); 6204 } 6205 } 6206 } 6207 6208 static int ipw_passive_dwell_time(struct ipw_priv *priv) 6209 { 6210 /* staying on passive channels longer than the DTIM interval during a 6211 * scan, while associated, causes the firmware to cancel the scan 6212 * without notification. Hence, don't stay on passive channels longer 6213 * than the beacon interval. 6214 */ 6215 if (priv->status & STATUS_ASSOCIATED 6216 && priv->assoc_network->beacon_interval > 10) 6217 return priv->assoc_network->beacon_interval - 10; 6218 else 6219 return 120; 6220 } 6221 6222 static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct) 6223 { 6224 struct ipw_scan_request_ext scan; 6225 int err = 0, scan_type; 6226 6227 if (!(priv->status & STATUS_INIT) || 6228 (priv->status & STATUS_EXIT_PENDING)) 6229 return 0; 6230 6231 mutex_lock(&priv->mutex); 6232 6233 if (direct && (priv->direct_scan_ssid_len == 0)) { 6234 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n"); 6235 priv->status &= ~STATUS_DIRECT_SCAN_PENDING; 6236 goto done; 6237 } 6238 6239 if (priv->status & STATUS_SCANNING) { 6240 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n"); 6241 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : 6242 STATUS_SCAN_PENDING; 6243 goto done; 6244 } 6245 6246 if (!(priv->status & STATUS_SCAN_FORCED) && 6247 priv->status & STATUS_SCAN_ABORTING) { 6248 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); 6249 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : 6250 STATUS_SCAN_PENDING; 6251 goto done; 6252 } 6253 6254 if (priv->status & STATUS_RF_KILL_MASK) { 6255 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n"); 6256 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : 6257 STATUS_SCAN_PENDING; 6258 goto done; 6259 } 6260 6261 memset(&scan, 0, sizeof(scan)); 6262 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee)); 6263 6264 if (type == IW_SCAN_TYPE_PASSIVE) { 6265 IPW_DEBUG_WX("use passive scanning\n"); 6266 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN; 6267 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = 6268 cpu_to_le16(ipw_passive_dwell_time(priv)); 6269 ipw_add_scan_channels(priv, &scan, scan_type); 6270 goto send_request; 6271 } 6272 6273 /* Use active scan by default. */ 6274 if (priv->config & CFG_SPEED_SCAN) 6275 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = 6276 cpu_to_le16(30); 6277 else 6278 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = 6279 cpu_to_le16(20); 6280 6281 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = 6282 cpu_to_le16(20); 6283 6284 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = 6285 cpu_to_le16(ipw_passive_dwell_time(priv)); 6286 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); 6287 6288 #ifdef CONFIG_IPW2200_MONITOR 6289 if (priv->ieee->iw_mode == IW_MODE_MONITOR) { 6290 u8 channel; 6291 u8 band = 0; 6292 6293 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { 6294 case LIBIPW_52GHZ_BAND: 6295 band = (u8) (IPW_A_MODE << 6) | 1; 6296 channel = priv->channel; 6297 break; 6298 6299 case LIBIPW_24GHZ_BAND: 6300 band = (u8) (IPW_B_MODE << 6) | 1; 6301 channel = priv->channel; 6302 break; 6303 6304 default: 6305 band = (u8) (IPW_B_MODE << 6) | 1; 6306 channel = 9; 6307 break; 6308 } 6309 6310 scan.channels_list[0] = band; 6311 scan.channels_list[1] = channel; 6312 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); 6313 6314 /* NOTE: The card will sit on this channel for this time 6315 * period. Scan aborts are timing sensitive and frequently 6316 * result in firmware restarts. As such, it is best to 6317 * set a small dwell_time here and just keep re-issuing 6318 * scans. Otherwise fast channel hopping will not actually 6319 * hop channels. 6320 * 6321 * TODO: Move SPEED SCAN support to all modes and bands */ 6322 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = 6323 cpu_to_le16(2000); 6324 } else { 6325 #endif /* CONFIG_IPW2200_MONITOR */ 6326 /* Honor direct scans first, otherwise if we are roaming make 6327 * this a direct scan for the current network. Finally, 6328 * ensure that every other scan is a fast channel hop scan */ 6329 if (direct) { 6330 err = ipw_send_ssid(priv, priv->direct_scan_ssid, 6331 priv->direct_scan_ssid_len); 6332 if (err) { 6333 IPW_DEBUG_HC("Attempt to send SSID command " 6334 "failed\n"); 6335 goto done; 6336 } 6337 6338 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; 6339 } else if ((priv->status & STATUS_ROAMING) 6340 || (!(priv->status & STATUS_ASSOCIATED) 6341 && (priv->config & CFG_STATIC_ESSID) 6342 && (le32_to_cpu(scan.full_scan_index) % 2))) { 6343 err = ipw_send_ssid(priv, priv->essid, priv->essid_len); 6344 if (err) { 6345 IPW_DEBUG_HC("Attempt to send SSID command " 6346 "failed.\n"); 6347 goto done; 6348 } 6349 6350 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; 6351 } else 6352 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; 6353 6354 ipw_add_scan_channels(priv, &scan, scan_type); 6355 #ifdef CONFIG_IPW2200_MONITOR 6356 } 6357 #endif 6358 6359 send_request: 6360 err = ipw_send_scan_request_ext(priv, &scan); 6361 if (err) { 6362 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); 6363 goto done; 6364 } 6365 6366 priv->status |= STATUS_SCANNING; 6367 if (direct) { 6368 priv->status &= ~STATUS_DIRECT_SCAN_PENDING; 6369 priv->direct_scan_ssid_len = 0; 6370 } else 6371 priv->status &= ~STATUS_SCAN_PENDING; 6372 6373 schedule_delayed_work(&priv->scan_check, IPW_SCAN_CHECK_WATCHDOG); 6374 done: 6375 mutex_unlock(&priv->mutex); 6376 return err; 6377 } 6378 6379 static void ipw_request_passive_scan(struct work_struct *work) 6380 { 6381 struct ipw_priv *priv = 6382 container_of(work, struct ipw_priv, request_passive_scan.work); 6383 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0); 6384 } 6385 6386 static void ipw_request_scan(struct work_struct *work) 6387 { 6388 struct ipw_priv *priv = 6389 container_of(work, struct ipw_priv, request_scan.work); 6390 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0); 6391 } 6392 6393 static void ipw_request_direct_scan(struct work_struct *work) 6394 { 6395 struct ipw_priv *priv = 6396 container_of(work, struct ipw_priv, request_direct_scan.work); 6397 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1); 6398 } 6399 6400 static void ipw_bg_abort_scan(struct work_struct *work) 6401 { 6402 struct ipw_priv *priv = 6403 container_of(work, struct ipw_priv, abort_scan); 6404 mutex_lock(&priv->mutex); 6405 ipw_abort_scan(priv); 6406 mutex_unlock(&priv->mutex); 6407 } 6408 6409 static int ipw_wpa_enable(struct ipw_priv *priv, int value) 6410 { 6411 /* This is called when wpa_supplicant loads and closes the driver 6412 * interface. */ 6413 priv->ieee->wpa_enabled = value; 6414 return 0; 6415 } 6416 6417 static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) 6418 { 6419 struct libipw_device *ieee = priv->ieee; 6420 struct libipw_security sec = { 6421 .flags = SEC_AUTH_MODE, 6422 }; 6423 int ret = 0; 6424 6425 if (value & IW_AUTH_ALG_SHARED_KEY) { 6426 sec.auth_mode = WLAN_AUTH_SHARED_KEY; 6427 ieee->open_wep = 0; 6428 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { 6429 sec.auth_mode = WLAN_AUTH_OPEN; 6430 ieee->open_wep = 1; 6431 } else if (value & IW_AUTH_ALG_LEAP) { 6432 sec.auth_mode = WLAN_AUTH_LEAP; 6433 ieee->open_wep = 1; 6434 } else 6435 return -EINVAL; 6436 6437 if (ieee->set_security) 6438 ieee->set_security(ieee->dev, &sec); 6439 else 6440 ret = -EOPNOTSUPP; 6441 6442 return ret; 6443 } 6444 6445 static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, 6446 int wpa_ie_len) 6447 { 6448 /* make sure WPA is enabled */ 6449 ipw_wpa_enable(priv, 1); 6450 } 6451 6452 static int ipw_set_rsn_capa(struct ipw_priv *priv, 6453 char *capabilities, int length) 6454 { 6455 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); 6456 6457 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, 6458 capabilities); 6459 } 6460 6461 /* 6462 * WE-18 support 6463 */ 6464 6465 static int ipw_wx_get_name(struct net_device *dev, 6466 struct iw_request_info *info, 6467 union iwreq_data *wrqu, char *extra) 6468 { 6469 strcpy(wrqu->name, "IEEE 802.11"); 6470 return 0; 6471 } 6472 6473 /* SIOCSIWGENIE */ 6474 static int ipw_wx_set_genie(struct net_device *dev, 6475 struct iw_request_info *info, 6476 union iwreq_data *wrqu, char *extra) 6477 { 6478 struct ipw_priv *priv = libipw_priv(dev); 6479 struct libipw_device *ieee = priv->ieee; 6480 u8 *buf; 6481 int err = 0; 6482 6483 if (wrqu->data.length > MAX_WPA_IE_LEN || 6484 (wrqu->data.length && extra == NULL)) 6485 return -EINVAL; 6486 6487 if (wrqu->data.length) { 6488 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL); 6489 if (buf == NULL) { 6490 err = -ENOMEM; 6491 goto out; 6492 } 6493 6494 kfree(ieee->wpa_ie); 6495 ieee->wpa_ie = buf; 6496 ieee->wpa_ie_len = wrqu->data.length; 6497 } else { 6498 kfree(ieee->wpa_ie); 6499 ieee->wpa_ie = NULL; 6500 ieee->wpa_ie_len = 0; 6501 } 6502 6503 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); 6504 out: 6505 return err; 6506 } 6507 6508 /* SIOCGIWGENIE */ 6509 static int ipw_wx_get_genie(struct net_device *dev, 6510 struct iw_request_info *info, 6511 union iwreq_data *wrqu, char *extra) 6512 { 6513 struct ipw_priv *priv = libipw_priv(dev); 6514 struct libipw_device *ieee = priv->ieee; 6515 int err = 0; 6516 6517 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { 6518 wrqu->data.length = 0; 6519 goto out; 6520 } 6521 6522 if (wrqu->data.length < ieee->wpa_ie_len) { 6523 err = -E2BIG; 6524 goto out; 6525 } 6526 6527 wrqu->data.length = ieee->wpa_ie_len; 6528 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); 6529 6530 out: 6531 return err; 6532 } 6533 6534 static int wext_cipher2level(int cipher) 6535 { 6536 switch (cipher) { 6537 case IW_AUTH_CIPHER_NONE: 6538 return SEC_LEVEL_0; 6539 case IW_AUTH_CIPHER_WEP40: 6540 case IW_AUTH_CIPHER_WEP104: 6541 return SEC_LEVEL_1; 6542 case IW_AUTH_CIPHER_TKIP: 6543 return SEC_LEVEL_2; 6544 case IW_AUTH_CIPHER_CCMP: 6545 return SEC_LEVEL_3; 6546 default: 6547 return -1; 6548 } 6549 } 6550 6551 /* SIOCSIWAUTH */ 6552 static int ipw_wx_set_auth(struct net_device *dev, 6553 struct iw_request_info *info, 6554 union iwreq_data *wrqu, char *extra) 6555 { 6556 struct ipw_priv *priv = libipw_priv(dev); 6557 struct libipw_device *ieee = priv->ieee; 6558 struct iw_param *param = &wrqu->param; 6559 struct libipw_crypt_data *crypt; 6560 unsigned long flags; 6561 int ret = 0; 6562 6563 switch (param->flags & IW_AUTH_INDEX) { 6564 case IW_AUTH_WPA_VERSION: 6565 break; 6566 case IW_AUTH_CIPHER_PAIRWISE: 6567 ipw_set_hw_decrypt_unicast(priv, 6568 wext_cipher2level(param->value)); 6569 break; 6570 case IW_AUTH_CIPHER_GROUP: 6571 ipw_set_hw_decrypt_multicast(priv, 6572 wext_cipher2level(param->value)); 6573 break; 6574 case IW_AUTH_KEY_MGMT: 6575 /* 6576 * ipw2200 does not use these parameters 6577 */ 6578 break; 6579 6580 case IW_AUTH_TKIP_COUNTERMEASURES: 6581 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; 6582 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) 6583 break; 6584 6585 flags = crypt->ops->get_flags(crypt->priv); 6586 6587 if (param->value) 6588 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; 6589 else 6590 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; 6591 6592 crypt->ops->set_flags(flags, crypt->priv); 6593 6594 break; 6595 6596 case IW_AUTH_DROP_UNENCRYPTED:{ 6597 /* HACK: 6598 * 6599 * wpa_supplicant calls set_wpa_enabled when the driver 6600 * is loaded and unloaded, regardless of if WPA is being 6601 * used. No other calls are made which can be used to 6602 * determine if encryption will be used or not prior to 6603 * association being expected. If encryption is not being 6604 * used, drop_unencrypted is set to false, else true -- we 6605 * can use this to determine if the CAP_PRIVACY_ON bit should 6606 * be set. 6607 */ 6608 struct libipw_security sec = { 6609 .flags = SEC_ENABLED, 6610 .enabled = param->value, 6611 }; 6612 priv->ieee->drop_unencrypted = param->value; 6613 /* We only change SEC_LEVEL for open mode. Others 6614 * are set by ipw_wpa_set_encryption. 6615 */ 6616 if (!param->value) { 6617 sec.flags |= SEC_LEVEL; 6618 sec.level = SEC_LEVEL_0; 6619 } else { 6620 sec.flags |= SEC_LEVEL; 6621 sec.level = SEC_LEVEL_1; 6622 } 6623 if (priv->ieee->set_security) 6624 priv->ieee->set_security(priv->ieee->dev, &sec); 6625 break; 6626 } 6627 6628 case IW_AUTH_80211_AUTH_ALG: 6629 ret = ipw_wpa_set_auth_algs(priv, param->value); 6630 break; 6631 6632 case IW_AUTH_WPA_ENABLED: 6633 ret = ipw_wpa_enable(priv, param->value); 6634 ipw_disassociate(priv); 6635 break; 6636 6637 case IW_AUTH_RX_UNENCRYPTED_EAPOL: 6638 ieee->ieee802_1x = param->value; 6639 break; 6640 6641 case IW_AUTH_PRIVACY_INVOKED: 6642 ieee->privacy_invoked = param->value; 6643 break; 6644 6645 default: 6646 return -EOPNOTSUPP; 6647 } 6648 return ret; 6649 } 6650 6651 /* SIOCGIWAUTH */ 6652 static int ipw_wx_get_auth(struct net_device *dev, 6653 struct iw_request_info *info, 6654 union iwreq_data *wrqu, char *extra) 6655 { 6656 struct ipw_priv *priv = libipw_priv(dev); 6657 struct libipw_device *ieee = priv->ieee; 6658 struct libipw_crypt_data *crypt; 6659 struct iw_param *param = &wrqu->param; 6660 6661 switch (param->flags & IW_AUTH_INDEX) { 6662 case IW_AUTH_WPA_VERSION: 6663 case IW_AUTH_CIPHER_PAIRWISE: 6664 case IW_AUTH_CIPHER_GROUP: 6665 case IW_AUTH_KEY_MGMT: 6666 /* 6667 * wpa_supplicant will control these internally 6668 */ 6669 return -EOPNOTSUPP; 6670 6671 case IW_AUTH_TKIP_COUNTERMEASURES: 6672 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; 6673 if (!crypt || !crypt->ops->get_flags) 6674 break; 6675 6676 param->value = (crypt->ops->get_flags(crypt->priv) & 6677 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; 6678 6679 break; 6680 6681 case IW_AUTH_DROP_UNENCRYPTED: 6682 param->value = ieee->drop_unencrypted; 6683 break; 6684 6685 case IW_AUTH_80211_AUTH_ALG: 6686 param->value = ieee->sec.auth_mode; 6687 break; 6688 6689 case IW_AUTH_WPA_ENABLED: 6690 param->value = ieee->wpa_enabled; 6691 break; 6692 6693 case IW_AUTH_RX_UNENCRYPTED_EAPOL: 6694 param->value = ieee->ieee802_1x; 6695 break; 6696 6697 case IW_AUTH_ROAMING_CONTROL: 6698 case IW_AUTH_PRIVACY_INVOKED: 6699 param->value = ieee->privacy_invoked; 6700 break; 6701 6702 default: 6703 return -EOPNOTSUPP; 6704 } 6705 return 0; 6706 } 6707 6708 /* SIOCSIWENCODEEXT */ 6709 static int ipw_wx_set_encodeext(struct net_device *dev, 6710 struct iw_request_info *info, 6711 union iwreq_data *wrqu, char *extra) 6712 { 6713 struct ipw_priv *priv = libipw_priv(dev); 6714 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; 6715 6716 if (hwcrypto) { 6717 if (ext->alg == IW_ENCODE_ALG_TKIP) { 6718 /* IPW HW can't build TKIP MIC, 6719 host decryption still needed */ 6720 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) 6721 priv->ieee->host_mc_decrypt = 1; 6722 else { 6723 priv->ieee->host_encrypt = 0; 6724 priv->ieee->host_encrypt_msdu = 1; 6725 priv->ieee->host_decrypt = 1; 6726 } 6727 } else { 6728 priv->ieee->host_encrypt = 0; 6729 priv->ieee->host_encrypt_msdu = 0; 6730 priv->ieee->host_decrypt = 0; 6731 priv->ieee->host_mc_decrypt = 0; 6732 } 6733 } 6734 6735 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra); 6736 } 6737 6738 /* SIOCGIWENCODEEXT */ 6739 static int ipw_wx_get_encodeext(struct net_device *dev, 6740 struct iw_request_info *info, 6741 union iwreq_data *wrqu, char *extra) 6742 { 6743 struct ipw_priv *priv = libipw_priv(dev); 6744 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra); 6745 } 6746 6747 /* SIOCSIWMLME */ 6748 static int ipw_wx_set_mlme(struct net_device *dev, 6749 struct iw_request_info *info, 6750 union iwreq_data *wrqu, char *extra) 6751 { 6752 struct ipw_priv *priv = libipw_priv(dev); 6753 struct iw_mlme *mlme = (struct iw_mlme *)extra; 6754 6755 switch (mlme->cmd) { 6756 case IW_MLME_DEAUTH: 6757 /* silently ignore */ 6758 break; 6759 6760 case IW_MLME_DISASSOC: 6761 ipw_disassociate(priv); 6762 break; 6763 6764 default: 6765 return -EOPNOTSUPP; 6766 } 6767 return 0; 6768 } 6769 6770 #ifdef CONFIG_IPW2200_QOS 6771 6772 /* QoS */ 6773 /* 6774 * get the modulation type of the current network or 6775 * the card current mode 6776 */ 6777 static u8 ipw_qos_current_mode(struct ipw_priv * priv) 6778 { 6779 u8 mode = 0; 6780 6781 if (priv->status & STATUS_ASSOCIATED) { 6782 unsigned long flags; 6783 6784 spin_lock_irqsave(&priv->ieee->lock, flags); 6785 mode = priv->assoc_network->mode; 6786 spin_unlock_irqrestore(&priv->ieee->lock, flags); 6787 } else { 6788 mode = priv->ieee->mode; 6789 } 6790 IPW_DEBUG_QOS("QoS network/card mode %d\n", mode); 6791 return mode; 6792 } 6793 6794 /* 6795 * Handle management frame beacon and probe response 6796 */ 6797 static int ipw_qos_handle_probe_response(struct ipw_priv *priv, 6798 int active_network, 6799 struct libipw_network *network) 6800 { 6801 u32 size = sizeof(struct libipw_qos_parameters); 6802 6803 if (network->capability & WLAN_CAPABILITY_IBSS) 6804 network->qos_data.active = network->qos_data.supported; 6805 6806 if (network->flags & NETWORK_HAS_QOS_MASK) { 6807 if (active_network && 6808 (network->flags & NETWORK_HAS_QOS_PARAMETERS)) 6809 network->qos_data.active = network->qos_data.supported; 6810 6811 if ((network->qos_data.active == 1) && (active_network == 1) && 6812 (network->flags & NETWORK_HAS_QOS_PARAMETERS) && 6813 (network->qos_data.old_param_count != 6814 network->qos_data.param_count)) { 6815 network->qos_data.old_param_count = 6816 network->qos_data.param_count; 6817 schedule_work(&priv->qos_activate); 6818 IPW_DEBUG_QOS("QoS parameters change call " 6819 "qos_activate\n"); 6820 } 6821 } else { 6822 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) 6823 memcpy(&network->qos_data.parameters, 6824 &def_parameters_CCK, size); 6825 else 6826 memcpy(&network->qos_data.parameters, 6827 &def_parameters_OFDM, size); 6828 6829 if ((network->qos_data.active == 1) && (active_network == 1)) { 6830 IPW_DEBUG_QOS("QoS was disabled call qos_activate\n"); 6831 schedule_work(&priv->qos_activate); 6832 } 6833 6834 network->qos_data.active = 0; 6835 network->qos_data.supported = 0; 6836 } 6837 if ((priv->status & STATUS_ASSOCIATED) && 6838 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { 6839 if (!ether_addr_equal(network->bssid, priv->bssid)) 6840 if (network->capability & WLAN_CAPABILITY_IBSS) 6841 if ((network->ssid_len == 6842 priv->assoc_network->ssid_len) && 6843 !memcmp(network->ssid, 6844 priv->assoc_network->ssid, 6845 network->ssid_len)) { 6846 schedule_work(&priv->merge_networks); 6847 } 6848 } 6849 6850 return 0; 6851 } 6852 6853 /* 6854 * This function set up the firmware to support QoS. It sends 6855 * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO 6856 */ 6857 static int ipw_qos_activate(struct ipw_priv *priv, 6858 struct libipw_qos_data *qos_network_data) 6859 { 6860 int err; 6861 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS]; 6862 struct libipw_qos_parameters *active_one = NULL; 6863 u32 size = sizeof(struct libipw_qos_parameters); 6864 u32 burst_duration; 6865 int i; 6866 u8 type; 6867 6868 type = ipw_qos_current_mode(priv); 6869 6870 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); 6871 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); 6872 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); 6873 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); 6874 6875 if (qos_network_data == NULL) { 6876 if (type == IEEE_B) { 6877 IPW_DEBUG_QOS("QoS activate network mode %d\n", type); 6878 active_one = &def_parameters_CCK; 6879 } else 6880 active_one = &def_parameters_OFDM; 6881 6882 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); 6883 burst_duration = ipw_qos_get_burst_duration(priv); 6884 for (i = 0; i < QOS_QUEUE_NUM; i++) 6885 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = 6886 cpu_to_le16(burst_duration); 6887 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { 6888 if (type == IEEE_B) { 6889 IPW_DEBUG_QOS("QoS activate IBSS network mode %d\n", 6890 type); 6891 if (priv->qos_data.qos_enable == 0) 6892 active_one = &def_parameters_CCK; 6893 else 6894 active_one = priv->qos_data.def_qos_parm_CCK; 6895 } else { 6896 if (priv->qos_data.qos_enable == 0) 6897 active_one = &def_parameters_OFDM; 6898 else 6899 active_one = priv->qos_data.def_qos_parm_OFDM; 6900 } 6901 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); 6902 } else { 6903 unsigned long flags; 6904 int active; 6905 6906 spin_lock_irqsave(&priv->ieee->lock, flags); 6907 active_one = &(qos_network_data->parameters); 6908 qos_network_data->old_param_count = 6909 qos_network_data->param_count; 6910 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); 6911 active = qos_network_data->supported; 6912 spin_unlock_irqrestore(&priv->ieee->lock, flags); 6913 6914 if (active == 0) { 6915 burst_duration = ipw_qos_get_burst_duration(priv); 6916 for (i = 0; i < QOS_QUEUE_NUM; i++) 6917 qos_parameters[QOS_PARAM_SET_ACTIVE]. 6918 tx_op_limit[i] = cpu_to_le16(burst_duration); 6919 } 6920 } 6921 6922 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); 6923 err = ipw_send_qos_params_command(priv, &qos_parameters[0]); 6924 if (err) 6925 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); 6926 6927 return err; 6928 } 6929 6930 /* 6931 * send IPW_CMD_WME_INFO to the firmware 6932 */ 6933 static int ipw_qos_set_info_element(struct ipw_priv *priv) 6934 { 6935 int ret = 0; 6936 struct libipw_qos_information_element qos_info; 6937 6938 if (priv == NULL) 6939 return -1; 6940 6941 qos_info.elementID = QOS_ELEMENT_ID; 6942 qos_info.length = sizeof(struct libipw_qos_information_element) - 2; 6943 6944 qos_info.version = QOS_VERSION_1; 6945 qos_info.ac_info = 0; 6946 6947 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); 6948 qos_info.qui_type = QOS_OUI_TYPE; 6949 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; 6950 6951 ret = ipw_send_qos_info_command(priv, &qos_info); 6952 if (ret != 0) { 6953 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); 6954 } 6955 return ret; 6956 } 6957 6958 /* 6959 * Set the QoS parameter with the association request structure 6960 */ 6961 static int ipw_qos_association(struct ipw_priv *priv, 6962 struct libipw_network *network) 6963 { 6964 int err = 0; 6965 struct libipw_qos_data *qos_data = NULL; 6966 struct libipw_qos_data ibss_data = { 6967 .supported = 1, 6968 .active = 1, 6969 }; 6970 6971 switch (priv->ieee->iw_mode) { 6972 case IW_MODE_ADHOC: 6973 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS)); 6974 6975 qos_data = &ibss_data; 6976 break; 6977 6978 case IW_MODE_INFRA: 6979 qos_data = &network->qos_data; 6980 break; 6981 6982 default: 6983 BUG(); 6984 break; 6985 } 6986 6987 err = ipw_qos_activate(priv, qos_data); 6988 if (err) { 6989 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; 6990 return err; 6991 } 6992 6993 if (priv->qos_data.qos_enable && qos_data->supported) { 6994 IPW_DEBUG_QOS("QoS will be enabled for this association\n"); 6995 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; 6996 return ipw_qos_set_info_element(priv); 6997 } 6998 6999 return 0; 7000 } 7001 7002 /* 7003 * handling the beaconing responses. if we get different QoS setting 7004 * off the network from the associated setting, adjust the QoS 7005 * setting 7006 */ 7007 static void ipw_qos_association_resp(struct ipw_priv *priv, 7008 struct libipw_network *network) 7009 { 7010 unsigned long flags; 7011 u32 size = sizeof(struct libipw_qos_parameters); 7012 int set_qos_param = 0; 7013 7014 if ((priv == NULL) || (network == NULL) || 7015 (priv->assoc_network == NULL)) 7016 return; 7017 7018 if (!(priv->status & STATUS_ASSOCIATED)) 7019 return; 7020 7021 if ((priv->ieee->iw_mode != IW_MODE_INFRA)) 7022 return; 7023 7024 spin_lock_irqsave(&priv->ieee->lock, flags); 7025 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { 7026 memcpy(&priv->assoc_network->qos_data, &network->qos_data, 7027 sizeof(struct libipw_qos_data)); 7028 priv->assoc_network->qos_data.active = 1; 7029 if ((network->qos_data.old_param_count != 7030 network->qos_data.param_count)) { 7031 set_qos_param = 1; 7032 network->qos_data.old_param_count = 7033 network->qos_data.param_count; 7034 } 7035 7036 } else { 7037 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) 7038 memcpy(&priv->assoc_network->qos_data.parameters, 7039 &def_parameters_CCK, size); 7040 else 7041 memcpy(&priv->assoc_network->qos_data.parameters, 7042 &def_parameters_OFDM, size); 7043 priv->assoc_network->qos_data.active = 0; 7044 priv->assoc_network->qos_data.supported = 0; 7045 set_qos_param = 1; 7046 } 7047 7048 spin_unlock_irqrestore(&priv->ieee->lock, flags); 7049 7050 if (set_qos_param == 1) 7051 schedule_work(&priv->qos_activate); 7052 } 7053 7054 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) 7055 { 7056 u32 ret = 0; 7057 7058 if (!priv) 7059 return 0; 7060 7061 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION)) 7062 ret = priv->qos_data.burst_duration_CCK; 7063 else 7064 ret = priv->qos_data.burst_duration_OFDM; 7065 7066 return ret; 7067 } 7068 7069 /* 7070 * Initialize the setting of QoS global 7071 */ 7072 static void ipw_qos_init(struct ipw_priv *priv, int enable, 7073 int burst_enable, u32 burst_duration_CCK, 7074 u32 burst_duration_OFDM) 7075 { 7076 priv->qos_data.qos_enable = enable; 7077 7078 if (priv->qos_data.qos_enable) { 7079 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; 7080 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; 7081 IPW_DEBUG_QOS("QoS is enabled\n"); 7082 } else { 7083 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; 7084 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; 7085 IPW_DEBUG_QOS("QoS is not enabled\n"); 7086 } 7087 7088 priv->qos_data.burst_enable = burst_enable; 7089 7090 if (burst_enable) { 7091 priv->qos_data.burst_duration_CCK = burst_duration_CCK; 7092 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; 7093 } else { 7094 priv->qos_data.burst_duration_CCK = 0; 7095 priv->qos_data.burst_duration_OFDM = 0; 7096 } 7097 } 7098 7099 /* 7100 * map the packet priority to the right TX Queue 7101 */ 7102 static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) 7103 { 7104 if (priority > 7 || !priv->qos_data.qos_enable) 7105 priority = 0; 7106 7107 return from_priority_to_tx_queue[priority] - 1; 7108 } 7109 7110 static int ipw_is_qos_active(struct net_device *dev, 7111 struct sk_buff *skb) 7112 { 7113 struct ipw_priv *priv = libipw_priv(dev); 7114 struct libipw_qos_data *qos_data = NULL; 7115 int active, supported; 7116 u8 *daddr = skb->data + ETH_ALEN; 7117 int unicast = !is_multicast_ether_addr(daddr); 7118 7119 if (!(priv->status & STATUS_ASSOCIATED)) 7120 return 0; 7121 7122 qos_data = &priv->assoc_network->qos_data; 7123 7124 if (priv->ieee->iw_mode == IW_MODE_ADHOC) { 7125 if (unicast == 0) 7126 qos_data->active = 0; 7127 else 7128 qos_data->active = qos_data->supported; 7129 } 7130 active = qos_data->active; 7131 supported = qos_data->supported; 7132 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " 7133 "unicast %d\n", 7134 priv->qos_data.qos_enable, active, supported, unicast); 7135 if (active && priv->qos_data.qos_enable) 7136 return 1; 7137 7138 return 0; 7139 7140 } 7141 /* 7142 * add QoS parameter to the TX command 7143 */ 7144 static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, 7145 u16 priority, 7146 struct tfd_data *tfd) 7147 { 7148 int tx_queue_id = 0; 7149 7150 7151 tx_queue_id = from_priority_to_tx_queue[priority] - 1; 7152 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; 7153 7154 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) { 7155 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; 7156 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK); 7157 } 7158 return 0; 7159 } 7160 7161 /* 7162 * background support to run QoS activate functionality 7163 */ 7164 static void ipw_bg_qos_activate(struct work_struct *work) 7165 { 7166 struct ipw_priv *priv = 7167 container_of(work, struct ipw_priv, qos_activate); 7168 7169 mutex_lock(&priv->mutex); 7170 7171 if (priv->status & STATUS_ASSOCIATED) 7172 ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); 7173 7174 mutex_unlock(&priv->mutex); 7175 } 7176 7177 static int ipw_handle_probe_response(struct net_device *dev, 7178 struct libipw_probe_response *resp, 7179 struct libipw_network *network) 7180 { 7181 struct ipw_priv *priv = libipw_priv(dev); 7182 int active_network = ((priv->status & STATUS_ASSOCIATED) && 7183 (network == priv->assoc_network)); 7184 7185 ipw_qos_handle_probe_response(priv, active_network, network); 7186 7187 return 0; 7188 } 7189 7190 static int ipw_handle_beacon(struct net_device *dev, 7191 struct libipw_beacon *resp, 7192 struct libipw_network *network) 7193 { 7194 struct ipw_priv *priv = libipw_priv(dev); 7195 int active_network = ((priv->status & STATUS_ASSOCIATED) && 7196 (network == priv->assoc_network)); 7197 7198 ipw_qos_handle_probe_response(priv, active_network, network); 7199 7200 return 0; 7201 } 7202 7203 static int ipw_handle_assoc_response(struct net_device *dev, 7204 struct libipw_assoc_response *resp, 7205 struct libipw_network *network) 7206 { 7207 struct ipw_priv *priv = libipw_priv(dev); 7208 ipw_qos_association_resp(priv, network); 7209 return 0; 7210 } 7211 7212 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters 7213 *qos_param) 7214 { 7215 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, 7216 sizeof(*qos_param) * 3, qos_param); 7217 } 7218 7219 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element 7220 *qos_param) 7221 { 7222 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), 7223 qos_param); 7224 } 7225 7226 #endif /* CONFIG_IPW2200_QOS */ 7227 7228 static int ipw_associate_network(struct ipw_priv *priv, 7229 struct libipw_network *network, 7230 struct ipw_supported_rates *rates, int roaming) 7231 { 7232 int err; 7233 7234 if (priv->config & CFG_FIXED_RATE) 7235 ipw_set_fixed_rate(priv, network->mode); 7236 7237 if (!(priv->config & CFG_STATIC_ESSID)) { 7238 priv->essid_len = min(network->ssid_len, 7239 (u8) IW_ESSID_MAX_SIZE); 7240 memcpy(priv->essid, network->ssid, priv->essid_len); 7241 } 7242 7243 network->last_associate = jiffies; 7244 7245 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); 7246 priv->assoc_request.channel = network->channel; 7247 priv->assoc_request.auth_key = 0; 7248 7249 if ((priv->capability & CAP_PRIVACY_ON) && 7250 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { 7251 priv->assoc_request.auth_type = AUTH_SHARED_KEY; 7252 priv->assoc_request.auth_key = priv->ieee->sec.active_key; 7253 7254 if (priv->ieee->sec.level == SEC_LEVEL_1) 7255 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); 7256 7257 } else if ((priv->capability & CAP_PRIVACY_ON) && 7258 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) 7259 priv->assoc_request.auth_type = AUTH_LEAP; 7260 else 7261 priv->assoc_request.auth_type = AUTH_OPEN; 7262 7263 if (priv->ieee->wpa_ie_len) { 7264 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */ 7265 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, 7266 priv->ieee->wpa_ie_len); 7267 } 7268 7269 /* 7270 * It is valid for our ieee device to support multiple modes, but 7271 * when it comes to associating to a given network we have to choose 7272 * just one mode. 7273 */ 7274 if (network->mode & priv->ieee->mode & IEEE_A) 7275 priv->assoc_request.ieee_mode = IPW_A_MODE; 7276 else if (network->mode & priv->ieee->mode & IEEE_G) 7277 priv->assoc_request.ieee_mode = IPW_G_MODE; 7278 else if (network->mode & priv->ieee->mode & IEEE_B) 7279 priv->assoc_request.ieee_mode = IPW_B_MODE; 7280 7281 priv->assoc_request.capability = cpu_to_le16(network->capability); 7282 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) 7283 && !(priv->config & CFG_PREAMBLE_LONG)) { 7284 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; 7285 } else { 7286 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; 7287 7288 /* Clear the short preamble if we won't be supporting it */ 7289 priv->assoc_request.capability &= 7290 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); 7291 } 7292 7293 /* Clear capability bits that aren't used in Ad Hoc */ 7294 if (priv->ieee->iw_mode == IW_MODE_ADHOC) 7295 priv->assoc_request.capability &= 7296 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); 7297 7298 IPW_DEBUG_ASSOC("%ssociation attempt: '%*pE', channel %d, 802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n", 7299 roaming ? "Rea" : "A", 7300 priv->essid_len, priv->essid, 7301 network->channel, 7302 ipw_modes[priv->assoc_request.ieee_mode], 7303 rates->num_rates, 7304 (priv->assoc_request.preamble_length == 7305 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", 7306 network->capability & 7307 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", 7308 priv->capability & CAP_PRIVACY_ON ? "on " : "off", 7309 priv->capability & CAP_PRIVACY_ON ? 7310 (priv->capability & CAP_SHARED_KEY ? "(shared)" : 7311 "(open)") : "", 7312 priv->capability & CAP_PRIVACY_ON ? " key=" : "", 7313 priv->capability & CAP_PRIVACY_ON ? 7314 '1' + priv->ieee->sec.active_key : '.', 7315 priv->capability & CAP_PRIVACY_ON ? '.' : ' '); 7316 7317 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval); 7318 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && 7319 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { 7320 priv->assoc_request.assoc_type = HC_IBSS_START; 7321 priv->assoc_request.assoc_tsf_msw = 0; 7322 priv->assoc_request.assoc_tsf_lsw = 0; 7323 } else { 7324 if (unlikely(roaming)) 7325 priv->assoc_request.assoc_type = HC_REASSOCIATE; 7326 else 7327 priv->assoc_request.assoc_type = HC_ASSOCIATE; 7328 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]); 7329 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]); 7330 } 7331 7332 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); 7333 7334 if (priv->ieee->iw_mode == IW_MODE_ADHOC) { 7335 eth_broadcast_addr(priv->assoc_request.dest); 7336 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window); 7337 } else { 7338 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); 7339 priv->assoc_request.atim_window = 0; 7340 } 7341 7342 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval); 7343 7344 err = ipw_send_ssid(priv, priv->essid, priv->essid_len); 7345 if (err) { 7346 IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); 7347 return err; 7348 } 7349 7350 rates->ieee_mode = priv->assoc_request.ieee_mode; 7351 rates->purpose = IPW_RATE_CONNECT; 7352 ipw_send_supported_rates(priv, rates); 7353 7354 if (priv->assoc_request.ieee_mode == IPW_G_MODE) 7355 priv->sys_config.dot11g_auto_detection = 1; 7356 else 7357 priv->sys_config.dot11g_auto_detection = 0; 7358 7359 if (priv->ieee->iw_mode == IW_MODE_ADHOC) 7360 priv->sys_config.answer_broadcast_ssid_probe = 1; 7361 else 7362 priv->sys_config.answer_broadcast_ssid_probe = 0; 7363 7364 err = ipw_send_system_config(priv); 7365 if (err) { 7366 IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); 7367 return err; 7368 } 7369 7370 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); 7371 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); 7372 if (err) { 7373 IPW_DEBUG_HC("Attempt to send associate command failed.\n"); 7374 return err; 7375 } 7376 7377 /* 7378 * If preemption is enabled, it is possible for the association 7379 * to complete before we return from ipw_send_associate. Therefore 7380 * we have to be sure and update our priviate data first. 7381 */ 7382 priv->channel = network->channel; 7383 memcpy(priv->bssid, network->bssid, ETH_ALEN); 7384 priv->status |= STATUS_ASSOCIATING; 7385 priv->status &= ~STATUS_SECURITY_UPDATED; 7386 7387 priv->assoc_network = network; 7388 7389 #ifdef CONFIG_IPW2200_QOS 7390 ipw_qos_association(priv, network); 7391 #endif 7392 7393 err = ipw_send_associate(priv, &priv->assoc_request); 7394 if (err) { 7395 IPW_DEBUG_HC("Attempt to send associate command failed.\n"); 7396 return err; 7397 } 7398 7399 IPW_DEBUG(IPW_DL_STATE, "associating: '%*pE' %pM\n", 7400 priv->essid_len, priv->essid, priv->bssid); 7401 7402 return 0; 7403 } 7404 7405 static void ipw_roam(void *data) 7406 { 7407 struct ipw_priv *priv = data; 7408 struct libipw_network *network = NULL; 7409 struct ipw_network_match match = { 7410 .network = priv->assoc_network 7411 }; 7412 7413 /* The roaming process is as follows: 7414 * 7415 * 1. Missed beacon threshold triggers the roaming process by 7416 * setting the status ROAM bit and requesting a scan. 7417 * 2. When the scan completes, it schedules the ROAM work 7418 * 3. The ROAM work looks at all of the known networks for one that 7419 * is a better network than the currently associated. If none 7420 * found, the ROAM process is over (ROAM bit cleared) 7421 * 4. If a better network is found, a disassociation request is 7422 * sent. 7423 * 5. When the disassociation completes, the roam work is again 7424 * scheduled. The second time through, the driver is no longer 7425 * associated, and the newly selected network is sent an 7426 * association request. 7427 * 6. At this point ,the roaming process is complete and the ROAM 7428 * status bit is cleared. 7429 */ 7430 7431 /* If we are no longer associated, and the roaming bit is no longer 7432 * set, then we are not actively roaming, so just return */ 7433 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) 7434 return; 7435 7436 if (priv->status & STATUS_ASSOCIATED) { 7437 /* First pass through ROAM process -- look for a better 7438 * network */ 7439 unsigned long flags; 7440 u8 rssi = priv->assoc_network->stats.rssi; 7441 priv->assoc_network->stats.rssi = -128; 7442 spin_lock_irqsave(&priv->ieee->lock, flags); 7443 list_for_each_entry(network, &priv->ieee->network_list, list) { 7444 if (network != priv->assoc_network) 7445 ipw_best_network(priv, &match, network, 1); 7446 } 7447 spin_unlock_irqrestore(&priv->ieee->lock, flags); 7448 priv->assoc_network->stats.rssi = rssi; 7449 7450 if (match.network == priv->assoc_network) { 7451 IPW_DEBUG_ASSOC("No better APs in this network to " 7452 "roam to.\n"); 7453 priv->status &= ~STATUS_ROAMING; 7454 ipw_debug_config(priv); 7455 return; 7456 } 7457 7458 ipw_send_disassociate(priv, 1); 7459 priv->assoc_network = match.network; 7460 7461 return; 7462 } 7463 7464 /* Second pass through ROAM process -- request association */ 7465 ipw_compatible_rates(priv, priv->assoc_network, &match.rates); 7466 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); 7467 priv->status &= ~STATUS_ROAMING; 7468 } 7469 7470 static void ipw_bg_roam(struct work_struct *work) 7471 { 7472 struct ipw_priv *priv = 7473 container_of(work, struct ipw_priv, roam); 7474 mutex_lock(&priv->mutex); 7475 ipw_roam(priv); 7476 mutex_unlock(&priv->mutex); 7477 } 7478 7479 static int ipw_associate(void *data) 7480 { 7481 struct ipw_priv *priv = data; 7482 7483 struct libipw_network *network = NULL; 7484 struct ipw_network_match match = { 7485 .network = NULL 7486 }; 7487 struct ipw_supported_rates *rates; 7488 struct list_head *element; 7489 unsigned long flags; 7490 7491 if (priv->ieee->iw_mode == IW_MODE_MONITOR) { 7492 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); 7493 return 0; 7494 } 7495 7496 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { 7497 IPW_DEBUG_ASSOC("Not attempting association (already in " 7498 "progress)\n"); 7499 return 0; 7500 } 7501 7502 if (priv->status & STATUS_DISASSOCIATING) { 7503 IPW_DEBUG_ASSOC("Not attempting association (in disassociating)\n"); 7504 schedule_work(&priv->associate); 7505 return 0; 7506 } 7507 7508 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { 7509 IPW_DEBUG_ASSOC("Not attempting association (scanning or not " 7510 "initialized)\n"); 7511 return 0; 7512 } 7513 7514 if (!(priv->config & CFG_ASSOCIATE) && 7515 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) { 7516 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); 7517 return 0; 7518 } 7519 7520 /* Protect our use of the network_list */ 7521 spin_lock_irqsave(&priv->ieee->lock, flags); 7522 list_for_each_entry(network, &priv->ieee->network_list, list) 7523 ipw_best_network(priv, &match, network, 0); 7524 7525 network = match.network; 7526 rates = &match.rates; 7527 7528 if (network == NULL && 7529 priv->ieee->iw_mode == IW_MODE_ADHOC && 7530 priv->config & CFG_ADHOC_CREATE && 7531 priv->config & CFG_STATIC_ESSID && 7532 priv->config & CFG_STATIC_CHANNEL) { 7533 /* Use oldest network if the free list is empty */ 7534 if (list_empty(&priv->ieee->network_free_list)) { 7535 struct libipw_network *oldest = NULL; 7536 struct libipw_network *target; 7537 7538 list_for_each_entry(target, &priv->ieee->network_list, list) { 7539 if ((oldest == NULL) || 7540 (target->last_scanned < oldest->last_scanned)) 7541 oldest = target; 7542 } 7543 7544 /* If there are no more slots, expire the oldest */ 7545 list_del(&oldest->list); 7546 target = oldest; 7547 IPW_DEBUG_ASSOC("Expired '%*pE' (%pM) from network list.\n", 7548 target->ssid_len, target->ssid, 7549 target->bssid); 7550 list_add_tail(&target->list, 7551 &priv->ieee->network_free_list); 7552 } 7553 7554 element = priv->ieee->network_free_list.next; 7555 network = list_entry(element, struct libipw_network, list); 7556 ipw_adhoc_create(priv, network); 7557 rates = &priv->rates; 7558 list_del(element); 7559 list_add_tail(&network->list, &priv->ieee->network_list); 7560 } 7561 spin_unlock_irqrestore(&priv->ieee->lock, flags); 7562 7563 /* If we reached the end of the list, then we don't have any valid 7564 * matching APs */ 7565 if (!network) { 7566 ipw_debug_config(priv); 7567 7568 if (!(priv->status & STATUS_SCANNING)) { 7569 if (!(priv->config & CFG_SPEED_SCAN)) 7570 schedule_delayed_work(&priv->request_scan, 7571 SCAN_INTERVAL); 7572 else 7573 schedule_delayed_work(&priv->request_scan, 0); 7574 } 7575 7576 return 0; 7577 } 7578 7579 ipw_associate_network(priv, network, rates, 0); 7580 7581 return 1; 7582 } 7583 7584 static void ipw_bg_associate(struct work_struct *work) 7585 { 7586 struct ipw_priv *priv = 7587 container_of(work, struct ipw_priv, associate); 7588 mutex_lock(&priv->mutex); 7589 ipw_associate(priv); 7590 mutex_unlock(&priv->mutex); 7591 } 7592 7593 static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, 7594 struct sk_buff *skb) 7595 { 7596 struct ieee80211_hdr *hdr; 7597 u16 fc; 7598 7599 hdr = (struct ieee80211_hdr *)skb->data; 7600 fc = le16_to_cpu(hdr->frame_control); 7601 if (!(fc & IEEE80211_FCTL_PROTECTED)) 7602 return; 7603 7604 fc &= ~IEEE80211_FCTL_PROTECTED; 7605 hdr->frame_control = cpu_to_le16(fc); 7606 switch (priv->ieee->sec.level) { 7607 case SEC_LEVEL_3: 7608 /* Remove CCMP HDR */ 7609 memmove(skb->data + LIBIPW_3ADDR_LEN, 7610 skb->data + LIBIPW_3ADDR_LEN + 8, 7611 skb->len - LIBIPW_3ADDR_LEN - 8); 7612 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ 7613 break; 7614 case SEC_LEVEL_2: 7615 break; 7616 case SEC_LEVEL_1: 7617 /* Remove IV */ 7618 memmove(skb->data + LIBIPW_3ADDR_LEN, 7619 skb->data + LIBIPW_3ADDR_LEN + 4, 7620 skb->len - LIBIPW_3ADDR_LEN - 4); 7621 skb_trim(skb, skb->len - 8); /* IV + ICV */ 7622 break; 7623 case SEC_LEVEL_0: 7624 break; 7625 default: 7626 printk(KERN_ERR "Unknown security level %d\n", 7627 priv->ieee->sec.level); 7628 break; 7629 } 7630 } 7631 7632 static void ipw_handle_data_packet(struct ipw_priv *priv, 7633 struct ipw_rx_mem_buffer *rxb, 7634 struct libipw_rx_stats *stats) 7635 { 7636 struct net_device *dev = priv->net_dev; 7637 struct libipw_hdr_4addr *hdr; 7638 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; 7639 7640 /* We received data from the HW, so stop the watchdog */ 7641 netif_trans_update(dev); 7642 7643 /* We only process data packets if the 7644 * interface is open */ 7645 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > 7646 skb_tailroom(rxb->skb))) { 7647 dev->stats.rx_errors++; 7648 priv->wstats.discard.misc++; 7649 IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); 7650 return; 7651 } else if (unlikely(!netif_running(priv->net_dev))) { 7652 dev->stats.rx_dropped++; 7653 priv->wstats.discard.misc++; 7654 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); 7655 return; 7656 } 7657 7658 /* Advance skb->data to the start of the actual payload */ 7659 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); 7660 7661 /* Set the size of the skb to the size of the frame */ 7662 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); 7663 7664 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); 7665 7666 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ 7667 hdr = (struct libipw_hdr_4addr *)rxb->skb->data; 7668 if (priv->ieee->iw_mode != IW_MODE_MONITOR && 7669 (is_multicast_ether_addr(hdr->addr1) ? 7670 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) 7671 ipw_rebuild_decrypted_skb(priv, rxb->skb); 7672 7673 if (!libipw_rx(priv->ieee, rxb->skb, stats)) 7674 dev->stats.rx_errors++; 7675 else { /* libipw_rx succeeded, so it now owns the SKB */ 7676 rxb->skb = NULL; 7677 __ipw_led_activity_on(priv); 7678 } 7679 } 7680 7681 #ifdef CONFIG_IPW2200_RADIOTAP 7682 static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, 7683 struct ipw_rx_mem_buffer *rxb, 7684 struct libipw_rx_stats *stats) 7685 { 7686 struct net_device *dev = priv->net_dev; 7687 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; 7688 struct ipw_rx_frame *frame = &pkt->u.frame; 7689 7690 /* initial pull of some data */ 7691 u16 received_channel = frame->received_channel; 7692 u8 antennaAndPhy = frame->antennaAndPhy; 7693 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ 7694 u16 pktrate = frame->rate; 7695 7696 /* Magic struct that slots into the radiotap header -- no reason 7697 * to build this manually element by element, we can write it much 7698 * more efficiently than we can parse it. ORDER MATTERS HERE */ 7699 struct ipw_rt_hdr *ipw_rt; 7700 7701 unsigned short len = le16_to_cpu(pkt->u.frame.length); 7702 7703 /* We received data from the HW, so stop the watchdog */ 7704 netif_trans_update(dev); 7705 7706 /* We only process data packets if the 7707 * interface is open */ 7708 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > 7709 skb_tailroom(rxb->skb))) { 7710 dev->stats.rx_errors++; 7711 priv->wstats.discard.misc++; 7712 IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); 7713 return; 7714 } else if (unlikely(!netif_running(priv->net_dev))) { 7715 dev->stats.rx_dropped++; 7716 priv->wstats.discard.misc++; 7717 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); 7718 return; 7719 } 7720 7721 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use 7722 * that now */ 7723 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { 7724 /* FIXME: Should alloc bigger skb instead */ 7725 dev->stats.rx_dropped++; 7726 priv->wstats.discard.misc++; 7727 IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); 7728 return; 7729 } 7730 7731 /* copy the frame itself */ 7732 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), 7733 rxb->skb->data + IPW_RX_FRAME_SIZE, len); 7734 7735 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; 7736 7737 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; 7738 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ 7739 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */ 7740 7741 /* Big bitfield of all the fields we provide in radiotap */ 7742 ipw_rt->rt_hdr.it_present = cpu_to_le32( 7743 (1 << IEEE80211_RADIOTAP_TSFT) | 7744 (1 << IEEE80211_RADIOTAP_FLAGS) | 7745 (1 << IEEE80211_RADIOTAP_RATE) | 7746 (1 << IEEE80211_RADIOTAP_CHANNEL) | 7747 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | 7748 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | 7749 (1 << IEEE80211_RADIOTAP_ANTENNA)); 7750 7751 /* Zero the flags, we'll add to them as we go */ 7752 ipw_rt->rt_flags = 0; 7753 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | 7754 frame->parent_tsf[2] << 16 | 7755 frame->parent_tsf[1] << 8 | 7756 frame->parent_tsf[0]); 7757 7758 /* Convert signal to DBM */ 7759 ipw_rt->rt_dbmsignal = antsignal; 7760 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise); 7761 7762 /* Convert the channel data and set the flags */ 7763 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); 7764 if (received_channel > 14) { /* 802.11a */ 7765 ipw_rt->rt_chbitmask = 7766 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); 7767 } else if (antennaAndPhy & 32) { /* 802.11b */ 7768 ipw_rt->rt_chbitmask = 7769 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); 7770 } else { /* 802.11g */ 7771 ipw_rt->rt_chbitmask = 7772 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); 7773 } 7774 7775 /* set the rate in multiples of 500k/s */ 7776 switch (pktrate) { 7777 case IPW_TX_RATE_1MB: 7778 ipw_rt->rt_rate = 2; 7779 break; 7780 case IPW_TX_RATE_2MB: 7781 ipw_rt->rt_rate = 4; 7782 break; 7783 case IPW_TX_RATE_5MB: 7784 ipw_rt->rt_rate = 10; 7785 break; 7786 case IPW_TX_RATE_6MB: 7787 ipw_rt->rt_rate = 12; 7788 break; 7789 case IPW_TX_RATE_9MB: 7790 ipw_rt->rt_rate = 18; 7791 break; 7792 case IPW_TX_RATE_11MB: 7793 ipw_rt->rt_rate = 22; 7794 break; 7795 case IPW_TX_RATE_12MB: 7796 ipw_rt->rt_rate = 24; 7797 break; 7798 case IPW_TX_RATE_18MB: 7799 ipw_rt->rt_rate = 36; 7800 break; 7801 case IPW_TX_RATE_24MB: 7802 ipw_rt->rt_rate = 48; 7803 break; 7804 case IPW_TX_RATE_36MB: 7805 ipw_rt->rt_rate = 72; 7806 break; 7807 case IPW_TX_RATE_48MB: 7808 ipw_rt->rt_rate = 96; 7809 break; 7810 case IPW_TX_RATE_54MB: 7811 ipw_rt->rt_rate = 108; 7812 break; 7813 default: 7814 ipw_rt->rt_rate = 0; 7815 break; 7816 } 7817 7818 /* antenna number */ 7819 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ 7820 7821 /* set the preamble flag if we have it */ 7822 if ((antennaAndPhy & 64)) 7823 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 7824 7825 /* Set the size of the skb to the size of the frame */ 7826 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); 7827 7828 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); 7829 7830 if (!libipw_rx(priv->ieee, rxb->skb, stats)) 7831 dev->stats.rx_errors++; 7832 else { /* libipw_rx succeeded, so it now owns the SKB */ 7833 rxb->skb = NULL; 7834 /* no LED during capture */ 7835 } 7836 } 7837 #endif 7838 7839 #ifdef CONFIG_IPW2200_PROMISCUOUS 7840 #define libipw_is_probe_response(fc) \ 7841 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \ 7842 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP ) 7843 7844 #define libipw_is_management(fc) \ 7845 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) 7846 7847 #define libipw_is_control(fc) \ 7848 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) 7849 7850 #define libipw_is_data(fc) \ 7851 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) 7852 7853 #define libipw_is_assoc_request(fc) \ 7854 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ) 7855 7856 #define libipw_is_reassoc_request(fc) \ 7857 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) 7858 7859 static void ipw_handle_promiscuous_rx(struct ipw_priv *priv, 7860 struct ipw_rx_mem_buffer *rxb, 7861 struct libipw_rx_stats *stats) 7862 { 7863 struct net_device *dev = priv->prom_net_dev; 7864 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; 7865 struct ipw_rx_frame *frame = &pkt->u.frame; 7866 struct ipw_rt_hdr *ipw_rt; 7867 7868 /* First cache any information we need before we overwrite 7869 * the information provided in the skb from the hardware */ 7870 struct ieee80211_hdr *hdr; 7871 u16 channel = frame->received_channel; 7872 u8 phy_flags = frame->antennaAndPhy; 7873 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM; 7874 s8 noise = (s8) le16_to_cpu(frame->noise); 7875 u8 rate = frame->rate; 7876 unsigned short len = le16_to_cpu(pkt->u.frame.length); 7877 struct sk_buff *skb; 7878 int hdr_only = 0; 7879 u16 filter = priv->prom_priv->filter; 7880 7881 /* If the filter is set to not include Rx frames then return */ 7882 if (filter & IPW_PROM_NO_RX) 7883 return; 7884 7885 /* We received data from the HW, so stop the watchdog */ 7886 netif_trans_update(dev); 7887 7888 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) { 7889 dev->stats.rx_errors++; 7890 IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); 7891 return; 7892 } 7893 7894 /* We only process data packets if the interface is open */ 7895 if (unlikely(!netif_running(dev))) { 7896 dev->stats.rx_dropped++; 7897 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); 7898 return; 7899 } 7900 7901 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use 7902 * that now */ 7903 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { 7904 /* FIXME: Should alloc bigger skb instead */ 7905 dev->stats.rx_dropped++; 7906 IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); 7907 return; 7908 } 7909 7910 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE; 7911 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { 7912 if (filter & IPW_PROM_NO_MGMT) 7913 return; 7914 if (filter & IPW_PROM_MGMT_HEADER_ONLY) 7915 hdr_only = 1; 7916 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { 7917 if (filter & IPW_PROM_NO_CTL) 7918 return; 7919 if (filter & IPW_PROM_CTL_HEADER_ONLY) 7920 hdr_only = 1; 7921 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { 7922 if (filter & IPW_PROM_NO_DATA) 7923 return; 7924 if (filter & IPW_PROM_DATA_HEADER_ONLY) 7925 hdr_only = 1; 7926 } 7927 7928 /* Copy the SKB since this is for the promiscuous side */ 7929 skb = skb_copy(rxb->skb, GFP_ATOMIC); 7930 if (skb == NULL) { 7931 IPW_ERROR("skb_clone failed for promiscuous copy.\n"); 7932 return; 7933 } 7934 7935 /* copy the frame data to write after where the radiotap header goes */ 7936 ipw_rt = (void *)skb->data; 7937 7938 if (hdr_only) 7939 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); 7940 7941 memcpy(ipw_rt->payload, hdr, len); 7942 7943 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; 7944 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ 7945 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */ 7946 7947 /* Set the size of the skb to the size of the frame */ 7948 skb_put(skb, sizeof(*ipw_rt) + len); 7949 7950 /* Big bitfield of all the fields we provide in radiotap */ 7951 ipw_rt->rt_hdr.it_present = cpu_to_le32( 7952 (1 << IEEE80211_RADIOTAP_TSFT) | 7953 (1 << IEEE80211_RADIOTAP_FLAGS) | 7954 (1 << IEEE80211_RADIOTAP_RATE) | 7955 (1 << IEEE80211_RADIOTAP_CHANNEL) | 7956 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | 7957 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | 7958 (1 << IEEE80211_RADIOTAP_ANTENNA)); 7959 7960 /* Zero the flags, we'll add to them as we go */ 7961 ipw_rt->rt_flags = 0; 7962 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | 7963 frame->parent_tsf[2] << 16 | 7964 frame->parent_tsf[1] << 8 | 7965 frame->parent_tsf[0]); 7966 7967 /* Convert to DBM */ 7968 ipw_rt->rt_dbmsignal = signal; 7969 ipw_rt->rt_dbmnoise = noise; 7970 7971 /* Convert the channel data and set the flags */ 7972 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel)); 7973 if (channel > 14) { /* 802.11a */ 7974 ipw_rt->rt_chbitmask = 7975 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); 7976 } else if (phy_flags & (1 << 5)) { /* 802.11b */ 7977 ipw_rt->rt_chbitmask = 7978 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); 7979 } else { /* 802.11g */ 7980 ipw_rt->rt_chbitmask = 7981 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); 7982 } 7983 7984 /* set the rate in multiples of 500k/s */ 7985 switch (rate) { 7986 case IPW_TX_RATE_1MB: 7987 ipw_rt->rt_rate = 2; 7988 break; 7989 case IPW_TX_RATE_2MB: 7990 ipw_rt->rt_rate = 4; 7991 break; 7992 case IPW_TX_RATE_5MB: 7993 ipw_rt->rt_rate = 10; 7994 break; 7995 case IPW_TX_RATE_6MB: 7996 ipw_rt->rt_rate = 12; 7997 break; 7998 case IPW_TX_RATE_9MB: 7999 ipw_rt->rt_rate = 18; 8000 break; 8001 case IPW_TX_RATE_11MB: 8002 ipw_rt->rt_rate = 22; 8003 break; 8004 case IPW_TX_RATE_12MB: 8005 ipw_rt->rt_rate = 24; 8006 break; 8007 case IPW_TX_RATE_18MB: 8008 ipw_rt->rt_rate = 36; 8009 break; 8010 case IPW_TX_RATE_24MB: 8011 ipw_rt->rt_rate = 48; 8012 break; 8013 case IPW_TX_RATE_36MB: 8014 ipw_rt->rt_rate = 72; 8015 break; 8016 case IPW_TX_RATE_48MB: 8017 ipw_rt->rt_rate = 96; 8018 break; 8019 case IPW_TX_RATE_54MB: 8020 ipw_rt->rt_rate = 108; 8021 break; 8022 default: 8023 ipw_rt->rt_rate = 0; 8024 break; 8025 } 8026 8027 /* antenna number */ 8028 ipw_rt->rt_antenna = (phy_flags & 3); 8029 8030 /* set the preamble flag if we have it */ 8031 if (phy_flags & (1 << 6)) 8032 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 8033 8034 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len); 8035 8036 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) { 8037 dev->stats.rx_errors++; 8038 dev_kfree_skb_any(skb); 8039 } 8040 } 8041 #endif 8042 8043 static int is_network_packet(struct ipw_priv *priv, 8044 struct libipw_hdr_4addr *header) 8045 { 8046 /* Filter incoming packets to determine if they are targeted toward 8047 * this network, discarding packets coming from ourselves */ 8048 switch (priv->ieee->iw_mode) { 8049 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ 8050 /* packets from our adapter are dropped (echo) */ 8051 if (ether_addr_equal(header->addr2, priv->net_dev->dev_addr)) 8052 return 0; 8053 8054 /* {broad,multi}cast packets to our BSSID go through */ 8055 if (is_multicast_ether_addr(header->addr1)) 8056 return ether_addr_equal(header->addr3, priv->bssid); 8057 8058 /* packets to our adapter go through */ 8059 return ether_addr_equal(header->addr1, 8060 priv->net_dev->dev_addr); 8061 8062 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ 8063 /* packets from our adapter are dropped (echo) */ 8064 if (ether_addr_equal(header->addr3, priv->net_dev->dev_addr)) 8065 return 0; 8066 8067 /* {broad,multi}cast packets to our BSS go through */ 8068 if (is_multicast_ether_addr(header->addr1)) 8069 return ether_addr_equal(header->addr2, priv->bssid); 8070 8071 /* packets to our adapter go through */ 8072 return ether_addr_equal(header->addr1, 8073 priv->net_dev->dev_addr); 8074 } 8075 8076 return 1; 8077 } 8078 8079 #define IPW_PACKET_RETRY_TIME HZ 8080 8081 static int is_duplicate_packet(struct ipw_priv *priv, 8082 struct libipw_hdr_4addr *header) 8083 { 8084 u16 sc = le16_to_cpu(header->seq_ctl); 8085 u16 seq = WLAN_GET_SEQ_SEQ(sc); 8086 u16 frag = WLAN_GET_SEQ_FRAG(sc); 8087 u16 *last_seq, *last_frag; 8088 unsigned long *last_time; 8089 8090 switch (priv->ieee->iw_mode) { 8091 case IW_MODE_ADHOC: 8092 { 8093 struct list_head *p; 8094 struct ipw_ibss_seq *entry = NULL; 8095 u8 *mac = header->addr2; 8096 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; 8097 8098 list_for_each(p, &priv->ibss_mac_hash[index]) { 8099 entry = 8100 list_entry(p, struct ipw_ibss_seq, list); 8101 if (ether_addr_equal(entry->mac, mac)) 8102 break; 8103 } 8104 if (p == &priv->ibss_mac_hash[index]) { 8105 entry = kmalloc_obj(*entry, GFP_ATOMIC); 8106 if (!entry) { 8107 IPW_ERROR 8108 ("Cannot malloc new mac entry\n"); 8109 return 0; 8110 } 8111 memcpy(entry->mac, mac, ETH_ALEN); 8112 entry->seq_num = seq; 8113 entry->frag_num = frag; 8114 entry->packet_time = jiffies; 8115 list_add(&entry->list, 8116 &priv->ibss_mac_hash[index]); 8117 return 0; 8118 } 8119 last_seq = &entry->seq_num; 8120 last_frag = &entry->frag_num; 8121 last_time = &entry->packet_time; 8122 break; 8123 } 8124 case IW_MODE_INFRA: 8125 last_seq = &priv->last_seq_num; 8126 last_frag = &priv->last_frag_num; 8127 last_time = &priv->last_packet_time; 8128 break; 8129 default: 8130 return 0; 8131 } 8132 if ((*last_seq == seq) && 8133 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { 8134 if (*last_frag == frag) 8135 goto drop; 8136 if (*last_frag + 1 != frag) 8137 /* out-of-order fragment */ 8138 goto drop; 8139 } else 8140 *last_seq = seq; 8141 8142 *last_frag = frag; 8143 *last_time = jiffies; 8144 return 0; 8145 8146 drop: 8147 /* Comment this line now since we observed the card receives 8148 * duplicate packets but the FCTL_RETRY bit is not set in the 8149 * IBSS mode with fragmentation enabled. 8150 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */ 8151 return 1; 8152 } 8153 8154 static void ipw_handle_mgmt_packet(struct ipw_priv *priv, 8155 struct ipw_rx_mem_buffer *rxb, 8156 struct libipw_rx_stats *stats) 8157 { 8158 struct sk_buff *skb = rxb->skb; 8159 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; 8160 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *) 8161 (skb->data + IPW_RX_FRAME_SIZE); 8162 8163 libipw_rx_mgt(priv->ieee, header, stats); 8164 8165 if (priv->ieee->iw_mode == IW_MODE_ADHOC && 8166 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == 8167 IEEE80211_STYPE_PROBE_RESP) || 8168 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == 8169 IEEE80211_STYPE_BEACON))) { 8170 if (ether_addr_equal(header->addr3, priv->bssid)) 8171 ipw_add_station(priv, header->addr2); 8172 } 8173 8174 if (priv->config & CFG_NET_STATS) { 8175 IPW_DEBUG_HC("sending stat packet\n"); 8176 8177 /* Set the size of the skb to the size of the full 8178 * ipw header and 802.11 frame */ 8179 skb_put(skb, le16_to_cpu(pkt->u.frame.length) + 8180 IPW_RX_FRAME_SIZE); 8181 8182 /* Advance past the ipw packet header to the 802.11 frame */ 8183 skb_pull(skb, IPW_RX_FRAME_SIZE); 8184 8185 /* Push the libipw_rx_stats before the 802.11 frame */ 8186 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); 8187 8188 skb->dev = priv->ieee->dev; 8189 8190 /* Point raw at the libipw_stats */ 8191 skb_reset_mac_header(skb); 8192 8193 skb->pkt_type = PACKET_OTHERHOST; 8194 skb->protocol = cpu_to_be16(ETH_P_80211_STATS); 8195 memset(skb->cb, 0, sizeof(rxb->skb->cb)); 8196 netif_rx(skb); 8197 rxb->skb = NULL; 8198 } 8199 } 8200 8201 /* 8202 * Main entry function for receiving a packet with 80211 headers. This 8203 * should be called when ever the FW has notified us that there is a new 8204 * skb in the receive queue. 8205 */ 8206 static void ipw_rx(struct ipw_priv *priv) 8207 { 8208 struct ipw_rx_mem_buffer *rxb; 8209 struct ipw_rx_packet *pkt; 8210 struct libipw_hdr_4addr *header; 8211 u32 r, i; 8212 u8 network_packet; 8213 u8 fill_rx = 0; 8214 8215 r = ipw_read32(priv, IPW_RX_READ_INDEX); 8216 ipw_read32(priv, IPW_RX_WRITE_INDEX); 8217 i = priv->rxq->read; 8218 8219 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2)) 8220 fill_rx = 1; 8221 8222 while (i != r) { 8223 rxb = priv->rxq->queue[i]; 8224 if (unlikely(rxb == NULL)) { 8225 printk(KERN_CRIT "Queue not allocated!\n"); 8226 break; 8227 } 8228 priv->rxq->queue[i] = NULL; 8229 8230 dma_sync_single_for_cpu(&priv->pci_dev->dev, rxb->dma_addr, 8231 IPW_RX_BUF_SIZE, DMA_FROM_DEVICE); 8232 8233 pkt = (struct ipw_rx_packet *)rxb->skb->data; 8234 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", 8235 pkt->header.message_type, 8236 pkt->header.rx_seq_num, pkt->header.control_bits); 8237 8238 switch (pkt->header.message_type) { 8239 case RX_FRAME_TYPE: /* 802.11 frame */ { 8240 struct libipw_rx_stats stats = { 8241 .rssi = pkt->u.frame.rssi_dbm - 8242 IPW_RSSI_TO_DBM, 8243 .signal = 8244 pkt->u.frame.rssi_dbm - 8245 IPW_RSSI_TO_DBM + 0x100, 8246 .noise = 8247 le16_to_cpu(pkt->u.frame.noise), 8248 .rate = pkt->u.frame.rate, 8249 .mac_time = jiffies, 8250 .received_channel = 8251 pkt->u.frame.received_channel, 8252 .freq = 8253 (pkt->u.frame. 8254 control & (1 << 0)) ? 8255 LIBIPW_24GHZ_BAND : 8256 LIBIPW_52GHZ_BAND, 8257 .len = le16_to_cpu(pkt->u.frame.length), 8258 }; 8259 8260 if (stats.rssi != 0) 8261 stats.mask |= LIBIPW_STATMASK_RSSI; 8262 if (stats.signal != 0) 8263 stats.mask |= LIBIPW_STATMASK_SIGNAL; 8264 if (stats.noise != 0) 8265 stats.mask |= LIBIPW_STATMASK_NOISE; 8266 if (stats.rate != 0) 8267 stats.mask |= LIBIPW_STATMASK_RATE; 8268 8269 priv->rx_packets++; 8270 8271 #ifdef CONFIG_IPW2200_PROMISCUOUS 8272 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) 8273 ipw_handle_promiscuous_rx(priv, rxb, &stats); 8274 #endif 8275 8276 #ifdef CONFIG_IPW2200_MONITOR 8277 if (priv->ieee->iw_mode == IW_MODE_MONITOR) { 8278 #ifdef CONFIG_IPW2200_RADIOTAP 8279 8280 ipw_handle_data_packet_monitor(priv, 8281 rxb, 8282 &stats); 8283 #else 8284 ipw_handle_data_packet(priv, rxb, 8285 &stats); 8286 #endif 8287 break; 8288 } 8289 #endif 8290 8291 header = 8292 (struct libipw_hdr_4addr *)(rxb->skb-> 8293 data + 8294 IPW_RX_FRAME_SIZE); 8295 /* TODO: Check Ad-Hoc dest/source and make sure 8296 * that we are actually parsing these packets 8297 * correctly -- we should probably use the 8298 * frame control of the packet and disregard 8299 * the current iw_mode */ 8300 8301 network_packet = 8302 is_network_packet(priv, header); 8303 if (network_packet && priv->assoc_network) { 8304 priv->assoc_network->stats.rssi = 8305 stats.rssi; 8306 priv->exp_avg_rssi = 8307 exponential_average(priv->exp_avg_rssi, 8308 stats.rssi, DEPTH_RSSI); 8309 } 8310 8311 IPW_DEBUG_RX("Frame: len=%u\n", 8312 le16_to_cpu(pkt->u.frame.length)); 8313 8314 if (le16_to_cpu(pkt->u.frame.length) < 8315 libipw_get_hdrlen(le16_to_cpu( 8316 header->frame_ctl))) { 8317 IPW_DEBUG_DROP 8318 ("Received packet is too small. " 8319 "Dropping.\n"); 8320 priv->net_dev->stats.rx_errors++; 8321 priv->wstats.discard.misc++; 8322 break; 8323 } 8324 8325 switch (WLAN_FC_GET_TYPE 8326 (le16_to_cpu(header->frame_ctl))) { 8327 8328 case IEEE80211_FTYPE_MGMT: 8329 ipw_handle_mgmt_packet(priv, rxb, 8330 &stats); 8331 break; 8332 8333 case IEEE80211_FTYPE_CTL: 8334 break; 8335 8336 case IEEE80211_FTYPE_DATA: 8337 if (unlikely(!network_packet || 8338 is_duplicate_packet(priv, 8339 header))) 8340 { 8341 IPW_DEBUG_DROP("Dropping: " 8342 "%pM, " 8343 "%pM, " 8344 "%pM\n", 8345 header->addr1, 8346 header->addr2, 8347 header->addr3); 8348 break; 8349 } 8350 8351 ipw_handle_data_packet(priv, rxb, 8352 &stats); 8353 8354 break; 8355 } 8356 break; 8357 } 8358 8359 case RX_HOST_NOTIFICATION_TYPE:{ 8360 IPW_DEBUG_RX 8361 ("Notification: subtype=%02X flags=%02X size=%d\n", 8362 pkt->u.notification.subtype, 8363 pkt->u.notification.flags, 8364 le16_to_cpu(pkt->u.notification.size)); 8365 ipw_rx_notification(priv, &pkt->u.notification); 8366 break; 8367 } 8368 8369 default: 8370 IPW_DEBUG_RX("Bad Rx packet of type %d\n", 8371 pkt->header.message_type); 8372 break; 8373 } 8374 8375 /* For now we just don't re-use anything. We can tweak this 8376 * later to try and re-use notification packets and SKBs that 8377 * fail to Rx correctly */ 8378 if (rxb->skb != NULL) { 8379 dev_kfree_skb_any(rxb->skb); 8380 rxb->skb = NULL; 8381 } 8382 8383 dma_unmap_single(&priv->pci_dev->dev, rxb->dma_addr, 8384 IPW_RX_BUF_SIZE, DMA_FROM_DEVICE); 8385 list_add_tail(&rxb->list, &priv->rxq->rx_used); 8386 8387 i = (i + 1) % RX_QUEUE_SIZE; 8388 8389 /* If there are a lot of unsued frames, restock the Rx queue 8390 * so the ucode won't assert */ 8391 if (fill_rx) { 8392 priv->rxq->read = i; 8393 ipw_rx_queue_replenish(priv); 8394 } 8395 } 8396 8397 /* Backtrack one entry */ 8398 priv->rxq->read = i; 8399 ipw_rx_queue_restock(priv); 8400 } 8401 8402 #define DEFAULT_RTS_THRESHOLD 2304U 8403 #define MIN_RTS_THRESHOLD 1U 8404 #define MAX_RTS_THRESHOLD 2304U 8405 #define DEFAULT_BEACON_INTERVAL 100U 8406 #define DEFAULT_SHORT_RETRY_LIMIT 7U 8407 #define DEFAULT_LONG_RETRY_LIMIT 4U 8408 8409 /* 8410 * ipw_sw_reset 8411 * @option: options to control different reset behaviour 8412 * 0 = reset everything except the 'disable' module_param 8413 * 1 = reset everything and print out driver info (for probe only) 8414 * 2 = reset everything 8415 */ 8416 static int ipw_sw_reset(struct ipw_priv *priv, int option) 8417 { 8418 int band, modulation; 8419 int old_mode = priv->ieee->iw_mode; 8420 8421 /* Initialize module parameter values here */ 8422 priv->config = 0; 8423 8424 /* We default to disabling the LED code as right now it causes 8425 * too many systems to lock up... */ 8426 if (!led_support) 8427 priv->config |= CFG_NO_LED; 8428 8429 if (associate) 8430 priv->config |= CFG_ASSOCIATE; 8431 else 8432 IPW_DEBUG_INFO("Auto associate disabled.\n"); 8433 8434 if (auto_create) 8435 priv->config |= CFG_ADHOC_CREATE; 8436 else 8437 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); 8438 8439 priv->config &= ~CFG_STATIC_ESSID; 8440 priv->essid_len = 0; 8441 memset(priv->essid, 0, IW_ESSID_MAX_SIZE); 8442 8443 if (disable && option) { 8444 priv->status |= STATUS_RF_KILL_SW; 8445 IPW_DEBUG_INFO("Radio disabled.\n"); 8446 } 8447 8448 if (default_channel != 0) { 8449 priv->config |= CFG_STATIC_CHANNEL; 8450 priv->channel = default_channel; 8451 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel); 8452 /* TODO: Validate that provided channel is in range */ 8453 } 8454 #ifdef CONFIG_IPW2200_QOS 8455 ipw_qos_init(priv, qos_enable, qos_burst_enable, 8456 burst_duration_CCK, burst_duration_OFDM); 8457 #endif /* CONFIG_IPW2200_QOS */ 8458 8459 switch (network_mode) { 8460 case 1: 8461 priv->ieee->iw_mode = IW_MODE_ADHOC; 8462 priv->net_dev->type = ARPHRD_ETHER; 8463 8464 break; 8465 #ifdef CONFIG_IPW2200_MONITOR 8466 case 2: 8467 priv->ieee->iw_mode = IW_MODE_MONITOR; 8468 #ifdef CONFIG_IPW2200_RADIOTAP 8469 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; 8470 #else 8471 priv->net_dev->type = ARPHRD_IEEE80211; 8472 #endif 8473 break; 8474 #endif 8475 default: 8476 case 0: 8477 priv->net_dev->type = ARPHRD_ETHER; 8478 priv->ieee->iw_mode = IW_MODE_INFRA; 8479 break; 8480 } 8481 8482 if (hwcrypto) { 8483 priv->ieee->host_encrypt = 0; 8484 priv->ieee->host_encrypt_msdu = 0; 8485 priv->ieee->host_decrypt = 0; 8486 priv->ieee->host_mc_decrypt = 0; 8487 } 8488 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); 8489 8490 /* IPW2200/2915 is abled to do hardware fragmentation. */ 8491 priv->ieee->host_open_frag = 0; 8492 8493 if ((priv->pci_dev->device == 0x4223) || 8494 (priv->pci_dev->device == 0x4224)) { 8495 if (option == 1) 8496 printk(KERN_INFO DRV_NAME 8497 ": Detected Intel PRO/Wireless 2915ABG Network " 8498 "Connection\n"); 8499 priv->ieee->abg_true = 1; 8500 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND; 8501 modulation = LIBIPW_OFDM_MODULATION | 8502 LIBIPW_CCK_MODULATION; 8503 priv->adapter = IPW_2915ABG; 8504 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; 8505 } else { 8506 if (option == 1) 8507 printk(KERN_INFO DRV_NAME 8508 ": Detected Intel PRO/Wireless 2200BG Network " 8509 "Connection\n"); 8510 8511 priv->ieee->abg_true = 0; 8512 band = LIBIPW_24GHZ_BAND; 8513 modulation = LIBIPW_OFDM_MODULATION | 8514 LIBIPW_CCK_MODULATION; 8515 priv->adapter = IPW_2200BG; 8516 priv->ieee->mode = IEEE_G | IEEE_B; 8517 } 8518 8519 priv->ieee->freq_band = band; 8520 priv->ieee->modulation = modulation; 8521 8522 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK; 8523 8524 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; 8525 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; 8526 8527 priv->rts_threshold = DEFAULT_RTS_THRESHOLD; 8528 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; 8529 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; 8530 8531 /* If power management is turned on, default to AC mode */ 8532 priv->power_mode = IPW_POWER_AC; 8533 priv->tx_power = IPW_TX_POWER_DEFAULT; 8534 8535 return old_mode == priv->ieee->iw_mode; 8536 } 8537 8538 /* 8539 * This file defines the Wireless Extension handlers. It does not 8540 * define any methods of hardware manipulation and relies on the 8541 * functions defined in ipw_main to provide the HW interaction. 8542 * 8543 * The exception to this is the use of the ipw_get_ordinal() 8544 * function used to poll the hardware vs. making unnecessary calls. 8545 * 8546 */ 8547 8548 static int ipw_set_channel(struct ipw_priv *priv, u8 channel) 8549 { 8550 if (channel == 0) { 8551 IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); 8552 priv->config &= ~CFG_STATIC_CHANNEL; 8553 IPW_DEBUG_ASSOC("Attempting to associate with new " 8554 "parameters.\n"); 8555 ipw_associate(priv); 8556 return 0; 8557 } 8558 8559 priv->config |= CFG_STATIC_CHANNEL; 8560 8561 if (priv->channel == channel) { 8562 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", 8563 channel); 8564 return 0; 8565 } 8566 8567 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); 8568 priv->channel = channel; 8569 8570 #ifdef CONFIG_IPW2200_MONITOR 8571 if (priv->ieee->iw_mode == IW_MODE_MONITOR) { 8572 int i; 8573 if (priv->status & STATUS_SCANNING) { 8574 IPW_DEBUG_SCAN("Scan abort triggered due to " 8575 "channel change.\n"); 8576 ipw_abort_scan(priv); 8577 } 8578 8579 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) 8580 udelay(10); 8581 8582 if (priv->status & STATUS_SCANNING) 8583 IPW_DEBUG_SCAN("Still scanning...\n"); 8584 else 8585 IPW_DEBUG_SCAN("Took %dms to abort current scan\n", 8586 1000 - i); 8587 8588 return 0; 8589 } 8590 #endif /* CONFIG_IPW2200_MONITOR */ 8591 8592 /* Network configuration changed -- force [re]association */ 8593 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); 8594 if (!ipw_disassociate(priv)) 8595 ipw_associate(priv); 8596 8597 return 0; 8598 } 8599 8600 static int ipw_wx_set_freq(struct net_device *dev, 8601 struct iw_request_info *info, 8602 union iwreq_data *wrqu, char *extra) 8603 { 8604 struct ipw_priv *priv = libipw_priv(dev); 8605 const struct libipw_geo *geo = libipw_get_geo(priv->ieee); 8606 struct iw_freq *fwrq = &wrqu->freq; 8607 int ret = 0, i; 8608 u8 channel, flags; 8609 int band; 8610 8611 if (fwrq->m == 0) { 8612 IPW_DEBUG_WX("SET Freq/Channel -> any\n"); 8613 mutex_lock(&priv->mutex); 8614 ret = ipw_set_channel(priv, 0); 8615 mutex_unlock(&priv->mutex); 8616 return ret; 8617 } 8618 /* if setting by freq convert to channel */ 8619 if (fwrq->e == 1) { 8620 channel = libipw_freq_to_channel(priv->ieee, fwrq->m); 8621 if (channel == 0) 8622 return -EINVAL; 8623 } else 8624 channel = fwrq->m; 8625 8626 if (!(band = libipw_is_valid_channel(priv->ieee, channel))) 8627 return -EINVAL; 8628 8629 if (priv->ieee->iw_mode == IW_MODE_ADHOC) { 8630 i = libipw_channel_to_index(priv->ieee, channel); 8631 if (i == -1) 8632 return -EINVAL; 8633 8634 flags = (band == LIBIPW_24GHZ_BAND) ? 8635 geo->bg[i].flags : geo->a[i].flags; 8636 if (flags & LIBIPW_CH_PASSIVE_ONLY) { 8637 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); 8638 return -EINVAL; 8639 } 8640 } 8641 8642 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m); 8643 mutex_lock(&priv->mutex); 8644 ret = ipw_set_channel(priv, channel); 8645 mutex_unlock(&priv->mutex); 8646 return ret; 8647 } 8648 8649 static int ipw_wx_get_freq(struct net_device *dev, 8650 struct iw_request_info *info, 8651 union iwreq_data *wrqu, char *extra) 8652 { 8653 struct ipw_priv *priv = libipw_priv(dev); 8654 8655 wrqu->freq.e = 0; 8656 8657 /* If we are associated, trying to associate, or have a statically 8658 * configured CHANNEL then return that; otherwise return ANY */ 8659 mutex_lock(&priv->mutex); 8660 if (priv->config & CFG_STATIC_CHANNEL || 8661 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) { 8662 int i; 8663 8664 i = libipw_channel_to_index(priv->ieee, priv->channel); 8665 BUG_ON(i == -1); 8666 wrqu->freq.e = 1; 8667 8668 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { 8669 case LIBIPW_52GHZ_BAND: 8670 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000; 8671 break; 8672 8673 case LIBIPW_24GHZ_BAND: 8674 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000; 8675 break; 8676 8677 default: 8678 BUG(); 8679 } 8680 } else 8681 wrqu->freq.m = 0; 8682 8683 mutex_unlock(&priv->mutex); 8684 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel); 8685 return 0; 8686 } 8687 8688 static int ipw_wx_set_mode(struct net_device *dev, 8689 struct iw_request_info *info, 8690 union iwreq_data *wrqu, char *extra) 8691 { 8692 struct ipw_priv *priv = libipw_priv(dev); 8693 int err = 0; 8694 8695 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); 8696 8697 switch (wrqu->mode) { 8698 #ifdef CONFIG_IPW2200_MONITOR 8699 case IW_MODE_MONITOR: 8700 #endif 8701 case IW_MODE_ADHOC: 8702 case IW_MODE_INFRA: 8703 break; 8704 case IW_MODE_AUTO: 8705 wrqu->mode = IW_MODE_INFRA; 8706 break; 8707 default: 8708 return -EINVAL; 8709 } 8710 if (wrqu->mode == priv->ieee->iw_mode) 8711 return 0; 8712 8713 mutex_lock(&priv->mutex); 8714 8715 ipw_sw_reset(priv, 0); 8716 8717 #ifdef CONFIG_IPW2200_MONITOR 8718 if (priv->ieee->iw_mode == IW_MODE_MONITOR) 8719 priv->net_dev->type = ARPHRD_ETHER; 8720 8721 if (wrqu->mode == IW_MODE_MONITOR) 8722 #ifdef CONFIG_IPW2200_RADIOTAP 8723 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; 8724 #else 8725 priv->net_dev->type = ARPHRD_IEEE80211; 8726 #endif 8727 #endif /* CONFIG_IPW2200_MONITOR */ 8728 8729 /* Free the existing firmware and reset the fw_loaded 8730 * flag so ipw_load() will bring in the new firmware */ 8731 free_firmware(); 8732 8733 priv->ieee->iw_mode = wrqu->mode; 8734 8735 schedule_work(&priv->adapter_restart); 8736 mutex_unlock(&priv->mutex); 8737 return err; 8738 } 8739 8740 static int ipw_wx_get_mode(struct net_device *dev, 8741 struct iw_request_info *info, 8742 union iwreq_data *wrqu, char *extra) 8743 { 8744 struct ipw_priv *priv = libipw_priv(dev); 8745 mutex_lock(&priv->mutex); 8746 wrqu->mode = priv->ieee->iw_mode; 8747 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); 8748 mutex_unlock(&priv->mutex); 8749 return 0; 8750 } 8751 8752 /* Values are in microsecond */ 8753 static const s32 timeout_duration[] = { 8754 350000, 8755 250000, 8756 75000, 8757 37000, 8758 25000, 8759 }; 8760 8761 static const s32 period_duration[] = { 8762 400000, 8763 700000, 8764 1000000, 8765 1000000, 8766 1000000 8767 }; 8768 8769 static int ipw_wx_get_range(struct net_device *dev, 8770 struct iw_request_info *info, 8771 union iwreq_data *wrqu, char *extra) 8772 { 8773 struct ipw_priv *priv = libipw_priv(dev); 8774 struct iw_range *range = (struct iw_range *)extra; 8775 const struct libipw_geo *geo = libipw_get_geo(priv->ieee); 8776 int i = 0, j; 8777 8778 wrqu->data.length = sizeof(*range); 8779 memset(range, 0, sizeof(*range)); 8780 8781 /* 54Mbs == ~27 Mb/s real (802.11g) */ 8782 range->throughput = 27 * 1000 * 1000; 8783 8784 range->max_qual.qual = 100; 8785 /* TODO: Find real max RSSI and stick here */ 8786 range->max_qual.level = 0; 8787 range->max_qual.noise = 0; 8788 range->max_qual.updated = 7; /* Updated all three */ 8789 8790 range->avg_qual.qual = 70; 8791 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */ 8792 range->avg_qual.level = 0; /* FIXME to real average level */ 8793 range->avg_qual.noise = 0; 8794 range->avg_qual.updated = 7; /* Updated all three */ 8795 mutex_lock(&priv->mutex); 8796 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); 8797 8798 for (i = 0; i < range->num_bitrates; i++) 8799 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * 8800 500000; 8801 8802 range->max_rts = DEFAULT_RTS_THRESHOLD; 8803 range->min_frag = MIN_FRAG_THRESHOLD; 8804 range->max_frag = MAX_FRAG_THRESHOLD; 8805 8806 range->encoding_size[0] = 5; 8807 range->encoding_size[1] = 13; 8808 range->num_encoding_sizes = 2; 8809 range->max_encoding_tokens = WEP_KEYS; 8810 8811 /* Set the Wireless Extension versions */ 8812 range->we_version_compiled = WIRELESS_EXT; 8813 range->we_version_source = 18; 8814 8815 i = 0; 8816 if (priv->ieee->mode & (IEEE_B | IEEE_G)) { 8817 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { 8818 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && 8819 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY)) 8820 continue; 8821 8822 range->freq[i].i = geo->bg[j].channel; 8823 range->freq[i].m = geo->bg[j].freq * 100000; 8824 range->freq[i].e = 1; 8825 i++; 8826 } 8827 } 8828 8829 if (priv->ieee->mode & IEEE_A) { 8830 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { 8831 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && 8832 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY)) 8833 continue; 8834 8835 range->freq[i].i = geo->a[j].channel; 8836 range->freq[i].m = geo->a[j].freq * 100000; 8837 range->freq[i].e = 1; 8838 i++; 8839 } 8840 } 8841 8842 range->num_channels = i; 8843 range->num_frequency = i; 8844 8845 mutex_unlock(&priv->mutex); 8846 8847 /* Event capability (kernel + driver) */ 8848 range->event_capa[0] = (IW_EVENT_CAPA_K_0 | 8849 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | 8850 IW_EVENT_CAPA_MASK(SIOCGIWAP) | 8851 IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); 8852 range->event_capa[1] = IW_EVENT_CAPA_K_1; 8853 8854 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | 8855 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; 8856 8857 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE; 8858 8859 IPW_DEBUG_WX("GET Range\n"); 8860 return 0; 8861 } 8862 8863 static int ipw_wx_set_wap(struct net_device *dev, 8864 struct iw_request_info *info, 8865 union iwreq_data *wrqu, char *extra) 8866 { 8867 struct ipw_priv *priv = libipw_priv(dev); 8868 8869 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) 8870 return -EINVAL; 8871 mutex_lock(&priv->mutex); 8872 if (is_broadcast_ether_addr(wrqu->ap_addr.sa_data) || 8873 is_zero_ether_addr(wrqu->ap_addr.sa_data)) { 8874 /* we disable mandatory BSSID association */ 8875 IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); 8876 priv->config &= ~CFG_STATIC_BSSID; 8877 IPW_DEBUG_ASSOC("Attempting to associate with new " 8878 "parameters.\n"); 8879 ipw_associate(priv); 8880 mutex_unlock(&priv->mutex); 8881 return 0; 8882 } 8883 8884 priv->config |= CFG_STATIC_BSSID; 8885 if (ether_addr_equal(priv->bssid, wrqu->ap_addr.sa_data)) { 8886 IPW_DEBUG_WX("BSSID set to current BSSID.\n"); 8887 mutex_unlock(&priv->mutex); 8888 return 0; 8889 } 8890 8891 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n", 8892 wrqu->ap_addr.sa_data); 8893 8894 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); 8895 8896 /* Network configuration changed -- force [re]association */ 8897 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); 8898 if (!ipw_disassociate(priv)) 8899 ipw_associate(priv); 8900 8901 mutex_unlock(&priv->mutex); 8902 return 0; 8903 } 8904 8905 static int ipw_wx_get_wap(struct net_device *dev, 8906 struct iw_request_info *info, 8907 union iwreq_data *wrqu, char *extra) 8908 { 8909 struct ipw_priv *priv = libipw_priv(dev); 8910 8911 /* If we are associated, trying to associate, or have a statically 8912 * configured BSSID then return that; otherwise return ANY */ 8913 mutex_lock(&priv->mutex); 8914 if (priv->config & CFG_STATIC_BSSID || 8915 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { 8916 wrqu->ap_addr.sa_family = ARPHRD_ETHER; 8917 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); 8918 } else 8919 eth_zero_addr(wrqu->ap_addr.sa_data); 8920 8921 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", 8922 wrqu->ap_addr.sa_data); 8923 mutex_unlock(&priv->mutex); 8924 return 0; 8925 } 8926 8927 static int ipw_wx_set_essid(struct net_device *dev, 8928 struct iw_request_info *info, 8929 union iwreq_data *wrqu, char *extra) 8930 { 8931 struct ipw_priv *priv = libipw_priv(dev); 8932 int length; 8933 8934 mutex_lock(&priv->mutex); 8935 8936 if (!wrqu->essid.flags) 8937 { 8938 IPW_DEBUG_WX("Setting ESSID to ANY\n"); 8939 ipw_disassociate(priv); 8940 priv->config &= ~CFG_STATIC_ESSID; 8941 ipw_associate(priv); 8942 mutex_unlock(&priv->mutex); 8943 return 0; 8944 } 8945 8946 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE); 8947 8948 priv->config |= CFG_STATIC_ESSID; 8949 8950 if (priv->essid_len == length && !memcmp(priv->essid, extra, length) 8951 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) { 8952 IPW_DEBUG_WX("ESSID set to current ESSID.\n"); 8953 mutex_unlock(&priv->mutex); 8954 return 0; 8955 } 8956 8957 IPW_DEBUG_WX("Setting ESSID: '%*pE' (%d)\n", length, extra, length); 8958 8959 priv->essid_len = length; 8960 memcpy(priv->essid, extra, priv->essid_len); 8961 8962 /* Network configuration changed -- force [re]association */ 8963 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); 8964 if (!ipw_disassociate(priv)) 8965 ipw_associate(priv); 8966 8967 mutex_unlock(&priv->mutex); 8968 return 0; 8969 } 8970 8971 static int ipw_wx_get_essid(struct net_device *dev, 8972 struct iw_request_info *info, 8973 union iwreq_data *wrqu, char *extra) 8974 { 8975 struct ipw_priv *priv = libipw_priv(dev); 8976 8977 /* If we are associated, trying to associate, or have a statically 8978 * configured ESSID then return that; otherwise return ANY */ 8979 mutex_lock(&priv->mutex); 8980 if (priv->config & CFG_STATIC_ESSID || 8981 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { 8982 IPW_DEBUG_WX("Getting essid: '%*pE'\n", 8983 priv->essid_len, priv->essid); 8984 memcpy(extra, priv->essid, priv->essid_len); 8985 wrqu->essid.length = priv->essid_len; 8986 wrqu->essid.flags = 1; /* active */ 8987 } else { 8988 IPW_DEBUG_WX("Getting essid: ANY\n"); 8989 wrqu->essid.length = 0; 8990 wrqu->essid.flags = 0; /* active */ 8991 } 8992 mutex_unlock(&priv->mutex); 8993 return 0; 8994 } 8995 8996 static int ipw_wx_set_nick(struct net_device *dev, 8997 struct iw_request_info *info, 8998 union iwreq_data *wrqu, char *extra) 8999 { 9000 struct ipw_priv *priv = libipw_priv(dev); 9001 9002 IPW_DEBUG_WX("Setting nick to '%s'\n", extra); 9003 if (wrqu->data.length > IW_ESSID_MAX_SIZE) 9004 return -E2BIG; 9005 mutex_lock(&priv->mutex); 9006 wrqu->data.length = min_t(size_t, wrqu->data.length, sizeof(priv->nick)); 9007 memset(priv->nick, 0, sizeof(priv->nick)); 9008 memcpy(priv->nick, extra, wrqu->data.length); 9009 IPW_DEBUG_TRACE("<<\n"); 9010 mutex_unlock(&priv->mutex); 9011 return 0; 9012 9013 } 9014 9015 static int ipw_wx_get_nick(struct net_device *dev, 9016 struct iw_request_info *info, 9017 union iwreq_data *wrqu, char *extra) 9018 { 9019 struct ipw_priv *priv = libipw_priv(dev); 9020 IPW_DEBUG_WX("Getting nick\n"); 9021 mutex_lock(&priv->mutex); 9022 wrqu->data.length = strlen(priv->nick); 9023 memcpy(extra, priv->nick, wrqu->data.length); 9024 wrqu->data.flags = 1; /* active */ 9025 mutex_unlock(&priv->mutex); 9026 return 0; 9027 } 9028 9029 static int ipw_wx_set_sens(struct net_device *dev, 9030 struct iw_request_info *info, 9031 union iwreq_data *wrqu, char *extra) 9032 { 9033 struct ipw_priv *priv = libipw_priv(dev); 9034 int err = 0; 9035 9036 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); 9037 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); 9038 mutex_lock(&priv->mutex); 9039 9040 if (wrqu->sens.fixed == 0) 9041 { 9042 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; 9043 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; 9044 goto out; 9045 } 9046 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || 9047 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { 9048 err = -EINVAL; 9049 goto out; 9050 } 9051 9052 priv->roaming_threshold = wrqu->sens.value; 9053 priv->disassociate_threshold = 3*wrqu->sens.value; 9054 out: 9055 mutex_unlock(&priv->mutex); 9056 return err; 9057 } 9058 9059 static int ipw_wx_get_sens(struct net_device *dev, 9060 struct iw_request_info *info, 9061 union iwreq_data *wrqu, char *extra) 9062 { 9063 struct ipw_priv *priv = libipw_priv(dev); 9064 mutex_lock(&priv->mutex); 9065 wrqu->sens.fixed = 1; 9066 wrqu->sens.value = priv->roaming_threshold; 9067 mutex_unlock(&priv->mutex); 9068 9069 IPW_DEBUG_WX("GET roaming threshold -> %s %d\n", 9070 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); 9071 9072 return 0; 9073 } 9074 9075 static int ipw_wx_set_rate(struct net_device *dev, 9076 struct iw_request_info *info, 9077 union iwreq_data *wrqu, char *extra) 9078 { 9079 /* TODO: We should use semaphores or locks for access to priv */ 9080 struct ipw_priv *priv = libipw_priv(dev); 9081 u32 target_rate = wrqu->bitrate.value; 9082 u32 fixed, mask; 9083 9084 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ 9085 /* value = X, fixed = 1 means only rate X */ 9086 /* value = X, fixed = 0 means all rates lower equal X */ 9087 9088 if (target_rate == -1) { 9089 fixed = 0; 9090 mask = LIBIPW_DEFAULT_RATES_MASK; 9091 /* Now we should reassociate */ 9092 goto apply; 9093 } 9094 9095 mask = 0; 9096 fixed = wrqu->bitrate.fixed; 9097 9098 if (target_rate == 1000000 || !fixed) 9099 mask |= LIBIPW_CCK_RATE_1MB_MASK; 9100 if (target_rate == 1000000) 9101 goto apply; 9102 9103 if (target_rate == 2000000 || !fixed) 9104 mask |= LIBIPW_CCK_RATE_2MB_MASK; 9105 if (target_rate == 2000000) 9106 goto apply; 9107 9108 if (target_rate == 5500000 || !fixed) 9109 mask |= LIBIPW_CCK_RATE_5MB_MASK; 9110 if (target_rate == 5500000) 9111 goto apply; 9112 9113 if (target_rate == 6000000 || !fixed) 9114 mask |= LIBIPW_OFDM_RATE_6MB_MASK; 9115 if (target_rate == 6000000) 9116 goto apply; 9117 9118 if (target_rate == 9000000 || !fixed) 9119 mask |= LIBIPW_OFDM_RATE_9MB_MASK; 9120 if (target_rate == 9000000) 9121 goto apply; 9122 9123 if (target_rate == 11000000 || !fixed) 9124 mask |= LIBIPW_CCK_RATE_11MB_MASK; 9125 if (target_rate == 11000000) 9126 goto apply; 9127 9128 if (target_rate == 12000000 || !fixed) 9129 mask |= LIBIPW_OFDM_RATE_12MB_MASK; 9130 if (target_rate == 12000000) 9131 goto apply; 9132 9133 if (target_rate == 18000000 || !fixed) 9134 mask |= LIBIPW_OFDM_RATE_18MB_MASK; 9135 if (target_rate == 18000000) 9136 goto apply; 9137 9138 if (target_rate == 24000000 || !fixed) 9139 mask |= LIBIPW_OFDM_RATE_24MB_MASK; 9140 if (target_rate == 24000000) 9141 goto apply; 9142 9143 if (target_rate == 36000000 || !fixed) 9144 mask |= LIBIPW_OFDM_RATE_36MB_MASK; 9145 if (target_rate == 36000000) 9146 goto apply; 9147 9148 if (target_rate == 48000000 || !fixed) 9149 mask |= LIBIPW_OFDM_RATE_48MB_MASK; 9150 if (target_rate == 48000000) 9151 goto apply; 9152 9153 if (target_rate == 54000000 || !fixed) 9154 mask |= LIBIPW_OFDM_RATE_54MB_MASK; 9155 if (target_rate == 54000000) 9156 goto apply; 9157 9158 IPW_DEBUG_WX("invalid rate specified, returning error\n"); 9159 return -EINVAL; 9160 9161 apply: 9162 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", 9163 mask, fixed ? "fixed" : "sub-rates"); 9164 mutex_lock(&priv->mutex); 9165 if (mask == LIBIPW_DEFAULT_RATES_MASK) { 9166 priv->config &= ~CFG_FIXED_RATE; 9167 ipw_set_fixed_rate(priv, priv->ieee->mode); 9168 } else 9169 priv->config |= CFG_FIXED_RATE; 9170 9171 if (priv->rates_mask == mask) { 9172 IPW_DEBUG_WX("Mask set to current mask.\n"); 9173 mutex_unlock(&priv->mutex); 9174 return 0; 9175 } 9176 9177 priv->rates_mask = mask; 9178 9179 /* Network configuration changed -- force [re]association */ 9180 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); 9181 if (!ipw_disassociate(priv)) 9182 ipw_associate(priv); 9183 9184 mutex_unlock(&priv->mutex); 9185 return 0; 9186 } 9187 9188 static int ipw_wx_get_rate(struct net_device *dev, 9189 struct iw_request_info *info, 9190 union iwreq_data *wrqu, char *extra) 9191 { 9192 struct ipw_priv *priv = libipw_priv(dev); 9193 mutex_lock(&priv->mutex); 9194 wrqu->bitrate.value = priv->last_rate; 9195 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0; 9196 mutex_unlock(&priv->mutex); 9197 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value); 9198 return 0; 9199 } 9200 9201 static int ipw_wx_set_rts(struct net_device *dev, 9202 struct iw_request_info *info, 9203 union iwreq_data *wrqu, char *extra) 9204 { 9205 struct ipw_priv *priv = libipw_priv(dev); 9206 mutex_lock(&priv->mutex); 9207 if (wrqu->rts.disabled || !wrqu->rts.fixed) 9208 priv->rts_threshold = DEFAULT_RTS_THRESHOLD; 9209 else { 9210 if (wrqu->rts.value < MIN_RTS_THRESHOLD || 9211 wrqu->rts.value > MAX_RTS_THRESHOLD) { 9212 mutex_unlock(&priv->mutex); 9213 return -EINVAL; 9214 } 9215 priv->rts_threshold = wrqu->rts.value; 9216 } 9217 9218 ipw_send_rts_threshold(priv, priv->rts_threshold); 9219 mutex_unlock(&priv->mutex); 9220 IPW_DEBUG_WX("SET RTS Threshold -> %d\n", priv->rts_threshold); 9221 return 0; 9222 } 9223 9224 static int ipw_wx_get_rts(struct net_device *dev, 9225 struct iw_request_info *info, 9226 union iwreq_data *wrqu, char *extra) 9227 { 9228 struct ipw_priv *priv = libipw_priv(dev); 9229 mutex_lock(&priv->mutex); 9230 wrqu->rts.value = priv->rts_threshold; 9231 wrqu->rts.fixed = 0; /* no auto select */ 9232 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); 9233 mutex_unlock(&priv->mutex); 9234 IPW_DEBUG_WX("GET RTS Threshold -> %d\n", wrqu->rts.value); 9235 return 0; 9236 } 9237 9238 static int ipw_wx_set_txpow(struct net_device *dev, 9239 struct iw_request_info *info, 9240 union iwreq_data *wrqu, char *extra) 9241 { 9242 struct ipw_priv *priv = libipw_priv(dev); 9243 int err = 0; 9244 9245 mutex_lock(&priv->mutex); 9246 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { 9247 err = -EINPROGRESS; 9248 goto out; 9249 } 9250 9251 if (!wrqu->power.fixed) 9252 wrqu->power.value = IPW_TX_POWER_DEFAULT; 9253 9254 if (wrqu->power.flags != IW_TXPOW_DBM) { 9255 err = -EINVAL; 9256 goto out; 9257 } 9258 9259 if ((wrqu->power.value > IPW_TX_POWER_MAX) || 9260 (wrqu->power.value < IPW_TX_POWER_MIN)) { 9261 err = -EINVAL; 9262 goto out; 9263 } 9264 9265 priv->tx_power = wrqu->power.value; 9266 err = ipw_set_tx_power(priv); 9267 out: 9268 mutex_unlock(&priv->mutex); 9269 return err; 9270 } 9271 9272 static int ipw_wx_get_txpow(struct net_device *dev, 9273 struct iw_request_info *info, 9274 union iwreq_data *wrqu, char *extra) 9275 { 9276 struct ipw_priv *priv = libipw_priv(dev); 9277 mutex_lock(&priv->mutex); 9278 wrqu->power.value = priv->tx_power; 9279 wrqu->power.fixed = 1; 9280 wrqu->power.flags = IW_TXPOW_DBM; 9281 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; 9282 mutex_unlock(&priv->mutex); 9283 9284 IPW_DEBUG_WX("GET TX Power -> %s %d\n", 9285 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); 9286 9287 return 0; 9288 } 9289 9290 static int ipw_wx_set_frag(struct net_device *dev, 9291 struct iw_request_info *info, 9292 union iwreq_data *wrqu, char *extra) 9293 { 9294 struct ipw_priv *priv = libipw_priv(dev); 9295 mutex_lock(&priv->mutex); 9296 if (wrqu->frag.disabled || !wrqu->frag.fixed) 9297 priv->ieee->fts = DEFAULT_FTS; 9298 else { 9299 if (wrqu->frag.value < MIN_FRAG_THRESHOLD || 9300 wrqu->frag.value > MAX_FRAG_THRESHOLD) { 9301 mutex_unlock(&priv->mutex); 9302 return -EINVAL; 9303 } 9304 9305 priv->ieee->fts = wrqu->frag.value & ~0x1; 9306 } 9307 9308 ipw_send_frag_threshold(priv, wrqu->frag.value); 9309 mutex_unlock(&priv->mutex); 9310 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", wrqu->frag.value); 9311 return 0; 9312 } 9313 9314 static int ipw_wx_get_frag(struct net_device *dev, 9315 struct iw_request_info *info, 9316 union iwreq_data *wrqu, char *extra) 9317 { 9318 struct ipw_priv *priv = libipw_priv(dev); 9319 mutex_lock(&priv->mutex); 9320 wrqu->frag.value = priv->ieee->fts; 9321 wrqu->frag.fixed = 0; /* no auto select */ 9322 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); 9323 mutex_unlock(&priv->mutex); 9324 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value); 9325 9326 return 0; 9327 } 9328 9329 static int ipw_wx_set_retry(struct net_device *dev, 9330 struct iw_request_info *info, 9331 union iwreq_data *wrqu, char *extra) 9332 { 9333 struct ipw_priv *priv = libipw_priv(dev); 9334 9335 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) 9336 return -EINVAL; 9337 9338 if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) 9339 return 0; 9340 9341 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255) 9342 return -EINVAL; 9343 9344 mutex_lock(&priv->mutex); 9345 if (wrqu->retry.flags & IW_RETRY_SHORT) 9346 priv->short_retry_limit = (u8) wrqu->retry.value; 9347 else if (wrqu->retry.flags & IW_RETRY_LONG) 9348 priv->long_retry_limit = (u8) wrqu->retry.value; 9349 else { 9350 priv->short_retry_limit = (u8) wrqu->retry.value; 9351 priv->long_retry_limit = (u8) wrqu->retry.value; 9352 } 9353 9354 ipw_send_retry_limit(priv, priv->short_retry_limit, 9355 priv->long_retry_limit); 9356 mutex_unlock(&priv->mutex); 9357 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", 9358 priv->short_retry_limit, priv->long_retry_limit); 9359 return 0; 9360 } 9361 9362 static int ipw_wx_get_retry(struct net_device *dev, 9363 struct iw_request_info *info, 9364 union iwreq_data *wrqu, char *extra) 9365 { 9366 struct ipw_priv *priv = libipw_priv(dev); 9367 9368 mutex_lock(&priv->mutex); 9369 wrqu->retry.disabled = 0; 9370 9371 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { 9372 mutex_unlock(&priv->mutex); 9373 return -EINVAL; 9374 } 9375 9376 if (wrqu->retry.flags & IW_RETRY_LONG) { 9377 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG; 9378 wrqu->retry.value = priv->long_retry_limit; 9379 } else if (wrqu->retry.flags & IW_RETRY_SHORT) { 9380 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT; 9381 wrqu->retry.value = priv->short_retry_limit; 9382 } else { 9383 wrqu->retry.flags = IW_RETRY_LIMIT; 9384 wrqu->retry.value = priv->short_retry_limit; 9385 } 9386 mutex_unlock(&priv->mutex); 9387 9388 IPW_DEBUG_WX("GET retry -> %d\n", wrqu->retry.value); 9389 9390 return 0; 9391 } 9392 9393 static int ipw_wx_set_scan(struct net_device *dev, 9394 struct iw_request_info *info, 9395 union iwreq_data *wrqu, char *extra) 9396 { 9397 struct ipw_priv *priv = libipw_priv(dev); 9398 struct iw_scan_req *req = (struct iw_scan_req *)extra; 9399 struct delayed_work *work = NULL; 9400 9401 mutex_lock(&priv->mutex); 9402 9403 priv->user_requested_scan = 1; 9404 9405 if (wrqu->data.length == sizeof(struct iw_scan_req)) { 9406 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { 9407 int len = min((int)req->essid_len, 9408 (int)sizeof(priv->direct_scan_ssid)); 9409 memcpy(priv->direct_scan_ssid, req->essid, len); 9410 priv->direct_scan_ssid_len = len; 9411 work = &priv->request_direct_scan; 9412 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { 9413 work = &priv->request_passive_scan; 9414 } 9415 } else { 9416 /* Normal active broadcast scan */ 9417 work = &priv->request_scan; 9418 } 9419 9420 mutex_unlock(&priv->mutex); 9421 9422 IPW_DEBUG_WX("Start scan\n"); 9423 9424 schedule_delayed_work(work, 0); 9425 9426 return 0; 9427 } 9428 9429 static int ipw_wx_get_scan(struct net_device *dev, 9430 struct iw_request_info *info, 9431 union iwreq_data *wrqu, char *extra) 9432 { 9433 struct ipw_priv *priv = libipw_priv(dev); 9434 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra); 9435 } 9436 9437 static int ipw_wx_set_encode(struct net_device *dev, 9438 struct iw_request_info *info, 9439 union iwreq_data *wrqu, char *key) 9440 { 9441 struct ipw_priv *priv = libipw_priv(dev); 9442 int ret; 9443 u32 cap = priv->capability; 9444 9445 mutex_lock(&priv->mutex); 9446 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key); 9447 9448 /* In IBSS mode, we need to notify the firmware to update 9449 * the beacon info after we changed the capability. */ 9450 if (cap != priv->capability && 9451 priv->ieee->iw_mode == IW_MODE_ADHOC && 9452 priv->status & STATUS_ASSOCIATED) 9453 ipw_disassociate(priv); 9454 9455 mutex_unlock(&priv->mutex); 9456 return ret; 9457 } 9458 9459 static int ipw_wx_get_encode(struct net_device *dev, 9460 struct iw_request_info *info, 9461 union iwreq_data *wrqu, char *key) 9462 { 9463 struct ipw_priv *priv = libipw_priv(dev); 9464 return libipw_wx_get_encode(priv->ieee, info, wrqu, key); 9465 } 9466 9467 static int ipw_wx_set_power(struct net_device *dev, 9468 struct iw_request_info *info, 9469 union iwreq_data *wrqu, char *extra) 9470 { 9471 struct ipw_priv *priv = libipw_priv(dev); 9472 int err; 9473 mutex_lock(&priv->mutex); 9474 if (wrqu->power.disabled) { 9475 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); 9476 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); 9477 if (err) { 9478 IPW_DEBUG_WX("failed setting power mode.\n"); 9479 mutex_unlock(&priv->mutex); 9480 return err; 9481 } 9482 IPW_DEBUG_WX("SET Power Management Mode -> off\n"); 9483 mutex_unlock(&priv->mutex); 9484 return 0; 9485 } 9486 9487 switch (wrqu->power.flags & IW_POWER_MODE) { 9488 case IW_POWER_ON: /* If not specified */ 9489 case IW_POWER_MODE: /* If set all mask */ 9490 case IW_POWER_ALL_R: /* If explicitly state all */ 9491 break; 9492 default: /* Otherwise we don't support it */ 9493 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", 9494 wrqu->power.flags); 9495 mutex_unlock(&priv->mutex); 9496 return -EOPNOTSUPP; 9497 } 9498 9499 /* If the user hasn't specified a power management mode yet, default 9500 * to BATTERY */ 9501 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) 9502 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; 9503 else 9504 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; 9505 9506 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); 9507 if (err) { 9508 IPW_DEBUG_WX("failed setting power mode.\n"); 9509 mutex_unlock(&priv->mutex); 9510 return err; 9511 } 9512 9513 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode); 9514 mutex_unlock(&priv->mutex); 9515 return 0; 9516 } 9517 9518 static int ipw_wx_get_power(struct net_device *dev, 9519 struct iw_request_info *info, 9520 union iwreq_data *wrqu, char *extra) 9521 { 9522 struct ipw_priv *priv = libipw_priv(dev); 9523 mutex_lock(&priv->mutex); 9524 if (!(priv->power_mode & IPW_POWER_ENABLED)) 9525 wrqu->power.disabled = 1; 9526 else 9527 wrqu->power.disabled = 0; 9528 9529 mutex_unlock(&priv->mutex); 9530 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); 9531 9532 return 0; 9533 } 9534 9535 static int ipw_wx_set_powermode(struct net_device *dev, 9536 struct iw_request_info *info, 9537 union iwreq_data *wrqu, char *extra) 9538 { 9539 struct ipw_priv *priv = libipw_priv(dev); 9540 int mode = *(int *)extra; 9541 int err; 9542 9543 mutex_lock(&priv->mutex); 9544 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) 9545 mode = IPW_POWER_AC; 9546 9547 if (IPW_POWER_LEVEL(priv->power_mode) != mode) { 9548 err = ipw_send_power_mode(priv, mode); 9549 if (err) { 9550 IPW_DEBUG_WX("failed setting power mode.\n"); 9551 mutex_unlock(&priv->mutex); 9552 return err; 9553 } 9554 priv->power_mode = IPW_POWER_ENABLED | mode; 9555 } 9556 mutex_unlock(&priv->mutex); 9557 return 0; 9558 } 9559 9560 #define MAX_WX_STRING 80 9561 static int ipw_wx_get_powermode(struct net_device *dev, 9562 struct iw_request_info *info, 9563 union iwreq_data *wrqu, char *extra) 9564 { 9565 struct ipw_priv *priv = libipw_priv(dev); 9566 int level = IPW_POWER_LEVEL(priv->power_mode); 9567 char *p = extra; 9568 9569 p += scnprintf(p, MAX_WX_STRING, "Power save level: %d ", level); 9570 9571 switch (level) { 9572 case IPW_POWER_AC: 9573 p += scnprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); 9574 break; 9575 case IPW_POWER_BATTERY: 9576 p += scnprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); 9577 break; 9578 default: 9579 p += scnprintf(p, MAX_WX_STRING - (p - extra), 9580 "(Timeout %dms, Period %dms)", 9581 timeout_duration[level - 1] / 1000, 9582 period_duration[level - 1] / 1000); 9583 } 9584 9585 if (!(priv->power_mode & IPW_POWER_ENABLED)) 9586 p += scnprintf(p, MAX_WX_STRING - (p - extra), " OFF"); 9587 9588 wrqu->data.length = p - extra + 1; 9589 9590 return 0; 9591 } 9592 9593 static int ipw_wx_set_wireless_mode(struct net_device *dev, 9594 struct iw_request_info *info, 9595 union iwreq_data *wrqu, char *extra) 9596 { 9597 struct ipw_priv *priv = libipw_priv(dev); 9598 int mode = *(int *)extra; 9599 u8 band = 0, modulation = 0; 9600 9601 if (mode == 0 || mode & ~IEEE_MODE_MASK) { 9602 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); 9603 return -EINVAL; 9604 } 9605 mutex_lock(&priv->mutex); 9606 if (priv->adapter == IPW_2915ABG) { 9607 priv->ieee->abg_true = 1; 9608 if (mode & IEEE_A) { 9609 band |= LIBIPW_52GHZ_BAND; 9610 modulation |= LIBIPW_OFDM_MODULATION; 9611 } else 9612 priv->ieee->abg_true = 0; 9613 } else { 9614 if (mode & IEEE_A) { 9615 IPW_WARNING("Attempt to set 2200BG into " 9616 "802.11a mode\n"); 9617 mutex_unlock(&priv->mutex); 9618 return -EINVAL; 9619 } 9620 9621 priv->ieee->abg_true = 0; 9622 } 9623 9624 if (mode & IEEE_B) { 9625 band |= LIBIPW_24GHZ_BAND; 9626 modulation |= LIBIPW_CCK_MODULATION; 9627 } else 9628 priv->ieee->abg_true = 0; 9629 9630 if (mode & IEEE_G) { 9631 band |= LIBIPW_24GHZ_BAND; 9632 modulation |= LIBIPW_OFDM_MODULATION; 9633 } else 9634 priv->ieee->abg_true = 0; 9635 9636 priv->ieee->mode = mode; 9637 priv->ieee->freq_band = band; 9638 priv->ieee->modulation = modulation; 9639 init_supported_rates(priv, &priv->rates); 9640 9641 /* Network configuration changed -- force [re]association */ 9642 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); 9643 if (!ipw_disassociate(priv)) { 9644 ipw_send_supported_rates(priv, &priv->rates); 9645 ipw_associate(priv); 9646 } 9647 9648 /* Update the band LEDs */ 9649 ipw_led_band_on(priv); 9650 9651 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", 9652 mode & IEEE_A ? 'a' : '.', 9653 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); 9654 mutex_unlock(&priv->mutex); 9655 return 0; 9656 } 9657 9658 static int ipw_wx_get_wireless_mode(struct net_device *dev, 9659 struct iw_request_info *info, 9660 union iwreq_data *wrqu, char *extra) 9661 { 9662 struct ipw_priv *priv = libipw_priv(dev); 9663 mutex_lock(&priv->mutex); 9664 switch (priv->ieee->mode) { 9665 case IEEE_A: 9666 strscpy_pad(extra, "802.11a (1)", MAX_WX_STRING); 9667 break; 9668 case IEEE_B: 9669 strscpy_pad(extra, "802.11b (2)", MAX_WX_STRING); 9670 break; 9671 case IEEE_A | IEEE_B: 9672 strscpy_pad(extra, "802.11ab (3)", MAX_WX_STRING); 9673 break; 9674 case IEEE_G: 9675 strscpy_pad(extra, "802.11g (4)", MAX_WX_STRING); 9676 break; 9677 case IEEE_A | IEEE_G: 9678 strscpy_pad(extra, "802.11ag (5)", MAX_WX_STRING); 9679 break; 9680 case IEEE_B | IEEE_G: 9681 strscpy_pad(extra, "802.11bg (6)", MAX_WX_STRING); 9682 break; 9683 case IEEE_A | IEEE_B | IEEE_G: 9684 strscpy_pad(extra, "802.11abg (7)", MAX_WX_STRING); 9685 break; 9686 default: 9687 strscpy_pad(extra, "unknown", MAX_WX_STRING); 9688 break; 9689 } 9690 9691 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); 9692 9693 wrqu->data.length = strlen(extra) + 1; 9694 mutex_unlock(&priv->mutex); 9695 9696 return 0; 9697 } 9698 9699 static int ipw_wx_set_preamble(struct net_device *dev, 9700 struct iw_request_info *info, 9701 union iwreq_data *wrqu, char *extra) 9702 { 9703 struct ipw_priv *priv = libipw_priv(dev); 9704 int mode = *(int *)extra; 9705 mutex_lock(&priv->mutex); 9706 /* Switching from SHORT -> LONG requires a disassociation */ 9707 if (mode == 1) { 9708 if (!(priv->config & CFG_PREAMBLE_LONG)) { 9709 priv->config |= CFG_PREAMBLE_LONG; 9710 9711 /* Network configuration changed -- force [re]association */ 9712 IPW_DEBUG_ASSOC 9713 ("[re]association triggered due to preamble change.\n"); 9714 if (!ipw_disassociate(priv)) 9715 ipw_associate(priv); 9716 } 9717 goto done; 9718 } 9719 9720 if (mode == 0) { 9721 priv->config &= ~CFG_PREAMBLE_LONG; 9722 goto done; 9723 } 9724 mutex_unlock(&priv->mutex); 9725 return -EINVAL; 9726 9727 done: 9728 mutex_unlock(&priv->mutex); 9729 return 0; 9730 } 9731 9732 static int ipw_wx_get_preamble(struct net_device *dev, 9733 struct iw_request_info *info, 9734 union iwreq_data *wrqu, char *extra) 9735 { 9736 struct ipw_priv *priv = libipw_priv(dev); 9737 mutex_lock(&priv->mutex); 9738 if (priv->config & CFG_PREAMBLE_LONG) 9739 snprintf(wrqu->name, IFNAMSIZ, "long (1)"); 9740 else 9741 snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); 9742 mutex_unlock(&priv->mutex); 9743 return 0; 9744 } 9745 9746 #ifdef CONFIG_IPW2200_MONITOR 9747 static int ipw_wx_set_monitor(struct net_device *dev, 9748 struct iw_request_info *info, 9749 union iwreq_data *wrqu, char *extra) 9750 { 9751 struct ipw_priv *priv = libipw_priv(dev); 9752 int *parms = (int *)extra; 9753 int enable = (parms[0] > 0); 9754 mutex_lock(&priv->mutex); 9755 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); 9756 if (enable) { 9757 if (priv->ieee->iw_mode != IW_MODE_MONITOR) { 9758 #ifdef CONFIG_IPW2200_RADIOTAP 9759 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; 9760 #else 9761 priv->net_dev->type = ARPHRD_IEEE80211; 9762 #endif 9763 schedule_work(&priv->adapter_restart); 9764 } 9765 9766 ipw_set_channel(priv, parms[1]); 9767 } else { 9768 if (priv->ieee->iw_mode != IW_MODE_MONITOR) { 9769 mutex_unlock(&priv->mutex); 9770 return 0; 9771 } 9772 priv->net_dev->type = ARPHRD_ETHER; 9773 schedule_work(&priv->adapter_restart); 9774 } 9775 mutex_unlock(&priv->mutex); 9776 return 0; 9777 } 9778 9779 #endif /* CONFIG_IPW2200_MONITOR */ 9780 9781 static int ipw_wx_reset(struct net_device *dev, 9782 struct iw_request_info *info, 9783 union iwreq_data *wrqu, char *extra) 9784 { 9785 struct ipw_priv *priv = libipw_priv(dev); 9786 IPW_DEBUG_WX("RESET\n"); 9787 schedule_work(&priv->adapter_restart); 9788 return 0; 9789 } 9790 9791 static int ipw_wx_sw_reset(struct net_device *dev, 9792 struct iw_request_info *info, 9793 union iwreq_data *wrqu, char *extra) 9794 { 9795 struct ipw_priv *priv = libipw_priv(dev); 9796 union iwreq_data wrqu_sec = { 9797 .encoding = { 9798 .flags = IW_ENCODE_DISABLED, 9799 }, 9800 }; 9801 int ret; 9802 9803 IPW_DEBUG_WX("SW_RESET\n"); 9804 9805 mutex_lock(&priv->mutex); 9806 9807 ret = ipw_sw_reset(priv, 2); 9808 if (!ret) { 9809 free_firmware(); 9810 ipw_adapter_restart(priv); 9811 } 9812 9813 /* The SW reset bit might have been toggled on by the 'disable' 9814 * module parameter, so take appropriate action */ 9815 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); 9816 9817 mutex_unlock(&priv->mutex); 9818 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); 9819 mutex_lock(&priv->mutex); 9820 9821 if (!(priv->status & STATUS_RF_KILL_MASK)) { 9822 /* Configuration likely changed -- force [re]association */ 9823 IPW_DEBUG_ASSOC("[re]association triggered due to sw " 9824 "reset.\n"); 9825 if (!ipw_disassociate(priv)) 9826 ipw_associate(priv); 9827 } 9828 9829 mutex_unlock(&priv->mutex); 9830 9831 return 0; 9832 } 9833 9834 /* Rebase the WE IOCTLs to zero for the handler array */ 9835 static iw_handler ipw_wx_handlers[] = { 9836 IW_HANDLER(SIOCGIWNAME, ipw_wx_get_name), 9837 IW_HANDLER(SIOCSIWFREQ, ipw_wx_set_freq), 9838 IW_HANDLER(SIOCGIWFREQ, ipw_wx_get_freq), 9839 IW_HANDLER(SIOCSIWMODE, ipw_wx_set_mode), 9840 IW_HANDLER(SIOCGIWMODE, ipw_wx_get_mode), 9841 IW_HANDLER(SIOCSIWSENS, ipw_wx_set_sens), 9842 IW_HANDLER(SIOCGIWSENS, ipw_wx_get_sens), 9843 IW_HANDLER(SIOCGIWRANGE, ipw_wx_get_range), 9844 IW_HANDLER(SIOCSIWAP, ipw_wx_set_wap), 9845 IW_HANDLER(SIOCGIWAP, ipw_wx_get_wap), 9846 IW_HANDLER(SIOCSIWSCAN, ipw_wx_set_scan), 9847 IW_HANDLER(SIOCGIWSCAN, ipw_wx_get_scan), 9848 IW_HANDLER(SIOCSIWESSID, ipw_wx_set_essid), 9849 IW_HANDLER(SIOCGIWESSID, ipw_wx_get_essid), 9850 IW_HANDLER(SIOCSIWNICKN, ipw_wx_set_nick), 9851 IW_HANDLER(SIOCGIWNICKN, ipw_wx_get_nick), 9852 IW_HANDLER(SIOCSIWRATE, ipw_wx_set_rate), 9853 IW_HANDLER(SIOCGIWRATE, ipw_wx_get_rate), 9854 IW_HANDLER(SIOCSIWRTS, ipw_wx_set_rts), 9855 IW_HANDLER(SIOCGIWRTS, ipw_wx_get_rts), 9856 IW_HANDLER(SIOCSIWFRAG, ipw_wx_set_frag), 9857 IW_HANDLER(SIOCGIWFRAG, ipw_wx_get_frag), 9858 IW_HANDLER(SIOCSIWTXPOW, ipw_wx_set_txpow), 9859 IW_HANDLER(SIOCGIWTXPOW, ipw_wx_get_txpow), 9860 IW_HANDLER(SIOCSIWRETRY, ipw_wx_set_retry), 9861 IW_HANDLER(SIOCGIWRETRY, ipw_wx_get_retry), 9862 IW_HANDLER(SIOCSIWENCODE, ipw_wx_set_encode), 9863 IW_HANDLER(SIOCGIWENCODE, ipw_wx_get_encode), 9864 IW_HANDLER(SIOCSIWPOWER, ipw_wx_set_power), 9865 IW_HANDLER(SIOCGIWPOWER, ipw_wx_get_power), 9866 IW_HANDLER(SIOCSIWSPY, ipw_wx_set_spy), 9867 IW_HANDLER(SIOCGIWSPY, ipw_wx_get_spy), 9868 IW_HANDLER(SIOCSIWTHRSPY, ipw_wx_set_thrspy), 9869 IW_HANDLER(SIOCGIWTHRSPY, ipw_wx_get_thrspy), 9870 IW_HANDLER(SIOCSIWGENIE, ipw_wx_set_genie), 9871 IW_HANDLER(SIOCGIWGENIE, ipw_wx_get_genie), 9872 IW_HANDLER(SIOCSIWMLME, ipw_wx_set_mlme), 9873 IW_HANDLER(SIOCSIWAUTH, ipw_wx_set_auth), 9874 IW_HANDLER(SIOCGIWAUTH, ipw_wx_get_auth), 9875 IW_HANDLER(SIOCSIWENCODEEXT, ipw_wx_set_encodeext), 9876 IW_HANDLER(SIOCGIWENCODEEXT, ipw_wx_get_encodeext), 9877 }; 9878 9879 enum { 9880 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, 9881 IPW_PRIV_GET_POWER, 9882 IPW_PRIV_SET_MODE, 9883 IPW_PRIV_GET_MODE, 9884 IPW_PRIV_SET_PREAMBLE, 9885 IPW_PRIV_GET_PREAMBLE, 9886 IPW_PRIV_RESET, 9887 IPW_PRIV_SW_RESET, 9888 #ifdef CONFIG_IPW2200_MONITOR 9889 IPW_PRIV_SET_MONITOR, 9890 #endif 9891 }; 9892 9893 static struct iw_priv_args ipw_priv_args[] = { 9894 { 9895 .cmd = IPW_PRIV_SET_POWER, 9896 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 9897 .name = "set_power"}, 9898 { 9899 .cmd = IPW_PRIV_GET_POWER, 9900 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, 9901 .name = "get_power"}, 9902 { 9903 .cmd = IPW_PRIV_SET_MODE, 9904 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 9905 .name = "set_mode"}, 9906 { 9907 .cmd = IPW_PRIV_GET_MODE, 9908 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, 9909 .name = "get_mode"}, 9910 { 9911 .cmd = IPW_PRIV_SET_PREAMBLE, 9912 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 9913 .name = "set_preamble"}, 9914 { 9915 .cmd = IPW_PRIV_GET_PREAMBLE, 9916 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, 9917 .name = "get_preamble"}, 9918 { 9919 IPW_PRIV_RESET, 9920 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, 9921 { 9922 IPW_PRIV_SW_RESET, 9923 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, 9924 #ifdef CONFIG_IPW2200_MONITOR 9925 { 9926 IPW_PRIV_SET_MONITOR, 9927 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, 9928 #endif /* CONFIG_IPW2200_MONITOR */ 9929 }; 9930 9931 static iw_handler ipw_priv_handler[] = { 9932 ipw_wx_set_powermode, 9933 ipw_wx_get_powermode, 9934 ipw_wx_set_wireless_mode, 9935 ipw_wx_get_wireless_mode, 9936 ipw_wx_set_preamble, 9937 ipw_wx_get_preamble, 9938 ipw_wx_reset, 9939 ipw_wx_sw_reset, 9940 #ifdef CONFIG_IPW2200_MONITOR 9941 ipw_wx_set_monitor, 9942 #endif 9943 }; 9944 9945 static const struct iw_handler_def ipw_wx_handler_def = { 9946 .standard = ipw_wx_handlers, 9947 .num_standard = ARRAY_SIZE(ipw_wx_handlers), 9948 .num_private = ARRAY_SIZE(ipw_priv_handler), 9949 .num_private_args = ARRAY_SIZE(ipw_priv_args), 9950 .private = ipw_priv_handler, 9951 .private_args = ipw_priv_args, 9952 .get_wireless_stats = ipw_get_wireless_stats, 9953 }; 9954 9955 /* 9956 * Get wireless statistics. 9957 * Called by /proc/net/wireless 9958 * Also called by SIOCGIWSTATS 9959 */ 9960 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) 9961 { 9962 struct ipw_priv *priv = libipw_priv(dev); 9963 struct iw_statistics *wstats; 9964 9965 wstats = &priv->wstats; 9966 9967 /* if hw is disabled, then ipw_get_ordinal() can't be called. 9968 * netdev->get_wireless_stats seems to be called before fw is 9969 * initialized. STATUS_ASSOCIATED will only be set if the hw is up 9970 * and associated; if not associcated, the values are all meaningless 9971 * anyway, so set them all to NULL and INVALID */ 9972 if (!(priv->status & STATUS_ASSOCIATED)) { 9973 wstats->miss.beacon = 0; 9974 wstats->discard.retries = 0; 9975 wstats->qual.qual = 0; 9976 wstats->qual.level = 0; 9977 wstats->qual.noise = 0; 9978 wstats->qual.updated = 7; 9979 wstats->qual.updated |= IW_QUAL_NOISE_INVALID | 9980 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; 9981 return wstats; 9982 } 9983 9984 wstats->qual.qual = priv->quality; 9985 wstats->qual.level = priv->exp_avg_rssi; 9986 wstats->qual.noise = priv->exp_avg_noise; 9987 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | 9988 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; 9989 9990 wstats->miss.beacon = average_value(&priv->average_missed_beacons); 9991 wstats->discard.retries = priv->last_tx_failures; 9992 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; 9993 9994 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) 9995 goto fail_get_ordinal; 9996 wstats->discard.retries += tx_retry; */ 9997 9998 return wstats; 9999 } 10000 10001 /* net device stuff */ 10002 10003 static void init_sys_config(struct ipw_sys_config *sys_config) 10004 { 10005 memset(sys_config, 0, sizeof(struct ipw_sys_config)); 10006 sys_config->bt_coexistence = 0; 10007 sys_config->answer_broadcast_ssid_probe = 0; 10008 sys_config->accept_all_data_frames = 0; 10009 sys_config->accept_non_directed_frames = 1; 10010 sys_config->exclude_unicast_unencrypted = 0; 10011 sys_config->disable_unicast_decryption = 1; 10012 sys_config->exclude_multicast_unencrypted = 0; 10013 sys_config->disable_multicast_decryption = 1; 10014 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B) 10015 antenna = CFG_SYS_ANTENNA_BOTH; 10016 sys_config->antenna_diversity = antenna; 10017 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */ 10018 sys_config->dot11g_auto_detection = 0; 10019 sys_config->enable_cts_to_self = 0; 10020 sys_config->bt_coexist_collision_thr = 0; 10021 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */ 10022 sys_config->silence_threshold = 0x1e; 10023 } 10024 10025 static int ipw_net_open(struct net_device *dev) 10026 { 10027 IPW_DEBUG_INFO("dev->open\n"); 10028 netif_start_queue(dev); 10029 return 0; 10030 } 10031 10032 static int ipw_net_stop(struct net_device *dev) 10033 { 10034 IPW_DEBUG_INFO("dev->close\n"); 10035 netif_stop_queue(dev); 10036 return 0; 10037 } 10038 10039 /* 10040 todo: 10041 10042 modify to send one tfd per fragment instead of using chunking. otherwise 10043 we need to heavily modify the libipw_skb_to_txb. 10044 */ 10045 10046 static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb, 10047 int pri) 10048 { 10049 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *) 10050 txb->fragments[0]->data; 10051 int i = 0; 10052 struct tfd_frame *tfd; 10053 #ifdef CONFIG_IPW2200_QOS 10054 int tx_id = ipw_get_tx_queue_number(priv, pri); 10055 struct clx2_tx_queue *txq = &priv->txq[tx_id]; 10056 #else 10057 struct clx2_tx_queue *txq = &priv->txq[0]; 10058 #endif 10059 struct clx2_queue *q = &txq->q; 10060 u8 id, hdr_len, unicast; 10061 int fc; 10062 10063 if (!(priv->status & STATUS_ASSOCIATED)) 10064 goto drop; 10065 10066 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); 10067 switch (priv->ieee->iw_mode) { 10068 case IW_MODE_ADHOC: 10069 unicast = !is_multicast_ether_addr(hdr->addr1); 10070 id = ipw_find_station(priv, hdr->addr1); 10071 if (id == IPW_INVALID_STATION) { 10072 id = ipw_add_station(priv, hdr->addr1); 10073 if (id == IPW_INVALID_STATION) { 10074 IPW_WARNING("Attempt to send data to " 10075 "invalid cell: %pM\n", 10076 hdr->addr1); 10077 goto drop; 10078 } 10079 } 10080 break; 10081 10082 case IW_MODE_INFRA: 10083 default: 10084 unicast = !is_multicast_ether_addr(hdr->addr3); 10085 id = 0; 10086 break; 10087 } 10088 10089 tfd = &txq->bd[q->first_empty]; 10090 txq->txb[q->first_empty] = txb; 10091 memset(tfd, 0, sizeof(*tfd)); 10092 tfd->u.data.station_number = id; 10093 10094 tfd->control_flags.message_type = TX_FRAME_TYPE; 10095 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; 10096 10097 tfd->u.data.cmd_id = DINO_CMD_TX; 10098 tfd->u.data.len = cpu_to_le16(txb->payload_size); 10099 10100 if (priv->assoc_request.ieee_mode == IPW_B_MODE) 10101 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; 10102 else 10103 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; 10104 10105 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) 10106 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; 10107 10108 fc = le16_to_cpu(hdr->frame_ctl); 10109 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); 10110 10111 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); 10112 10113 if (likely(unicast)) 10114 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; 10115 10116 if (txb->encrypted && !priv->ieee->host_encrypt) { 10117 switch (priv->ieee->sec.level) { 10118 case SEC_LEVEL_3: 10119 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= 10120 cpu_to_le16(IEEE80211_FCTL_PROTECTED); 10121 /* XXX: ACK flag must be set for CCMP even if it 10122 * is a multicast/broadcast packet, because CCMP 10123 * group communication encrypted by GTK is 10124 * actually done by the AP. */ 10125 if (!unicast) 10126 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; 10127 10128 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; 10129 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; 10130 tfd->u.data.key_index = 0; 10131 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; 10132 break; 10133 case SEC_LEVEL_2: 10134 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= 10135 cpu_to_le16(IEEE80211_FCTL_PROTECTED); 10136 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; 10137 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; 10138 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; 10139 break; 10140 case SEC_LEVEL_1: 10141 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= 10142 cpu_to_le16(IEEE80211_FCTL_PROTECTED); 10143 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx; 10144 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <= 10145 40) 10146 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; 10147 else 10148 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; 10149 break; 10150 case SEC_LEVEL_0: 10151 break; 10152 default: 10153 printk(KERN_ERR "Unknown security level %d\n", 10154 priv->ieee->sec.level); 10155 break; 10156 } 10157 } else 10158 /* No hardware encryption */ 10159 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; 10160 10161 #ifdef CONFIG_IPW2200_QOS 10162 if (fc & IEEE80211_STYPE_QOS_DATA) 10163 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data)); 10164 #endif /* CONFIG_IPW2200_QOS */ 10165 10166 /* payload */ 10167 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), 10168 txb->nr_frags)); 10169 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", 10170 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); 10171 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { 10172 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", 10173 i, le32_to_cpu(tfd->u.data.num_chunks), 10174 txb->fragments[i]->len - hdr_len); 10175 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n", 10176 i, tfd->u.data.num_chunks, 10177 txb->fragments[i]->len - hdr_len); 10178 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, 10179 txb->fragments[i]->len - hdr_len); 10180 10181 tfd->u.data.chunk_ptr[i] = 10182 cpu_to_le32(dma_map_single(&priv->pci_dev->dev, 10183 txb->fragments[i]->data + hdr_len, 10184 txb->fragments[i]->len - hdr_len, 10185 DMA_TO_DEVICE)); 10186 tfd->u.data.chunk_len[i] = 10187 cpu_to_le16(txb->fragments[i]->len - hdr_len); 10188 } 10189 10190 if (i != txb->nr_frags) { 10191 struct sk_buff *skb; 10192 u16 remaining_bytes = 0; 10193 int j; 10194 10195 for (j = i; j < txb->nr_frags; j++) 10196 remaining_bytes += txb->fragments[j]->len - hdr_len; 10197 10198 printk(KERN_INFO "Trying to reallocate for %d bytes\n", 10199 remaining_bytes); 10200 skb = alloc_skb(remaining_bytes, GFP_ATOMIC); 10201 if (skb != NULL) { 10202 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); 10203 for (j = i; j < txb->nr_frags; j++) { 10204 int size = txb->fragments[j]->len - hdr_len; 10205 10206 printk(KERN_INFO "Adding frag %d %d...\n", 10207 j, size); 10208 skb_put_data(skb, 10209 txb->fragments[j]->data + hdr_len, 10210 size); 10211 } 10212 dev_kfree_skb_any(txb->fragments[i]); 10213 txb->fragments[i] = skb; 10214 tfd->u.data.chunk_ptr[i] = 10215 cpu_to_le32(dma_map_single(&priv->pci_dev->dev, 10216 skb->data, 10217 remaining_bytes, 10218 DMA_TO_DEVICE)); 10219 10220 le32_add_cpu(&tfd->u.data.num_chunks, 1); 10221 } 10222 } 10223 10224 /* kick DMA */ 10225 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); 10226 ipw_write32(priv, q->reg_w, q->first_empty); 10227 10228 if (ipw_tx_queue_space(q) < q->high_mark) 10229 netif_stop_queue(priv->net_dev); 10230 10231 return NETDEV_TX_OK; 10232 10233 drop: 10234 IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); 10235 libipw_txb_free(txb); 10236 return NETDEV_TX_OK; 10237 } 10238 10239 static int ipw_net_is_queue_full(struct net_device *dev, int pri) 10240 { 10241 struct ipw_priv *priv = libipw_priv(dev); 10242 #ifdef CONFIG_IPW2200_QOS 10243 int tx_id = ipw_get_tx_queue_number(priv, pri); 10244 struct clx2_tx_queue *txq = &priv->txq[tx_id]; 10245 #else 10246 struct clx2_tx_queue *txq = &priv->txq[0]; 10247 #endif /* CONFIG_IPW2200_QOS */ 10248 10249 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark) 10250 return 1; 10251 10252 return 0; 10253 } 10254 10255 #ifdef CONFIG_IPW2200_PROMISCUOUS 10256 static void ipw_handle_promiscuous_tx(struct ipw_priv *priv, 10257 struct libipw_txb *txb) 10258 { 10259 struct libipw_rx_stats dummystats; 10260 struct ieee80211_hdr *hdr; 10261 u8 n; 10262 u16 filter = priv->prom_priv->filter; 10263 int hdr_only = 0; 10264 10265 if (filter & IPW_PROM_NO_TX) 10266 return; 10267 10268 memset(&dummystats, 0, sizeof(dummystats)); 10269 10270 /* Filtering of fragment chains is done against the first fragment */ 10271 hdr = (void *)txb->fragments[0]->data; 10272 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { 10273 if (filter & IPW_PROM_NO_MGMT) 10274 return; 10275 if (filter & IPW_PROM_MGMT_HEADER_ONLY) 10276 hdr_only = 1; 10277 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { 10278 if (filter & IPW_PROM_NO_CTL) 10279 return; 10280 if (filter & IPW_PROM_CTL_HEADER_ONLY) 10281 hdr_only = 1; 10282 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { 10283 if (filter & IPW_PROM_NO_DATA) 10284 return; 10285 if (filter & IPW_PROM_DATA_HEADER_ONLY) 10286 hdr_only = 1; 10287 } 10288 10289 for(n=0; n<txb->nr_frags; ++n) { 10290 struct sk_buff *src = txb->fragments[n]; 10291 struct sk_buff *dst; 10292 struct ieee80211_radiotap_header *rt_hdr; 10293 int len; 10294 10295 if (hdr_only) { 10296 hdr = (void *)src->data; 10297 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); 10298 } else 10299 len = src->len; 10300 10301 dst = alloc_skb(len + sizeof(*rt_hdr) + sizeof(u16)*2, GFP_ATOMIC); 10302 if (!dst) 10303 continue; 10304 10305 rt_hdr = skb_put(dst, sizeof(*rt_hdr)); 10306 10307 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION; 10308 rt_hdr->it_pad = 0; 10309 rt_hdr->it_present = 0; /* after all, it's just an idea */ 10310 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL); 10311 10312 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16( 10313 ieee80211chan2mhz(priv->channel)); 10314 if (priv->channel > 14) /* 802.11a */ 10315 *(__le16*)skb_put(dst, sizeof(u16)) = 10316 cpu_to_le16(IEEE80211_CHAN_OFDM | 10317 IEEE80211_CHAN_5GHZ); 10318 else if (priv->ieee->mode == IEEE_B) /* 802.11b */ 10319 *(__le16*)skb_put(dst, sizeof(u16)) = 10320 cpu_to_le16(IEEE80211_CHAN_CCK | 10321 IEEE80211_CHAN_2GHZ); 10322 else /* 802.11g */ 10323 *(__le16*)skb_put(dst, sizeof(u16)) = 10324 cpu_to_le16(IEEE80211_CHAN_OFDM | 10325 IEEE80211_CHAN_2GHZ); 10326 10327 rt_hdr->it_len = cpu_to_le16(dst->len); 10328 10329 skb_copy_from_linear_data(src, skb_put(dst, len), len); 10330 10331 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats)) 10332 dev_kfree_skb_any(dst); 10333 } 10334 } 10335 #endif 10336 10337 static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb, 10338 struct net_device *dev, int pri) 10339 { 10340 struct ipw_priv *priv = libipw_priv(dev); 10341 unsigned long flags; 10342 netdev_tx_t ret; 10343 10344 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); 10345 spin_lock_irqsave(&priv->lock, flags); 10346 10347 #ifdef CONFIG_IPW2200_PROMISCUOUS 10348 if (rtap_iface && netif_running(priv->prom_net_dev)) 10349 ipw_handle_promiscuous_tx(priv, txb); 10350 #endif 10351 10352 ret = ipw_tx_skb(priv, txb, pri); 10353 if (ret == NETDEV_TX_OK) 10354 __ipw_led_activity_on(priv); 10355 spin_unlock_irqrestore(&priv->lock, flags); 10356 10357 return ret; 10358 } 10359 10360 static void ipw_net_set_multicast_list(struct net_device *dev) 10361 { 10362 10363 } 10364 10365 static int ipw_net_set_mac_address(struct net_device *dev, void *p) 10366 { 10367 struct ipw_priv *priv = libipw_priv(dev); 10368 struct sockaddr *addr = p; 10369 10370 if (!is_valid_ether_addr(addr->sa_data)) 10371 return -EADDRNOTAVAIL; 10372 mutex_lock(&priv->mutex); 10373 priv->config |= CFG_CUSTOM_MAC; 10374 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); 10375 printk(KERN_INFO "%s: Setting MAC to %pM\n", 10376 priv->net_dev->name, priv->mac_addr); 10377 schedule_work(&priv->adapter_restart); 10378 mutex_unlock(&priv->mutex); 10379 return 0; 10380 } 10381 10382 static void ipw_ethtool_get_drvinfo(struct net_device *dev, 10383 struct ethtool_drvinfo *info) 10384 { 10385 struct ipw_priv *p = libipw_priv(dev); 10386 char vers[64]; 10387 u32 len; 10388 10389 strscpy(info->driver, DRV_NAME, sizeof(info->driver)); 10390 strscpy(info->version, DRV_VERSION, sizeof(info->version)); 10391 10392 len = sizeof(vers); 10393 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); 10394 10395 strscpy(info->fw_version, vers, sizeof(info->fw_version)); 10396 strscpy(info->bus_info, pci_name(p->pci_dev), 10397 sizeof(info->bus_info)); 10398 } 10399 10400 static u32 ipw_ethtool_get_link(struct net_device *dev) 10401 { 10402 struct ipw_priv *priv = libipw_priv(dev); 10403 return (priv->status & STATUS_ASSOCIATED) != 0; 10404 } 10405 10406 static int ipw_ethtool_get_eeprom_len(struct net_device *dev) 10407 { 10408 return IPW_EEPROM_IMAGE_SIZE; 10409 } 10410 10411 static int ipw_ethtool_get_eeprom(struct net_device *dev, 10412 struct ethtool_eeprom *eeprom, u8 * bytes) 10413 { 10414 struct ipw_priv *p = libipw_priv(dev); 10415 10416 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) 10417 return -EINVAL; 10418 mutex_lock(&p->mutex); 10419 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); 10420 mutex_unlock(&p->mutex); 10421 return 0; 10422 } 10423 10424 static int ipw_ethtool_set_eeprom(struct net_device *dev, 10425 struct ethtool_eeprom *eeprom, u8 * bytes) 10426 { 10427 struct ipw_priv *p = libipw_priv(dev); 10428 int i; 10429 10430 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) 10431 return -EINVAL; 10432 mutex_lock(&p->mutex); 10433 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); 10434 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) 10435 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); 10436 mutex_unlock(&p->mutex); 10437 return 0; 10438 } 10439 10440 static const struct ethtool_ops ipw_ethtool_ops = { 10441 .get_link = ipw_ethtool_get_link, 10442 .get_drvinfo = ipw_ethtool_get_drvinfo, 10443 .get_eeprom_len = ipw_ethtool_get_eeprom_len, 10444 .get_eeprom = ipw_ethtool_get_eeprom, 10445 .set_eeprom = ipw_ethtool_set_eeprom, 10446 }; 10447 10448 static irqreturn_t ipw_isr(int irq, void *data) 10449 { 10450 struct ipw_priv *priv = data; 10451 u32 inta, inta_mask; 10452 10453 if (!priv) 10454 return IRQ_NONE; 10455 10456 spin_lock(&priv->irq_lock); 10457 10458 if (!(priv->status & STATUS_INT_ENABLED)) { 10459 /* IRQ is disabled */ 10460 goto none; 10461 } 10462 10463 inta = ipw_read32(priv, IPW_INTA_RW); 10464 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); 10465 10466 if (inta == 0xFFFFFFFF) { 10467 /* Hardware disappeared */ 10468 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); 10469 goto none; 10470 } 10471 10472 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { 10473 /* Shared interrupt */ 10474 goto none; 10475 } 10476 10477 /* tell the device to stop sending interrupts */ 10478 __ipw_disable_interrupts(priv); 10479 10480 /* ack current interrupts */ 10481 inta &= (IPW_INTA_MASK_ALL & inta_mask); 10482 ipw_write32(priv, IPW_INTA_RW, inta); 10483 10484 /* Cache INTA value for our tasklet */ 10485 priv->isr_inta = inta; 10486 10487 tasklet_schedule(&priv->irq_tasklet); 10488 10489 spin_unlock(&priv->irq_lock); 10490 10491 return IRQ_HANDLED; 10492 none: 10493 spin_unlock(&priv->irq_lock); 10494 return IRQ_NONE; 10495 } 10496 10497 static void ipw_rf_kill(void *adapter) 10498 { 10499 struct ipw_priv *priv = adapter; 10500 unsigned long flags; 10501 10502 spin_lock_irqsave(&priv->lock, flags); 10503 10504 if (rf_kill_active(priv)) { 10505 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); 10506 schedule_delayed_work(&priv->rf_kill, 2 * HZ); 10507 goto exit_unlock; 10508 } 10509 10510 /* RF Kill is now disabled, so bring the device back up */ 10511 10512 if (!(priv->status & STATUS_RF_KILL_MASK)) { 10513 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " 10514 "device\n"); 10515 10516 /* we can not do an adapter restart while inside an irq lock */ 10517 schedule_work(&priv->adapter_restart); 10518 } else 10519 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " 10520 "enabled\n"); 10521 10522 exit_unlock: 10523 spin_unlock_irqrestore(&priv->lock, flags); 10524 } 10525 10526 static void ipw_bg_rf_kill(struct work_struct *work) 10527 { 10528 struct ipw_priv *priv = 10529 container_of(work, struct ipw_priv, rf_kill.work); 10530 mutex_lock(&priv->mutex); 10531 ipw_rf_kill(priv); 10532 mutex_unlock(&priv->mutex); 10533 } 10534 10535 static void ipw_link_up(struct ipw_priv *priv) 10536 { 10537 priv->last_seq_num = -1; 10538 priv->last_frag_num = -1; 10539 priv->last_packet_time = 0; 10540 10541 netif_carrier_on(priv->net_dev); 10542 10543 cancel_delayed_work(&priv->request_scan); 10544 cancel_delayed_work(&priv->request_direct_scan); 10545 cancel_delayed_work(&priv->request_passive_scan); 10546 cancel_delayed_work(&priv->scan_event); 10547 ipw_reset_stats(priv); 10548 /* Ensure the rate is updated immediately */ 10549 priv->last_rate = ipw_get_current_rate(priv); 10550 ipw_gather_stats(priv); 10551 ipw_led_link_up(priv); 10552 notify_wx_assoc_event(priv); 10553 10554 if (priv->config & CFG_BACKGROUND_SCAN) 10555 schedule_delayed_work(&priv->request_scan, HZ); 10556 } 10557 10558 static void ipw_bg_link_up(struct work_struct *work) 10559 { 10560 struct ipw_priv *priv = 10561 container_of(work, struct ipw_priv, link_up); 10562 mutex_lock(&priv->mutex); 10563 ipw_link_up(priv); 10564 mutex_unlock(&priv->mutex); 10565 } 10566 10567 static void ipw_link_down(struct ipw_priv *priv) 10568 { 10569 ipw_led_link_down(priv); 10570 netif_carrier_off(priv->net_dev); 10571 notify_wx_assoc_event(priv); 10572 10573 /* Cancel any queued work ... */ 10574 cancel_delayed_work(&priv->request_scan); 10575 cancel_delayed_work(&priv->request_direct_scan); 10576 cancel_delayed_work(&priv->request_passive_scan); 10577 cancel_delayed_work(&priv->adhoc_check); 10578 cancel_delayed_work(&priv->gather_stats); 10579 10580 ipw_reset_stats(priv); 10581 10582 if (!(priv->status & STATUS_EXIT_PENDING)) { 10583 /* Queue up another scan... */ 10584 schedule_delayed_work(&priv->request_scan, 0); 10585 } else 10586 cancel_delayed_work(&priv->scan_event); 10587 } 10588 10589 static void ipw_bg_link_down(struct work_struct *work) 10590 { 10591 struct ipw_priv *priv = 10592 container_of(work, struct ipw_priv, link_down); 10593 mutex_lock(&priv->mutex); 10594 ipw_link_down(priv); 10595 mutex_unlock(&priv->mutex); 10596 } 10597 10598 static void ipw_setup_deferred_work(struct ipw_priv *priv) 10599 { 10600 init_waitqueue_head(&priv->wait_command_queue); 10601 init_waitqueue_head(&priv->wait_state); 10602 10603 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check); 10604 INIT_WORK(&priv->associate, ipw_bg_associate); 10605 INIT_WORK(&priv->disassociate, ipw_bg_disassociate); 10606 INIT_WORK(&priv->system_config, ipw_system_config); 10607 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish); 10608 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart); 10609 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill); 10610 INIT_WORK(&priv->up, ipw_bg_up); 10611 INIT_WORK(&priv->down, ipw_bg_down); 10612 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan); 10613 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan); 10614 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan); 10615 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event); 10616 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats); 10617 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan); 10618 INIT_WORK(&priv->roam, ipw_bg_roam); 10619 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check); 10620 INIT_WORK(&priv->link_up, ipw_bg_link_up); 10621 INIT_WORK(&priv->link_down, ipw_bg_link_down); 10622 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on); 10623 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off); 10624 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off); 10625 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network); 10626 10627 #ifdef CONFIG_IPW2200_QOS 10628 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate); 10629 #endif /* CONFIG_IPW2200_QOS */ 10630 10631 tasklet_setup(&priv->irq_tasklet, ipw_irq_tasklet); 10632 } 10633 10634 static void shim__set_security(struct net_device *dev, 10635 struct libipw_security *sec) 10636 { 10637 struct ipw_priv *priv = libipw_priv(dev); 10638 int i; 10639 for (i = 0; i < 4; i++) { 10640 if (sec->flags & (1 << i)) { 10641 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; 10642 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; 10643 if (sec->key_sizes[i] == 0) 10644 priv->ieee->sec.flags &= ~(1 << i); 10645 else { 10646 memcpy(priv->ieee->sec.keys[i], sec->keys[i], 10647 sec->key_sizes[i]); 10648 priv->ieee->sec.flags |= (1 << i); 10649 } 10650 priv->status |= STATUS_SECURITY_UPDATED; 10651 } else if (sec->level != SEC_LEVEL_1) 10652 priv->ieee->sec.flags &= ~(1 << i); 10653 } 10654 10655 if (sec->flags & SEC_ACTIVE_KEY) { 10656 priv->ieee->sec.active_key = sec->active_key; 10657 priv->ieee->sec.flags |= SEC_ACTIVE_KEY; 10658 priv->status |= STATUS_SECURITY_UPDATED; 10659 } else 10660 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; 10661 10662 if ((sec->flags & SEC_AUTH_MODE) && 10663 (priv->ieee->sec.auth_mode != sec->auth_mode)) { 10664 priv->ieee->sec.auth_mode = sec->auth_mode; 10665 priv->ieee->sec.flags |= SEC_AUTH_MODE; 10666 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) 10667 priv->capability |= CAP_SHARED_KEY; 10668 else 10669 priv->capability &= ~CAP_SHARED_KEY; 10670 priv->status |= STATUS_SECURITY_UPDATED; 10671 } 10672 10673 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { 10674 priv->ieee->sec.flags |= SEC_ENABLED; 10675 priv->ieee->sec.enabled = sec->enabled; 10676 priv->status |= STATUS_SECURITY_UPDATED; 10677 if (sec->enabled) 10678 priv->capability |= CAP_PRIVACY_ON; 10679 else 10680 priv->capability &= ~CAP_PRIVACY_ON; 10681 } 10682 10683 if (sec->flags & SEC_ENCRYPT) 10684 priv->ieee->sec.encrypt = sec->encrypt; 10685 10686 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { 10687 priv->ieee->sec.level = sec->level; 10688 priv->ieee->sec.flags |= SEC_LEVEL; 10689 priv->status |= STATUS_SECURITY_UPDATED; 10690 } 10691 10692 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) 10693 ipw_set_hwcrypto_keys(priv); 10694 10695 /* To match current functionality of ipw2100 (which works well w/ 10696 * various supplicants, we don't force a disassociate if the 10697 * privacy capability changes ... */ 10698 #if 0 10699 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && 10700 (((priv->assoc_request.capability & 10701 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) || 10702 (!(priv->assoc_request.capability & 10703 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) { 10704 IPW_DEBUG_ASSOC("Disassociating due to capability " 10705 "change.\n"); 10706 ipw_disassociate(priv); 10707 } 10708 #endif 10709 } 10710 10711 static int init_supported_rates(struct ipw_priv *priv, 10712 struct ipw_supported_rates *rates) 10713 { 10714 /* TODO: Mask out rates based on priv->rates_mask */ 10715 10716 memset(rates, 0, sizeof(*rates)); 10717 /* configure supported rates */ 10718 switch (priv->ieee->freq_band) { 10719 case LIBIPW_52GHZ_BAND: 10720 rates->ieee_mode = IPW_A_MODE; 10721 rates->purpose = IPW_RATE_CAPABILITIES; 10722 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, 10723 LIBIPW_OFDM_DEFAULT_RATES_MASK); 10724 break; 10725 10726 default: /* Mixed or 2.4Ghz */ 10727 rates->ieee_mode = IPW_G_MODE; 10728 rates->purpose = IPW_RATE_CAPABILITIES; 10729 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION, 10730 LIBIPW_CCK_DEFAULT_RATES_MASK); 10731 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) { 10732 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, 10733 LIBIPW_OFDM_DEFAULT_RATES_MASK); 10734 } 10735 break; 10736 } 10737 10738 return 0; 10739 } 10740 10741 static int ipw_config(struct ipw_priv *priv) 10742 { 10743 /* This is only called from ipw_up, which resets/reloads the firmware 10744 so, we don't need to first disable the card before we configure 10745 it */ 10746 if (ipw_set_tx_power(priv)) 10747 goto error; 10748 10749 /* initialize adapter address */ 10750 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) 10751 goto error; 10752 10753 /* set basic system config settings */ 10754 init_sys_config(&priv->sys_config); 10755 10756 /* Support Bluetooth if we have BT h/w on board, and user wants to. 10757 * Does not support BT priority yet (don't abort or defer our Tx) */ 10758 if (bt_coexist) { 10759 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; 10760 10761 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) 10762 priv->sys_config.bt_coexistence 10763 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; 10764 if (bt_caps & EEPROM_SKU_CAP_BT_OOB) 10765 priv->sys_config.bt_coexistence 10766 |= CFG_BT_COEXISTENCE_OOB; 10767 } 10768 10769 #ifdef CONFIG_IPW2200_PROMISCUOUS 10770 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { 10771 priv->sys_config.accept_all_data_frames = 1; 10772 priv->sys_config.accept_non_directed_frames = 1; 10773 priv->sys_config.accept_all_mgmt_bcpr = 1; 10774 priv->sys_config.accept_all_mgmt_frames = 1; 10775 } 10776 #endif 10777 10778 if (priv->ieee->iw_mode == IW_MODE_ADHOC) 10779 priv->sys_config.answer_broadcast_ssid_probe = 1; 10780 else 10781 priv->sys_config.answer_broadcast_ssid_probe = 0; 10782 10783 if (ipw_send_system_config(priv)) 10784 goto error; 10785 10786 init_supported_rates(priv, &priv->rates); 10787 if (ipw_send_supported_rates(priv, &priv->rates)) 10788 goto error; 10789 10790 /* Set request-to-send threshold */ 10791 if (priv->rts_threshold) { 10792 if (ipw_send_rts_threshold(priv, priv->rts_threshold)) 10793 goto error; 10794 } 10795 #ifdef CONFIG_IPW2200_QOS 10796 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); 10797 ipw_qos_activate(priv, NULL); 10798 #endif /* CONFIG_IPW2200_QOS */ 10799 10800 if (ipw_set_random_seed(priv)) 10801 goto error; 10802 10803 /* final state transition to the RUN state */ 10804 if (ipw_send_host_complete(priv)) 10805 goto error; 10806 10807 priv->status |= STATUS_INIT; 10808 10809 ipw_led_init(priv); 10810 ipw_led_radio_on(priv); 10811 priv->notif_missed_beacons = 0; 10812 10813 /* Set hardware WEP key if it is configured. */ 10814 if ((priv->capability & CAP_PRIVACY_ON) && 10815 (priv->ieee->sec.level == SEC_LEVEL_1) && 10816 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) 10817 ipw_set_hwcrypto_keys(priv); 10818 10819 return 0; 10820 10821 error: 10822 return -EIO; 10823 } 10824 10825 /* 10826 * NOTE: 10827 * 10828 * These tables have been tested in conjunction with the 10829 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. 10830 * 10831 * Altering this values, using it on other hardware, or in geographies 10832 * not intended for resale of the above mentioned Intel adapters has 10833 * not been tested. 10834 * 10835 * Remember to update the table in README.ipw2200 when changing this 10836 * table. 10837 * 10838 */ 10839 static const struct libipw_geo ipw_geos[] = { 10840 { /* Restricted */ 10841 "---", 10842 .bg_channels = 11, 10843 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 10844 {2427, 4}, {2432, 5}, {2437, 6}, 10845 {2442, 7}, {2447, 8}, {2452, 9}, 10846 {2457, 10}, {2462, 11}}, 10847 }, 10848 10849 { /* Custom US/Canada */ 10850 "ZZF", 10851 .bg_channels = 11, 10852 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 10853 {2427, 4}, {2432, 5}, {2437, 6}, 10854 {2442, 7}, {2447, 8}, {2452, 9}, 10855 {2457, 10}, {2462, 11}}, 10856 .a_channels = 8, 10857 .a = {{5180, 36}, 10858 {5200, 40}, 10859 {5220, 44}, 10860 {5240, 48}, 10861 {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, 10862 {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, 10863 {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, 10864 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}}, 10865 }, 10866 10867 { /* Rest of World */ 10868 "ZZD", 10869 .bg_channels = 13, 10870 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 10871 {2427, 4}, {2432, 5}, {2437, 6}, 10872 {2442, 7}, {2447, 8}, {2452, 9}, 10873 {2457, 10}, {2462, 11}, {2467, 12}, 10874 {2472, 13}}, 10875 }, 10876 10877 { /* Custom USA & Europe & High */ 10878 "ZZA", 10879 .bg_channels = 11, 10880 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 10881 {2427, 4}, {2432, 5}, {2437, 6}, 10882 {2442, 7}, {2447, 8}, {2452, 9}, 10883 {2457, 10}, {2462, 11}}, 10884 .a_channels = 13, 10885 .a = {{5180, 36}, 10886 {5200, 40}, 10887 {5220, 44}, 10888 {5240, 48}, 10889 {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, 10890 {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, 10891 {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, 10892 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, 10893 {5745, 149}, 10894 {5765, 153}, 10895 {5785, 157}, 10896 {5805, 161}, 10897 {5825, 165}}, 10898 }, 10899 10900 { /* Custom NA & Europe */ 10901 "ZZB", 10902 .bg_channels = 11, 10903 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 10904 {2427, 4}, {2432, 5}, {2437, 6}, 10905 {2442, 7}, {2447, 8}, {2452, 9}, 10906 {2457, 10}, {2462, 11}}, 10907 .a_channels = 13, 10908 .a = {{5180, 36}, 10909 {5200, 40}, 10910 {5220, 44}, 10911 {5240, 48}, 10912 {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, 10913 {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, 10914 {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, 10915 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, 10916 {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, 10917 {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, 10918 {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, 10919 {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, 10920 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, 10921 }, 10922 10923 { /* Custom Japan */ 10924 "ZZC", 10925 .bg_channels = 11, 10926 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 10927 {2427, 4}, {2432, 5}, {2437, 6}, 10928 {2442, 7}, {2447, 8}, {2452, 9}, 10929 {2457, 10}, {2462, 11}}, 10930 .a_channels = 4, 10931 .a = {{5170, 34}, {5190, 38}, 10932 {5210, 42}, {5230, 46}}, 10933 }, 10934 10935 { /* Custom */ 10936 "ZZM", 10937 .bg_channels = 11, 10938 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 10939 {2427, 4}, {2432, 5}, {2437, 6}, 10940 {2442, 7}, {2447, 8}, {2452, 9}, 10941 {2457, 10}, {2462, 11}}, 10942 }, 10943 10944 { /* Europe */ 10945 "ZZE", 10946 .bg_channels = 13, 10947 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 10948 {2427, 4}, {2432, 5}, {2437, 6}, 10949 {2442, 7}, {2447, 8}, {2452, 9}, 10950 {2457, 10}, {2462, 11}, {2467, 12}, 10951 {2472, 13}}, 10952 .a_channels = 19, 10953 .a = {{5180, 36}, 10954 {5200, 40}, 10955 {5220, 44}, 10956 {5240, 48}, 10957 {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, 10958 {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, 10959 {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, 10960 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, 10961 {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, 10962 {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, 10963 {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, 10964 {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, 10965 {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, 10966 {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, 10967 {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, 10968 {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, 10969 {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, 10970 {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, 10971 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}}, 10972 }, 10973 10974 { /* Custom Japan */ 10975 "ZZJ", 10976 .bg_channels = 14, 10977 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 10978 {2427, 4}, {2432, 5}, {2437, 6}, 10979 {2442, 7}, {2447, 8}, {2452, 9}, 10980 {2457, 10}, {2462, 11}, {2467, 12}, 10981 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}}, 10982 .a_channels = 4, 10983 .a = {{5170, 34}, {5190, 38}, 10984 {5210, 42}, {5230, 46}}, 10985 }, 10986 10987 { /* Rest of World */ 10988 "ZZR", 10989 .bg_channels = 14, 10990 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 10991 {2427, 4}, {2432, 5}, {2437, 6}, 10992 {2442, 7}, {2447, 8}, {2452, 9}, 10993 {2457, 10}, {2462, 11}, {2467, 12}, 10994 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY | 10995 LIBIPW_CH_PASSIVE_ONLY}}, 10996 }, 10997 10998 { /* High Band */ 10999 "ZZH", 11000 .bg_channels = 13, 11001 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 11002 {2427, 4}, {2432, 5}, {2437, 6}, 11003 {2442, 7}, {2447, 8}, {2452, 9}, 11004 {2457, 10}, {2462, 11}, 11005 {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, 11006 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, 11007 .a_channels = 4, 11008 .a = {{5745, 149}, {5765, 153}, 11009 {5785, 157}, {5805, 161}}, 11010 }, 11011 11012 { /* Custom Europe */ 11013 "ZZG", 11014 .bg_channels = 13, 11015 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 11016 {2427, 4}, {2432, 5}, {2437, 6}, 11017 {2442, 7}, {2447, 8}, {2452, 9}, 11018 {2457, 10}, {2462, 11}, 11019 {2467, 12}, {2472, 13}}, 11020 .a_channels = 4, 11021 .a = {{5180, 36}, {5200, 40}, 11022 {5220, 44}, {5240, 48}}, 11023 }, 11024 11025 { /* Europe */ 11026 "ZZK", 11027 .bg_channels = 13, 11028 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 11029 {2427, 4}, {2432, 5}, {2437, 6}, 11030 {2442, 7}, {2447, 8}, {2452, 9}, 11031 {2457, 10}, {2462, 11}, 11032 {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, 11033 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, 11034 .a_channels = 24, 11035 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, 11036 {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, 11037 {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, 11038 {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, 11039 {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, 11040 {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, 11041 {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, 11042 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, 11043 {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, 11044 {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, 11045 {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, 11046 {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, 11047 {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, 11048 {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, 11049 {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, 11050 {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, 11051 {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, 11052 {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, 11053 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}, 11054 {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, 11055 {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, 11056 {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, 11057 {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, 11058 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, 11059 }, 11060 11061 { /* Europe */ 11062 "ZZL", 11063 .bg_channels = 11, 11064 .bg = {{2412, 1}, {2417, 2}, {2422, 3}, 11065 {2427, 4}, {2432, 5}, {2437, 6}, 11066 {2442, 7}, {2447, 8}, {2452, 9}, 11067 {2457, 10}, {2462, 11}}, 11068 .a_channels = 13, 11069 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, 11070 {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, 11071 {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, 11072 {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, 11073 {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, 11074 {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, 11075 {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, 11076 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, 11077 {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, 11078 {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, 11079 {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, 11080 {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, 11081 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, 11082 } 11083 }; 11084 11085 static void ipw_set_geo(struct ipw_priv *priv) 11086 { 11087 int j; 11088 11089 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { 11090 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], 11091 ipw_geos[j].name, 3)) 11092 break; 11093 } 11094 11095 if (j == ARRAY_SIZE(ipw_geos)) { 11096 IPW_WARNING("SKU [%c%c%c] not recognized.\n", 11097 priv->eeprom[EEPROM_COUNTRY_CODE + 0], 11098 priv->eeprom[EEPROM_COUNTRY_CODE + 1], 11099 priv->eeprom[EEPROM_COUNTRY_CODE + 2]); 11100 j = 0; 11101 } 11102 11103 libipw_set_geo(priv->ieee, &ipw_geos[j]); 11104 } 11105 11106 #define MAX_HW_RESTARTS 5 11107 static int ipw_up(struct ipw_priv *priv) 11108 { 11109 int rc, i; 11110 11111 /* Age scan list entries found before suspend */ 11112 if (priv->suspend_time) { 11113 libipw_networks_age(priv->ieee, priv->suspend_time); 11114 priv->suspend_time = 0; 11115 } 11116 11117 if (priv->status & STATUS_EXIT_PENDING) 11118 return -EIO; 11119 11120 if (cmdlog && !priv->cmdlog) { 11121 priv->cmdlog = kzalloc_objs(*priv->cmdlog, cmdlog); 11122 if (priv->cmdlog == NULL) { 11123 IPW_ERROR("Error allocating %d command log entries.\n", 11124 cmdlog); 11125 return -ENOMEM; 11126 } else { 11127 priv->cmdlog_len = cmdlog; 11128 } 11129 } 11130 11131 for (i = 0; i < MAX_HW_RESTARTS; i++) { 11132 /* Load the microcode, firmware, and eeprom. 11133 * Also start the clocks. */ 11134 rc = ipw_load(priv); 11135 if (rc) { 11136 IPW_ERROR("Unable to load firmware: %d\n", rc); 11137 return rc; 11138 } 11139 11140 ipw_init_ordinals(priv); 11141 if (!(priv->config & CFG_CUSTOM_MAC)) 11142 eeprom_parse_mac(priv, priv->mac_addr); 11143 eth_hw_addr_set(priv->net_dev, priv->mac_addr); 11144 11145 ipw_set_geo(priv); 11146 11147 if (priv->status & STATUS_RF_KILL_SW) { 11148 IPW_WARNING("Radio disabled by module parameter.\n"); 11149 return 0; 11150 } else if (rf_kill_active(priv)) { 11151 IPW_WARNING("Radio Frequency Kill Switch is On:\n" 11152 "Kill switch must be turned off for " 11153 "wireless networking to work.\n"); 11154 schedule_delayed_work(&priv->rf_kill, 2 * HZ); 11155 return 0; 11156 } 11157 11158 rc = ipw_config(priv); 11159 if (!rc) { 11160 IPW_DEBUG_INFO("Configured device on count %i\n", i); 11161 11162 /* If configure to try and auto-associate, kick 11163 * off a scan. */ 11164 schedule_delayed_work(&priv->request_scan, 0); 11165 11166 return 0; 11167 } 11168 11169 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); 11170 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", 11171 i, MAX_HW_RESTARTS); 11172 11173 /* We had an error bringing up the hardware, so take it 11174 * all the way back down so we can try again */ 11175 ipw_down(priv); 11176 } 11177 11178 /* tried to restart and config the device for as long as our 11179 * patience could withstand */ 11180 IPW_ERROR("Unable to initialize device after %d attempts.\n", i); 11181 11182 return -EIO; 11183 } 11184 11185 static void ipw_bg_up(struct work_struct *work) 11186 { 11187 struct ipw_priv *priv = 11188 container_of(work, struct ipw_priv, up); 11189 mutex_lock(&priv->mutex); 11190 ipw_up(priv); 11191 mutex_unlock(&priv->mutex); 11192 } 11193 11194 static void ipw_deinit(struct ipw_priv *priv) 11195 { 11196 int i; 11197 11198 if (priv->status & STATUS_SCANNING) { 11199 IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); 11200 ipw_abort_scan(priv); 11201 } 11202 11203 if (priv->status & STATUS_ASSOCIATED) { 11204 IPW_DEBUG_INFO("Disassociating during shutdown.\n"); 11205 ipw_disassociate(priv); 11206 } 11207 11208 ipw_led_shutdown(priv); 11209 11210 /* Wait up to 1s for status to change to not scanning and not 11211 * associated (disassociation can take a while for a ful 802.11 11212 * exchange */ 11213 for (i = 1000; i && (priv->status & 11214 (STATUS_DISASSOCIATING | 11215 STATUS_ASSOCIATED | STATUS_SCANNING)); i--) 11216 udelay(10); 11217 11218 if (priv->status & (STATUS_DISASSOCIATING | 11219 STATUS_ASSOCIATED | STATUS_SCANNING)) 11220 IPW_DEBUG_INFO("Still associated or scanning...\n"); 11221 else 11222 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); 11223 11224 /* Attempt to disable the card */ 11225 ipw_send_card_disable(priv, 0); 11226 11227 priv->status &= ~STATUS_INIT; 11228 } 11229 11230 static void ipw_down(struct ipw_priv *priv) 11231 { 11232 int exit_pending = priv->status & STATUS_EXIT_PENDING; 11233 11234 priv->status |= STATUS_EXIT_PENDING; 11235 11236 if (ipw_is_init(priv)) 11237 ipw_deinit(priv); 11238 11239 /* Wipe out the EXIT_PENDING status bit if we are not actually 11240 * exiting the module */ 11241 if (!exit_pending) 11242 priv->status &= ~STATUS_EXIT_PENDING; 11243 11244 /* tell the device to stop sending interrupts */ 11245 ipw_disable_interrupts(priv); 11246 11247 /* Clear all bits but the RF Kill */ 11248 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; 11249 netif_carrier_off(priv->net_dev); 11250 11251 ipw_stop_nic(priv); 11252 11253 ipw_led_radio_off(priv); 11254 } 11255 11256 static void ipw_bg_down(struct work_struct *work) 11257 { 11258 struct ipw_priv *priv = 11259 container_of(work, struct ipw_priv, down); 11260 mutex_lock(&priv->mutex); 11261 ipw_down(priv); 11262 mutex_unlock(&priv->mutex); 11263 } 11264 11265 static int ipw_wdev_init(struct net_device *dev) 11266 { 11267 int i, rc = 0; 11268 struct ipw_priv *priv = libipw_priv(dev); 11269 const struct libipw_geo *geo = libipw_get_geo(priv->ieee); 11270 struct wireless_dev *wdev = &priv->ieee->wdev; 11271 11272 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN); 11273 11274 /* fill-out priv->ieee->bg_band */ 11275 if (geo->bg_channels) { 11276 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band; 11277 11278 bg_band->band = NL80211_BAND_2GHZ; 11279 bg_band->n_channels = geo->bg_channels; 11280 bg_band->channels = kzalloc_objs(struct ieee80211_channel, 11281 geo->bg_channels); 11282 if (!bg_band->channels) { 11283 rc = -ENOMEM; 11284 goto out; 11285 } 11286 /* translate geo->bg to bg_band.channels */ 11287 for (i = 0; i < geo->bg_channels; i++) { 11288 bg_band->channels[i].band = NL80211_BAND_2GHZ; 11289 bg_band->channels[i].center_freq = geo->bg[i].freq; 11290 bg_band->channels[i].hw_value = geo->bg[i].channel; 11291 bg_band->channels[i].max_power = geo->bg[i].max_power; 11292 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) 11293 bg_band->channels[i].flags |= 11294 IEEE80211_CHAN_NO_IR; 11295 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS) 11296 bg_band->channels[i].flags |= 11297 IEEE80211_CHAN_NO_IR; 11298 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT) 11299 bg_band->channels[i].flags |= 11300 IEEE80211_CHAN_RADAR; 11301 /* No equivalent for LIBIPW_CH_80211H_RULES, 11302 LIBIPW_CH_UNIFORM_SPREADING, or 11303 LIBIPW_CH_B_ONLY... */ 11304 } 11305 /* point at bitrate info */ 11306 bg_band->bitrates = ipw2200_bg_rates; 11307 bg_band->n_bitrates = ipw2200_num_bg_rates; 11308 11309 wdev->wiphy->bands[NL80211_BAND_2GHZ] = bg_band; 11310 } 11311 11312 /* fill-out priv->ieee->a_band */ 11313 if (geo->a_channels) { 11314 struct ieee80211_supported_band *a_band = &priv->ieee->a_band; 11315 11316 a_band->band = NL80211_BAND_5GHZ; 11317 a_band->n_channels = geo->a_channels; 11318 a_band->channels = kzalloc_objs(struct ieee80211_channel, 11319 geo->a_channels); 11320 if (!a_band->channels) { 11321 rc = -ENOMEM; 11322 goto out; 11323 } 11324 /* translate geo->a to a_band.channels */ 11325 for (i = 0; i < geo->a_channels; i++) { 11326 a_band->channels[i].band = NL80211_BAND_5GHZ; 11327 a_band->channels[i].center_freq = geo->a[i].freq; 11328 a_band->channels[i].hw_value = geo->a[i].channel; 11329 a_band->channels[i].max_power = geo->a[i].max_power; 11330 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) 11331 a_band->channels[i].flags |= 11332 IEEE80211_CHAN_NO_IR; 11333 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS) 11334 a_band->channels[i].flags |= 11335 IEEE80211_CHAN_NO_IR; 11336 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT) 11337 a_band->channels[i].flags |= 11338 IEEE80211_CHAN_RADAR; 11339 /* No equivalent for LIBIPW_CH_80211H_RULES, 11340 LIBIPW_CH_UNIFORM_SPREADING, or 11341 LIBIPW_CH_B_ONLY... */ 11342 } 11343 /* point at bitrate info */ 11344 a_band->bitrates = ipw2200_a_rates; 11345 a_band->n_bitrates = ipw2200_num_a_rates; 11346 11347 wdev->wiphy->bands[NL80211_BAND_5GHZ] = a_band; 11348 } 11349 11350 wdev->wiphy->cipher_suites = ipw_cipher_suites; 11351 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(ipw_cipher_suites); 11352 11353 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev); 11354 11355 /* With that information in place, we can now register the wiphy... */ 11356 rc = wiphy_register(wdev->wiphy); 11357 if (rc) 11358 goto out; 11359 11360 return 0; 11361 out: 11362 kfree(priv->ieee->a_band.channels); 11363 kfree(priv->ieee->bg_band.channels); 11364 return rc; 11365 } 11366 11367 /* PCI driver stuff */ 11368 static const struct pci_device_id card_ids[] = { 11369 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, 11370 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, 11371 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, 11372 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, 11373 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, 11374 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, 11375 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, 11376 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, 11377 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, 11378 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, 11379 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, 11380 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, 11381 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, 11382 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, 11383 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, 11384 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, 11385 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, 11386 /* 11387 * This ID conflicts with i40e, but the devices can be differentiated 11388 * because i40e devices use PCI_CLASS_NETWORK_ETHERNET and ipw2200 11389 * devices use PCI_CLASS_NETWORK_OTHER. 11390 */ 11391 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x104f), 11392 PCI_CLASS_NETWORK_OTHER << 8, 0xffff00, 0}, 11393 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */ 11394 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */ 11395 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */ 11396 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */ 11397 11398 /* required last entry */ 11399 {0,} 11400 }; 11401 11402 MODULE_DEVICE_TABLE(pci, card_ids); 11403 11404 static struct attribute *ipw_sysfs_entries[] = { 11405 &dev_attr_rf_kill.attr, 11406 &dev_attr_direct_dword.attr, 11407 &dev_attr_indirect_byte.attr, 11408 &dev_attr_indirect_dword.attr, 11409 &dev_attr_mem_gpio_reg.attr, 11410 &dev_attr_command_event_reg.attr, 11411 &dev_attr_nic_type.attr, 11412 &dev_attr_status.attr, 11413 &dev_attr_cfg.attr, 11414 &dev_attr_error.attr, 11415 &dev_attr_event_log.attr, 11416 &dev_attr_cmd_log.attr, 11417 &dev_attr_eeprom_delay.attr, 11418 &dev_attr_ucode_version.attr, 11419 &dev_attr_rtc.attr, 11420 &dev_attr_scan_age.attr, 11421 &dev_attr_led.attr, 11422 &dev_attr_speed_scan.attr, 11423 &dev_attr_net_stats.attr, 11424 &dev_attr_channels.attr, 11425 #ifdef CONFIG_IPW2200_PROMISCUOUS 11426 &dev_attr_rtap_iface.attr, 11427 &dev_attr_rtap_filter.attr, 11428 #endif 11429 NULL 11430 }; 11431 11432 static const struct attribute_group ipw_attribute_group = { 11433 .name = NULL, /* put in device directory */ 11434 .attrs = ipw_sysfs_entries, 11435 }; 11436 11437 #ifdef CONFIG_IPW2200_PROMISCUOUS 11438 static int ipw_prom_open(struct net_device *dev) 11439 { 11440 struct ipw_prom_priv *prom_priv = libipw_priv(dev); 11441 struct ipw_priv *priv = prom_priv->priv; 11442 11443 IPW_DEBUG_INFO("prom dev->open\n"); 11444 netif_carrier_off(dev); 11445 11446 if (priv->ieee->iw_mode != IW_MODE_MONITOR) { 11447 priv->sys_config.accept_all_data_frames = 1; 11448 priv->sys_config.accept_non_directed_frames = 1; 11449 priv->sys_config.accept_all_mgmt_bcpr = 1; 11450 priv->sys_config.accept_all_mgmt_frames = 1; 11451 11452 ipw_send_system_config(priv); 11453 } 11454 11455 return 0; 11456 } 11457 11458 static int ipw_prom_stop(struct net_device *dev) 11459 { 11460 struct ipw_prom_priv *prom_priv = libipw_priv(dev); 11461 struct ipw_priv *priv = prom_priv->priv; 11462 11463 IPW_DEBUG_INFO("prom dev->stop\n"); 11464 11465 if (priv->ieee->iw_mode != IW_MODE_MONITOR) { 11466 priv->sys_config.accept_all_data_frames = 0; 11467 priv->sys_config.accept_non_directed_frames = 0; 11468 priv->sys_config.accept_all_mgmt_bcpr = 0; 11469 priv->sys_config.accept_all_mgmt_frames = 0; 11470 11471 ipw_send_system_config(priv); 11472 } 11473 11474 return 0; 11475 } 11476 11477 static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb, 11478 struct net_device *dev) 11479 { 11480 IPW_DEBUG_INFO("prom dev->xmit\n"); 11481 dev_kfree_skb(skb); 11482 return NETDEV_TX_OK; 11483 } 11484 11485 static const struct net_device_ops ipw_prom_netdev_ops = { 11486 .ndo_open = ipw_prom_open, 11487 .ndo_stop = ipw_prom_stop, 11488 .ndo_start_xmit = ipw_prom_hard_start_xmit, 11489 .ndo_set_mac_address = eth_mac_addr, 11490 .ndo_validate_addr = eth_validate_addr, 11491 }; 11492 11493 static int ipw_prom_alloc(struct ipw_priv *priv) 11494 { 11495 int rc = 0; 11496 11497 if (priv->prom_net_dev) 11498 return -EPERM; 11499 11500 priv->prom_net_dev = alloc_libipw(sizeof(struct ipw_prom_priv), 1); 11501 if (priv->prom_net_dev == NULL) 11502 return -ENOMEM; 11503 11504 priv->prom_priv = libipw_priv(priv->prom_net_dev); 11505 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev); 11506 priv->prom_priv->priv = priv; 11507 11508 strcpy(priv->prom_net_dev->name, "rtap%d"); 11509 eth_hw_addr_set(priv->prom_net_dev, priv->mac_addr); 11510 11511 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP; 11512 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops; 11513 11514 priv->prom_net_dev->min_mtu = 68; 11515 priv->prom_net_dev->max_mtu = LIBIPW_DATA_LEN; 11516 11517 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR; 11518 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev); 11519 11520 rc = register_netdev(priv->prom_net_dev); 11521 if (rc) { 11522 free_libipw(priv->prom_net_dev, 1); 11523 priv->prom_net_dev = NULL; 11524 return rc; 11525 } 11526 11527 return 0; 11528 } 11529 11530 static void ipw_prom_free(struct ipw_priv *priv) 11531 { 11532 if (!priv->prom_net_dev) 11533 return; 11534 11535 unregister_netdev(priv->prom_net_dev); 11536 free_libipw(priv->prom_net_dev, 1); 11537 11538 priv->prom_net_dev = NULL; 11539 } 11540 11541 #endif 11542 11543 static const struct net_device_ops ipw_netdev_ops = { 11544 .ndo_open = ipw_net_open, 11545 .ndo_stop = ipw_net_stop, 11546 .ndo_set_rx_mode = ipw_net_set_multicast_list, 11547 .ndo_set_mac_address = ipw_net_set_mac_address, 11548 .ndo_start_xmit = libipw_xmit, 11549 .ndo_validate_addr = eth_validate_addr, 11550 }; 11551 11552 static int ipw_pci_probe(struct pci_dev *pdev, 11553 const struct pci_device_id *ent) 11554 { 11555 int err = 0; 11556 struct net_device *net_dev; 11557 void __iomem *base; 11558 u32 length, val; 11559 struct ipw_priv *priv; 11560 int i; 11561 11562 net_dev = alloc_libipw(sizeof(struct ipw_priv), 0); 11563 if (net_dev == NULL) { 11564 err = -ENOMEM; 11565 goto out; 11566 } 11567 11568 priv = libipw_priv(net_dev); 11569 priv->ieee = netdev_priv(net_dev); 11570 11571 priv->net_dev = net_dev; 11572 priv->pci_dev = pdev; 11573 ipw_debug_level = debug; 11574 spin_lock_init(&priv->irq_lock); 11575 spin_lock_init(&priv->lock); 11576 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) 11577 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); 11578 11579 mutex_init(&priv->mutex); 11580 if (pci_enable_device(pdev)) { 11581 err = -ENODEV; 11582 goto out_free_libipw; 11583 } 11584 11585 pci_set_master(pdev); 11586 11587 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); 11588 if (!err) 11589 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); 11590 if (err) { 11591 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); 11592 goto out_pci_disable_device; 11593 } 11594 11595 pci_set_drvdata(pdev, priv); 11596 11597 err = pci_request_regions(pdev, DRV_NAME); 11598 if (err) 11599 goto out_pci_disable_device; 11600 11601 /* We disable the RETRY_TIMEOUT register (0x41) to keep 11602 * PCI Tx retries from interfering with C3 CPU state */ 11603 pci_read_config_dword(pdev, 0x40, &val); 11604 if ((val & 0x0000ff00) != 0) 11605 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); 11606 11607 length = pci_resource_len(pdev, 0); 11608 priv->hw_len = length; 11609 11610 base = pci_ioremap_bar(pdev, 0); 11611 if (!base) { 11612 err = -ENODEV; 11613 goto out_pci_release_regions; 11614 } 11615 11616 priv->hw_base = base; 11617 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); 11618 IPW_DEBUG_INFO("pci_resource_base = %p\n", base); 11619 11620 ipw_setup_deferred_work(priv); 11621 11622 ipw_sw_reset(priv, 1); 11623 11624 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv); 11625 if (err) { 11626 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); 11627 goto out_iounmap; 11628 } 11629 11630 SET_NETDEV_DEV(net_dev, &pdev->dev); 11631 11632 mutex_lock(&priv->mutex); 11633 11634 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; 11635 priv->ieee->set_security = shim__set_security; 11636 priv->ieee->is_queue_full = ipw_net_is_queue_full; 11637 11638 #ifdef CONFIG_IPW2200_QOS 11639 priv->ieee->is_qos_active = ipw_is_qos_active; 11640 priv->ieee->handle_probe_response = ipw_handle_beacon; 11641 priv->ieee->handle_beacon = ipw_handle_probe_response; 11642 priv->ieee->handle_assoc_response = ipw_handle_assoc_response; 11643 #endif /* CONFIG_IPW2200_QOS */ 11644 11645 priv->ieee->perfect_rssi = -20; 11646 priv->ieee->worst_rssi = -85; 11647 11648 net_dev->netdev_ops = &ipw_netdev_ops; 11649 priv->ieee->spy_enabled = true; 11650 net_dev->wireless_handlers = &ipw_wx_handler_def; 11651 net_dev->ethtool_ops = &ipw_ethtool_ops; 11652 11653 net_dev->min_mtu = 68; 11654 net_dev->max_mtu = LIBIPW_DATA_LEN; 11655 11656 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); 11657 if (err) { 11658 IPW_ERROR("failed to create sysfs device attributes\n"); 11659 mutex_unlock(&priv->mutex); 11660 goto out_release_irq; 11661 } 11662 11663 if (ipw_up(priv)) { 11664 mutex_unlock(&priv->mutex); 11665 err = -EIO; 11666 goto out_remove_sysfs; 11667 } 11668 11669 mutex_unlock(&priv->mutex); 11670 11671 err = ipw_wdev_init(net_dev); 11672 if (err) { 11673 IPW_ERROR("failed to register wireless device\n"); 11674 goto out_remove_sysfs; 11675 } 11676 11677 err = register_netdev(net_dev); 11678 if (err) { 11679 IPW_ERROR("failed to register network device\n"); 11680 goto out_unregister_wiphy; 11681 } 11682 11683 #ifdef CONFIG_IPW2200_PROMISCUOUS 11684 if (rtap_iface) { 11685 err = ipw_prom_alloc(priv); 11686 if (err) { 11687 IPW_ERROR("Failed to register promiscuous network " 11688 "device (error %d).\n", err); 11689 unregister_netdev(priv->net_dev); 11690 goto out_unregister_wiphy; 11691 } 11692 } 11693 #endif 11694 11695 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " 11696 "channels, %d 802.11a channels)\n", 11697 priv->ieee->geo.name, priv->ieee->geo.bg_channels, 11698 priv->ieee->geo.a_channels); 11699 11700 return 0; 11701 11702 out_unregister_wiphy: 11703 wiphy_unregister(priv->ieee->wdev.wiphy); 11704 kfree(priv->ieee->a_band.channels); 11705 kfree(priv->ieee->bg_band.channels); 11706 out_remove_sysfs: 11707 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); 11708 out_release_irq: 11709 free_irq(pdev->irq, priv); 11710 out_iounmap: 11711 iounmap(priv->hw_base); 11712 out_pci_release_regions: 11713 pci_release_regions(pdev); 11714 out_pci_disable_device: 11715 pci_disable_device(pdev); 11716 out_free_libipw: 11717 free_libipw(priv->net_dev, 0); 11718 out: 11719 return err; 11720 } 11721 11722 static void ipw_pci_remove(struct pci_dev *pdev) 11723 { 11724 struct ipw_priv *priv = pci_get_drvdata(pdev); 11725 struct list_head *p, *q; 11726 int i; 11727 11728 if (!priv) 11729 return; 11730 11731 mutex_lock(&priv->mutex); 11732 11733 priv->status |= STATUS_EXIT_PENDING; 11734 ipw_down(priv); 11735 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); 11736 11737 mutex_unlock(&priv->mutex); 11738 11739 unregister_netdev(priv->net_dev); 11740 11741 if (priv->rxq) { 11742 ipw_rx_queue_free(priv, priv->rxq); 11743 priv->rxq = NULL; 11744 } 11745 ipw_tx_queue_free(priv); 11746 11747 if (priv->cmdlog) { 11748 kfree(priv->cmdlog); 11749 priv->cmdlog = NULL; 11750 } 11751 11752 /* make sure all works are inactive */ 11753 cancel_delayed_work_sync(&priv->adhoc_check); 11754 cancel_work_sync(&priv->associate); 11755 cancel_work_sync(&priv->disassociate); 11756 cancel_work_sync(&priv->system_config); 11757 cancel_work_sync(&priv->rx_replenish); 11758 cancel_work_sync(&priv->adapter_restart); 11759 cancel_delayed_work_sync(&priv->rf_kill); 11760 cancel_work_sync(&priv->up); 11761 cancel_work_sync(&priv->down); 11762 cancel_delayed_work_sync(&priv->request_scan); 11763 cancel_delayed_work_sync(&priv->request_direct_scan); 11764 cancel_delayed_work_sync(&priv->request_passive_scan); 11765 cancel_delayed_work_sync(&priv->scan_event); 11766 cancel_delayed_work_sync(&priv->gather_stats); 11767 cancel_work_sync(&priv->abort_scan); 11768 cancel_work_sync(&priv->roam); 11769 cancel_delayed_work_sync(&priv->scan_check); 11770 cancel_work_sync(&priv->link_up); 11771 cancel_work_sync(&priv->link_down); 11772 cancel_delayed_work_sync(&priv->led_link_on); 11773 cancel_delayed_work_sync(&priv->led_link_off); 11774 cancel_delayed_work_sync(&priv->led_act_off); 11775 cancel_work_sync(&priv->merge_networks); 11776 11777 /* Free MAC hash list for ADHOC */ 11778 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { 11779 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { 11780 list_del(p); 11781 kfree(list_entry(p, struct ipw_ibss_seq, list)); 11782 } 11783 } 11784 11785 kfree(priv->error); 11786 priv->error = NULL; 11787 11788 #ifdef CONFIG_IPW2200_PROMISCUOUS 11789 ipw_prom_free(priv); 11790 #endif 11791 11792 free_irq(pdev->irq, priv); 11793 iounmap(priv->hw_base); 11794 pci_release_regions(pdev); 11795 pci_disable_device(pdev); 11796 /* wiphy_unregister needs to be here, before free_libipw */ 11797 wiphy_unregister(priv->ieee->wdev.wiphy); 11798 kfree(priv->ieee->a_band.channels); 11799 kfree(priv->ieee->bg_band.channels); 11800 free_libipw(priv->net_dev, 0); 11801 free_firmware(); 11802 } 11803 11804 static int __maybe_unused ipw_pci_suspend(struct device *dev_d) 11805 { 11806 struct ipw_priv *priv = dev_get_drvdata(dev_d); 11807 struct net_device *dev = priv->net_dev; 11808 11809 printk(KERN_INFO "%s: Going into suspend...\n", dev->name); 11810 11811 /* Take down the device; powers it off, etc. */ 11812 ipw_down(priv); 11813 11814 /* Remove the PRESENT state of the device */ 11815 netif_device_detach(dev); 11816 11817 priv->suspend_at = ktime_get_boottime_seconds(); 11818 11819 return 0; 11820 } 11821 11822 static int __maybe_unused ipw_pci_resume(struct device *dev_d) 11823 { 11824 struct pci_dev *pdev = to_pci_dev(dev_d); 11825 struct ipw_priv *priv = pci_get_drvdata(pdev); 11826 struct net_device *dev = priv->net_dev; 11827 u32 val; 11828 11829 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); 11830 11831 /* 11832 * Suspend/Resume resets the PCI configuration space, so we have to 11833 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries 11834 * from interfering with C3 CPU state. pci_restore_state won't help 11835 * here since it only restores the first 64 bytes pci config header. 11836 */ 11837 pci_read_config_dword(pdev, 0x40, &val); 11838 if ((val & 0x0000ff00) != 0) 11839 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); 11840 11841 /* Set the device back into the PRESENT state; this will also wake 11842 * the queue of needed */ 11843 netif_device_attach(dev); 11844 11845 priv->suspend_time = ktime_get_boottime_seconds() - priv->suspend_at; 11846 11847 /* Bring the device back up */ 11848 schedule_work(&priv->up); 11849 11850 return 0; 11851 } 11852 11853 static void ipw_pci_shutdown(struct pci_dev *pdev) 11854 { 11855 struct ipw_priv *priv = pci_get_drvdata(pdev); 11856 11857 /* Take down the device; powers it off, etc. */ 11858 ipw_down(priv); 11859 11860 pci_disable_device(pdev); 11861 } 11862 11863 static SIMPLE_DEV_PM_OPS(ipw_pci_pm_ops, ipw_pci_suspend, ipw_pci_resume); 11864 11865 /* driver initialization stuff */ 11866 static struct pci_driver ipw_driver = { 11867 .name = DRV_NAME, 11868 .id_table = card_ids, 11869 .probe = ipw_pci_probe, 11870 .remove = ipw_pci_remove, 11871 .driver.pm = &ipw_pci_pm_ops, 11872 .shutdown = ipw_pci_shutdown, 11873 }; 11874 11875 static int __init ipw_init(void) 11876 { 11877 int ret; 11878 11879 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); 11880 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); 11881 11882 ret = pci_register_driver(&ipw_driver); 11883 if (ret) { 11884 IPW_ERROR("Unable to initialize PCI module\n"); 11885 return ret; 11886 } 11887 11888 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); 11889 if (ret) { 11890 IPW_ERROR("Unable to create driver sysfs file\n"); 11891 pci_unregister_driver(&ipw_driver); 11892 return ret; 11893 } 11894 11895 return ret; 11896 } 11897 11898 static void __exit ipw_exit(void) 11899 { 11900 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); 11901 pci_unregister_driver(&ipw_driver); 11902 } 11903 11904 module_param(disable, int, 0444); 11905 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); 11906 11907 module_param(associate, int, 0444); 11908 MODULE_PARM_DESC(associate, "auto associate when scanning (default off)"); 11909 11910 module_param(auto_create, int, 0444); 11911 MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); 11912 11913 module_param_named(led, led_support, int, 0444); 11914 MODULE_PARM_DESC(led, "enable led control on some systems (default 1 on)"); 11915 11916 module_param(debug, int, 0444); 11917 MODULE_PARM_DESC(debug, "debug output mask"); 11918 11919 module_param_named(channel, default_channel, int, 0444); 11920 MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); 11921 11922 #ifdef CONFIG_IPW2200_PROMISCUOUS 11923 module_param(rtap_iface, int, 0444); 11924 MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)"); 11925 #endif 11926 11927 #ifdef CONFIG_IPW2200_QOS 11928 module_param(qos_enable, int, 0444); 11929 MODULE_PARM_DESC(qos_enable, "enable all QoS functionalities"); 11930 11931 module_param(qos_burst_enable, int, 0444); 11932 MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); 11933 11934 module_param(qos_no_ack_mask, int, 0444); 11935 MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); 11936 11937 module_param(burst_duration_CCK, int, 0444); 11938 MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); 11939 11940 module_param(burst_duration_OFDM, int, 0444); 11941 MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); 11942 #endif /* CONFIG_IPW2200_QOS */ 11943 11944 #ifdef CONFIG_IPW2200_MONITOR 11945 module_param_named(mode, network_mode, int, 0444); 11946 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); 11947 #else 11948 module_param_named(mode, network_mode, int, 0444); 11949 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); 11950 #endif 11951 11952 module_param(bt_coexist, int, 0444); 11953 MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); 11954 11955 module_param(hwcrypto, int, 0444); 11956 MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); 11957 11958 module_param(cmdlog, int, 0444); 11959 MODULE_PARM_DESC(cmdlog, 11960 "allocate a ring buffer for logging firmware commands"); 11961 11962 module_param(roaming, int, 0444); 11963 MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); 11964 11965 module_param(antenna, int, 0444); 11966 MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)"); 11967 11968 module_exit(ipw_exit); 11969 module_init(ipw_init); 11970