00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <linux/config.h>
00034 #include <linux/version.h>
00035
00036 #include <asm/delay.h>
00037 #include <asm/uaccess.h>
00038
00039 #include <linux/slab.h>
00040 #include <linux/netdevice.h>
00041 #include <linux/etherdevice.h>
00042 #include <linux/proc_fs.h>
00043 #include <linux/if_arp.h>
00044 #include <linux/delay.h>
00045 #include <linux/random.h>
00046 #include <linux/wait.h>
00047 #include <linux/sched.h>
00048 #include <linux/rtnetlink.h>
00049 #include "hostap_wext.h"
00050 #include <asm/irq.h>
00051
00052
00053 #include "hostap_80211.h"
00054 #include "hostap.h"
00055 #include "hostap_ap.h"
00056
00057
00058 #include "../click_wifi/packet_anno.h"
00059
00060 #include "ieee80211_radiotap.h"
00061
00062
00063
00064
00065 #define PUSH_PRISM 0
00066
00067
00068 static int mtu = 1500;
00069 MODULE_PARM(mtu, "i");
00070 MODULE_PARM_DESC(mtu, "Maximum transfer unit");
00071
00072 static int channel[MAX_PARM_DEVICES] = { 3, DEF_INTS };
00073 MODULE_PARM(channel, PARM_MIN_MAX "i");
00074 MODULE_PARM_DESC(channel, "Initial channel");
00075
00076 static char *essid[MAX_PARM_DEVICES] = { "test" };
00077 MODULE_PARM(essid, PARM_MIN_MAX "s");
00078 MODULE_PARM_DESC(essid, "Host AP's ESSID");
00079
00080 static int iw_mode[MAX_PARM_DEVICES] = { IW_MODE_MASTER, DEF_INTS };
00081 MODULE_PARM(iw_mode, PARM_MIN_MAX "i");
00082 MODULE_PARM_DESC(iw_mode, "Initial operation mode");
00083
00084 static int beacon_int[MAX_PARM_DEVICES] = { 100, DEF_INTS };
00085 MODULE_PARM(beacon_int, PARM_MIN_MAX "i");
00086 MODULE_PARM_DESC(beacon_int, "Beacon interval (1 = 1024 usec)");
00087
00088 static int dtim_period[MAX_PARM_DEVICES] = { 1, DEF_INTS };
00089 MODULE_PARM(dtim_period, PARM_MIN_MAX "i");
00090 MODULE_PARM_DESC(dtim_period, "DTIM period");
00091
00092 static int delayed_enable ;
00093 MODULE_PARM(delayed_enable, "i");
00094 MODULE_PARM_DESC(delayed_enable, "Delay MAC port enable until netdevice open");
00095
00096 static int disable_on_close ;
00097 MODULE_PARM(disable_on_close, "i");
00098 MODULE_PARM_DESC(disable_on_close, "Disable MAC port on netdevice close");
00099
00100 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
00101 static int bus_master_threshold_rx[MAX_PARM_DEVICES] = { 100, DEF_INTS };
00102 MODULE_PARM(bus_master_threshold_rx, "i");
00103 MODULE_PARM_DESC(bus_master_threshold_rx, "Packet length threshold for using "
00104 "PCI bus master on RX");
00105
00106 static int bus_master_threshold_tx[MAX_PARM_DEVICES] = { 100, DEF_INTS };
00107 MODULE_PARM(bus_master_threshold_tx, "i");
00108 MODULE_PARM_DESC(bus_master_threshold_tx, "Packet length threshold for using "
00109 "PCI bus master on TX");
00110 #endif
00111
00112 static char *dev_template = "wlan%d";
00113 MODULE_PARM(dev_template, "s");
00114 MODULE_PARM_DESC(dev_template, "Prefix for network device name (default: "
00115 "wlan%d)");
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 #ifdef final_version
00129 #define EXTRA_EVENTS_WTERR 0
00130 #else
00131
00132 #define EXTRA_EVENTS_WTERR HFA384X_EV_WTERR
00133 #endif
00134
00135 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
00136 #define EXTRA_EVENTS_BUS_MASTER (HFA384X_EV_PCI_M0 | HFA384X_EV_PCI_M1)
00137 #else
00138 #define EXTRA_EVENTS_BUS_MASTER 0
00139 #endif
00140
00141
00142 #define HFA384X_BAP0_EVENTS \
00143 (HFA384X_EV_TXEXC | HFA384X_EV_RX | HFA384X_EV_INFO | HFA384X_EV_TX)
00144
00145
00146 #define HFA384X_EVENT_MASK \
00147 (HFA384X_BAP0_EVENTS | HFA384X_EV_ALLOC | HFA384X_EV_INFDROP | \
00148 HFA384X_EV_CMD | HFA384X_EV_TICK | \
00149 EXTRA_EVENTS_WTERR | EXTRA_EVENTS_BUS_MASTER)
00150
00151
00152
00153
00154
00155 #define HFA384X_TX_CTRL_FLAGS \
00156 (HFA384X_TX_CTRL_802_11 | HFA384X_TX_CTRL_TX_EX | HFA384X_TX_CTRL_TX_OK)
00157
00158
00159
00160 #define HFA384X_CMD_BUSY_TIMEOUT 5000
00161 #define HFA384X_BAP_BUSY_TIMEOUT 50000
00162
00163
00164 #define HFA384X_CMD_COMPL_TIMEOUT 20000
00165 #define HFA384X_DL_COMPL_TIMEOUT 1000000
00166
00167
00168
00169 #define HFA384X_INIT_TIMEOUT (HZ / 2)
00170 #define HFA384X_ALLOC_COMPL_TIMEOUT (HZ / 20)
00171
00172
00173 static void prism2_hw_reset(struct net_device *dev);
00174 static void prism2_check_sta_fw_version(local_info_t *local);
00175
00176 #ifdef PRISM2_DOWNLOAD_SUPPORT
00177
00178 static u8 * prism2_read_pda(struct net_device *dev);
00179 static int prism2_download(local_info_t *local,
00180 struct prism2_download_param *param);
00181 static void prism2_download_free_data(struct prism2_download_data *dl);
00182 static int prism2_download_volatile(local_info_t *local,
00183 struct prism2_download_data *param);
00184 static int prism2_download_genesis(local_info_t *local,
00185 struct prism2_download_data *param);
00186 #endif
00187
00188
00189
00190
00191 #ifndef final_version
00192
00193
00194 #define HFA384X_MAGIC 0x8A32
00195 #endif
00196
00197
00198
00199
00200 static u16 hfa384x_read_reg(struct net_device *dev, u16 reg)
00201 {
00202 return HFA384X_INW(reg);
00203 }
00204
00205
00206 static void hfa384x_read_regs(struct net_device *dev,
00207 struct hfa384x_regs *regs)
00208 {
00209 regs->cmd = HFA384X_INW(HFA384X_CMD_OFF);
00210 regs->evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
00211 regs->offset0 = HFA384X_INW(HFA384X_OFFSET0_OFF);
00212 regs->offset1 = HFA384X_INW(HFA384X_OFFSET1_OFF);
00213 regs->swsupport0 = HFA384X_INW(HFA384X_SWSUPPORT0_OFF);
00214 }
00215
00216
00217
00218 static inline void __hostap_cmd_queue_free(local_info_t *local,
00219 struct hostap_cmd_queue *entry,
00220 int del_req)
00221 {
00222 if (del_req) {
00223 entry->del_req = 1;
00224 if (!list_empty(&entry->list)) {
00225 list_del_init(&entry->list);
00226 local->cmd_queue_len--;
00227 }
00228 }
00229
00230 if (atomic_dec_and_test(&entry->usecnt) && entry->del_req)
00231 kfree(entry);
00232 }
00233
00234 static inline void hostap_cmd_queue_free(local_info_t *local,
00235 struct hostap_cmd_queue *entry,
00236 int del_req)
00237 {
00238 unsigned long flags;
00239
00240 spin_lock_irqsave(&local->cmdlock, flags);
00241 __hostap_cmd_queue_free(local, entry, del_req);
00242 spin_unlock_irqrestore(&local->cmdlock, flags);
00243 }
00244
00245
00246 static inline int hfa384x_cmd_issue(struct net_device *dev,
00247 struct hostap_cmd_queue *entry)
00248 {
00249 struct hostap_interface *iface = dev->priv;
00250 local_info_t *local = iface->local;
00251 int tries;
00252 u16 reg;
00253 unsigned long flags;
00254
00255 if (entry->issued) {
00256 printk(KERN_DEBUG "%s: driver bug - re-issuing command @%p\n",
00257 dev->name, entry);
00258 }
00259
00260
00261
00262 tries = HFA384X_CMD_BUSY_TIMEOUT;
00263 while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
00264 tries--;
00265 udelay(1);
00266 }
00267 #ifndef final_version
00268 if (tries != HFA384X_CMD_BUSY_TIMEOUT) {
00269 prism2_io_debug_error(dev, 1);
00270 printk(KERN_DEBUG "%s: hfa384x_cmd_issue: cmd reg was busy "
00271 "for %d usec\n", dev->name,
00272 HFA384X_CMD_BUSY_TIMEOUT - tries);
00273 }
00274 #endif
00275 if (tries == 0) {
00276 reg = HFA384X_INW(HFA384X_CMD_OFF);
00277 prism2_io_debug_error(dev, 2);
00278 printk(KERN_DEBUG "%s: hfa384x_cmd_issue - timeout - "
00279 "reg=0x%04x\n", dev->name, reg);
00280 return -ETIMEDOUT;
00281 }
00282
00283
00284 spin_lock_irqsave(&local->cmdlock, flags);
00285 HFA384X_OUTW(entry->param0, HFA384X_PARAM0_OFF);
00286 HFA384X_OUTW(entry->param1, HFA384X_PARAM1_OFF);
00287 HFA384X_OUTW(entry->cmd, HFA384X_CMD_OFF);
00288 entry->issued = 1;
00289 spin_unlock_irqrestore(&local->cmdlock, flags);
00290
00291 return 0;
00292 }
00293
00294
00295
00296
00297
00298 static int hfa384x_cmd(struct net_device *dev, u16 cmd, u16 param0,
00299 u16 *param1, u16 *resp0)
00300 {
00301 struct hostap_interface *iface = dev->priv;
00302 local_info_t *local = iface->local;
00303 int err, res, issue, issued = 0;
00304 unsigned long flags;
00305 struct hostap_cmd_queue *entry;
00306 DECLARE_WAITQUEUE(wait, current);
00307
00308 if (in_interrupt()) {
00309 printk(KERN_DEBUG "%s: hfa384x_cmd called from interrupt "
00310 "context\n", dev->name);
00311 return -1;
00312 }
00313
00314 if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN) {
00315 printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
00316 dev->name);
00317 return -1;
00318 }
00319
00320 if (signal_pending(current))
00321 return -EINTR;
00322
00323 entry = (struct hostap_cmd_queue *)
00324 kmalloc(sizeof(*entry), GFP_ATOMIC);
00325 if (entry == NULL) {
00326 printk(KERN_DEBUG "%s: hfa384x_cmd - kmalloc failed\n",
00327 dev->name);
00328 return -ENOMEM;
00329 }
00330 memset(entry, 0, sizeof(*entry));
00331 atomic_set(&entry->usecnt, 1);
00332 entry->type = CMD_SLEEP;
00333 entry->cmd = cmd;
00334 entry->param0 = param0;
00335 if (param1)
00336 entry->param1 = *param1;
00337 init_waitqueue_head(&entry->compl);
00338
00339
00340
00341 add_wait_queue(&entry->compl, &wait);
00342 set_current_state(TASK_INTERRUPTIBLE);
00343
00344 spin_lock_irqsave(&local->cmdlock, flags);
00345 issue = list_empty(&local->cmd_queue);
00346 if (issue)
00347 entry->issuing = 1;
00348 list_add_tail(&entry->list, &local->cmd_queue);
00349 local->cmd_queue_len++;
00350 spin_unlock_irqrestore(&local->cmdlock, flags);
00351
00352 err = 0;
00353 if (!issue)
00354 goto wait_completion;
00355
00356 if (signal_pending(current))
00357 err = -EINTR;
00358
00359 if (!err) {
00360 if (hfa384x_cmd_issue(dev, entry))
00361 err = -ETIMEDOUT;
00362 else
00363 issued = 1;
00364 }
00365
00366 wait_completion:
00367 if (!err && entry->type != CMD_COMPLETED) {
00368
00369 res = schedule_timeout(2 * HZ);
00370 } else
00371 res = -1;
00372
00373 if (!err && signal_pending(current))
00374 err = -EINTR;
00375
00376 if (err && issued) {
00377
00378
00379
00380
00381
00382 udelay(300);
00383 }
00384
00385 set_current_state(TASK_RUNNING);
00386 remove_wait_queue(&entry->compl, &wait);
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 spin_lock_irqsave(&local->cmdlock, flags);
00406 if (!list_empty(&entry->list)) {
00407 printk(KERN_DEBUG "%s: hfa384x_cmd: entry still in list? "
00408 "(entry=%p, type=%d, res=%d)\n", dev->name, entry,
00409 entry->type, res);
00410 list_del_init(&entry->list);
00411 local->cmd_queue_len--;
00412 }
00413 spin_unlock_irqrestore(&local->cmdlock, flags);
00414
00415 if (err) {
00416 printk(KERN_DEBUG "%s: hfa384x_cmd: interrupted; err=%d\n",
00417 dev->name, err);
00418 res = err;
00419 goto done;
00420 }
00421
00422 if (entry->type != CMD_COMPLETED) {
00423 u16 reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
00424 printk(KERN_DEBUG "%s: hfa384x_cmd: command was not "
00425 "completed (res=%d, entry=%p, type=%d, cmd=0x%04x, "
00426 "param0=0x%04x, EVSTAT=%04x INTEN=%04x)\n", dev->name,
00427 res, entry, entry->type, entry->cmd, entry->param0, reg,
00428 HFA384X_INW(HFA384X_INTEN_OFF));
00429 if (reg & HFA384X_EV_CMD) {
00430
00431
00432
00433 printk(KERN_WARNING "%s: interrupt delivery does not "
00434 "seem to work\n", dev->name);
00435 }
00436 prism2_io_debug_error(dev, 3);
00437 res = -ETIMEDOUT;
00438 goto done;
00439 }
00440
00441 if (resp0 != NULL)
00442 *resp0 = entry->resp0;
00443 #ifndef final_version
00444 if (entry->res) {
00445 printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x, "
00446 "resp0=0x%04x\n",
00447 dev->name, cmd, entry->res, entry->resp0);
00448 }
00449 #endif
00450
00451 res = entry->res;
00452 done:
00453 hostap_cmd_queue_free(local, entry, 1);
00454 return res;
00455 }
00456
00457
00458
00459
00460
00461 static int hfa384x_cmd_callback(struct net_device *dev, u16 cmd, u16 param0,
00462 void (*callback)(struct net_device *dev,
00463 void *context, u16 resp0,
00464 u16 status),
00465 void *context)
00466 {
00467 struct hostap_interface *iface = dev->priv;
00468 local_info_t *local = iface->local;
00469 int issue, ret;
00470 unsigned long flags;
00471 struct hostap_cmd_queue *entry;
00472
00473 if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN + 2) {
00474 printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
00475 dev->name);
00476 return -1;
00477 }
00478
00479 entry = (struct hostap_cmd_queue *)
00480 kmalloc(sizeof(*entry), GFP_ATOMIC);
00481 if (entry == NULL) {
00482 printk(KERN_DEBUG "%s: hfa384x_cmd_callback - kmalloc "
00483 "failed\n", dev->name);
00484 return -ENOMEM;
00485 }
00486 memset(entry, 0, sizeof(*entry));
00487 atomic_set(&entry->usecnt, 1);
00488 entry->type = CMD_CALLBACK;
00489 entry->cmd = cmd;
00490 entry->param0 = param0;
00491 entry->callback = callback;
00492 entry->context = context;
00493
00494 spin_lock_irqsave(&local->cmdlock, flags);
00495 issue = list_empty(&local->cmd_queue);
00496 if (issue)
00497 entry->issuing = 1;
00498 list_add_tail(&entry->list, &local->cmd_queue);
00499 local->cmd_queue_len++;
00500 spin_unlock_irqrestore(&local->cmdlock, flags);
00501
00502 if (issue && hfa384x_cmd_issue(dev, entry))
00503 ret = -ETIMEDOUT;
00504 else
00505 ret = 0;
00506
00507 hostap_cmd_queue_free(local, entry, ret);
00508
00509 return ret;
00510 }
00511
00512
00513 static int hfa384x_cmd_wait(struct net_device *dev, u16 cmd, u16 param0)
00514 {
00515 int res, tries;
00516 u16 reg;
00517
00518
00519
00520 tries = HFA384X_CMD_BUSY_TIMEOUT;
00521 while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
00522 tries--;
00523 udelay(1);
00524 }
00525 if (tries == 0) {
00526 prism2_io_debug_error(dev, 4);
00527 printk(KERN_DEBUG "%s: hfa384x_cmd_wait - timeout - "
00528 "reg=0x%04x\n", dev->name,
00529 HFA384X_INW(HFA384X_CMD_OFF));
00530 return -ETIMEDOUT;
00531 }
00532
00533
00534 HFA384X_OUTW(param0, HFA384X_PARAM0_OFF);
00535 HFA384X_OUTW(cmd, HFA384X_CMD_OFF);
00536
00537
00538 if ((cmd & HFA384X_CMDCODE_MASK) == HFA384X_CMDCODE_DOWNLOAD)
00539 tries = HFA384X_DL_COMPL_TIMEOUT;
00540 else
00541 tries = HFA384X_CMD_COMPL_TIMEOUT;
00542
00543 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
00544 tries > 0) {
00545 tries--;
00546 udelay(10);
00547 }
00548 if (tries == 0) {
00549 reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
00550 prism2_io_debug_error(dev, 5);
00551 printk(KERN_DEBUG "%s: hfa384x_cmd_wait - timeout2 - "
00552 "reg=0x%04x\n", dev->name, reg);
00553 return -ETIMEDOUT;
00554 }
00555
00556 res = (HFA384X_INW(HFA384X_STATUS_OFF) &
00557 (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) | BIT(9) |
00558 BIT(8))) >> 8;
00559 #ifndef final_version
00560 if (res) {
00561 printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x\n",
00562 dev->name, cmd, res);
00563 }
00564 #endif
00565
00566 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
00567
00568 return res;
00569 }
00570
00571
00572 static int hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd, u16 param0)
00573 {
00574 int tries;
00575 u16 reg;
00576
00577
00578 tries = HFA384X_CMD_BUSY_TIMEOUT;
00579 while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
00580 tries--;
00581 udelay(1);
00582 }
00583 if (tries == 0) {
00584 reg = HFA384X_INW(HFA384X_CMD_OFF);
00585 prism2_io_debug_error(dev, 6);
00586 printk("%s: hfa384x_cmd - timeout - reg=0x%04x\n", dev->name,
00587 reg);
00588 return -ETIMEDOUT;
00589 }
00590
00591
00592 HFA384X_OUTW(param0, HFA384X_PARAM0_OFF);
00593 HFA384X_OUTW(cmd, HFA384X_CMD_OFF);
00594
00595 return 0;
00596 }
00597
00598
00599 static inline int hfa384x_wait_offset(struct net_device *dev, u16 o_off)
00600 {
00601 int tries = HFA384X_BAP_BUSY_TIMEOUT;
00602 int res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
00603
00604 while (res && tries > 0) {
00605 tries--;
00606 udelay(1);
00607 res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
00608 }
00609 return res;
00610 }
00611
00612
00613
00614 static int hfa384x_setup_bap(struct net_device *dev, u16 bap, u16 id,
00615 int offset)
00616 {
00617 u16 o_off, s_off;
00618 int ret = 0;
00619
00620 if (offset % 2 || bap > 1)
00621 return -EINVAL;
00622
00623 if (bap == BAP1) {
00624 o_off = HFA384X_OFFSET1_OFF;
00625 s_off = HFA384X_SELECT1_OFF;
00626 } else {
00627 o_off = HFA384X_OFFSET0_OFF;
00628 s_off = HFA384X_SELECT0_OFF;
00629 }
00630
00631 if (hfa384x_wait_offset(dev, o_off)) {
00632 prism2_io_debug_error(dev, 7);
00633 printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout before\n",
00634 dev->name);
00635 ret = -ETIMEDOUT;
00636 goto out;
00637 }
00638
00639 HFA384X_OUTW(id, s_off);
00640 HFA384X_OUTW(offset, o_off);
00641
00642 if (hfa384x_wait_offset(dev, o_off)) {
00643 prism2_io_debug_error(dev, 8);
00644 printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout after\n",
00645 dev->name);
00646 ret = -ETIMEDOUT;
00647 goto out;
00648 }
00649 #ifndef final_version
00650 if (HFA384X_INW(o_off) & HFA384X_OFFSET_ERR) {
00651 prism2_io_debug_error(dev, 9);
00652 printk(KERN_DEBUG "%s: hfa384x_setup_bap - offset error "
00653 "(%d,0x04%x,%d); reg=0x%04x\n",
00654 dev->name, bap, id, offset, HFA384X_INW(o_off));
00655 ret = -EINVAL;
00656 }
00657 #endif
00658
00659 out:
00660 return ret;
00661 }
00662
00663
00664 static int hfa384x_get_rid(struct net_device *dev, u16 rid, void *buf, int len,
00665 int exact_len)
00666 {
00667 struct hostap_interface *iface = dev->priv;
00668 local_info_t *local = iface->local;
00669 int res, rlen = 0;
00670 struct hfa384x_rid_hdr rec;
00671
00672 res = down_interruptible(&local->rid_bap_sem);
00673 if (res)
00674 return res;
00675
00676 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS, rid, NULL, NULL);
00677 if (res) {
00678 printk(KERN_DEBUG "%s: hfa384x_get_rid: CMDCODE_ACCESS failed "
00679 "(res=%d, rid=%04x, len=%d)\n",
00680 dev->name, res, rid, len);
00681 up(&local->rid_bap_sem);
00682 return res;
00683 }
00684
00685 spin_lock_bh(&local->baplock);
00686
00687 res = hfa384x_setup_bap(dev, BAP0, rid, 0);
00688 if (!res)
00689 res = hfa384x_from_bap(dev, BAP0, &rec, sizeof(rec));
00690
00691 if (le16_to_cpu(rec.len) == 0) {
00692
00693 res = -ENODATA;
00694 }
00695
00696 rlen = (le16_to_cpu(rec.len) - 1) * 2;
00697 if (!res && exact_len && rlen != len) {
00698 printk(KERN_DEBUG "%s: hfa384x_get_rid - RID len mismatch: "
00699 "rid=0x%04x, len=%d (expected %d)\n",
00700 dev->name, rid, rlen, len);
00701 res = -ENODATA;
00702 }
00703
00704 if (!res)
00705 res = hfa384x_from_bap(dev, BAP0, buf, len);
00706
00707 spin_unlock_bh(&local->baplock);
00708 up(&local->rid_bap_sem);
00709
00710 if (res) {
00711 if (res != -ENODATA)
00712 printk(KERN_DEBUG "%s: hfa384x_get_rid (rid=%04x, "
00713 "len=%d) - failed - res=%d\n", dev->name, rid,
00714 len, res);
00715 if (res == -ETIMEDOUT)
00716 prism2_hw_reset(dev);
00717 return res;
00718 }
00719
00720 return rlen;
00721 }
00722
00723
00724 static int hfa384x_set_rid(struct net_device *dev, u16 rid, void *buf, int len)
00725 {
00726 struct hostap_interface *iface = dev->priv;
00727 local_info_t *local = iface->local;
00728 struct hfa384x_rid_hdr rec;
00729 int res;
00730
00731 rec.rid = cpu_to_le16(rid);
00732
00733 rec.len = cpu_to_le16(len / 2 + len % 2 + 1);
00734
00735 res = down_interruptible(&local->rid_bap_sem);
00736 if (res)
00737 return res;
00738
00739 spin_lock_bh(&local->baplock);
00740 res = hfa384x_setup_bap(dev, BAP0, rid, 0);
00741 if (!res)
00742 res = hfa384x_to_bap(dev, BAP0, &rec, sizeof(rec));
00743 if (!res)
00744 res = hfa384x_to_bap(dev, BAP0, buf, len);
00745 spin_unlock_bh(&local->baplock);
00746
00747 if (res) {
00748 printk(KERN_DEBUG "%s: hfa384x_set_rid (rid=%04x, len=%d) - "
00749 "failed - res=%d\n", dev->name, rid, len, res);
00750 up(&local->rid_bap_sem);
00751 return res;
00752 }
00753
00754 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS_WRITE, rid, NULL, NULL);
00755 up(&local->rid_bap_sem);
00756 if (res) {
00757 printk(KERN_DEBUG "%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE "
00758 "failed (res=%d, rid=%04x, len=%d)\n",
00759 dev->name, res, rid, len);
00760 return res;
00761 }
00762
00763 if (res == -ETIMEDOUT)
00764 prism2_hw_reset(dev);
00765
00766 return res;
00767 }
00768
00769
00770 static void hfa384x_disable_interrupts(struct net_device *dev)
00771 {
00772
00773 HFA384X_OUTW(0, HFA384X_INTEN_OFF);
00774 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
00775 }
00776
00777
00778 static void hfa384x_enable_interrupts(struct net_device *dev)
00779 {
00780
00781 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
00782 HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
00783 }
00784
00785
00786 static void hfa384x_events_no_bap0(struct net_device *dev)
00787 {
00788 HFA384X_OUTW(HFA384X_EVENT_MASK & ~HFA384X_BAP0_EVENTS,
00789 HFA384X_INTEN_OFF);
00790 }
00791
00792
00793 static void hfa384x_events_all(struct net_device *dev)
00794 {
00795 HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
00796 }
00797
00798
00799 static void hfa384x_events_only_cmd(struct net_device *dev)
00800 {
00801 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_INTEN_OFF);
00802 }
00803
00804
00805 static u16 hfa384x_allocate_fid(struct net_device *dev, int len)
00806 {
00807 u16 fid;
00808 unsigned long delay;
00809
00810
00811
00812
00813 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_ALLOC, len)) {
00814 printk(KERN_DEBUG "%s: cannot allocate fid, len=%d\n",
00815 dev->name, len);
00816 return 0xffff;
00817 }
00818
00819 delay = jiffies + HFA384X_ALLOC_COMPL_TIMEOUT;
00820 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC) &&
00821 time_before(jiffies, delay))
00822 yield();
00823 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC)) {
00824 printk("%s: fid allocate, len=%d - timeout\n", dev->name, len);
00825 return 0xffff;
00826 }
00827
00828 fid = HFA384X_INW(HFA384X_ALLOCFID_OFF);
00829 HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
00830
00831 return fid;
00832 }
00833
00834
00835 static int prism2_reset_port(struct net_device *dev)
00836 {
00837 struct hostap_interface *iface = dev->priv;
00838 local_info_t *local = iface->local;
00839 int res;
00840
00841 if (!local->dev_enabled)
00842 return 0;
00843
00844 res = hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0,
00845 NULL, NULL);
00846 if (res)
00847 printk(KERN_DEBUG "%s: reset port failed to disable port\n",
00848 dev->name);
00849 else {
00850 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0,
00851 NULL, NULL);
00852 if (res)
00853 printk(KERN_DEBUG "%s: reset port failed to enable "
00854 "port\n", dev->name);
00855 }
00856
00857
00858
00859
00860 if (local->fragm_threshold != 2346 &&
00861 hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
00862 local->fragm_threshold)) {
00863 printk(KERN_DEBUG "%s: failed to restore fragmentation "
00864 "threshold (%d) after Port0 enable\n",
00865 dev->name, local->fragm_threshold);
00866 }
00867
00868 return res;
00869 }
00870
00871
00872 static int prism2_get_version_info(struct net_device *dev, u16 rid,
00873 const char *txt)
00874 {
00875 struct hfa384x_comp_ident comp;
00876
00877 if (hfa384x_get_rid(dev, rid, &comp, sizeof(comp), 1) < 0) {
00878 printk(KERN_DEBUG "Could not get RID for component %s\n", txt);
00879 return -1;
00880 }
00881
00882 printk(KERN_INFO "%s: %s: id=0x%02x v%d.%d.%d\n", dev->name, txt,
00883 __le16_to_cpu(comp.id), __le16_to_cpu(comp.major),
00884 __le16_to_cpu(comp.minor), __le16_to_cpu(comp.variant));
00885 return 0;
00886 }
00887
00888
00889 static int prism2_setup_rids(struct net_device *dev)
00890 {
00891 struct hostap_interface *iface = dev->priv;
00892 local_info_t *local = iface->local;
00893 u16 tmp;
00894 int ret = 0;
00895
00896 hostap_set_word(dev, HFA384X_RID_TICKTIME, 2000);
00897
00898 if (!local->fw_ap) {
00899 tmp = hostap_get_porttype(local);
00900 ret = hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, tmp);
00901 if (ret) {
00902 printk("%s: Port type setting to %d failed\n",
00903 dev->name, tmp);
00904 goto fail;
00905 }
00906 }
00907
00908
00909
00910 if (local->iw_mode != IW_MODE_MASTER || local->essid[0] != '\0') {
00911 ret = hostap_set_string(dev, HFA384X_RID_CNFOWNSSID,
00912 local->essid);
00913 if (ret) {
00914 printk("%s: AP own SSID setting failed\n", dev->name);
00915 goto fail;
00916 }
00917 }
00918
00919 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXDATALEN,
00920 PRISM2_DATA_MAXLEN);
00921 if (ret) {
00922 printk("%s: MAC data length setting to %d failed\n",
00923 dev->name, PRISM2_DATA_MAXLEN);
00924 goto fail;
00925 }
00926
00927 if (hfa384x_get_rid(dev, HFA384X_RID_CHANNELLIST, &tmp, 2, 1) < 0) {
00928 printk("%s: Channel list read failed\n", dev->name);
00929 ret = -EINVAL;
00930 goto fail;
00931 }
00932 local->channel_mask = __le16_to_cpu(tmp);
00933
00934 if (local->channel < 1 || local->channel > 14 ||
00935 !(local->channel_mask & (1 << (local->channel - 1)))) {
00936 printk(KERN_WARNING "%s: Channel setting out of range "
00937 "(%d)!\n", dev->name, local->channel);
00938 ret = -EBUSY;
00939 goto fail;
00940 }
00941
00942 ret = hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel);
00943 if (ret) {
00944 printk("%s: Channel setting to %d failed\n",
00945 dev->name, local->channel);
00946 goto fail;
00947 }
00948
00949 ret = hostap_set_word(dev, HFA384X_RID_CNFBEACONINT,
00950 local->beacon_int);
00951 if (ret) {
00952 printk("%s: Beacon interval setting to %d failed\n",
00953 dev->name, local->beacon_int);
00954
00955 if (ret == -ETIMEDOUT)
00956 goto fail;
00957 }
00958
00959 ret = hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD,
00960 local->dtim_period);
00961 if (ret) {
00962 printk("%s: DTIM period setting to %d failed\n",
00963 dev->name, local->dtim_period);
00964
00965 if (ret == -ETIMEDOUT)
00966 goto fail;
00967 }
00968
00969 ret = hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
00970 local->is_promisc);
00971 if (ret)
00972 printk(KERN_INFO "%s: Setting promiscuous mode (%d) failed\n",
00973 dev->name, local->is_promisc);
00974
00975 if (!local->fw_ap) {
00976 ret = hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID,
00977 local->essid);
00978 if (ret) {
00979 printk("%s: Desired SSID setting failed\n", dev->name);
00980 goto fail;
00981 }
00982 }
00983
00984
00985
00986
00987 if (local->tx_rate_control == 0) {
00988 local->tx_rate_control =
00989 HFA384X_RATES_1MBPS |
00990 HFA384X_RATES_2MBPS |
00991 HFA384X_RATES_5MBPS |
00992 HFA384X_RATES_11MBPS;
00993 }
00994
00995
00996
00997
00998
00999
01000
01001 if (local->basic_rates == 0)
01002 local->basic_rates = HFA384X_RATES_1MBPS;
01003
01004 if (!local->fw_ap) {
01005 ret = hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
01006 local->tx_rate_control);
01007 if (ret) {
01008 printk("%s: TXRateControl setting to %d failed\n",
01009 dev->name, local->tx_rate_control);
01010 goto fail;
01011 }
01012
01013 ret = hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
01014 local->tx_rate_control);
01015 if (ret) {
01016 printk("%s: cnfSupportedRates setting to %d failed\n",
01017 dev->name, local->tx_rate_control);
01018 }
01019
01020 ret = hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
01021 local->basic_rates);
01022 if (ret) {
01023 printk("%s: cnfBasicRates setting to %d failed\n",
01024 dev->name, local->basic_rates);
01025 }
01026
01027 ret = hostap_set_word(dev, HFA384X_RID_CREATEIBSS, 1);
01028 if (ret) {
01029 printk("%s: Create IBSS setting to 1 failed\n",
01030 dev->name);
01031 }
01032 }
01033
01034 if (local->name_set)
01035 (void) hostap_set_string(dev, HFA384X_RID_CNFOWNNAME,
01036 local->name);
01037
01038 if (hostap_set_encryption(local)) {
01039 printk(KERN_INFO "%s: could not configure encryption\n",
01040 dev->name);
01041 }
01042
01043 (void) hostap_set_antsel(local);
01044
01045 if (hostap_set_roaming(local)) {
01046 printk(KERN_INFO "%s: could not set host roaming\n",
01047 dev->name);
01048 }
01049
01050 if (local->sta_fw_ver >= PRISM2_FW_VER(1,6,3) &&
01051 hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY, local->enh_sec))
01052 printk(KERN_INFO "%s: cnfEnhSecurity setting to 0x%x failed\n",
01053 dev->name, local->enh_sec);
01054
01055
01056
01057
01058
01059
01060
01061 if (local->sta_fw_ver >= PRISM2_FW_VER(0,8,2)) {
01062 if (hostap_set_word(dev, HFA384X_RID_CNFTHIRTY2TALLY, 1)) {
01063 printk(KERN_INFO "%s: cnfThirty2Tally setting "
01064 "failed\n", dev->name);
01065 local->tallies32 = 0;
01066 } else
01067 local->tallies32 = 1;
01068 } else
01069 local->tallies32 = 0;
01070
01071 hostap_set_auth_algs(local);
01072
01073 if (hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
01074 local->fragm_threshold)) {
01075 printk(KERN_INFO "%s: setting FragmentationThreshold to %d "
01076 "failed\n", dev->name, local->fragm_threshold);
01077 }
01078
01079 if (hostap_set_word(dev, HFA384X_RID_RTSTHRESHOLD,
01080 local->rts_threshold)) {
01081 printk(KERN_INFO "%s: setting RTSThreshold to %d failed\n",
01082 dev->name, local->rts_threshold);
01083 }
01084
01085 if (local->manual_retry_count >= 0 &&
01086 hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
01087 local->manual_retry_count)) {
01088 printk(KERN_INFO "%s: setting cnfAltRetryCount to %d failed\n",
01089 dev->name, local->manual_retry_count);
01090 }
01091
01092 fail:
01093 return ret;
01094 }
01095
01096
01097 static void prism2_clear_cmd_queue(local_info_t *local)
01098 {
01099 struct list_head *ptr, *n;
01100 unsigned long flags;
01101 struct hostap_cmd_queue *entry;
01102
01103 spin_lock_irqsave(&local->cmdlock, flags);
01104 for (ptr = local->cmd_queue.next, n = ptr->next;
01105 ptr != &local->cmd_queue; ptr = n, n = ptr->next) {
01106 entry = list_entry(ptr, struct hostap_cmd_queue, list);
01107 atomic_inc(&entry->usecnt);
01108 printk(KERN_DEBUG "%s: removed pending cmd_queue entry "
01109 "(type=%d, cmd=0x%04x, param0=0x%04x)\n",
01110 local->dev->name, entry->type, entry->cmd,
01111 entry->param0);
01112 __hostap_cmd_queue_free(local, entry, 1);
01113 }
01114 if (local->cmd_queue_len) {
01115 printk(KERN_DEBUG "%s: cmd_queue_len (%d) not zero after "
01116 "flush\n", local->dev->name, local->cmd_queue_len);
01117 local->cmd_queue_len = 0;
01118 }
01119 spin_unlock_irqrestore(&local->cmdlock, flags);
01120 }
01121
01122
01123 static int prism2_hw_init(struct net_device *dev, int initial)
01124 {
01125 struct hostap_interface *iface = dev->priv;
01126 local_info_t *local = iface->local;
01127 int ret, first = 1;
01128 unsigned long start, delay;
01129
01130 PDEBUG(DEBUG_FLOW, "prism2_hw_init()\n");
01131
01132 clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits);
01133
01134 init:
01135
01136 ret = hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_INIT, 0);
01137 if (ret) {
01138 printk("%s: first command failed - is the card compatible?\n",
01139 dev_info);
01140 return 1;
01141 }
01142
01143 if (first && (HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
01144
01145
01146 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
01147 printk(KERN_DEBUG "%s: init command completed too quickly - "
01148 "retrying\n", dev->name);
01149 first = 0;
01150 goto init;
01151 }
01152
01153 start = jiffies;
01154 delay = jiffies + HFA384X_INIT_TIMEOUT;
01155 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
01156 time_before(jiffies, delay))
01157 yield();
01158 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
01159 printk("%s: card initialization timed out\n", dev_info);
01160 return 1;
01161 }
01162 printk(KERN_DEBUG "prism2_hw_init: initialized in %lu ms\n",
01163 (jiffies - start) * 1000 / HZ);
01164 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
01165 return 0;
01166 }
01167
01168
01169 static int prism2_hw_init2(struct net_device *dev, int initial)
01170 {
01171 struct hostap_interface *iface = dev->priv;
01172 local_info_t *local = iface->local;
01173 int i;
01174
01175 #ifdef PRISM2_DOWNLOAD_SUPPORT
01176 local->pda = prism2_read_pda(dev);
01177 #endif
01178
01179 hfa384x_disable_interrupts(dev);
01180
01181 #ifndef final_version
01182 HFA384X_OUTW(HFA384X_MAGIC, HFA384X_SWSUPPORT0_OFF);
01183 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
01184 printk("SWSUPPORT0 write/read failed: %04X != %04X\n",
01185 HFA384X_INW(HFA384X_SWSUPPORT0_OFF), HFA384X_MAGIC);
01186 goto failed;
01187 }
01188 #endif
01189
01190 if (initial || local->pri_only) {
01191 hfa384x_events_only_cmd(dev);
01192
01193 if (prism2_get_version_info(dev, HFA384X_RID_NICID, "NIC") ||
01194 prism2_get_version_info(dev, HFA384X_RID_PRIID, "PRI")) {
01195 hfa384x_disable_interrupts(dev);
01196 goto failed;
01197 }
01198
01199 if (prism2_get_version_info(dev, HFA384X_RID_STAID, "STA")) {
01200 printk(KERN_DEBUG "%s: Failed to read STA f/w version "
01201 "- only Primary f/w present\n", dev->name);
01202 local->pri_only = 1;
01203 return 0;
01204 }
01205 local->pri_only = 0;
01206 hfa384x_disable_interrupts(dev);
01207 }
01208
01209
01210
01211
01212
01213
01214 local->txfid_len = PRISM2_TXFID_LEN;
01215 for (i = 0; i < PRISM2_TXFID_COUNT; i++) {
01216 local->txfid[i] = hfa384x_allocate_fid(dev, local->txfid_len);
01217 if (local->txfid[i] == 0xffff && local->txfid_len > 1600) {
01218 local->txfid[i] = hfa384x_allocate_fid(dev, 1600);
01219 if (local->txfid[i] != 0xffff) {
01220 printk(KERN_DEBUG "%s: Using shorter TX FID "
01221 "(1600 bytes)\n", dev->name);
01222 local->txfid_len = 1600;
01223 }
01224 }
01225 if (local->txfid[i] == 0xffff)
01226 goto failed;
01227 local->intransmitfid[i] = PRISM2_TXFID_EMPTY;
01228 }
01229
01230 hfa384x_events_only_cmd(dev);
01231
01232 if (initial) {
01233 prism2_check_sta_fw_version(local);
01234
01235 if (hfa384x_get_rid(dev, HFA384X_RID_CNFOWNMACADDR,
01236 &dev->dev_addr, 6, 1) < 0) {
01237 printk("%s: could not get own MAC address\n",
01238 dev->name);
01239 }
01240 if (local->apdev)
01241 memcpy(local->apdev->dev_addr, dev->dev_addr,
01242 ETH_ALEN);
01243 if (local->stadev)
01244 memcpy(local->stadev->dev_addr, dev->dev_addr,
01245 ETH_ALEN);
01246 } else if (local->fw_ap)
01247 prism2_check_sta_fw_version(local);
01248
01249 prism2_setup_rids(dev);
01250
01251
01252 return 0;
01253
01254 failed:
01255 printk(KERN_WARNING "%s: Initialization failed\n", dev_info);
01256 return 1;
01257 }
01258
01259
01260 static int prism2_hw_enable(struct net_device *dev, int initial)
01261 {
01262 struct hostap_interface *iface = dev->priv;
01263 local_info_t *local = iface->local;
01264 int was_resetting = local->hw_resetting;
01265
01266 if (hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL, NULL)) {
01267 printk("%s: MAC port 0 enabling failed\n", dev->name);
01268 return 1;
01269 }
01270
01271 local->hw_ready = 1;
01272 local->hw_reset_tries = 0;
01273 local->hw_resetting = 0;
01274 hfa384x_enable_interrupts(dev);
01275
01276
01277
01278
01279 if (initial && prism2_reset_port(dev)) {
01280 printk("%s: MAC port 0 reseting failed\n", dev->name);
01281 return 1;
01282 }
01283
01284 if (was_resetting && netif_queue_stopped(dev)) {
01285
01286
01287
01288 hostap_netif_wake_queues(dev);
01289 }
01290
01291 return 0;
01292 }
01293
01294
01295 static int prism2_hw_config(struct net_device *dev, int initial)
01296 {
01297 struct hostap_interface *iface = dev->priv;
01298 local_info_t *local = iface->local;
01299 if (local->hw_downloading)
01300 return 1;
01301
01302 if (prism2_hw_init(dev, initial) || prism2_hw_init2(dev, initial))
01303 return 1;
01304
01305 if (!local->pri_only && (!initial || !delayed_enable)) {
01306 if (!local->dev_enabled)
01307 prism2_callback(local, PRISM2_CALLBACK_ENABLE);
01308 local->dev_enabled = 1;
01309 return prism2_hw_enable(dev, initial);
01310 }
01311
01312 return 0;
01313 }
01314
01315
01316 static void prism2_hw_shutdown(struct net_device *dev, int no_disable)
01317 {
01318 struct hostap_interface *iface = dev->priv;
01319 local_info_t *local = iface->local;
01320
01321
01322 hfa384x_events_only_cmd(dev);
01323
01324 local->hw_ready = 0;
01325 if (local->dev_enabled)
01326 prism2_callback(local, PRISM2_CALLBACK_DISABLE);
01327 local->dev_enabled = 0;
01328
01329 if (local->func->card_present && !local->func->card_present(local)) {
01330 printk(KERN_DEBUG "%s: card already removed or not configured "
01331 "during shutdown\n", dev->name);
01332 return;
01333 }
01334
01335 if ((no_disable & HOSTAP_HW_NO_DISABLE) == 0 &&
01336 hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL, NULL))
01337 printk(KERN_WARNING "%s: Shutdown failed\n", dev_info);
01338
01339 hfa384x_disable_interrupts(dev);
01340
01341 if (no_disable & HOSTAP_HW_ENABLE_CMDCOMPL)
01342 hfa384x_events_only_cmd(dev);
01343 else
01344 prism2_clear_cmd_queue(local);
01345 }
01346
01347
01348 static void prism2_hw_reset(struct net_device *dev)
01349 {
01350 struct hostap_interface *iface = dev->priv;
01351 local_info_t *local = iface->local;
01352
01353 #if 0
01354 static long last_reset = 0;
01355
01356
01357
01358 if (time_before_eq(jiffies, last_reset + HZ))
01359 return;
01360 last_reset = jiffies;
01361 #endif
01362
01363 if (in_interrupt()) {
01364 printk(KERN_DEBUG "%s: driver bug - prism2_hw_reset() called "
01365 "in interrupt context\n", dev->name);
01366 return;
01367 }
01368
01369 if (local->hw_downloading)
01370 return;
01371
01372 if (local->hw_resetting) {
01373 printk(KERN_WARNING "%s: %s: already resetting card - "
01374 "ignoring reset request\n", dev_info, dev->name);
01375 return;
01376 }
01377
01378 local->hw_reset_tries++;
01379 if (local->hw_reset_tries > 10) {
01380 printk(KERN_WARNING "%s: too many reset tries, skipping\n",
01381 dev->name);
01382 return;
01383 }
01384
01385 printk(KERN_WARNING "%s: %s: resetting card\n", dev_info, dev->name);
01386 hfa384x_disable_interrupts(dev);
01387 local->hw_resetting = 1;
01388 if (local->func->cor_sreset) {
01389
01390
01391
01392
01393
01394
01395 disable_irq(dev->irq);
01396 local->func->cor_sreset(local);
01397 enable_irq(dev->irq);
01398 }
01399 prism2_hw_shutdown(dev, 1);
01400 prism2_hw_config(dev, 0);
01401 local->hw_resetting = 0;
01402
01403 #ifdef PRISM2_DOWNLOAD_SUPPORT
01404 if (local->dl_pri) {
01405 printk(KERN_DEBUG "%s: persistent download of primary "
01406 "firmware\n", dev->name);
01407 if (prism2_download_genesis(local, local->dl_pri) < 0)
01408 printk(KERN_WARNING "%s: download (PRI) failed\n",
01409 dev->name);
01410 }
01411
01412 if (local->dl_sec) {
01413 printk(KERN_DEBUG "%s: persistent download of secondary "
01414 "firmware\n", dev->name);
01415 if (prism2_download_volatile(local, local->dl_sec) < 0)
01416 printk(KERN_WARNING "%s: download (SEC) failed\n",
01417 dev->name);
01418 }
01419 #endif
01420 }
01421
01422
01423 static void prism2_schedule_reset(local_info_t *local)
01424 {
01425 PRISM2_SCHEDULE_TASK(&local->reset_queue);
01426 }
01427
01428
01429
01430
01431 static void handle_reset_queue(void *data)
01432 {
01433 local_info_t *local = (local_info_t *) data;
01434
01435 printk(KERN_DEBUG "%s: scheduled card reset\n", local->dev->name);
01436 prism2_hw_reset(local->dev);
01437
01438 if (netif_queue_stopped(local->dev)) {
01439 int i;
01440
01441 for (i = 0; i < PRISM2_TXFID_COUNT; i++)
01442 if (local->intransmitfid[i] == PRISM2_TXFID_EMPTY) {
01443 PDEBUG(DEBUG_EXTRA, "prism2_tx_timeout: "
01444 "wake up queue\n");
01445 hostap_netif_wake_queues(local->dev);
01446 break;
01447 }
01448 }
01449
01450 #ifndef NEW_MODULE_CODE
01451 MOD_DEC_USE_COUNT;
01452 #endif
01453 }
01454
01455
01456
01457
01458
01459 static void prism2_netif_update_trans_start(struct net_device *dev)
01460 {
01461 struct hostap_interface *iface = dev->priv;
01462 local_info_t *local = iface->local;
01463 struct list_head *ptr;
01464 unsigned long flags;
01465
01466 read_lock_irqsave(&local->iface_lock, flags);
01467 list_for_each(ptr, &local->hostap_interfaces) {
01468 iface = list_entry(ptr, struct hostap_interface, list);
01469 iface->dev->trans_start = jiffies;
01470 }
01471 read_unlock_irqrestore(&local->iface_lock, flags);
01472 }
01473
01474
01475 static int prism2_get_txfid_idx(local_info_t *local)
01476 {
01477 int idx, end;
01478 unsigned long flags;
01479
01480 spin_lock_irqsave(&local->txfidlock, flags);
01481 end = idx = local->next_txfid;
01482 do {
01483 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
01484 local->intransmitfid[idx] = PRISM2_TXFID_RESERVED;
01485 spin_unlock_irqrestore(&local->txfidlock, flags);
01486 return idx;
01487 }
01488 idx++;
01489 if (idx >= PRISM2_TXFID_COUNT)
01490 idx = 0;
01491 } while (idx != end);
01492 spin_unlock_irqrestore(&local->txfidlock, flags);
01493
01494 PDEBUG(DEBUG_EXTRA2, "prism2_get_txfid_idx: no room in txfid buf: "
01495 "packet dropped\n");
01496 local->stats.tx_dropped++;
01497
01498 return -1;
01499 }
01500
01501
01502
01503 static void prism2_transmit_cb(struct net_device *dev, void *context,
01504 u16 resp0, u16 res)
01505 {
01506 struct hostap_interface *iface = dev->priv;
01507 local_info_t *local = iface->local;
01508 int idx = (int) context;
01509
01510 if (res) {
01511 printk(KERN_DEBUG "%s: prism2_transmit_cb - res=0x%02x\n",
01512 dev->name, res);
01513 return;
01514 }
01515
01516 if (idx < 0 || idx >= PRISM2_TXFID_COUNT) {
01517 printk(KERN_DEBUG "%s: prism2_transmit_cb called with invalid "
01518 "idx=%d\n", dev->name, idx);
01519 return;
01520 }
01521
01522 if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
01523 printk(KERN_DEBUG "%s: driver bug: prism2_transmit_cb called "
01524 "with no pending transmit\n", dev->name);
01525 }
01526
01527 if (netif_queue_stopped(dev)) {
01528
01529
01530 hostap_netif_wake_queues(dev);
01531 }
01532
01533 spin_lock(&local->txfidlock);
01534
01535
01536
01537 local->intransmitfid[idx] = resp0;
01538
01539 PDEBUG(DEBUG_FID, "%s: prism2_cmd_ev: txfid[%d]=0x%04x, resp0=0x%04x, "
01540 "transmit_txfid=0x%04x\n", dev->name, idx, local->txfid[idx],
01541 resp0, local->intransmitfid[local->next_txfid]);
01542
01543 idx++;
01544 if (idx >= PRISM2_TXFID_COUNT)
01545 idx = 0;
01546 local->next_txfid = idx;
01547
01548
01549 do {
01550 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
01551 spin_unlock(&local->txfidlock);
01552 return;
01553 }
01554 idx++;
01555 if (idx >= PRISM2_TXFID_COUNT)
01556 idx = 0;
01557 } while (idx != local->next_txfid);
01558 spin_unlock(&local->txfidlock);
01559
01560
01561 hostap_netif_stop_queues(dev);
01562 }
01563
01564
01565
01566
01567 static int prism2_transmit(struct net_device *dev, int idx)
01568 {
01569 struct hostap_interface *iface = dev->priv;
01570 local_info_t *local = iface->local;
01571 int res;
01572
01573
01574
01575
01576
01577 if (test_and_set_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
01578 printk(KERN_DEBUG "%s: driver bug - prism2_transmit() called "
01579 "when previous TX was pending\n", dev->name);
01580 return -1;
01581 }
01582
01583
01584 hostap_netif_stop_queues(dev);
01585
01586
01587 res = hfa384x_cmd_callback(
01588 dev,
01589 HFA384X_CMDCODE_TRANSMIT | HFA384X_CMD_TX_RECLAIM,
01590 local->txfid[idx],
01591 prism2_transmit_cb, (void *) idx);
01592
01593 if (res) {
01594 struct net_device_stats *stats;
01595 printk(KERN_DEBUG "%s: prism2_transmit: CMDCODE_TRANSMIT "
01596 "failed (res=%d)\n", dev->name, res);
01597 stats = hostap_get_stats(dev);
01598 stats->tx_dropped++;
01599 hostap_netif_wake_queues(dev);
01600 return -1;
01601 }
01602 prism2_netif_update_trans_start(dev);
01603
01604
01605
01606
01607
01608 return 0;
01609 }
01610
01611
01612
01613 static void prism2_cmd_ev(struct net_device *dev)
01614 {
01615 struct hostap_interface *iface = dev->priv;
01616 local_info_t *local = iface->local;
01617 struct hostap_cmd_queue *entry = NULL;
01618
01619 spin_lock(&local->cmdlock);
01620 if (!list_empty(&local->cmd_queue)) {
01621 entry = list_entry(local->cmd_queue.next,
01622 struct hostap_cmd_queue, list);
01623 atomic_inc(&entry->usecnt);
01624 list_del_init(&entry->list);
01625 local->cmd_queue_len--;
01626
01627 if (!entry->issued) {
01628 printk(KERN_DEBUG "%s: Command completion event, but "
01629 "cmd not issued\n", dev->name);
01630 __hostap_cmd_queue_free(local, entry, 1);
01631 entry = NULL;
01632 }
01633 }
01634 spin_unlock(&local->cmdlock);
01635
01636 if (!entry) {
01637 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
01638 printk(KERN_DEBUG "%s: Command completion event, but no "
01639 "pending commands\n", dev->name);
01640 return;
01641 }
01642
01643 entry->resp0 = HFA384X_INW(HFA384X_RESP0_OFF);
01644 entry->res = (HFA384X_INW(HFA384X_STATUS_OFF) &
01645 (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) |
01646 BIT(9) | BIT(8))) >> 8;
01647 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
01648
01649
01650 if (entry->type == CMD_SLEEP) {
01651 entry->type = CMD_COMPLETED;
01652 wake_up_interruptible(&entry->compl);
01653 } else if (entry->type == CMD_CALLBACK) {
01654 if (entry->callback)
01655 entry->callback(dev, entry->context, entry->resp0,
01656 entry->res);
01657 } else {
01658 printk(KERN_DEBUG "%s: Invalid command completion type %d\n",
01659 dev->name, entry->type);
01660 }
01661 hostap_cmd_queue_free(local, entry, 1);
01662
01663
01664 entry = NULL;
01665 spin_lock(&local->cmdlock);
01666 if (!list_empty(&local->cmd_queue)) {
01667 entry = list_entry(local->cmd_queue.next,
01668 struct hostap_cmd_queue, list);
01669 if (entry->issuing) {
01670
01671
01672 entry = NULL;
01673 }
01674 if (entry)
01675 atomic_inc(&entry->usecnt);
01676 }
01677 spin_unlock(&local->cmdlock);
01678
01679 if (entry) {
01680
01681
01682 int res = hfa384x_cmd_issue(dev, entry);
01683 spin_lock(&local->cmdlock);
01684 __hostap_cmd_queue_free(local, entry, res);
01685 spin_unlock(&local->cmdlock);
01686 }
01687 }
01688
01689
01690 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
01691 static void prism2_tx_cb(struct net_device *dev, void *context,
01692 u16 resp0, u16 res)
01693 {
01694 struct hostap_interface *iface = dev->priv;
01695 local_info_t *local = iface->local;
01696 unsigned long addr;
01697 int buf_len = (int) context;
01698
01699 if (res) {
01700 printk(KERN_DEBUG "%s: prism2_tx_cb - res=0x%02x\n",
01701 dev->name, res);
01702 return;
01703 }
01704
01705 addr = virt_to_phys(local->bus_m0_buf);
01706 HFA384X_OUTW((addr & 0xffff0000) >> 16, HFA384X_PCI_M0_ADDRH_OFF);
01707 HFA384X_OUTW(addr & 0x0000ffff, HFA384X_PCI_M0_ADDRL_OFF);
01708 HFA384X_OUTW(buf_len / 2, HFA384X_PCI_M0_LEN_OFF);
01709 HFA384X_OUTW(HFA384X_PCI_CTL_TO_BAP, HFA384X_PCI_M0_CTL_OFF);
01710 }
01711 #endif
01712
01713 #define NUM_RADIOTAP_ELEMENTS 18
01714
01715 static int radiotap_elem_to_bytes[NUM_RADIOTAP_ELEMENTS] =
01716 {8,
01717 1,
01718 1,
01719 4,
01720 2,
01721 1,
01722 1,
01723 2,
01724 2,
01725 2,
01726 1,
01727 1,
01728 1,
01729 1,
01730 2,
01731 2,
01732 1,
01733 1,
01734 };
01735
01736
01737
01738
01739
01740
01741
01742
01743 static int rt_el_present(struct ieee80211_radiotap_header *th, u_int32_t element)
01744 {
01745 if (element > NUM_RADIOTAP_ELEMENTS)
01746 return 0;
01747 return th->it_present & (1 << element);
01748 }
01749
01750 static int rt_check_header(struct ieee80211_radiotap_header *th, int len)
01751 {
01752 int bytes = 0;
01753 int x = 0;
01754 if (th->it_version != 0)
01755 return 0;
01756
01757 if (th->it_len < sizeof(struct ieee80211_radiotap_header))
01758 return 0;
01759
01760 for (x = 0; x < NUM_RADIOTAP_ELEMENTS; x++) {
01761 if (rt_el_present(th, x))
01762 bytes += radiotap_elem_to_bytes[x];
01763 }
01764
01765 if (th->it_len < sizeof(struct ieee80211_radiotap_header) + bytes)
01766 return 0;
01767
01768 if (th->it_len > len)
01769 return 0;
01770
01771 return 1;
01772 }
01773
01774 static u_int8_t *rt_el_offset(struct ieee80211_radiotap_header *th, u_int32_t element) {
01775 unsigned int x = 0;
01776 u_int8_t *offset = ((u_int8_t *) th) + sizeof(struct ieee80211_radiotap_header);
01777 for (x = 0; x < NUM_RADIOTAP_ELEMENTS && x < element; x++) {
01778 if (rt_el_present(th, x))
01779 offset += radiotap_elem_to_bytes[x];
01780 }
01781
01782 return offset;
01783 }
01784
01785
01786 static int prism2_tx(struct sk_buff *skb, struct net_device *dev)
01787 {
01788 struct hostap_interface *iface = dev->priv;
01789 local_info_t *local = iface->local;
01790 int res, idx = -1, ret = 1, data_len = 0;
01791 struct hfa384x_tx_frame txdesc;
01792 u16 fc;
01793 enum { WDS_NO, WDS_OWN_FRAME, WDS_COMPLIANT_FRAME } use_wds = WDS_NO;
01794 struct net_device_stats *stats;
01795 u8 *wepbuf = NULL;
01796 int wepbuf_len = 0;
01797 void *sta = NULL;
01798 u8 *encaps_data = NULL;
01799 int encaps_len = 0, skip_header_bytes = 0;
01800 int to_assoc_ap = 0;
01801 int rate = 0;
01802
01803 prism2_callback(local, PRISM2_CALLBACK_TX_START);
01804 stats = hostap_get_stats(dev);
01805
01806 if ((local->func->card_present && !local->func->card_present(local)) ||
01807 !local->hw_ready || local->hw_downloading || local->pri_only) {
01808 if (net_ratelimit())
01809 printk(KERN_DEBUG "%s: prism2_tx: hw not ready - "
01810 "skipping\n", dev->name);
01811 ret = 0;
01812 goto fail;
01813 }
01814
01815 if (skb->len < 24) {
01816 printk(KERN_DEBUG "%s: prism2_tx: short skb (len=%d)\n",
01817 dev->name, skb->len);
01818 ret = 0;
01819 goto fail;
01820 }
01821
01822 if (local->dev != dev) {
01823 use_wds = (local->iw_mode == IW_MODE_MASTER &&
01824 !(local->wds_type & HOSTAP_WDS_STANDARD_FRAME)) ?
01825 WDS_OWN_FRAME : WDS_COMPLIANT_FRAME;
01826 if (dev == local->stadev) {
01827 to_assoc_ap = 1;
01828 use_wds = WDS_NO;
01829 } else if (dev == local->apdev) {
01830 printk(KERN_DEBUG "%s: prism2_tx: trying to use "
01831 "AP device with Ethernet net dev\n", dev->name);
01832 ret = 0;
01833 goto fail;
01834 }
01835 } else {
01836 if (local->iw_mode == IW_MODE_REPEAT) {
01837 printk(KERN_DEBUG "%s: prism2_tx: trying to use "
01838 "non-WDS link in Repeater mode\n", dev->name);
01839 ret = 0;
01840 goto fail;
01841 } else if (local->iw_mode == IW_MODE_INFRA &&
01842 (local->wds_type & HOSTAP_WDS_AP_CLIENT) &&
01843 memcmp(skb->data + ETH_ALEN, dev->dev_addr,
01844 ETH_ALEN) != 0) {
01845
01846
01847 use_wds = WDS_COMPLIANT_FRAME;
01848 }
01849 }
01850
01851 rate = 0;
01852 if (skb->len > sizeof(wlan_ng_prism2_header)) {
01853 pull_prism2_header(skb);
01854 }
01855
01856 if (skb->len > sizeof(struct click_wifi_extra)) {
01857 pull_wifi_extra_header(skb);
01858 }
01859 struct ieee80211_radiotap_header *th = (struct ieee80211_radiotap_header *)
01860 skb->data;
01861 if (rt_check_header(th, skb->len)) {
01862 if (rt_el_present(th, IEEE80211_RADIOTAP_RATE)) {
01863 rate = *((u_int8_t *) rt_el_offset(th,
01864 IEEE80211_RADIOTAP_RATE));
01865 }
01866 skb_pull(skb, th->it_len);
01867 }
01868
01869
01870 struct click_wifi_extra *ceh = (struct click_wifi_extra *) (skb->cb + EXTRA_HEADER_CB_OFFSET);
01871
01872 if (ceh->magic == WIFI_EXTRA_MAGIC && ceh->rate) {
01873 rate = ceh->rate;
01874 }
01875
01876 if (skb->len < sizeof(txdesc)) {
01877 printk(KERN_DEBUG "%s: prism2_tx: short ETH_P_HOSTAP "
01878 "skb\n", dev->name);
01879 ret = 0;
01880 goto fail;
01881 }
01882
01883 memset(&txdesc, 0, sizeof(txdesc));
01884 memcpy(&txdesc.frame_control, skb->data, 24);
01885 skb_pull(skb, 24);
01886
01887 data_len = skb->len;
01888
01889 fc = le16_to_cpu(txdesc.frame_control);
01890
01891 txdesc.tx_control = __cpu_to_le16(local->tx_control);
01892 txdesc.data_len = __cpu_to_le16(data_len);
01893 txdesc.len = __cpu_to_be16(data_len);
01894
01895 switch (rate) {
01896
01897
01898
01899
01900
01901
01902 case 0:
01903 txdesc.tx_rate = 0x00;
01904 break;
01905 case 2:
01906 txdesc.tx_rate = 0x0A;
01907 break;
01908 case 4:
01909 txdesc.tx_rate = 0x14;
01910 break;
01911 case 11:
01912 txdesc.tx_rate = 0x37;
01913 break;
01914 case 22:
01915 txdesc.tx_rate = 0x6E;
01916 break;
01917 default:
01918 printk(KERN_WARNING "%s: invalid attempt for packet rate %d\n",
01919 local->dev->name, rate);
01920 txdesc.tx_rate = 0;
01921 }
01922
01923
01924 skb->dev = dev;
01925
01926
01927 idx = prism2_get_txfid_idx(local);
01928 if (idx < 0)
01929 goto fail;
01930
01931 if (local->frame_dump & PRISM2_DUMP_TX_HDR)
01932 hostap_dump_tx_header(dev->name, &txdesc);
01933
01934 spin_lock(&local->baplock);
01935 res = hfa384x_setup_bap(dev, BAP0, local->txfid[idx], 0);
01936
01937 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
01938 if (!res && skb->len >= local->bus_master_threshold_tx) {
01939 u8 *pos;
01940 int buf_len;
01941
01942 local->bus_m0_tx_idx = idx;
01943
01944
01945
01946
01947
01948
01949
01950
01951 hostap_netif_stop_queues(dev);
01952
01953 spin_unlock(&local->baplock);
01954
01955
01956 pos = local->bus_m0_buf;
01957 memcpy(pos, &txdesc, sizeof(txdesc));
01958 pos += sizeof(txdesc);
01959
01960 if (!wepbuf) {
01961 if (encaps_len > 0) {
01962 memcpy(pos, encaps_data, encaps_len);
01963 pos += encaps_len;
01964 }
01965 memcpy(pos, skb->data + skip_header_bytes,
01966 skb->len - skip_header_bytes);
01967 pos += skb->len - skip_header_bytes;
01968 }
01969 if (!wepbuf && use_wds == WDS_OWN_FRAME) {
01970
01971
01972 memcpy(pos, skb->data + ETH_ALEN, ETH_ALEN);
01973 pos += ETH_ALEN;
01974 }
01975
01976 if (wepbuf) {
01977 memcpy(pos, wepbuf, wepbuf_len);
01978 pos += wepbuf_len;
01979 }
01980
01981 buf_len = pos - local->bus_m0_buf;
01982 if (buf_len & 1)
01983 buf_len++;
01984
01985 #ifdef PRISM2_ENABLE_BEFORE_TX_BUS_MASTER
01986
01987
01988 if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_ENABLE, 0,
01989 prism2_tx_cb, (void *) buf_len)) {
01990 printk(KERN_DEBUG "%s: TX: enable port0 failed\n",
01991 dev->name);
01992 }
01993 #else
01994 prism2_tx_cb(dev, (void *) buf_len, 0, 0);
01995 #endif
01996
01997
01998
01999
02000 goto tx_stats;
02001 }
02002 #endif
02003
02004 if (!res)
02005 res = hfa384x_to_bap(dev, BAP0, &txdesc, sizeof(txdesc));
02006 if (!res && !wepbuf && encaps_len > 0)
02007 res = hfa384x_to_bap(dev, BAP0, encaps_data, encaps_len);
02008 if (!res && !wepbuf && use_wds != WDS_OWN_FRAME)
02009 res = hfa384x_to_bap(dev, BAP0, skb->data + skip_header_bytes,
02010 skb->len - skip_header_bytes);
02011 else if (!res && !wepbuf && use_wds == WDS_OWN_FRAME) {
02012 int wlen, is_odd;
02013
02014 wlen = skb->len - skip_header_bytes;
02015 is_odd = wlen & 1;
02016
02017 if (is_odd)
02018 wlen--;
02019
02020 res = hfa384x_to_bap(dev, BAP0, skb->data + skip_header_bytes,
02021 wlen);
02022
02023
02024 if (!res && is_odd) {
02025 char tmpbuf[ETH_ALEN + 1];
02026 tmpbuf[0] = *(skb->data + skb->len - 1);
02027 memcpy(tmpbuf + 1, skb->data + ETH_ALEN, ETH_ALEN);
02028 res = hfa384x_to_bap(dev, BAP0, tmpbuf, ETH_ALEN + 1);
02029 } else if (!res) {
02030 res = hfa384x_to_bap(dev, BAP0, skb->data + ETH_ALEN,
02031 ETH_ALEN);
02032 }
02033 }
02034
02035 if (!res && wepbuf)
02036 res = hfa384x_to_bap(dev, BAP0, wepbuf, wepbuf_len);
02037 spin_unlock(&local->baplock);
02038
02039 if (!res)
02040 res = prism2_transmit(dev, idx);
02041 if (res) {
02042 printk(KERN_DEBUG "%s: prism2_tx - to BAP0 failed\n",
02043 dev->name);
02044 local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
02045 PRISM2_SCHEDULE_TASK(&local->reset_queue);
02046 ret = 0;
02047 goto fail;
02048 }
02049
02050 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
02051 tx_stats:
02052 #endif
02053 stats->tx_packets++;
02054 stats->tx_bytes += data_len + 36;
02055
02056 ret = 0;
02057
02058 fail:
02059 if (wepbuf)
02060 kfree(wepbuf);
02061
02062 if (!ret)
02063 dev_kfree_skb(skb);
02064
02065
02066 if (sta)
02067 hostap_handle_sta_release(sta);
02068
02069 prism2_callback(local, PRISM2_CALLBACK_TX_END);
02070 return ret;
02071 }
02072
02073
02074
02075 static int prism2_tx_80211(struct sk_buff *skb, struct net_device *dev)
02076 {
02077 struct hostap_interface *iface = dev->priv;
02078 local_info_t *local = iface->local;
02079 struct hfa384x_tx_frame txdesc;
02080 int hdr_len, data_len, ret = 1, idx, res;
02081 u16 fc, tx_control;
02082
02083 if ((local->func->card_present && !local->func->card_present(local)) ||
02084 !local->hw_ready || local->hw_downloading || local->pri_only) {
02085 printk(KERN_DEBUG "%s: prism2_tx_80211: hw not ready - "
02086 "skipping\n", dev->name);
02087 ret = 0;
02088 local->apdevstats.tx_dropped++;
02089 goto fail;
02090 }
02091
02092 if (skb->len < 24) {
02093 printk(KERN_DEBUG "%s: prism2_tx_80211: short skb (len=%d)\n",
02094 dev->name, skb->len);
02095 ret = 0;
02096 local->apdevstats.tx_dropped++;
02097 goto fail;
02098 }
02099
02100 memset(&txdesc, 0, sizeof(txdesc));
02101
02102
02103
02104
02105 hdr_len = 24;
02106 memcpy(&txdesc.frame_control, skb->data, hdr_len);
02107 fc = le16_to_cpu(txdesc.frame_control);
02108 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
02109 (fc & WLAN_FC_FROMDS) && (fc & WLAN_FC_TODS) && skb->len >= 30) {
02110
02111 memcpy(txdesc.addr4, skb->data + hdr_len, ETH_ALEN);
02112 hdr_len += ETH_ALEN;
02113 }
02114
02115 tx_control = local->tx_control;
02116
02117
02118
02119 if (((fc & WLAN_FC_PVER) == BIT(1)) &&
02120 local->ap && local->ap->tx_callback_idx) {
02121 tx_control |= HFA384X_TX_CTRL_TX_OK;
02122 txdesc.sw_support = cpu_to_le16(local->ap->tx_callback_idx);
02123
02124
02125 fc &= ~WLAN_FC_PVER;
02126 txdesc.frame_control = cpu_to_le16(fc);
02127 }
02128 txdesc.tx_control = cpu_to_le16(tx_control);
02129
02130 data_len = skb->len - hdr_len;
02131 txdesc.data_len = __cpu_to_le16(data_len);
02132 txdesc.len = __cpu_to_be16(data_len);
02133
02134
02135
02136
02137
02138
02139
02140
02141 if (hostap_handle_sta_tx(local, skb, &txdesc, 0, 0, NULL, NULL) ==
02142 AP_TX_BUFFERED &&
02143 (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
02144 (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_AUTH &&
02145 WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ASSOC_RESP &&
02146 WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_REASSOC_RESP))) {
02147
02148
02149 ret = 0;
02150 goto tx_exit;
02151 }
02152
02153 idx = prism2_get_txfid_idx(local);
02154 if (idx < 0) {
02155 local->apdevstats.tx_dropped++;
02156 goto fail;
02157 }
02158
02159 spin_lock(&local->baplock);
02160 res = hfa384x_setup_bap(dev, BAP0, local->txfid[idx], 0);
02161 if (!res)
02162 res = hfa384x_to_bap(dev, BAP0, &txdesc, sizeof(txdesc));
02163 if (!res)
02164 res = hfa384x_to_bap(dev, BAP0, skb->data + hdr_len,
02165 skb->len - hdr_len);
02166 spin_unlock(&local->baplock);
02167
02168 if (!res)
02169 res = prism2_transmit(dev, idx);
02170 if (res) {
02171 printk(KERN_DEBUG "%s: prism2_tx_80211 - to BAP0 failed\n",
02172 dev->name);
02173 local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
02174 PRISM2_SCHEDULE_TASK(&local->reset_queue);
02175 local->apdevstats.tx_dropped++;
02176 ret = 0;
02177 goto fail;
02178 }
02179
02180 ret = 0;
02181
02182 local->apdevstats.tx_packets++;
02183 local->apdevstats.tx_bytes += skb->len;
02184
02185 fail:
02186 if (!ret)
02187 dev_kfree_skb(skb);
02188 tx_exit:
02189 return ret;
02190 }
02191
02192
02193
02194
02195
02196
02197
02198 #define EXTRA_FID_READ_TESTS
02199
02200 static inline u16 prism2_read_fid_reg(struct net_device *dev, u16 reg)
02201 {
02202 #ifdef EXTRA_FID_READ_TESTS
02203 u16 val, val2, val3;
02204 int i;
02205
02206 for (i = 0; i < 10; i++) {
02207 val = HFA384X_INW(reg);
02208 val2 = HFA384X_INW(reg);
02209 val3 = HFA384X_INW(reg);
02210
02211 if (val == val2 && val == val3)
02212 return val;
02213
02214 printk(KERN_DEBUG "%s: detected fid change (try=%d, reg=%04x):"
02215 " %04x %04x %04x\n",
02216 dev->name, i, reg, val, val2, val3);
02217 if ((val == val2 || val == val3) && val != 0)
02218 return val;
02219 if (val2 == val3 && val2 != 0)
02220 return val2;
02221 }
02222 printk(KERN_WARNING "%s: Uhhuh.. could not read good fid from reg "
02223 "%04x (%04x %04x %04x)\n", dev->name, reg, val, val2, val3);
02224 return val;
02225 #else
02226 return HFA384X_INW(reg);
02227 #endif
02228 }
02229
02230
02231
02232 static void prism2_rx(local_info_t *local)
02233 {
02234 struct net_device *dev = local->dev;
02235 int res, rx_pending = 0;
02236 u16 len, hdr_len, rxfid, status, macport;
02237 struct net_device_stats *stats;
02238 struct hfa384x_rx_frame rxdesc;
02239 struct sk_buff *skb = NULL;
02240
02241 prism2_callback(local, PRISM2_CALLBACK_RX_START);
02242 stats = hostap_get_stats(dev);
02243
02244 rxfid = prism2_read_fid_reg(dev, HFA384X_RXFID_OFF);
02245 #ifndef final_version
02246 if (rxfid == 0) {
02247 rxfid = HFA384X_INW(HFA384X_RXFID_OFF);
02248 printk(KERN_DEBUG "prism2_rx: rxfid=0 (next 0x%04x)\n",
02249 rxfid);
02250 if (rxfid == 0) {
02251 PRISM2_SCHEDULE_TASK(&local->reset_queue);
02252 goto rx_dropped;
02253 }
02254
02255 }
02256 #endif
02257
02258 spin_lock(&local->baplock);
02259 res = hfa384x_setup_bap(dev, BAP0, rxfid, 0);
02260 if (!res)
02261 res = hfa384x_from_bap(dev, BAP0, &rxdesc, sizeof(rxdesc));
02262
02263 if (res) {
02264 spin_unlock(&local->baplock);
02265 printk(KERN_DEBUG "%s: copy from BAP0 failed %d\n", dev->name,
02266 res);
02267 if (res == -ETIMEDOUT) {
02268 PRISM2_SCHEDULE_TASK(&local->reset_queue);
02269 }
02270 goto rx_dropped;
02271 }
02272
02273 len = le16_to_cpu(rxdesc.data_len);
02274 hdr_len = sizeof(rxdesc);
02275 status = le16_to_cpu(rxdesc.status);
02276 macport = (status >> 8) & 0x07;
02277
02278
02279
02280
02281
02282 if (len > PRISM2_DATA_MAXLEN + 8 ) {
02283 if (macport == 7 && local->iw_mode == IW_MODE_MONITOR) {
02284 if (len >= (u16) -14) {
02285 hdr_len -= 65535 - len;
02286 hdr_len--;
02287 }
02288 len = 0;
02289 } else {
02290 spin_unlock(&local->baplock);
02291 printk(KERN_DEBUG "%s: Received frame with invalid "
02292 "length 0x%04x\n", dev->name, len);
02293 hostap_dump_rx_header(dev->name, &rxdesc);
02294 goto rx_dropped;
02295 }
02296 }
02297
02298
02299 skb = dev_alloc_skb(len + hdr_len + sizeof(wlan_ng_prism2_header));
02300 skb_reserve(skb, sizeof(wlan_ng_prism2_header));
02301
02302 if (!skb) {
02303 spin_unlock(&local->baplock);
02304 printk(KERN_DEBUG "%s: RX failed to allocate skb\n",
02305 dev->name);
02306 goto rx_dropped;
02307 }
02308 skb->dev = dev;
02309 memcpy(skb_put(skb, hdr_len), &rxdesc, hdr_len);
02310
02311 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
02312 if (len >= local->bus_master_threshold_rx) {
02313 unsigned long addr;
02314
02315 hfa384x_events_no_bap1(dev);
02316
02317 local->rx_skb = skb;
02318
02319
02320 addr = virt_to_phys(skb_put(skb, len));
02321 HFA384X_OUTW((addr & 0xffff0000) >> 16,
02322 HFA384X_PCI_M0_ADDRH_OFF);
02323 HFA384X_OUTW(addr & 0x0000ffff, HFA384X_PCI_M0_ADDRL_OFF);
02324 if (len & 1)
02325 len++;
02326 HFA384X_OUTW(len / 2, HFA384X_PCI_M0_LEN_OFF);
02327 HFA384X_OUTW(HFA384X_PCI_CTL_FROM_BAP, HFA384X_PCI_M0_CTL_OFF);
02328
02329
02330
02331
02332 rx_pending = 1;
02333
02334
02335
02336
02337 spin_unlock(&local->baplock);
02338 } else
02339 #endif
02340 {
02341 if (len > 0)
02342 res = hfa384x_from_bap(dev, BAP0, skb_put(skb, len),
02343 len);
02344 spin_unlock(&local->baplock);
02345 if (res) {
02346 printk(KERN_DEBUG "%s: RX failed to read "
02347 "frame data\n", dev->name);
02348 goto rx_dropped;
02349 }
02350
02351 skb_queue_tail(&local->rx_list, skb);
02352 tasklet_schedule(&local->rx_tasklet);
02353 }
02354
02355 rx_exit:
02356 prism2_callback(local, PRISM2_CALLBACK_RX_END);
02357 if (!rx_pending) {
02358 HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
02359 }
02360
02361 return;
02362
02363 rx_dropped:
02364 stats->rx_dropped++;
02365 if (skb)
02366 dev_kfree_skb(skb);
02367 goto rx_exit;
02368 }
02369
02370 struct hostap_rx_radiotap_header {
02371 struct ieee80211_radiotap_header wr_ihdr;
02372 u_int8_t wr_flags;
02373 u_int8_t wr_rate;
02374 u_int16_t wr_chan_freq;
02375 u_int16_t wr_chan_flags;
02376 u_int8_t wr_antenna;
02377 u_int8_t wr_antsignal;
02378 u_int16_t wr_rx_flags;
02379 };
02380
02381
02382
02383
02384 #define ATH_RX_RADIOTAP_PRESENT ( \
02385 (1 << IEEE80211_RADIOTAP_FLAGS) | \
02386 (1 << IEEE80211_RADIOTAP_RATE) | \
02387 (1 << IEEE80211_RADIOTAP_CHANNEL) | \
02388 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
02389 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
02390 (1 << IEEE80211_RADIOTAP_RX_FLAGS) | \
02391 0)
02392
02393
02394
02395 static void hostap_rx_skb(local_info_t *local, struct sk_buff *skb)
02396 {
02397 struct hfa384x_rx_frame *rxdesc;
02398 struct net_device *dev = skb->dev;
02399 int hdrlen, rx_hdrlen;
02400
02401 rx_hdrlen = sizeof(*rxdesc);
02402 if (skb->len < sizeof(*rxdesc)) {
02403
02404 if (local->iw_mode == IW_MODE_MONITOR &&
02405 skb->len >= sizeof(*rxdesc) - 30) {
02406 rx_hdrlen = skb->len;
02407 } else {
02408 dev_kfree_skb(skb);
02409 return;
02410 }
02411 }
02412
02413 rxdesc = (struct hfa384x_rx_frame *) skb->data;
02414
02415 if (local->frame_dump & PRISM2_DUMP_RX_HDR &&
02416 skb->len >= sizeof(*rxdesc))
02417 hostap_dump_rx_header(dev->name, rxdesc);
02418
02419 if (skb->len > PRISM2_DATA_MAXLEN) {
02420 printk(KERN_DEBUG "%s: RX: len(%d) > MAX(%d)\n",
02421 dev->name, skb->len, PRISM2_DATA_MAXLEN);
02422 goto drop;
02423 }
02424
02425 if (1) {
02426
02427 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(rxdesc->frame_control));
02428 if (hdrlen > rx_hdrlen)
02429 hdrlen = rx_hdrlen;
02430
02431 memmove(skb_pull(skb, rx_hdrlen - hdrlen),
02432 &rxdesc->frame_control, hdrlen);
02433 }
02434
02435 {
02436 if (skb_headroom(skb) < sizeof(struct hostap_rx_radiotap_header) &&
02437 pskb_expand_head(skb, sizeof(struct hostap_rx_radiotap_header), 0, GFP_ATOMIC)) {
02438 printk (KERN_WARNING "couldn't pskb_expand_head\n");
02439 goto drop;
02440 }
02441
02442 struct hostap_rx_radiotap_header *th;
02443 th = (struct hostap_rx_radiotap_header *) skb_push(skb, sizeof(struct hostap_rx_radiotap_header));
02444 memset(th, 0, sizeof(struct hostap_rx_radiotap_header));
02445 th->wr_ihdr.it_version = 0;
02446 th->wr_ihdr.it_len = sizeof(struct hostap_rx_radiotap_header);
02447 th->wr_ihdr.it_present = ATH_RX_RADIOTAP_PRESENT;
02448 th->wr_flags = 0;
02449 th->wr_rate = rxdesc->rate/5;
02450 th->wr_chan_freq = 0;
02451 th->wr_chan_flags = 0;
02452 th->wr_antenna = 0;
02453 th->wr_antsignal = rxdesc->signal;
02454 th->wr_rx_flags = 0;
02455 if (le16_to_cpu(rxdesc->status) & HFA384X_RX_STATUS_FCSERR)
02456 th->wr_rx_flags |= IEEE80211_RADIOTAP_F_RX_BADFCS;
02457
02458 }
02459
02460 if (skb) {
02461 struct net_device_stats *stats;
02462 stats = hostap_get_stats(dev);
02463 stats->rx_packets++;
02464 stats->rx_bytes += skb->len;
02465 skb->protocol = eth_type_trans(skb, dev);
02466 skb->dev = dev;
02467 netif_rx(skb);
02468 }
02469 return;
02470
02471 drop:
02472 dev_kfree_skb(skb);
02473 }
02474
02475
02476
02477 static void hostap_rx_tasklet(unsigned long data)
02478 {
02479 local_info_t *local = (local_info_t *) data;
02480 struct sk_buff *skb;
02481
02482 while ((skb = skb_dequeue(&local->rx_list)) != NULL)
02483 hostap_rx_skb(local, skb);
02484 }
02485
02486
02487
02488 static void prism2_alloc_ev(struct net_device *dev)
02489 {
02490 struct hostap_interface *iface = dev->priv;
02491 local_info_t *local = iface->local;
02492 int idx;
02493 u16 fid;
02494
02495 fid = prism2_read_fid_reg(dev, HFA384X_ALLOCFID_OFF);
02496
02497 PDEBUG(DEBUG_FID, "FID: interrupt: ALLOC - fid=0x%04x\n", fid);
02498
02499 spin_lock(&local->txfidlock);
02500 idx = local->next_alloc;
02501
02502 do {
02503 if (local->txfid[idx] == fid) {
02504 PDEBUG(DEBUG_FID, "FID: found matching txfid[%d]\n",
02505 idx);
02506
02507 #ifndef final_version
02508 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY)
02509 printk("Already released txfid found at idx "
02510 "%d\n", idx);
02511 if (local->intransmitfid[idx] == PRISM2_TXFID_RESERVED)
02512 printk("Already reserved txfid found at idx "
02513 "%d\n", idx);
02514 #endif
02515 local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
02516 idx++;
02517 local->next_alloc = idx >= PRISM2_TXFID_COUNT ? 0 :
02518 idx;
02519
02520 if (!test_bit(HOSTAP_BITS_TRANSMIT, &local->bits) &&
02521 netif_queue_stopped(dev))
02522 hostap_netif_wake_queues(dev);
02523
02524 spin_unlock(&local->txfidlock);
02525 return;
02526 }
02527
02528 idx++;
02529 if (idx >= PRISM2_TXFID_COUNT)
02530 idx = 0;
02531 } while (idx != local->next_alloc);
02532
02533 printk(KERN_WARNING "%s: could not find matching txfid (0x%04x, new "
02534 "read 0x%04x) for alloc event\n", dev->name, fid,
02535 HFA384X_INW(HFA384X_ALLOCFID_OFF));
02536 printk(KERN_DEBUG "TXFIDs:");
02537 for (idx = 0; idx < PRISM2_TXFID_COUNT; idx++)
02538 printk(" %04x[%04x]", local->txfid[idx],
02539 local->intransmitfid[idx]);
02540 printk("\n");
02541 spin_unlock(&local->txfidlock);
02542
02543
02544
02545
02546
02547 }
02548
02549
02550
02551 static void hostap_tx_callback(local_info_t *local,
02552 struct hfa384x_tx_frame *txdesc, int ok,
02553 char *payload)
02554 {
02555 u16 sw_support, hdrlen, len;
02556 struct sk_buff *skb;
02557 struct hostap_tx_callback_info *cb;
02558
02559
02560 if (memcmp(txdesc->addr2, local->dev->dev_addr, ETH_ALEN)) {
02561 return;
02562 }
02563
02564 sw_support = le16_to_cpu(txdesc->sw_support);
02565
02566 spin_lock(&local->lock);
02567 cb = local->tx_callback;
02568 while (cb != NULL && cb->idx != sw_support)
02569 cb = cb->next;
02570 spin_unlock(&local->lock);
02571
02572 if (cb == NULL) {
02573 printk(KERN_DEBUG "%s: could not find TX callback (idx %d)\n",
02574 local->dev->name, sw_support);
02575 return;
02576 }
02577
02578 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(txdesc->frame_control));
02579 len = le16_to_cpu(txdesc->data_len);
02580 skb = dev_alloc_skb(hdrlen + len);
02581 if (skb == NULL) {
02582 printk(KERN_DEBUG "%s: hostap_tx_callback failed to allocate "
02583 "skb\n", local->dev->name);
02584 return;
02585 }
02586
02587 memcpy(skb_put(skb, hdrlen), (void *) &txdesc->frame_control, hdrlen);
02588 if (payload)
02589 memcpy(skb_put(skb, len), payload, len);
02590
02591 skb->dev = local->dev;
02592 skb->mac.raw = skb->data;
02593
02594 cb->func(skb, ok, cb->data);
02595 }
02596
02597
02598
02599 static int hostap_tx_compl_read(local_info_t *local, int error,
02600 struct hfa384x_tx_frame *txdesc,
02601 char **payload)
02602 {
02603 u16 fid, len;
02604 int res, ret = 0;
02605 struct net_device *dev = local->dev;
02606
02607 fid = prism2_read_fid_reg(dev, HFA384X_TXCOMPLFID_OFF);
02608
02609 PDEBUG(DEBUG_FID, "interrupt: TX (err=%d) - fid=0x%04x\n", fid, error);
02610
02611 spin_lock(&local->baplock);
02612 res = hfa384x_setup_bap(dev, BAP0, fid, 0);
02613 if (!res)
02614 res = hfa384x_from_bap(dev, BAP0, txdesc, sizeof(*txdesc));
02615 if (res) {
02616 PDEBUG(DEBUG_EXTRA, "%s: TX (err=%d) - fid=0x%04x - could not "
02617 "read txdesc\n", dev->name, error, fid);
02618 if (res == -ETIMEDOUT) {
02619 PRISM2_SCHEDULE_TASK(&local->reset_queue);
02620 }
02621 ret = -1;
02622 goto fail;
02623 }
02624
02625 if (1 || txdesc->sw_support) {
02626 len = le16_to_cpu(txdesc->data_len);
02627 if (len < PRISM2_DATA_MAXLEN) {
02628 *payload = (char *) kmalloc(len, GFP_ATOMIC);
02629 if (*payload == NULL ||
02630 hfa384x_from_bap(dev, BAP0, *payload, len)) {
02631 PDEBUG(DEBUG_EXTRA, "%s: could not read TX "
02632 "frame payload\n", dev->name);
02633 kfree(*payload);
02634 *payload = NULL;
02635 ret = -1;
02636 goto fail;
02637 }
02638 }
02639 }
02640
02641 fail:
02642 spin_unlock(&local->baplock);
02643
02644 return ret;
02645 }
02646
02647
02648 #define HOSTAP_TX_RADIOTAP_PRESENT ( \
02649 (1 << IEEE80211_RADIOTAP_FLAGS) | \
02650 (1 << IEEE80211_RADIOTAP_RATE) | \
02651 (1 << IEEE80211_RADIOTAP_DBM_TX_POWER) | \
02652 (1 << IEEE80211_RADIOTAP_ANTENNA) | \
02653 (1 << IEEE80211_RADIOTAP_TX_FLAGS) | \
02654 (1 << IEEE80211_RADIOTAP_RTS_RETRIES) | \
02655 (1 << IEEE80211_RADIOTAP_DATA_RETRIES) | \
02656 0)
02657
02658 struct hostap_tx_radiotap_header {
02659 struct ieee80211_radiotap_header wt_ihdr;
02660 u_int8_t wt_flags;
02661 u_int8_t wt_rate;
02662 u_int8_t wt_txpower;
02663 u_int8_t wt_antenna;
02664 u_int16_t wt_tx_flags;
02665 u_int8_t wt_rts_retries;
02666 u_int8_t wt_data_retries;
02667
02668 };
02669
02670
02671
02672 static void click_tx_callback(local_info_t *local,
02673 struct hfa384x_tx_frame *txdesc, int success,
02674 char *payload)
02675 {
02676 u16 sw_support, hdrlen, len;
02677 struct sk_buff *skb;
02678
02679
02680 if (memcmp(txdesc->addr2, local->dev->dev_addr, ETH_ALEN)) {
02681 return;
02682 }
02683
02684 sw_support = le16_to_cpu(txdesc->sw_support);
02685
02686
02687
02688 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(txdesc->frame_control));
02689 len = le16_to_cpu(txdesc->data_len);
02690
02691 skb = dev_alloc_skb(hdrlen + len + sizeof(wlan_ng_prism2_header));
02692 if (skb == NULL) {
02693 printk(KERN_DEBUG "%s: hostap_tx_callback failed to allocate "
02694 "skb\n", local->dev->name);
02695 return;
02696 }
02697
02698 skb_reserve(skb, sizeof(wlan_ng_prism2_header));
02699
02700
02701 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(txdesc->frame_control));
02702 memcpy(skb_put(skb, hdrlen), &txdesc->frame_control, hdrlen);
02703
02704 if (payload) {
02705 memcpy(skb_put(skb, len), payload, len);
02706 }
02707
02708
02709 skb->dev = local->dev;
02710 skb->mac.raw = skb->data;
02711
02712 memset(skb->cb, 0, sizeof(skb->cb));
02713
02714 if (PUSH_PRISM) {
02715 push_prism2_header(local->dev, skb,
02716 skb->len,
02717 0,
02718 txdesc->tx_rate/5,
02719 1,
02720 0);
02721 } else {
02722 struct hostap_tx_radiotap_header *th;
02723
02724 if (skb_headroom(skb) < sizeof(struct hostap_tx_radiotap_header) &&
02725 pskb_expand_head(skb,
02726 sizeof(struct hostap_tx_radiotap_header),
02727 0, GFP_ATOMIC)) {
02728 dev_kfree_skb(skb);
02729 return;
02730 }
02731
02732 th = (struct hostap_tx_radiotap_header *) skb_push(skb, sizeof(struct hostap_tx_radiotap_header));
02733 memset(th, 0, sizeof(struct hostap_tx_radiotap_header));
02734 th->wt_ihdr.it_version = 0;
02735 th->wt_ihdr.it_len = sizeof(struct hostap_tx_radiotap_header);
02736 th->wt_ihdr.it_present = HOSTAP_TX_RADIOTAP_PRESENT;
02737 th->wt_flags = 0;
02738 th->wt_rate = txdesc->tx_rate/5;
02739 th->wt_txpower = 0;
02740 th->wt_antenna = 0;
02741 th->wt_tx_flags = 0;
02742 if (!success)
02743 th->wt_tx_flags |= IEEE80211_RADIOTAP_F_TX_FAIL;
02744 th->wt_rts_retries = 0;
02745 th->wt_data_retries = txdesc->retry_count;
02746 }
02747 netif_rx(skb);
02748 }
02749
02750
02751
02752 static void prism2_tx_ev(local_info_t *local)
02753 {
02754 struct net_device *dev = local->dev;
02755 char *payload = NULL;
02756 struct hfa384x_tx_frame txdesc;
02757
02758 if (hostap_tx_compl_read(local, 0, &txdesc, &payload))
02759 goto fail;
02760
02761
02762
02763 click_tx_callback(local, &txdesc, 1, payload);
02764
02765
02766 if (local->frame_dump & PRISM2_DUMP_TX_HDR) {
02767 PDEBUG(DEBUG_EXTRA, "%s: TX - status=0x%04x "
02768 "retry_count=%d tx_rate=%d seq_ctrl=%d "
02769 "duration_id=%d\n",
02770 dev->name, le16_to_cpu(txdesc.status),
02771 txdesc.retry_count, txdesc.tx_rate,
02772 le16_to_cpu(txdesc.seq_ctrl),
02773 le16_to_cpu(txdesc.duration_id));
02774 }
02775
02776 if (0 && txdesc.sw_support)
02777 hostap_tx_callback(local, &txdesc, 1, payload);
02778 kfree(payload);
02779
02780 fail:
02781 HFA384X_OUTW(HFA384X_EV_TX, HFA384X_EVACK_OFF);
02782 }
02783
02784
02785
02786 static void hostap_sta_tx_exc_tasklet(unsigned long data)
02787 {
02788 local_info_t *local = (local_info_t *) data;
02789 struct sk_buff *skb;
02790
02791 while ((skb = skb_dequeue(&local->sta_tx_exc_list)) != NULL) {
02792 struct hfa384x_tx_frame *txdesc =
02793 (struct hfa384x_tx_frame *) skb->data;
02794 hostap_handle_sta_tx_exc(local, txdesc);
02795 dev_kfree_skb(skb);
02796 }
02797 }
02798
02799
02800
02801 static void prism2_txexc(local_info_t *local)
02802 {
02803 struct net_device *dev = local->dev;
02804 u16 status, fc;
02805 int show_dump, res;
02806 char *payload = NULL;
02807 struct hfa384x_tx_frame txdesc;
02808
02809 show_dump = local->frame_dump & PRISM2_DUMP_TXEXC_HDR;
02810 local->stats.tx_errors++;
02811
02812 res = hostap_tx_compl_read(local, 1, &txdesc, &payload);
02813 HFA384X_OUTW(HFA384X_EV_TXEXC, HFA384X_EVACK_OFF);
02814 if (res)
02815 return;
02816
02817 status = le16_to_cpu(txdesc.status);
02818
02819
02820
02821
02822 click_tx_callback(local, &txdesc, 0, payload);
02823
02824
02825 #if WIRELESS_EXT > 13
02826
02827
02828
02829
02830 if (status & (HFA384X_TX_STATUS_RETRYERR | HFA384X_TX_STATUS_AGEDERR))
02831 {
02832 union iwreq_data wrqu;
02833
02834
02835 memcpy(wrqu.addr.sa_data, txdesc.addr1, ETH_ALEN);
02836 wrqu.addr.sa_family = ARPHRD_ETHER;
02837 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
02838 } else
02839 show_dump = 1;
02840 #endif
02841
02842
02843 if (0 &&
02844 (local->iw_mode == IW_MODE_MASTER ||
02845 local->iw_mode == IW_MODE_REPEAT ||
02846 local->wds_type & HOSTAP_WDS_AP_CLIENT)) {
02847 struct sk_buff *skb;
02848 skb = dev_alloc_skb(sizeof(txdesc));
02849 if (skb) {
02850 memcpy(skb_put(skb, sizeof(txdesc)), &txdesc,
02851 sizeof(txdesc));
02852 skb_queue_tail(&local->sta_tx_exc_list, skb);
02853 tasklet_schedule(&local->sta_tx_exc_tasklet);
02854 }
02855 }
02856
02857 if (0 && txdesc.sw_support)
02858 hostap_tx_callback(local, &txdesc, 0, payload);
02859 kfree(payload);
02860
02861 if (!show_dump)
02862 return;
02863
02864 PDEBUG(DEBUG_EXTRA, "%s: TXEXC - status=0x%04x (%s%s%s%s)"
02865 " tx_control=%04x\n",
02866 dev->name, status,
02867 status & HFA384X_TX_STATUS_RETRYERR ? "[RetryErr]" : "",
02868 status & HFA384X_TX_STATUS_AGEDERR ? "[AgedErr]" : "",
02869 status & HFA384X_TX_STATUS_DISCON ? "[Discon]" : "",
02870 status & HFA384X_TX_STATUS_FORMERR ? "[FormErr]" : "",
02871 le16_to_cpu(txdesc.tx_control));
02872
02873 fc = le16_to_cpu(txdesc.frame_control);
02874 PDEBUG(DEBUG_EXTRA, " retry_count=%d tx_rate=%d fc=0x%04x "
02875 "(%s%s%s::%d%s%s)\n",
02876 txdesc.retry_count, txdesc.tx_rate, fc,
02877 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT ? "Mgmt" : "",
02878 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_CTRL ? "Ctrl" : "",
02879 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA ? "Data" : "",
02880 WLAN_FC_GET_STYPE(fc),
02881 fc & WLAN_FC_TODS ? " ToDS" : "",
02882 fc & WLAN_FC_FROMDS ? " FromDS" : "");
02883 PDEBUG(DEBUG_EXTRA, " A1=" MACSTR " A2=" MACSTR " A3="
02884 MACSTR " A4=" MACSTR "\n",
02885 MAC2STR(txdesc.addr1), MAC2STR(txdesc.addr2),
02886 MAC2STR(txdesc.addr3), MAC2STR(txdesc.addr4));
02887 }
02888
02889
02890
02891 static void hostap_info_tasklet(unsigned long data)
02892 {
02893 local_info_t *local = (local_info_t *) data;
02894 struct sk_buff *skb;
02895
02896 while ((skb = skb_dequeue(&local->info_list)) != NULL) {
02897 hostap_info_process(local, skb);
02898 dev_kfree_skb(skb);
02899 }
02900 }
02901
02902
02903
02904 static void prism2_info(local_info_t *local)
02905 {
02906 struct net_device *dev = local->dev;
02907 u16 fid;
02908 int res, left;
02909 struct hfa384x_info_frame info;
02910 struct sk_buff *skb;
02911
02912 fid = HFA384X_INW(HFA384X_INFOFID_OFF);
02913
02914 spin_lock(&local->baplock);
02915 res = hfa384x_setup_bap(dev, BAP0, fid, 0);
02916 if (!res)
02917 res = hfa384x_from_bap(dev, BAP0, &info, sizeof(info));
02918 if (res) {
02919 spin_unlock(&local->baplock);
02920 printk(KERN_DEBUG "Could not get info frame (fid=0x%04x)\n",
02921 fid);
02922 if (res == -ETIMEDOUT) {
02923 PRISM2_SCHEDULE_TASK(&local->reset_queue);
02924 }
02925 goto out;
02926 }
02927
02928 le16_to_cpus(&info.len);
02929 le16_to_cpus(&info.type);
02930 left = (info.len - 1) * 2;
02931
02932 if (info.len & 0x8000 || info.len == 0 || left > 2060) {
02933
02934
02935
02936 spin_unlock(&local->baplock);
02937 printk(KERN_DEBUG "%s: Received info frame with invalid "
02938 "length 0x%04x (type 0x%04x)\n", dev->name, info.len,
02939 info.type);
02940 goto out;
02941 }
02942
02943 skb = dev_alloc_skb(sizeof(info) + left);
02944 if (skb == NULL) {
02945 spin_unlock(&local->baplock);
02946 printk(KERN_DEBUG "%s: Could not allocate skb for info "
02947 "frame\n", dev->name);
02948 goto out;
02949 }
02950
02951 memcpy(skb_put(skb, sizeof(info)), &info, sizeof(info));
02952 if (left > 0 && hfa384x_from_bap(dev, BAP0, skb_put(skb, left), left))
02953 {
02954 spin_unlock(&local->baplock);
02955 printk(KERN_WARNING "%s: Info frame read failed (fid=0x%04x, "
02956 "len=0x%04x, type=0x%04x\n",
02957 dev->name, fid, info.len, info.type);
02958 dev_kfree_skb(skb);
02959 goto out;
02960 }
02961 spin_unlock(&local->baplock);
02962
02963 skb_queue_tail(&local->info_list, skb);
02964 tasklet_schedule(&local->info_tasklet);
02965
02966 out:
02967 HFA384X_OUTW(HFA384X_EV_INFO, HFA384X_EVACK_OFF);
02968 }
02969
02970
02971
02972 static void hostap_bap_tasklet(unsigned long data)
02973 {
02974 local_info_t *local = (local_info_t *) data;
02975 struct net_device *dev = local->dev;
02976 u16 ev;
02977 int frames = 30;
02978
02979 if (local->func->card_present && !local->func->card_present(local))
02980 return;
02981
02982 set_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
02983
02984
02985
02986 while (frames-- > 0) {
02987 ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
02988 if (ev == 0xffff || !(ev & HFA384X_BAP0_EVENTS))
02989 break;
02990 if (ev & HFA384X_EV_RX)
02991 prism2_rx(local);
02992 if (ev & HFA384X_EV_INFO)
02993 prism2_info(local);
02994 if (ev & HFA384X_EV_TX)
02995 prism2_tx_ev(local);
02996 if (ev & HFA384X_EV_TXEXC)
02997 prism2_txexc(local);
02998 }
02999
03000 set_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
03001 clear_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
03002
03003
03004 hfa384x_events_all(dev);
03005 clear_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
03006 }
03007
03008
03009 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
03010
03011 static void prism2_bus_master_ev(struct net_device *dev, int bap)
03012 {
03013 struct hostap_interface *iface = dev->priv;
03014 local_info_t *local = iface->local;
03015 if (bap == BAP1) {
03016
03017
03018 skb_queue_tail(&local->rx_list, local->rx_skb);
03019 tasklet_schedule(&local->rx_tasklet);
03020 HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
03021 } else {
03022 if (prism2_transmit(dev, local->bus_m0_tx_idx)) {
03023 printk(KERN_DEBUG "%s: prism2_transmit() failed "
03024 "when called from bus master event\n",
03025 dev->name);
03026 local->intransmitfid[local->bus_m0_tx_idx] =
03027 PRISM2_TXFID_EMPTY;
03028 PRISM2_SCHEDULE_TASK(&local->reset_queue);
03029 }
03030 }
03031 }
03032 #endif
03033
03034
03035
03036 static void prism2_infdrop(struct net_device *dev)
03037 {
03038 static unsigned long last_inquire = 0;
03039
03040 PDEBUG(DEBUG_EXTRA, "%s: INFDROP event\n", dev->name);
03041
03042
03043
03044
03045
03046
03047 if (!last_inquire || time_after(jiffies, last_inquire + HZ)) {
03048 hfa384x_cmd_callback(dev, HFA384X_CMDCODE_INQUIRE,
03049 HFA384X_INFO_COMMTALLIES, NULL, NULL);
03050 last_inquire = jiffies;
03051 }
03052 }
03053
03054
03055
03056 static void prism2_ev_tick(struct net_device *dev)
03057 {
03058 struct hostap_interface *iface = dev->priv;
03059 local_info_t *local = iface->local;
03060 u16 evstat, inten;
03061 static int prev_stuck = 0;
03062
03063 if (time_after(jiffies, local->last_tick_timer + 5 * HZ) &&
03064 local->last_tick_timer) {
03065 evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
03066 inten = HFA384X_INW(HFA384X_INTEN_OFF);
03067 if (!prev_stuck) {
03068 printk(KERN_INFO "%s: SW TICK stuck? "
03069 "bits=0x%lx EvStat=%04x IntEn=%04x\n",
03070 dev->name, local->bits, evstat, inten);
03071 }
03072 local->sw_tick_stuck++;
03073 if ((evstat & HFA384X_BAP0_EVENTS) &&
03074 (inten & HFA384X_BAP0_EVENTS)) {
03075 printk(KERN_INFO "%s: trying to recover from IRQ "
03076 "hang\n", dev->name);
03077 hfa384x_events_no_bap0(dev);
03078 }
03079 prev_stuck = 1;
03080 } else
03081 prev_stuck = 0;
03082 }
03083
03084
03085
03086 static inline void prism2_check_magic(local_info_t *local)
03087 {
03088
03089
03090
03091
03092
03093
03094 #ifndef PRISM2_PCI
03095 #ifndef final_version
03096 static unsigned long last_magic_err = 0;
03097 struct net_device *dev = local->dev;
03098
03099 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
03100 if (!local->hw_ready)
03101 return;
03102 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
03103 if (time_after(jiffies, last_magic_err + 10 * HZ)) {
03104 printk("%s: Interrupt, but SWSUPPORT0 does not match: "
03105 "%04X != %04X - card removed?\n", dev->name,
03106 HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
03107 HFA384X_MAGIC);
03108 last_magic_err = jiffies;
03109 } else if (net_ratelimit()) {
03110 printk(KERN_DEBUG "%s: interrupt - SWSUPPORT0=%04x "
03111 "MAGIC=%04x\n", dev->name,
03112 HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
03113 HFA384X_MAGIC);
03114 }
03115 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != 0xffff)
03116 PRISM2_SCHEDULE_TASK(&local->reset_queue);
03117 return;
03118 }
03119 #endif
03120 #endif
03121 }
03122
03123
03124
03125 static irqreturn_t prism2_interrupt(int irq, void *dev_id, struct pt_regs *regs)
03126 {
03127 struct net_device *dev = (struct net_device *) dev_id;
03128 struct hostap_interface *iface = dev->priv;
03129 local_info_t *local = iface->local;
03130 int events = 0;
03131 u16 ev;
03132
03133 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 0);
03134
03135 if (local->func->card_present && !local->func->card_present(local)) {
03136 printk(KERN_DEBUG "%s: Interrupt, but dev not OK\n",
03137 dev->name);
03138 return IRQ_HANDLED;
03139 }
03140
03141 prism2_check_magic(local);
03142
03143 for (;;) {
03144 ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
03145 if (ev == 0xffff) {
03146 if (local->shutdown)
03147 return IRQ_HANDLED;
03148 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
03149 printk(KERN_DEBUG "%s: prism2_interrupt: ev=0xffff\n",
03150 dev->name);
03151 return IRQ_HANDLED;
03152 }
03153
03154 ev &= HFA384X_INW(HFA384X_INTEN_OFF);
03155 if (ev == 0)
03156 break;
03157
03158 if (ev & HFA384X_EV_CMD) {
03159 prism2_cmd_ev(dev);
03160 }
03161
03162
03163
03164
03165
03166 if (!local->hw_ready || local->hw_resetting ||
03167 !local->dev_enabled) {
03168 ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
03169 if (ev & HFA384X_EV_CMD)
03170 goto next_event;
03171 if ((ev & HFA384X_EVENT_MASK) == 0)
03172 return IRQ_HANDLED;
03173 if (local->dev_enabled && (ev & ~HFA384X_EV_TICK) &&
03174 net_ratelimit()) {
03175 printk(KERN_DEBUG "%s: prism2_interrupt: hw "
03176 "not ready; skipping events 0x%04x "
03177 "(IntEn=0x%04x)%s%s%s\n",
03178 dev->name, ev,
03179 HFA384X_INW(HFA384X_INTEN_OFF),
03180 !local->hw_ready ? " (!hw_ready)" : "",
03181 local->hw_resetting ?
03182 " (hw_resetting)" : "",
03183 !local->dev_enabled ?
03184 " (!dev_enabled)" : "");
03185 }
03186 HFA384X_OUTW(ev, HFA384X_EVACK_OFF);
03187 return IRQ_HANDLED;
03188 }
03189
03190 if (ev & HFA384X_EV_TICK) {
03191 prism2_ev_tick(dev);
03192 HFA384X_OUTW(HFA384X_EV_TICK, HFA384X_EVACK_OFF);
03193 }
03194
03195 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
03196 if (ev & HFA384X_EV_PCI_M0) {
03197 prism2_bus_master_ev(dev, BAP0);
03198 HFA384X_OUTW(HFA384X_EV_PCI_M0, HFA384X_EVACK_OFF);
03199 }
03200
03201 if (ev & HFA384X_EV_PCI_M1) {
03202
03203 HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
03204
03205 prism2_bus_master_ev(dev, BAP1);
03206 HFA384X_OUTW(HFA384X_EV_PCI_M1, HFA384X_EVACK_OFF);
03207 }
03208 #endif
03209
03210 if (ev & HFA384X_EV_ALLOC) {
03211 prism2_alloc_ev(dev);
03212 HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
03213 }
03214
03215
03216
03217
03218 if (ev & HFA384X_BAP0_EVENTS) {
03219 hfa384x_events_no_bap0(dev);
03220 tasklet_schedule(&local->bap_tasklet);
03221 }
03222
03223 #ifndef final_version
03224 if (ev & HFA384X_EV_WTERR) {
03225 PDEBUG(DEBUG_EXTRA, "%s: WTERR event\n", dev->name);
03226 HFA384X_OUTW(HFA384X_EV_WTERR, HFA384X_EVACK_OFF);
03227 }
03228 #endif
03229
03230 if (ev & HFA384X_EV_INFDROP) {
03231 prism2_infdrop(dev);
03232 HFA384X_OUTW(HFA384X_EV_INFDROP, HFA384X_EVACK_OFF);
03233 }
03234
03235 next_event:
03236 events++;
03237 if (events >= PRISM2_MAX_INTERRUPT_EVENTS) {
03238 PDEBUG(DEBUG_EXTRA, "prism2_interrupt: >%d events "
03239 "(EvStat=0x%04x)\n",
03240 PRISM2_MAX_INTERRUPT_EVENTS,
03241 HFA384X_INW(HFA384X_EVSTAT_OFF));
03242 break;
03243 }
03244 }
03245 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 1);
03246 return IRQ_RETVAL(events);
03247 }
03248
03249
03250 static void prism2_check_sta_fw_version(local_info_t *local)
03251 {
03252 struct hfa384x_comp_ident comp;
03253 int id, variant, major, minor;
03254
03255 if (hfa384x_get_rid(local->dev, HFA384X_RID_STAID,
03256 &comp, sizeof(comp), 1) < 0)
03257 return;
03258
03259 local->fw_ap = 0;
03260 id = le16_to_cpu(comp.id);
03261 if (id != HFA384X_COMP_ID_STA) {
03262 if (id == HFA384X_COMP_ID_FW_AP)
03263 local->fw_ap = 1;
03264 return;
03265 }
03266
03267 major = __le16_to_cpu(comp.major);
03268 minor = __le16_to_cpu(comp.minor);
03269 variant = __le16_to_cpu(comp.variant);
03270 local->sta_fw_ver = PRISM2_FW_VER(major, minor, variant);
03271
03272
03273
03274
03275
03276
03277
03278 local->fw_encrypt_ok = local->sta_fw_ver >= PRISM2_FW_VER(1,4,9);
03279
03280 if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
03281 !local->fw_encrypt_ok) {
03282 printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
03283 "a workaround for firmware bug in Host AP mode WEP\n",
03284 local->dev->name);
03285 local->host_encrypt = 1;
03286 }
03287
03288
03289
03290
03291
03292
03293
03294
03295 if (local->sta_fw_ver >= PRISM2_FW_VER(1,5,0))
03296 local->wds_type |= HOSTAP_WDS_STANDARD_FRAME;
03297 else {
03298 printk(KERN_DEBUG "%s: defaulting to bogus WDS frame as a "
03299 "workaround for firmware bug in Host AP mode WDS\n",
03300 local->dev->name);
03301 }
03302
03303 hostap_check_sta_fw_version(local->ap, local->sta_fw_ver);
03304 }
03305
03306
03307 static void prism2_crypt_deinit_entries(local_info_t *local, int force)
03308 {
03309 struct list_head *ptr, *n;
03310 struct prism2_crypt_data *entry;
03311
03312 for (ptr = local->crypt_deinit_list.next, n = ptr->next;
03313 ptr != &local->crypt_deinit_list; ptr = n, n = ptr->next) {
03314 entry = list_entry(ptr, struct prism2_crypt_data, list);
03315
03316 if (atomic_read(&entry->refcnt) != 0 && !force)
03317 continue;
03318
03319 list_del(ptr);
03320
03321 if (entry->ops)
03322 entry->ops->deinit(entry->priv);
03323 kfree(entry);
03324 }
03325 }
03326
03327
03328 static void prism2_crypt_deinit_handler(unsigned long data)
03329 {
03330 local_info_t *local = (local_info_t *) data;
03331 unsigned long flags;
03332
03333 spin_lock_irqsave(&local->lock, flags);
03334 prism2_crypt_deinit_entries(local, 0);
03335 if (!list_empty(&local->crypt_deinit_list)) {
03336 printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
03337 "deletion list\n", local->dev->name);
03338 local->crypt_deinit_timer.expires = jiffies + HZ;
03339 add_timer(&local->crypt_deinit_timer);
03340 }
03341 spin_unlock_irqrestore(&local->lock, flags);
03342
03343 }
03344
03345
03346 static void hostap_passive_scan(unsigned long data)
03347 {
03348 local_info_t *local = (local_info_t *) data;
03349 struct net_device *dev = local->dev;
03350 u16 channel;
03351
03352 if (local->passive_scan_interval <= 0)
03353 return;
03354
03355 if (local->passive_scan_state == PASSIVE_SCAN_LISTEN) {
03356 int max_tries = 16;
03357
03358
03359
03360
03361
03362 if (test_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
03363 printk(KERN_DEBUG "%s: passive scan detected pending "
03364 "TX - delaying\n", dev->name);
03365 local->passive_scan_timer.expires = jiffies + HZ / 10;
03366 add_timer(&local->passive_scan_timer);
03367 return;
03368 }
03369
03370 do {
03371 local->passive_scan_channel++;
03372 if (local->passive_scan_channel > 14)
03373 local->passive_scan_channel = 1;
03374 max_tries--;
03375 } while (!(local->channel_mask &
03376 (1 << (local->passive_scan_channel - 1))) &&
03377 max_tries > 0);
03378
03379 if (max_tries == 0) {
03380 printk(KERN_INFO "%s: no allowed passive scan channels"
03381 " found\n", dev->name);
03382 return;
03383 }
03384
03385 printk(KERN_DEBUG "%s: passive scan channel %d\n",
03386 dev->name, local->passive_scan_channel);
03387 channel = local->passive_scan_channel;
03388 local->passive_scan_state = PASSIVE_SCAN_WAIT;
03389 local->passive_scan_timer.expires = jiffies + HZ / 10;
03390 } else {
03391 channel = local->channel;
03392 local->passive_scan_state = PASSIVE_SCAN_LISTEN;
03393 local->passive_scan_timer.expires = jiffies +
03394 local->passive_scan_interval * HZ;
03395 }
03396
03397 if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_TEST |
03398 (HFA384X_TEST_CHANGE_CHANNEL << 8),
03399 channel, NULL, NULL))
03400 printk(KERN_ERR "%s: passive scan channel set %d "
03401 "failed\n", dev->name, channel);
03402
03403 add_timer(&local->passive_scan_timer);
03404 }
03405
03406
03407
03408
03409
03410
03411 static void hostap_tick_timer(unsigned long data)
03412 {
03413 static unsigned long last_inquire = 0;
03414 local_info_t *local = (local_info_t *) data;
03415 local->last_tick_timer = jiffies;
03416
03417
03418
03419 if ((!last_inquire || time_after(jiffies, last_inquire + 10 * HZ)) &&
03420 !local->hw_downloading && local->hw_ready &&
03421 !local->hw_resetting && local->dev_enabled) {
03422 hfa384x_cmd_callback(local->dev, HFA384X_CMDCODE_INQUIRE,
03423 HFA384X_INFO_COMMTALLIES, NULL, NULL);
03424 last_inquire = jiffies;
03425 }
03426
03427 local->tick_timer.expires = jiffies + 2 * HZ;
03428 add_timer(&local->tick_timer);
03429 }
03430
03431
03432 #ifndef PRISM2_NO_PROCFS_DEBUG
03433 static int prism2_registers_proc_read(char *page, char **start, off_t off,
03434 int count, int *eof, void *data)
03435 {
03436 char *p = page;
03437 local_info_t *local = (local_info_t *) data;
03438
03439 if (off != 0) {
03440 *eof = 1;
03441 return 0;
03442 }
03443
03444 #define SHOW_REG(n) \
03445 p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF))
03446
03447 SHOW_REG(CMD);
03448 SHOW_REG(PARAM0);
03449 SHOW_REG(PARAM1);
03450 SHOW_REG(PARAM2);
03451 SHOW_REG(STATUS);
03452 SHOW_REG(RESP0);
03453 SHOW_REG(RESP1);
03454 SHOW_REG(RESP2);
03455 SHOW_REG(INFOFID);
03456 SHOW_REG(CONTROL);
03457 SHOW_REG(SELECT0);
03458 SHOW_REG(SELECT1);
03459 SHOW_REG(OFFSET0);
03460 SHOW_REG(OFFSET1);
03461 SHOW_REG(RXFID);
03462 SHOW_REG(ALLOCFID);
03463 SHOW_REG(TXCOMPLFID);
03464 SHOW_REG(SWSUPPORT0);
03465 SHOW_REG(SWSUPPORT1);
03466 SHOW_REG(SWSUPPORT2);
03467 SHOW_REG(EVSTAT);
03468 SHOW_REG(INTEN);
03469 SHOW_REG(EVACK);
03470
03471
03472
03473
03474 SHOW_REG(AUXPAGE);
03475 SHOW_REG(AUXOFFSET);
03476
03477 #ifdef PRISM2_PCI
03478 SHOW_REG(PCICOR);
03479 SHOW_REG(PCIHCR);
03480 SHOW_REG(PCI_M0_ADDRH);
03481 SHOW_REG(PCI_M0_ADDRL);
03482 SHOW_REG(PCI_M0_LEN);
03483 SHOW_REG(PCI_M0_CTL);
03484 SHOW_REG(PCI_STATUS);
03485 SHOW_REG(PCI_M1_ADDRH);
03486 SHOW_REG(PCI_M1_ADDRL);
03487 SHOW_REG(PCI_M1_LEN);
03488 SHOW_REG(PCI_M1_CTL);
03489 #endif
03490
03491 return (p - page);
03492 }
03493 #endif
03494
03495 #ifndef ARPHRD_IEEE80211_RADIOTAP
03496 #define ARPHRD_IEEE80211_RADIOTAP 803
03497 #endif
03498
03499 static struct net_device *
03500 prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx)
03501 {
03502 struct net_device *dev;
03503 struct hostap_interface *iface;
03504 struct local_info *local;
03505 int len, i;
03506
03507 if (funcs == NULL)
03508 return NULL;
03509
03510 len = sizeof(struct hostap_interface) +
03511 3 + sizeof(struct local_info) +
03512 3 + sizeof(struct ap_data);
03513
03514 dev = alloc_etherdev(len);
03515 if (dev == NULL)
03516 return NULL;
03517
03518 iface = dev->priv;
03519 local = (struct local_info *) ((((long) (iface + 1)) + 3) & ~3);
03520 local->ap = (struct ap_data *) ((((long) (local + 1)) + 3) & ~3);
03521 local->dev = iface->dev = dev;
03522 iface->local = local;
03523 iface->type = HOSTAP_INTERFACE_MAIN;
03524 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
03525 dev->name = iface->name;
03526 #endif
03527 INIT_LIST_HEAD(&local->hostap_interfaces);
03528 list_add(&iface->list, &local->hostap_interfaces);
03529
03530 local->hw_module = THIS_MODULE;
03531
03532 #ifdef PRISM2_IO_DEBUG
03533 local->io_debug_enabled = 1;
03534 #endif
03535
03536 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
03537 local->bus_m0_buf = (u8 *) kmalloc(sizeof(struct hfa384x_tx_frame) +
03538 PRISM2_DATA_MAXLEN, GFP_DMA);
03539 if (local->bus_m0_buf == NULL)
03540 goto fail;
03541 #endif
03542
03543 local->func = funcs;
03544 local->func->cmd = hfa384x_cmd;
03545 local->func->read_regs = hfa384x_read_regs;
03546 local->func->get_rid = hfa384x_get_rid;
03547 local->func->set_rid = hfa384x_set_rid;
03548 local->func->hw_enable = prism2_hw_enable;
03549 local->func->hw_config = prism2_hw_config;
03550 local->func->hw_reset = prism2_hw_reset;
03551 local->func->hw_shutdown = prism2_hw_shutdown;
03552 local->func->reset_port = prism2_reset_port;
03553 local->func->tx = prism2_tx;
03554 local->func->schedule_reset = prism2_schedule_reset;
03555 #ifdef PRISM2_DOWNLOAD_SUPPORT
03556 local->func->download = prism2_download;
03557 #endif
03558 local->func->tx_80211 = prism2_tx_80211;
03559
03560 local->disable_on_close = disable_on_close;
03561 local->mtu = mtu;
03562
03563 rwlock_init(&local->iface_lock);
03564 spin_lock_init(&local->txfidlock);
03565 spin_lock_init(&local->cmdlock);
03566 spin_lock_init(&local->baplock);
03567 spin_lock_init(&local->lock);
03568 init_MUTEX(&local->rid_bap_sem);
03569
03570 if (card_idx < 0 || card_idx >= MAX_PARM_DEVICES)
03571 card_idx = 0;
03572 local->card_idx = card_idx;
03573
03574 i = essid[card_idx] == NULL ? 0 : card_idx;
03575 len = strlen(essid[i]);
03576 memcpy(local->essid, essid[i],
03577 len > MAX_SSID_LEN ? MAX_SSID_LEN : len);
03578 local->essid[MAX_SSID_LEN] = '\0';
03579 i = GET_INT_PARM(iw_mode, card_idx);
03580 if ((i >= IW_MODE_ADHOC && i <= IW_MODE_REPEAT) ||
03581 i == IW_MODE_MONITOR) {
03582 local->iw_mode = i;
03583 } else {
03584 printk(KERN_WARNING "prism2: Unknown iw_mode %d; using "
03585 "IW_MODE_MASTER\n", i);
03586 local->iw_mode = IW_MODE_MASTER;
03587 }
03588 local->channel = GET_INT_PARM(channel, card_idx);
03589 local->beacon_int = GET_INT_PARM(beacon_int, card_idx);
03590 local->dtim_period = GET_INT_PARM(dtim_period, card_idx);
03591 local->wds_max_connections = 16;
03592 local->tx_control = HFA384X_TX_CTRL_FLAGS;
03593 local->manual_retry_count = -1;
03594 local->rts_threshold = 2347;
03595 local->fragm_threshold = 2346;
03596 local->auth_algs = PRISM2_AUTH_OPEN | PRISM2_AUTH_SHARED_KEY;
03597 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
03598 local->bus_master_threshold_rx = GET_INT_PARM(bus_master_threshold_rx,
03599 card_idx);
03600 local->bus_master_threshold_tx = GET_INT_PARM(bus_master_threshold_tx,
03601 card_idx);
03602 #endif
03603
03604
03605 INIT_WORK(&local->reset_queue, handle_reset_queue, local);
03606 INIT_WORK(&local->set_multicast_list_queue,
03607 hostap_set_multicast_list_queue, local->dev);
03608
03609
03610
03611 HOSTAP_TASKLET_INIT(&local->bap_tasklet, hostap_bap_tasklet,
03612 (unsigned long) local);
03613
03614 HOSTAP_TASKLET_INIT(&local->info_tasklet, hostap_info_tasklet,
03615 (unsigned long) local);
03616 hostap_info_init(local);
03617
03618 HOSTAP_TASKLET_INIT(&local->rx_tasklet,
03619 hostap_rx_tasklet, (unsigned long) local);
03620 skb_queue_head_init(&local->rx_list);
03621
03622 HOSTAP_TASKLET_INIT(&local->sta_tx_exc_tasklet,
03623 hostap_sta_tx_exc_tasklet, (unsigned long) local);
03624 skb_queue_head_init(&local->sta_tx_exc_list);
03625
03626 INIT_LIST_HEAD(&local->cmd_queue);
03627 init_waitqueue_head(&local->hostscan_wq);
03628 INIT_LIST_HEAD(&local->crypt_deinit_list);
03629 init_timer(&local->crypt_deinit_timer);
03630 local->crypt_deinit_timer.data = (unsigned long) local;
03631 local->crypt_deinit_timer.function = prism2_crypt_deinit_handler;
03632
03633 init_timer(&local->passive_scan_timer);
03634 local->passive_scan_timer.data = (unsigned long) local;
03635 local->passive_scan_timer.function = hostap_passive_scan;
03636
03637 init_timer(&local->tick_timer);
03638 local->tick_timer.data = (unsigned long) local;
03639 local->tick_timer.function = hostap_tick_timer;
03640 local->tick_timer.expires = jiffies + 2 * HZ;
03641 add_timer(&local->tick_timer);
03642
03643 hostap_setup_dev(dev, local, 1);
03644
03645 dev->type = ARPHRD_ETHER;
03646 local->monitor_type = ARPHRD_IEEE80211_RADIOTAP;
03647 local->saved_eth_header_parse = dev->hard_header_parse;
03648
03649 return dev;
03650
03651 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
03652 fail:
03653 kfree(local->bus_m0_buf);
03654 free_netdev(dev);
03655 return NULL;
03656 #endif
03657 }
03658
03659
03660 static int prism2_init_dev(local_info_t *local)
03661 {
03662 struct net_device *dev = local->dev;
03663 int len, ret;
03664
03665 len = strlen(dev_template);
03666 if (len >= IFNAMSIZ || strstr(dev_template, "%d") == NULL) {
03667 printk(KERN_WARNING "hostap: Invalid dev_template='%s'\n",
03668 dev_template);
03669 return 1;
03670 }
03671
03672 rtnl_lock();
03673 ret = dev_alloc_name(dev, dev_template);
03674 if (ret >= 0)
03675 ret = register_netdevice(dev);
03676 rtnl_unlock();
03677 if (ret < 0) {
03678 printk(KERN_WARNING "%s: register netdevice failed!\n",
03679 dev_info);
03680 return 1;
03681 }
03682 printk(KERN_INFO "%s: Registered netdevice %s\n", dev_info, dev->name);
03683
03684 hostap_init_proc(local);
03685 #ifndef PRISM2_NO_PROCFS_DEBUG
03686 create_proc_read_entry("registers", 0, local->proc,
03687 prism2_registers_proc_read, local);
03688 #endif
03689 hostap_init_data(local);
03690
03691 return 0;
03692 }
03693
03694
03695 static void prism2_free_local_data(struct net_device *dev)
03696 {
03697 struct hostap_tx_callback_info *tx_cb, *tx_cb_prev;
03698 int i;
03699 struct sk_buff *skb;
03700 struct hostap_interface *iface;
03701 struct local_info *local;
03702 struct list_head *ptr, *n;
03703
03704 if (dev == NULL)
03705 return;
03706
03707 iface = dev->priv;
03708 local = iface->local;
03709
03710 flush_scheduled_work();
03711
03712 if (timer_pending(&local->crypt_deinit_timer))
03713 del_timer(&local->crypt_deinit_timer);
03714 prism2_crypt_deinit_entries(local, 1);
03715
03716 if (timer_pending(&local->passive_scan_timer))
03717 del_timer(&local->passive_scan_timer);
03718
03719 if (timer_pending(&local->tick_timer))
03720 del_timer(&local->tick_timer);
03721
03722 prism2_clear_cmd_queue(local);
03723
03724 while ((skb = skb_dequeue(&local->info_list)) != NULL)
03725 dev_kfree_skb(skb);
03726
03727 while ((skb = skb_dequeue(&local->rx_list)) != NULL)
03728 dev_kfree_skb(skb);
03729
03730 while ((skb = skb_dequeue(&local->sta_tx_exc_list)) != NULL)
03731 dev_kfree_skb(skb);
03732
03733 if (local->dev_enabled)
03734 prism2_callback(local, PRISM2_CALLBACK_DISABLE);
03735
03736 if (local->crypt) {
03737 if (local->crypt->ops)
03738 local->crypt->ops->deinit(local->crypt->priv);
03739 kfree(local->crypt);
03740 local->crypt = NULL;
03741 }
03742
03743 if (local->ap != NULL)
03744 hostap_free_data(local->ap);
03745
03746 #ifndef PRISM2_NO_PROCFS_DEBUG
03747 if (local->proc != NULL)
03748 remove_proc_entry("registers", local->proc);
03749 #endif
03750 hostap_remove_proc(local);
03751
03752 tx_cb = local->tx_callback;
03753 while (tx_cb != NULL) {
03754 tx_cb_prev = tx_cb;
03755 tx_cb = tx_cb->next;
03756 kfree(tx_cb_prev);
03757 }
03758
03759 hostap_set_hostapd(local, 0, 0);
03760
03761 for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
03762 if (local->frag_cache[i].skb != NULL)
03763 dev_kfree_skb(local->frag_cache[i].skb);
03764 }
03765
03766 #ifdef PRISM2_DOWNLOAD_SUPPORT
03767 prism2_download_free_data(local->dl_pri);
03768 prism2_download_free_data(local->dl_sec);
03769 #endif
03770
03771 list_for_each_safe(ptr, n, &local->hostap_interfaces) {
03772 iface = list_entry(ptr, struct hostap_interface, list);
03773 if (iface->type == HOSTAP_INTERFACE_MAIN) {
03774
03775 continue;
03776 }
03777 hostap_remove_interface(iface->dev, 0, 1);
03778 }
03779
03780 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
03781 kfree(local->bus_m0_buf);
03782 #endif
03783 kfree(local->pda);
03784 kfree(local->last_scan_results);
03785
03786 unregister_netdev(local->dev);
03787 free_netdev(local->dev);
03788 }
03789
03790
03791
03792
03793 #ifdef PRISM2_DOWNLOAD_SUPPORT
03794 #include "hostap_download.c"
03795 #endif
03796
03797 #ifdef PRISM2_CALLBACK
03798
03799
03800
03801
03802 #include "hostap_callback.c"
03803 #endif