1 /* main.c - (formerly known as dldwd_cs.c, orinoco_cs.c and orinoco.c)
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
10 * (C) Copyright David Gibson, IBM Corporation 2001-2003.
11 * Copyright (C) 2000 David Gibson, Linuxcare Australia.
12 * With some help from :
13 * Copyright (C) 2001 Jean Tourrilhes, HP Labs
14 * Copyright (C) 2001 Benjamin Herrenschmidt
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
18 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
19 * AT fasta.fh-dortmund.de>
20 * http://www.stud.fh-dortmund.de/~andy/wvlan/
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
32 * The initial developer of the original code is David A. Hinds
33 * <dahinds AT users.sourceforge.net>. Portions created by David
34 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
37 * Alternatively, the contents of this file may be used under the
38 * terms of the GNU General Public License version 2 (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of the
40 * above. If you wish to allow the use of your version of this file
41 * only under the terms of the GPL and not to allow others to use your
42 * version of this file under the MPL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and
44 * other provisions required by the GPL. If you do not delete the
45 * provisions above, a recipient may use your version of this file
46 * under either the MPL or the GPL. */
50 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
52 * o Fix possible races in SPY handling.
53 * o Disconnect wireless extensions from fundamental configuration.
54 * o (maybe) Software WEP support (patch from Stano Meduna).
55 * o (maybe) Use multiple Tx buffers - driver handling queue
56 * rather than firmware.
59 /* Locking and synchronization:
61 * The basic principle is that everything is serialized through a
62 * single spinlock, priv->lock. The lock is used in user, bh and irq
63 * context, so when taken outside hardirq context it should always be
64 * taken with interrupts disabled. The lock protects both the
65 * hardware and the struct orinoco_private.
67 * Another flag, priv->hw_unavailable indicates that the hardware is
68 * unavailable for an extended period of time (e.g. suspended, or in
69 * the middle of a hard reset). This flag is protected by the
70 * spinlock. All code which touches the hardware should check the
71 * flag after taking the lock, and if it is set, give up on whatever
72 * they are doing and drop the lock again. The orinoco_lock()
73 * function handles this (it unlocks and returns -EBUSY if
74 * hw_unavailable is non-zero).
77 #define DRIVER_NAME "orinoco"
79 #include <linux/module.h>
80 #include <linux/kernel.h>
81 #include <linux/init.h>
82 #include <linux/delay.h>
83 #include <linux/netdevice.h>
84 #include <linux/etherdevice.h>
85 #include <linux/ethtool.h>
86 #include <linux/suspend.h>
87 #include <linux/if_arp.h>
88 #include <linux/wireless.h>
89 #include <linux/ieee80211.h>
90 #include <net/iw_handler.h>
92 #include "hermes_rid.h"
93 #include "hermes_dld.h"
103 /********************************************************************/
104 /* Module information */
105 /********************************************************************/
107 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
108 "David Gibson <hermes@gibson.dropbear.id.au>");
109 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
110 "and similar wireless cards");
111 MODULE_LICENSE("Dual MPL/GPL");
113 /* Level of debugging. Used in the macros in orinoco.h */
115 int orinoco_debug = ORINOCO_DEBUG;
116 EXPORT_SYMBOL(orinoco_debug);
117 module_param(orinoco_debug, int, 0644);
118 MODULE_PARM_DESC(orinoco_debug, "Debug level");
121 static int suppress_linkstatus; /* = 0 */
122 module_param(suppress_linkstatus, bool, 0644);
123 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
125 static int ignore_disconnect; /* = 0 */
126 module_param(ignore_disconnect, int, 0644);
127 MODULE_PARM_DESC(ignore_disconnect,
128 "Don't report lost link to the network layer");
130 int force_monitor; /* = 0 */
131 module_param(force_monitor, int, 0644);
132 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
134 /********************************************************************/
135 /* Internal constants */
136 /********************************************************************/
138 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
139 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
140 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
142 #define ORINOCO_MIN_MTU 256
143 #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
145 #define SYMBOL_MAX_VER_LEN (14)
146 #define MAX_IRQLOOPS_PER_IRQ 10
147 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
148 * how many events the
150 * legitimately generate */
151 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
153 #define DUMMY_FID 0xFFFF
155 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
156 HERMES_MAX_MULTICAST : 0)*/
157 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
159 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
160 | HERMES_EV_TX | HERMES_EV_TXEXC \
161 | HERMES_EV_WTERR | HERMES_EV_INFO \
164 static const struct ethtool_ops orinoco_ethtool_ops;
166 /********************************************************************/
168 /********************************************************************/
170 /* Beginning of the Tx descriptor, used in TxExc handling */
171 struct hermes_txexc_data {
172 struct hermes_tx_descriptor desc;
176 } __attribute__ ((packed));
178 /* Rx frame header except compatibility 802.3 header */
179 struct hermes_rx_descriptor {
200 } __attribute__ ((packed));
202 struct orinoco_rx_data {
203 struct hermes_rx_descriptor *desc;
205 struct list_head list;
208 /********************************************************************/
209 /* Function prototypes */
210 /********************************************************************/
212 static void __orinoco_set_multicast_list(struct net_device *dev);
214 /********************************************************************/
215 /* Internal helper functions */
216 /********************************************************************/
218 void set_port_type(struct orinoco_private *priv)
220 switch (priv->iw_mode) {
223 priv->createibss = 0;
226 if (priv->prefer_port3) {
228 priv->createibss = 0;
230 priv->port_type = priv->ibss_port;
231 priv->createibss = 1;
234 case IW_MODE_MONITOR:
236 priv->createibss = 0;
239 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
244 /********************************************************************/
246 /********************************************************************/
248 static int orinoco_open(struct net_device *dev)
250 struct orinoco_private *priv = netdev_priv(dev);
254 if (orinoco_lock(priv, &flags) != 0)
257 err = __orinoco_up(dev);
262 orinoco_unlock(priv, &flags);
267 static int orinoco_stop(struct net_device *dev)
269 struct orinoco_private *priv = netdev_priv(dev);
272 /* We mustn't use orinoco_lock() here, because we need to be
273 able to close the interface even if hw_unavailable is set
274 (e.g. as we're released after a PC Card removal) */
275 spin_lock_irq(&priv->lock);
279 err = __orinoco_down(dev);
281 spin_unlock_irq(&priv->lock);
286 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
288 struct orinoco_private *priv = netdev_priv(dev);
293 static void orinoco_set_multicast_list(struct net_device *dev)
295 struct orinoco_private *priv = netdev_priv(dev);
298 if (orinoco_lock(priv, &flags) != 0) {
299 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
300 "called when hw_unavailable\n", dev->name);
304 __orinoco_set_multicast_list(dev);
305 orinoco_unlock(priv, &flags);
308 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
310 struct orinoco_private *priv = netdev_priv(dev);
312 if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
315 /* MTU + encapsulation + header length */
316 if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
317 (priv->nicbuf_size - ETH_HLEN))
325 /********************************************************************/
327 /********************************************************************/
329 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
331 struct orinoco_private *priv = netdev_priv(dev);
332 struct net_device_stats *stats = &priv->stats;
333 hermes_t *hw = &priv->hw;
335 u16 txfid = priv->txfid;
340 if (!netif_running(dev)) {
341 printk(KERN_ERR "%s: Tx on stopped device!\n",
343 return NETDEV_TX_BUSY;
346 if (netif_queue_stopped(dev)) {
347 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
349 return NETDEV_TX_BUSY;
352 if (orinoco_lock(priv, &flags) != 0) {
353 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
355 return NETDEV_TX_BUSY;
358 if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
359 /* Oops, the firmware hasn't established a connection,
360 silently drop the packet (this seems to be the
365 /* Check packet length */
366 if (skb->len < ETH_HLEN)
369 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
371 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
372 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
375 if (priv->has_alt_txcntl) {
376 /* WPA enabled firmwares have tx_cntl at the end of
377 * the 802.11 header. So write zeroed descriptor and
378 * 802.11 header at the same time
380 char desc[HERMES_802_3_OFFSET];
381 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
383 memset(&desc, 0, sizeof(desc));
385 *txcntl = cpu_to_le16(tx_control);
386 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
390 printk(KERN_ERR "%s: Error %d writing Tx "
391 "descriptor to BAP\n", dev->name, err);
395 struct hermes_tx_descriptor desc;
397 memset(&desc, 0, sizeof(desc));
399 desc.tx_control = cpu_to_le16(tx_control);
400 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
404 printk(KERN_ERR "%s: Error %d writing Tx "
405 "descriptor to BAP\n", dev->name, err);
409 /* Clear the 802.11 header and data length fields - some
410 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
411 * if this isn't done. */
412 hermes_clear_words(hw, HERMES_DATA0,
413 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
416 eh = (struct ethhdr *)skb->data;
418 /* Encapsulate Ethernet-II frames */
419 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
420 struct header_struct {
421 struct ethhdr eth; /* 802.3 header */
422 u8 encap[6]; /* 802.2 header */
423 } __attribute__ ((packed)) hdr;
425 /* Strip destination and source from the data */
426 skb_pull(skb, 2 * ETH_ALEN);
428 /* And move them to a separate header */
429 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
430 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
431 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
433 /* Insert the SNAP header */
434 if (skb_headroom(skb) < sizeof(hdr)) {
436 "%s: Not enough headroom for 802.2 headers %d\n",
437 dev->name, skb_headroom(skb));
440 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
441 memcpy(eh, &hdr, sizeof(hdr));
444 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
445 txfid, HERMES_802_3_OFFSET);
447 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
452 /* Calculate Michael MIC */
453 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
454 u8 mic_buf[MICHAEL_MIC_LEN + 1];
460 /* MIC start is on an odd boundary */
461 mic_buf[0] = skb->data[skb->len - 1];
463 offset = skb->len - 1;
464 len = MICHAEL_MIC_LEN + 1;
468 len = MICHAEL_MIC_LEN;
471 orinoco_mic(priv->tx_tfm_mic,
472 priv->tkip_key[priv->tx_key].tx_mic,
473 eh->h_dest, eh->h_source, 0 /* priority */,
474 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
477 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
478 txfid, HERMES_802_3_OFFSET + offset);
480 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
486 /* Finally, we actually initiate the send */
487 netif_stop_queue(dev);
489 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
492 netif_start_queue(dev);
494 printk(KERN_ERR "%s: Error %d transmitting packet\n",
499 dev->trans_start = jiffies;
500 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
508 orinoco_unlock(priv, &flags);
514 schedule_work(&priv->reset_work);
515 orinoco_unlock(priv, &flags);
516 return NETDEV_TX_BUSY;
519 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
521 struct orinoco_private *priv = netdev_priv(dev);
522 u16 fid = hermes_read_regn(hw, ALLOCFID);
524 if (fid != priv->txfid) {
525 if (fid != DUMMY_FID)
526 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
531 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
534 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
536 struct orinoco_private *priv = netdev_priv(dev);
537 struct net_device_stats *stats = &priv->stats;
541 netif_wake_queue(dev);
543 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
546 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
548 struct orinoco_private *priv = netdev_priv(dev);
549 struct net_device_stats *stats = &priv->stats;
550 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
552 struct hermes_txexc_data hdr;
555 if (fid == DUMMY_FID)
556 return; /* Nothing's really happened */
558 /* Read part of the frame header - we need status and addr1 */
559 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
560 sizeof(struct hermes_txexc_data),
563 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
567 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
568 "(FID=%04X error %d)\n",
569 dev->name, fid, err);
573 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
576 /* We produce a TXDROP event only for retry or lifetime
577 * exceeded, because that's the only status that really mean
578 * that this particular node went away.
579 * Other errors means that *we* screwed up. - Jean II */
580 status = le16_to_cpu(hdr.desc.status);
581 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
582 union iwreq_data wrqu;
584 /* Copy 802.11 dest address.
585 * We use the 802.11 header because the frame may
586 * not be 802.3 or may be mangled...
587 * In Ad-Hoc mode, it will be the node address.
588 * In managed mode, it will be most likely the AP addr
589 * User space will figure out how to convert it to
590 * whatever it needs (IP address or else).
592 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
593 wrqu.addr.sa_family = ARPHRD_ETHER;
595 /* Send event to user space */
596 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
599 netif_wake_queue(dev);
602 static void orinoco_tx_timeout(struct net_device *dev)
604 struct orinoco_private *priv = netdev_priv(dev);
605 struct net_device_stats *stats = &priv->stats;
606 struct hermes *hw = &priv->hw;
608 printk(KERN_WARNING "%s: Tx timeout! "
609 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
610 dev->name, hermes_read_regn(hw, ALLOCFID),
611 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
615 schedule_work(&priv->reset_work);
618 /********************************************************************/
619 /* Rx path (data frames) */
620 /********************************************************************/
622 /* Does the frame have a SNAP header indicating it should be
623 * de-encapsulated to Ethernet-II? */
624 static inline int is_ethersnap(void *_hdr)
628 /* We de-encapsulate all packets which, a) have SNAP headers
629 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
630 * and where b) the OUI of the SNAP header is 00:00:00 or
631 * 00:00:f8 - we need both because different APs appear to use
632 * different OUIs for some reason */
633 return (memcmp(hdr, &encaps_hdr, 5) == 0)
634 && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
637 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
638 int level, int noise)
640 struct iw_quality wstats;
641 wstats.level = level - 0x95;
642 wstats.noise = noise - 0x95;
643 wstats.qual = (level > noise) ? (level - noise) : 0;
644 wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
645 /* Update spy records */
646 wireless_spy_update(dev, mac, &wstats);
649 static void orinoco_stat_gather(struct net_device *dev,
651 struct hermes_rx_descriptor *desc)
653 struct orinoco_private *priv = netdev_priv(dev);
655 /* Using spy support with lots of Rx packets, like in an
656 * infrastructure (AP), will really slow down everything, because
657 * the MAC address must be compared to each entry of the spy list.
658 * If the user really asks for it (set some address in the
659 * spy list), we do it, but he will pay the price.
660 * Note that to get here, you need both WIRELESS_SPY
661 * compiled in AND some addresses in the list !!!
663 /* Note : gcc will optimise the whole section away if
664 * WIRELESS_SPY is not defined... - Jean II */
665 if (SPY_NUMBER(priv)) {
666 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
667 desc->signal, desc->silence);
672 * orinoco_rx_monitor - handle received monitor frames.
677 * desc rx descriptor of the frame
679 * Call context: interrupt
681 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
682 struct hermes_rx_descriptor *desc)
684 u32 hdrlen = 30; /* return full header by default */
690 struct orinoco_private *priv = netdev_priv(dev);
691 struct net_device_stats *stats = &priv->stats;
692 hermes_t *hw = &priv->hw;
694 len = le16_to_cpu(desc->data_len);
696 /* Determine the size of the header and the data */
697 fc = le16_to_cpu(desc->frame_ctl);
698 switch (fc & IEEE80211_FCTL_FTYPE) {
699 case IEEE80211_FTYPE_DATA:
700 if ((fc & IEEE80211_FCTL_TODS)
701 && (fc & IEEE80211_FCTL_FROMDS))
707 case IEEE80211_FTYPE_MGMT:
711 case IEEE80211_FTYPE_CTL:
712 switch (fc & IEEE80211_FCTL_STYPE) {
713 case IEEE80211_STYPE_PSPOLL:
714 case IEEE80211_STYPE_RTS:
715 case IEEE80211_STYPE_CFEND:
716 case IEEE80211_STYPE_CFENDACK:
719 case IEEE80211_STYPE_CTS:
720 case IEEE80211_STYPE_ACK:
726 /* Unknown frame type */
730 /* sanity check the length */
731 if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
732 printk(KERN_DEBUG "%s: oversized monitor frame, "
733 "data length = %d\n", dev->name, datalen);
734 stats->rx_length_errors++;
738 skb = dev_alloc_skb(hdrlen + datalen);
740 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
745 /* Copy the 802.11 header to the skb */
746 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
747 skb_reset_mac_header(skb);
749 /* If any, copy the data from the card to the skb */
751 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
752 ALIGN(datalen, 2), rxfid,
753 HERMES_802_2_OFFSET);
755 printk(KERN_ERR "%s: error %d reading monitor frame\n",
762 skb->ip_summed = CHECKSUM_NONE;
763 skb->pkt_type = PACKET_OTHERHOST;
764 skb->protocol = cpu_to_be16(ETH_P_802_2);
767 stats->rx_bytes += skb->len;
773 dev_kfree_skb_irq(skb);
779 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
781 struct orinoco_private *priv = netdev_priv(dev);
782 struct net_device_stats *stats = &priv->stats;
783 struct iw_statistics *wstats = &priv->wstats;
784 struct sk_buff *skb = NULL;
787 struct hermes_rx_descriptor *desc;
788 struct orinoco_rx_data *rx_data;
791 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
794 "%s: Can't allocate space for RX descriptor\n",
799 rxfid = hermes_read_regn(hw, RXFID);
801 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
804 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
805 "Frame dropped.\n", dev->name, err);
809 status = le16_to_cpu(desc->status);
811 if (status & HERMES_RXSTAT_BADCRC) {
812 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
814 stats->rx_crc_errors++;
818 /* Handle frames in monitor mode */
819 if (priv->iw_mode == IW_MODE_MONITOR) {
820 orinoco_rx_monitor(dev, rxfid, desc);
824 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
825 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
827 wstats->discard.code++;
831 length = le16_to_cpu(desc->data_len);
834 if (length < 3) { /* No for even an 802.2 LLC header */
835 /* At least on Symbol firmware with PCF we get quite a
836 lot of these legitimately - Poll frames with no
840 if (length > IEEE80211_MAX_DATA_LEN) {
841 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
843 stats->rx_length_errors++;
847 /* Payload size does not include Michael MIC. Increase payload
848 * size to read it together with the data. */
849 if (status & HERMES_RXSTAT_MIC)
850 length += MICHAEL_MIC_LEN;
852 /* We need space for the packet data itself, plus an ethernet
853 header, plus 2 bytes so we can align the IP header on a
854 32bit boundary, plus 1 byte so we can read in odd length
855 packets from the card, which has an IO granularity of 16
857 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
859 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
864 /* We'll prepend the header, so reserve space for it. The worst
865 case is no decapsulation, when 802.3 header is prepended and
866 nothing is removed. 2 is for aligning the IP header. */
867 skb_reserve(skb, ETH_HLEN + 2);
869 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
870 ALIGN(length, 2), rxfid,
871 HERMES_802_2_OFFSET);
873 printk(KERN_ERR "%s: error %d reading frame. "
874 "Frame dropped.\n", dev->name, err);
878 /* Add desc and skb to rx queue */
879 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
881 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
885 rx_data->desc = desc;
887 list_add_tail(&rx_data->list, &priv->rx_list);
888 tasklet_schedule(&priv->rx_tasklet);
893 dev_kfree_skb_irq(skb);
901 static void orinoco_rx(struct net_device *dev,
902 struct hermes_rx_descriptor *desc,
905 struct orinoco_private *priv = netdev_priv(dev);
906 struct net_device_stats *stats = &priv->stats;
911 status = le16_to_cpu(desc->status);
912 length = le16_to_cpu(desc->data_len);
913 fc = le16_to_cpu(desc->frame_ctl);
915 /* Calculate and check MIC */
916 if (status & HERMES_RXSTAT_MIC) {
917 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
918 HERMES_MIC_KEY_ID_SHIFT);
919 u8 mic[MICHAEL_MIC_LEN];
921 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
922 desc->addr3 : desc->addr2;
924 /* Extract Michael MIC from payload */
925 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
927 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
928 length -= MICHAEL_MIC_LEN;
930 orinoco_mic(priv->rx_tfm_mic,
931 priv->tkip_key[key_id].rx_mic,
934 0, /* priority or QoS? */
939 if (memcmp(mic, rxmic,
941 union iwreq_data wrqu;
942 struct iw_michaelmicfailure wxmic;
944 printk(KERN_WARNING "%s: "
945 "Invalid Michael MIC in data frame from %pM, "
947 dev->name, src, key_id);
949 /* TODO: update stats */
951 /* Notify userspace */
952 memset(&wxmic, 0, sizeof(wxmic));
953 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
954 wxmic.flags |= (desc->addr1[0] & 1) ?
955 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
956 wxmic.src_addr.sa_family = ARPHRD_ETHER;
957 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
959 (void) orinoco_hw_get_tkip_iv(priv, key_id,
962 memset(&wrqu, 0, sizeof(wrqu));
963 wrqu.data.length = sizeof(wxmic);
964 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
971 /* Handle decapsulation
972 * In most cases, the firmware tell us about SNAP frames.
973 * For some reason, the SNAP frames sent by LinkSys APs
974 * are not properly recognised by most firmwares.
975 * So, check ourselves */
976 if (length >= ENCAPS_OVERHEAD &&
977 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
978 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
979 is_ethersnap(skb->data))) {
980 /* These indicate a SNAP within 802.2 LLC within
981 802.11 frame which we'll need to de-encapsulate to
982 the original EthernetII frame. */
983 hdr = (struct ethhdr *)skb_push(skb,
984 ETH_HLEN - ENCAPS_OVERHEAD);
986 /* 802.3 frame - prepend 802.3 header as is */
987 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
988 hdr->h_proto = htons(length);
990 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
991 if (fc & IEEE80211_FCTL_FROMDS)
992 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
994 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
996 skb->protocol = eth_type_trans(skb, dev);
997 skb->ip_summed = CHECKSUM_NONE;
998 if (fc & IEEE80211_FCTL_TODS)
999 skb->pkt_type = PACKET_OTHERHOST;
1001 /* Process the wireless stats if needed */
1002 orinoco_stat_gather(dev, skb, desc);
1004 /* Pass the packet to the networking stack */
1006 stats->rx_packets++;
1007 stats->rx_bytes += length;
1014 stats->rx_dropped++;
1017 static void orinoco_rx_isr_tasklet(unsigned long data)
1019 struct net_device *dev = (struct net_device *) data;
1020 struct orinoco_private *priv = netdev_priv(dev);
1021 struct orinoco_rx_data *rx_data, *temp;
1022 struct hermes_rx_descriptor *desc;
1023 struct sk_buff *skb;
1024 unsigned long flags;
1026 /* orinoco_rx requires the driver lock, and we also need to
1027 * protect priv->rx_list, so just hold the lock over the
1030 * If orinoco_lock fails, we've unplugged the card. In this
1031 * case just abort. */
1032 if (orinoco_lock(priv, &flags) != 0)
1035 /* extract desc and skb from queue */
1036 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1037 desc = rx_data->desc;
1039 list_del(&rx_data->list);
1042 orinoco_rx(dev, desc, skb);
1047 orinoco_unlock(priv, &flags);
1050 /********************************************************************/
1051 /* Rx path (info frames) */
1052 /********************************************************************/
1054 static void print_linkstatus(struct net_device *dev, u16 status)
1058 if (suppress_linkstatus)
1062 case HERMES_LINKSTATUS_NOT_CONNECTED:
1063 s = "Not Connected";
1065 case HERMES_LINKSTATUS_CONNECTED:
1068 case HERMES_LINKSTATUS_DISCONNECTED:
1071 case HERMES_LINKSTATUS_AP_CHANGE:
1074 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1075 s = "AP Out of Range";
1077 case HERMES_LINKSTATUS_AP_IN_RANGE:
1080 case HERMES_LINKSTATUS_ASSOC_FAILED:
1081 s = "Association Failed";
1087 printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
1088 dev->name, s, status);
1091 /* Search scan results for requested BSSID, join it if found */
1092 static void orinoco_join_ap(struct work_struct *work)
1094 struct orinoco_private *priv =
1095 container_of(work, struct orinoco_private, join_work);
1096 struct net_device *dev = priv->ndev;
1097 struct hermes *hw = &priv->hw;
1099 unsigned long flags;
1103 } __attribute__ ((packed)) req;
1104 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1105 struct prism2_scan_apinfo *atom = NULL;
1111 /* Allocate buffer for scan results */
1112 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1116 if (orinoco_lock(priv, &flags) != 0)
1119 /* Sanity checks in case user changed something in the meantime */
1120 if (!priv->bssid_fixed)
1123 if (strlen(priv->desired_essid) == 0)
1126 /* Read scan results from the firmware */
1127 err = hermes_read_ltv(hw, USER_BAP,
1128 HERMES_RID_SCANRESULTSTABLE,
1129 MAX_SCAN_LEN, &len, buf);
1131 printk(KERN_ERR "%s: Cannot read scan results\n",
1136 len = HERMES_RECLEN_TO_BYTES(len);
1138 /* Go through the scan results looking for the channel of the AP
1139 * we were requested to join */
1140 for (; offset + atom_len <= len; offset += atom_len) {
1141 atom = (struct prism2_scan_apinfo *) (buf + offset);
1142 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1149 DEBUG(1, "%s: Requested AP not found in scan results\n",
1154 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1155 req.channel = atom->channel; /* both are little-endian */
1156 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1159 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1162 orinoco_unlock(priv, &flags);
1168 /* Send new BSSID to userspace */
1169 static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
1171 struct net_device *dev = priv->ndev;
1172 struct hermes *hw = &priv->hw;
1173 union iwreq_data wrqu;
1176 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
1177 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1181 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1183 /* Send event to user space */
1184 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1187 static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1189 struct net_device *dev = priv->ndev;
1190 struct hermes *hw = &priv->hw;
1191 union iwreq_data wrqu;
1199 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
1200 sizeof(buf), NULL, &buf);
1204 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1206 int rem = sizeof(buf) - (ie - &buf[0]);
1207 wrqu.data.length = ie[1] + 2;
1208 if (wrqu.data.length > rem)
1209 wrqu.data.length = rem;
1211 if (wrqu.data.length)
1212 /* Send event to user space */
1213 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1217 static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1219 struct net_device *dev = priv->ndev;
1220 struct hermes *hw = &priv->hw;
1221 union iwreq_data wrqu;
1223 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1229 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
1230 sizeof(buf), NULL, &buf);
1234 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1236 int rem = sizeof(buf) - (ie - &buf[0]);
1237 wrqu.data.length = ie[1] + 2;
1238 if (wrqu.data.length > rem)
1239 wrqu.data.length = rem;
1241 if (wrqu.data.length)
1242 /* Send event to user space */
1243 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1247 static void orinoco_send_wevents(struct work_struct *work)
1249 struct orinoco_private *priv =
1250 container_of(work, struct orinoco_private, wevent_work);
1251 unsigned long flags;
1253 if (orinoco_lock(priv, &flags) != 0)
1256 orinoco_send_assocreqie_wevent(priv);
1257 orinoco_send_assocrespie_wevent(priv);
1258 orinoco_send_bssid_wevent(priv);
1260 orinoco_unlock(priv, &flags);
1263 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1265 struct orinoco_private *priv = netdev_priv(dev);
1270 } __attribute__ ((packed)) info;
1274 /* This is an answer to an INQUIRE command that we did earlier,
1275 * or an information "event" generated by the card
1276 * The controller return to us a pseudo frame containing
1277 * the information in question - Jean II */
1278 infofid = hermes_read_regn(hw, INFOFID);
1280 /* Read the info frame header - don't try too hard */
1281 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1284 printk(KERN_ERR "%s: error %d reading info frame. "
1285 "Frame dropped.\n", dev->name, err);
1289 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1290 type = le16_to_cpu(info.type);
1293 case HERMES_INQ_TALLIES: {
1294 struct hermes_tallies_frame tallies;
1295 struct iw_statistics *wstats = &priv->wstats;
1297 if (len > sizeof(tallies)) {
1298 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1300 len = sizeof(tallies);
1303 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1304 infofid, sizeof(info));
1308 /* Increment our various counters */
1309 /* wstats->discard.nwid - no wrong BSSID stuff */
1310 wstats->discard.code +=
1311 le16_to_cpu(tallies.RxWEPUndecryptable);
1312 if (len == sizeof(tallies))
1313 wstats->discard.code +=
1314 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1315 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1316 wstats->discard.misc +=
1317 le16_to_cpu(tallies.TxDiscardsWrongSA);
1318 wstats->discard.fragment +=
1319 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1320 wstats->discard.retries +=
1321 le16_to_cpu(tallies.TxRetryLimitExceeded);
1322 /* wstats->miss.beacon - no match */
1325 case HERMES_INQ_LINKSTATUS: {
1326 struct hermes_linkstatus linkstatus;
1330 if (priv->iw_mode == IW_MODE_MONITOR)
1333 if (len != sizeof(linkstatus)) {
1334 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1339 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1340 infofid, sizeof(info));
1343 newstatus = le16_to_cpu(linkstatus.linkstatus);
1345 /* Symbol firmware uses "out of range" to signal that
1346 * the hostscan frame can be requested. */
1347 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1348 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1349 priv->has_hostscan && priv->scan_inprogress) {
1350 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1354 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1355 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1356 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1359 netif_carrier_on(dev);
1360 else if (!ignore_disconnect)
1361 netif_carrier_off(dev);
1363 if (newstatus != priv->last_linkstatus) {
1364 priv->last_linkstatus = newstatus;
1365 print_linkstatus(dev, newstatus);
1366 /* The info frame contains only one word which is the
1367 * status (see hermes.h). The status is pretty boring
1368 * in itself, that's why we export the new BSSID...
1370 schedule_work(&priv->wevent_work);
1374 case HERMES_INQ_SCAN:
1375 if (!priv->scan_inprogress && priv->bssid_fixed &&
1376 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1377 schedule_work(&priv->join_work);
1381 case HERMES_INQ_HOSTSCAN:
1382 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1383 /* Result of a scanning. Contains information about
1384 * cells in the vicinity - Jean II */
1385 union iwreq_data wrqu;
1388 /* Scan is no longer in progress */
1389 priv->scan_inprogress = 0;
1393 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1398 /* Allocate buffer for results */
1399 buf = kmalloc(len, GFP_ATOMIC);
1401 /* No memory, so can't printk()... */
1404 /* Read scan data */
1405 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1406 infofid, sizeof(info));
1412 #ifdef ORINOCO_DEBUG
1415 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1416 for (i = 1; i < (len * 2); i++)
1417 printk(":%02X", buf[i]);
1420 #endif /* ORINOCO_DEBUG */
1422 if (orinoco_process_scan_results(priv, buf, len) == 0) {
1423 /* Send an empty event to user space.
1424 * We don't send the received data on the event because
1425 * it would require us to do complex transcoding, and
1426 * we want to minimise the work done in the irq handler
1427 * Use a request to extract the data - Jean II */
1428 wrqu.data.length = 0;
1429 wrqu.data.flags = 0;
1430 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1435 case HERMES_INQ_CHANNELINFO:
1437 struct agere_ext_scan_info *bss;
1439 if (!priv->scan_inprogress) {
1440 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
1441 "len=%d\n", dev->name, len);
1445 /* An empty result indicates that the scan is complete */
1447 union iwreq_data wrqu;
1449 /* Scan is no longer in progress */
1450 priv->scan_inprogress = 0;
1452 wrqu.data.length = 0;
1453 wrqu.data.flags = 0;
1454 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1459 else if (len > sizeof(*bss)) {
1461 "%s: Ext scan results too large (%d bytes). "
1462 "Truncating results to %zd bytes.\n",
1463 dev->name, len, sizeof(*bss));
1465 } else if (len < (offsetof(struct agere_ext_scan_info,
1467 /* Drop this result now so we don't have to
1468 * keep checking later */
1470 "%s: Ext scan results too short (%d bytes)\n",
1475 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
1479 /* Read scan data */
1480 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
1481 infofid, sizeof(info));
1487 orinoco_add_ext_scan_result(priv, bss);
1492 case HERMES_INQ_SEC_STAT_AGERE:
1493 /* Security status (Agere specific) */
1494 /* Ignore this frame for now */
1495 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1499 printk(KERN_DEBUG "%s: Unknown information frame received: "
1500 "type 0x%04x, length %d\n", dev->name, type, len);
1501 /* We don't actually do anything about it */
1506 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1508 if (net_ratelimit())
1509 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1512 /********************************************************************/
1513 /* Internal hardware control routines */
1514 /********************************************************************/
1516 int __orinoco_up(struct net_device *dev)
1518 struct orinoco_private *priv = netdev_priv(dev);
1519 struct hermes *hw = &priv->hw;
1522 netif_carrier_off(dev); /* just to make sure */
1524 err = __orinoco_program_rids(dev);
1526 printk(KERN_ERR "%s: Error %d configuring card\n",
1531 /* Fire things up again */
1532 hermes_set_irqmask(hw, ORINOCO_INTEN);
1533 err = hermes_enable_port(hw, 0);
1535 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1540 netif_start_queue(dev);
1544 EXPORT_SYMBOL(__orinoco_up);
1546 int __orinoco_down(struct net_device *dev)
1548 struct orinoco_private *priv = netdev_priv(dev);
1549 struct hermes *hw = &priv->hw;
1552 netif_stop_queue(dev);
1554 if (!priv->hw_unavailable) {
1555 if (!priv->broken_disableport) {
1556 err = hermes_disable_port(hw, 0);
1558 /* Some firmwares (e.g. Intersil 1.3.x) seem
1559 * to have problems disabling the port, oh
1561 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1563 priv->broken_disableport = 1;
1566 hermes_set_irqmask(hw, 0);
1567 hermes_write_regn(hw, EVACK, 0xffff);
1570 /* firmware will have to reassociate */
1571 netif_carrier_off(dev);
1572 priv->last_linkstatus = 0xffff;
1576 EXPORT_SYMBOL(__orinoco_down);
1578 static int orinoco_allocate_fid(struct net_device *dev)
1580 struct orinoco_private *priv = netdev_priv(dev);
1581 struct hermes *hw = &priv->hw;
1584 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1585 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1586 /* Try workaround for old Symbol firmware bug */
1587 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1588 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1590 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1591 "(old Symbol firmware?). Work around %s\n",
1592 dev->name, err ? "failed!" : "ok.");
1598 int orinoco_reinit_firmware(struct net_device *dev)
1600 struct orinoco_private *priv = netdev_priv(dev);
1601 struct hermes *hw = &priv->hw;
1604 err = hermes_init(hw);
1605 if (priv->do_fw_download && !err) {
1606 err = orinoco_download(priv);
1608 priv->do_fw_download = 0;
1611 err = orinoco_allocate_fid(dev);
1615 EXPORT_SYMBOL(orinoco_reinit_firmware);
1617 int __orinoco_program_rids(struct net_device *dev)
1619 struct orinoco_private *priv = netdev_priv(dev);
1620 hermes_t *hw = &priv->hw;
1622 struct hermes_idstring idbuf;
1624 /* Set the MAC address */
1625 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1626 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1628 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1633 /* Set up the link mode */
1634 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1637 printk(KERN_ERR "%s: Error %d setting port type\n",
1641 /* Set the channel/frequency */
1642 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1643 err = hermes_write_wordrec(hw, USER_BAP,
1644 HERMES_RID_CNFOWNCHANNEL,
1647 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1648 dev->name, err, priv->channel);
1653 if (priv->has_ibss) {
1656 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1657 printk(KERN_WARNING "%s: This firmware requires an "
1658 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1659 /* With wvlan_cs, in this case, we would crash.
1660 * hopefully, this driver will behave better...
1664 createibss = priv->createibss;
1667 err = hermes_write_wordrec(hw, USER_BAP,
1668 HERMES_RID_CNFCREATEIBSS,
1671 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1677 /* Set the desired BSSID */
1678 err = __orinoco_hw_set_wap(priv);
1680 printk(KERN_ERR "%s: Error %d setting AP address\n",
1684 /* Set the desired ESSID */
1685 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1686 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1687 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1688 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1689 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1692 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1696 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1697 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1700 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1705 /* Set the station name */
1706 idbuf.len = cpu_to_le16(strlen(priv->nick));
1707 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1708 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1709 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1712 printk(KERN_ERR "%s: Error %d setting nickname\n",
1717 /* Set AP density */
1718 if (priv->has_sensitivity) {
1719 err = hermes_write_wordrec(hw, USER_BAP,
1720 HERMES_RID_CNFSYSTEMSCALE,
1723 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1724 "Disabling sensitivity control\n",
1727 priv->has_sensitivity = 0;
1731 /* Set RTS threshold */
1732 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1735 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1740 /* Set fragmentation threshold or MWO robustness */
1742 err = hermes_write_wordrec(hw, USER_BAP,
1743 HERMES_RID_CNFMWOROBUST_AGERE,
1746 err = hermes_write_wordrec(hw, USER_BAP,
1747 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1750 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1756 err = __orinoco_hw_set_bitrate(priv);
1758 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1763 /* Set power management */
1765 err = hermes_write_wordrec(hw, USER_BAP,
1766 HERMES_RID_CNFPMENABLED,
1769 printk(KERN_ERR "%s: Error %d setting up PM\n",
1774 err = hermes_write_wordrec(hw, USER_BAP,
1775 HERMES_RID_CNFMULTICASTRECEIVE,
1778 printk(KERN_ERR "%s: Error %d setting up PM\n",
1782 err = hermes_write_wordrec(hw, USER_BAP,
1783 HERMES_RID_CNFMAXSLEEPDURATION,
1786 printk(KERN_ERR "%s: Error %d setting up PM\n",
1790 err = hermes_write_wordrec(hw, USER_BAP,
1791 HERMES_RID_CNFPMHOLDOVERDURATION,
1794 printk(KERN_ERR "%s: Error %d setting up PM\n",
1800 /* Set preamble - only for Symbol so far... */
1801 if (priv->has_preamble) {
1802 err = hermes_write_wordrec(hw, USER_BAP,
1803 HERMES_RID_CNFPREAMBLE_SYMBOL,
1806 printk(KERN_ERR "%s: Error %d setting preamble\n",
1812 /* Set up encryption */
1813 if (priv->has_wep || priv->has_wpa) {
1814 err = __orinoco_hw_setup_enc(priv);
1816 printk(KERN_ERR "%s: Error %d activating encryption\n",
1822 if (priv->iw_mode == IW_MODE_MONITOR) {
1823 /* Enable monitor mode */
1824 dev->type = ARPHRD_IEEE80211;
1825 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1826 HERMES_TEST_MONITOR, 0, NULL);
1828 /* Disable monitor mode */
1829 dev->type = ARPHRD_ETHER;
1830 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1831 HERMES_TEST_STOP, 0, NULL);
1836 /* Set promiscuity / multicast*/
1837 priv->promiscuous = 0;
1840 /* FIXME: what about netif_tx_lock */
1841 __orinoco_set_multicast_list(dev);
1846 /* FIXME: return int? */
1848 __orinoco_set_multicast_list(struct net_device *dev)
1850 struct orinoco_private *priv = netdev_priv(dev);
1852 int promisc, mc_count;
1854 /* The Hermes doesn't seem to have an allmulti mode, so we go
1855 * into promiscuous mode and let the upper levels deal. */
1856 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1857 (dev->mc_count > MAX_MULTICAST(priv))) {
1862 mc_count = dev->mc_count;
1865 err = __orinoco_hw_set_multicast_list(priv, dev->mc_list, mc_count,
1869 /* This must be called from user context, without locks held - use
1870 * schedule_work() */
1871 void orinoco_reset(struct work_struct *work)
1873 struct orinoco_private *priv =
1874 container_of(work, struct orinoco_private, reset_work);
1875 struct net_device *dev = priv->ndev;
1876 struct hermes *hw = &priv->hw;
1878 unsigned long flags;
1880 if (orinoco_lock(priv, &flags) != 0)
1881 /* When the hardware becomes available again, whatever
1882 * detects that is responsible for re-initializing
1883 * it. So no need for anything further */
1886 netif_stop_queue(dev);
1888 /* Shut off interrupts. Depending on what state the hardware
1889 * is in, this might not work, but we'll try anyway */
1890 hermes_set_irqmask(hw, 0);
1891 hermes_write_regn(hw, EVACK, 0xffff);
1893 priv->hw_unavailable++;
1894 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1895 netif_carrier_off(dev);
1897 orinoco_unlock(priv, &flags);
1899 /* Scanning support: Cleanup of driver struct */
1900 orinoco_clear_scan_results(priv, 0);
1901 priv->scan_inprogress = 0;
1903 if (priv->hard_reset) {
1904 err = (*priv->hard_reset)(priv);
1906 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1907 "performing hard reset\n", dev->name, err);
1912 err = orinoco_reinit_firmware(dev);
1914 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1919 /* This has to be called from user context */
1920 spin_lock_irq(&priv->lock);
1922 priv->hw_unavailable--;
1924 /* priv->open or priv->hw_unavailable might have changed while
1925 * we dropped the lock */
1926 if (priv->open && (!priv->hw_unavailable)) {
1927 err = __orinoco_up(dev);
1929 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1932 dev->trans_start = jiffies;
1935 spin_unlock_irq(&priv->lock);
1939 hermes_set_irqmask(hw, 0);
1940 netif_device_detach(dev);
1941 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1944 /********************************************************************/
1945 /* Interrupt handler */
1946 /********************************************************************/
1948 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1950 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1953 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1955 /* This seems to happen a fair bit under load, but ignoring it
1956 seems to work fine...*/
1957 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1961 irqreturn_t orinoco_interrupt(int irq, void *dev_id)
1963 struct net_device *dev = dev_id;
1964 struct orinoco_private *priv = netdev_priv(dev);
1965 hermes_t *hw = &priv->hw;
1966 int count = MAX_IRQLOOPS_PER_IRQ;
1968 /* These are used to detect a runaway interrupt situation.
1970 * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1971 * we panic and shut down the hardware
1973 /* jiffies value the last time we were called */
1974 static int last_irq_jiffy; /* = 0 */
1975 static int loops_this_jiffy; /* = 0 */
1976 unsigned long flags;
1978 if (orinoco_lock(priv, &flags) != 0) {
1979 /* If hw is unavailable - we don't know if the irq was
1984 evstat = hermes_read_regn(hw, EVSTAT);
1985 events = evstat & hw->inten;
1987 orinoco_unlock(priv, &flags);
1991 if (jiffies != last_irq_jiffy)
1992 loops_this_jiffy = 0;
1993 last_irq_jiffy = jiffies;
1995 while (events && count--) {
1996 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
1997 printk(KERN_WARNING "%s: IRQ handler is looping too "
1998 "much! Resetting.\n", dev->name);
1999 /* Disable interrupts for now */
2000 hermes_set_irqmask(hw, 0);
2001 schedule_work(&priv->reset_work);
2005 /* Check the card hasn't been removed */
2006 if (!hermes_present(hw)) {
2007 DEBUG(0, "orinoco_interrupt(): card removed\n");
2011 if (events & HERMES_EV_TICK)
2012 __orinoco_ev_tick(dev, hw);
2013 if (events & HERMES_EV_WTERR)
2014 __orinoco_ev_wterr(dev, hw);
2015 if (events & HERMES_EV_INFDROP)
2016 __orinoco_ev_infdrop(dev, hw);
2017 if (events & HERMES_EV_INFO)
2018 __orinoco_ev_info(dev, hw);
2019 if (events & HERMES_EV_RX)
2020 __orinoco_ev_rx(dev, hw);
2021 if (events & HERMES_EV_TXEXC)
2022 __orinoco_ev_txexc(dev, hw);
2023 if (events & HERMES_EV_TX)
2024 __orinoco_ev_tx(dev, hw);
2025 if (events & HERMES_EV_ALLOC)
2026 __orinoco_ev_alloc(dev, hw);
2028 hermes_write_regn(hw, EVACK, evstat);
2030 evstat = hermes_read_regn(hw, EVSTAT);
2031 events = evstat & hw->inten;
2034 orinoco_unlock(priv, &flags);
2037 EXPORT_SYMBOL(orinoco_interrupt);
2039 /********************************************************************/
2040 /* Power management */
2041 /********************************************************************/
2042 #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
2043 static int orinoco_pm_notifier(struct notifier_block *notifier,
2044 unsigned long pm_event,
2047 struct orinoco_private *priv = container_of(notifier,
2048 struct orinoco_private,
2051 /* All we need to do is cache the firmware before suspend, and
2052 * release it when we come out.
2054 * Only need to do this if we're downloading firmware. */
2055 if (!priv->do_fw_download)
2059 case PM_HIBERNATION_PREPARE:
2060 case PM_SUSPEND_PREPARE:
2061 orinoco_cache_fw(priv, 0);
2064 case PM_POST_RESTORE:
2065 /* Restore from hibernation failed. We need to clean
2066 * up in exactly the same way, so fall through. */
2067 case PM_POST_HIBERNATION:
2068 case PM_POST_SUSPEND:
2069 orinoco_uncache_fw(priv);
2072 case PM_RESTORE_PREPARE:
2079 #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
2080 #define orinoco_pm_notifier NULL
2083 /********************************************************************/
2084 /* Initialization */
2085 /********************************************************************/
2088 u16 id, variant, major, minor;
2089 } __attribute__ ((packed));
2091 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2093 if (nic_id->id < 0x8000)
2094 return FIRMWARE_TYPE_AGERE;
2095 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2096 return FIRMWARE_TYPE_SYMBOL;
2098 return FIRMWARE_TYPE_INTERSIL;
2101 /* Set priv->firmware type, determine firmware properties */
2102 static int determine_firmware(struct net_device *dev)
2104 struct orinoco_private *priv = netdev_priv(dev);
2105 hermes_t *hw = &priv->hw;
2107 struct comp_id nic_id, sta_id;
2108 unsigned int firmver;
2109 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
2111 /* Get the hardware version */
2112 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2114 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2119 le16_to_cpus(&nic_id.id);
2120 le16_to_cpus(&nic_id.variant);
2121 le16_to_cpus(&nic_id.major);
2122 le16_to_cpus(&nic_id.minor);
2123 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2124 dev->name, nic_id.id, nic_id.variant,
2125 nic_id.major, nic_id.minor);
2127 priv->firmware_type = determine_firmware_type(&nic_id);
2129 /* Get the firmware version */
2130 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2132 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2137 le16_to_cpus(&sta_id.id);
2138 le16_to_cpus(&sta_id.variant);
2139 le16_to_cpus(&sta_id.major);
2140 le16_to_cpus(&sta_id.minor);
2141 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2142 dev->name, sta_id.id, sta_id.variant,
2143 sta_id.major, sta_id.minor);
2145 switch (sta_id.id) {
2147 printk(KERN_ERR "%s: Primary firmware is active\n",
2151 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2154 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2155 case 0x21: /* Symbol Spectrum24 Trilogy */
2158 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2163 /* Default capabilities */
2164 priv->has_sensitivity = 1;
2166 priv->has_preamble = 0;
2167 priv->has_port3 = 1;
2170 priv->has_big_wep = 0;
2171 priv->has_alt_txcntl = 0;
2172 priv->has_ext_scan = 0;
2174 priv->do_fw_download = 0;
2176 /* Determine capabilities from the firmware version */
2177 switch (priv->firmware_type) {
2178 case FIRMWARE_TYPE_AGERE:
2179 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2180 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2181 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2182 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2184 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2186 priv->has_ibss = (firmver >= 0x60006);
2187 priv->has_wep = (firmver >= 0x40020);
2188 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2189 Gold cards from the others? */
2190 priv->has_mwo = (firmver >= 0x60000);
2191 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2192 priv->ibss_port = 1;
2193 priv->has_hostscan = (firmver >= 0x8000a);
2194 priv->do_fw_download = 1;
2195 priv->broken_monitor = (firmver >= 0x80000);
2196 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
2197 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
2198 priv->has_wpa = (firmver >= 0x9002a);
2199 /* Tested with Agere firmware :
2200 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2201 * Tested CableTron firmware : 4.32 => Anton */
2203 case FIRMWARE_TYPE_SYMBOL:
2204 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2205 /* Intel MAC : 00:02:B3:* */
2206 /* 3Com MAC : 00:50:DA:* */
2207 memset(tmp, 0, sizeof(tmp));
2208 /* Get the Symbol firmware version */
2209 err = hermes_read_ltv(hw, USER_BAP,
2210 HERMES_RID_SECONDARYVERSION_SYMBOL,
2211 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2214 "%s: Error %d reading Symbol firmware info. "
2215 "Wildly guessing capabilities...\n",
2220 /* The firmware revision is a string, the format is
2221 * something like : "V2.20-01".
2222 * Quick and dirty parsing... - Jean II
2224 firmver = ((tmp[1] - '0') << 16)
2225 | ((tmp[3] - '0') << 12)
2226 | ((tmp[4] - '0') << 8)
2227 | ((tmp[6] - '0') << 4)
2230 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2233 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2236 priv->has_ibss = (firmver >= 0x20000);
2237 priv->has_wep = (firmver >= 0x15012);
2238 priv->has_big_wep = (firmver >= 0x20000);
2239 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2240 (firmver >= 0x29000 && firmver < 0x30000) ||
2242 priv->has_preamble = (firmver >= 0x20000);
2243 priv->ibss_port = 4;
2245 /* Symbol firmware is found on various cards, but
2246 * there has been no attempt to check firmware
2247 * download on non-spectrum_cs based cards.
2249 * Given that the Agere firmware download works
2250 * differently, we should avoid doing a firmware
2251 * download with the Symbol algorithm on non-spectrum
2254 * For now we can identify a spectrum_cs based card
2255 * because it has a firmware reset function.
2257 priv->do_fw_download = (priv->stop_fw != NULL);
2259 priv->broken_disableport = (firmver == 0x25013) ||
2260 (firmver >= 0x30000 && firmver <= 0x31000);
2261 priv->has_hostscan = (firmver >= 0x31001) ||
2262 (firmver >= 0x29057 && firmver < 0x30000);
2263 /* Tested with Intel firmware : 0x20015 => Jean II */
2264 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2266 case FIRMWARE_TYPE_INTERSIL:
2267 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2268 * Samsung, Compaq 100/200 and Proxim are slightly
2269 * different and less well tested */
2270 /* D-Link MAC : 00:40:05:* */
2271 /* Addtron MAC : 00:90:D1:* */
2272 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2273 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2276 firmver = ((unsigned long)sta_id.major << 16) |
2277 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2279 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2280 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2281 priv->has_pm = (firmver >= 0x000700);
2282 priv->has_hostscan = (firmver >= 0x010301);
2284 if (firmver >= 0x000800)
2285 priv->ibss_port = 0;
2287 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2288 "than v0.8.x - several features not supported\n",
2290 priv->ibss_port = 1;
2294 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2300 static int orinoco_init(struct net_device *dev)
2302 struct orinoco_private *priv = netdev_priv(dev);
2303 hermes_t *hw = &priv->hw;
2305 struct hermes_idstring nickbuf;
2309 /* No need to lock, the hw_unavailable flag is already set in
2310 * alloc_orinocodev() */
2311 priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
2313 /* Initialize the firmware */
2314 err = hermes_init(hw);
2316 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2321 err = determine_firmware(dev);
2323 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2328 if (priv->do_fw_download) {
2329 #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
2330 orinoco_cache_fw(priv, 0);
2333 err = orinoco_download(priv);
2335 priv->do_fw_download = 0;
2337 /* Check firmware version again */
2338 err = determine_firmware(dev);
2340 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2346 if (priv->has_port3)
2347 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n",
2350 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2352 if (priv->has_wep) {
2353 printk(KERN_DEBUG "%s: WEP supported, %s-bit key\n", dev->name,
2354 priv->has_big_wep ? "104" : "40");
2356 if (priv->has_wpa) {
2357 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
2358 if (orinoco_mic_init(priv)) {
2359 printk(KERN_ERR "%s: Failed to setup MIC crypto "
2360 "algorithm. Disabling WPA support\n", dev->name);
2365 /* Now we have the firmware capabilities, allocate appropiate
2366 * sized scan buffers */
2367 if (orinoco_bss_data_allocate(priv))
2369 orinoco_bss_data_init(priv);
2371 /* Get the MAC address */
2372 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2373 ETH_ALEN, NULL, dev->dev_addr);
2375 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2380 printk(KERN_DEBUG "%s: MAC address %pM\n",
2381 dev->name, dev->dev_addr);
2383 /* Get the station name */
2384 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2385 sizeof(nickbuf), &reclen, &nickbuf);
2387 printk(KERN_ERR "%s: failed to read station name\n",
2392 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2394 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2395 memcpy(priv->nick, &nickbuf.val, len);
2396 priv->nick[len] = '\0';
2398 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2400 err = orinoco_allocate_fid(dev);
2402 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2407 /* Get allowed channels */
2408 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2409 &priv->channel_mask);
2411 printk(KERN_ERR "%s: failed to read channel list!\n",
2416 /* Get initial AP density */
2417 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2419 if (err || priv->ap_density < 1 || priv->ap_density > 3)
2420 priv->has_sensitivity = 0;
2422 /* Get initial RTS threshold */
2423 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2426 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2431 /* Get initial fragmentation settings */
2433 err = hermes_read_wordrec(hw, USER_BAP,
2434 HERMES_RID_CNFMWOROBUST_AGERE,
2437 err = hermes_read_wordrec(hw, USER_BAP,
2438 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2439 &priv->frag_thresh);
2441 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2446 /* Power management setup */
2450 err = hermes_read_wordrec(hw, USER_BAP,
2451 HERMES_RID_CNFMAXSLEEPDURATION,
2454 printk(KERN_ERR "%s: failed to read power management period!\n",
2458 err = hermes_read_wordrec(hw, USER_BAP,
2459 HERMES_RID_CNFPMHOLDOVERDURATION,
2462 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2468 /* Preamble setup */
2469 if (priv->has_preamble) {
2470 err = hermes_read_wordrec(hw, USER_BAP,
2471 HERMES_RID_CNFPREAMBLE_SYMBOL,
2477 /* Set up the default configuration */
2478 priv->iw_mode = IW_MODE_INFRA;
2479 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2480 priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
2481 set_port_type(priv);
2482 priv->channel = 0; /* use firmware default */
2484 priv->promiscuous = 0;
2485 priv->encode_alg = IW_ENCODE_ALG_NONE;
2487 priv->wpa_enabled = 0;
2488 priv->tkip_cm_active = 0;
2490 priv->wpa_ie_len = 0;
2491 priv->wpa_ie = NULL;
2493 /* Make the hardware available, as long as it hasn't been
2494 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2495 spin_lock_irq(&priv->lock);
2496 priv->hw_unavailable--;
2497 spin_unlock_irq(&priv->lock);
2499 printk(KERN_DEBUG "%s: ready\n", dev->name);
2505 static const struct net_device_ops orinoco_netdev_ops = {
2506 .ndo_init = orinoco_init,
2507 .ndo_open = orinoco_open,
2508 .ndo_stop = orinoco_stop,
2509 .ndo_start_xmit = orinoco_xmit,
2510 .ndo_set_multicast_list = orinoco_set_multicast_list,
2511 .ndo_change_mtu = orinoco_change_mtu,
2512 .ndo_tx_timeout = orinoco_tx_timeout,
2513 .ndo_get_stats = orinoco_get_stats,
2517 *alloc_orinocodev(int sizeof_card,
2518 struct device *device,
2519 int (*hard_reset)(struct orinoco_private *),
2520 int (*stop_fw)(struct orinoco_private *, int))
2522 struct net_device *dev;
2523 struct orinoco_private *priv;
2525 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2528 priv = netdev_priv(dev);
2531 priv->card = (void *)((unsigned long)priv
2532 + sizeof(struct orinoco_private));
2537 /* Setup / override net_device fields */
2538 dev->netdev_ops = &orinoco_netdev_ops;
2539 dev->watchdog_timeo = HZ; /* 1 second timeout */
2540 dev->ethtool_ops = &orinoco_ethtool_ops;
2541 dev->wireless_handlers = &orinoco_handler_def;
2543 priv->wireless_data.spy_data = &priv->spy_data;
2544 dev->wireless_data = &priv->wireless_data;
2546 /* we use the default eth_mac_addr for setting the MAC addr */
2548 /* Reserve space in skb for the SNAP header */
2549 dev->hard_header_len += ENCAPS_OVERHEAD;
2551 /* Set up default callbacks */
2552 priv->hard_reset = hard_reset;
2553 priv->stop_fw = stop_fw;
2555 spin_lock_init(&priv->lock);
2557 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2558 * before anything else touches the
2560 INIT_WORK(&priv->reset_work, orinoco_reset);
2561 INIT_WORK(&priv->join_work, orinoco_join_ap);
2562 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
2564 INIT_LIST_HEAD(&priv->rx_list);
2565 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
2566 (unsigned long) dev);
2568 netif_carrier_off(dev);
2569 priv->last_linkstatus = 0xffff;
2571 priv->cached_pri_fw = NULL;
2572 priv->cached_fw = NULL;
2574 /* Register PM notifiers */
2575 priv->pm_notifier.notifier_call = orinoco_pm_notifier;
2576 register_pm_notifier(&priv->pm_notifier);
2580 EXPORT_SYMBOL(alloc_orinocodev);
2582 void free_orinocodev(struct net_device *dev)
2584 struct orinoco_private *priv = netdev_priv(dev);
2585 struct orinoco_rx_data *rx_data, *temp;
2587 /* If the tasklet is scheduled when we call tasklet_kill it
2588 * will run one final time. However the tasklet will only
2589 * drain priv->rx_list if the hw is still available. */
2590 tasklet_kill(&priv->rx_tasklet);
2592 /* Explicitly drain priv->rx_list */
2593 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
2594 list_del(&rx_data->list);
2596 dev_kfree_skb(rx_data->skb);
2597 kfree(rx_data->desc);
2601 unregister_pm_notifier(&priv->pm_notifier);
2602 orinoco_uncache_fw(priv);
2604 priv->wpa_ie_len = 0;
2605 kfree(priv->wpa_ie);
2606 orinoco_mic_free(priv);
2607 orinoco_bss_data_free(priv);
2610 EXPORT_SYMBOL(free_orinocodev);
2612 static void orinoco_get_drvinfo(struct net_device *dev,
2613 struct ethtool_drvinfo *info)
2615 struct orinoco_private *priv = netdev_priv(dev);
2617 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
2618 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
2619 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
2620 if (dev->dev.parent)
2621 strncpy(info->bus_info, dev_name(dev->dev.parent),
2622 sizeof(info->bus_info) - 1);
2624 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
2625 "PCMCIA %p", priv->hw.iobase);
2628 static const struct ethtool_ops orinoco_ethtool_ops = {
2629 .get_drvinfo = orinoco_get_drvinfo,
2630 .get_link = ethtool_op_get_link,
2633 /********************************************************************/
2634 /* Module initialization */
2635 /********************************************************************/
2637 /* Can't be declared "const" or the whole __initdata section will
2639 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
2640 " (David Gibson <hermes@gibson.dropbear.id.au>, "
2641 "Pavel Roskin <proski@gnu.org>, et al)";
2643 static int __init init_orinoco(void)
2645 printk(KERN_DEBUG "%s\n", version);
2649 static void __exit exit_orinoco(void)
2653 module_init(init_orinoco);
2654 module_exit(exit_orinoco);