Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Host AP (software wireless LAN access point) driver for |
| 3 | * Intersil Prism2/2.5/3. |
| 4 | * |
| 5 | * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen |
| 6 | * <jkmaline@cc.hut.fi> |
Jouni Malinen | 62fe7e3 | 2005-07-30 20:43:20 -0700 | [diff] [blame] | 7 | * Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi> |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. See README and COPYING for |
| 12 | * more details. |
| 13 | * |
| 14 | * FIX: |
| 15 | * - there is currently no way of associating TX packets to correct wds device |
| 16 | * when TX Exc/OK event occurs, so all tx_packets and some |
| 17 | * tx_errors/tx_dropped are added to the main netdevice; using sw_support |
| 18 | * field in txdesc might be used to fix this (using Alloc event to increment |
| 19 | * tx_packets would need some further info in txfid table) |
| 20 | * |
| 21 | * Buffer Access Path (BAP) usage: |
| 22 | * Prism2 cards have two separate BAPs for accessing the card memory. These |
| 23 | * should allow concurrent access to two different frames and the driver |
| 24 | * previously used BAP0 for sending data and BAP1 for receiving data. |
| 25 | * However, there seems to be number of issues with concurrent access and at |
| 26 | * least one know hardware bug in using BAP0 and BAP1 concurrently with PCI |
| 27 | * Prism2.5. Therefore, the driver now only uses BAP0 for moving data between |
| 28 | * host and card memories. BAP0 accesses are protected with local->baplock |
| 29 | * (spin_lock_bh) to prevent concurrent use. |
| 30 | */ |
| 31 | |
| 32 | |
| 33 | #include <linux/config.h> |
| 34 | #include <linux/version.h> |
| 35 | |
| 36 | #include <asm/delay.h> |
| 37 | #include <asm/uaccess.h> |
| 38 | |
| 39 | #include <linux/slab.h> |
| 40 | #include <linux/netdevice.h> |
| 41 | #include <linux/etherdevice.h> |
| 42 | #include <linux/proc_fs.h> |
| 43 | #include <linux/if_arp.h> |
| 44 | #include <linux/delay.h> |
| 45 | #include <linux/random.h> |
| 46 | #include <linux/wait.h> |
| 47 | #include <linux/sched.h> |
| 48 | #include <linux/rtnetlink.h> |
| 49 | #include <linux/wireless.h> |
| 50 | #include <net/iw_handler.h> |
Jouni Malinen | ebed67d | 2005-07-30 20:43:19 -0700 | [diff] [blame] | 51 | #include <net/ieee80211.h> |
| 52 | #include <net/ieee80211_crypt.h> |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 53 | #include <asm/irq.h> |
| 54 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 55 | #include "hostap_80211.h" |
| 56 | #include "hostap.h" |
| 57 | #include "hostap_ap.h" |
| 58 | |
| 59 | |
| 60 | /* #define final_version */ |
| 61 | |
| 62 | static int mtu = 1500; |
| 63 | module_param(mtu, int, 0444); |
| 64 | MODULE_PARM_DESC(mtu, "Maximum transfer unit"); |
| 65 | |
| 66 | static int channel[MAX_PARM_DEVICES] = { 3, DEF_INTS }; |
| 67 | module_param_array(channel, int, NULL, 0444); |
| 68 | MODULE_PARM_DESC(channel, "Initial channel"); |
| 69 | |
| 70 | static char essid[33] = "test"; |
| 71 | module_param_string(essid, essid, sizeof(essid), 0444); |
| 72 | MODULE_PARM_DESC(essid, "Host AP's ESSID"); |
| 73 | |
| 74 | static int iw_mode[MAX_PARM_DEVICES] = { IW_MODE_MASTER, DEF_INTS }; |
| 75 | module_param_array(iw_mode, int, NULL, 0444); |
| 76 | MODULE_PARM_DESC(iw_mode, "Initial operation mode"); |
| 77 | |
| 78 | static int beacon_int[MAX_PARM_DEVICES] = { 100, DEF_INTS }; |
| 79 | module_param_array(beacon_int, int, NULL, 0444); |
| 80 | MODULE_PARM_DESC(beacon_int, "Beacon interval (1 = 1024 usec)"); |
| 81 | |
| 82 | static int dtim_period[MAX_PARM_DEVICES] = { 1, DEF_INTS }; |
| 83 | module_param_array(dtim_period, int, NULL, 0444); |
| 84 | MODULE_PARM_DESC(dtim_period, "DTIM period"); |
| 85 | |
| 86 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 87 | static int bus_master_threshold_rx[MAX_PARM_DEVICES] = { 100, DEF_INTS }; |
| 88 | module_param_array(bus_master_threshold_rx, int, NULL, 0444); |
| 89 | MODULE_PARM_DESC(bus_master_threshold_rx, "Packet length threshold for using " |
| 90 | "PCI bus master on RX"); |
| 91 | |
| 92 | static int bus_master_threshold_tx[MAX_PARM_DEVICES] = { 100, DEF_INTS }; |
| 93 | module_param_array(bus_master_threshold_tx, int, NULL, 0444); |
| 94 | MODULE_PARM_DESC(bus_master_threshold_tx, "Packet length threshold for using " |
| 95 | "PCI bus master on TX"); |
| 96 | #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */ |
| 97 | |
| 98 | static char dev_template[16] = "wlan%d"; |
| 99 | module_param_string(dev_template, dev_template, sizeof(dev_template), 0444); |
| 100 | MODULE_PARM_DESC(dev_template, "Prefix for network device name (default: " |
| 101 | "wlan%d)"); |
| 102 | |
| 103 | #ifdef final_version |
| 104 | #define EXTRA_EVENTS_WTERR 0 |
| 105 | #else |
| 106 | /* check WTERR events (Wait Time-out) in development versions */ |
| 107 | #define EXTRA_EVENTS_WTERR HFA384X_EV_WTERR |
| 108 | #endif |
| 109 | |
| 110 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 111 | #define EXTRA_EVENTS_BUS_MASTER (HFA384X_EV_PCI_M0 | HFA384X_EV_PCI_M1) |
| 112 | #else |
| 113 | #define EXTRA_EVENTS_BUS_MASTER 0 |
| 114 | #endif |
| 115 | |
| 116 | /* Events that will be using BAP0 */ |
| 117 | #define HFA384X_BAP0_EVENTS \ |
| 118 | (HFA384X_EV_TXEXC | HFA384X_EV_RX | HFA384X_EV_INFO | HFA384X_EV_TX) |
| 119 | |
| 120 | /* event mask, i.e., events that will result in an interrupt */ |
| 121 | #define HFA384X_EVENT_MASK \ |
| 122 | (HFA384X_BAP0_EVENTS | HFA384X_EV_ALLOC | HFA384X_EV_INFDROP | \ |
| 123 | HFA384X_EV_CMD | HFA384X_EV_TICK | \ |
| 124 | EXTRA_EVENTS_WTERR | EXTRA_EVENTS_BUS_MASTER) |
| 125 | |
| 126 | /* Default TX control flags: use 802.11 headers and request interrupt for |
| 127 | * failed transmits. Frames that request ACK callback, will add |
| 128 | * _TX_OK flag and _ALT_RTRY flag may be used to select different retry policy. |
| 129 | */ |
| 130 | #define HFA384X_TX_CTRL_FLAGS \ |
| 131 | (HFA384X_TX_CTRL_802_11 | HFA384X_TX_CTRL_TX_EX) |
| 132 | |
| 133 | |
| 134 | /* ca. 1 usec */ |
| 135 | #define HFA384X_CMD_BUSY_TIMEOUT 5000 |
| 136 | #define HFA384X_BAP_BUSY_TIMEOUT 50000 |
| 137 | |
| 138 | /* ca. 10 usec */ |
| 139 | #define HFA384X_CMD_COMPL_TIMEOUT 20000 |
| 140 | #define HFA384X_DL_COMPL_TIMEOUT 1000000 |
| 141 | |
| 142 | /* Wait times for initialization; yield to other processes to avoid busy |
| 143 | * waiting for long time. */ |
| 144 | #define HFA384X_INIT_TIMEOUT (HZ / 2) /* 500 ms */ |
| 145 | #define HFA384X_ALLOC_COMPL_TIMEOUT (HZ / 20) /* 50 ms */ |
| 146 | |
| 147 | |
| 148 | static void prism2_hw_reset(struct net_device *dev); |
| 149 | static void prism2_check_sta_fw_version(local_info_t *local); |
| 150 | |
| 151 | #ifdef PRISM2_DOWNLOAD_SUPPORT |
| 152 | /* hostap_download.c */ |
| 153 | static int prism2_download_aux_dump(struct net_device *dev, |
| 154 | unsigned int addr, int len, u8 *buf); |
| 155 | static u8 * prism2_read_pda(struct net_device *dev); |
| 156 | static int prism2_download(local_info_t *local, |
| 157 | struct prism2_download_param *param); |
| 158 | static void prism2_download_free_data(struct prism2_download_data *dl); |
| 159 | static int prism2_download_volatile(local_info_t *local, |
| 160 | struct prism2_download_data *param); |
| 161 | static int prism2_download_genesis(local_info_t *local, |
| 162 | struct prism2_download_data *param); |
| 163 | static int prism2_get_ram_size(local_info_t *local); |
| 164 | #endif /* PRISM2_DOWNLOAD_SUPPORT */ |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | #ifndef final_version |
| 170 | /* magic value written to SWSUPPORT0 reg. for detecting whether card is still |
| 171 | * present */ |
| 172 | #define HFA384X_MAGIC 0x8A32 |
| 173 | #endif |
| 174 | |
| 175 | |
| 176 | static u16 hfa384x_read_reg(struct net_device *dev, u16 reg) |
| 177 | { |
| 178 | return HFA384X_INW(reg); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | static void hfa384x_read_regs(struct net_device *dev, |
| 183 | struct hfa384x_regs *regs) |
| 184 | { |
| 185 | regs->cmd = HFA384X_INW(HFA384X_CMD_OFF); |
| 186 | regs->evstat = HFA384X_INW(HFA384X_EVSTAT_OFF); |
| 187 | regs->offset0 = HFA384X_INW(HFA384X_OFFSET0_OFF); |
| 188 | regs->offset1 = HFA384X_INW(HFA384X_OFFSET1_OFF); |
| 189 | regs->swsupport0 = HFA384X_INW(HFA384X_SWSUPPORT0_OFF); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | /** |
| 194 | * __hostap_cmd_queue_free - Free Prism2 command queue entry (private) |
| 195 | * @local: pointer to private Host AP driver data |
| 196 | * @entry: Prism2 command queue entry to be freed |
| 197 | * @del_req: request the entry to be removed |
| 198 | * |
| 199 | * Internal helper function for freeing Prism2 command queue entries. |
| 200 | * Caller must have acquired local->cmdlock before calling this function. |
| 201 | */ |
| 202 | static inline void __hostap_cmd_queue_free(local_info_t *local, |
| 203 | struct hostap_cmd_queue *entry, |
| 204 | int del_req) |
| 205 | { |
| 206 | if (del_req) { |
| 207 | entry->del_req = 1; |
| 208 | if (!list_empty(&entry->list)) { |
| 209 | list_del_init(&entry->list); |
| 210 | local->cmd_queue_len--; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | if (atomic_dec_and_test(&entry->usecnt) && entry->del_req) |
| 215 | kfree(entry); |
| 216 | } |
| 217 | |
| 218 | |
| 219 | /** |
| 220 | * hostap_cmd_queue_free - Free Prism2 command queue entry |
| 221 | * @local: pointer to private Host AP driver data |
| 222 | * @entry: Prism2 command queue entry to be freed |
| 223 | * @del_req: request the entry to be removed |
| 224 | * |
| 225 | * Free a Prism2 command queue entry. |
| 226 | */ |
| 227 | static inline void hostap_cmd_queue_free(local_info_t *local, |
| 228 | struct hostap_cmd_queue *entry, |
| 229 | int del_req) |
| 230 | { |
| 231 | unsigned long flags; |
| 232 | |
| 233 | spin_lock_irqsave(&local->cmdlock, flags); |
| 234 | __hostap_cmd_queue_free(local, entry, del_req); |
| 235 | spin_unlock_irqrestore(&local->cmdlock, flags); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /** |
| 240 | * prism2_clear_cmd_queue - Free all pending Prism2 command queue entries |
| 241 | * @local: pointer to private Host AP driver data |
| 242 | */ |
| 243 | static void prism2_clear_cmd_queue(local_info_t *local) |
| 244 | { |
| 245 | struct list_head *ptr, *n; |
| 246 | unsigned long flags; |
| 247 | struct hostap_cmd_queue *entry; |
| 248 | |
| 249 | spin_lock_irqsave(&local->cmdlock, flags); |
| 250 | list_for_each_safe(ptr, n, &local->cmd_queue) { |
| 251 | entry = list_entry(ptr, struct hostap_cmd_queue, list); |
| 252 | atomic_inc(&entry->usecnt); |
| 253 | printk(KERN_DEBUG "%s: removed pending cmd_queue entry " |
| 254 | "(type=%d, cmd=0x%04x, param0=0x%04x)\n", |
| 255 | local->dev->name, entry->type, entry->cmd, |
| 256 | entry->param0); |
| 257 | __hostap_cmd_queue_free(local, entry, 1); |
| 258 | } |
| 259 | if (local->cmd_queue_len) { |
| 260 | /* This should not happen; print debug message and clear |
| 261 | * queue length. */ |
| 262 | printk(KERN_DEBUG "%s: cmd_queue_len (%d) not zero after " |
| 263 | "flush\n", local->dev->name, local->cmd_queue_len); |
| 264 | local->cmd_queue_len = 0; |
| 265 | } |
| 266 | spin_unlock_irqrestore(&local->cmdlock, flags); |
| 267 | } |
| 268 | |
| 269 | |
| 270 | /** |
| 271 | * hfa384x_cmd_issue - Issue a Prism2 command to the hardware |
| 272 | * @dev: pointer to net_device |
| 273 | * @entry: Prism2 command queue entry to be issued |
| 274 | */ |
| 275 | static inline int hfa384x_cmd_issue(struct net_device *dev, |
| 276 | struct hostap_cmd_queue *entry) |
| 277 | { |
| 278 | struct hostap_interface *iface; |
| 279 | local_info_t *local; |
| 280 | int tries; |
| 281 | u16 reg; |
| 282 | unsigned long flags; |
| 283 | |
| 284 | iface = netdev_priv(dev); |
| 285 | local = iface->local; |
| 286 | |
| 287 | if (local->func->card_present && !local->func->card_present(local)) |
| 288 | return -ENODEV; |
| 289 | |
| 290 | if (entry->issued) { |
| 291 | printk(KERN_DEBUG "%s: driver bug - re-issuing command @%p\n", |
| 292 | dev->name, entry); |
| 293 | } |
| 294 | |
| 295 | /* wait until busy bit is clear; this should always be clear since the |
| 296 | * commands are serialized */ |
| 297 | tries = HFA384X_CMD_BUSY_TIMEOUT; |
| 298 | while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) { |
| 299 | tries--; |
| 300 | udelay(1); |
| 301 | } |
| 302 | #ifndef final_version |
| 303 | if (tries != HFA384X_CMD_BUSY_TIMEOUT) { |
| 304 | prism2_io_debug_error(dev, 1); |
| 305 | printk(KERN_DEBUG "%s: hfa384x_cmd_issue: cmd reg was busy " |
| 306 | "for %d usec\n", dev->name, |
| 307 | HFA384X_CMD_BUSY_TIMEOUT - tries); |
| 308 | } |
| 309 | #endif |
| 310 | if (tries == 0) { |
| 311 | reg = HFA384X_INW(HFA384X_CMD_OFF); |
| 312 | prism2_io_debug_error(dev, 2); |
| 313 | printk(KERN_DEBUG "%s: hfa384x_cmd_issue - timeout - " |
| 314 | "reg=0x%04x\n", dev->name, reg); |
| 315 | return -ETIMEDOUT; |
| 316 | } |
| 317 | |
| 318 | /* write command */ |
| 319 | spin_lock_irqsave(&local->cmdlock, flags); |
| 320 | HFA384X_OUTW(entry->param0, HFA384X_PARAM0_OFF); |
| 321 | HFA384X_OUTW(entry->param1, HFA384X_PARAM1_OFF); |
| 322 | HFA384X_OUTW(entry->cmd, HFA384X_CMD_OFF); |
| 323 | entry->issued = 1; |
| 324 | spin_unlock_irqrestore(&local->cmdlock, flags); |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | |
| 330 | /** |
| 331 | * hfa384x_cmd - Issue a Prism2 command and wait (sleep) for completion |
| 332 | * @dev: pointer to net_device |
| 333 | * @cmd: Prism2 command code (HFA384X_CMD_CODE_*) |
| 334 | * @param0: value for Param0 register |
| 335 | * @param1: value for Param1 register (pointer; %NULL if not used) |
| 336 | * @resp0: pointer for Resp0 data or %NULL if Resp0 is not needed |
| 337 | * |
| 338 | * Issue given command (possibly after waiting in command queue) and sleep |
| 339 | * until the command is completed (or timed out or interrupted). This can be |
| 340 | * called only from user process context. |
| 341 | */ |
| 342 | static int hfa384x_cmd(struct net_device *dev, u16 cmd, u16 param0, |
| 343 | u16 *param1, u16 *resp0) |
| 344 | { |
| 345 | struct hostap_interface *iface; |
| 346 | local_info_t *local; |
| 347 | int err, res, issue, issued = 0; |
| 348 | unsigned long flags; |
| 349 | struct hostap_cmd_queue *entry; |
| 350 | DECLARE_WAITQUEUE(wait, current); |
| 351 | |
| 352 | iface = netdev_priv(dev); |
| 353 | local = iface->local; |
| 354 | |
| 355 | if (in_interrupt()) { |
| 356 | printk(KERN_DEBUG "%s: hfa384x_cmd called from interrupt " |
| 357 | "context\n", dev->name); |
| 358 | return -1; |
| 359 | } |
| 360 | |
| 361 | if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN) { |
| 362 | printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n", |
| 363 | dev->name); |
| 364 | return -1; |
| 365 | } |
| 366 | |
| 367 | if (signal_pending(current)) |
| 368 | return -EINTR; |
| 369 | |
| 370 | entry = (struct hostap_cmd_queue *) |
| 371 | kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 372 | if (entry == NULL) { |
| 373 | printk(KERN_DEBUG "%s: hfa384x_cmd - kmalloc failed\n", |
| 374 | dev->name); |
| 375 | return -ENOMEM; |
| 376 | } |
| 377 | memset(entry, 0, sizeof(*entry)); |
| 378 | atomic_set(&entry->usecnt, 1); |
| 379 | entry->type = CMD_SLEEP; |
| 380 | entry->cmd = cmd; |
| 381 | entry->param0 = param0; |
| 382 | if (param1) |
| 383 | entry->param1 = *param1; |
| 384 | init_waitqueue_head(&entry->compl); |
| 385 | |
| 386 | /* prepare to wait for command completion event, but do not sleep yet |
| 387 | */ |
| 388 | add_wait_queue(&entry->compl, &wait); |
| 389 | set_current_state(TASK_INTERRUPTIBLE); |
| 390 | |
| 391 | spin_lock_irqsave(&local->cmdlock, flags); |
| 392 | issue = list_empty(&local->cmd_queue); |
| 393 | if (issue) |
| 394 | entry->issuing = 1; |
| 395 | list_add_tail(&entry->list, &local->cmd_queue); |
| 396 | local->cmd_queue_len++; |
| 397 | spin_unlock_irqrestore(&local->cmdlock, flags); |
| 398 | |
| 399 | err = 0; |
| 400 | if (!issue) |
| 401 | goto wait_completion; |
| 402 | |
| 403 | if (signal_pending(current)) |
| 404 | err = -EINTR; |
| 405 | |
| 406 | if (!err) { |
| 407 | if (hfa384x_cmd_issue(dev, entry)) |
| 408 | err = -ETIMEDOUT; |
| 409 | else |
| 410 | issued = 1; |
| 411 | } |
| 412 | |
| 413 | wait_completion: |
| 414 | if (!err && entry->type != CMD_COMPLETED) { |
| 415 | /* sleep until command is completed or timed out */ |
| 416 | res = schedule_timeout(2 * HZ); |
| 417 | } else |
| 418 | res = -1; |
| 419 | |
| 420 | if (!err && signal_pending(current)) |
| 421 | err = -EINTR; |
| 422 | |
| 423 | if (err && issued) { |
| 424 | /* the command was issued, so a CmdCompl event should occur |
| 425 | * soon; however, there's a pending signal and |
| 426 | * schedule_timeout() would be interrupted; wait a short period |
| 427 | * of time to avoid removing entry from the list before |
| 428 | * CmdCompl event */ |
| 429 | udelay(300); |
| 430 | } |
| 431 | |
| 432 | set_current_state(TASK_RUNNING); |
| 433 | remove_wait_queue(&entry->compl, &wait); |
| 434 | |
| 435 | /* If entry->list is still in the list, it must be removed |
| 436 | * first and in this case prism2_cmd_ev() does not yet have |
| 437 | * local reference to it, and the data can be kfree()'d |
| 438 | * here. If the command completion event is still generated, |
| 439 | * it will be assigned to next (possibly) pending command, but |
| 440 | * the driver will reset the card anyway due to timeout |
| 441 | * |
| 442 | * If the entry is not in the list prism2_cmd_ev() has a local |
| 443 | * reference to it, but keeps cmdlock as long as the data is |
| 444 | * needed, so the data can be kfree()'d here. */ |
| 445 | |
| 446 | /* FIX: if the entry->list is in the list, it has not been completed |
| 447 | * yet, so removing it here is somewhat wrong.. this could cause |
| 448 | * references to freed memory and next list_del() causing NULL pointer |
| 449 | * dereference.. it would probably be better to leave the entry in the |
| 450 | * list and the list should be emptied during hw reset */ |
| 451 | |
| 452 | spin_lock_irqsave(&local->cmdlock, flags); |
| 453 | if (!list_empty(&entry->list)) { |
| 454 | printk(KERN_DEBUG "%s: hfa384x_cmd: entry still in list? " |
| 455 | "(entry=%p, type=%d, res=%d)\n", dev->name, entry, |
| 456 | entry->type, res); |
| 457 | list_del_init(&entry->list); |
| 458 | local->cmd_queue_len--; |
| 459 | } |
| 460 | spin_unlock_irqrestore(&local->cmdlock, flags); |
| 461 | |
| 462 | if (err) { |
| 463 | printk(KERN_DEBUG "%s: hfa384x_cmd: interrupted; err=%d\n", |
| 464 | dev->name, err); |
| 465 | res = err; |
| 466 | goto done; |
| 467 | } |
| 468 | |
| 469 | if (entry->type != CMD_COMPLETED) { |
| 470 | u16 reg = HFA384X_INW(HFA384X_EVSTAT_OFF); |
| 471 | printk(KERN_DEBUG "%s: hfa384x_cmd: command was not " |
| 472 | "completed (res=%d, entry=%p, type=%d, cmd=0x%04x, " |
| 473 | "param0=0x%04x, EVSTAT=%04x INTEN=%04x)\n", dev->name, |
| 474 | res, entry, entry->type, entry->cmd, entry->param0, reg, |
| 475 | HFA384X_INW(HFA384X_INTEN_OFF)); |
| 476 | if (reg & HFA384X_EV_CMD) { |
| 477 | /* Command completion event is pending, but the |
| 478 | * interrupt was not delivered - probably an issue |
| 479 | * with pcmcia-cs configuration. */ |
| 480 | printk(KERN_WARNING "%s: interrupt delivery does not " |
| 481 | "seem to work\n", dev->name); |
| 482 | } |
| 483 | prism2_io_debug_error(dev, 3); |
| 484 | res = -ETIMEDOUT; |
| 485 | goto done; |
| 486 | } |
| 487 | |
| 488 | if (resp0 != NULL) |
| 489 | *resp0 = entry->resp0; |
| 490 | #ifndef final_version |
| 491 | if (entry->res) { |
| 492 | printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x, " |
| 493 | "resp0=0x%04x\n", |
| 494 | dev->name, cmd, entry->res, entry->resp0); |
| 495 | } |
| 496 | #endif /* final_version */ |
| 497 | |
| 498 | res = entry->res; |
| 499 | done: |
| 500 | hostap_cmd_queue_free(local, entry, 1); |
| 501 | return res; |
| 502 | } |
| 503 | |
| 504 | |
| 505 | /** |
| 506 | * hfa384x_cmd_callback - Issue a Prism2 command; callback when completed |
| 507 | * @dev: pointer to net_device |
| 508 | * @cmd: Prism2 command code (HFA384X_CMD_CODE_*) |
| 509 | * @param0: value for Param0 register |
| 510 | * @callback: command completion callback function (%NULL = no callback) |
Pavel Roskin | b15eff2 | 2005-07-30 12:50:05 -0700 | [diff] [blame] | 511 | * @context: context data to be given to the callback function |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 512 | * |
| 513 | * Issue given command (possibly after waiting in command queue) and use |
| 514 | * callback function to indicate command completion. This can be called both |
| 515 | * from user and interrupt context. The callback function will be called in |
| 516 | * hardware IRQ context. It can be %NULL, when no function is called when |
| 517 | * command is completed. |
| 518 | */ |
| 519 | static int hfa384x_cmd_callback(struct net_device *dev, u16 cmd, u16 param0, |
| 520 | void (*callback)(struct net_device *dev, |
Pavel Roskin | b15eff2 | 2005-07-30 12:50:05 -0700 | [diff] [blame] | 521 | long context, u16 resp0, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 522 | u16 status), |
Pavel Roskin | b15eff2 | 2005-07-30 12:50:05 -0700 | [diff] [blame] | 523 | long context) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 524 | { |
| 525 | struct hostap_interface *iface; |
| 526 | local_info_t *local; |
| 527 | int issue, ret; |
| 528 | unsigned long flags; |
| 529 | struct hostap_cmd_queue *entry; |
| 530 | |
| 531 | iface = netdev_priv(dev); |
| 532 | local = iface->local; |
| 533 | |
| 534 | if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN + 2) { |
| 535 | printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n", |
| 536 | dev->name); |
| 537 | return -1; |
| 538 | } |
| 539 | |
| 540 | entry = (struct hostap_cmd_queue *) |
| 541 | kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 542 | if (entry == NULL) { |
| 543 | printk(KERN_DEBUG "%s: hfa384x_cmd_callback - kmalloc " |
| 544 | "failed\n", dev->name); |
| 545 | return -ENOMEM; |
| 546 | } |
| 547 | memset(entry, 0, sizeof(*entry)); |
| 548 | atomic_set(&entry->usecnt, 1); |
| 549 | entry->type = CMD_CALLBACK; |
| 550 | entry->cmd = cmd; |
| 551 | entry->param0 = param0; |
| 552 | entry->callback = callback; |
| 553 | entry->context = context; |
| 554 | |
| 555 | spin_lock_irqsave(&local->cmdlock, flags); |
| 556 | issue = list_empty(&local->cmd_queue); |
| 557 | if (issue) |
| 558 | entry->issuing = 1; |
| 559 | list_add_tail(&entry->list, &local->cmd_queue); |
| 560 | local->cmd_queue_len++; |
| 561 | spin_unlock_irqrestore(&local->cmdlock, flags); |
| 562 | |
| 563 | if (issue && hfa384x_cmd_issue(dev, entry)) |
| 564 | ret = -ETIMEDOUT; |
| 565 | else |
| 566 | ret = 0; |
| 567 | |
| 568 | hostap_cmd_queue_free(local, entry, ret); |
| 569 | |
| 570 | return ret; |
| 571 | } |
| 572 | |
| 573 | |
| 574 | /** |
| 575 | * __hfa384x_cmd_no_wait - Issue a Prism2 command (private) |
| 576 | * @dev: pointer to net_device |
| 577 | * @cmd: Prism2 command code (HFA384X_CMD_CODE_*) |
| 578 | * @param0: value for Param0 register |
| 579 | * @io_debug_num: I/O debug error number |
| 580 | * |
| 581 | * Shared helper function for hfa384x_cmd_wait() and hfa384x_cmd_no_wait(). |
| 582 | */ |
| 583 | static int __hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd, u16 param0, |
| 584 | int io_debug_num) |
| 585 | { |
| 586 | int tries; |
| 587 | u16 reg; |
| 588 | |
| 589 | /* wait until busy bit is clear; this should always be clear since the |
| 590 | * commands are serialized */ |
| 591 | tries = HFA384X_CMD_BUSY_TIMEOUT; |
| 592 | while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) { |
| 593 | tries--; |
| 594 | udelay(1); |
| 595 | } |
| 596 | if (tries == 0) { |
| 597 | reg = HFA384X_INW(HFA384X_CMD_OFF); |
| 598 | prism2_io_debug_error(dev, io_debug_num); |
| 599 | printk(KERN_DEBUG "%s: __hfa384x_cmd_no_wait(%d) - timeout - " |
| 600 | "reg=0x%04x\n", dev->name, io_debug_num, reg); |
| 601 | return -ETIMEDOUT; |
| 602 | } |
| 603 | |
| 604 | /* write command */ |
| 605 | HFA384X_OUTW(param0, HFA384X_PARAM0_OFF); |
| 606 | HFA384X_OUTW(cmd, HFA384X_CMD_OFF); |
| 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | |
| 612 | /** |
| 613 | * hfa384x_cmd_wait - Issue a Prism2 command and busy wait for completion |
| 614 | * @dev: pointer to net_device |
| 615 | * @cmd: Prism2 command code (HFA384X_CMD_CODE_*) |
| 616 | * @param0: value for Param0 register |
| 617 | */ |
| 618 | static int hfa384x_cmd_wait(struct net_device *dev, u16 cmd, u16 param0) |
| 619 | { |
| 620 | int res, tries; |
| 621 | u16 reg; |
| 622 | |
| 623 | res = __hfa384x_cmd_no_wait(dev, cmd, param0, 4); |
| 624 | if (res) |
| 625 | return res; |
| 626 | |
| 627 | /* wait for command completion */ |
| 628 | if ((cmd & HFA384X_CMDCODE_MASK) == HFA384X_CMDCODE_DOWNLOAD) |
| 629 | tries = HFA384X_DL_COMPL_TIMEOUT; |
| 630 | else |
| 631 | tries = HFA384X_CMD_COMPL_TIMEOUT; |
| 632 | |
| 633 | while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) && |
| 634 | tries > 0) { |
| 635 | tries--; |
| 636 | udelay(10); |
| 637 | } |
| 638 | if (tries == 0) { |
| 639 | reg = HFA384X_INW(HFA384X_EVSTAT_OFF); |
| 640 | prism2_io_debug_error(dev, 5); |
| 641 | printk(KERN_DEBUG "%s: hfa384x_cmd_wait - timeout2 - " |
| 642 | "reg=0x%04x\n", dev->name, reg); |
| 643 | return -ETIMEDOUT; |
| 644 | } |
| 645 | |
| 646 | res = (HFA384X_INW(HFA384X_STATUS_OFF) & |
| 647 | (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) | BIT(9) | |
| 648 | BIT(8))) >> 8; |
| 649 | #ifndef final_version |
| 650 | if (res) { |
| 651 | printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x\n", |
| 652 | dev->name, cmd, res); |
| 653 | } |
| 654 | #endif |
| 655 | |
| 656 | HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF); |
| 657 | |
| 658 | return res; |
| 659 | } |
| 660 | |
| 661 | |
| 662 | /** |
| 663 | * hfa384x_cmd_no_wait - Issue a Prism2 command; do not wait for completion |
| 664 | * @dev: pointer to net_device |
| 665 | * @cmd: Prism2 command code (HFA384X_CMD_CODE_*) |
| 666 | * @param0: value for Param0 register |
| 667 | */ |
| 668 | static inline int hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd, |
| 669 | u16 param0) |
| 670 | { |
| 671 | return __hfa384x_cmd_no_wait(dev, cmd, param0, 6); |
| 672 | } |
| 673 | |
| 674 | |
| 675 | /** |
| 676 | * prism2_cmd_ev - Prism2 command completion event handler |
| 677 | * @dev: pointer to net_device |
| 678 | * |
| 679 | * Interrupt handler for command completion events. Called by the main |
| 680 | * interrupt handler in hardware IRQ context. Read Resp0 and status registers |
| 681 | * from the hardware and ACK the event. Depending on the issued command type |
| 682 | * either wake up the sleeping process that is waiting for command completion |
| 683 | * or call the callback function. Issue the next command, if one is pending. |
| 684 | */ |
| 685 | static void prism2_cmd_ev(struct net_device *dev) |
| 686 | { |
| 687 | struct hostap_interface *iface; |
| 688 | local_info_t *local; |
| 689 | struct hostap_cmd_queue *entry = NULL; |
| 690 | |
| 691 | iface = netdev_priv(dev); |
| 692 | local = iface->local; |
| 693 | |
| 694 | spin_lock(&local->cmdlock); |
| 695 | if (!list_empty(&local->cmd_queue)) { |
| 696 | entry = list_entry(local->cmd_queue.next, |
| 697 | struct hostap_cmd_queue, list); |
| 698 | atomic_inc(&entry->usecnt); |
| 699 | list_del_init(&entry->list); |
| 700 | local->cmd_queue_len--; |
| 701 | |
| 702 | if (!entry->issued) { |
| 703 | printk(KERN_DEBUG "%s: Command completion event, but " |
| 704 | "cmd not issued\n", dev->name); |
| 705 | __hostap_cmd_queue_free(local, entry, 1); |
| 706 | entry = NULL; |
| 707 | } |
| 708 | } |
| 709 | spin_unlock(&local->cmdlock); |
| 710 | |
| 711 | if (!entry) { |
| 712 | HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF); |
| 713 | printk(KERN_DEBUG "%s: Command completion event, but no " |
| 714 | "pending commands\n", dev->name); |
| 715 | return; |
| 716 | } |
| 717 | |
| 718 | entry->resp0 = HFA384X_INW(HFA384X_RESP0_OFF); |
| 719 | entry->res = (HFA384X_INW(HFA384X_STATUS_OFF) & |
| 720 | (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) | |
| 721 | BIT(9) | BIT(8))) >> 8; |
| 722 | HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF); |
| 723 | |
| 724 | /* TODO: rest of the CmdEv handling could be moved to tasklet */ |
| 725 | if (entry->type == CMD_SLEEP) { |
| 726 | entry->type = CMD_COMPLETED; |
| 727 | wake_up_interruptible(&entry->compl); |
| 728 | } else if (entry->type == CMD_CALLBACK) { |
| 729 | if (entry->callback) |
| 730 | entry->callback(dev, entry->context, entry->resp0, |
| 731 | entry->res); |
| 732 | } else { |
| 733 | printk(KERN_DEBUG "%s: Invalid command completion type %d\n", |
| 734 | dev->name, entry->type); |
| 735 | } |
| 736 | hostap_cmd_queue_free(local, entry, 1); |
| 737 | |
| 738 | /* issue next command, if pending */ |
| 739 | entry = NULL; |
| 740 | spin_lock(&local->cmdlock); |
| 741 | if (!list_empty(&local->cmd_queue)) { |
| 742 | entry = list_entry(local->cmd_queue.next, |
| 743 | struct hostap_cmd_queue, list); |
| 744 | if (entry->issuing) { |
| 745 | /* hfa384x_cmd() has already started issuing this |
| 746 | * command, so do not start here */ |
| 747 | entry = NULL; |
| 748 | } |
| 749 | if (entry) |
| 750 | atomic_inc(&entry->usecnt); |
| 751 | } |
| 752 | spin_unlock(&local->cmdlock); |
| 753 | |
| 754 | if (entry) { |
| 755 | /* issue next command; if command issuing fails, remove the |
| 756 | * entry from cmd_queue */ |
| 757 | int res = hfa384x_cmd_issue(dev, entry); |
| 758 | spin_lock(&local->cmdlock); |
| 759 | __hostap_cmd_queue_free(local, entry, res); |
| 760 | spin_unlock(&local->cmdlock); |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | |
| 765 | static inline int hfa384x_wait_offset(struct net_device *dev, u16 o_off) |
| 766 | { |
| 767 | int tries = HFA384X_BAP_BUSY_TIMEOUT; |
| 768 | int res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY; |
| 769 | |
| 770 | while (res && tries > 0) { |
| 771 | tries--; |
| 772 | udelay(1); |
| 773 | res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY; |
| 774 | } |
| 775 | return res; |
| 776 | } |
| 777 | |
| 778 | |
| 779 | /* Offset must be even */ |
| 780 | static int hfa384x_setup_bap(struct net_device *dev, u16 bap, u16 id, |
| 781 | int offset) |
| 782 | { |
| 783 | u16 o_off, s_off; |
| 784 | int ret = 0; |
| 785 | |
| 786 | if (offset % 2 || bap > 1) |
| 787 | return -EINVAL; |
| 788 | |
| 789 | if (bap == BAP1) { |
| 790 | o_off = HFA384X_OFFSET1_OFF; |
| 791 | s_off = HFA384X_SELECT1_OFF; |
| 792 | } else { |
| 793 | o_off = HFA384X_OFFSET0_OFF; |
| 794 | s_off = HFA384X_SELECT0_OFF; |
| 795 | } |
| 796 | |
| 797 | if (hfa384x_wait_offset(dev, o_off)) { |
| 798 | prism2_io_debug_error(dev, 7); |
| 799 | printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout before\n", |
| 800 | dev->name); |
| 801 | ret = -ETIMEDOUT; |
| 802 | goto out; |
| 803 | } |
| 804 | |
| 805 | HFA384X_OUTW(id, s_off); |
| 806 | HFA384X_OUTW(offset, o_off); |
| 807 | |
| 808 | if (hfa384x_wait_offset(dev, o_off)) { |
| 809 | prism2_io_debug_error(dev, 8); |
| 810 | printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout after\n", |
| 811 | dev->name); |
| 812 | ret = -ETIMEDOUT; |
| 813 | goto out; |
| 814 | } |
| 815 | #ifndef final_version |
| 816 | if (HFA384X_INW(o_off) & HFA384X_OFFSET_ERR) { |
| 817 | prism2_io_debug_error(dev, 9); |
| 818 | printk(KERN_DEBUG "%s: hfa384x_setup_bap - offset error " |
| 819 | "(%d,0x04%x,%d); reg=0x%04x\n", |
| 820 | dev->name, bap, id, offset, HFA384X_INW(o_off)); |
| 821 | ret = -EINVAL; |
| 822 | } |
| 823 | #endif |
| 824 | |
| 825 | out: |
| 826 | return ret; |
| 827 | } |
| 828 | |
| 829 | |
| 830 | static int hfa384x_get_rid(struct net_device *dev, u16 rid, void *buf, int len, |
| 831 | int exact_len) |
| 832 | { |
| 833 | struct hostap_interface *iface; |
| 834 | local_info_t *local; |
| 835 | int res, rlen = 0; |
| 836 | struct hfa384x_rid_hdr rec; |
| 837 | |
| 838 | iface = netdev_priv(dev); |
| 839 | local = iface->local; |
| 840 | |
| 841 | if (local->no_pri) { |
| 842 | printk(KERN_DEBUG "%s: cannot get RID %04x (len=%d) - no PRI " |
| 843 | "f/w\n", dev->name, rid, len); |
| 844 | return -ENOTTY; /* Well.. not really correct, but return |
| 845 | * something unique enough.. */ |
| 846 | } |
| 847 | |
| 848 | if ((local->func->card_present && !local->func->card_present(local)) || |
| 849 | local->hw_downloading) |
| 850 | return -ENODEV; |
| 851 | |
| 852 | res = down_interruptible(&local->rid_bap_sem); |
| 853 | if (res) |
| 854 | return res; |
| 855 | |
| 856 | res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS, rid, NULL, NULL); |
| 857 | if (res) { |
| 858 | printk(KERN_DEBUG "%s: hfa384x_get_rid: CMDCODE_ACCESS failed " |
| 859 | "(res=%d, rid=%04x, len=%d)\n", |
| 860 | dev->name, res, rid, len); |
| 861 | up(&local->rid_bap_sem); |
| 862 | return res; |
| 863 | } |
| 864 | |
| 865 | spin_lock_bh(&local->baplock); |
| 866 | |
| 867 | res = hfa384x_setup_bap(dev, BAP0, rid, 0); |
| 868 | if (!res) |
| 869 | res = hfa384x_from_bap(dev, BAP0, &rec, sizeof(rec)); |
| 870 | |
| 871 | if (le16_to_cpu(rec.len) == 0) { |
| 872 | /* RID not available */ |
| 873 | res = -ENODATA; |
| 874 | } |
| 875 | |
| 876 | rlen = (le16_to_cpu(rec.len) - 1) * 2; |
| 877 | if (!res && exact_len && rlen != len) { |
| 878 | printk(KERN_DEBUG "%s: hfa384x_get_rid - RID len mismatch: " |
| 879 | "rid=0x%04x, len=%d (expected %d)\n", |
| 880 | dev->name, rid, rlen, len); |
| 881 | res = -ENODATA; |
| 882 | } |
| 883 | |
| 884 | if (!res) |
| 885 | res = hfa384x_from_bap(dev, BAP0, buf, len); |
| 886 | |
| 887 | spin_unlock_bh(&local->baplock); |
| 888 | up(&local->rid_bap_sem); |
| 889 | |
| 890 | if (res) { |
| 891 | if (res != -ENODATA) |
| 892 | printk(KERN_DEBUG "%s: hfa384x_get_rid (rid=%04x, " |
| 893 | "len=%d) - failed - res=%d\n", dev->name, rid, |
| 894 | len, res); |
| 895 | if (res == -ETIMEDOUT) |
| 896 | prism2_hw_reset(dev); |
| 897 | return res; |
| 898 | } |
| 899 | |
| 900 | return rlen; |
| 901 | } |
| 902 | |
| 903 | |
| 904 | static int hfa384x_set_rid(struct net_device *dev, u16 rid, void *buf, int len) |
| 905 | { |
| 906 | struct hostap_interface *iface; |
| 907 | local_info_t *local; |
| 908 | struct hfa384x_rid_hdr rec; |
| 909 | int res; |
| 910 | |
| 911 | iface = netdev_priv(dev); |
| 912 | local = iface->local; |
| 913 | |
| 914 | if (local->no_pri) { |
| 915 | printk(KERN_DEBUG "%s: cannot set RID %04x (len=%d) - no PRI " |
| 916 | "f/w\n", dev->name, rid, len); |
| 917 | return -ENOTTY; /* Well.. not really correct, but return |
| 918 | * something unique enough.. */ |
| 919 | } |
| 920 | |
| 921 | if ((local->func->card_present && !local->func->card_present(local)) || |
| 922 | local->hw_downloading) |
| 923 | return -ENODEV; |
| 924 | |
| 925 | rec.rid = cpu_to_le16(rid); |
| 926 | /* RID len in words and +1 for rec.rid */ |
| 927 | rec.len = cpu_to_le16(len / 2 + len % 2 + 1); |
| 928 | |
| 929 | res = down_interruptible(&local->rid_bap_sem); |
| 930 | if (res) |
| 931 | return res; |
| 932 | |
| 933 | spin_lock_bh(&local->baplock); |
| 934 | res = hfa384x_setup_bap(dev, BAP0, rid, 0); |
| 935 | if (!res) |
| 936 | res = hfa384x_to_bap(dev, BAP0, &rec, sizeof(rec)); |
| 937 | if (!res) |
| 938 | res = hfa384x_to_bap(dev, BAP0, buf, len); |
| 939 | spin_unlock_bh(&local->baplock); |
| 940 | |
| 941 | if (res) { |
| 942 | printk(KERN_DEBUG "%s: hfa384x_set_rid (rid=%04x, len=%d) - " |
| 943 | "failed - res=%d\n", dev->name, rid, len, res); |
| 944 | up(&local->rid_bap_sem); |
| 945 | return res; |
| 946 | } |
| 947 | |
| 948 | res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS_WRITE, rid, NULL, NULL); |
| 949 | up(&local->rid_bap_sem); |
| 950 | if (res) { |
| 951 | printk(KERN_DEBUG "%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE " |
| 952 | "failed (res=%d, rid=%04x, len=%d)\n", |
| 953 | dev->name, res, rid, len); |
| 954 | return res; |
| 955 | } |
| 956 | |
| 957 | if (res == -ETIMEDOUT) |
| 958 | prism2_hw_reset(dev); |
| 959 | |
| 960 | return res; |
| 961 | } |
| 962 | |
| 963 | |
| 964 | static void hfa384x_disable_interrupts(struct net_device *dev) |
| 965 | { |
| 966 | /* disable interrupts and clear event status */ |
| 967 | HFA384X_OUTW(0, HFA384X_INTEN_OFF); |
| 968 | HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF); |
| 969 | } |
| 970 | |
| 971 | |
| 972 | static void hfa384x_enable_interrupts(struct net_device *dev) |
| 973 | { |
| 974 | /* ack pending events and enable interrupts from selected events */ |
| 975 | HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF); |
| 976 | HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF); |
| 977 | } |
| 978 | |
| 979 | |
| 980 | static void hfa384x_events_no_bap0(struct net_device *dev) |
| 981 | { |
| 982 | HFA384X_OUTW(HFA384X_EVENT_MASK & ~HFA384X_BAP0_EVENTS, |
| 983 | HFA384X_INTEN_OFF); |
| 984 | } |
| 985 | |
| 986 | |
| 987 | static void hfa384x_events_all(struct net_device *dev) |
| 988 | { |
| 989 | HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF); |
| 990 | } |
| 991 | |
| 992 | |
| 993 | static void hfa384x_events_only_cmd(struct net_device *dev) |
| 994 | { |
| 995 | HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_INTEN_OFF); |
| 996 | } |
| 997 | |
| 998 | |
| 999 | static u16 hfa384x_allocate_fid(struct net_device *dev, int len) |
| 1000 | { |
| 1001 | u16 fid; |
| 1002 | unsigned long delay; |
| 1003 | |
| 1004 | /* FIX: this could be replace with hfa384x_cmd() if the Alloc event |
| 1005 | * below would be handled like CmdCompl event (sleep here, wake up from |
| 1006 | * interrupt handler */ |
| 1007 | if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_ALLOC, len)) { |
| 1008 | printk(KERN_DEBUG "%s: cannot allocate fid, len=%d\n", |
| 1009 | dev->name, len); |
| 1010 | return 0xffff; |
| 1011 | } |
| 1012 | |
| 1013 | delay = jiffies + HFA384X_ALLOC_COMPL_TIMEOUT; |
| 1014 | while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC) && |
| 1015 | time_before(jiffies, delay)) |
| 1016 | yield(); |
| 1017 | if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC)) { |
| 1018 | printk("%s: fid allocate, len=%d - timeout\n", dev->name, len); |
| 1019 | return 0xffff; |
| 1020 | } |
| 1021 | |
| 1022 | fid = HFA384X_INW(HFA384X_ALLOCFID_OFF); |
| 1023 | HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF); |
| 1024 | |
| 1025 | return fid; |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | static int prism2_reset_port(struct net_device *dev) |
| 1030 | { |
| 1031 | struct hostap_interface *iface; |
| 1032 | local_info_t *local; |
| 1033 | int res; |
| 1034 | |
| 1035 | iface = netdev_priv(dev); |
| 1036 | local = iface->local; |
| 1037 | |
| 1038 | if (!local->dev_enabled) |
| 1039 | return 0; |
| 1040 | |
| 1041 | res = hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0, |
| 1042 | NULL, NULL); |
| 1043 | if (res) |
| 1044 | printk(KERN_DEBUG "%s: reset port failed to disable port\n", |
| 1045 | dev->name); |
| 1046 | else { |
| 1047 | res = hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0, |
| 1048 | NULL, NULL); |
| 1049 | if (res) |
| 1050 | printk(KERN_DEBUG "%s: reset port failed to enable " |
| 1051 | "port\n", dev->name); |
| 1052 | } |
| 1053 | |
| 1054 | /* It looks like at least some STA firmware versions reset |
| 1055 | * fragmentation threshold back to 2346 after enable command. Restore |
| 1056 | * the configured value, if it differs from this default. */ |
| 1057 | if (local->fragm_threshold != 2346 && |
| 1058 | hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, |
| 1059 | local->fragm_threshold)) { |
| 1060 | printk(KERN_DEBUG "%s: failed to restore fragmentation " |
| 1061 | "threshold (%d) after Port0 enable\n", |
| 1062 | dev->name, local->fragm_threshold); |
| 1063 | } |
| 1064 | |
| 1065 | return res; |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | static int prism2_get_version_info(struct net_device *dev, u16 rid, |
| 1070 | const char *txt) |
| 1071 | { |
| 1072 | struct hfa384x_comp_ident comp; |
| 1073 | struct hostap_interface *iface; |
| 1074 | local_info_t *local; |
| 1075 | |
| 1076 | iface = netdev_priv(dev); |
| 1077 | local = iface->local; |
| 1078 | |
| 1079 | if (local->no_pri) { |
| 1080 | /* PRI f/w not yet available - cannot read RIDs */ |
| 1081 | return -1; |
| 1082 | } |
| 1083 | if (hfa384x_get_rid(dev, rid, &comp, sizeof(comp), 1) < 0) { |
| 1084 | printk(KERN_DEBUG "Could not get RID for component %s\n", txt); |
| 1085 | return -1; |
| 1086 | } |
| 1087 | |
| 1088 | printk(KERN_INFO "%s: %s: id=0x%02x v%d.%d.%d\n", dev->name, txt, |
| 1089 | __le16_to_cpu(comp.id), __le16_to_cpu(comp.major), |
| 1090 | __le16_to_cpu(comp.minor), __le16_to_cpu(comp.variant)); |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
| 1094 | |
| 1095 | static int prism2_setup_rids(struct net_device *dev) |
| 1096 | { |
| 1097 | struct hostap_interface *iface; |
| 1098 | local_info_t *local; |
| 1099 | u16 tmp; |
| 1100 | int ret = 0; |
| 1101 | |
| 1102 | iface = netdev_priv(dev); |
| 1103 | local = iface->local; |
| 1104 | |
| 1105 | hostap_set_word(dev, HFA384X_RID_TICKTIME, 2000); |
| 1106 | |
| 1107 | if (!local->fw_ap) { |
| 1108 | tmp = hostap_get_porttype(local); |
| 1109 | ret = hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, tmp); |
| 1110 | if (ret) { |
| 1111 | printk("%s: Port type setting to %d failed\n", |
| 1112 | dev->name, tmp); |
| 1113 | goto fail; |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | /* Setting SSID to empty string seems to kill the card in Host AP mode |
| 1118 | */ |
| 1119 | if (local->iw_mode != IW_MODE_MASTER || local->essid[0] != '\0') { |
| 1120 | ret = hostap_set_string(dev, HFA384X_RID_CNFOWNSSID, |
| 1121 | local->essid); |
| 1122 | if (ret) { |
| 1123 | printk("%s: AP own SSID setting failed\n", dev->name); |
| 1124 | goto fail; |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | ret = hostap_set_word(dev, HFA384X_RID_CNFMAXDATALEN, |
| 1129 | PRISM2_DATA_MAXLEN); |
| 1130 | if (ret) { |
| 1131 | printk("%s: MAC data length setting to %d failed\n", |
| 1132 | dev->name, PRISM2_DATA_MAXLEN); |
| 1133 | goto fail; |
| 1134 | } |
| 1135 | |
| 1136 | if (hfa384x_get_rid(dev, HFA384X_RID_CHANNELLIST, &tmp, 2, 1) < 0) { |
| 1137 | printk("%s: Channel list read failed\n", dev->name); |
| 1138 | ret = -EINVAL; |
| 1139 | goto fail; |
| 1140 | } |
| 1141 | local->channel_mask = __le16_to_cpu(tmp); |
| 1142 | |
| 1143 | if (local->channel < 1 || local->channel > 14 || |
| 1144 | !(local->channel_mask & (1 << (local->channel - 1)))) { |
| 1145 | printk(KERN_WARNING "%s: Channel setting out of range " |
| 1146 | "(%d)!\n", dev->name, local->channel); |
| 1147 | ret = -EBUSY; |
| 1148 | goto fail; |
| 1149 | } |
| 1150 | |
| 1151 | ret = hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel); |
| 1152 | if (ret) { |
| 1153 | printk("%s: Channel setting to %d failed\n", |
| 1154 | dev->name, local->channel); |
| 1155 | goto fail; |
| 1156 | } |
| 1157 | |
| 1158 | ret = hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, |
| 1159 | local->beacon_int); |
| 1160 | if (ret) { |
| 1161 | printk("%s: Beacon interval setting to %d failed\n", |
| 1162 | dev->name, local->beacon_int); |
| 1163 | /* this may fail with Symbol/Lucent firmware */ |
| 1164 | if (ret == -ETIMEDOUT) |
| 1165 | goto fail; |
| 1166 | } |
| 1167 | |
| 1168 | ret = hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, |
| 1169 | local->dtim_period); |
| 1170 | if (ret) { |
| 1171 | printk("%s: DTIM period setting to %d failed\n", |
| 1172 | dev->name, local->dtim_period); |
| 1173 | /* this may fail with Symbol/Lucent firmware */ |
| 1174 | if (ret == -ETIMEDOUT) |
| 1175 | goto fail; |
| 1176 | } |
| 1177 | |
| 1178 | ret = hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE, |
| 1179 | local->is_promisc); |
| 1180 | if (ret) |
| 1181 | printk(KERN_INFO "%s: Setting promiscuous mode (%d) failed\n", |
| 1182 | dev->name, local->is_promisc); |
| 1183 | |
| 1184 | if (!local->fw_ap) { |
| 1185 | ret = hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID, |
| 1186 | local->essid); |
| 1187 | if (ret) { |
| 1188 | printk("%s: Desired SSID setting failed\n", dev->name); |
| 1189 | goto fail; |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | /* Setup TXRateControl, defaults to allow use of 1, 2, 5.5, and |
| 1194 | * 11 Mbps in automatic TX rate fallback and 1 and 2 Mbps as basic |
| 1195 | * rates */ |
| 1196 | if (local->tx_rate_control == 0) { |
| 1197 | local->tx_rate_control = |
| 1198 | HFA384X_RATES_1MBPS | |
| 1199 | HFA384X_RATES_2MBPS | |
| 1200 | HFA384X_RATES_5MBPS | |
| 1201 | HFA384X_RATES_11MBPS; |
| 1202 | } |
| 1203 | if (local->basic_rates == 0) |
| 1204 | local->basic_rates = HFA384X_RATES_1MBPS | HFA384X_RATES_2MBPS; |
| 1205 | |
| 1206 | if (!local->fw_ap) { |
| 1207 | ret = hostap_set_word(dev, HFA384X_RID_TXRATECONTROL, |
| 1208 | local->tx_rate_control); |
| 1209 | if (ret) { |
| 1210 | printk("%s: TXRateControl setting to %d failed\n", |
| 1211 | dev->name, local->tx_rate_control); |
| 1212 | goto fail; |
| 1213 | } |
| 1214 | |
| 1215 | ret = hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES, |
| 1216 | local->tx_rate_control); |
| 1217 | if (ret) { |
| 1218 | printk("%s: cnfSupportedRates setting to %d failed\n", |
| 1219 | dev->name, local->tx_rate_control); |
| 1220 | } |
| 1221 | |
| 1222 | ret = hostap_set_word(dev, HFA384X_RID_CNFBASICRATES, |
| 1223 | local->basic_rates); |
| 1224 | if (ret) { |
| 1225 | printk("%s: cnfBasicRates setting to %d failed\n", |
| 1226 | dev->name, local->basic_rates); |
| 1227 | } |
| 1228 | |
| 1229 | ret = hostap_set_word(dev, HFA384X_RID_CREATEIBSS, 1); |
| 1230 | if (ret) { |
| 1231 | printk("%s: Create IBSS setting to 1 failed\n", |
| 1232 | dev->name); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | if (local->name_set) |
| 1237 | (void) hostap_set_string(dev, HFA384X_RID_CNFOWNNAME, |
| 1238 | local->name); |
| 1239 | |
| 1240 | if (hostap_set_encryption(local)) { |
| 1241 | printk(KERN_INFO "%s: could not configure encryption\n", |
| 1242 | dev->name); |
| 1243 | } |
| 1244 | |
| 1245 | (void) hostap_set_antsel(local); |
| 1246 | |
| 1247 | if (hostap_set_roaming(local)) { |
| 1248 | printk(KERN_INFO "%s: could not set host roaming\n", |
| 1249 | dev->name); |
| 1250 | } |
| 1251 | |
| 1252 | if (local->sta_fw_ver >= PRISM2_FW_VER(1,6,3) && |
| 1253 | hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY, local->enh_sec)) |
| 1254 | printk(KERN_INFO "%s: cnfEnhSecurity setting to 0x%x failed\n", |
| 1255 | dev->name, local->enh_sec); |
| 1256 | |
| 1257 | /* 32-bit tallies were added in STA f/w 0.8.0, but they were apparently |
| 1258 | * not working correctly (last seven counters report bogus values). |
| 1259 | * This has been fixed in 0.8.2, so enable 32-bit tallies only |
| 1260 | * beginning with that firmware version. Another bug fix for 32-bit |
| 1261 | * tallies in 1.4.0; should 16-bit tallies be used for some other |
| 1262 | * versions, too? */ |
| 1263 | if (local->sta_fw_ver >= PRISM2_FW_VER(0,8,2)) { |
| 1264 | if (hostap_set_word(dev, HFA384X_RID_CNFTHIRTY2TALLY, 1)) { |
| 1265 | printk(KERN_INFO "%s: cnfThirty2Tally setting " |
| 1266 | "failed\n", dev->name); |
| 1267 | local->tallies32 = 0; |
| 1268 | } else |
| 1269 | local->tallies32 = 1; |
| 1270 | } else |
| 1271 | local->tallies32 = 0; |
| 1272 | |
| 1273 | hostap_set_auth_algs(local); |
| 1274 | |
| 1275 | if (hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, |
| 1276 | local->fragm_threshold)) { |
| 1277 | printk(KERN_INFO "%s: setting FragmentationThreshold to %d " |
| 1278 | "failed\n", dev->name, local->fragm_threshold); |
| 1279 | } |
| 1280 | |
| 1281 | if (hostap_set_word(dev, HFA384X_RID_RTSTHRESHOLD, |
| 1282 | local->rts_threshold)) { |
| 1283 | printk(KERN_INFO "%s: setting RTSThreshold to %d failed\n", |
| 1284 | dev->name, local->rts_threshold); |
| 1285 | } |
| 1286 | |
| 1287 | if (local->manual_retry_count >= 0 && |
| 1288 | hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT, |
| 1289 | local->manual_retry_count)) { |
| 1290 | printk(KERN_INFO "%s: setting cnfAltRetryCount to %d failed\n", |
| 1291 | dev->name, local->manual_retry_count); |
| 1292 | } |
| 1293 | |
| 1294 | if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1) && |
| 1295 | hfa384x_get_rid(dev, HFA384X_RID_CNFDBMADJUST, &tmp, 2, 1) == 2) { |
| 1296 | local->rssi_to_dBm = le16_to_cpu(tmp); |
| 1297 | } |
| 1298 | |
| 1299 | if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->wpa && |
| 1300 | hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1)) { |
| 1301 | printk(KERN_INFO "%s: setting ssnHandlingMode to 1 failed\n", |
| 1302 | dev->name); |
| 1303 | } |
| 1304 | |
| 1305 | if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->generic_elem && |
| 1306 | hfa384x_set_rid(dev, HFA384X_RID_GENERICELEMENT, |
| 1307 | local->generic_elem, local->generic_elem_len)) { |
| 1308 | printk(KERN_INFO "%s: setting genericElement failed\n", |
| 1309 | dev->name); |
| 1310 | } |
| 1311 | |
| 1312 | fail: |
| 1313 | return ret; |
| 1314 | } |
| 1315 | |
| 1316 | |
| 1317 | static int prism2_hw_init(struct net_device *dev, int initial) |
| 1318 | { |
| 1319 | struct hostap_interface *iface; |
| 1320 | local_info_t *local; |
| 1321 | int ret, first = 1; |
| 1322 | unsigned long start, delay; |
| 1323 | |
| 1324 | PDEBUG(DEBUG_FLOW, "prism2_hw_init()\n"); |
| 1325 | |
| 1326 | iface = netdev_priv(dev); |
| 1327 | local = iface->local; |
| 1328 | |
| 1329 | clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits); |
| 1330 | |
| 1331 | init: |
| 1332 | /* initialize HFA 384x */ |
| 1333 | ret = hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_INIT, 0); |
| 1334 | if (ret) { |
| 1335 | printk(KERN_INFO "%s: first command failed - assuming card " |
| 1336 | "does not have primary firmware\n", dev_info); |
| 1337 | } |
| 1338 | |
| 1339 | if (first && (HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) { |
| 1340 | /* EvStat has Cmd bit set in some cases, so retry once if no |
| 1341 | * wait was needed */ |
| 1342 | HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF); |
| 1343 | printk(KERN_DEBUG "%s: init command completed too quickly - " |
| 1344 | "retrying\n", dev->name); |
| 1345 | first = 0; |
| 1346 | goto init; |
| 1347 | } |
| 1348 | |
| 1349 | start = jiffies; |
| 1350 | delay = jiffies + HFA384X_INIT_TIMEOUT; |
| 1351 | while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) && |
| 1352 | time_before(jiffies, delay)) |
| 1353 | yield(); |
| 1354 | if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) { |
| 1355 | printk(KERN_DEBUG "%s: assuming no Primary image in " |
| 1356 | "flash - card initialization not completed\n", |
| 1357 | dev_info); |
| 1358 | local->no_pri = 1; |
| 1359 | #ifdef PRISM2_DOWNLOAD_SUPPORT |
| 1360 | if (local->sram_type == -1) |
| 1361 | local->sram_type = prism2_get_ram_size(local); |
| 1362 | #endif /* PRISM2_DOWNLOAD_SUPPORT */ |
| 1363 | return 1; |
| 1364 | } |
| 1365 | local->no_pri = 0; |
| 1366 | printk(KERN_DEBUG "prism2_hw_init: initialized in %lu ms\n", |
| 1367 | (jiffies - start) * 1000 / HZ); |
| 1368 | HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF); |
| 1369 | return 0; |
| 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | static int prism2_hw_init2(struct net_device *dev, int initial) |
| 1374 | { |
| 1375 | struct hostap_interface *iface; |
| 1376 | local_info_t *local; |
| 1377 | int i; |
| 1378 | |
| 1379 | iface = netdev_priv(dev); |
| 1380 | local = iface->local; |
| 1381 | |
| 1382 | #ifdef PRISM2_DOWNLOAD_SUPPORT |
| 1383 | kfree(local->pda); |
| 1384 | if (local->no_pri) |
| 1385 | local->pda = NULL; |
| 1386 | else |
| 1387 | local->pda = prism2_read_pda(dev); |
| 1388 | #endif /* PRISM2_DOWNLOAD_SUPPORT */ |
| 1389 | |
| 1390 | hfa384x_disable_interrupts(dev); |
| 1391 | |
| 1392 | #ifndef final_version |
| 1393 | HFA384X_OUTW(HFA384X_MAGIC, HFA384X_SWSUPPORT0_OFF); |
| 1394 | if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) { |
| 1395 | printk("SWSUPPORT0 write/read failed: %04X != %04X\n", |
| 1396 | HFA384X_INW(HFA384X_SWSUPPORT0_OFF), HFA384X_MAGIC); |
| 1397 | goto failed; |
| 1398 | } |
| 1399 | #endif |
| 1400 | |
| 1401 | if (initial || local->pri_only) { |
| 1402 | hfa384x_events_only_cmd(dev); |
| 1403 | /* get card version information */ |
| 1404 | if (prism2_get_version_info(dev, HFA384X_RID_NICID, "NIC") || |
| 1405 | prism2_get_version_info(dev, HFA384X_RID_PRIID, "PRI")) { |
| 1406 | hfa384x_disable_interrupts(dev); |
| 1407 | goto failed; |
| 1408 | } |
| 1409 | |
| 1410 | if (prism2_get_version_info(dev, HFA384X_RID_STAID, "STA")) { |
| 1411 | printk(KERN_DEBUG "%s: Failed to read STA f/w version " |
| 1412 | "- only Primary f/w present\n", dev->name); |
| 1413 | local->pri_only = 1; |
| 1414 | return 0; |
| 1415 | } |
| 1416 | local->pri_only = 0; |
| 1417 | hfa384x_disable_interrupts(dev); |
| 1418 | } |
| 1419 | |
| 1420 | /* FIX: could convert allocate_fid to use sleeping CmdCompl wait and |
| 1421 | * enable interrupts before this. This would also require some sort of |
| 1422 | * sleeping AllocEv waiting */ |
| 1423 | |
| 1424 | /* allocate TX FIDs */ |
| 1425 | local->txfid_len = PRISM2_TXFID_LEN; |
| 1426 | for (i = 0; i < PRISM2_TXFID_COUNT; i++) { |
| 1427 | local->txfid[i] = hfa384x_allocate_fid(dev, local->txfid_len); |
| 1428 | if (local->txfid[i] == 0xffff && local->txfid_len > 1600) { |
| 1429 | local->txfid[i] = hfa384x_allocate_fid(dev, 1600); |
| 1430 | if (local->txfid[i] != 0xffff) { |
| 1431 | printk(KERN_DEBUG "%s: Using shorter TX FID " |
| 1432 | "(1600 bytes)\n", dev->name); |
| 1433 | local->txfid_len = 1600; |
| 1434 | } |
| 1435 | } |
| 1436 | if (local->txfid[i] == 0xffff) |
| 1437 | goto failed; |
| 1438 | local->intransmitfid[i] = PRISM2_TXFID_EMPTY; |
| 1439 | } |
| 1440 | |
| 1441 | hfa384x_events_only_cmd(dev); |
| 1442 | |
| 1443 | if (initial) { |
| 1444 | struct list_head *ptr; |
| 1445 | prism2_check_sta_fw_version(local); |
| 1446 | |
| 1447 | if (hfa384x_get_rid(dev, HFA384X_RID_CNFOWNMACADDR, |
| 1448 | &dev->dev_addr, 6, 1) < 0) { |
| 1449 | printk("%s: could not get own MAC address\n", |
| 1450 | dev->name); |
| 1451 | } |
| 1452 | list_for_each(ptr, &local->hostap_interfaces) { |
| 1453 | iface = list_entry(ptr, struct hostap_interface, list); |
| 1454 | memcpy(iface->dev->dev_addr, dev->dev_addr, ETH_ALEN); |
| 1455 | } |
| 1456 | } else if (local->fw_ap) |
| 1457 | prism2_check_sta_fw_version(local); |
| 1458 | |
| 1459 | prism2_setup_rids(dev); |
| 1460 | |
| 1461 | /* MAC is now configured, but port 0 is not yet enabled */ |
| 1462 | return 0; |
| 1463 | |
| 1464 | failed: |
| 1465 | if (!local->no_pri) |
| 1466 | printk(KERN_WARNING "%s: Initialization failed\n", dev_info); |
| 1467 | return 1; |
| 1468 | } |
| 1469 | |
| 1470 | |
| 1471 | static int prism2_hw_enable(struct net_device *dev, int initial) |
| 1472 | { |
| 1473 | struct hostap_interface *iface; |
| 1474 | local_info_t *local; |
| 1475 | int was_resetting; |
| 1476 | |
| 1477 | iface = netdev_priv(dev); |
| 1478 | local = iface->local; |
| 1479 | was_resetting = local->hw_resetting; |
| 1480 | |
| 1481 | if (hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL, NULL)) { |
| 1482 | printk("%s: MAC port 0 enabling failed\n", dev->name); |
| 1483 | return 1; |
| 1484 | } |
| 1485 | |
| 1486 | local->hw_ready = 1; |
| 1487 | local->hw_reset_tries = 0; |
| 1488 | local->hw_resetting = 0; |
| 1489 | hfa384x_enable_interrupts(dev); |
| 1490 | |
| 1491 | /* at least D-Link DWL-650 seems to require additional port reset |
| 1492 | * before it starts acting as an AP, so reset port automatically |
| 1493 | * here just in case */ |
| 1494 | if (initial && prism2_reset_port(dev)) { |
| 1495 | printk("%s: MAC port 0 reseting failed\n", dev->name); |
| 1496 | return 1; |
| 1497 | } |
| 1498 | |
| 1499 | if (was_resetting && netif_queue_stopped(dev)) { |
| 1500 | /* If hw_reset() was called during pending transmit, netif |
| 1501 | * queue was stopped. Wake it up now since the wlan card has |
| 1502 | * been resetted. */ |
| 1503 | netif_wake_queue(dev); |
| 1504 | } |
| 1505 | |
| 1506 | return 0; |
| 1507 | } |
| 1508 | |
| 1509 | |
| 1510 | static int prism2_hw_config(struct net_device *dev, int initial) |
| 1511 | { |
| 1512 | struct hostap_interface *iface; |
| 1513 | local_info_t *local; |
| 1514 | |
| 1515 | iface = netdev_priv(dev); |
| 1516 | local = iface->local; |
| 1517 | |
| 1518 | if (local->hw_downloading) |
| 1519 | return 1; |
| 1520 | |
| 1521 | if (prism2_hw_init(dev, initial)) { |
| 1522 | return local->no_pri ? 0 : 1; |
| 1523 | } |
| 1524 | |
| 1525 | if (prism2_hw_init2(dev, initial)) |
| 1526 | return 1; |
| 1527 | |
| 1528 | /* Enable firmware if secondary image is loaded and at least one of the |
| 1529 | * netdevices is up. */ |
| 1530 | if (!local->pri_only && |
| 1531 | (initial == 0 || (initial == 2 && local->num_dev_open > 0))) { |
| 1532 | if (!local->dev_enabled) |
| 1533 | prism2_callback(local, PRISM2_CALLBACK_ENABLE); |
| 1534 | local->dev_enabled = 1; |
| 1535 | return prism2_hw_enable(dev, initial); |
| 1536 | } |
| 1537 | |
| 1538 | return 0; |
| 1539 | } |
| 1540 | |
| 1541 | |
| 1542 | static void prism2_hw_shutdown(struct net_device *dev, int no_disable) |
| 1543 | { |
| 1544 | struct hostap_interface *iface; |
| 1545 | local_info_t *local; |
| 1546 | |
| 1547 | iface = netdev_priv(dev); |
| 1548 | local = iface->local; |
| 1549 | |
| 1550 | /* Allow only command completion events during disable */ |
| 1551 | hfa384x_events_only_cmd(dev); |
| 1552 | |
| 1553 | local->hw_ready = 0; |
| 1554 | if (local->dev_enabled) |
| 1555 | prism2_callback(local, PRISM2_CALLBACK_DISABLE); |
| 1556 | local->dev_enabled = 0; |
| 1557 | |
| 1558 | if (local->func->card_present && !local->func->card_present(local)) { |
| 1559 | printk(KERN_DEBUG "%s: card already removed or not configured " |
| 1560 | "during shutdown\n", dev->name); |
| 1561 | return; |
| 1562 | } |
| 1563 | |
| 1564 | if ((no_disable & HOSTAP_HW_NO_DISABLE) == 0 && |
| 1565 | hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL, NULL)) |
| 1566 | printk(KERN_WARNING "%s: Shutdown failed\n", dev_info); |
| 1567 | |
| 1568 | hfa384x_disable_interrupts(dev); |
| 1569 | |
| 1570 | if (no_disable & HOSTAP_HW_ENABLE_CMDCOMPL) |
| 1571 | hfa384x_events_only_cmd(dev); |
| 1572 | else |
| 1573 | prism2_clear_cmd_queue(local); |
| 1574 | } |
| 1575 | |
| 1576 | |
| 1577 | static void prism2_hw_reset(struct net_device *dev) |
| 1578 | { |
| 1579 | struct hostap_interface *iface; |
| 1580 | local_info_t *local; |
| 1581 | |
| 1582 | #if 0 |
| 1583 | static long last_reset = 0; |
| 1584 | |
| 1585 | /* do not reset card more than once per second to avoid ending up in a |
| 1586 | * busy loop reseting the card */ |
| 1587 | if (time_before_eq(jiffies, last_reset + HZ)) |
| 1588 | return; |
| 1589 | last_reset = jiffies; |
| 1590 | #endif |
| 1591 | |
| 1592 | iface = netdev_priv(dev); |
| 1593 | local = iface->local; |
| 1594 | |
| 1595 | if (in_interrupt()) { |
| 1596 | printk(KERN_DEBUG "%s: driver bug - prism2_hw_reset() called " |
| 1597 | "in interrupt context\n", dev->name); |
| 1598 | return; |
| 1599 | } |
| 1600 | |
| 1601 | if (local->hw_downloading) |
| 1602 | return; |
| 1603 | |
| 1604 | if (local->hw_resetting) { |
| 1605 | printk(KERN_WARNING "%s: %s: already resetting card - " |
| 1606 | "ignoring reset request\n", dev_info, dev->name); |
| 1607 | return; |
| 1608 | } |
| 1609 | |
| 1610 | local->hw_reset_tries++; |
| 1611 | if (local->hw_reset_tries > 10) { |
| 1612 | printk(KERN_WARNING "%s: too many reset tries, skipping\n", |
| 1613 | dev->name); |
| 1614 | return; |
| 1615 | } |
| 1616 | |
| 1617 | printk(KERN_WARNING "%s: %s: resetting card\n", dev_info, dev->name); |
| 1618 | hfa384x_disable_interrupts(dev); |
| 1619 | local->hw_resetting = 1; |
| 1620 | if (local->func->cor_sreset) { |
| 1621 | /* Host system seems to hang in some cases with high traffic |
| 1622 | * load or shared interrupts during COR sreset. Disable shared |
| 1623 | * interrupts during reset to avoid these crashes. COS sreset |
| 1624 | * takes quite a long time, so it is unfortunate that this |
| 1625 | * seems to be needed. Anyway, I do not know of any better way |
| 1626 | * of avoiding the crash. */ |
| 1627 | disable_irq(dev->irq); |
| 1628 | local->func->cor_sreset(local); |
| 1629 | enable_irq(dev->irq); |
| 1630 | } |
| 1631 | prism2_hw_shutdown(dev, 1); |
| 1632 | prism2_hw_config(dev, 0); |
| 1633 | local->hw_resetting = 0; |
| 1634 | |
| 1635 | #ifdef PRISM2_DOWNLOAD_SUPPORT |
| 1636 | if (local->dl_pri) { |
| 1637 | printk(KERN_DEBUG "%s: persistent download of primary " |
| 1638 | "firmware\n", dev->name); |
| 1639 | if (prism2_download_genesis(local, local->dl_pri) < 0) |
| 1640 | printk(KERN_WARNING "%s: download (PRI) failed\n", |
| 1641 | dev->name); |
| 1642 | } |
| 1643 | |
| 1644 | if (local->dl_sec) { |
| 1645 | printk(KERN_DEBUG "%s: persistent download of secondary " |
| 1646 | "firmware\n", dev->name); |
| 1647 | if (prism2_download_volatile(local, local->dl_sec) < 0) |
| 1648 | printk(KERN_WARNING "%s: download (SEC) failed\n", |
| 1649 | dev->name); |
| 1650 | } |
| 1651 | #endif /* PRISM2_DOWNLOAD_SUPPORT */ |
| 1652 | |
| 1653 | /* TODO: restore beacon TIM bits for STAs that have buffered frames */ |
| 1654 | } |
| 1655 | |
| 1656 | |
| 1657 | static void prism2_schedule_reset(local_info_t *local) |
| 1658 | { |
| 1659 | schedule_work(&local->reset_queue); |
| 1660 | } |
| 1661 | |
| 1662 | |
| 1663 | /* Called only as scheduled task after noticing card timeout in interrupt |
| 1664 | * context */ |
| 1665 | static void handle_reset_queue(void *data) |
| 1666 | { |
| 1667 | local_info_t *local = (local_info_t *) data; |
| 1668 | |
| 1669 | printk(KERN_DEBUG "%s: scheduled card reset\n", local->dev->name); |
| 1670 | prism2_hw_reset(local->dev); |
| 1671 | |
| 1672 | if (netif_queue_stopped(local->dev)) { |
| 1673 | int i; |
| 1674 | |
| 1675 | for (i = 0; i < PRISM2_TXFID_COUNT; i++) |
| 1676 | if (local->intransmitfid[i] == PRISM2_TXFID_EMPTY) { |
| 1677 | PDEBUG(DEBUG_EXTRA, "prism2_tx_timeout: " |
| 1678 | "wake up queue\n"); |
| 1679 | netif_wake_queue(local->dev); |
| 1680 | break; |
| 1681 | } |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | |
| 1686 | static int prism2_get_txfid_idx(local_info_t *local) |
| 1687 | { |
| 1688 | int idx, end; |
| 1689 | unsigned long flags; |
| 1690 | |
| 1691 | spin_lock_irqsave(&local->txfidlock, flags); |
| 1692 | end = idx = local->next_txfid; |
| 1693 | do { |
| 1694 | if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) { |
| 1695 | local->intransmitfid[idx] = PRISM2_TXFID_RESERVED; |
| 1696 | spin_unlock_irqrestore(&local->txfidlock, flags); |
| 1697 | return idx; |
| 1698 | } |
| 1699 | idx++; |
| 1700 | if (idx >= PRISM2_TXFID_COUNT) |
| 1701 | idx = 0; |
| 1702 | } while (idx != end); |
| 1703 | spin_unlock_irqrestore(&local->txfidlock, flags); |
| 1704 | |
| 1705 | PDEBUG(DEBUG_EXTRA2, "prism2_get_txfid_idx: no room in txfid buf: " |
| 1706 | "packet dropped\n"); |
| 1707 | local->stats.tx_dropped++; |
| 1708 | |
| 1709 | return -1; |
| 1710 | } |
| 1711 | |
| 1712 | |
| 1713 | /* Called only from hardware IRQ */ |
Pavel Roskin | b15eff2 | 2005-07-30 12:50:05 -0700 | [diff] [blame] | 1714 | static void prism2_transmit_cb(struct net_device *dev, long context, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1715 | u16 resp0, u16 res) |
| 1716 | { |
| 1717 | struct hostap_interface *iface; |
| 1718 | local_info_t *local; |
| 1719 | int idx = (int) context; |
| 1720 | |
| 1721 | iface = netdev_priv(dev); |
| 1722 | local = iface->local; |
| 1723 | |
| 1724 | if (res) { |
| 1725 | printk(KERN_DEBUG "%s: prism2_transmit_cb - res=0x%02x\n", |
| 1726 | dev->name, res); |
| 1727 | return; |
| 1728 | } |
| 1729 | |
| 1730 | if (idx < 0 || idx >= PRISM2_TXFID_COUNT) { |
| 1731 | printk(KERN_DEBUG "%s: prism2_transmit_cb called with invalid " |
| 1732 | "idx=%d\n", dev->name, idx); |
| 1733 | return; |
| 1734 | } |
| 1735 | |
| 1736 | if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) { |
| 1737 | printk(KERN_DEBUG "%s: driver bug: prism2_transmit_cb called " |
| 1738 | "with no pending transmit\n", dev->name); |
| 1739 | } |
| 1740 | |
| 1741 | if (netif_queue_stopped(dev)) { |
| 1742 | /* ready for next TX, so wake up queue that was stopped in |
| 1743 | * prism2_transmit() */ |
| 1744 | netif_wake_queue(dev); |
| 1745 | } |
| 1746 | |
| 1747 | spin_lock(&local->txfidlock); |
| 1748 | |
| 1749 | /* With reclaim, Resp0 contains new txfid for transmit; the old txfid |
| 1750 | * will be automatically allocated for the next TX frame */ |
| 1751 | local->intransmitfid[idx] = resp0; |
| 1752 | |
| 1753 | PDEBUG(DEBUG_FID, "%s: prism2_transmit_cb: txfid[%d]=0x%04x, " |
| 1754 | "resp0=0x%04x, transmit_txfid=0x%04x\n", |
| 1755 | dev->name, idx, local->txfid[idx], |
| 1756 | resp0, local->intransmitfid[local->next_txfid]); |
| 1757 | |
| 1758 | idx++; |
| 1759 | if (idx >= PRISM2_TXFID_COUNT) |
| 1760 | idx = 0; |
| 1761 | local->next_txfid = idx; |
| 1762 | |
| 1763 | /* check if all TX buffers are occupied */ |
| 1764 | do { |
| 1765 | if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) { |
| 1766 | spin_unlock(&local->txfidlock); |
| 1767 | return; |
| 1768 | } |
| 1769 | idx++; |
| 1770 | if (idx >= PRISM2_TXFID_COUNT) |
| 1771 | idx = 0; |
| 1772 | } while (idx != local->next_txfid); |
| 1773 | spin_unlock(&local->txfidlock); |
| 1774 | |
| 1775 | /* no empty TX buffers, stop queue */ |
| 1776 | netif_stop_queue(dev); |
| 1777 | } |
| 1778 | |
| 1779 | |
| 1780 | /* Called only from software IRQ if PCI bus master is not used (with bus master |
| 1781 | * this can be called both from software and hardware IRQ) */ |
| 1782 | static int prism2_transmit(struct net_device *dev, int idx) |
| 1783 | { |
| 1784 | struct hostap_interface *iface; |
| 1785 | local_info_t *local; |
| 1786 | int res; |
| 1787 | |
| 1788 | iface = netdev_priv(dev); |
| 1789 | local = iface->local; |
| 1790 | |
| 1791 | /* The driver tries to stop netif queue so that there would not be |
| 1792 | * more than one attempt to transmit frames going on; check that this |
| 1793 | * is really the case */ |
| 1794 | |
| 1795 | if (test_and_set_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) { |
| 1796 | printk(KERN_DEBUG "%s: driver bug - prism2_transmit() called " |
| 1797 | "when previous TX was pending\n", dev->name); |
| 1798 | return -1; |
| 1799 | } |
| 1800 | |
| 1801 | /* stop the queue for the time that transmit is pending */ |
| 1802 | netif_stop_queue(dev); |
| 1803 | |
| 1804 | /* transmit packet */ |
| 1805 | res = hfa384x_cmd_callback( |
| 1806 | dev, |
| 1807 | HFA384X_CMDCODE_TRANSMIT | HFA384X_CMD_TX_RECLAIM, |
| 1808 | local->txfid[idx], |
Pavel Roskin | b15eff2 | 2005-07-30 12:50:05 -0700 | [diff] [blame] | 1809 | prism2_transmit_cb, (long) idx); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1810 | |
| 1811 | if (res) { |
| 1812 | struct net_device_stats *stats; |
| 1813 | printk(KERN_DEBUG "%s: prism2_transmit: CMDCODE_TRANSMIT " |
| 1814 | "failed (res=%d)\n", dev->name, res); |
| 1815 | stats = hostap_get_stats(dev); |
| 1816 | stats->tx_dropped++; |
| 1817 | netif_wake_queue(dev); |
| 1818 | return -1; |
| 1819 | } |
| 1820 | dev->trans_start = jiffies; |
| 1821 | |
| 1822 | /* Since we did not wait for command completion, the card continues |
| 1823 | * to process on the background and we will finish handling when |
| 1824 | * command completion event is handled (prism2_cmd_ev() function) */ |
| 1825 | |
| 1826 | return 0; |
| 1827 | } |
| 1828 | |
| 1829 | |
| 1830 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 1831 | /* Called only from hardware IRQ */ |
| 1832 | static void prism2_tx_cb(struct net_device *dev, void *context, |
| 1833 | u16 resp0, u16 res) |
| 1834 | { |
| 1835 | struct hostap_interface *iface; |
| 1836 | local_info_t *local; |
| 1837 | unsigned long addr; |
| 1838 | int buf_len = (int) context; |
| 1839 | |
| 1840 | iface = netdev_priv(dev); |
| 1841 | local = iface->local; |
| 1842 | |
| 1843 | if (res) { |
| 1844 | printk(KERN_DEBUG "%s: prism2_tx_cb - res=0x%02x\n", |
| 1845 | dev->name, res); |
| 1846 | return; |
| 1847 | } |
| 1848 | |
| 1849 | addr = virt_to_phys(local->bus_m0_buf); |
| 1850 | HFA384X_OUTW((addr & 0xffff0000) >> 16, HFA384X_PCI_M0_ADDRH_OFF); |
| 1851 | HFA384X_OUTW(addr & 0x0000ffff, HFA384X_PCI_M0_ADDRL_OFF); |
| 1852 | HFA384X_OUTW(buf_len / 2, HFA384X_PCI_M0_LEN_OFF); |
| 1853 | HFA384X_OUTW(HFA384X_PCI_CTL_TO_BAP, HFA384X_PCI_M0_CTL_OFF); |
| 1854 | } |
| 1855 | #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */ |
| 1856 | |
| 1857 | |
| 1858 | /* Send IEEE 802.11 frame (convert the header into Prism2 TX descriptor and |
| 1859 | * send the payload with this descriptor) */ |
| 1860 | /* Called only from software IRQ */ |
| 1861 | static int prism2_tx_80211(struct sk_buff *skb, struct net_device *dev) |
| 1862 | { |
| 1863 | struct hostap_interface *iface; |
| 1864 | local_info_t *local; |
| 1865 | struct hfa384x_tx_frame txdesc; |
| 1866 | struct hostap_ieee80211_hdr *hdr; |
| 1867 | struct hostap_skb_tx_data *meta; |
| 1868 | int hdr_len, data_len, idx, res, ret = -1; |
| 1869 | u16 tx_control, fc; |
| 1870 | |
| 1871 | iface = netdev_priv(dev); |
| 1872 | local = iface->local; |
| 1873 | |
| 1874 | meta = (struct hostap_skb_tx_data *) skb->cb; |
| 1875 | hdr = (struct hostap_ieee80211_hdr *) skb->data; |
| 1876 | |
| 1877 | prism2_callback(local, PRISM2_CALLBACK_TX_START); |
| 1878 | |
| 1879 | if ((local->func->card_present && !local->func->card_present(local)) || |
| 1880 | !local->hw_ready || local->hw_downloading || local->pri_only) { |
| 1881 | if (net_ratelimit()) { |
| 1882 | printk(KERN_DEBUG "%s: prism2_tx_80211: hw not ready -" |
| 1883 | " skipping\n", dev->name); |
| 1884 | } |
| 1885 | goto fail; |
| 1886 | } |
| 1887 | |
| 1888 | memset(&txdesc, 0, sizeof(txdesc)); |
| 1889 | |
| 1890 | /* skb->data starts with txdesc->frame_control */ |
| 1891 | hdr_len = 24; |
| 1892 | memcpy(&txdesc.frame_control, skb->data, hdr_len); |
| 1893 | fc = le16_to_cpu(txdesc.frame_control); |
Jouni Malinen | ebed67d | 2005-07-30 20:43:19 -0700 | [diff] [blame] | 1894 | if (HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1895 | (fc & WLAN_FC_FROMDS) && (fc & WLAN_FC_TODS) && skb->len >= 30) { |
| 1896 | /* Addr4 */ |
| 1897 | memcpy(txdesc.addr4, skb->data + hdr_len, ETH_ALEN); |
| 1898 | hdr_len += ETH_ALEN; |
| 1899 | } |
| 1900 | |
| 1901 | tx_control = local->tx_control; |
| 1902 | if (meta->tx_cb_idx) { |
| 1903 | tx_control |= HFA384X_TX_CTRL_TX_OK; |
| 1904 | txdesc.sw_support = cpu_to_le16(meta->tx_cb_idx); |
| 1905 | } |
| 1906 | txdesc.tx_control = cpu_to_le16(tx_control); |
| 1907 | txdesc.tx_rate = meta->rate; |
| 1908 | |
| 1909 | data_len = skb->len - hdr_len; |
| 1910 | txdesc.data_len = cpu_to_le16(data_len); |
| 1911 | txdesc.len = cpu_to_be16(data_len); |
| 1912 | |
| 1913 | idx = prism2_get_txfid_idx(local); |
| 1914 | if (idx < 0) |
| 1915 | goto fail; |
| 1916 | |
| 1917 | if (local->frame_dump & PRISM2_DUMP_TX_HDR) |
| 1918 | hostap_dump_tx_header(dev->name, &txdesc); |
| 1919 | |
| 1920 | spin_lock(&local->baplock); |
| 1921 | res = hfa384x_setup_bap(dev, BAP0, local->txfid[idx], 0); |
| 1922 | |
| 1923 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 1924 | if (!res && skb->len >= local->bus_master_threshold_tx) { |
| 1925 | u8 *pos; |
| 1926 | int buf_len; |
| 1927 | |
| 1928 | local->bus_m0_tx_idx = idx; |
| 1929 | |
| 1930 | /* FIX: BAP0 should be locked during bus master transfer, but |
| 1931 | * baplock with BH's disabled is not OK for this; netif queue |
| 1932 | * stopping is not enough since BAP0 is used also for RID |
| 1933 | * read/write */ |
| 1934 | |
| 1935 | /* stop the queue for the time that bus mastering on BAP0 is |
| 1936 | * in use */ |
| 1937 | netif_stop_queue(dev); |
| 1938 | |
| 1939 | spin_unlock(&local->baplock); |
| 1940 | |
| 1941 | /* Copy frame data to bus_m0_buf */ |
| 1942 | pos = local->bus_m0_buf; |
| 1943 | memcpy(pos, &txdesc, sizeof(txdesc)); |
| 1944 | pos += sizeof(txdesc); |
| 1945 | memcpy(pos, skb->data + hdr_len, skb->len - hdr_len); |
| 1946 | pos += skb->len - hdr_len; |
| 1947 | buf_len = pos - local->bus_m0_buf; |
| 1948 | if (buf_len & 1) |
| 1949 | buf_len++; |
| 1950 | |
| 1951 | #ifdef PRISM2_ENABLE_BEFORE_TX_BUS_MASTER |
| 1952 | /* Any RX packet seems to break something with TX bus |
| 1953 | * mastering; enable command is enough to fix this.. */ |
| 1954 | if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_ENABLE, 0, |
Pavel Roskin | b15eff2 | 2005-07-30 12:50:05 -0700 | [diff] [blame] | 1955 | prism2_tx_cb, (long) buf_len)) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1956 | printk(KERN_DEBUG "%s: TX: enable port0 failed\n", |
| 1957 | dev->name); |
| 1958 | } |
| 1959 | #else /* PRISM2_ENABLE_BEFORE_TX_BUS_MASTER */ |
| 1960 | prism2_tx_cb(dev, (void *) buf_len, 0, 0); |
| 1961 | #endif /* PRISM2_ENABLE_BEFORE_TX_BUS_MASTER */ |
| 1962 | |
| 1963 | /* Bus master transfer will be started from command completion |
| 1964 | * event handler and TX handling will be finished by calling |
| 1965 | * prism2_transmit() from bus master event handler */ |
| 1966 | goto tx_stats; |
| 1967 | } |
| 1968 | #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */ |
| 1969 | |
| 1970 | if (!res) |
| 1971 | res = hfa384x_to_bap(dev, BAP0, &txdesc, sizeof(txdesc)); |
| 1972 | if (!res) |
| 1973 | res = hfa384x_to_bap(dev, BAP0, skb->data + hdr_len, |
| 1974 | skb->len - hdr_len); |
| 1975 | spin_unlock(&local->baplock); |
| 1976 | |
| 1977 | if (!res) |
| 1978 | res = prism2_transmit(dev, idx); |
| 1979 | if (res) { |
| 1980 | printk(KERN_DEBUG "%s: prism2_tx_80211 - to BAP0 failed\n", |
| 1981 | dev->name); |
| 1982 | local->intransmitfid[idx] = PRISM2_TXFID_EMPTY; |
| 1983 | schedule_work(&local->reset_queue); |
| 1984 | goto fail; |
| 1985 | } |
| 1986 | |
| 1987 | ret = 0; |
| 1988 | |
| 1989 | fail: |
| 1990 | prism2_callback(local, PRISM2_CALLBACK_TX_END); |
| 1991 | return ret; |
| 1992 | } |
| 1993 | |
| 1994 | |
| 1995 | /* Some SMP systems have reported number of odd errors with hostap_pci. fid |
| 1996 | * register has changed values between consecutive reads for an unknown reason. |
| 1997 | * This should really not happen, so more debugging is needed. This test |
| 1998 | * version is a big slower, but it will detect most of such register changes |
| 1999 | * and will try to get the correct fid eventually. */ |
| 2000 | #define EXTRA_FID_READ_TESTS |
| 2001 | |
| 2002 | static inline u16 prism2_read_fid_reg(struct net_device *dev, u16 reg) |
| 2003 | { |
| 2004 | #ifdef EXTRA_FID_READ_TESTS |
| 2005 | u16 val, val2, val3; |
| 2006 | int i; |
| 2007 | |
| 2008 | for (i = 0; i < 10; i++) { |
| 2009 | val = HFA384X_INW(reg); |
| 2010 | val2 = HFA384X_INW(reg); |
| 2011 | val3 = HFA384X_INW(reg); |
| 2012 | |
| 2013 | if (val == val2 && val == val3) |
| 2014 | return val; |
| 2015 | |
| 2016 | printk(KERN_DEBUG "%s: detected fid change (try=%d, reg=%04x):" |
| 2017 | " %04x %04x %04x\n", |
| 2018 | dev->name, i, reg, val, val2, val3); |
| 2019 | if ((val == val2 || val == val3) && val != 0) |
| 2020 | return val; |
| 2021 | if (val2 == val3 && val2 != 0) |
| 2022 | return val2; |
| 2023 | } |
| 2024 | printk(KERN_WARNING "%s: Uhhuh.. could not read good fid from reg " |
| 2025 | "%04x (%04x %04x %04x)\n", dev->name, reg, val, val2, val3); |
| 2026 | return val; |
| 2027 | #else /* EXTRA_FID_READ_TESTS */ |
| 2028 | return HFA384X_INW(reg); |
| 2029 | #endif /* EXTRA_FID_READ_TESTS */ |
| 2030 | } |
| 2031 | |
| 2032 | |
| 2033 | /* Called only as a tasklet (software IRQ) */ |
| 2034 | static void prism2_rx(local_info_t *local) |
| 2035 | { |
| 2036 | struct net_device *dev = local->dev; |
| 2037 | int res, rx_pending = 0; |
| 2038 | u16 len, hdr_len, rxfid, status, macport; |
| 2039 | struct net_device_stats *stats; |
| 2040 | struct hfa384x_rx_frame rxdesc; |
| 2041 | struct sk_buff *skb = NULL; |
| 2042 | |
| 2043 | prism2_callback(local, PRISM2_CALLBACK_RX_START); |
| 2044 | stats = hostap_get_stats(dev); |
| 2045 | |
| 2046 | rxfid = prism2_read_fid_reg(dev, HFA384X_RXFID_OFF); |
| 2047 | #ifndef final_version |
| 2048 | if (rxfid == 0) { |
| 2049 | rxfid = HFA384X_INW(HFA384X_RXFID_OFF); |
| 2050 | printk(KERN_DEBUG "prism2_rx: rxfid=0 (next 0x%04x)\n", |
| 2051 | rxfid); |
| 2052 | if (rxfid == 0) { |
| 2053 | schedule_work(&local->reset_queue); |
| 2054 | goto rx_dropped; |
| 2055 | } |
| 2056 | /* try to continue with the new rxfid value */ |
| 2057 | } |
| 2058 | #endif |
| 2059 | |
| 2060 | spin_lock(&local->baplock); |
| 2061 | res = hfa384x_setup_bap(dev, BAP0, rxfid, 0); |
| 2062 | if (!res) |
| 2063 | res = hfa384x_from_bap(dev, BAP0, &rxdesc, sizeof(rxdesc)); |
| 2064 | |
| 2065 | if (res) { |
| 2066 | spin_unlock(&local->baplock); |
| 2067 | printk(KERN_DEBUG "%s: copy from BAP0 failed %d\n", dev->name, |
| 2068 | res); |
| 2069 | if (res == -ETIMEDOUT) { |
| 2070 | schedule_work(&local->reset_queue); |
| 2071 | } |
| 2072 | goto rx_dropped; |
| 2073 | } |
| 2074 | |
| 2075 | len = le16_to_cpu(rxdesc.data_len); |
| 2076 | hdr_len = sizeof(rxdesc); |
| 2077 | status = le16_to_cpu(rxdesc.status); |
| 2078 | macport = (status >> 8) & 0x07; |
| 2079 | |
| 2080 | /* Drop frames with too large reported payload length. Monitor mode |
| 2081 | * seems to sometimes pass frames (e.g., ctrl::ack) with signed and |
| 2082 | * negative value, so allow also values 65522 .. 65534 (-14 .. -2) for |
| 2083 | * macport 7 */ |
| 2084 | if (len > PRISM2_DATA_MAXLEN + 8 /* WEP */) { |
| 2085 | if (macport == 7 && local->iw_mode == IW_MODE_MONITOR) { |
| 2086 | if (len >= (u16) -14) { |
| 2087 | hdr_len -= 65535 - len; |
| 2088 | hdr_len--; |
| 2089 | } |
| 2090 | len = 0; |
| 2091 | } else { |
| 2092 | spin_unlock(&local->baplock); |
| 2093 | printk(KERN_DEBUG "%s: Received frame with invalid " |
| 2094 | "length 0x%04x\n", dev->name, len); |
| 2095 | hostap_dump_rx_header(dev->name, &rxdesc); |
| 2096 | goto rx_dropped; |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | skb = dev_alloc_skb(len + hdr_len); |
| 2101 | if (!skb) { |
| 2102 | spin_unlock(&local->baplock); |
| 2103 | printk(KERN_DEBUG "%s: RX failed to allocate skb\n", |
| 2104 | dev->name); |
| 2105 | goto rx_dropped; |
| 2106 | } |
| 2107 | skb->dev = dev; |
| 2108 | memcpy(skb_put(skb, hdr_len), &rxdesc, hdr_len); |
| 2109 | |
| 2110 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 2111 | if (len >= local->bus_master_threshold_rx) { |
| 2112 | unsigned long addr; |
| 2113 | |
| 2114 | hfa384x_events_no_bap1(dev); |
| 2115 | |
| 2116 | local->rx_skb = skb; |
| 2117 | /* Internal BAP0 offset points to the byte following rxdesc; |
| 2118 | * copy rest of the data using bus master */ |
| 2119 | addr = virt_to_phys(skb_put(skb, len)); |
| 2120 | HFA384X_OUTW((addr & 0xffff0000) >> 16, |
| 2121 | HFA384X_PCI_M0_ADDRH_OFF); |
| 2122 | HFA384X_OUTW(addr & 0x0000ffff, HFA384X_PCI_M0_ADDRL_OFF); |
| 2123 | if (len & 1) |
| 2124 | len++; |
| 2125 | HFA384X_OUTW(len / 2, HFA384X_PCI_M0_LEN_OFF); |
| 2126 | HFA384X_OUTW(HFA384X_PCI_CTL_FROM_BAP, HFA384X_PCI_M0_CTL_OFF); |
| 2127 | |
| 2128 | /* pci_bus_m1 event will be generated when data transfer is |
| 2129 | * complete and the frame will then be added to rx_list and |
| 2130 | * rx_tasklet is scheduled */ |
| 2131 | rx_pending = 1; |
| 2132 | |
| 2133 | /* Have to release baplock before returning, although BAP0 |
| 2134 | * should really not be used before DMA transfer has been |
| 2135 | * completed. */ |
| 2136 | spin_unlock(&local->baplock); |
| 2137 | } else |
| 2138 | #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */ |
| 2139 | { |
| 2140 | if (len > 0) |
| 2141 | res = hfa384x_from_bap(dev, BAP0, skb_put(skb, len), |
| 2142 | len); |
| 2143 | spin_unlock(&local->baplock); |
| 2144 | if (res) { |
| 2145 | printk(KERN_DEBUG "%s: RX failed to read " |
| 2146 | "frame data\n", dev->name); |
| 2147 | goto rx_dropped; |
| 2148 | } |
| 2149 | |
| 2150 | skb_queue_tail(&local->rx_list, skb); |
| 2151 | tasklet_schedule(&local->rx_tasklet); |
| 2152 | } |
| 2153 | |
| 2154 | rx_exit: |
| 2155 | prism2_callback(local, PRISM2_CALLBACK_RX_END); |
| 2156 | if (!rx_pending) { |
| 2157 | HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF); |
| 2158 | } |
| 2159 | |
| 2160 | return; |
| 2161 | |
| 2162 | rx_dropped: |
| 2163 | stats->rx_dropped++; |
| 2164 | if (skb) |
| 2165 | dev_kfree_skb(skb); |
| 2166 | goto rx_exit; |
| 2167 | } |
| 2168 | |
| 2169 | |
| 2170 | /* Called only as a tasklet (software IRQ) */ |
| 2171 | static void hostap_rx_skb(local_info_t *local, struct sk_buff *skb) |
| 2172 | { |
| 2173 | struct hfa384x_rx_frame *rxdesc; |
| 2174 | struct net_device *dev = skb->dev; |
| 2175 | struct hostap_80211_rx_status stats; |
| 2176 | int hdrlen, rx_hdrlen; |
| 2177 | |
| 2178 | rx_hdrlen = sizeof(*rxdesc); |
| 2179 | if (skb->len < sizeof(*rxdesc)) { |
| 2180 | /* Allow monitor mode to receive shorter frames */ |
| 2181 | if (local->iw_mode == IW_MODE_MONITOR && |
| 2182 | skb->len >= sizeof(*rxdesc) - 30) { |
| 2183 | rx_hdrlen = skb->len; |
| 2184 | } else { |
| 2185 | dev_kfree_skb(skb); |
| 2186 | return; |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | rxdesc = (struct hfa384x_rx_frame *) skb->data; |
| 2191 | |
| 2192 | if (local->frame_dump & PRISM2_DUMP_RX_HDR && |
| 2193 | skb->len >= sizeof(*rxdesc)) |
| 2194 | hostap_dump_rx_header(dev->name, rxdesc); |
| 2195 | |
| 2196 | if (le16_to_cpu(rxdesc->status) & HFA384X_RX_STATUS_FCSERR && |
| 2197 | (!local->monitor_allow_fcserr || |
| 2198 | local->iw_mode != IW_MODE_MONITOR)) |
| 2199 | goto drop; |
| 2200 | |
| 2201 | if (skb->len > PRISM2_DATA_MAXLEN) { |
| 2202 | printk(KERN_DEBUG "%s: RX: len(%d) > MAX(%d)\n", |
| 2203 | dev->name, skb->len, PRISM2_DATA_MAXLEN); |
| 2204 | goto drop; |
| 2205 | } |
| 2206 | |
| 2207 | stats.mac_time = le32_to_cpu(rxdesc->time); |
| 2208 | stats.signal = rxdesc->signal - local->rssi_to_dBm; |
| 2209 | stats.noise = rxdesc->silence - local->rssi_to_dBm; |
| 2210 | stats.rate = rxdesc->rate; |
| 2211 | |
| 2212 | /* Convert Prism2 RX structure into IEEE 802.11 header */ |
| 2213 | hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(rxdesc->frame_control)); |
| 2214 | if (hdrlen > rx_hdrlen) |
| 2215 | hdrlen = rx_hdrlen; |
| 2216 | |
| 2217 | memmove(skb_pull(skb, rx_hdrlen - hdrlen), |
| 2218 | &rxdesc->frame_control, hdrlen); |
| 2219 | |
| 2220 | hostap_80211_rx(dev, skb, &stats); |
| 2221 | return; |
| 2222 | |
| 2223 | drop: |
| 2224 | dev_kfree_skb(skb); |
| 2225 | } |
| 2226 | |
| 2227 | |
| 2228 | /* Called only as a tasklet (software IRQ) */ |
| 2229 | static void hostap_rx_tasklet(unsigned long data) |
| 2230 | { |
| 2231 | local_info_t *local = (local_info_t *) data; |
| 2232 | struct sk_buff *skb; |
| 2233 | |
| 2234 | while ((skb = skb_dequeue(&local->rx_list)) != NULL) |
| 2235 | hostap_rx_skb(local, skb); |
| 2236 | } |
| 2237 | |
| 2238 | |
| 2239 | /* Called only from hardware IRQ */ |
| 2240 | static void prism2_alloc_ev(struct net_device *dev) |
| 2241 | { |
| 2242 | struct hostap_interface *iface; |
| 2243 | local_info_t *local; |
| 2244 | int idx; |
| 2245 | u16 fid; |
| 2246 | |
| 2247 | iface = netdev_priv(dev); |
| 2248 | local = iface->local; |
| 2249 | |
| 2250 | fid = prism2_read_fid_reg(dev, HFA384X_ALLOCFID_OFF); |
| 2251 | |
| 2252 | PDEBUG(DEBUG_FID, "FID: interrupt: ALLOC - fid=0x%04x\n", fid); |
| 2253 | |
| 2254 | spin_lock(&local->txfidlock); |
| 2255 | idx = local->next_alloc; |
| 2256 | |
| 2257 | do { |
| 2258 | if (local->txfid[idx] == fid) { |
| 2259 | PDEBUG(DEBUG_FID, "FID: found matching txfid[%d]\n", |
| 2260 | idx); |
| 2261 | |
| 2262 | #ifndef final_version |
| 2263 | if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) |
| 2264 | printk("Already released txfid found at idx " |
| 2265 | "%d\n", idx); |
| 2266 | if (local->intransmitfid[idx] == PRISM2_TXFID_RESERVED) |
| 2267 | printk("Already reserved txfid found at idx " |
| 2268 | "%d\n", idx); |
| 2269 | #endif |
| 2270 | local->intransmitfid[idx] = PRISM2_TXFID_EMPTY; |
| 2271 | idx++; |
| 2272 | local->next_alloc = idx >= PRISM2_TXFID_COUNT ? 0 : |
| 2273 | idx; |
| 2274 | |
| 2275 | if (!test_bit(HOSTAP_BITS_TRANSMIT, &local->bits) && |
| 2276 | netif_queue_stopped(dev)) |
| 2277 | netif_wake_queue(dev); |
| 2278 | |
| 2279 | spin_unlock(&local->txfidlock); |
| 2280 | return; |
| 2281 | } |
| 2282 | |
| 2283 | idx++; |
| 2284 | if (idx >= PRISM2_TXFID_COUNT) |
| 2285 | idx = 0; |
| 2286 | } while (idx != local->next_alloc); |
| 2287 | |
| 2288 | printk(KERN_WARNING "%s: could not find matching txfid (0x%04x, new " |
| 2289 | "read 0x%04x) for alloc event\n", dev->name, fid, |
| 2290 | HFA384X_INW(HFA384X_ALLOCFID_OFF)); |
| 2291 | printk(KERN_DEBUG "TXFIDs:"); |
| 2292 | for (idx = 0; idx < PRISM2_TXFID_COUNT; idx++) |
| 2293 | printk(" %04x[%04x]", local->txfid[idx], |
| 2294 | local->intransmitfid[idx]); |
| 2295 | printk("\n"); |
| 2296 | spin_unlock(&local->txfidlock); |
| 2297 | |
| 2298 | /* FIX: should probably schedule reset; reference to one txfid was lost |
| 2299 | * completely.. Bad things will happen if we run out of txfids |
| 2300 | * Actually, this will cause netdev watchdog to notice TX timeout and |
| 2301 | * then card reset after all txfids have been leaked. */ |
| 2302 | } |
| 2303 | |
| 2304 | |
| 2305 | /* Called only as a tasklet (software IRQ) */ |
| 2306 | static void hostap_tx_callback(local_info_t *local, |
| 2307 | struct hfa384x_tx_frame *txdesc, int ok, |
| 2308 | char *payload) |
| 2309 | { |
| 2310 | u16 sw_support, hdrlen, len; |
| 2311 | struct sk_buff *skb; |
| 2312 | struct hostap_tx_callback_info *cb; |
| 2313 | |
| 2314 | /* Make sure that frame was from us. */ |
| 2315 | if (memcmp(txdesc->addr2, local->dev->dev_addr, ETH_ALEN)) { |
| 2316 | printk(KERN_DEBUG "%s: TX callback - foreign frame\n", |
| 2317 | local->dev->name); |
| 2318 | return; |
| 2319 | } |
| 2320 | |
| 2321 | sw_support = le16_to_cpu(txdesc->sw_support); |
| 2322 | |
| 2323 | spin_lock(&local->lock); |
| 2324 | cb = local->tx_callback; |
| 2325 | while (cb != NULL && cb->idx != sw_support) |
| 2326 | cb = cb->next; |
| 2327 | spin_unlock(&local->lock); |
| 2328 | |
| 2329 | if (cb == NULL) { |
| 2330 | printk(KERN_DEBUG "%s: could not find TX callback (idx %d)\n", |
| 2331 | local->dev->name, sw_support); |
| 2332 | return; |
| 2333 | } |
| 2334 | |
| 2335 | hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(txdesc->frame_control)); |
| 2336 | len = le16_to_cpu(txdesc->data_len); |
| 2337 | skb = dev_alloc_skb(hdrlen + len); |
| 2338 | if (skb == NULL) { |
| 2339 | printk(KERN_DEBUG "%s: hostap_tx_callback failed to allocate " |
| 2340 | "skb\n", local->dev->name); |
| 2341 | return; |
| 2342 | } |
| 2343 | |
| 2344 | memcpy(skb_put(skb, hdrlen), (void *) &txdesc->frame_control, hdrlen); |
| 2345 | if (payload) |
| 2346 | memcpy(skb_put(skb, len), payload, len); |
| 2347 | |
| 2348 | skb->dev = local->dev; |
| 2349 | skb->mac.raw = skb->data; |
| 2350 | |
| 2351 | cb->func(skb, ok, cb->data); |
| 2352 | } |
| 2353 | |
| 2354 | |
| 2355 | /* Called only as a tasklet (software IRQ) */ |
| 2356 | static int hostap_tx_compl_read(local_info_t *local, int error, |
| 2357 | struct hfa384x_tx_frame *txdesc, |
| 2358 | char **payload) |
| 2359 | { |
| 2360 | u16 fid, len; |
| 2361 | int res, ret = 0; |
| 2362 | struct net_device *dev = local->dev; |
| 2363 | |
| 2364 | fid = prism2_read_fid_reg(dev, HFA384X_TXCOMPLFID_OFF); |
| 2365 | |
| 2366 | PDEBUG(DEBUG_FID, "interrupt: TX (err=%d) - fid=0x%04x\n", fid, error); |
| 2367 | |
| 2368 | spin_lock(&local->baplock); |
| 2369 | res = hfa384x_setup_bap(dev, BAP0, fid, 0); |
| 2370 | if (!res) |
| 2371 | res = hfa384x_from_bap(dev, BAP0, txdesc, sizeof(*txdesc)); |
| 2372 | if (res) { |
| 2373 | PDEBUG(DEBUG_EXTRA, "%s: TX (err=%d) - fid=0x%04x - could not " |
| 2374 | "read txdesc\n", dev->name, error, fid); |
| 2375 | if (res == -ETIMEDOUT) { |
| 2376 | schedule_work(&local->reset_queue); |
| 2377 | } |
| 2378 | ret = -1; |
| 2379 | goto fail; |
| 2380 | } |
| 2381 | if (txdesc->sw_support) { |
| 2382 | len = le16_to_cpu(txdesc->data_len); |
| 2383 | if (len < PRISM2_DATA_MAXLEN) { |
| 2384 | *payload = (char *) kmalloc(len, GFP_ATOMIC); |
| 2385 | if (*payload == NULL || |
| 2386 | hfa384x_from_bap(dev, BAP0, *payload, len)) { |
| 2387 | PDEBUG(DEBUG_EXTRA, "%s: could not read TX " |
| 2388 | "frame payload\n", dev->name); |
| 2389 | kfree(*payload); |
| 2390 | *payload = NULL; |
| 2391 | ret = -1; |
| 2392 | goto fail; |
| 2393 | } |
| 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | fail: |
| 2398 | spin_unlock(&local->baplock); |
| 2399 | |
| 2400 | return ret; |
| 2401 | } |
| 2402 | |
| 2403 | |
| 2404 | /* Called only as a tasklet (software IRQ) */ |
| 2405 | static void prism2_tx_ev(local_info_t *local) |
| 2406 | { |
| 2407 | struct net_device *dev = local->dev; |
| 2408 | char *payload = NULL; |
| 2409 | struct hfa384x_tx_frame txdesc; |
| 2410 | |
| 2411 | if (hostap_tx_compl_read(local, 0, &txdesc, &payload)) |
| 2412 | goto fail; |
| 2413 | |
| 2414 | if (local->frame_dump & PRISM2_DUMP_TX_HDR) { |
| 2415 | PDEBUG(DEBUG_EXTRA, "%s: TX - status=0x%04x " |
| 2416 | "retry_count=%d tx_rate=%d seq_ctrl=%d " |
| 2417 | "duration_id=%d\n", |
| 2418 | dev->name, le16_to_cpu(txdesc.status), |
| 2419 | txdesc.retry_count, txdesc.tx_rate, |
| 2420 | le16_to_cpu(txdesc.seq_ctrl), |
| 2421 | le16_to_cpu(txdesc.duration_id)); |
| 2422 | } |
| 2423 | |
| 2424 | if (txdesc.sw_support) |
| 2425 | hostap_tx_callback(local, &txdesc, 1, payload); |
| 2426 | kfree(payload); |
| 2427 | |
| 2428 | fail: |
| 2429 | HFA384X_OUTW(HFA384X_EV_TX, HFA384X_EVACK_OFF); |
| 2430 | } |
| 2431 | |
| 2432 | |
| 2433 | /* Called only as a tasklet (software IRQ) */ |
| 2434 | static void hostap_sta_tx_exc_tasklet(unsigned long data) |
| 2435 | { |
| 2436 | local_info_t *local = (local_info_t *) data; |
| 2437 | struct sk_buff *skb; |
| 2438 | |
| 2439 | while ((skb = skb_dequeue(&local->sta_tx_exc_list)) != NULL) { |
| 2440 | struct hfa384x_tx_frame *txdesc = |
| 2441 | (struct hfa384x_tx_frame *) skb->data; |
| 2442 | |
| 2443 | if (skb->len >= sizeof(*txdesc)) { |
| 2444 | /* Convert Prism2 RX structure into IEEE 802.11 header |
| 2445 | */ |
| 2446 | u16 fc = le16_to_cpu(txdesc->frame_control); |
| 2447 | int hdrlen = hostap_80211_get_hdrlen(fc); |
| 2448 | memmove(skb_pull(skb, sizeof(*txdesc) - hdrlen), |
| 2449 | &txdesc->frame_control, hdrlen); |
| 2450 | |
| 2451 | hostap_handle_sta_tx_exc(local, skb); |
| 2452 | } |
| 2453 | dev_kfree_skb(skb); |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | |
| 2458 | /* Called only as a tasklet (software IRQ) */ |
| 2459 | static void prism2_txexc(local_info_t *local) |
| 2460 | { |
| 2461 | struct net_device *dev = local->dev; |
| 2462 | u16 status, fc; |
| 2463 | int show_dump, res; |
| 2464 | char *payload = NULL; |
| 2465 | struct hfa384x_tx_frame txdesc; |
| 2466 | |
| 2467 | show_dump = local->frame_dump & PRISM2_DUMP_TXEXC_HDR; |
| 2468 | local->stats.tx_errors++; |
| 2469 | |
| 2470 | res = hostap_tx_compl_read(local, 1, &txdesc, &payload); |
| 2471 | HFA384X_OUTW(HFA384X_EV_TXEXC, HFA384X_EVACK_OFF); |
| 2472 | if (res) |
| 2473 | return; |
| 2474 | |
| 2475 | status = le16_to_cpu(txdesc.status); |
| 2476 | |
| 2477 | /* We produce a TXDROP event only for retry or lifetime |
| 2478 | * exceeded, because that's the only status that really mean |
| 2479 | * that this particular node went away. |
| 2480 | * Other errors means that *we* screwed up. - Jean II */ |
| 2481 | if (status & (HFA384X_TX_STATUS_RETRYERR | HFA384X_TX_STATUS_AGEDERR)) |
| 2482 | { |
| 2483 | union iwreq_data wrqu; |
| 2484 | |
| 2485 | /* Copy 802.11 dest address. */ |
| 2486 | memcpy(wrqu.addr.sa_data, txdesc.addr1, ETH_ALEN); |
| 2487 | wrqu.addr.sa_family = ARPHRD_ETHER; |
| 2488 | wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL); |
| 2489 | } else |
| 2490 | show_dump = 1; |
| 2491 | |
| 2492 | if (local->iw_mode == IW_MODE_MASTER || |
| 2493 | local->iw_mode == IW_MODE_REPEAT || |
| 2494 | local->wds_type & HOSTAP_WDS_AP_CLIENT) { |
| 2495 | struct sk_buff *skb; |
| 2496 | skb = dev_alloc_skb(sizeof(txdesc)); |
| 2497 | if (skb) { |
| 2498 | memcpy(skb_put(skb, sizeof(txdesc)), &txdesc, |
| 2499 | sizeof(txdesc)); |
| 2500 | skb_queue_tail(&local->sta_tx_exc_list, skb); |
| 2501 | tasklet_schedule(&local->sta_tx_exc_tasklet); |
| 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | if (txdesc.sw_support) |
| 2506 | hostap_tx_callback(local, &txdesc, 0, payload); |
| 2507 | kfree(payload); |
| 2508 | |
| 2509 | if (!show_dump) |
| 2510 | return; |
| 2511 | |
| 2512 | PDEBUG(DEBUG_EXTRA, "%s: TXEXC - status=0x%04x (%s%s%s%s)" |
| 2513 | " tx_control=%04x\n", |
| 2514 | dev->name, status, |
| 2515 | status & HFA384X_TX_STATUS_RETRYERR ? "[RetryErr]" : "", |
| 2516 | status & HFA384X_TX_STATUS_AGEDERR ? "[AgedErr]" : "", |
| 2517 | status & HFA384X_TX_STATUS_DISCON ? "[Discon]" : "", |
| 2518 | status & HFA384X_TX_STATUS_FORMERR ? "[FormErr]" : "", |
| 2519 | le16_to_cpu(txdesc.tx_control)); |
| 2520 | |
| 2521 | fc = le16_to_cpu(txdesc.frame_control); |
| 2522 | PDEBUG(DEBUG_EXTRA, " retry_count=%d tx_rate=%d fc=0x%04x " |
| 2523 | "(%s%s%s::%d%s%s)\n", |
| 2524 | txdesc.retry_count, txdesc.tx_rate, fc, |
Jouni Malinen | ebed67d | 2005-07-30 20:43:19 -0700 | [diff] [blame] | 2525 | HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT ? "Mgmt" : "", |
| 2526 | HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_CTRL ? "Ctrl" : "", |
| 2527 | HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA ? "Data" : "", |
| 2528 | HOSTAP_FC_GET_STYPE(fc), |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 2529 | fc & WLAN_FC_TODS ? " ToDS" : "", |
| 2530 | fc & WLAN_FC_FROMDS ? " FromDS" : ""); |
| 2531 | PDEBUG(DEBUG_EXTRA, " A1=" MACSTR " A2=" MACSTR " A3=" |
| 2532 | MACSTR " A4=" MACSTR "\n", |
| 2533 | MAC2STR(txdesc.addr1), MAC2STR(txdesc.addr2), |
| 2534 | MAC2STR(txdesc.addr3), MAC2STR(txdesc.addr4)); |
| 2535 | } |
| 2536 | |
| 2537 | |
| 2538 | /* Called only as a tasklet (software IRQ) */ |
| 2539 | static void hostap_info_tasklet(unsigned long data) |
| 2540 | { |
| 2541 | local_info_t *local = (local_info_t *) data; |
| 2542 | struct sk_buff *skb; |
| 2543 | |
| 2544 | while ((skb = skb_dequeue(&local->info_list)) != NULL) { |
| 2545 | hostap_info_process(local, skb); |
| 2546 | dev_kfree_skb(skb); |
| 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | |
| 2551 | /* Called only as a tasklet (software IRQ) */ |
| 2552 | static void prism2_info(local_info_t *local) |
| 2553 | { |
| 2554 | struct net_device *dev = local->dev; |
| 2555 | u16 fid; |
| 2556 | int res, left; |
| 2557 | struct hfa384x_info_frame info; |
| 2558 | struct sk_buff *skb; |
| 2559 | |
| 2560 | fid = HFA384X_INW(HFA384X_INFOFID_OFF); |
| 2561 | |
| 2562 | spin_lock(&local->baplock); |
| 2563 | res = hfa384x_setup_bap(dev, BAP0, fid, 0); |
| 2564 | if (!res) |
| 2565 | res = hfa384x_from_bap(dev, BAP0, &info, sizeof(info)); |
| 2566 | if (res) { |
| 2567 | spin_unlock(&local->baplock); |
| 2568 | printk(KERN_DEBUG "Could not get info frame (fid=0x%04x)\n", |
| 2569 | fid); |
| 2570 | if (res == -ETIMEDOUT) { |
| 2571 | schedule_work(&local->reset_queue); |
| 2572 | } |
| 2573 | goto out; |
| 2574 | } |
| 2575 | |
| 2576 | le16_to_cpus(&info.len); |
| 2577 | le16_to_cpus(&info.type); |
| 2578 | left = (info.len - 1) * 2; |
| 2579 | |
| 2580 | if (info.len & 0x8000 || info.len == 0 || left > 2060) { |
| 2581 | /* data register seems to give 0x8000 in some error cases even |
| 2582 | * though busy bit is not set in offset register; |
| 2583 | * in addition, length must be at least 1 due to type field */ |
| 2584 | spin_unlock(&local->baplock); |
| 2585 | printk(KERN_DEBUG "%s: Received info frame with invalid " |
| 2586 | "length 0x%04x (type 0x%04x)\n", dev->name, info.len, |
| 2587 | info.type); |
| 2588 | goto out; |
| 2589 | } |
| 2590 | |
| 2591 | skb = dev_alloc_skb(sizeof(info) + left); |
| 2592 | if (skb == NULL) { |
| 2593 | spin_unlock(&local->baplock); |
| 2594 | printk(KERN_DEBUG "%s: Could not allocate skb for info " |
| 2595 | "frame\n", dev->name); |
| 2596 | goto out; |
| 2597 | } |
| 2598 | |
| 2599 | memcpy(skb_put(skb, sizeof(info)), &info, sizeof(info)); |
| 2600 | if (left > 0 && hfa384x_from_bap(dev, BAP0, skb_put(skb, left), left)) |
| 2601 | { |
| 2602 | spin_unlock(&local->baplock); |
| 2603 | printk(KERN_WARNING "%s: Info frame read failed (fid=0x%04x, " |
| 2604 | "len=0x%04x, type=0x%04x\n", |
| 2605 | dev->name, fid, info.len, info.type); |
| 2606 | dev_kfree_skb(skb); |
| 2607 | goto out; |
| 2608 | } |
| 2609 | spin_unlock(&local->baplock); |
| 2610 | |
| 2611 | skb_queue_tail(&local->info_list, skb); |
| 2612 | tasklet_schedule(&local->info_tasklet); |
| 2613 | |
| 2614 | out: |
| 2615 | HFA384X_OUTW(HFA384X_EV_INFO, HFA384X_EVACK_OFF); |
| 2616 | } |
| 2617 | |
| 2618 | |
| 2619 | /* Called only as a tasklet (software IRQ) */ |
| 2620 | static void hostap_bap_tasklet(unsigned long data) |
| 2621 | { |
| 2622 | local_info_t *local = (local_info_t *) data; |
| 2623 | struct net_device *dev = local->dev; |
| 2624 | u16 ev; |
| 2625 | int frames = 30; |
| 2626 | |
| 2627 | if (local->func->card_present && !local->func->card_present(local)) |
| 2628 | return; |
| 2629 | |
| 2630 | set_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits); |
| 2631 | |
| 2632 | /* Process all pending BAP events without generating new interrupts |
| 2633 | * for them */ |
| 2634 | while (frames-- > 0) { |
| 2635 | ev = HFA384X_INW(HFA384X_EVSTAT_OFF); |
| 2636 | if (ev == 0xffff || !(ev & HFA384X_BAP0_EVENTS)) |
| 2637 | break; |
| 2638 | if (ev & HFA384X_EV_RX) |
| 2639 | prism2_rx(local); |
| 2640 | if (ev & HFA384X_EV_INFO) |
| 2641 | prism2_info(local); |
| 2642 | if (ev & HFA384X_EV_TX) |
| 2643 | prism2_tx_ev(local); |
| 2644 | if (ev & HFA384X_EV_TXEXC) |
| 2645 | prism2_txexc(local); |
| 2646 | } |
| 2647 | |
| 2648 | set_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits); |
| 2649 | clear_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits); |
| 2650 | |
| 2651 | /* Enable interrupts for new BAP events */ |
| 2652 | hfa384x_events_all(dev); |
| 2653 | clear_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits); |
| 2654 | } |
| 2655 | |
| 2656 | |
| 2657 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 2658 | /* Called only from hardware IRQ */ |
| 2659 | static void prism2_bus_master_ev(struct net_device *dev, int bap) |
| 2660 | { |
| 2661 | struct hostap_interface *iface; |
| 2662 | local_info_t *local; |
| 2663 | |
| 2664 | iface = netdev_priv(dev); |
| 2665 | local = iface->local; |
| 2666 | |
| 2667 | if (bap == BAP1) { |
| 2668 | /* FIX: frame payload was DMA'd to skb->data; might need to |
| 2669 | * invalidate data cache for that memory area */ |
| 2670 | skb_queue_tail(&local->rx_list, local->rx_skb); |
| 2671 | tasklet_schedule(&local->rx_tasklet); |
| 2672 | HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF); |
| 2673 | } else { |
| 2674 | if (prism2_transmit(dev, local->bus_m0_tx_idx)) { |
| 2675 | printk(KERN_DEBUG "%s: prism2_transmit() failed " |
| 2676 | "when called from bus master event\n", |
| 2677 | dev->name); |
| 2678 | local->intransmitfid[local->bus_m0_tx_idx] = |
| 2679 | PRISM2_TXFID_EMPTY; |
| 2680 | schedule_work(&local->reset_queue); |
| 2681 | } |
| 2682 | } |
| 2683 | } |
| 2684 | #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */ |
| 2685 | |
| 2686 | |
| 2687 | /* Called only from hardware IRQ */ |
| 2688 | static void prism2_infdrop(struct net_device *dev) |
| 2689 | { |
| 2690 | static unsigned long last_inquire = 0; |
| 2691 | |
| 2692 | PDEBUG(DEBUG_EXTRA, "%s: INFDROP event\n", dev->name); |
| 2693 | |
| 2694 | /* some firmware versions seem to get stuck with |
| 2695 | * full CommTallies in high traffic load cases; every |
| 2696 | * packet will then cause INFDROP event and CommTallies |
| 2697 | * info frame will not be sent automatically. Try to |
| 2698 | * get out of this state by inquiring CommTallies. */ |
| 2699 | if (!last_inquire || time_after(jiffies, last_inquire + HZ)) { |
| 2700 | hfa384x_cmd_callback(dev, HFA384X_CMDCODE_INQUIRE, |
Pavel Roskin | b15eff2 | 2005-07-30 12:50:05 -0700 | [diff] [blame] | 2701 | HFA384X_INFO_COMMTALLIES, NULL, 0); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 2702 | last_inquire = jiffies; |
| 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | |
| 2707 | /* Called only from hardware IRQ */ |
| 2708 | static void prism2_ev_tick(struct net_device *dev) |
| 2709 | { |
| 2710 | struct hostap_interface *iface; |
| 2711 | local_info_t *local; |
| 2712 | u16 evstat, inten; |
| 2713 | static int prev_stuck = 0; |
| 2714 | |
| 2715 | iface = netdev_priv(dev); |
| 2716 | local = iface->local; |
| 2717 | |
| 2718 | if (time_after(jiffies, local->last_tick_timer + 5 * HZ) && |
| 2719 | local->last_tick_timer) { |
| 2720 | evstat = HFA384X_INW(HFA384X_EVSTAT_OFF); |
| 2721 | inten = HFA384X_INW(HFA384X_INTEN_OFF); |
| 2722 | if (!prev_stuck) { |
| 2723 | printk(KERN_INFO "%s: SW TICK stuck? " |
| 2724 | "bits=0x%lx EvStat=%04x IntEn=%04x\n", |
| 2725 | dev->name, local->bits, evstat, inten); |
| 2726 | } |
| 2727 | local->sw_tick_stuck++; |
| 2728 | if ((evstat & HFA384X_BAP0_EVENTS) && |
| 2729 | (inten & HFA384X_BAP0_EVENTS)) { |
| 2730 | printk(KERN_INFO "%s: trying to recover from IRQ " |
| 2731 | "hang\n", dev->name); |
| 2732 | hfa384x_events_no_bap0(dev); |
| 2733 | } |
| 2734 | prev_stuck = 1; |
| 2735 | } else |
| 2736 | prev_stuck = 0; |
| 2737 | } |
| 2738 | |
| 2739 | |
| 2740 | /* Called only from hardware IRQ */ |
| 2741 | static inline void prism2_check_magic(local_info_t *local) |
| 2742 | { |
| 2743 | /* at least PCI Prism2.5 with bus mastering seems to sometimes |
| 2744 | * return 0x0000 in SWSUPPORT0 for unknown reason, but re-reading the |
| 2745 | * register once or twice seems to get the correct value.. PCI cards |
| 2746 | * cannot anyway be removed during normal operation, so there is not |
| 2747 | * really any need for this verification with them. */ |
| 2748 | |
| 2749 | #ifndef PRISM2_PCI |
| 2750 | #ifndef final_version |
| 2751 | static unsigned long last_magic_err = 0; |
| 2752 | struct net_device *dev = local->dev; |
| 2753 | |
| 2754 | if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) { |
| 2755 | if (!local->hw_ready) |
| 2756 | return; |
| 2757 | HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF); |
| 2758 | if (time_after(jiffies, last_magic_err + 10 * HZ)) { |
| 2759 | printk("%s: Interrupt, but SWSUPPORT0 does not match: " |
| 2760 | "%04X != %04X - card removed?\n", dev->name, |
| 2761 | HFA384X_INW(HFA384X_SWSUPPORT0_OFF), |
| 2762 | HFA384X_MAGIC); |
| 2763 | last_magic_err = jiffies; |
| 2764 | } else if (net_ratelimit()) { |
| 2765 | printk(KERN_DEBUG "%s: interrupt - SWSUPPORT0=%04x " |
| 2766 | "MAGIC=%04x\n", dev->name, |
| 2767 | HFA384X_INW(HFA384X_SWSUPPORT0_OFF), |
| 2768 | HFA384X_MAGIC); |
| 2769 | } |
| 2770 | if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != 0xffff) |
| 2771 | schedule_work(&local->reset_queue); |
| 2772 | return; |
| 2773 | } |
| 2774 | #endif /* final_version */ |
| 2775 | #endif /* !PRISM2_PCI */ |
| 2776 | } |
| 2777 | |
| 2778 | |
| 2779 | /* Called only from hardware IRQ */ |
| 2780 | static irqreturn_t prism2_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
| 2781 | { |
| 2782 | struct net_device *dev = (struct net_device *) dev_id; |
| 2783 | struct hostap_interface *iface; |
| 2784 | local_info_t *local; |
| 2785 | int events = 0; |
| 2786 | u16 ev; |
| 2787 | |
| 2788 | iface = netdev_priv(dev); |
| 2789 | local = iface->local; |
| 2790 | |
| 2791 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 0); |
| 2792 | |
| 2793 | if (local->func->card_present && !local->func->card_present(local)) { |
| 2794 | if (net_ratelimit()) { |
| 2795 | printk(KERN_DEBUG "%s: Interrupt, but dev not OK\n", |
| 2796 | dev->name); |
| 2797 | } |
| 2798 | return IRQ_HANDLED; |
| 2799 | } |
| 2800 | |
| 2801 | prism2_check_magic(local); |
| 2802 | |
| 2803 | for (;;) { |
| 2804 | ev = HFA384X_INW(HFA384X_EVSTAT_OFF); |
| 2805 | if (ev == 0xffff) { |
| 2806 | if (local->shutdown) |
| 2807 | return IRQ_HANDLED; |
| 2808 | HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF); |
| 2809 | printk(KERN_DEBUG "%s: prism2_interrupt: ev=0xffff\n", |
| 2810 | dev->name); |
| 2811 | return IRQ_HANDLED; |
| 2812 | } |
| 2813 | |
| 2814 | ev &= HFA384X_INW(HFA384X_INTEN_OFF); |
| 2815 | if (ev == 0) |
| 2816 | break; |
| 2817 | |
| 2818 | if (ev & HFA384X_EV_CMD) { |
| 2819 | prism2_cmd_ev(dev); |
| 2820 | } |
| 2821 | |
| 2822 | /* Above events are needed even before hw is ready, but other |
| 2823 | * events should be skipped during initialization. This may |
| 2824 | * change for AllocEv if allocate_fid is implemented without |
| 2825 | * busy waiting. */ |
| 2826 | if (!local->hw_ready || local->hw_resetting || |
| 2827 | !local->dev_enabled) { |
| 2828 | ev = HFA384X_INW(HFA384X_EVSTAT_OFF); |
| 2829 | if (ev & HFA384X_EV_CMD) |
| 2830 | goto next_event; |
| 2831 | if ((ev & HFA384X_EVENT_MASK) == 0) |
| 2832 | return IRQ_HANDLED; |
| 2833 | if (local->dev_enabled && (ev & ~HFA384X_EV_TICK) && |
| 2834 | net_ratelimit()) { |
| 2835 | printk(KERN_DEBUG "%s: prism2_interrupt: hw " |
| 2836 | "not ready; skipping events 0x%04x " |
| 2837 | "(IntEn=0x%04x)%s%s%s\n", |
| 2838 | dev->name, ev, |
| 2839 | HFA384X_INW(HFA384X_INTEN_OFF), |
| 2840 | !local->hw_ready ? " (!hw_ready)" : "", |
| 2841 | local->hw_resetting ? |
| 2842 | " (hw_resetting)" : "", |
| 2843 | !local->dev_enabled ? |
| 2844 | " (!dev_enabled)" : ""); |
| 2845 | } |
| 2846 | HFA384X_OUTW(ev, HFA384X_EVACK_OFF); |
| 2847 | return IRQ_HANDLED; |
| 2848 | } |
| 2849 | |
| 2850 | if (ev & HFA384X_EV_TICK) { |
| 2851 | prism2_ev_tick(dev); |
| 2852 | HFA384X_OUTW(HFA384X_EV_TICK, HFA384X_EVACK_OFF); |
| 2853 | } |
| 2854 | |
| 2855 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 2856 | if (ev & HFA384X_EV_PCI_M0) { |
| 2857 | prism2_bus_master_ev(dev, BAP0); |
| 2858 | HFA384X_OUTW(HFA384X_EV_PCI_M0, HFA384X_EVACK_OFF); |
| 2859 | } |
| 2860 | |
| 2861 | if (ev & HFA384X_EV_PCI_M1) { |
| 2862 | /* previous RX has been copied can be ACKed now */ |
| 2863 | HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF); |
| 2864 | |
| 2865 | prism2_bus_master_ev(dev, BAP1); |
| 2866 | HFA384X_OUTW(HFA384X_EV_PCI_M1, HFA384X_EVACK_OFF); |
| 2867 | } |
| 2868 | #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */ |
| 2869 | |
| 2870 | if (ev & HFA384X_EV_ALLOC) { |
| 2871 | prism2_alloc_ev(dev); |
| 2872 | HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF); |
| 2873 | } |
| 2874 | |
| 2875 | /* Reading data from the card is quite time consuming, so do it |
| 2876 | * in tasklets. TX, TXEXC, RX, and INFO events will be ACKed |
| 2877 | * and unmasked after needed data has been read completely. */ |
| 2878 | if (ev & HFA384X_BAP0_EVENTS) { |
| 2879 | hfa384x_events_no_bap0(dev); |
| 2880 | tasklet_schedule(&local->bap_tasklet); |
| 2881 | } |
| 2882 | |
| 2883 | #ifndef final_version |
| 2884 | if (ev & HFA384X_EV_WTERR) { |
| 2885 | PDEBUG(DEBUG_EXTRA, "%s: WTERR event\n", dev->name); |
| 2886 | HFA384X_OUTW(HFA384X_EV_WTERR, HFA384X_EVACK_OFF); |
| 2887 | } |
| 2888 | #endif /* final_version */ |
| 2889 | |
| 2890 | if (ev & HFA384X_EV_INFDROP) { |
| 2891 | prism2_infdrop(dev); |
| 2892 | HFA384X_OUTW(HFA384X_EV_INFDROP, HFA384X_EVACK_OFF); |
| 2893 | } |
| 2894 | |
| 2895 | next_event: |
| 2896 | events++; |
| 2897 | if (events >= PRISM2_MAX_INTERRUPT_EVENTS) { |
| 2898 | PDEBUG(DEBUG_EXTRA, "prism2_interrupt: >%d events " |
| 2899 | "(EvStat=0x%04x)\n", |
| 2900 | PRISM2_MAX_INTERRUPT_EVENTS, |
| 2901 | HFA384X_INW(HFA384X_EVSTAT_OFF)); |
| 2902 | break; |
| 2903 | } |
| 2904 | } |
| 2905 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 1); |
| 2906 | return IRQ_RETVAL(events); |
| 2907 | } |
| 2908 | |
| 2909 | |
| 2910 | static void prism2_check_sta_fw_version(local_info_t *local) |
| 2911 | { |
| 2912 | struct hfa384x_comp_ident comp; |
| 2913 | int id, variant, major, minor; |
| 2914 | |
| 2915 | if (hfa384x_get_rid(local->dev, HFA384X_RID_STAID, |
| 2916 | &comp, sizeof(comp), 1) < 0) |
| 2917 | return; |
| 2918 | |
| 2919 | local->fw_ap = 0; |
| 2920 | id = le16_to_cpu(comp.id); |
| 2921 | if (id != HFA384X_COMP_ID_STA) { |
| 2922 | if (id == HFA384X_COMP_ID_FW_AP) |
| 2923 | local->fw_ap = 1; |
| 2924 | return; |
| 2925 | } |
| 2926 | |
| 2927 | major = __le16_to_cpu(comp.major); |
| 2928 | minor = __le16_to_cpu(comp.minor); |
| 2929 | variant = __le16_to_cpu(comp.variant); |
| 2930 | local->sta_fw_ver = PRISM2_FW_VER(major, minor, variant); |
| 2931 | |
| 2932 | /* Station firmware versions before 1.4.x seem to have a bug in |
| 2933 | * firmware-based WEP encryption when using Host AP mode, so use |
| 2934 | * host_encrypt as a default for them. Firmware version 1.4.9 is the |
| 2935 | * first one that has been seen to produce correct encryption, but the |
| 2936 | * bug might be fixed before that (although, at least 1.4.2 is broken). |
| 2937 | */ |
| 2938 | local->fw_encrypt_ok = local->sta_fw_ver >= PRISM2_FW_VER(1,4,9); |
| 2939 | |
| 2940 | if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt && |
| 2941 | !local->fw_encrypt_ok) { |
| 2942 | printk(KERN_DEBUG "%s: defaulting to host-based encryption as " |
| 2943 | "a workaround for firmware bug in Host AP mode WEP\n", |
| 2944 | local->dev->name); |
| 2945 | local->host_encrypt = 1; |
| 2946 | } |
| 2947 | |
| 2948 | /* IEEE 802.11 standard compliant WDS frames (4 addresses) were broken |
| 2949 | * in station firmware versions before 1.5.x. With these versions, the |
| 2950 | * driver uses a workaround with bogus frame format (4th address after |
| 2951 | * the payload). This is not compatible with other AP devices. Since |
| 2952 | * the firmware bug is fixed in the latest station firmware versions, |
| 2953 | * automatically enable standard compliant mode for cards using station |
| 2954 | * firmware version 1.5.0 or newer. */ |
| 2955 | if (local->sta_fw_ver >= PRISM2_FW_VER(1,5,0)) |
| 2956 | local->wds_type |= HOSTAP_WDS_STANDARD_FRAME; |
| 2957 | else { |
| 2958 | printk(KERN_DEBUG "%s: defaulting to bogus WDS frame as a " |
| 2959 | "workaround for firmware bug in Host AP mode WDS\n", |
| 2960 | local->dev->name); |
| 2961 | } |
| 2962 | |
| 2963 | hostap_check_sta_fw_version(local->ap, local->sta_fw_ver); |
| 2964 | } |
| 2965 | |
| 2966 | |
| 2967 | static void prism2_crypt_deinit_entries(local_info_t *local, int force) |
| 2968 | { |
| 2969 | struct list_head *ptr, *n; |
Jouni Malinen | 62fe7e3 | 2005-07-30 20:43:20 -0700 | [diff] [blame] | 2970 | struct ieee80211_crypt_data *entry; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 2971 | |
| 2972 | for (ptr = local->crypt_deinit_list.next, n = ptr->next; |
| 2973 | ptr != &local->crypt_deinit_list; ptr = n, n = ptr->next) { |
Jouni Malinen | 62fe7e3 | 2005-07-30 20:43:20 -0700 | [diff] [blame] | 2974 | entry = list_entry(ptr, struct ieee80211_crypt_data, list); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 2975 | |
| 2976 | if (atomic_read(&entry->refcnt) != 0 && !force) |
| 2977 | continue; |
| 2978 | |
| 2979 | list_del(ptr); |
| 2980 | |
| 2981 | if (entry->ops) |
| 2982 | entry->ops->deinit(entry->priv); |
| 2983 | kfree(entry); |
| 2984 | } |
| 2985 | } |
| 2986 | |
| 2987 | |
| 2988 | static void prism2_crypt_deinit_handler(unsigned long data) |
| 2989 | { |
| 2990 | local_info_t *local = (local_info_t *) data; |
| 2991 | unsigned long flags; |
| 2992 | |
| 2993 | spin_lock_irqsave(&local->lock, flags); |
| 2994 | prism2_crypt_deinit_entries(local, 0); |
| 2995 | if (!list_empty(&local->crypt_deinit_list)) { |
| 2996 | printk(KERN_DEBUG "%s: entries remaining in delayed crypt " |
| 2997 | "deletion list\n", local->dev->name); |
| 2998 | local->crypt_deinit_timer.expires = jiffies + HZ; |
| 2999 | add_timer(&local->crypt_deinit_timer); |
| 3000 | } |
| 3001 | spin_unlock_irqrestore(&local->lock, flags); |
| 3002 | |
| 3003 | } |
| 3004 | |
| 3005 | |
| 3006 | static void hostap_passive_scan(unsigned long data) |
| 3007 | { |
| 3008 | local_info_t *local = (local_info_t *) data; |
| 3009 | struct net_device *dev = local->dev; |
| 3010 | u16 channel; |
| 3011 | |
| 3012 | if (local->passive_scan_interval <= 0) |
| 3013 | return; |
| 3014 | |
| 3015 | if (local->passive_scan_state == PASSIVE_SCAN_LISTEN) { |
| 3016 | int max_tries = 16; |
| 3017 | |
| 3018 | /* Even though host system does not really know when the WLAN |
| 3019 | * MAC is sending frames, try to avoid changing channels for |
| 3020 | * passive scanning when a host-generated frame is being |
| 3021 | * transmitted */ |
| 3022 | if (test_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) { |
| 3023 | printk(KERN_DEBUG "%s: passive scan detected pending " |
| 3024 | "TX - delaying\n", dev->name); |
| 3025 | local->passive_scan_timer.expires = jiffies + HZ / 10; |
| 3026 | add_timer(&local->passive_scan_timer); |
| 3027 | return; |
| 3028 | } |
| 3029 | |
| 3030 | do { |
| 3031 | local->passive_scan_channel++; |
| 3032 | if (local->passive_scan_channel > 14) |
| 3033 | local->passive_scan_channel = 1; |
| 3034 | max_tries--; |
| 3035 | } while (!(local->channel_mask & |
| 3036 | (1 << (local->passive_scan_channel - 1))) && |
| 3037 | max_tries > 0); |
| 3038 | |
| 3039 | if (max_tries == 0) { |
| 3040 | printk(KERN_INFO "%s: no allowed passive scan channels" |
| 3041 | " found\n", dev->name); |
| 3042 | return; |
| 3043 | } |
| 3044 | |
| 3045 | printk(KERN_DEBUG "%s: passive scan channel %d\n", |
| 3046 | dev->name, local->passive_scan_channel); |
| 3047 | channel = local->passive_scan_channel; |
| 3048 | local->passive_scan_state = PASSIVE_SCAN_WAIT; |
| 3049 | local->passive_scan_timer.expires = jiffies + HZ / 10; |
| 3050 | } else { |
| 3051 | channel = local->channel; |
| 3052 | local->passive_scan_state = PASSIVE_SCAN_LISTEN; |
| 3053 | local->passive_scan_timer.expires = jiffies + |
| 3054 | local->passive_scan_interval * HZ; |
| 3055 | } |
| 3056 | |
| 3057 | if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_TEST | |
| 3058 | (HFA384X_TEST_CHANGE_CHANNEL << 8), |
Pavel Roskin | b15eff2 | 2005-07-30 12:50:05 -0700 | [diff] [blame] | 3059 | channel, NULL, 0)) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 3060 | printk(KERN_ERR "%s: passive scan channel set %d " |
| 3061 | "failed\n", dev->name, channel); |
| 3062 | |
| 3063 | add_timer(&local->passive_scan_timer); |
| 3064 | } |
| 3065 | |
| 3066 | |
| 3067 | /* Called only as a scheduled task when communications quality values should |
| 3068 | * be updated. */ |
| 3069 | static void handle_comms_qual_update(void *data) |
| 3070 | { |
| 3071 | local_info_t *local = data; |
| 3072 | prism2_update_comms_qual(local->dev); |
| 3073 | } |
| 3074 | |
| 3075 | |
| 3076 | /* Software watchdog - called as a timer. Hardware interrupt (Tick event) is |
| 3077 | * used to monitor that local->last_tick_timer is being updated. If not, |
| 3078 | * interrupt busy-loop is assumed and driver tries to recover by masking out |
| 3079 | * some events. */ |
| 3080 | static void hostap_tick_timer(unsigned long data) |
| 3081 | { |
| 3082 | static unsigned long last_inquire = 0; |
| 3083 | local_info_t *local = (local_info_t *) data; |
| 3084 | local->last_tick_timer = jiffies; |
| 3085 | |
| 3086 | /* Inquire CommTallies every 10 seconds to keep the statistics updated |
| 3087 | * more often during low load and when using 32-bit tallies. */ |
| 3088 | if ((!last_inquire || time_after(jiffies, last_inquire + 10 * HZ)) && |
| 3089 | !local->hw_downloading && local->hw_ready && |
| 3090 | !local->hw_resetting && local->dev_enabled) { |
| 3091 | hfa384x_cmd_callback(local->dev, HFA384X_CMDCODE_INQUIRE, |
Pavel Roskin | b15eff2 | 2005-07-30 12:50:05 -0700 | [diff] [blame] | 3092 | HFA384X_INFO_COMMTALLIES, NULL, 0); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 3093 | last_inquire = jiffies; |
| 3094 | } |
| 3095 | |
| 3096 | if ((local->last_comms_qual_update == 0 || |
| 3097 | time_after(jiffies, local->last_comms_qual_update + 10 * HZ)) && |
| 3098 | (local->iw_mode == IW_MODE_INFRA || |
| 3099 | local->iw_mode == IW_MODE_ADHOC)) { |
| 3100 | schedule_work(&local->comms_qual_update); |
| 3101 | } |
| 3102 | |
| 3103 | local->tick_timer.expires = jiffies + 2 * HZ; |
| 3104 | add_timer(&local->tick_timer); |
| 3105 | } |
| 3106 | |
| 3107 | |
| 3108 | #ifndef PRISM2_NO_PROCFS_DEBUG |
| 3109 | static int prism2_registers_proc_read(char *page, char **start, off_t off, |
| 3110 | int count, int *eof, void *data) |
| 3111 | { |
| 3112 | char *p = page; |
| 3113 | local_info_t *local = (local_info_t *) data; |
| 3114 | |
| 3115 | if (off != 0) { |
| 3116 | *eof = 1; |
| 3117 | return 0; |
| 3118 | } |
| 3119 | |
| 3120 | #define SHOW_REG(n) \ |
| 3121 | p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF)) |
| 3122 | |
| 3123 | SHOW_REG(CMD); |
| 3124 | SHOW_REG(PARAM0); |
| 3125 | SHOW_REG(PARAM1); |
| 3126 | SHOW_REG(PARAM2); |
| 3127 | SHOW_REG(STATUS); |
| 3128 | SHOW_REG(RESP0); |
| 3129 | SHOW_REG(RESP1); |
| 3130 | SHOW_REG(RESP2); |
| 3131 | SHOW_REG(INFOFID); |
| 3132 | SHOW_REG(CONTROL); |
| 3133 | SHOW_REG(SELECT0); |
| 3134 | SHOW_REG(SELECT1); |
| 3135 | SHOW_REG(OFFSET0); |
| 3136 | SHOW_REG(OFFSET1); |
| 3137 | SHOW_REG(RXFID); |
| 3138 | SHOW_REG(ALLOCFID); |
| 3139 | SHOW_REG(TXCOMPLFID); |
| 3140 | SHOW_REG(SWSUPPORT0); |
| 3141 | SHOW_REG(SWSUPPORT1); |
| 3142 | SHOW_REG(SWSUPPORT2); |
| 3143 | SHOW_REG(EVSTAT); |
| 3144 | SHOW_REG(INTEN); |
| 3145 | SHOW_REG(EVACK); |
| 3146 | /* Do not read data registers, because they change the state of the |
| 3147 | * MAC (offset += 2) */ |
| 3148 | /* SHOW_REG(DATA0); */ |
| 3149 | /* SHOW_REG(DATA1); */ |
| 3150 | SHOW_REG(AUXPAGE); |
| 3151 | SHOW_REG(AUXOFFSET); |
| 3152 | /* SHOW_REG(AUXDATA); */ |
| 3153 | #ifdef PRISM2_PCI |
| 3154 | SHOW_REG(PCICOR); |
| 3155 | SHOW_REG(PCIHCR); |
| 3156 | SHOW_REG(PCI_M0_ADDRH); |
| 3157 | SHOW_REG(PCI_M0_ADDRL); |
| 3158 | SHOW_REG(PCI_M0_LEN); |
| 3159 | SHOW_REG(PCI_M0_CTL); |
| 3160 | SHOW_REG(PCI_STATUS); |
| 3161 | SHOW_REG(PCI_M1_ADDRH); |
| 3162 | SHOW_REG(PCI_M1_ADDRL); |
| 3163 | SHOW_REG(PCI_M1_LEN); |
| 3164 | SHOW_REG(PCI_M1_CTL); |
| 3165 | #endif /* PRISM2_PCI */ |
| 3166 | |
| 3167 | return (p - page); |
| 3168 | } |
| 3169 | #endif /* PRISM2_NO_PROCFS_DEBUG */ |
| 3170 | |
| 3171 | |
| 3172 | struct set_tim_data { |
| 3173 | struct list_head list; |
| 3174 | int aid; |
| 3175 | int set; |
| 3176 | }; |
| 3177 | |
| 3178 | static int prism2_set_tim(struct net_device *dev, int aid, int set) |
| 3179 | { |
| 3180 | struct list_head *ptr; |
| 3181 | struct set_tim_data *new_entry; |
| 3182 | struct hostap_interface *iface; |
| 3183 | local_info_t *local; |
| 3184 | |
| 3185 | iface = netdev_priv(dev); |
| 3186 | local = iface->local; |
| 3187 | |
| 3188 | new_entry = (struct set_tim_data *) |
| 3189 | kmalloc(sizeof(*new_entry), GFP_ATOMIC); |
| 3190 | if (new_entry == NULL) { |
| 3191 | printk(KERN_DEBUG "%s: prism2_set_tim: kmalloc failed\n", |
| 3192 | local->dev->name); |
| 3193 | return -ENOMEM; |
| 3194 | } |
| 3195 | memset(new_entry, 0, sizeof(*new_entry)); |
| 3196 | new_entry->aid = aid; |
| 3197 | new_entry->set = set; |
| 3198 | |
| 3199 | spin_lock_bh(&local->set_tim_lock); |
| 3200 | list_for_each(ptr, &local->set_tim_list) { |
| 3201 | struct set_tim_data *entry = |
| 3202 | list_entry(ptr, struct set_tim_data, list); |
| 3203 | if (entry->aid == aid) { |
| 3204 | PDEBUG(DEBUG_PS2, "%s: prism2_set_tim: aid=%d " |
| 3205 | "set=%d ==> %d\n", |
| 3206 | local->dev->name, aid, entry->set, set); |
| 3207 | entry->set = set; |
| 3208 | kfree(new_entry); |
| 3209 | new_entry = NULL; |
| 3210 | break; |
| 3211 | } |
| 3212 | } |
| 3213 | if (new_entry) |
| 3214 | list_add_tail(&new_entry->list, &local->set_tim_list); |
| 3215 | spin_unlock_bh(&local->set_tim_lock); |
| 3216 | |
| 3217 | schedule_work(&local->set_tim_queue); |
| 3218 | |
| 3219 | return 0; |
| 3220 | } |
| 3221 | |
| 3222 | |
| 3223 | static void handle_set_tim_queue(void *data) |
| 3224 | { |
| 3225 | local_info_t *local = (local_info_t *) data; |
| 3226 | struct set_tim_data *entry; |
| 3227 | u16 val; |
| 3228 | |
| 3229 | for (;;) { |
| 3230 | entry = NULL; |
| 3231 | spin_lock_bh(&local->set_tim_lock); |
| 3232 | if (!list_empty(&local->set_tim_list)) { |
| 3233 | entry = list_entry(local->set_tim_list.next, |
| 3234 | struct set_tim_data, list); |
| 3235 | list_del(&entry->list); |
| 3236 | } |
| 3237 | spin_unlock_bh(&local->set_tim_lock); |
| 3238 | if (!entry) |
| 3239 | break; |
| 3240 | |
| 3241 | PDEBUG(DEBUG_PS2, "%s: handle_set_tim_queue: aid=%d set=%d\n", |
| 3242 | local->dev->name, entry->aid, entry->set); |
| 3243 | |
| 3244 | val = entry->aid; |
| 3245 | if (entry->set) |
| 3246 | val |= 0x8000; |
| 3247 | if (hostap_set_word(local->dev, HFA384X_RID_CNFTIMCTRL, val)) { |
| 3248 | printk(KERN_DEBUG "%s: set_tim failed (aid=%d " |
| 3249 | "set=%d)\n", |
| 3250 | local->dev->name, entry->aid, entry->set); |
| 3251 | } |
| 3252 | |
| 3253 | kfree(entry); |
| 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | |
| 3258 | static void prism2_clear_set_tim_queue(local_info_t *local) |
| 3259 | { |
| 3260 | struct list_head *ptr, *n; |
| 3261 | |
| 3262 | list_for_each_safe(ptr, n, &local->set_tim_list) { |
| 3263 | struct set_tim_data *entry; |
| 3264 | entry = list_entry(ptr, struct set_tim_data, list); |
| 3265 | list_del(&entry->list); |
| 3266 | kfree(entry); |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | |
| 3271 | static struct net_device * |
Dave Hansen | 0cd545d | 2005-07-30 12:49:58 -0700 | [diff] [blame] | 3272 | prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx, |
| 3273 | struct device *sdev) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 3274 | { |
| 3275 | struct net_device *dev; |
| 3276 | struct hostap_interface *iface; |
| 3277 | struct local_info *local; |
| 3278 | int len, i, ret; |
| 3279 | |
| 3280 | if (funcs == NULL) |
| 3281 | return NULL; |
| 3282 | |
| 3283 | len = strlen(dev_template); |
| 3284 | if (len >= IFNAMSIZ || strstr(dev_template, "%d") == NULL) { |
| 3285 | printk(KERN_WARNING "hostap: Invalid dev_template='%s'\n", |
| 3286 | dev_template); |
| 3287 | return NULL; |
| 3288 | } |
| 3289 | |
| 3290 | len = sizeof(struct hostap_interface) + |
| 3291 | 3 + sizeof(struct local_info) + |
| 3292 | 3 + sizeof(struct ap_data); |
| 3293 | |
| 3294 | dev = alloc_etherdev(len); |
| 3295 | if (dev == NULL) |
| 3296 | return NULL; |
| 3297 | |
| 3298 | iface = netdev_priv(dev); |
| 3299 | local = (struct local_info *) ((((long) (iface + 1)) + 3) & ~3); |
| 3300 | local->ap = (struct ap_data *) ((((long) (local + 1)) + 3) & ~3); |
| 3301 | local->dev = iface->dev = dev; |
| 3302 | iface->local = local; |
| 3303 | iface->type = HOSTAP_INTERFACE_MASTER; |
| 3304 | INIT_LIST_HEAD(&local->hostap_interfaces); |
| 3305 | |
| 3306 | local->hw_module = THIS_MODULE; |
| 3307 | |
| 3308 | #ifdef PRISM2_IO_DEBUG |
| 3309 | local->io_debug_enabled = 1; |
| 3310 | #endif /* PRISM2_IO_DEBUG */ |
| 3311 | |
| 3312 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 3313 | local->bus_m0_buf = (u8 *) kmalloc(sizeof(struct hfa384x_tx_frame) + |
| 3314 | PRISM2_DATA_MAXLEN, GFP_DMA); |
| 3315 | if (local->bus_m0_buf == NULL) |
| 3316 | goto fail; |
| 3317 | #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */ |
| 3318 | |
| 3319 | local->func = funcs; |
| 3320 | local->func->cmd = hfa384x_cmd; |
| 3321 | local->func->read_regs = hfa384x_read_regs; |
| 3322 | local->func->get_rid = hfa384x_get_rid; |
| 3323 | local->func->set_rid = hfa384x_set_rid; |
| 3324 | local->func->hw_enable = prism2_hw_enable; |
| 3325 | local->func->hw_config = prism2_hw_config; |
| 3326 | local->func->hw_reset = prism2_hw_reset; |
| 3327 | local->func->hw_shutdown = prism2_hw_shutdown; |
| 3328 | local->func->reset_port = prism2_reset_port; |
| 3329 | local->func->schedule_reset = prism2_schedule_reset; |
| 3330 | #ifdef PRISM2_DOWNLOAD_SUPPORT |
| 3331 | local->func->read_aux = prism2_download_aux_dump; |
| 3332 | local->func->download = prism2_download; |
| 3333 | #endif /* PRISM2_DOWNLOAD_SUPPORT */ |
| 3334 | local->func->tx = prism2_tx_80211; |
| 3335 | local->func->set_tim = prism2_set_tim; |
| 3336 | local->func->need_tx_headroom = 0; /* no need to add txdesc in |
| 3337 | * skb->data (FIX: maybe for DMA bus |
| 3338 | * mastering? */ |
| 3339 | |
| 3340 | local->mtu = mtu; |
| 3341 | |
| 3342 | rwlock_init(&local->iface_lock); |
| 3343 | spin_lock_init(&local->txfidlock); |
| 3344 | spin_lock_init(&local->cmdlock); |
| 3345 | spin_lock_init(&local->baplock); |
| 3346 | spin_lock_init(&local->lock); |
| 3347 | init_MUTEX(&local->rid_bap_sem); |
| 3348 | |
| 3349 | if (card_idx < 0 || card_idx >= MAX_PARM_DEVICES) |
| 3350 | card_idx = 0; |
| 3351 | local->card_idx = card_idx; |
| 3352 | |
| 3353 | len = strlen(essid); |
| 3354 | memcpy(local->essid, essid, |
| 3355 | len > MAX_SSID_LEN ? MAX_SSID_LEN : len); |
| 3356 | local->essid[MAX_SSID_LEN] = '\0'; |
| 3357 | i = GET_INT_PARM(iw_mode, card_idx); |
| 3358 | if ((i >= IW_MODE_ADHOC && i <= IW_MODE_REPEAT) || |
| 3359 | i == IW_MODE_MONITOR) { |
| 3360 | local->iw_mode = i; |
| 3361 | } else { |
| 3362 | printk(KERN_WARNING "prism2: Unknown iw_mode %d; using " |
| 3363 | "IW_MODE_MASTER\n", i); |
| 3364 | local->iw_mode = IW_MODE_MASTER; |
| 3365 | } |
| 3366 | local->channel = GET_INT_PARM(channel, card_idx); |
| 3367 | local->beacon_int = GET_INT_PARM(beacon_int, card_idx); |
| 3368 | local->dtim_period = GET_INT_PARM(dtim_period, card_idx); |
| 3369 | local->wds_max_connections = 16; |
| 3370 | local->tx_control = HFA384X_TX_CTRL_FLAGS; |
| 3371 | local->manual_retry_count = -1; |
| 3372 | local->rts_threshold = 2347; |
| 3373 | local->fragm_threshold = 2346; |
| 3374 | local->rssi_to_dBm = 100; /* default; to be overriden by |
| 3375 | * cnfDbmAdjust, if available */ |
| 3376 | local->auth_algs = PRISM2_AUTH_OPEN | PRISM2_AUTH_SHARED_KEY; |
| 3377 | local->sram_type = -1; |
Jouni Malinen | 72ca9c6 | 2005-07-30 12:50:01 -0700 | [diff] [blame] | 3378 | local->scan_channel_mask = 0xffff; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 3379 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 3380 | local->bus_master_threshold_rx = GET_INT_PARM(bus_master_threshold_rx, |
| 3381 | card_idx); |
| 3382 | local->bus_master_threshold_tx = GET_INT_PARM(bus_master_threshold_tx, |
| 3383 | card_idx); |
| 3384 | #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */ |
| 3385 | |
| 3386 | /* Initialize task queue structures */ |
| 3387 | INIT_WORK(&local->reset_queue, handle_reset_queue, local); |
| 3388 | INIT_WORK(&local->set_multicast_list_queue, |
| 3389 | hostap_set_multicast_list_queue, local->dev); |
| 3390 | |
| 3391 | INIT_WORK(&local->set_tim_queue, handle_set_tim_queue, local); |
| 3392 | INIT_LIST_HEAD(&local->set_tim_list); |
| 3393 | spin_lock_init(&local->set_tim_lock); |
| 3394 | |
| 3395 | INIT_WORK(&local->comms_qual_update, handle_comms_qual_update, local); |
| 3396 | |
| 3397 | /* Initialize tasklets for handling hardware IRQ related operations |
| 3398 | * outside hw IRQ handler */ |
| 3399 | #define HOSTAP_TASKLET_INIT(q, f, d) \ |
| 3400 | do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \ |
| 3401 | while (0) |
| 3402 | HOSTAP_TASKLET_INIT(&local->bap_tasklet, hostap_bap_tasklet, |
| 3403 | (unsigned long) local); |
| 3404 | |
| 3405 | HOSTAP_TASKLET_INIT(&local->info_tasklet, hostap_info_tasklet, |
| 3406 | (unsigned long) local); |
| 3407 | hostap_info_init(local); |
| 3408 | |
| 3409 | HOSTAP_TASKLET_INIT(&local->rx_tasklet, |
| 3410 | hostap_rx_tasklet, (unsigned long) local); |
| 3411 | skb_queue_head_init(&local->rx_list); |
| 3412 | |
| 3413 | HOSTAP_TASKLET_INIT(&local->sta_tx_exc_tasklet, |
| 3414 | hostap_sta_tx_exc_tasklet, (unsigned long) local); |
| 3415 | skb_queue_head_init(&local->sta_tx_exc_list); |
| 3416 | |
| 3417 | INIT_LIST_HEAD(&local->cmd_queue); |
| 3418 | init_waitqueue_head(&local->hostscan_wq); |
| 3419 | INIT_LIST_HEAD(&local->crypt_deinit_list); |
| 3420 | init_timer(&local->crypt_deinit_timer); |
| 3421 | local->crypt_deinit_timer.data = (unsigned long) local; |
| 3422 | local->crypt_deinit_timer.function = prism2_crypt_deinit_handler; |
| 3423 | |
| 3424 | init_timer(&local->passive_scan_timer); |
| 3425 | local->passive_scan_timer.data = (unsigned long) local; |
| 3426 | local->passive_scan_timer.function = hostap_passive_scan; |
| 3427 | |
| 3428 | init_timer(&local->tick_timer); |
| 3429 | local->tick_timer.data = (unsigned long) local; |
| 3430 | local->tick_timer.function = hostap_tick_timer; |
| 3431 | local->tick_timer.expires = jiffies + 2 * HZ; |
| 3432 | add_timer(&local->tick_timer); |
| 3433 | |
| 3434 | INIT_LIST_HEAD(&local->bss_list); |
| 3435 | |
| 3436 | hostap_setup_dev(dev, local, 1); |
| 3437 | local->saved_eth_header_parse = dev->hard_header_parse; |
| 3438 | |
| 3439 | dev->hard_start_xmit = hostap_master_start_xmit; |
| 3440 | dev->type = ARPHRD_IEEE80211; |
| 3441 | dev->hard_header_parse = hostap_80211_header_parse; |
| 3442 | |
| 3443 | rtnl_lock(); |
| 3444 | ret = dev_alloc_name(dev, "wifi%d"); |
Dave Hansen | 0cd545d | 2005-07-30 12:49:58 -0700 | [diff] [blame] | 3445 | SET_NETDEV_DEV(dev, sdev); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 3446 | if (ret >= 0) |
| 3447 | ret = register_netdevice(dev); |
| 3448 | rtnl_unlock(); |
| 3449 | if (ret < 0) { |
| 3450 | printk(KERN_WARNING "%s: register netdevice failed!\n", |
| 3451 | dev_info); |
| 3452 | goto fail; |
| 3453 | } |
| 3454 | printk(KERN_INFO "%s: Registered netdevice %s\n", dev_info, dev->name); |
| 3455 | |
| 3456 | #ifndef PRISM2_NO_PROCFS_DEBUG |
| 3457 | create_proc_read_entry("registers", 0, local->proc, |
| 3458 | prism2_registers_proc_read, local); |
| 3459 | #endif /* PRISM2_NO_PROCFS_DEBUG */ |
| 3460 | |
| 3461 | hostap_init_data(local); |
| 3462 | return dev; |
| 3463 | |
| 3464 | fail: |
| 3465 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 3466 | kfree(local->bus_m0_buf); |
| 3467 | #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */ |
| 3468 | free_netdev(dev); |
| 3469 | return NULL; |
| 3470 | } |
| 3471 | |
| 3472 | |
| 3473 | static int hostap_hw_ready(struct net_device *dev) |
| 3474 | { |
| 3475 | struct hostap_interface *iface; |
| 3476 | struct local_info *local; |
| 3477 | |
| 3478 | iface = netdev_priv(dev); |
| 3479 | local = iface->local; |
| 3480 | local->ddev = hostap_add_interface(local, HOSTAP_INTERFACE_MAIN, 0, |
| 3481 | "", dev_template); |
| 3482 | |
| 3483 | if (local->ddev) { |
| 3484 | if (local->iw_mode == IW_MODE_INFRA || |
| 3485 | local->iw_mode == IW_MODE_ADHOC) { |
| 3486 | netif_carrier_off(local->dev); |
| 3487 | netif_carrier_off(local->ddev); |
| 3488 | } |
| 3489 | hostap_init_proc(local); |
| 3490 | hostap_init_ap_proc(local); |
| 3491 | return 0; |
| 3492 | } |
| 3493 | |
| 3494 | return -1; |
| 3495 | } |
| 3496 | |
| 3497 | |
| 3498 | static void prism2_free_local_data(struct net_device *dev) |
| 3499 | { |
| 3500 | struct hostap_tx_callback_info *tx_cb, *tx_cb_prev; |
| 3501 | int i; |
| 3502 | struct hostap_interface *iface; |
| 3503 | struct local_info *local; |
| 3504 | struct list_head *ptr, *n; |
| 3505 | |
| 3506 | if (dev == NULL) |
| 3507 | return; |
| 3508 | |
| 3509 | iface = netdev_priv(dev); |
| 3510 | local = iface->local; |
| 3511 | |
| 3512 | flush_scheduled_work(); |
| 3513 | |
| 3514 | if (timer_pending(&local->crypt_deinit_timer)) |
| 3515 | del_timer(&local->crypt_deinit_timer); |
| 3516 | prism2_crypt_deinit_entries(local, 1); |
| 3517 | |
| 3518 | if (timer_pending(&local->passive_scan_timer)) |
| 3519 | del_timer(&local->passive_scan_timer); |
| 3520 | |
| 3521 | if (timer_pending(&local->tick_timer)) |
| 3522 | del_timer(&local->tick_timer); |
| 3523 | |
| 3524 | prism2_clear_cmd_queue(local); |
| 3525 | |
| 3526 | skb_queue_purge(&local->info_list); |
| 3527 | skb_queue_purge(&local->rx_list); |
| 3528 | skb_queue_purge(&local->sta_tx_exc_list); |
| 3529 | |
| 3530 | if (local->dev_enabled) |
| 3531 | prism2_callback(local, PRISM2_CALLBACK_DISABLE); |
| 3532 | |
| 3533 | for (i = 0; i < WEP_KEYS; i++) { |
Jouni Malinen | 62fe7e3 | 2005-07-30 20:43:20 -0700 | [diff] [blame] | 3534 | struct ieee80211_crypt_data *crypt = local->crypt[i]; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 3535 | if (crypt) { |
| 3536 | if (crypt->ops) |
| 3537 | crypt->ops->deinit(crypt->priv); |
| 3538 | kfree(crypt); |
| 3539 | local->crypt[i] = NULL; |
| 3540 | } |
| 3541 | } |
| 3542 | |
| 3543 | if (local->ap != NULL) |
| 3544 | hostap_free_data(local->ap); |
| 3545 | |
| 3546 | #ifndef PRISM2_NO_PROCFS_DEBUG |
| 3547 | if (local->proc != NULL) |
| 3548 | remove_proc_entry("registers", local->proc); |
| 3549 | #endif /* PRISM2_NO_PROCFS_DEBUG */ |
| 3550 | hostap_remove_proc(local); |
| 3551 | |
| 3552 | tx_cb = local->tx_callback; |
| 3553 | while (tx_cb != NULL) { |
| 3554 | tx_cb_prev = tx_cb; |
| 3555 | tx_cb = tx_cb->next; |
| 3556 | kfree(tx_cb_prev); |
| 3557 | } |
| 3558 | |
| 3559 | hostap_set_hostapd(local, 0, 0); |
| 3560 | hostap_set_hostapd_sta(local, 0, 0); |
| 3561 | |
| 3562 | for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) { |
| 3563 | if (local->frag_cache[i].skb != NULL) |
| 3564 | dev_kfree_skb(local->frag_cache[i].skb); |
| 3565 | } |
| 3566 | |
| 3567 | #ifdef PRISM2_DOWNLOAD_SUPPORT |
| 3568 | prism2_download_free_data(local->dl_pri); |
| 3569 | prism2_download_free_data(local->dl_sec); |
| 3570 | #endif /* PRISM2_DOWNLOAD_SUPPORT */ |
| 3571 | |
| 3572 | list_for_each_safe(ptr, n, &local->hostap_interfaces) { |
| 3573 | iface = list_entry(ptr, struct hostap_interface, list); |
| 3574 | if (iface->type == HOSTAP_INTERFACE_MASTER) { |
| 3575 | /* special handling for this interface below */ |
| 3576 | continue; |
| 3577 | } |
| 3578 | hostap_remove_interface(iface->dev, 0, 1); |
| 3579 | } |
| 3580 | |
| 3581 | prism2_clear_set_tim_queue(local); |
| 3582 | |
| 3583 | list_for_each_safe(ptr, n, &local->bss_list) { |
| 3584 | struct hostap_bss_info *bss = |
| 3585 | list_entry(ptr, struct hostap_bss_info, list); |
| 3586 | kfree(bss); |
| 3587 | } |
| 3588 | |
| 3589 | #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER) |
| 3590 | kfree(local->bus_m0_buf); |
| 3591 | #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */ |
| 3592 | kfree(local->pda); |
| 3593 | kfree(local->last_scan_results); |
| 3594 | kfree(local->generic_elem); |
| 3595 | |
| 3596 | unregister_netdev(local->dev); |
| 3597 | free_netdev(local->dev); |
| 3598 | } |
| 3599 | |
| 3600 | |
| 3601 | #ifndef PRISM2_PLX |
| 3602 | static void prism2_suspend(struct net_device *dev) |
| 3603 | { |
| 3604 | struct hostap_interface *iface; |
| 3605 | struct local_info *local; |
| 3606 | union iwreq_data wrqu; |
| 3607 | |
| 3608 | iface = dev->priv; |
| 3609 | local = iface->local; |
| 3610 | |
| 3611 | /* Send disconnect event, e.g., to trigger reassociation after resume |
| 3612 | * if wpa_supplicant is used. */ |
| 3613 | memset(&wrqu, 0, sizeof(wrqu)); |
| 3614 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 3615 | wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL); |
| 3616 | |
| 3617 | /* Disable hardware and firmware */ |
| 3618 | prism2_hw_shutdown(dev, 0); |
| 3619 | } |
| 3620 | #endif /* PRISM2_PLX */ |
| 3621 | |
| 3622 | |
| 3623 | /* These might at some point be compiled separately and used as separate |
| 3624 | * kernel modules or linked into one */ |
| 3625 | #ifdef PRISM2_DOWNLOAD_SUPPORT |
| 3626 | #include "hostap_download.c" |
| 3627 | #endif /* PRISM2_DOWNLOAD_SUPPORT */ |
| 3628 | |
| 3629 | #ifdef PRISM2_CALLBACK |
| 3630 | /* External hostap_callback.c file can be used to, e.g., blink activity led. |
| 3631 | * This can use platform specific code and must define prism2_callback() |
| 3632 | * function (if PRISM2_CALLBACK is not defined, these function calls are not |
| 3633 | * used. */ |
| 3634 | #include "hostap_callback.c" |
| 3635 | #endif /* PRISM2_CALLBACK */ |