77 #define DRIVER_NAME "orinoco"
79 #include <linux/module.h>
80 #include <linux/kernel.h>
81 #include <linux/slab.h>
84 #include <linux/device.h>
85 #include <linux/netdevice.h>
88 #include <linux/if_arp.h>
89 #include <linux/wireless.h>
113 "and similar wireless cards");
118 int orinoco_debug = ORINOCO_DEBUG;
124 static bool suppress_linkstatus;
128 static int ignore_disconnect;
131 "Don't report lost link to the network layer");
142 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
143 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
145 #define ORINOCO_MIN_MTU 256
146 #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
148 #define MAX_IRQLOOPS_PER_IRQ 10
149 #define MAX_IRQLOOPS_PER_JIFFY (20000 / HZ)
154 #define DUMMY_FID 0xFFFF
158 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
160 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
161 | HERMES_EV_TX | HERMES_EV_TXEXC \
162 | HERMES_EV_WTERR | HERMES_EV_INFO \
218 static int __orinoco_set_multicast_list(
struct net_device *
dev);
263 if (orinoco_lock(priv, &flags) != 0)
266 err = __orinoco_up(priv);
271 orinoco_unlock(priv, &flags);
285 orinoco_lock_irq(priv);
289 err = __orinoco_down(priv);
291 orinoco_unlock_irq(priv);
310 if (orinoco_lock(priv, &flags) != 0) {
312 "called when hw_unavailable\n", dev->
name);
316 __orinoco_set_multicast_list(dev);
317 orinoco_unlock(priv, &flags);
399 "%s: Not enough headroom for 802.2 headers %d\n",
400 dev->
name, skb_headroom(skb));
406 hdr.eth.h_proto =
htons(len);
407 memcpy(hdr.encap, encaps_hdr,
sizeof(encaps_hdr));
411 memcpy(eh, &hdr,
sizeof(hdr));
417 u8 *
mic = &mic_buf[0];
422 *mic = skb->
data[skb->
len - 1];
447 if (!netif_running(dev)) {
453 if (netif_queue_stopped(dev)) {
459 if (orinoco_lock(priv, &flags) != 0) {
460 printk(
KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
465 if (!netif_carrier_ok(dev) ||
492 memset(&desc, 0,
sizeof(desc));
495 err = hw->
ops->bap_pwrite(hw,
USER_BAP, &desc,
sizeof(desc),
500 "descriptor to BAP\n", dev->
name, err);
506 memset(&desc, 0,
sizeof(desc));
509 err = hw->
ops->bap_pwrite(hw,
USER_BAP, &desc,
sizeof(desc),
514 "descriptor to BAP\n", dev->
name, err);
541 err = hw->
ops->bap_pwrite(hw,
USER_BAP, &mic_buf[0], len,
551 netif_stop_queue(dev);
556 netif_start_queue(dev);
571 orinoco_unlock(priv, &flags);
578 orinoco_unlock(priv, &flags);
587 if (fid != priv->
txfid) {
604 netif_wake_queue(dev);
631 "(FID=%04X error %d)\n",
632 dev->
name, fid, err);
636 DEBUG(1,
"%s: Tx error, err %d (FID=%04X)\n", dev->
name,
662 netif_wake_queue(dev);
672 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
688 static inline int is_ethersnap(
void *_hdr)
697 return (
memcmp(hdr, &encaps_hdr, 5) == 0)
698 && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
702 int level,
int noise)
705 wstats.
level = level - 0x95;
706 wstats.noise = noise - 0x95;
707 wstats.qual = (level >
noise) ? (level - noise) : 0;
713 static void orinoco_stat_gather(
struct net_device *dev,
730 orinoco_spy_gather(dev, skb_mac_header(skb) +
ETH_ALEN,
745 static void orinoco_rx_monitor(
struct net_device *dev,
u16 rxfid,
797 "data length = %d\n", dev->
name, datalen);
802 skb = dev_alloc_skb(hdrlen + datalen);
811 skb_reset_mac_header(skb);
816 ALIGN(datalen, 2), rxfid,
858 "%s: Can't allocate space for RX descriptor\n",
865 err = hw->
ops->bap_pread(hw,
IRQ_BAP, desc,
sizeof(*desc),
869 "Frame dropped.\n", dev->
name, err);
876 DEBUG(1,
"%s: Bad CRC on Rx. Frame dropped.\n",
884 orinoco_rx_monitor(dev, rxfid, desc);
889 DEBUG(1,
"%s: Undecryptable frame on Rx. Frame dropped.\n",
921 skb = dev_alloc_skb(length +
ETH_HLEN + 2 + 1);
934 ALIGN(length, 2), rxfid,
938 "Frame dropped.\n", dev->
name, err);
943 rx_data = kzalloc(
sizeof(*rx_data),
GFP_ATOMIC);
964 static void orinoco_rx(
struct net_device *dev,
979 if (status & HERMES_RXSTAT_MIC) {
998 "%pM using key %i, but key is not installed\n",
999 dev->
name, src, key_id);
1005 skb->
data, skb->
len, &mic[0]);
1013 "Invalid Michael MIC in data frame from %pM, "
1015 dev->
name, src, key_id);
1020 memset(&wxmic, 0,
sizeof(wxmic));
1022 wxmic.flags |= (desc->
addr1[0] & 1) ?
1030 memset(&wrqu, 0,
sizeof(wrqu));
1031 wrqu.data.length =
sizeof(wxmic);
1047 is_ethersnap(skb->
data))) {
1059 if (fc & IEEE80211_FCTL_FROMDS)
1066 if (fc & IEEE80211_FCTL_TODS)
1070 orinoco_stat_gather(dev, skb, desc);
1085 static void orinoco_rx_isr_tasklet(
unsigned long data)
1092 unsigned long flags;
1100 if (orinoco_lock(priv, &flags) != 0)
1105 desc = rx_data->
desc;
1110 orinoco_rx(dev, desc, skb);
1115 orinoco_unlock(priv, &flags);
1122 static void print_linkstatus(
struct net_device *dev,
u16 status)
1126 if (suppress_linkstatus)
1131 s =
"Not Connected";
1143 s =
"AP Out of Range";
1149 s =
"Association Failed";
1156 dev->
name, s, status);
1167 unsigned long flags;
1184 if (orinoco_lock(priv, &flags) != 0)
1208 for (; offset + atom_len <= len; offset += atom_len) {
1217 DEBUG(1,
"%s: Requested AP not found in scan results\n",
1230 orinoco_unlock(priv, &flags);
1255 static void orinoco_send_assocreqie_wevent(
struct orinoco_private *priv)
1268 sizeof(buf),
NULL, &buf);
1272 ie = orinoco_get_wpa_ie(buf,
sizeof(buf));
1274 int rem =
sizeof(
buf) - (ie - &buf[0]);
1275 wrqu.data.length = ie[1] + 2;
1276 if (wrqu.data.length > rem)
1277 wrqu.data.length = rem;
1279 if (wrqu.data.length)
1285 static void orinoco_send_assocrespie_wevent(
struct orinoco_private *priv)
1299 sizeof(buf),
NULL, &buf);
1303 ie = orinoco_get_wpa_ie(buf,
sizeof(buf));
1305 int rem =
sizeof(
buf) - (ie - &buf[0]);
1306 wrqu.data.length = ie[1] + 2;
1307 if (wrqu.data.length > rem)
1308 wrqu.data.length = rem;
1310 if (wrqu.data.length)
1316 static void orinoco_send_wevents(
struct work_struct *work)
1320 unsigned long flags;
1322 if (orinoco_lock(priv, &flags) != 0)
1325 orinoco_send_assocreqie_wevent(priv);
1326 orinoco_send_assocrespie_wevent(priv);
1327 orinoco_send_bssid_wevent(priv);
1329 orinoco_unlock(priv, &flags);
1336 unsigned long flags;
1349 spin_unlock_irqrestore(&priv->
scan_lock, flags);
1357 unsigned long flags;
1368 spin_unlock_irqrestore(&priv->
scan_lock, flags);
1373 static void orinoco_process_scan_results(
struct work_struct *work)
1378 unsigned long flags;
1391 spin_unlock_irqrestore(&priv->
scan_lock, flags);
1429 err = hw->
ops->bap_pread(hw,
IRQ_BAP, &info,
sizeof(info),
1433 "Frame dropped.\n", dev->
name, err);
1445 if (len >
sizeof(tallies)) {
1448 len =
sizeof(tallies);
1451 err = hw->
ops->bap_pread(hw,
IRQ_BAP, &tallies, len,
1452 infofid,
sizeof(info));
1460 if (len ==
sizeof(tallies))
1488 infofid,
sizeof(info));
1508 else if (!ignore_disconnect)
1513 print_linkstatus(dev, newstatus);
1552 err = hw->
ops->bap_pread(hw,
IRQ_BAP, (
void *) buf, len,
1553 infofid,
sizeof(info));
1560 #ifdef ORINOCO_DEBUG
1564 for (i = 1; i < (len * 2); i++)
1570 qbuf_scan(priv, buf, len, type);
1579 "len=%d\n", dev->
name, len);
1585 qbuf_scan(priv,
NULL, len, type);
1595 "%s: Ext scan results too short (%d bytes)\n",
1605 err = hw->
ops->bap_pread(hw,
IRQ_BAP, (
void *) bss, len,
1606 infofid,
sizeof(info));
1610 qbuf_scan(priv, bss, len, type);
1622 "type 0x%04x, length %d\n", dev->
name, type, len);
1629 static void __orinoco_ev_infdrop(
struct net_device *dev,
struct hermes *hw)
1647 err = __orinoco_commit(priv);
1656 err = hermes_enable_port(hw, 0);
1663 netif_start_queue(dev);
1674 netif_stop_queue(dev);
1678 err = hermes_disable_port(hw, 0);
1688 hermes_set_irqmask(hw, 0);
1706 err = hw->
ops->init(hw);
1719 __orinoco_set_multicast_list(
struct net_device *dev)
1750 unsigned long flags;
1752 if (orinoco_lock(priv, &flags) != 0)
1758 netif_stop_queue(dev);
1762 hermes_set_irqmask(hw, 0);
1769 orinoco_unlock(priv, &flags);
1778 "performing hard reset\n", dev->
name, err);
1783 err = orinoco_reinit_firmware(priv);
1785 printk(
KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1791 orinoco_lock_irq(priv);
1798 err = __orinoco_up(priv);
1806 orinoco_unlock_irq(priv);
1810 hermes_set_irqmask(hw, 0);
1829 (
void) __orinoco_set_multicast_list(dev);
1848 err = hermes_disable_port(hw, 0);
1851 "while reconfiguring card\n", dev->
name);
1856 err = __orinoco_commit(priv);
1863 err = hermes_enable_port(hw, 0);
1909 static int last_irq_jiffy;
1910 static int loops_this_jiffy;
1911 unsigned long flags;
1913 if (orinoco_lock(priv, &flags) != 0) {
1920 events = evstat & hw->
inten;
1922 orinoco_unlock(priv, &flags);
1926 if (jiffies != last_irq_jiffy)
1927 loops_this_jiffy = 0;
1930 while (events && count--) {
1933 "much! Resetting.\n", dev->
name);
1935 hermes_set_irqmask(hw, 0);
1941 if (!hermes_present(hw)) {
1942 DEBUG(0,
"orinoco_interrupt(): card removed\n");
1947 __orinoco_ev_tick(dev, hw);
1949 __orinoco_ev_wterr(dev, hw);
1951 __orinoco_ev_infdrop(dev, hw);
1957 __orinoco_ev_txexc(dev, hw);
1959 __orinoco_ev_tx(dev, hw);
1961 __orinoco_ev_alloc(dev, hw);
1966 events = evstat & hw->
inten;
1969 orinoco_unlock(priv, &flags);
1977 #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
1979 unsigned long pm_event,
2017 priv->
pm_notifier.notifier_call = orinoco_pm_notifier;
2026 #define orinoco_register_pm_notifier(priv) do { } while (0)
2027 #define orinoco_unregister_pm_notifier(priv) do { } while (0)
2046 err = hw->
ops->init(hw);
2048 dev_err(dev,
"Failed to initialize firmware (err = %d)\n",
2057 dev_err(dev,
"Incompatible firmware, aborting\n");
2062 #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
2075 dev_err(dev,
"Incompatible firmware, aborting\n");
2081 dev_info(dev,
"Ad-hoc demo mode supported\n");
2083 dev_info(dev,
"IEEE standard IBSS ad-hoc mode supported\n");
2085 dev_info(dev,
"WEP supported, %s-bit key\n",
2088 dev_info(dev,
"WPA-PSK supported\n");
2090 dev_err(dev,
"Failed to setup MIC crypto algorithm. "
2091 "Disabling WPA support\n");
2102 dev_err(dev,
"Failed to allocate NIC buffer!\n");
2129 orinoco_lock_irq(priv);
2131 orinoco_unlock_irq(priv);
2143 .ndo_start_xmit = orinoco_xmit,
2195 priv = wiphy_priv(wiphy);
2199 priv->
card = (
void *)((
unsigned long)priv
2223 INIT_LIST_HEAD(&priv->
rx_list);
2225 (
unsigned long) priv);
2228 INIT_LIST_HEAD(&priv->scan_list);
2229 INIT_WORK(&priv->process_scan, orinoco_process_scan_results);
2231 priv->last_linkstatus = 0xffff;
2233 #if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
2234 priv->cached_pri_fw =
NULL;
2235 priv->cached_fw =
NULL;
2253 unsigned long base_addr,
2268 wdev = netdev_priv(dev);
2269 wdev->
wiphy = wiphy;
2342 dev_kfree_skb(rx_data->
skb);
2352 if ((sd->
len > 0) && sd->
buf)
2370 unsigned long flags;
2373 priv->
hw.ops->lock_irqsave(&priv->
lock, &flags);
2375 err = orinoco_reinit_firmware(priv);
2386 err = __orinoco_up(priv);
2393 priv->
hw.ops->unlock_irqrestore(&priv->
lock, &flags);
2402 unsigned long flags;
2405 priv->
hw.ops->lock_irqsave(&priv->
lock, &flags);
2406 err = __orinoco_down(priv);
2413 priv->
hw.ops->unlock_irqrestore(&priv->
lock, &flags);
2427 static int __init init_orinoco(
void)
2433 static void __exit exit_orinoco(
void)