34 #include <asm/delay.h>
35 #include <asm/uaccess.h>
37 #include <linux/slab.h>
38 #include <linux/netdevice.h>
41 #include <linux/if_arp.h>
43 #include <linux/random.h>
44 #include <linux/wait.h>
45 #include <linux/sched.h>
46 #include <linux/rtnetlink.h>
47 #include <linux/wireless.h>
59 static int mtu = 1500;
67 static char essid[33] =
"test";
83 static char dev_template[16] =
"wlan%d";
89 #define EXTRA_EVENTS_WTERR 0
92 #define EXTRA_EVENTS_WTERR HFA384X_EV_WTERR
96 #define HFA384X_BAP0_EVENTS \
97 (HFA384X_EV_TXEXC | HFA384X_EV_RX | HFA384X_EV_INFO | HFA384X_EV_TX)
100 #define HFA384X_EVENT_MASK \
101 (HFA384X_BAP0_EVENTS | HFA384X_EV_ALLOC | HFA384X_EV_INFDROP | \
102 HFA384X_EV_CMD | HFA384X_EV_TICK | \
109 #define HFA384X_TX_CTRL_FLAGS \
110 (HFA384X_TX_CTRL_802_11 | HFA384X_TX_CTRL_TX_EX)
114 #define HFA384X_CMD_BUSY_TIMEOUT 5000
115 #define HFA384X_BAP_BUSY_TIMEOUT 50000
118 #define HFA384X_CMD_COMPL_TIMEOUT 20000
119 #define HFA384X_DL_COMPL_TIMEOUT 1000000
123 #define HFA384X_INIT_TIMEOUT (HZ / 2)
124 #define HFA384X_ALLOC_COMPL_TIMEOUT (HZ / 20)
128 static void prism2_check_sta_fw_version(
local_info_t *local);
130 #ifdef PRISM2_DOWNLOAD_SUPPORT
137 static void prism2_download_free_data(
struct prism2_download_data *
dl);
138 static int prism2_download_volatile(
local_info_t *local,
139 struct prism2_download_data *
param);
141 struct prism2_download_data *
param);
148 #ifndef final_version
151 #define HFA384X_MAGIC 0x8A32
181 static inline void __hostap_cmd_queue_free(
local_info_t *local,
182 struct hostap_cmd_queue *
entry,
187 if (!list_empty(&entry->list)) {
188 list_del_init(&entry->list);
189 local->cmd_queue_len--;
206 static inline void hostap_cmd_queue_free(
local_info_t *local,
207 struct hostap_cmd_queue *entry,
213 __hostap_cmd_queue_free(local, entry, del_req);
214 spin_unlock_irqrestore(&local->cmdlock, flags);
226 struct hostap_cmd_queue *
entry;
233 "(type=%d, cmd=0x%04x, param0=0x%04x)\n",
234 local->
dev->name, entry->type, entry->cmd,
236 __hostap_cmd_queue_free(local, entry, 1);
238 if (local->cmd_queue_len) {
242 "flush\n", local->
dev->name, local->cmd_queue_len);
243 local->cmd_queue_len = 0;
245 spin_unlock_irqrestore(&local->cmdlock, flags);
255 struct hostap_cmd_queue *entry)
257 struct hostap_interface *iface;
263 iface = netdev_priv(dev);
264 local = iface->local;
266 if (local->func->card_present && !local->func->card_present(local))
281 #ifndef final_version
283 prism2_io_debug_error(dev, 1);
285 "for %d usec\n", dev->
name,
291 prism2_io_debug_error(dev, 2);
293 "reg=0x%04x\n", dev->
name, reg);
303 spin_unlock_irqrestore(&local->cmdlock, flags);
324 struct hostap_interface *iface;
328 struct hostap_cmd_queue *
entry;
331 iface = netdev_priv(dev);
332 local = iface->local;
336 "context\n", dev->
name);
340 if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN) {
354 entry->type = CMD_SLEEP;
367 issue = list_empty(&local->cmd_queue);
371 local->cmd_queue_len++;
372 spin_unlock_irqrestore(&local->cmdlock, flags);
376 goto wait_completion;
382 if (hfa384x_cmd_issue(dev, entry))
389 if (!err && entry->type != CMD_COMPLETED) {
395 if (!err && signal_pending(
current))
428 if (!list_empty(&entry->list)) {
430 "(entry=%p, type=%d, res=%d)\n", dev->
name, entry,
432 list_del_init(&entry->list);
433 local->cmd_queue_len--;
435 spin_unlock_irqrestore(&local->cmdlock, flags);
444 if (entry->type != CMD_COMPLETED) {
447 "completed (res=%d, entry=%p, type=%d, cmd=0x%04x, "
448 "param0=0x%04x, EVSTAT=%04x INTEN=%04x)\n", dev->
name,
449 res, entry, entry->type, entry->cmd, entry->param0, reg,
456 "seem to work\n", dev->
name);
458 prism2_io_debug_error(dev, 3);
464 *resp0 = entry->resp0;
465 #ifndef final_version
469 dev->
name, cmd, entry->res, entry->resp0);
475 hostap_cmd_queue_free(local, entry, 1);
494 static int hfa384x_cmd_callback(
struct net_device *dev,
u16 cmd,
u16 param0,
500 struct hostap_interface *iface;
504 struct hostap_cmd_queue *
entry;
506 iface = netdev_priv(dev);
507 local = iface->local;
509 if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN + 2) {
520 entry->type = CMD_CALLBACK;
527 issue = list_empty(&local->cmd_queue);
531 local->cmd_queue_len++;
532 spin_unlock_irqrestore(&local->cmdlock, flags);
534 if (issue && hfa384x_cmd_issue(dev, entry))
539 hostap_cmd_queue_free(local, entry, ret);
554 static int __hfa384x_cmd_no_wait(
struct net_device *dev,
u16 cmd,
u16 param0,
569 prism2_io_debug_error(dev, io_debug_num);
571 "reg=0x%04x\n", dev->
name, io_debug_num, reg);
594 res = __hfa384x_cmd_no_wait(dev, cmd, param0, 4);
611 prism2_io_debug_error(dev, 5);
613 "reg=0x%04x\n", dev->
name, reg);
620 #ifndef final_version
623 dev->
name, cmd, res);
639 static inline int hfa384x_cmd_no_wait(
struct net_device *dev,
u16 cmd,
642 return __hfa384x_cmd_no_wait(dev, cmd, param0, 6);
656 static void prism2_cmd_ev(
struct net_device *dev)
658 struct hostap_interface *iface;
660 struct hostap_cmd_queue *entry =
NULL;
662 iface = netdev_priv(dev);
663 local = iface->local;
665 spin_lock(&local->cmdlock);
666 if (!list_empty(&local->cmd_queue)) {
668 struct hostap_cmd_queue,
list);
670 list_del_init(&entry->list);
671 local->cmd_queue_len--;
673 if (!entry->issued) {
675 "cmd not issued\n", dev->
name);
676 __hostap_cmd_queue_free(local, entry, 1);
680 spin_unlock(&local->cmdlock);
685 "pending commands\n", dev->
name);
696 if (entry->type == CMD_SLEEP) {
697 entry->type = CMD_COMPLETED;
699 }
else if (entry->type == CMD_CALLBACK) {
701 entry->callback(dev, entry->context, entry->resp0,
705 dev->
name, entry->type);
707 hostap_cmd_queue_free(local, entry, 1);
711 spin_lock(&local->cmdlock);
712 if (!list_empty(&local->cmd_queue)) {
714 struct hostap_cmd_queue,
list);
715 if (entry->issuing) {
723 spin_unlock(&local->cmdlock);
728 int res = hfa384x_cmd_issue(dev, entry);
729 spin_lock(&local->cmdlock);
730 __hostap_cmd_queue_free(local, entry, res);
731 spin_unlock(&local->cmdlock);
736 static int hfa384x_wait_offset(
struct net_device *dev,
u16 o_off)
741 while (res && tries > 0) {
757 if (offset % 2 || bap > 1)
761 o_off = HFA384X_OFFSET1_OFF;
762 s_off = HFA384X_SELECT1_OFF;
764 o_off = HFA384X_OFFSET0_OFF;
765 s_off = HFA384X_SELECT0_OFF;
768 if (hfa384x_wait_offset(dev, o_off)) {
769 prism2_io_debug_error(dev, 7);
779 if (hfa384x_wait_offset(dev, o_off)) {
780 prism2_io_debug_error(dev, 8);
786 #ifndef final_version
788 prism2_io_debug_error(dev, 9);
790 "(%d,0x04%x,%d); reg=0x%04x\n",
801 static int hfa384x_get_rid(
struct net_device *dev,
u16 rid,
void *
buf,
int len,
804 struct hostap_interface *iface;
809 iface = netdev_priv(dev);
810 local = iface->local;
814 "f/w\n", dev->
name, rid, len);
819 if ((local->func->card_present && !local->func->card_present(local)) ||
820 local->hw_downloading)
830 "(res=%d, rid=%04x, len=%d)\n",
831 dev->
name, res, rid, len);
836 spin_lock_bh(&local->baplock);
838 res = hfa384x_setup_bap(dev,
BAP0, rid, 0);
840 res = hfa384x_from_bap(dev,
BAP0, &rec,
sizeof(rec));
848 if (!res && exact_len && rlen != len) {
850 "rid=0x%04x, len=%d (expected %d)\n",
851 dev->
name, rid, rlen, len);
856 res = hfa384x_from_bap(dev,
BAP0, buf, len);
858 spin_unlock_bh(&local->baplock);
864 "len=%d) - failed - res=%d\n", dev->
name, rid,
867 prism2_hw_reset(dev);
875 static int hfa384x_set_rid(
struct net_device *dev,
u16 rid,
void *buf,
int len)
877 struct hostap_interface *iface;
882 iface = netdev_priv(dev);
883 local = iface->local;
887 "f/w\n", dev->
name, rid, len);
892 if ((local->func->card_present && !local->func->card_present(local)) ||
893 local->hw_downloading)
904 spin_lock_bh(&local->baplock);
905 res = hfa384x_setup_bap(dev,
BAP0, rid, 0);
907 res = hfa384x_to_bap(dev,
BAP0, &rec,
sizeof(rec));
909 res = hfa384x_to_bap(dev,
BAP0, buf, len);
910 spin_unlock_bh(&local->baplock);
914 "failed - res=%d\n", dev->
name, rid, len, res);
924 "failed (res=%d, rid=%04x, len=%d)\n",
925 dev->
name, res, rid, len);
928 prism2_hw_reset(dev);
935 static void hfa384x_disable_interrupts(
struct net_device *dev)
943 static void hfa384x_enable_interrupts(
struct net_device *dev)
951 static void hfa384x_events_no_bap0(
struct net_device *dev)
958 static void hfa384x_events_all(
struct net_device *dev)
964 static void hfa384x_events_only_cmd(
struct net_device *dev)
970 static u16 hfa384x_allocate_fid(
struct net_device *dev,
int len)
988 if (!(
HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC)) {
989 printk(
"%s: fid allocate, len=%d - timeout\n", dev->
name, len);
1000 static int prism2_reset_port(
struct net_device *dev)
1002 struct hostap_interface *iface;
1006 iface = netdev_priv(dev);
1007 local = iface->local;
1009 if (!local->dev_enabled)
1022 "port\n", dev->
name);
1028 if (local->fragm_threshold != 2346 &&
1030 local->fragm_threshold)) {
1032 "threshold (%d) after Port0 enable\n",
1033 dev->
name, local->fragm_threshold);
1043 static int prism2_get_version_info(
struct net_device *dev,
u16 rid,
1047 struct hostap_interface *iface;
1050 iface = netdev_priv(dev);
1051 local = iface->local;
1053 if (local->no_pri) {
1057 if (hfa384x_get_rid(dev, rid, &comp,
sizeof(comp), 1) < 0) {
1069 static int prism2_setup_rids(
struct net_device *dev)
1071 struct hostap_interface *iface;
1076 iface = netdev_priv(dev);
1077 local = iface->local;
1081 if (!local->fw_ap) {
1085 printk(
"%s: Port type setting to %d failed\n",
1093 if (local->iw_mode !=
IW_MODE_MASTER || local->essid[0] !=
'\0') {
1097 printk(
"%s: AP own SSID setting failed\n", dev->
name);
1103 PRISM2_DATA_MAXLEN);
1105 printk(
"%s: MAC data length setting to %d failed\n",
1106 dev->
name, PRISM2_DATA_MAXLEN);
1111 printk(
"%s: Channel list read failed\n", dev->
name);
1117 if (local->channel < 1 || local->channel > 14 ||
1118 !(local->channel_mask & (1 << (local->channel - 1)))) {
1120 "(%d)!\n", dev->
name, local->channel);
1127 printk(
"%s: Channel setting to %d failed\n",
1128 dev->
name, local->channel);
1135 printk(
"%s: Beacon interval setting to %d failed\n",
1136 dev->
name, local->beacon_int);
1143 local->dtim_period);
1145 printk(
"%s: DTIM period setting to %d failed\n",
1146 dev->
name, local->dtim_period);
1156 dev->
name, local->is_promisc);
1158 if (!local->fw_ap) {
1162 printk(
"%s: Desired SSID setting failed\n", dev->
name);
1170 if (local->tx_rate_control == 0) {
1171 local->tx_rate_control =
1177 if (local->basic_rates == 0)
1180 if (!local->fw_ap) {
1182 local->tx_rate_control);
1184 printk(
"%s: TXRateControl setting to %d failed\n",
1185 dev->
name, local->tx_rate_control);
1190 local->tx_rate_control);
1192 printk(
"%s: cnfSupportedRates setting to %d failed\n",
1193 dev->
name, local->tx_rate_control);
1197 local->basic_rates);
1199 printk(
"%s: cnfBasicRates setting to %d failed\n",
1200 dev->
name, local->basic_rates);
1205 printk(
"%s: Create IBSS setting to 1 failed\n",
1210 if (local->name_set)
1226 if (local->sta_fw_ver >= PRISM2_FW_VER(1,6,3) &&
1229 dev->
name, local->enh_sec);
1237 if (local->sta_fw_ver >= PRISM2_FW_VER(0,8,2)) {
1240 "failed\n", dev->
name);
1241 local->tallies32 = 0;
1243 local->tallies32 = 1;
1245 local->tallies32 = 0;
1250 local->fragm_threshold)) {
1252 "failed\n", dev->
name, local->fragm_threshold);
1256 local->rts_threshold)) {
1258 dev->
name, local->rts_threshold);
1261 if (local->manual_retry_count >= 0 &&
1263 local->manual_retry_count)) {
1265 dev->
name, local->manual_retry_count);
1268 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1) &&
1273 if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->wpa &&
1279 if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->generic_elem &&
1281 local->generic_elem, local->generic_elem_len)) {
1291 static int prism2_hw_init(
struct net_device *dev,
int initial)
1293 struct hostap_interface *iface;
1298 PDEBUG(DEBUG_FLOW,
"prism2_hw_init()\n");
1300 iface = netdev_priv(dev);
1301 local = iface->local;
1303 clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits);
1310 "does not have primary firmware\n",
dev_info);
1313 if (first && (
HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
1318 "retrying\n", dev->
name);
1325 while (!(
HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
1328 if (!(
HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
1330 "flash - card initialization not completed\n",
1333 #ifdef PRISM2_DOWNLOAD_SUPPORT
1334 if (local->sram_type == -1)
1335 local->sram_type = prism2_get_ram_size(local);
1341 (jiffies - start) * 1000 /
HZ);
1347 static int prism2_hw_init2(
struct net_device *dev,
int initial)
1349 struct hostap_interface *iface;
1353 iface = netdev_priv(dev);
1354 local = iface->local;
1356 #ifdef PRISM2_DOWNLOAD_SUPPORT
1361 local->pda = prism2_read_pda(dev);
1364 hfa384x_disable_interrupts(dev);
1366 #ifndef final_version
1369 printk(
"SWSUPPORT0 write/read failed: %04X != %04X\n",
1375 if (initial || local->pri_only) {
1376 hfa384x_events_only_cmd(dev);
1380 hfa384x_disable_interrupts(dev);
1386 "- only Primary f/w present\n", dev->
name);
1387 local->pri_only = 1;
1390 local->pri_only = 0;
1391 hfa384x_disable_interrupts(dev);
1399 local->txfid_len = PRISM2_TXFID_LEN;
1400 for (i = 0; i < PRISM2_TXFID_COUNT; i++) {
1401 local->txfid[
i] = hfa384x_allocate_fid(dev, local->txfid_len);
1402 if (local->txfid[i] == 0xffff && local->txfid_len > 1600) {
1403 local->txfid[
i] = hfa384x_allocate_fid(dev, 1600);
1404 if (local->txfid[i] != 0xffff) {
1406 "(1600 bytes)\n", dev->
name);
1407 local->txfid_len = 1600;
1410 if (local->txfid[i] == 0xffff)
1412 local->intransmitfid[
i] = PRISM2_TXFID_EMPTY;
1415 hfa384x_events_only_cmd(dev);
1419 prism2_check_sta_fw_version(local);
1423 printk(
"%s: could not get own MAC address\n",
1430 }
else if (local->fw_ap)
1431 prism2_check_sta_fw_version(local);
1433 prism2_setup_rids(dev);
1445 static int prism2_hw_enable(
struct net_device *dev,
int initial)
1447 struct hostap_interface *iface;
1451 iface = netdev_priv(dev);
1452 local = iface->local;
1453 was_resetting = local->hw_resetting;
1456 printk(
"%s: MAC port 0 enabling failed\n", dev->
name);
1460 local->hw_ready = 1;
1461 local->hw_reset_tries = 0;
1462 local->hw_resetting = 0;
1463 hfa384x_enable_interrupts(dev);
1468 if (initial && prism2_reset_port(dev)) {
1469 printk(
"%s: MAC port 0 resetting failed\n", dev->
name);
1473 if (was_resetting && netif_queue_stopped(dev)) {
1477 netif_wake_queue(dev);
1484 static int prism2_hw_config(
struct net_device *dev,
int initial)
1486 struct hostap_interface *iface;
1489 iface = netdev_priv(dev);
1490 local = iface->local;
1492 if (local->hw_downloading)
1495 if (prism2_hw_init(dev, initial)) {
1496 return local->no_pri ? 0 : 1;
1499 if (prism2_hw_init2(dev, initial))
1504 if (!local->pri_only &&
1505 (initial == 0 || (initial == 2 && local->num_dev_open > 0))) {
1506 if (!local->dev_enabled)
1507 prism2_callback(local, PRISM2_CALLBACK_ENABLE);
1508 local->dev_enabled = 1;
1509 return prism2_hw_enable(dev, initial);
1516 static void prism2_hw_shutdown(
struct net_device *dev,
int no_disable)
1518 struct hostap_interface *iface;
1521 iface = netdev_priv(dev);
1522 local = iface->local;
1525 hfa384x_events_only_cmd(dev);
1527 local->hw_ready = 0;
1528 if (local->dev_enabled)
1529 prism2_callback(local, PRISM2_CALLBACK_DISABLE);
1530 local->dev_enabled = 0;
1532 if (local->func->card_present && !local->func->card_present(local)) {
1534 "during shutdown\n", dev->
name);
1538 if ((no_disable & HOSTAP_HW_NO_DISABLE) == 0 &&
1542 hfa384x_disable_interrupts(dev);
1544 if (no_disable & HOSTAP_HW_ENABLE_CMDCOMPL)
1545 hfa384x_events_only_cmd(dev);
1547 prism2_clear_cmd_queue(local);
1551 static void prism2_hw_reset(
struct net_device *dev)
1553 struct hostap_interface *iface;
1557 static long last_reset = 0;
1566 iface = netdev_priv(dev);
1567 local = iface->local;
1571 "in interrupt context\n", dev->
name);
1575 if (local->hw_downloading)
1578 if (local->hw_resetting) {
1584 local->hw_reset_tries++;
1585 if (local->hw_reset_tries > 10) {
1592 hfa384x_disable_interrupts(dev);
1593 local->hw_resetting = 1;
1594 if (local->func->cor_sreset) {
1602 local->func->cor_sreset(local);
1605 prism2_hw_shutdown(dev, 1);
1606 prism2_hw_config(dev, 0);
1607 local->hw_resetting = 0;
1609 #ifdef PRISM2_DOWNLOAD_SUPPORT
1610 if (local->dl_pri) {
1612 "firmware\n", dev->
name);
1613 if (prism2_download_genesis(local, local->dl_pri) < 0)
1618 if (local->dl_sec) {
1620 "firmware\n", dev->
name);
1621 if (prism2_download_volatile(local, local->dl_sec) < 0)
1644 prism2_hw_reset(local->
dev);
1646 if (netif_queue_stopped(local->
dev)) {
1649 for (i = 0; i < PRISM2_TXFID_COUNT; i++)
1650 if (local->intransmitfid[i] == PRISM2_TXFID_EMPTY) {
1651 PDEBUG(DEBUG_EXTRA,
"prism2_tx_timeout: "
1653 netif_wake_queue(local->
dev);
1663 unsigned long flags;
1666 end = idx = local->next_txfid;
1668 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
1669 local->intransmitfid[
idx] = PRISM2_TXFID_RESERVED;
1670 spin_unlock_irqrestore(&local->txfidlock, flags);
1674 if (idx >= PRISM2_TXFID_COUNT)
1676 }
while (idx != end);
1677 spin_unlock_irqrestore(&local->txfidlock, flags);
1679 PDEBUG(DEBUG_EXTRA2,
"prism2_get_txfid_idx: no room in txfid buf: "
1680 "packet dropped\n");
1681 local->
dev->stats.tx_dropped++;
1688 static void prism2_transmit_cb(
struct net_device *dev,
long context,
1691 struct hostap_interface *iface;
1693 int idx = (
int) context;
1695 iface = netdev_priv(dev);
1696 local = iface->local;
1704 if (idx < 0 || idx >= PRISM2_TXFID_COUNT) {
1706 "idx=%d\n", dev->
name, idx);
1712 "with no pending transmit\n", dev->
name);
1715 if (netif_queue_stopped(dev)) {
1718 netif_wake_queue(dev);
1721 spin_lock(&local->txfidlock);
1725 local->intransmitfid[
idx] = resp0;
1727 PDEBUG(DEBUG_FID,
"%s: prism2_transmit_cb: txfid[%d]=0x%04x, "
1728 "resp0=0x%04x, transmit_txfid=0x%04x\n",
1729 dev->
name, idx, local->txfid[idx],
1730 resp0, local->intransmitfid[local->next_txfid]);
1733 if (idx >= PRISM2_TXFID_COUNT)
1735 local->next_txfid =
idx;
1739 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
1740 spin_unlock(&local->txfidlock);
1744 if (idx >= PRISM2_TXFID_COUNT)
1746 }
while (idx != local->next_txfid);
1747 spin_unlock(&local->txfidlock);
1750 netif_stop_queue(dev);
1756 static int prism2_transmit(
struct net_device *dev,
int idx)
1758 struct hostap_interface *iface;
1762 iface = netdev_priv(dev);
1763 local = iface->local;
1771 "when previous TX was pending\n", dev->
name);
1776 netif_stop_queue(dev);
1779 res = hfa384x_cmd_callback(
1783 prism2_transmit_cb, (
long) idx);
1787 "failed (res=%d)\n", dev->
name, res);
1788 dev->
stats.tx_dropped++;
1789 netif_wake_queue(dev);
1807 struct hostap_interface *iface;
1810 struct hostap_skb_tx_data *
meta;
1814 iface = netdev_priv(dev);
1815 local = iface->local;
1817 meta = (
struct hostap_skb_tx_data *) skb->cb;
1819 prism2_callback(local, PRISM2_CALLBACK_TX_START);
1821 if ((local->func->card_present && !local->func->card_present(local)) ||
1822 !local->hw_ready || local->hw_downloading || local->pri_only) {
1825 " skipping\n", dev->
name);
1834 skb_copy_from_linear_data(skb, &
txdesc.frame_control, hdr_len);
1836 if (ieee80211_is_data(
txdesc.frame_control) &&
1837 ieee80211_has_a4(
txdesc.frame_control) &&
1840 skb_copy_from_linear_data_offset(skb, hdr_len,
txdesc.addr4,
1845 tx_control = local->tx_control;
1846 if (meta->tx_cb_idx) {
1851 txdesc.tx_rate = meta->rate;
1857 idx = prism2_get_txfid_idx(local);
1861 if (local->frame_dump & PRISM2_DUMP_TX_HDR)
1864 spin_lock(&local->baplock);
1865 res = hfa384x_setup_bap(dev,
BAP0, local->txfid[idx], 0);
1870 res = hfa384x_to_bap(dev,
BAP0, skb->
data + hdr_len,
1871 skb->
len - hdr_len);
1872 spin_unlock(&local->baplock);
1875 res = prism2_transmit(dev, idx);
1879 local->intransmitfid[
idx] = PRISM2_TXFID_EMPTY;
1887 prism2_callback(local, PRISM2_CALLBACK_TX_END);
1897 #define EXTRA_FID_READ_TESTS
1901 #ifdef EXTRA_FID_READ_TESTS
1905 for (i = 0; i < 10; i++) {
1910 if (val == val2 && val == val3)
1914 " %04x %04x %04x\n",
1915 dev->
name, i, reg, val, val2, val3);
1916 if ((val == val2 || val == val3) && val != 0)
1918 if (val2 == val3 && val2 != 0)
1922 "%04x (%04x %04x %04x)\n", dev->
name, reg, val, val2, val3);
1934 int res, rx_pending = 0;
1939 prism2_callback(local, PRISM2_CALLBACK_RX_START);
1941 rxfid = prism2_read_fid_reg(dev, HFA384X_RXFID_OFF);
1942 #ifndef final_version
1955 spin_lock(&local->baplock);
1956 res = hfa384x_setup_bap(dev,
BAP0, rxfid, 0);
1961 spin_unlock(&local->baplock);
1971 hdr_len =
sizeof(
rxdesc);
1973 macport = (status >> 8) & 0x07;
1979 if (len > PRISM2_DATA_MAXLEN + 8 ) {
1981 if (len >= (
u16) -14) {
1982 hdr_len -= 65535 -
len;
1987 spin_unlock(&local->baplock);
1989 "length 0x%04x\n", dev->
name, len);
1995 skb = dev_alloc_skb(len + hdr_len);
1997 spin_unlock(&local->baplock);
2006 res = hfa384x_from_bap(dev,
BAP0,
skb_put(skb, len), len);
2007 spin_unlock(&local->baplock);
2010 "frame data\n", dev->
name);
2015 tasklet_schedule(&local->rx_tasklet);
2018 prism2_callback(local, PRISM2_CALLBACK_RX_END);
2026 dev->
stats.rx_dropped++;
2041 rx_hdrlen =
sizeof(*rxdesc);
2042 if (skb->
len <
sizeof(*rxdesc)) {
2045 skb->
len >=
sizeof(*rxdesc) - 30) {
2046 rx_hdrlen = skb->
len;
2055 if (local->frame_dump & PRISM2_DUMP_RX_HDR &&
2056 skb->
len >=
sizeof(*rxdesc))
2060 (!local->monitor_allow_fcserr ||
2064 if (skb->
len > PRISM2_DATA_MAXLEN) {
2066 dev->
name, skb->
len, PRISM2_DATA_MAXLEN);
2071 stats.signal = rxdesc->
signal - local->rssi_to_dBm;
2077 if (hdrlen > rx_hdrlen)
2092 static void hostap_rx_tasklet(
unsigned long data)
2098 hostap_rx_skb(local, skb);
2103 static void prism2_alloc_ev(
struct net_device *dev)
2105 struct hostap_interface *iface;
2110 iface = netdev_priv(dev);
2111 local = iface->local;
2113 fid = prism2_read_fid_reg(dev, HFA384X_ALLOCFID_OFF);
2115 PDEBUG(DEBUG_FID,
"FID: interrupt: ALLOC - fid=0x%04x\n", fid);
2117 spin_lock(&local->txfidlock);
2118 idx = local->next_alloc;
2121 if (local->txfid[idx] == fid) {
2122 PDEBUG(DEBUG_FID,
"FID: found matching txfid[%d]\n",
2125 #ifndef final_version
2126 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY)
2127 printk(
"Already released txfid found at idx "
2129 if (local->intransmitfid[idx] == PRISM2_TXFID_RESERVED)
2130 printk(
"Already reserved txfid found at idx "
2133 local->intransmitfid[
idx] = PRISM2_TXFID_EMPTY;
2135 local->next_alloc = idx >= PRISM2_TXFID_COUNT ? 0 :
2138 if (!
test_bit(HOSTAP_BITS_TRANSMIT, &local->bits) &&
2139 netif_queue_stopped(dev))
2140 netif_wake_queue(dev);
2142 spin_unlock(&local->txfidlock);
2147 if (idx >= PRISM2_TXFID_COUNT)
2149 }
while (idx != local->next_alloc);
2152 "read 0x%04x) for alloc event\n", dev->
name, fid,
2155 for (idx = 0; idx < PRISM2_TXFID_COUNT; idx++)
2156 printk(
" %04x[%04x]", local->txfid[idx],
2157 local->intransmitfid[idx]);
2159 spin_unlock(&local->txfidlock);
2175 struct hostap_tx_callback_info *
cb;
2186 spin_lock(&local->lock);
2187 cb = local->tx_callback;
2188 while (cb !=
NULL && cb->idx != sw_support)
2190 spin_unlock(&local->lock);
2194 local->
dev->name, sw_support);
2200 skb = dev_alloc_skb(hdrlen + len);
2203 "skb\n", local->
dev->name);
2212 skb_reset_mac_header(skb);
2214 cb->func(skb, ok, cb->
data);
2227 fid = prism2_read_fid_reg(dev, HFA384X_TXCOMPLFID_OFF);
2229 PDEBUG(DEBUG_FID,
"interrupt: TX (err=%d) - fid=0x%04x\n", fid, error);
2231 spin_lock(&local->baplock);
2232 res = hfa384x_setup_bap(dev,
BAP0, fid, 0);
2234 res = hfa384x_from_bap(dev,
BAP0, txdesc,
sizeof(*txdesc));
2236 PDEBUG(DEBUG_EXTRA,
"%s: TX (err=%d) - fid=0x%04x - could not "
2237 "read txdesc\n", dev->
name, error, fid);
2246 if (len < PRISM2_DATA_MAXLEN) {
2248 if (*payload ==
NULL ||
2249 hfa384x_from_bap(dev,
BAP0, *payload, len)) {
2250 PDEBUG(DEBUG_EXTRA,
"%s: could not read TX "
2251 "frame payload\n", dev->
name);
2261 spin_unlock(&local->baplock);
2271 char *payload =
NULL;
2274 if (hostap_tx_compl_read(local, 0, &txdesc, &payload))
2277 if (local->frame_dump & PRISM2_DUMP_TX_HDR) {
2278 PDEBUG(DEBUG_EXTRA,
"%s: TX - status=0x%04x "
2279 "retry_count=%d tx_rate=%d seq_ctrl=%d "
2288 hostap_tx_callback(local, &txdesc, 1, payload);
2297 static void hostap_sta_tx_exc_tasklet(
unsigned long data)
2306 if (skb->
len >=
sizeof(*txdesc)) {
2326 char *payload =
NULL;
2329 show_dump = local->frame_dump & PRISM2_DUMP_TXEXC_HDR;
2330 dev->
stats.tx_errors++;
2332 res = hostap_tx_compl_read(local, 1, &txdesc, &payload);
2356 local->wds_type & HOSTAP_WDS_AP_CLIENT) {
2358 skb = dev_alloc_skb(
sizeof(txdesc));
2363 tasklet_schedule(&local->sta_tx_exc_tasklet);
2368 hostap_tx_callback(local, &txdesc, 0, payload);
2374 PDEBUG(DEBUG_EXTRA,
"%s: TXEXC - status=0x%04x (%s%s%s%s)"
2375 " tx_control=%04x\n",
2384 PDEBUG(DEBUG_EXTRA,
" retry_count=%d tx_rate=%d fc=0x%04x "
2385 "(%s%s%s::%d%s%s)\n",
2392 ieee80211_has_fromds(txdesc.
frame_control) ?
" FromDS" :
"");
2393 PDEBUG(DEBUG_EXTRA,
" A1=%pM A2=%pM A3=%pM A4=%pM\n",
2400 static void hostap_info_tasklet(
unsigned long data)
2423 spin_lock(&local->baplock);
2424 res = hfa384x_setup_bap(dev,
BAP0, fid, 0);
2426 res = hfa384x_from_bap(dev,
BAP0, &
info,
sizeof(
info));
2428 spin_unlock(&local->baplock);
2443 spin_unlock(&local->baplock);
2445 "length 0x%04x (type 0x%04x)\n", dev->
name,
2450 skb = dev_alloc_skb(
sizeof(
info) + left);
2452 spin_unlock(&local->baplock);
2454 "frame\n", dev->
name);
2459 if (left > 0 && hfa384x_from_bap(dev,
BAP0,
skb_put(skb, left), left))
2461 spin_unlock(&local->baplock);
2463 "len=0x%04x, type=0x%04x\n", dev->
name, fid,
2468 spin_unlock(&local->baplock);
2471 tasklet_schedule(&local->info_tasklet);
2479 static void hostap_bap_tasklet(
unsigned long data)
2486 if (local->func->card_present && !local->func->card_present(local))
2489 set_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
2493 while (frames-- > 0) {
2502 prism2_tx_ev(local);
2504 prism2_txexc(local);
2507 set_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
2508 clear_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
2511 hfa384x_events_all(dev);
2512 clear_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
2517 static void prism2_infdrop(
struct net_device *dev)
2519 static unsigned long last_inquire = 0;
2521 PDEBUG(DEBUG_EXTRA,
"%s: INFDROP event\n", dev->
name);
2528 if (!last_inquire ||
time_after(jiffies, last_inquire +
HZ)) {
2537 static void prism2_ev_tick(
struct net_device *dev)
2539 struct hostap_interface *iface;
2542 static int prev_stuck = 0;
2544 iface = netdev_priv(dev);
2545 local = iface->local;
2547 if (
time_after(jiffies, local->last_tick_timer + 5 *
HZ) &&
2548 local->last_tick_timer) {
2553 "bits=0x%lx EvStat=%04x IntEn=%04x\n",
2554 dev->
name, local->bits, evstat, inten);
2556 local->sw_tick_stuck++;
2557 if ((evstat & HFA384X_BAP0_EVENTS) &&
2558 (inten & HFA384X_BAP0_EVENTS)) {
2560 "hang\n", dev->
name);
2561 hfa384x_events_no_bap0(dev);
2579 #ifndef final_version
2580 static unsigned long last_magic_err = 0;
2584 if (!local->hw_ready)
2588 printk(
"%s: Interrupt, but SWSUPPORT0 does not match: "
2589 "%04X != %04X - card removed?\n", dev->
name,
2595 "MAGIC=%04x\n", dev->
name,
2599 if (
HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != 0xffff)
2612 struct hostap_interface *iface;
2617 iface = netdev_priv(dev);
2618 local = iface->local;
2621 spin_lock(&local->irq_init_lock);
2627 spin_unlock(&local->irq_init_lock);
2630 spin_unlock(&local->irq_init_lock);
2632 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 0);
2634 if (local->func->card_present && !local->func->card_present(local)) {
2642 prism2_check_magic(local);
2647 if (local->shutdown)
2659 if (ev & HFA384X_EV_CMD) {
2667 if (!local->hw_ready || local->hw_resetting ||
2668 !local->dev_enabled) {
2670 if (ev & HFA384X_EV_CMD)
2677 "not ready; skipping events 0x%04x "
2678 "(IntEn=0x%04x)%s%s%s\n",
2681 !local->hw_ready ?
" (!hw_ready)" :
"",
2682 local->hw_resetting ?
2683 " (hw_resetting)" :
"",
2684 !local->dev_enabled ?
2685 " (!dev_enabled)" :
"");
2692 prism2_ev_tick(dev);
2696 if (ev & HFA384X_EV_ALLOC) {
2697 prism2_alloc_ev(dev);
2704 if (ev & HFA384X_BAP0_EVENTS) {
2705 hfa384x_events_no_bap0(dev);
2706 tasklet_schedule(&local->bap_tasklet);
2709 #ifndef final_version
2711 PDEBUG(DEBUG_EXTRA,
"%s: WTERR event\n", dev->
name);
2717 prism2_infdrop(dev);
2724 PDEBUG(DEBUG_EXTRA,
"prism2_interrupt: >%d events "
2725 "(EvStat=0x%04x)\n",
2731 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 1);
2736 static void prism2_check_sta_fw_version(
local_info_t *local)
2742 &comp,
sizeof(comp), 1) < 0)
2756 local->sta_fw_ver = PRISM2_FW_VER(major, minor, variant);
2764 local->fw_encrypt_ok = local->sta_fw_ver >= PRISM2_FW_VER(1,4,9);
2767 !local->fw_encrypt_ok) {
2769 "a workaround for firmware bug in Host AP mode WEP\n",
2771 local->host_encrypt = 1;
2781 if (local->sta_fw_ver >= PRISM2_FW_VER(1,5,0))
2782 local->wds_type |= HOSTAP_WDS_STANDARD_FRAME;
2785 "workaround for firmware bug in Host AP mode WDS\n",
2793 static void hostap_passive_scan(
unsigned long data)
2799 if (local->passive_scan_interval <= 0)
2802 if (local->passive_scan_state == PASSIVE_SCAN_LISTEN) {
2809 if (
test_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
2811 "TX - delaying\n", dev->
name);
2812 local->passive_scan_timer.expires =
jiffies +
HZ / 10;
2818 local->passive_scan_channel++;
2819 if (local->passive_scan_channel > 14)
2820 local->passive_scan_channel = 1;
2822 }
while (!(local->channel_mask &
2823 (1 << (local->passive_scan_channel - 1))) &&
2826 if (max_tries == 0) {
2828 " found\n", dev->
name);
2833 dev->
name, local->passive_scan_channel);
2834 chan = local->passive_scan_channel;
2835 local->passive_scan_state = PASSIVE_SCAN_WAIT;
2836 local->passive_scan_timer.expires =
jiffies +
HZ / 10;
2838 chan = local->channel;
2839 local->passive_scan_state = PASSIVE_SCAN_LISTEN;
2840 local->passive_scan_timer.expires =
jiffies +
2841 local->passive_scan_interval *
HZ;
2848 "failed\n", dev->
name, chan);
2856 static void handle_comms_qual_update(
struct work_struct *work)
2868 static void hostap_tick_timer(
unsigned long data)
2870 static unsigned long last_inquire = 0;
2872 local->last_tick_timer =
jiffies;
2876 if ((!last_inquire ||
time_after(jiffies, last_inquire + 10 *
HZ)) &&
2877 !local->hw_downloading && local->hw_ready &&
2878 !local->hw_resetting && local->dev_enabled) {
2884 if ((local->last_comms_qual_update == 0 ||
2885 time_after(jiffies, local->last_comms_qual_update + 10 *
HZ)) &&
2891 local->tick_timer.expires =
jiffies + 2 *
HZ;
2896 #ifndef PRISM2_NO_PROCFS_DEBUG
2897 static int prism2_registers_proc_read(
char *
page,
char **start,
off_t off,
2898 int count,
int *eof,
void *data)
2908 #define SHOW_REG(n) \
2909 p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF))
2966 static int prism2_set_tim(
struct net_device *dev,
int aid,
int set)
2970 struct hostap_interface *iface;
2973 iface = netdev_priv(dev);
2974 local = iface->local;
2976 new_entry = kzalloc(
sizeof(*new_entry),
GFP_ATOMIC);
2977 if (new_entry ==
NULL)
2981 new_entry->
set =
set;
2983 spin_lock_bh(&local->set_tim_lock);
2987 if (entry->
aid == aid) {
2988 PDEBUG(DEBUG_PS2,
"%s: prism2_set_tim: aid=%d "
2990 local->
dev->name, aid, entry->
set,
set);
2999 spin_unlock_bh(&local->set_tim_lock);
3007 static void handle_set_tim_queue(
struct work_struct *work)
3015 spin_lock_bh(&local->set_tim_lock);
3016 if (!list_empty(&local->set_tim_list)) {
3021 spin_unlock_bh(&local->set_tim_lock);
3025 PDEBUG(DEBUG_PS2,
"%s: handle_set_tim_queue: aid=%d set=%d\n",
3026 local->
dev->name, entry->
aid, entry->
set);
3034 local->
dev->name, entry->
aid, entry->
set);
3042 static void prism2_clear_set_tim_queue(
local_info_t *local)
3063 static void prism2_set_lockdep_class_one(
struct net_device *dev,
3068 &hostap_netdev_xmit_lock_key);
3071 static void prism2_set_lockdep_class(
struct net_device *dev)
3074 &hostap_netdev_addr_lock_key);
3075 netdev_for_each_tx_queue(dev, prism2_set_lockdep_class_one,
NULL);
3079 prism2_init_local_data(
struct prism2_helper_functions *funcs,
int card_idx,
3083 struct hostap_interface *iface;
3084 struct local_info *local;
3090 len =
strlen(dev_template);
3097 len =
sizeof(
struct hostap_interface) +
3101 dev = alloc_etherdev(len);
3105 iface = netdev_priv(dev);
3106 local = (
struct local_info *) ((((
long) (iface + 1)) + 3) & ~3);
3107 local->ap = (
struct ap_data *) ((((
long) (local + 1)) + 3) & ~3);
3108 local->dev = iface->dev =
dev;
3109 iface->local =
local;
3110 iface->type = HOSTAP_INTERFACE_MASTER;
3111 INIT_LIST_HEAD(&local->hostap_interfaces);
3115 #ifdef PRISM2_IO_DEBUG
3116 local->io_debug_enabled = 1;
3119 local->func = funcs;
3120 local->func->cmd = hfa384x_cmd;
3121 local->func->read_regs = hfa384x_read_regs;
3122 local->func->get_rid = hfa384x_get_rid;
3123 local->func->set_rid = hfa384x_set_rid;
3124 local->func->hw_enable = prism2_hw_enable;
3125 local->func->hw_config = prism2_hw_config;
3126 local->func->hw_reset = prism2_hw_reset;
3127 local->func->hw_shutdown = prism2_hw_shutdown;
3128 local->func->reset_port = prism2_reset_port;
3129 local->func->schedule_reset = prism2_schedule_reset;
3130 #ifdef PRISM2_DOWNLOAD_SUPPORT
3131 local->func->read_aux = prism2_download_aux_dump;
3132 local->func->download = prism2_download;
3134 local->func->tx = prism2_tx_80211;
3135 local->func->set_tim = prism2_set_tim;
3136 local->func->need_tx_headroom = 0;
3152 local->card_idx = card_idx;
3155 memcpy(local->essid, essid,
3156 len > MAX_SSID_LEN ? MAX_SSID_LEN : len);
3157 local->essid[MAX_SSID_LEN] =
'\0';
3164 "IW_MODE_MASTER\n", i);
3168 local->beacon_int =
GET_INT_PARM(beacon_int, card_idx);
3169 local->dtim_period =
GET_INT_PARM(dtim_period, card_idx);
3170 local->wds_max_connections = 16;
3172 local->manual_retry_count = -1;
3173 local->rts_threshold = 2347;
3174 local->fragm_threshold = 2346;
3175 local->rssi_to_dBm = 100;
3178 local->sram_type = -1;
3179 local->scan_channel_mask = 0xffff;
3180 local->monitor_type = PRISM2_MONITOR_RADIOTAP;
3183 INIT_WORK(&local->reset_queue, handle_reset_queue);
3184 INIT_WORK(&local->set_multicast_list_queue,
3187 INIT_WORK(&local->set_tim_queue, handle_set_tim_queue);
3188 INIT_LIST_HEAD(&local->set_tim_list);
3191 INIT_WORK(&local->comms_qual_update, handle_comms_qual_update);
3195 #define HOSTAP_TASKLET_INIT(q, f, d) \
3196 do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \
3199 (
unsigned long) local);
3202 (
unsigned long) local);
3206 hostap_rx_tasklet, (
unsigned long) local);
3207 skb_queue_head_init(&local->rx_list);
3210 hostap_sta_tx_exc_tasklet, (
unsigned long) local);
3211 skb_queue_head_init(&local->sta_tx_exc_list);
3213 INIT_LIST_HEAD(&local->cmd_queue);
3219 local->passive_scan_timer.data = (
unsigned long) local;
3220 local->passive_scan_timer.function = hostap_passive_scan;
3223 local->tick_timer.data = (
unsigned long) local;
3224 local->tick_timer.function = hostap_tick_timer;
3225 local->tick_timer.expires =
jiffies + 2 *
HZ;
3228 INIT_LIST_HEAD(&local->bss_list);
3241 prism2_set_lockdep_class(dev);
3259 static int hostap_hw_ready(
struct net_device *dev)
3261 struct hostap_interface *iface;
3262 struct local_info *local;
3264 iface = netdev_priv(dev);
3265 local = iface->local;
3276 #ifndef PRISM2_NO_PROCFS_DEBUG
3277 create_proc_read_entry(
"registers", 0, local->proc,
3278 prism2_registers_proc_read, local);
3288 static void prism2_free_local_data(
struct net_device *dev)
3290 struct hostap_tx_callback_info *tx_cb, *tx_cb_prev;
3292 struct hostap_interface *iface;
3293 struct local_info *local;
3299 iface = netdev_priv(dev);
3300 local = iface->local;
3305 if (iface->type == HOSTAP_INTERFACE_MASTER) {
3315 flush_work(&local->set_multicast_list_queue);
3317 #ifndef PRISM2_NO_STATION_MODES
3324 if (timer_pending(&local->passive_scan_timer))
3327 if (timer_pending(&local->tick_timer))
3330 prism2_clear_cmd_queue(local);
3336 if (local->dev_enabled)
3337 prism2_callback(local, PRISM2_CALLBACK_DISABLE);
3339 if (local->ap !=
NULL)
3342 #ifndef PRISM2_NO_PROCFS_DEBUG
3343 if (local->proc !=
NULL)
3348 tx_cb = local->tx_callback;
3349 while (tx_cb !=
NULL) {
3351 tx_cb = tx_cb->next;
3358 for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
3359 if (local->frag_cache[i].skb !=
NULL)
3360 dev_kfree_skb(local->frag_cache[i].skb);
3363 #ifdef PRISM2_DOWNLOAD_SUPPORT
3364 prism2_download_free_data(local->dl_pri);
3365 prism2_download_free_data(local->dl_sec);
3368 prism2_clear_set_tim_queue(local);
3371 struct hostap_bss_info *bss =
3377 kfree(local->last_scan_results);
3378 kfree(local->generic_elem);
3384 #if (defined(PRISM2_PCI) && defined(CONFIG_PM)) || defined(PRISM2_PCCARD)
3385 static void prism2_suspend(
struct net_device *dev)
3387 struct hostap_interface *iface;
3388 struct local_info *local;
3391 iface = netdev_priv(dev);
3392 local = iface->local;
3396 memset(&wrqu, 0,
sizeof(wrqu));
3401 prism2_hw_shutdown(dev, 0);
3408 #ifdef PRISM2_DOWNLOAD_SUPPORT
3412 #ifdef PRISM2_CALLBACK
3417 #include "hostap_callback.c"