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
);
735 stats
->rx_length_errors
++;
739 skb
= dev_alloc_skb(hdrlen
+ datalen
);
741 printk(KERN_WARNING
"%s: Cannot allocate skb for monitor frame\n",
747 /* Copy the 802.11 header to the skb */
748 memcpy(skb_put(skb
, hdrlen
), &(desc
->frame_ctl
), hdrlen
);
749 skb_reset_mac_header(skb
);
751 /* If any, copy the data from the card to the skb */
753 err
= hermes_bap_pread(hw
, IRQ_BAP
, skb_put(skb
, datalen
),
754 ALIGN(datalen
, 2), rxfid
,
755 HERMES_802_2_OFFSET
);
757 printk(KERN_ERR
"%s: error %d reading monitor frame\n",
764 skb
->ip_summed
= CHECKSUM_NONE
;
765 skb
->pkt_type
= PACKET_OTHERHOST
;
766 skb
->protocol
= cpu_to_be16(ETH_P_802_2
);
769 stats
->rx_bytes
+= skb
->len
;
775 dev_kfree_skb_irq(skb
);
781 static void __orinoco_ev_rx(struct net_device
*dev
, hermes_t
*hw
)
783 struct orinoco_private
*priv
= netdev_priv(dev
);
784 struct net_device_stats
*stats
= &priv
->stats
;
785 struct iw_statistics
*wstats
= &priv
->wstats
;
786 struct sk_buff
*skb
= NULL
;
789 struct hermes_rx_descriptor
*desc
;
790 struct orinoco_rx_data
*rx_data
;
793 desc
= kmalloc(sizeof(*desc
), GFP_ATOMIC
);
796 "%s: Can't allocate space for RX descriptor\n",
801 rxfid
= hermes_read_regn(hw
, RXFID
);
803 err
= hermes_bap_pread(hw
, IRQ_BAP
, desc
, sizeof(*desc
),
806 printk(KERN_ERR
"%s: error %d reading Rx descriptor. "
807 "Frame dropped.\n", dev
->name
, err
);
811 status
= le16_to_cpu(desc
->status
);
813 if (status
& HERMES_RXSTAT_BADCRC
) {
814 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
816 stats
->rx_crc_errors
++;
820 /* Handle frames in monitor mode */
821 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
822 orinoco_rx_monitor(dev
, rxfid
, desc
);
826 if (status
& HERMES_RXSTAT_UNDECRYPTABLE
) {
827 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
829 wstats
->discard
.code
++;
833 length
= le16_to_cpu(desc
->data_len
);
836 if (length
< 3) { /* No for even an 802.2 LLC header */
837 /* At least on Symbol firmware with PCF we get quite a
838 lot of these legitimately - Poll frames with no
842 if (length
> IEEE80211_MAX_DATA_LEN
) {
843 printk(KERN_WARNING
"%s: Oversized frame received (%d bytes)\n",
845 stats
->rx_length_errors
++;
849 /* Payload size does not include Michael MIC. Increase payload
850 * size to read it together with the data. */
851 if (status
& HERMES_RXSTAT_MIC
)
852 length
+= MICHAEL_MIC_LEN
;
854 /* We need space for the packet data itself, plus an ethernet
855 header, plus 2 bytes so we can align the IP header on a
856 32bit boundary, plus 1 byte so we can read in odd length
857 packets from the card, which has an IO granularity of 16
859 skb
= dev_alloc_skb(length
+ETH_HLEN
+2+1);
861 printk(KERN_WARNING
"%s: Can't allocate skb for Rx\n",
866 /* We'll prepend the header, so reserve space for it. The worst
867 case is no decapsulation, when 802.3 header is prepended and
868 nothing is removed. 2 is for aligning the IP header. */
869 skb_reserve(skb
, ETH_HLEN
+ 2);
871 err
= hermes_bap_pread(hw
, IRQ_BAP
, skb_put(skb
, length
),
872 ALIGN(length
, 2), rxfid
,
873 HERMES_802_2_OFFSET
);
875 printk(KERN_ERR
"%s: error %d reading frame. "
876 "Frame dropped.\n", dev
->name
, err
);
880 /* Add desc and skb to rx queue */
881 rx_data
= kzalloc(sizeof(*rx_data
), GFP_ATOMIC
);
883 printk(KERN_WARNING
"%s: Can't allocate RX packet\n",
887 rx_data
->desc
= desc
;
889 list_add_tail(&rx_data
->list
, &priv
->rx_list
);
890 tasklet_schedule(&priv
->rx_tasklet
);
895 dev_kfree_skb_irq(skb
);
903 static void orinoco_rx(struct net_device
*dev
,
904 struct hermes_rx_descriptor
*desc
,
907 struct orinoco_private
*priv
= netdev_priv(dev
);
908 struct net_device_stats
*stats
= &priv
->stats
;
913 status
= le16_to_cpu(desc
->status
);
914 length
= le16_to_cpu(desc
->data_len
);
915 fc
= le16_to_cpu(desc
->frame_ctl
);
917 /* Calculate and check MIC */
918 if (status
& HERMES_RXSTAT_MIC
) {
919 int key_id
= ((status
& HERMES_RXSTAT_MIC_KEY_ID
) >>
920 HERMES_MIC_KEY_ID_SHIFT
);
921 u8 mic
[MICHAEL_MIC_LEN
];
923 u8
*src
= (fc
& IEEE80211_FCTL_FROMDS
) ?
924 desc
->addr3
: desc
->addr2
;
926 /* Extract Michael MIC from payload */
927 rxmic
= skb
->data
+ skb
->len
- MICHAEL_MIC_LEN
;
929 skb_trim(skb
, skb
->len
- MICHAEL_MIC_LEN
);
930 length
-= MICHAEL_MIC_LEN
;
932 orinoco_mic(priv
->rx_tfm_mic
,
933 priv
->tkip_key
[key_id
].rx_mic
,
936 0, /* priority or QoS? */
941 if (memcmp(mic
, rxmic
,
943 union iwreq_data wrqu
;
944 struct iw_michaelmicfailure wxmic
;
946 printk(KERN_WARNING
"%s: "
947 "Invalid Michael MIC in data frame from %pM, "
949 dev
->name
, src
, key_id
);
951 /* TODO: update stats */
953 /* Notify userspace */
954 memset(&wxmic
, 0, sizeof(wxmic
));
955 wxmic
.flags
= key_id
& IW_MICFAILURE_KEY_ID
;
956 wxmic
.flags
|= (desc
->addr1
[0] & 1) ?
957 IW_MICFAILURE_GROUP
: IW_MICFAILURE_PAIRWISE
;
958 wxmic
.src_addr
.sa_family
= ARPHRD_ETHER
;
959 memcpy(wxmic
.src_addr
.sa_data
, src
, ETH_ALEN
);
961 (void) orinoco_hw_get_tkip_iv(priv
, key_id
,
964 memset(&wrqu
, 0, sizeof(wrqu
));
965 wrqu
.data
.length
= sizeof(wxmic
);
966 wireless_send_event(dev
, IWEVMICHAELMICFAILURE
, &wrqu
,
973 /* Handle decapsulation
974 * In most cases, the firmware tell us about SNAP frames.
975 * For some reason, the SNAP frames sent by LinkSys APs
976 * are not properly recognised by most firmwares.
977 * So, check ourselves */
978 if (length
>= ENCAPS_OVERHEAD
&&
979 (((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_1042
) ||
980 ((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_TUNNEL
) ||
981 is_ethersnap(skb
->data
))) {
982 /* These indicate a SNAP within 802.2 LLC within
983 802.11 frame which we'll need to de-encapsulate to
984 the original EthernetII frame. */
985 hdr
= (struct ethhdr
*)skb_push(skb
,
986 ETH_HLEN
- ENCAPS_OVERHEAD
);
988 /* 802.3 frame - prepend 802.3 header as is */
989 hdr
= (struct ethhdr
*)skb_push(skb
, ETH_HLEN
);
990 hdr
->h_proto
= htons(length
);
992 memcpy(hdr
->h_dest
, desc
->addr1
, ETH_ALEN
);
993 if (fc
& IEEE80211_FCTL_FROMDS
)
994 memcpy(hdr
->h_source
, desc
->addr3
, ETH_ALEN
);
996 memcpy(hdr
->h_source
, desc
->addr2
, ETH_ALEN
);
998 skb
->protocol
= eth_type_trans(skb
, dev
);
999 skb
->ip_summed
= CHECKSUM_NONE
;
1000 if (fc
& IEEE80211_FCTL_TODS
)
1001 skb
->pkt_type
= PACKET_OTHERHOST
;
1003 /* Process the wireless stats if needed */
1004 orinoco_stat_gather(dev
, skb
, desc
);
1006 /* Pass the packet to the networking stack */
1008 stats
->rx_packets
++;
1009 stats
->rx_bytes
+= length
;
1016 stats
->rx_dropped
++;
1019 static void orinoco_rx_isr_tasklet(unsigned long data
)
1021 struct net_device
*dev
= (struct net_device
*) data
;
1022 struct orinoco_private
*priv
= netdev_priv(dev
);
1023 struct orinoco_rx_data
*rx_data
, *temp
;
1024 struct hermes_rx_descriptor
*desc
;
1025 struct sk_buff
*skb
;
1026 unsigned long flags
;
1028 /* orinoco_rx requires the driver lock, and we also need to
1029 * protect priv->rx_list, so just hold the lock over the
1032 * If orinoco_lock fails, we've unplugged the card. In this
1033 * case just abort. */
1034 if (orinoco_lock(priv
, &flags
) != 0)
1037 /* extract desc and skb from queue */
1038 list_for_each_entry_safe(rx_data
, temp
, &priv
->rx_list
, list
) {
1039 desc
= rx_data
->desc
;
1041 list_del(&rx_data
->list
);
1044 orinoco_rx(dev
, desc
, skb
);
1049 orinoco_unlock(priv
, &flags
);
1052 /********************************************************************/
1053 /* Rx path (info frames) */
1054 /********************************************************************/
1056 static void print_linkstatus(struct net_device
*dev
, u16 status
)
1060 if (suppress_linkstatus
)
1064 case HERMES_LINKSTATUS_NOT_CONNECTED
:
1065 s
= "Not Connected";
1067 case HERMES_LINKSTATUS_CONNECTED
:
1070 case HERMES_LINKSTATUS_DISCONNECTED
:
1073 case HERMES_LINKSTATUS_AP_CHANGE
:
1076 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE
:
1077 s
= "AP Out of Range";
1079 case HERMES_LINKSTATUS_AP_IN_RANGE
:
1082 case HERMES_LINKSTATUS_ASSOC_FAILED
:
1083 s
= "Association Failed";
1089 printk(KERN_DEBUG
"%s: New link status: %s (%04x)\n",
1090 dev
->name
, s
, status
);
1093 /* Search scan results for requested BSSID, join it if found */
1094 static void orinoco_join_ap(struct work_struct
*work
)
1096 struct orinoco_private
*priv
=
1097 container_of(work
, struct orinoco_private
, join_work
);
1098 struct net_device
*dev
= priv
->ndev
;
1099 struct hermes
*hw
= &priv
->hw
;
1101 unsigned long flags
;
1105 } __attribute__ ((packed
)) req
;
1106 const int atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
1107 struct prism2_scan_apinfo
*atom
= NULL
;
1113 /* Allocate buffer for scan results */
1114 buf
= kmalloc(MAX_SCAN_LEN
, GFP_KERNEL
);
1118 if (orinoco_lock(priv
, &flags
) != 0)
1121 /* Sanity checks in case user changed something in the meantime */
1122 if (!priv
->bssid_fixed
)
1125 if (strlen(priv
->desired_essid
) == 0)
1128 /* Read scan results from the firmware */
1129 err
= hermes_read_ltv(hw
, USER_BAP
,
1130 HERMES_RID_SCANRESULTSTABLE
,
1131 MAX_SCAN_LEN
, &len
, buf
);
1133 printk(KERN_ERR
"%s: Cannot read scan results\n",
1138 len
= HERMES_RECLEN_TO_BYTES(len
);
1140 /* Go through the scan results looking for the channel of the AP
1141 * we were requested to join */
1142 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
1143 atom
= (struct prism2_scan_apinfo
*) (buf
+ offset
);
1144 if (memcmp(&atom
->bssid
, priv
->desired_bssid
, ETH_ALEN
) == 0) {
1151 DEBUG(1, "%s: Requested AP not found in scan results\n",
1156 memcpy(req
.bssid
, priv
->desired_bssid
, ETH_ALEN
);
1157 req
.channel
= atom
->channel
; /* both are little-endian */
1158 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
, HERMES_RID_CNFJOINREQUEST
,
1161 printk(KERN_ERR
"%s: Error issuing join request\n", dev
->name
);
1164 orinoco_unlock(priv
, &flags
);
1170 /* Send new BSSID to userspace */
1171 static void orinoco_send_bssid_wevent(struct orinoco_private
*priv
)
1173 struct net_device
*dev
= priv
->ndev
;
1174 struct hermes
*hw
= &priv
->hw
;
1175 union iwreq_data wrqu
;
1178 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTBSSID
,
1179 ETH_ALEN
, NULL
, wrqu
.ap_addr
.sa_data
);
1183 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1185 /* Send event to user space */
1186 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
1189 static void orinoco_send_assocreqie_wevent(struct orinoco_private
*priv
)
1191 struct net_device
*dev
= priv
->ndev
;
1192 struct hermes
*hw
= &priv
->hw
;
1193 union iwreq_data wrqu
;
1201 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENT_ASSOC_REQ_INFO
,
1202 sizeof(buf
), NULL
, &buf
);
1206 ie
= orinoco_get_wpa_ie(buf
, sizeof(buf
));
1208 int rem
= sizeof(buf
) - (ie
- &buf
[0]);
1209 wrqu
.data
.length
= ie
[1] + 2;
1210 if (wrqu
.data
.length
> rem
)
1211 wrqu
.data
.length
= rem
;
1213 if (wrqu
.data
.length
)
1214 /* Send event to user space */
1215 wireless_send_event(dev
, IWEVASSOCREQIE
, &wrqu
, ie
);
1219 static void orinoco_send_assocrespie_wevent(struct orinoco_private
*priv
)
1221 struct net_device
*dev
= priv
->ndev
;
1222 struct hermes
*hw
= &priv
->hw
;
1223 union iwreq_data wrqu
;
1225 u8 buf
[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1231 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENT_ASSOC_RESP_INFO
,
1232 sizeof(buf
), NULL
, &buf
);
1236 ie
= orinoco_get_wpa_ie(buf
, sizeof(buf
));
1238 int rem
= sizeof(buf
) - (ie
- &buf
[0]);
1239 wrqu
.data
.length
= ie
[1] + 2;
1240 if (wrqu
.data
.length
> rem
)
1241 wrqu
.data
.length
= rem
;
1243 if (wrqu
.data
.length
)
1244 /* Send event to user space */
1245 wireless_send_event(dev
, IWEVASSOCRESPIE
, &wrqu
, ie
);
1249 static void orinoco_send_wevents(struct work_struct
*work
)
1251 struct orinoco_private
*priv
=
1252 container_of(work
, struct orinoco_private
, wevent_work
);
1253 unsigned long flags
;
1255 if (orinoco_lock(priv
, &flags
) != 0)
1258 orinoco_send_assocreqie_wevent(priv
);
1259 orinoco_send_assocrespie_wevent(priv
);
1260 orinoco_send_bssid_wevent(priv
);
1262 orinoco_unlock(priv
, &flags
);
1265 static void __orinoco_ev_info(struct net_device
*dev
, hermes_t
*hw
)
1267 struct orinoco_private
*priv
= netdev_priv(dev
);
1272 } __attribute__ ((packed
)) info
;
1276 /* This is an answer to an INQUIRE command that we did earlier,
1277 * or an information "event" generated by the card
1278 * The controller return to us a pseudo frame containing
1279 * the information in question - Jean II */
1280 infofid
= hermes_read_regn(hw
, INFOFID
);
1282 /* Read the info frame header - don't try too hard */
1283 err
= hermes_bap_pread(hw
, IRQ_BAP
, &info
, sizeof(info
),
1286 printk(KERN_ERR
"%s: error %d reading info frame. "
1287 "Frame dropped.\n", dev
->name
, err
);
1291 len
= HERMES_RECLEN_TO_BYTES(le16_to_cpu(info
.len
));
1292 type
= le16_to_cpu(info
.type
);
1295 case HERMES_INQ_TALLIES
: {
1296 struct hermes_tallies_frame tallies
;
1297 struct iw_statistics
*wstats
= &priv
->wstats
;
1299 if (len
> sizeof(tallies
)) {
1300 printk(KERN_WARNING
"%s: Tallies frame too long (%d bytes)\n",
1302 len
= sizeof(tallies
);
1305 err
= hermes_bap_pread(hw
, IRQ_BAP
, &tallies
, len
,
1306 infofid
, sizeof(info
));
1310 /* Increment our various counters */
1311 /* wstats->discard.nwid - no wrong BSSID stuff */
1312 wstats
->discard
.code
+=
1313 le16_to_cpu(tallies
.RxWEPUndecryptable
);
1314 if (len
== sizeof(tallies
))
1315 wstats
->discard
.code
+=
1316 le16_to_cpu(tallies
.RxDiscards_WEPICVError
) +
1317 le16_to_cpu(tallies
.RxDiscards_WEPExcluded
);
1318 wstats
->discard
.misc
+=
1319 le16_to_cpu(tallies
.TxDiscardsWrongSA
);
1320 wstats
->discard
.fragment
+=
1321 le16_to_cpu(tallies
.RxMsgInBadMsgFragments
);
1322 wstats
->discard
.retries
+=
1323 le16_to_cpu(tallies
.TxRetryLimitExceeded
);
1324 /* wstats->miss.beacon - no match */
1327 case HERMES_INQ_LINKSTATUS
: {
1328 struct hermes_linkstatus linkstatus
;
1332 if (priv
->iw_mode
== IW_MODE_MONITOR
)
1335 if (len
!= sizeof(linkstatus
)) {
1336 printk(KERN_WARNING
"%s: Unexpected size for linkstatus frame (%d bytes)\n",
1341 err
= hermes_bap_pread(hw
, IRQ_BAP
, &linkstatus
, len
,
1342 infofid
, sizeof(info
));
1345 newstatus
= le16_to_cpu(linkstatus
.linkstatus
);
1347 /* Symbol firmware uses "out of range" to signal that
1348 * the hostscan frame can be requested. */
1349 if (newstatus
== HERMES_LINKSTATUS_AP_OUT_OF_RANGE
&&
1350 priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
&&
1351 priv
->has_hostscan
&& priv
->scan_inprogress
) {
1352 hermes_inquire(hw
, HERMES_INQ_HOSTSCAN_SYMBOL
);
1356 connected
= (newstatus
== HERMES_LINKSTATUS_CONNECTED
)
1357 || (newstatus
== HERMES_LINKSTATUS_AP_CHANGE
)
1358 || (newstatus
== HERMES_LINKSTATUS_AP_IN_RANGE
);
1361 netif_carrier_on(dev
);
1362 else if (!ignore_disconnect
)
1363 netif_carrier_off(dev
);
1365 if (newstatus
!= priv
->last_linkstatus
) {
1366 priv
->last_linkstatus
= newstatus
;
1367 print_linkstatus(dev
, newstatus
);
1368 /* The info frame contains only one word which is the
1369 * status (see hermes.h). The status is pretty boring
1370 * in itself, that's why we export the new BSSID...
1372 schedule_work(&priv
->wevent_work
);
1376 case HERMES_INQ_SCAN
:
1377 if (!priv
->scan_inprogress
&& priv
->bssid_fixed
&&
1378 priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
) {
1379 schedule_work(&priv
->join_work
);
1383 case HERMES_INQ_HOSTSCAN
:
1384 case HERMES_INQ_HOSTSCAN_SYMBOL
: {
1385 /* Result of a scanning. Contains information about
1386 * cells in the vicinity - Jean II */
1387 union iwreq_data wrqu
;
1390 /* Scan is no longer in progress */
1391 priv
->scan_inprogress
= 0;
1395 printk(KERN_WARNING
"%s: Scan results too large (%d bytes)\n",
1400 /* Allocate buffer for results */
1401 buf
= kmalloc(len
, GFP_ATOMIC
);
1403 /* No memory, so can't printk()... */
1406 /* Read scan data */
1407 err
= hermes_bap_pread(hw
, IRQ_BAP
, (void *) buf
, len
,
1408 infofid
, sizeof(info
));
1414 #ifdef ORINOCO_DEBUG
1417 printk(KERN_DEBUG
"Scan result [%02X", buf
[0]);
1418 for (i
= 1; i
< (len
* 2); i
++)
1419 printk(":%02X", buf
[i
]);
1422 #endif /* ORINOCO_DEBUG */
1424 if (orinoco_process_scan_results(priv
, buf
, len
) == 0) {
1425 /* Send an empty event to user space.
1426 * We don't send the received data on the event because
1427 * it would require us to do complex transcoding, and
1428 * we want to minimise the work done in the irq handler
1429 * Use a request to extract the data - Jean II */
1430 wrqu
.data
.length
= 0;
1431 wrqu
.data
.flags
= 0;
1432 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
1437 case HERMES_INQ_CHANNELINFO
:
1439 struct agere_ext_scan_info
*bss
;
1441 if (!priv
->scan_inprogress
) {
1442 printk(KERN_DEBUG
"%s: Got chaninfo without scan, "
1443 "len=%d\n", dev
->name
, len
);
1447 /* An empty result indicates that the scan is complete */
1449 union iwreq_data wrqu
;
1451 /* Scan is no longer in progress */
1452 priv
->scan_inprogress
= 0;
1454 wrqu
.data
.length
= 0;
1455 wrqu
.data
.flags
= 0;
1456 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
1461 else if (len
> sizeof(*bss
)) {
1463 "%s: Ext scan results too large (%d bytes). "
1464 "Truncating results to %zd bytes.\n",
1465 dev
->name
, len
, sizeof(*bss
));
1467 } else if (len
< (offsetof(struct agere_ext_scan_info
,
1469 /* Drop this result now so we don't have to
1470 * keep checking later */
1472 "%s: Ext scan results too short (%d bytes)\n",
1477 bss
= kmalloc(sizeof(*bss
), GFP_ATOMIC
);
1481 /* Read scan data */
1482 err
= hermes_bap_pread(hw
, IRQ_BAP
, (void *) bss
, len
,
1483 infofid
, sizeof(info
));
1489 orinoco_add_ext_scan_result(priv
, bss
);
1494 case HERMES_INQ_SEC_STAT_AGERE
:
1495 /* Security status (Agere specific) */
1496 /* Ignore this frame for now */
1497 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
)
1501 printk(KERN_DEBUG
"%s: Unknown information frame received: "
1502 "type 0x%04x, length %d\n", dev
->name
, type
, len
);
1503 /* We don't actually do anything about it */
1508 static void __orinoco_ev_infdrop(struct net_device
*dev
, hermes_t
*hw
)
1510 if (net_ratelimit())
1511 printk(KERN_DEBUG
"%s: Information frame lost.\n", dev
->name
);
1514 /********************************************************************/
1515 /* Internal hardware control routines */
1516 /********************************************************************/
1518 int __orinoco_up(struct net_device
*dev
)
1520 struct orinoco_private
*priv
= netdev_priv(dev
);
1521 struct hermes
*hw
= &priv
->hw
;
1524 netif_carrier_off(dev
); /* just to make sure */
1526 err
= __orinoco_program_rids(dev
);
1528 printk(KERN_ERR
"%s: Error %d configuring card\n",
1533 /* Fire things up again */
1534 hermes_set_irqmask(hw
, ORINOCO_INTEN
);
1535 err
= hermes_enable_port(hw
, 0);
1537 printk(KERN_ERR
"%s: Error %d enabling MAC port\n",
1542 netif_start_queue(dev
);
1546 EXPORT_SYMBOL(__orinoco_up
);
1548 int __orinoco_down(struct net_device
*dev
)
1550 struct orinoco_private
*priv
= netdev_priv(dev
);
1551 struct hermes
*hw
= &priv
->hw
;
1554 netif_stop_queue(dev
);
1556 if (!priv
->hw_unavailable
) {
1557 if (!priv
->broken_disableport
) {
1558 err
= hermes_disable_port(hw
, 0);
1560 /* Some firmwares (e.g. Intersil 1.3.x) seem
1561 * to have problems disabling the port, oh
1563 printk(KERN_WARNING
"%s: Error %d disabling MAC port\n",
1565 priv
->broken_disableport
= 1;
1568 hermes_set_irqmask(hw
, 0);
1569 hermes_write_regn(hw
, EVACK
, 0xffff);
1572 /* firmware will have to reassociate */
1573 netif_carrier_off(dev
);
1574 priv
->last_linkstatus
= 0xffff;
1578 EXPORT_SYMBOL(__orinoco_down
);
1580 static int orinoco_allocate_fid(struct net_device
*dev
)
1582 struct orinoco_private
*priv
= netdev_priv(dev
);
1583 struct hermes
*hw
= &priv
->hw
;
1586 err
= hermes_allocate(hw
, priv
->nicbuf_size
, &priv
->txfid
);
1587 if (err
== -EIO
&& priv
->nicbuf_size
> TX_NICBUF_SIZE_BUG
) {
1588 /* Try workaround for old Symbol firmware bug */
1589 priv
->nicbuf_size
= TX_NICBUF_SIZE_BUG
;
1590 err
= hermes_allocate(hw
, priv
->nicbuf_size
, &priv
->txfid
);
1592 printk(KERN_WARNING
"%s: firmware ALLOC bug detected "
1593 "(old Symbol firmware?). Work around %s\n",
1594 dev
->name
, err
? "failed!" : "ok.");
1600 int orinoco_reinit_firmware(struct net_device
*dev
)
1602 struct orinoco_private
*priv
= netdev_priv(dev
);
1603 struct hermes
*hw
= &priv
->hw
;
1606 err
= hermes_init(hw
);
1607 if (priv
->do_fw_download
&& !err
) {
1608 err
= orinoco_download(priv
);
1610 priv
->do_fw_download
= 0;
1613 err
= orinoco_allocate_fid(dev
);
1617 EXPORT_SYMBOL(orinoco_reinit_firmware
);
1619 int __orinoco_program_rids(struct net_device
*dev
)
1621 struct orinoco_private
*priv
= netdev_priv(dev
);
1622 hermes_t
*hw
= &priv
->hw
;
1624 struct hermes_idstring idbuf
;
1626 /* Set the MAC address */
1627 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
1628 HERMES_BYTES_TO_RECLEN(ETH_ALEN
), dev
->dev_addr
);
1630 printk(KERN_ERR
"%s: Error %d setting MAC address\n",
1635 /* Set up the link mode */
1636 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPORTTYPE
,
1639 printk(KERN_ERR
"%s: Error %d setting port type\n",
1643 /* Set the channel/frequency */
1644 if (priv
->channel
!= 0 && priv
->iw_mode
!= IW_MODE_INFRA
) {
1645 err
= hermes_write_wordrec(hw
, USER_BAP
,
1646 HERMES_RID_CNFOWNCHANNEL
,
1649 printk(KERN_ERR
"%s: Error %d setting channel %d\n",
1650 dev
->name
, err
, priv
->channel
);
1655 if (priv
->has_ibss
) {
1658 if ((strlen(priv
->desired_essid
) == 0) && (priv
->createibss
)) {
1659 printk(KERN_WARNING
"%s: This firmware requires an "
1660 "ESSID in IBSS-Ad-Hoc mode.\n", dev
->name
);
1661 /* With wvlan_cs, in this case, we would crash.
1662 * hopefully, this driver will behave better...
1666 createibss
= priv
->createibss
;
1669 err
= hermes_write_wordrec(hw
, USER_BAP
,
1670 HERMES_RID_CNFCREATEIBSS
,
1673 printk(KERN_ERR
"%s: Error %d setting CREATEIBSS\n",
1679 /* Set the desired BSSID */
1680 err
= __orinoco_hw_set_wap(priv
);
1682 printk(KERN_ERR
"%s: Error %d setting AP address\n",
1686 /* Set the desired ESSID */
1687 idbuf
.len
= cpu_to_le16(strlen(priv
->desired_essid
));
1688 memcpy(&idbuf
.val
, priv
->desired_essid
, sizeof(idbuf
.val
));
1689 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1690 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNSSID
,
1691 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
1694 printk(KERN_ERR
"%s: Error %d setting OWNSSID\n",
1698 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFDESIREDSSID
,
1699 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
1702 printk(KERN_ERR
"%s: Error %d setting DESIREDSSID\n",
1707 /* Set the station name */
1708 idbuf
.len
= cpu_to_le16(strlen(priv
->nick
));
1709 memcpy(&idbuf
.val
, priv
->nick
, sizeof(idbuf
.val
));
1710 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
1711 HERMES_BYTES_TO_RECLEN(strlen(priv
->nick
)+2),
1714 printk(KERN_ERR
"%s: Error %d setting nickname\n",
1719 /* Set AP density */
1720 if (priv
->has_sensitivity
) {
1721 err
= hermes_write_wordrec(hw
, USER_BAP
,
1722 HERMES_RID_CNFSYSTEMSCALE
,
1725 printk(KERN_WARNING
"%s: Error %d setting SYSTEMSCALE. "
1726 "Disabling sensitivity control\n",
1729 priv
->has_sensitivity
= 0;
1733 /* Set RTS threshold */
1734 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
1737 printk(KERN_ERR
"%s: Error %d setting RTS threshold\n",
1742 /* Set fragmentation threshold or MWO robustness */
1744 err
= hermes_write_wordrec(hw
, USER_BAP
,
1745 HERMES_RID_CNFMWOROBUST_AGERE
,
1748 err
= hermes_write_wordrec(hw
, USER_BAP
,
1749 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
1752 printk(KERN_ERR
"%s: Error %d setting fragmentation\n",
1758 err
= __orinoco_hw_set_bitrate(priv
);
1760 printk(KERN_ERR
"%s: Error %d setting bitrate\n",
1765 /* Set power management */
1767 err
= hermes_write_wordrec(hw
, USER_BAP
,
1768 HERMES_RID_CNFPMENABLED
,
1771 printk(KERN_ERR
"%s: Error %d setting up PM\n",
1776 err
= hermes_write_wordrec(hw
, USER_BAP
,
1777 HERMES_RID_CNFMULTICASTRECEIVE
,
1780 printk(KERN_ERR
"%s: Error %d setting up PM\n",
1784 err
= hermes_write_wordrec(hw
, USER_BAP
,
1785 HERMES_RID_CNFMAXSLEEPDURATION
,
1788 printk(KERN_ERR
"%s: Error %d setting up PM\n",
1792 err
= hermes_write_wordrec(hw
, USER_BAP
,
1793 HERMES_RID_CNFPMHOLDOVERDURATION
,
1796 printk(KERN_ERR
"%s: Error %d setting up PM\n",
1802 /* Set preamble - only for Symbol so far... */
1803 if (priv
->has_preamble
) {
1804 err
= hermes_write_wordrec(hw
, USER_BAP
,
1805 HERMES_RID_CNFPREAMBLE_SYMBOL
,
1808 printk(KERN_ERR
"%s: Error %d setting preamble\n",
1814 /* Set up encryption */
1815 if (priv
->has_wep
|| priv
->has_wpa
) {
1816 err
= __orinoco_hw_setup_enc(priv
);
1818 printk(KERN_ERR
"%s: Error %d activating encryption\n",
1824 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
1825 /* Enable monitor mode */
1826 dev
->type
= ARPHRD_IEEE80211
;
1827 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
1828 HERMES_TEST_MONITOR
, 0, NULL
);
1830 /* Disable monitor mode */
1831 dev
->type
= ARPHRD_ETHER
;
1832 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
1833 HERMES_TEST_STOP
, 0, NULL
);
1838 /* Set promiscuity / multicast*/
1839 priv
->promiscuous
= 0;
1842 /* FIXME: what about netif_tx_lock */
1843 __orinoco_set_multicast_list(dev
);
1848 /* FIXME: return int? */
1850 __orinoco_set_multicast_list(struct net_device
*dev
)
1852 struct orinoco_private
*priv
= netdev_priv(dev
);
1854 int promisc
, mc_count
;
1856 /* The Hermes doesn't seem to have an allmulti mode, so we go
1857 * into promiscuous mode and let the upper levels deal. */
1858 if ((dev
->flags
& IFF_PROMISC
) || (dev
->flags
& IFF_ALLMULTI
) ||
1859 (dev
->mc_count
> MAX_MULTICAST(priv
))) {
1864 mc_count
= dev
->mc_count
;
1867 err
= __orinoco_hw_set_multicast_list(priv
, dev
->mc_list
, mc_count
,
1871 /* This must be called from user context, without locks held - use
1872 * schedule_work() */
1873 void orinoco_reset(struct work_struct
*work
)
1875 struct orinoco_private
*priv
=
1876 container_of(work
, struct orinoco_private
, reset_work
);
1877 struct net_device
*dev
= priv
->ndev
;
1878 struct hermes
*hw
= &priv
->hw
;
1880 unsigned long flags
;
1882 if (orinoco_lock(priv
, &flags
) != 0)
1883 /* When the hardware becomes available again, whatever
1884 * detects that is responsible for re-initializing
1885 * it. So no need for anything further */
1888 netif_stop_queue(dev
);
1890 /* Shut off interrupts. Depending on what state the hardware
1891 * is in, this might not work, but we'll try anyway */
1892 hermes_set_irqmask(hw
, 0);
1893 hermes_write_regn(hw
, EVACK
, 0xffff);
1895 priv
->hw_unavailable
++;
1896 priv
->last_linkstatus
= 0xffff; /* firmware will have to reassociate */
1897 netif_carrier_off(dev
);
1899 orinoco_unlock(priv
, &flags
);
1901 /* Scanning support: Cleanup of driver struct */
1902 orinoco_clear_scan_results(priv
, 0);
1903 priv
->scan_inprogress
= 0;
1905 if (priv
->hard_reset
) {
1906 err
= (*priv
->hard_reset
)(priv
);
1908 printk(KERN_ERR
"%s: orinoco_reset: Error %d "
1909 "performing hard reset\n", dev
->name
, err
);
1914 err
= orinoco_reinit_firmware(dev
);
1916 printk(KERN_ERR
"%s: orinoco_reset: Error %d re-initializing firmware\n",
1921 /* This has to be called from user context */
1922 spin_lock_irq(&priv
->lock
);
1924 priv
->hw_unavailable
--;
1926 /* priv->open or priv->hw_unavailable might have changed while
1927 * we dropped the lock */
1928 if (priv
->open
&& (!priv
->hw_unavailable
)) {
1929 err
= __orinoco_up(dev
);
1931 printk(KERN_ERR
"%s: orinoco_reset: Error %d reenabling card\n",
1934 dev
->trans_start
= jiffies
;
1937 spin_unlock_irq(&priv
->lock
);
1941 hermes_set_irqmask(hw
, 0);
1942 netif_device_detach(dev
);
1943 printk(KERN_ERR
"%s: Device has been disabled!\n", dev
->name
);
1946 /********************************************************************/
1947 /* Interrupt handler */
1948 /********************************************************************/
1950 static void __orinoco_ev_tick(struct net_device
*dev
, hermes_t
*hw
)
1952 printk(KERN_DEBUG
"%s: TICK\n", dev
->name
);
1955 static void __orinoco_ev_wterr(struct net_device
*dev
, hermes_t
*hw
)
1957 /* This seems to happen a fair bit under load, but ignoring it
1958 seems to work fine...*/
1959 printk(KERN_DEBUG
"%s: MAC controller error (WTERR). Ignoring.\n",
1963 irqreturn_t
orinoco_interrupt(int irq
, void *dev_id
)
1965 struct net_device
*dev
= dev_id
;
1966 struct orinoco_private
*priv
= netdev_priv(dev
);
1967 hermes_t
*hw
= &priv
->hw
;
1968 int count
= MAX_IRQLOOPS_PER_IRQ
;
1970 /* These are used to detect a runaway interrupt situation.
1972 * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1973 * we panic and shut down the hardware
1975 /* jiffies value the last time we were called */
1976 static int last_irq_jiffy
; /* = 0 */
1977 static int loops_this_jiffy
; /* = 0 */
1978 unsigned long flags
;
1980 if (orinoco_lock(priv
, &flags
) != 0) {
1981 /* If hw is unavailable - we don't know if the irq was
1986 evstat
= hermes_read_regn(hw
, EVSTAT
);
1987 events
= evstat
& hw
->inten
;
1989 orinoco_unlock(priv
, &flags
);
1993 if (jiffies
!= last_irq_jiffy
)
1994 loops_this_jiffy
= 0;
1995 last_irq_jiffy
= jiffies
;
1997 while (events
&& count
--) {
1998 if (++loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
) {
1999 printk(KERN_WARNING
"%s: IRQ handler is looping too "
2000 "much! Resetting.\n", dev
->name
);
2001 /* Disable interrupts for now */
2002 hermes_set_irqmask(hw
, 0);
2003 schedule_work(&priv
->reset_work
);
2007 /* Check the card hasn't been removed */
2008 if (!hermes_present(hw
)) {
2009 DEBUG(0, "orinoco_interrupt(): card removed\n");
2013 if (events
& HERMES_EV_TICK
)
2014 __orinoco_ev_tick(dev
, hw
);
2015 if (events
& HERMES_EV_WTERR
)
2016 __orinoco_ev_wterr(dev
, hw
);
2017 if (events
& HERMES_EV_INFDROP
)
2018 __orinoco_ev_infdrop(dev
, hw
);
2019 if (events
& HERMES_EV_INFO
)
2020 __orinoco_ev_info(dev
, hw
);
2021 if (events
& HERMES_EV_RX
)
2022 __orinoco_ev_rx(dev
, hw
);
2023 if (events
& HERMES_EV_TXEXC
)
2024 __orinoco_ev_txexc(dev
, hw
);
2025 if (events
& HERMES_EV_TX
)
2026 __orinoco_ev_tx(dev
, hw
);
2027 if (events
& HERMES_EV_ALLOC
)
2028 __orinoco_ev_alloc(dev
, hw
);
2030 hermes_write_regn(hw
, EVACK
, evstat
);
2032 evstat
= hermes_read_regn(hw
, EVSTAT
);
2033 events
= evstat
& hw
->inten
;
2036 orinoco_unlock(priv
, &flags
);
2039 EXPORT_SYMBOL(orinoco_interrupt
);
2041 /********************************************************************/
2042 /* Power management */
2043 /********************************************************************/
2044 #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
2045 static int orinoco_pm_notifier(struct notifier_block
*notifier
,
2046 unsigned long pm_event
,
2049 struct orinoco_private
*priv
= container_of(notifier
,
2050 struct orinoco_private
,
2053 /* All we need to do is cache the firmware before suspend, and
2054 * release it when we come out.
2056 * Only need to do this if we're downloading firmware. */
2057 if (!priv
->do_fw_download
)
2061 case PM_HIBERNATION_PREPARE
:
2062 case PM_SUSPEND_PREPARE
:
2063 orinoco_cache_fw(priv
, 0);
2066 case PM_POST_RESTORE
:
2067 /* Restore from hibernation failed. We need to clean
2068 * up in exactly the same way, so fall through. */
2069 case PM_POST_HIBERNATION
:
2070 case PM_POST_SUSPEND
:
2071 orinoco_uncache_fw(priv
);
2074 case PM_RESTORE_PREPARE
:
2082 static void orinoco_register_pm_notifier(struct orinoco_private
*priv
)
2084 priv
->pm_notifier
.notifier_call
= orinoco_pm_notifier
;
2085 register_pm_notifier(&priv
->pm_notifier
);
2088 static void orinoco_unregister_pm_notifier(struct orinoco_private
*priv
)
2090 unregister_pm_notifier(&priv
->pm_notifier
);
2092 #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
2093 #define orinoco_register_pm_notifier(priv) do { } while(0)
2094 #define orinoco_unregister_pm_notifier(priv) do { } while(0)
2097 /********************************************************************/
2098 /* Initialization */
2099 /********************************************************************/
2102 u16 id
, variant
, major
, minor
;
2103 } __attribute__ ((packed
));
2105 static inline fwtype_t
determine_firmware_type(struct comp_id
*nic_id
)
2107 if (nic_id
->id
< 0x8000)
2108 return FIRMWARE_TYPE_AGERE
;
2109 else if (nic_id
->id
== 0x8000 && nic_id
->major
== 0)
2110 return FIRMWARE_TYPE_SYMBOL
;
2112 return FIRMWARE_TYPE_INTERSIL
;
2115 /* Set priv->firmware type, determine firmware properties */
2116 static int determine_firmware(struct net_device
*dev
)
2118 struct orinoco_private
*priv
= netdev_priv(dev
);
2119 hermes_t
*hw
= &priv
->hw
;
2121 struct comp_id nic_id
, sta_id
;
2122 unsigned int firmver
;
2123 char tmp
[SYMBOL_MAX_VER_LEN
+1] __attribute__((aligned(2)));
2125 /* Get the hardware version */
2126 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_NICID
, &nic_id
);
2128 printk(KERN_ERR
"%s: Cannot read hardware identity: error %d\n",
2133 le16_to_cpus(&nic_id
.id
);
2134 le16_to_cpus(&nic_id
.variant
);
2135 le16_to_cpus(&nic_id
.major
);
2136 le16_to_cpus(&nic_id
.minor
);
2137 printk(KERN_DEBUG
"%s: Hardware identity %04x:%04x:%04x:%04x\n",
2138 dev
->name
, nic_id
.id
, nic_id
.variant
,
2139 nic_id
.major
, nic_id
.minor
);
2141 priv
->firmware_type
= determine_firmware_type(&nic_id
);
2143 /* Get the firmware version */
2144 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_STAID
, &sta_id
);
2146 printk(KERN_ERR
"%s: Cannot read station identity: error %d\n",
2151 le16_to_cpus(&sta_id
.id
);
2152 le16_to_cpus(&sta_id
.variant
);
2153 le16_to_cpus(&sta_id
.major
);
2154 le16_to_cpus(&sta_id
.minor
);
2155 printk(KERN_DEBUG
"%s: Station identity %04x:%04x:%04x:%04x\n",
2156 dev
->name
, sta_id
.id
, sta_id
.variant
,
2157 sta_id
.major
, sta_id
.minor
);
2159 switch (sta_id
.id
) {
2161 printk(KERN_ERR
"%s: Primary firmware is active\n",
2165 printk(KERN_ERR
"%s: Tertiary firmware is active\n",
2168 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2169 case 0x21: /* Symbol Spectrum24 Trilogy */
2172 printk(KERN_NOTICE
"%s: Unknown station ID, please report\n",
2177 /* Default capabilities */
2178 priv
->has_sensitivity
= 1;
2180 priv
->has_preamble
= 0;
2181 priv
->has_port3
= 1;
2184 priv
->has_big_wep
= 0;
2185 priv
->has_alt_txcntl
= 0;
2186 priv
->has_ext_scan
= 0;
2188 priv
->do_fw_download
= 0;
2190 /* Determine capabilities from the firmware version */
2191 switch (priv
->firmware_type
) {
2192 case FIRMWARE_TYPE_AGERE
:
2193 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2194 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2195 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
2196 "Lucent/Agere %d.%02d", sta_id
.major
, sta_id
.minor
);
2198 firmver
= ((unsigned long)sta_id
.major
<< 16) | sta_id
.minor
;
2200 priv
->has_ibss
= (firmver
>= 0x60006);
2201 priv
->has_wep
= (firmver
>= 0x40020);
2202 priv
->has_big_wep
= 1; /* FIXME: this is wrong - how do we tell
2203 Gold cards from the others? */
2204 priv
->has_mwo
= (firmver
>= 0x60000);
2205 priv
->has_pm
= (firmver
>= 0x40020); /* Don't work in 7.52 ? */
2206 priv
->ibss_port
= 1;
2207 priv
->has_hostscan
= (firmver
>= 0x8000a);
2208 priv
->do_fw_download
= 1;
2209 priv
->broken_monitor
= (firmver
>= 0x80000);
2210 priv
->has_alt_txcntl
= (firmver
>= 0x90000); /* All 9.x ? */
2211 priv
->has_ext_scan
= (firmver
>= 0x90000); /* All 9.x ? */
2212 priv
->has_wpa
= (firmver
>= 0x9002a);
2213 /* Tested with Agere firmware :
2214 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2215 * Tested CableTron firmware : 4.32 => Anton */
2217 case FIRMWARE_TYPE_SYMBOL
:
2218 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2219 /* Intel MAC : 00:02:B3:* */
2220 /* 3Com MAC : 00:50:DA:* */
2221 memset(tmp
, 0, sizeof(tmp
));
2222 /* Get the Symbol firmware version */
2223 err
= hermes_read_ltv(hw
, USER_BAP
,
2224 HERMES_RID_SECONDARYVERSION_SYMBOL
,
2225 SYMBOL_MAX_VER_LEN
, NULL
, &tmp
);
2228 "%s: Error %d reading Symbol firmware info. "
2229 "Wildly guessing capabilities...\n",
2234 /* The firmware revision is a string, the format is
2235 * something like : "V2.20-01".
2236 * Quick and dirty parsing... - Jean II
2238 firmver
= ((tmp
[1] - '0') << 16)
2239 | ((tmp
[3] - '0') << 12)
2240 | ((tmp
[4] - '0') << 8)
2241 | ((tmp
[6] - '0') << 4)
2244 tmp
[SYMBOL_MAX_VER_LEN
] = '\0';
2247 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
2250 priv
->has_ibss
= (firmver
>= 0x20000);
2251 priv
->has_wep
= (firmver
>= 0x15012);
2252 priv
->has_big_wep
= (firmver
>= 0x20000);
2253 priv
->has_pm
= (firmver
>= 0x20000 && firmver
< 0x22000) ||
2254 (firmver
>= 0x29000 && firmver
< 0x30000) ||
2256 priv
->has_preamble
= (firmver
>= 0x20000);
2257 priv
->ibss_port
= 4;
2259 /* Symbol firmware is found on various cards, but
2260 * there has been no attempt to check firmware
2261 * download on non-spectrum_cs based cards.
2263 * Given that the Agere firmware download works
2264 * differently, we should avoid doing a firmware
2265 * download with the Symbol algorithm on non-spectrum
2268 * For now we can identify a spectrum_cs based card
2269 * because it has a firmware reset function.
2271 priv
->do_fw_download
= (priv
->stop_fw
!= NULL
);
2273 priv
->broken_disableport
= (firmver
== 0x25013) ||
2274 (firmver
>= 0x30000 && firmver
<= 0x31000);
2275 priv
->has_hostscan
= (firmver
>= 0x31001) ||
2276 (firmver
>= 0x29057 && firmver
< 0x30000);
2277 /* Tested with Intel firmware : 0x20015 => Jean II */
2278 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2280 case FIRMWARE_TYPE_INTERSIL
:
2281 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2282 * Samsung, Compaq 100/200 and Proxim are slightly
2283 * different and less well tested */
2284 /* D-Link MAC : 00:40:05:* */
2285 /* Addtron MAC : 00:90:D1:* */
2286 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
2287 "Intersil %d.%d.%d", sta_id
.major
, sta_id
.minor
,
2290 firmver
= ((unsigned long)sta_id
.major
<< 16) |
2291 ((unsigned long)sta_id
.minor
<< 8) | sta_id
.variant
;
2293 priv
->has_ibss
= (firmver
>= 0x000700); /* FIXME */
2294 priv
->has_big_wep
= priv
->has_wep
= (firmver
>= 0x000800);
2295 priv
->has_pm
= (firmver
>= 0x000700);
2296 priv
->has_hostscan
= (firmver
>= 0x010301);
2298 if (firmver
>= 0x000800)
2299 priv
->ibss_port
= 0;
2301 printk(KERN_NOTICE
"%s: Intersil firmware earlier "
2302 "than v0.8.x - several features not supported\n",
2304 priv
->ibss_port
= 1;
2308 printk(KERN_DEBUG
"%s: Firmware determined as %s\n", dev
->name
,
2314 static int orinoco_init(struct net_device
*dev
)
2316 struct orinoco_private
*priv
= netdev_priv(dev
);
2317 hermes_t
*hw
= &priv
->hw
;
2319 struct hermes_idstring nickbuf
;
2323 /* No need to lock, the hw_unavailable flag is already set in
2324 * alloc_orinocodev() */
2325 priv
->nicbuf_size
= IEEE80211_MAX_FRAME_LEN
+ ETH_HLEN
;
2327 /* Initialize the firmware */
2328 err
= hermes_init(hw
);
2330 printk(KERN_ERR
"%s: failed to initialize firmware (err = %d)\n",
2335 err
= determine_firmware(dev
);
2337 printk(KERN_ERR
"%s: Incompatible firmware, aborting\n",
2342 if (priv
->do_fw_download
) {
2343 #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
2344 orinoco_cache_fw(priv
, 0);
2347 err
= orinoco_download(priv
);
2349 priv
->do_fw_download
= 0;
2351 /* Check firmware version again */
2352 err
= determine_firmware(dev
);
2354 printk(KERN_ERR
"%s: Incompatible firmware, aborting\n",
2360 if (priv
->has_port3
)
2361 printk(KERN_DEBUG
"%s: Ad-hoc demo mode supported\n",
2364 printk(KERN_DEBUG
"%s: IEEE standard IBSS ad-hoc mode supported\n",
2366 if (priv
->has_wep
) {
2367 printk(KERN_DEBUG
"%s: WEP supported, %s-bit key\n", dev
->name
,
2368 priv
->has_big_wep
? "104" : "40");
2370 if (priv
->has_wpa
) {
2371 printk(KERN_DEBUG
"%s: WPA-PSK supported\n", dev
->name
);
2372 if (orinoco_mic_init(priv
)) {
2373 printk(KERN_ERR
"%s: Failed to setup MIC crypto "
2374 "algorithm. Disabling WPA support\n", dev
->name
);
2379 /* Now we have the firmware capabilities, allocate appropiate
2380 * sized scan buffers */
2381 if (orinoco_bss_data_allocate(priv
))
2383 orinoco_bss_data_init(priv
);
2385 /* Get the MAC address */
2386 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
2387 ETH_ALEN
, NULL
, dev
->dev_addr
);
2389 printk(KERN_WARNING
"%s: failed to read MAC address!\n",
2394 printk(KERN_DEBUG
"%s: MAC address %pM\n",
2395 dev
->name
, dev
->dev_addr
);
2397 /* Get the station name */
2398 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
2399 sizeof(nickbuf
), &reclen
, &nickbuf
);
2401 printk(KERN_ERR
"%s: failed to read station name\n",
2406 len
= min(IW_ESSID_MAX_SIZE
, (int)le16_to_cpu(nickbuf
.len
));
2408 len
= min(IW_ESSID_MAX_SIZE
, 2 * reclen
);
2409 memcpy(priv
->nick
, &nickbuf
.val
, len
);
2410 priv
->nick
[len
] = '\0';
2412 printk(KERN_DEBUG
"%s: Station name \"%s\"\n", dev
->name
, priv
->nick
);
2414 err
= orinoco_allocate_fid(dev
);
2416 printk(KERN_ERR
"%s: failed to allocate NIC buffer!\n",
2421 /* Get allowed channels */
2422 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CHANNELLIST
,
2423 &priv
->channel_mask
);
2425 printk(KERN_ERR
"%s: failed to read channel list!\n",
2430 /* Get initial AP density */
2431 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFSYSTEMSCALE
,
2433 if (err
|| priv
->ap_density
< 1 || priv
->ap_density
> 3)
2434 priv
->has_sensitivity
= 0;
2436 /* Get initial RTS threshold */
2437 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
2440 printk(KERN_ERR
"%s: failed to read RTS threshold!\n",
2445 /* Get initial fragmentation settings */
2447 err
= hermes_read_wordrec(hw
, USER_BAP
,
2448 HERMES_RID_CNFMWOROBUST_AGERE
,
2451 err
= hermes_read_wordrec(hw
, USER_BAP
,
2452 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
2453 &priv
->frag_thresh
);
2455 printk(KERN_ERR
"%s: failed to read fragmentation settings!\n",
2460 /* Power management setup */
2464 err
= hermes_read_wordrec(hw
, USER_BAP
,
2465 HERMES_RID_CNFMAXSLEEPDURATION
,
2468 printk(KERN_ERR
"%s: failed to read power management period!\n",
2472 err
= hermes_read_wordrec(hw
, USER_BAP
,
2473 HERMES_RID_CNFPMHOLDOVERDURATION
,
2476 printk(KERN_ERR
"%s: failed to read power management timeout!\n",
2482 /* Preamble setup */
2483 if (priv
->has_preamble
) {
2484 err
= hermes_read_wordrec(hw
, USER_BAP
,
2485 HERMES_RID_CNFPREAMBLE_SYMBOL
,
2491 /* Set up the default configuration */
2492 priv
->iw_mode
= IW_MODE_INFRA
;
2493 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2494 priv
->prefer_port3
= priv
->has_port3
&& (!priv
->has_ibss
);
2495 set_port_type(priv
);
2496 priv
->channel
= 0; /* use firmware default */
2498 priv
->promiscuous
= 0;
2499 priv
->encode_alg
= IW_ENCODE_ALG_NONE
;
2501 priv
->wpa_enabled
= 0;
2502 priv
->tkip_cm_active
= 0;
2504 priv
->wpa_ie_len
= 0;
2505 priv
->wpa_ie
= NULL
;
2507 /* Make the hardware available, as long as it hasn't been
2508 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2509 spin_lock_irq(&priv
->lock
);
2510 priv
->hw_unavailable
--;
2511 spin_unlock_irq(&priv
->lock
);
2513 printk(KERN_DEBUG
"%s: ready\n", dev
->name
);
2519 static const struct net_device_ops orinoco_netdev_ops
= {
2520 .ndo_init
= orinoco_init
,
2521 .ndo_open
= orinoco_open
,
2522 .ndo_stop
= orinoco_stop
,
2523 .ndo_start_xmit
= orinoco_xmit
,
2524 .ndo_set_multicast_list
= orinoco_set_multicast_list
,
2525 .ndo_change_mtu
= orinoco_change_mtu
,
2526 .ndo_set_mac_address
= eth_mac_addr
,
2527 .ndo_validate_addr
= eth_validate_addr
,
2528 .ndo_tx_timeout
= orinoco_tx_timeout
,
2529 .ndo_get_stats
= orinoco_get_stats
,
2533 *alloc_orinocodev(int sizeof_card
,
2534 struct device
*device
,
2535 int (*hard_reset
)(struct orinoco_private
*),
2536 int (*stop_fw
)(struct orinoco_private
*, int))
2538 struct net_device
*dev
;
2539 struct orinoco_private
*priv
;
2541 dev
= alloc_etherdev(sizeof(struct orinoco_private
) + sizeof_card
);
2544 priv
= netdev_priv(dev
);
2547 priv
->card
= (void *)((unsigned long)priv
2548 + sizeof(struct orinoco_private
));
2553 /* Setup / override net_device fields */
2554 dev
->netdev_ops
= &orinoco_netdev_ops
;
2555 dev
->watchdog_timeo
= HZ
; /* 1 second timeout */
2556 dev
->ethtool_ops
= &orinoco_ethtool_ops
;
2557 dev
->wireless_handlers
= &orinoco_handler_def
;
2559 priv
->wireless_data
.spy_data
= &priv
->spy_data
;
2560 dev
->wireless_data
= &priv
->wireless_data
;
2563 /* Reserve space in skb for the SNAP header */
2564 dev
->hard_header_len
+= ENCAPS_OVERHEAD
;
2566 /* Set up default callbacks */
2567 priv
->hard_reset
= hard_reset
;
2568 priv
->stop_fw
= stop_fw
;
2570 spin_lock_init(&priv
->lock
);
2572 priv
->hw_unavailable
= 1; /* orinoco_init() must clear this
2573 * before anything else touches the
2575 INIT_WORK(&priv
->reset_work
, orinoco_reset
);
2576 INIT_WORK(&priv
->join_work
, orinoco_join_ap
);
2577 INIT_WORK(&priv
->wevent_work
, orinoco_send_wevents
);
2579 INIT_LIST_HEAD(&priv
->rx_list
);
2580 tasklet_init(&priv
->rx_tasklet
, orinoco_rx_isr_tasklet
,
2581 (unsigned long) dev
);
2583 netif_carrier_off(dev
);
2584 priv
->last_linkstatus
= 0xffff;
2586 #if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
2587 priv
->cached_pri_fw
= NULL
;
2588 priv
->cached_fw
= NULL
;
2591 /* Register PM notifiers */
2592 orinoco_register_pm_notifier(priv
);
2596 EXPORT_SYMBOL(alloc_orinocodev
);
2598 void free_orinocodev(struct net_device
*dev
)
2600 struct orinoco_private
*priv
= netdev_priv(dev
);
2601 struct orinoco_rx_data
*rx_data
, *temp
;
2603 /* If the tasklet is scheduled when we call tasklet_kill it
2604 * will run one final time. However the tasklet will only
2605 * drain priv->rx_list if the hw is still available. */
2606 tasklet_kill(&priv
->rx_tasklet
);
2608 /* Explicitly drain priv->rx_list */
2609 list_for_each_entry_safe(rx_data
, temp
, &priv
->rx_list
, list
) {
2610 list_del(&rx_data
->list
);
2612 dev_kfree_skb(rx_data
->skb
);
2613 kfree(rx_data
->desc
);
2617 orinoco_unregister_pm_notifier(priv
);
2618 orinoco_uncache_fw(priv
);
2620 priv
->wpa_ie_len
= 0;
2621 kfree(priv
->wpa_ie
);
2622 orinoco_mic_free(priv
);
2623 orinoco_bss_data_free(priv
);
2626 EXPORT_SYMBOL(free_orinocodev
);
2628 static void orinoco_get_drvinfo(struct net_device
*dev
,
2629 struct ethtool_drvinfo
*info
)
2631 struct orinoco_private
*priv
= netdev_priv(dev
);
2633 strncpy(info
->driver
, DRIVER_NAME
, sizeof(info
->driver
) - 1);
2634 strncpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
) - 1);
2635 strncpy(info
->fw_version
, priv
->fw_name
, sizeof(info
->fw_version
) - 1);
2636 if (dev
->dev
.parent
)
2637 strncpy(info
->bus_info
, dev_name(dev
->dev
.parent
),
2638 sizeof(info
->bus_info
) - 1);
2640 snprintf(info
->bus_info
, sizeof(info
->bus_info
) - 1,
2641 "PCMCIA %p", priv
->hw
.iobase
);
2644 static const struct ethtool_ops orinoco_ethtool_ops
= {
2645 .get_drvinfo
= orinoco_get_drvinfo
,
2646 .get_link
= ethtool_op_get_link
,
2649 /********************************************************************/
2650 /* Module initialization */
2651 /********************************************************************/
2653 /* Can't be declared "const" or the whole __initdata section will
2655 static char version
[] __initdata
= DRIVER_NAME
" " DRIVER_VERSION
2656 " (David Gibson <hermes@gibson.dropbear.id.au>, "
2657 "Pavel Roskin <proski@gnu.org>, et al)";
2659 static int __init
init_orinoco(void)
2661 printk(KERN_DEBUG
"%s\n", version
);
2665 static void __exit
exit_orinoco(void)
2669 module_init(init_orinoco
);
2670 module_exit(exit_orinoco
);