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/device.h>
84 #include <linux/netdevice.h>
85 #include <linux/etherdevice.h>
86 #include <linux/ethtool.h>
87 #include <linux/suspend.h>
88 #include <linux/if_arp.h>
89 #include <linux/wireless.h>
90 #include <linux/ieee80211.h>
91 #include <net/iw_handler.h>
92 #include <net/cfg80211.h>
94 #include "hermes_rid.h"
95 #include "hermes_dld.h"
106 /********************************************************************/
107 /* Module information */
108 /********************************************************************/
110 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
111 "David Gibson <hermes@gibson.dropbear.id.au>");
112 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
113 "and similar wireless cards");
114 MODULE_LICENSE("Dual MPL/GPL");
116 /* Level of debugging. Used in the macros in orinoco.h */
118 int orinoco_debug
= ORINOCO_DEBUG
;
119 EXPORT_SYMBOL(orinoco_debug
);
120 module_param(orinoco_debug
, int, 0644);
121 MODULE_PARM_DESC(orinoco_debug
, "Debug level");
124 static int suppress_linkstatus
; /* = 0 */
125 module_param(suppress_linkstatus
, bool, 0644);
126 MODULE_PARM_DESC(suppress_linkstatus
, "Don't log link status changes");
128 static int ignore_disconnect
; /* = 0 */
129 module_param(ignore_disconnect
, int, 0644);
130 MODULE_PARM_DESC(ignore_disconnect
,
131 "Don't report lost link to the network layer");
133 int force_monitor
; /* = 0 */
134 module_param(force_monitor
, int, 0644);
135 MODULE_PARM_DESC(force_monitor
, "Allow monitor mode for all firmware versions");
137 /********************************************************************/
138 /* Internal constants */
139 /********************************************************************/
141 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
142 static const u8 encaps_hdr
[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
143 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
145 #define ORINOCO_MIN_MTU 256
146 #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
148 #define MAX_IRQLOOPS_PER_IRQ 10
149 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
150 * how many events the
152 * legitimately generate */
154 #define DUMMY_FID 0xFFFF
156 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
157 HERMES_MAX_MULTICAST : 0)*/
158 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
160 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
161 | HERMES_EV_TX | HERMES_EV_TXEXC \
162 | HERMES_EV_WTERR | HERMES_EV_INFO \
165 static const struct ethtool_ops orinoco_ethtool_ops
;
167 /********************************************************************/
169 /********************************************************************/
171 /* Beginning of the Tx descriptor, used in TxExc handling */
172 struct hermes_txexc_data
{
173 struct hermes_tx_descriptor desc
;
177 } __attribute__ ((packed
));
179 /* Rx frame header except compatibility 802.3 header */
180 struct hermes_rx_descriptor
{
201 } __attribute__ ((packed
));
203 struct orinoco_rx_data
{
204 struct hermes_rx_descriptor
*desc
;
206 struct list_head list
;
209 struct orinoco_scan_data
{
213 struct list_head list
;
216 /********************************************************************/
217 /* Function prototypes */
218 /********************************************************************/
220 static int __orinoco_set_multicast_list(struct net_device
*dev
);
221 static int __orinoco_up(struct orinoco_private
*priv
);
222 static int __orinoco_down(struct orinoco_private
*priv
);
223 static int __orinoco_commit(struct orinoco_private
*priv
);
225 /********************************************************************/
226 /* Internal helper functions */
227 /********************************************************************/
229 void set_port_type(struct orinoco_private
*priv
)
231 switch (priv
->iw_mode
) {
232 case NL80211_IFTYPE_STATION
:
234 priv
->createibss
= 0;
236 case NL80211_IFTYPE_ADHOC
:
237 if (priv
->prefer_port3
) {
239 priv
->createibss
= 0;
241 priv
->port_type
= priv
->ibss_port
;
242 priv
->createibss
= 1;
245 case NL80211_IFTYPE_MONITOR
:
247 priv
->createibss
= 0;
250 printk(KERN_ERR
"%s: Invalid priv->iw_mode in set_port_type()\n",
255 /********************************************************************/
257 /********************************************************************/
259 int orinoco_open(struct net_device
*dev
)
261 struct orinoco_private
*priv
= ndev_priv(dev
);
265 if (orinoco_lock(priv
, &flags
) != 0)
268 err
= __orinoco_up(priv
);
273 orinoco_unlock(priv
, &flags
);
277 EXPORT_SYMBOL(orinoco_open
);
279 int orinoco_stop(struct net_device
*dev
)
281 struct orinoco_private
*priv
= ndev_priv(dev
);
284 /* We mustn't use orinoco_lock() here, because we need to be
285 able to close the interface even if hw_unavailable is set
286 (e.g. as we're released after a PC Card removal) */
287 orinoco_lock_irq(priv
);
291 err
= __orinoco_down(priv
);
293 orinoco_unlock_irq(priv
);
297 EXPORT_SYMBOL(orinoco_stop
);
299 struct net_device_stats
*orinoco_get_stats(struct net_device
*dev
)
301 struct orinoco_private
*priv
= ndev_priv(dev
);
305 EXPORT_SYMBOL(orinoco_get_stats
);
307 void orinoco_set_multicast_list(struct net_device
*dev
)
309 struct orinoco_private
*priv
= ndev_priv(dev
);
312 if (orinoco_lock(priv
, &flags
) != 0) {
313 printk(KERN_DEBUG
"%s: orinoco_set_multicast_list() "
314 "called when hw_unavailable\n", dev
->name
);
318 __orinoco_set_multicast_list(dev
);
319 orinoco_unlock(priv
, &flags
);
321 EXPORT_SYMBOL(orinoco_set_multicast_list
);
323 int orinoco_change_mtu(struct net_device
*dev
, int new_mtu
)
325 struct orinoco_private
*priv
= ndev_priv(dev
);
327 if ((new_mtu
< ORINOCO_MIN_MTU
) || (new_mtu
> ORINOCO_MAX_MTU
))
330 /* MTU + encapsulation + header length */
331 if ((new_mtu
+ ENCAPS_OVERHEAD
+ sizeof(struct ieee80211_hdr
)) >
332 (priv
->nicbuf_size
- ETH_HLEN
))
339 EXPORT_SYMBOL(orinoco_change_mtu
);
341 /********************************************************************/
343 /********************************************************************/
345 /* Add encapsulation and MIC to the existing SKB.
346 * The main xmit routine will then send the whole lot to the card.
347 * Need 8 bytes headroom
348 * Need 8 bytes tailroom
350 * With encapsulated ethernet II frame
352 * 803.3 header (14 bytes)
355 * 803.3 header (14 bytes) len[2]
356 * dst[6] 803.2 header (8 bytes)
358 * len[2] <- leave alone -> len[2]
359 * -------- -------- <-- 0
367 * returns 0 on success, -ENOMEM on error.
369 int orinoco_process_xmit_skb(struct sk_buff
*skb
,
370 struct net_device
*dev
,
371 struct orinoco_private
*priv
,
375 struct orinoco_tkip_key
*key
;
379 key
= (struct orinoco_tkip_key
*) priv
->keys
[priv
->tx_key
].key
;
381 do_mic
= ((priv
->encode_alg
== ORINOCO_ALG_TKIP
) &&
385 *tx_control
|= (priv
->tx_key
<< HERMES_MIC_KEY_ID_SHIFT
) |
388 eh
= (struct ethhdr
*)skb
->data
;
390 /* Encapsulate Ethernet-II frames */
391 if (ntohs(eh
->h_proto
) > ETH_DATA_LEN
) { /* Ethernet-II frame */
392 struct header_struct
{
393 struct ethhdr eth
; /* 802.3 header */
394 u8 encap
[6]; /* 802.2 header */
395 } __attribute__ ((packed
)) hdr
;
396 int len
= skb
->len
+ sizeof(encaps_hdr
) - (2 * ETH_ALEN
);
398 if (skb_headroom(skb
) < ENCAPS_OVERHEAD
) {
401 "%s: Not enough headroom for 802.2 headers %d\n",
402 dev
->name
, skb_headroom(skb
));
406 /* Fill in new header */
407 memcpy(&hdr
.eth
, eh
, 2 * ETH_ALEN
);
408 hdr
.eth
.h_proto
= htons(len
);
409 memcpy(hdr
.encap
, encaps_hdr
, sizeof(encaps_hdr
));
411 /* Make room for the new header, and copy it in */
412 eh
= (struct ethhdr
*) skb_push(skb
, ENCAPS_OVERHEAD
);
413 memcpy(eh
, &hdr
, sizeof(hdr
));
416 /* Calculate Michael MIC */
418 size_t len
= skb
->len
- ETH_HLEN
;
419 u8
*mic
= &mic_buf
[0];
421 /* Have to write to an even address, so copy the spare
424 *mic
= skb
->data
[skb
->len
- 1];
428 orinoco_mic(priv
->tx_tfm_mic
, key
->tx_mic
,
429 eh
->h_dest
, eh
->h_source
, 0 /* priority */,
430 skb
->data
+ ETH_HLEN
,
436 EXPORT_SYMBOL(orinoco_process_xmit_skb
);
438 static netdev_tx_t
orinoco_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
440 struct orinoco_private
*priv
= ndev_priv(dev
);
441 struct net_device_stats
*stats
= &priv
->stats
;
442 hermes_t
*hw
= &priv
->hw
;
444 u16 txfid
= priv
->txfid
;
447 u8 mic_buf
[MICHAEL_MIC_LEN
+1];
449 if (!netif_running(dev
)) {
450 printk(KERN_ERR
"%s: Tx on stopped device!\n",
452 return NETDEV_TX_BUSY
;
455 if (netif_queue_stopped(dev
)) {
456 printk(KERN_DEBUG
"%s: Tx while transmitter busy!\n",
458 return NETDEV_TX_BUSY
;
461 if (orinoco_lock(priv
, &flags
) != 0) {
462 printk(KERN_ERR
"%s: orinoco_xmit() called while hw_unavailable\n",
464 return NETDEV_TX_BUSY
;
467 if (!netif_carrier_ok(dev
) ||
468 (priv
->iw_mode
== NL80211_IFTYPE_MONITOR
)) {
469 /* Oops, the firmware hasn't established a connection,
470 silently drop the packet (this seems to be the
475 /* Check packet length */
476 if (skb
->len
< ETH_HLEN
)
479 tx_control
= HERMES_TXCTRL_TX_OK
| HERMES_TXCTRL_TX_EX
;
481 err
= orinoco_process_xmit_skb(skb
, dev
, priv
, &tx_control
,
486 if (priv
->has_alt_txcntl
) {
487 /* WPA enabled firmwares have tx_cntl at the end of
488 * the 802.11 header. So write zeroed descriptor and
489 * 802.11 header at the same time
491 char desc
[HERMES_802_3_OFFSET
];
492 __le16
*txcntl
= (__le16
*) &desc
[HERMES_TXCNTL2_OFFSET
];
494 memset(&desc
, 0, sizeof(desc
));
496 *txcntl
= cpu_to_le16(tx_control
);
497 err
= hw
->ops
->bap_pwrite(hw
, USER_BAP
, &desc
, sizeof(desc
),
501 printk(KERN_ERR
"%s: Error %d writing Tx "
502 "descriptor to BAP\n", dev
->name
, err
);
506 struct hermes_tx_descriptor desc
;
508 memset(&desc
, 0, sizeof(desc
));
510 desc
.tx_control
= cpu_to_le16(tx_control
);
511 err
= hw
->ops
->bap_pwrite(hw
, USER_BAP
, &desc
, sizeof(desc
),
515 printk(KERN_ERR
"%s: Error %d writing Tx "
516 "descriptor to BAP\n", dev
->name
, err
);
520 /* Clear the 802.11 header and data length fields - some
521 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
522 * if this isn't done. */
523 hermes_clear_words(hw
, HERMES_DATA0
,
524 HERMES_802_3_OFFSET
- HERMES_802_11_OFFSET
);
527 err
= hw
->ops
->bap_pwrite(hw
, USER_BAP
, skb
->data
, skb
->len
,
528 txfid
, HERMES_802_3_OFFSET
);
530 printk(KERN_ERR
"%s: Error %d writing packet to BAP\n",
535 if (tx_control
& HERMES_TXCTRL_MIC
) {
536 size_t offset
= HERMES_802_3_OFFSET
+ skb
->len
;
537 size_t len
= MICHAEL_MIC_LEN
;
543 err
= hw
->ops
->bap_pwrite(hw
, USER_BAP
, &mic_buf
[0], len
,
546 printk(KERN_ERR
"%s: Error %d writing MIC to BAP\n",
552 /* Finally, we actually initiate the send */
553 netif_stop_queue(dev
);
555 err
= hw
->ops
->cmd_wait(hw
, HERMES_CMD_TX
| HERMES_CMD_RECL
,
558 netif_start_queue(dev
);
560 printk(KERN_ERR
"%s: Error %d transmitting packet\n",
565 dev
->trans_start
= jiffies
;
566 stats
->tx_bytes
+= HERMES_802_3_OFFSET
+ skb
->len
;
574 orinoco_unlock(priv
, &flags
);
580 schedule_work(&priv
->reset_work
);
581 orinoco_unlock(priv
, &flags
);
582 return NETDEV_TX_BUSY
;
585 static void __orinoco_ev_alloc(struct net_device
*dev
, hermes_t
*hw
)
587 struct orinoco_private
*priv
= ndev_priv(dev
);
588 u16 fid
= hermes_read_regn(hw
, ALLOCFID
);
590 if (fid
!= priv
->txfid
) {
591 if (fid
!= DUMMY_FID
)
592 printk(KERN_WARNING
"%s: Allocate event on unexpected fid (%04X)\n",
597 hermes_write_regn(hw
, ALLOCFID
, DUMMY_FID
);
600 static void __orinoco_ev_tx(struct net_device
*dev
, hermes_t
*hw
)
602 struct orinoco_private
*priv
= ndev_priv(dev
);
603 struct net_device_stats
*stats
= &priv
->stats
;
607 netif_wake_queue(dev
);
609 hermes_write_regn(hw
, TXCOMPLFID
, DUMMY_FID
);
612 static void __orinoco_ev_txexc(struct net_device
*dev
, hermes_t
*hw
)
614 struct orinoco_private
*priv
= ndev_priv(dev
);
615 struct net_device_stats
*stats
= &priv
->stats
;
616 u16 fid
= hermes_read_regn(hw
, TXCOMPLFID
);
618 struct hermes_txexc_data hdr
;
621 if (fid
== DUMMY_FID
)
622 return; /* Nothing's really happened */
624 /* Read part of the frame header - we need status and addr1 */
625 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, &hdr
,
626 sizeof(struct hermes_txexc_data
),
629 hermes_write_regn(hw
, TXCOMPLFID
, DUMMY_FID
);
633 printk(KERN_WARNING
"%s: Unable to read descriptor on Tx error "
634 "(FID=%04X error %d)\n",
635 dev
->name
, fid
, err
);
639 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev
->name
,
642 /* We produce a TXDROP event only for retry or lifetime
643 * exceeded, because that's the only status that really mean
644 * that this particular node went away.
645 * Other errors means that *we* screwed up. - Jean II */
646 status
= le16_to_cpu(hdr
.desc
.status
);
647 if (status
& (HERMES_TXSTAT_RETRYERR
| HERMES_TXSTAT_AGEDERR
)) {
648 union iwreq_data wrqu
;
650 /* Copy 802.11 dest address.
651 * We use the 802.11 header because the frame may
652 * not be 802.3 or may be mangled...
653 * In Ad-Hoc mode, it will be the node address.
654 * In managed mode, it will be most likely the AP addr
655 * User space will figure out how to convert it to
656 * whatever it needs (IP address or else).
658 memcpy(wrqu
.addr
.sa_data
, hdr
.addr1
, ETH_ALEN
);
659 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
661 /* Send event to user space */
662 wireless_send_event(dev
, IWEVTXDROP
, &wrqu
, NULL
);
665 netif_wake_queue(dev
);
668 void orinoco_tx_timeout(struct net_device
*dev
)
670 struct orinoco_private
*priv
= ndev_priv(dev
);
671 struct net_device_stats
*stats
= &priv
->stats
;
672 struct hermes
*hw
= &priv
->hw
;
674 printk(KERN_WARNING
"%s: Tx timeout! "
675 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
676 dev
->name
, hermes_read_regn(hw
, ALLOCFID
),
677 hermes_read_regn(hw
, TXCOMPLFID
), hermes_read_regn(hw
, EVSTAT
));
681 schedule_work(&priv
->reset_work
);
683 EXPORT_SYMBOL(orinoco_tx_timeout
);
685 /********************************************************************/
686 /* Rx path (data frames) */
687 /********************************************************************/
689 /* Does the frame have a SNAP header indicating it should be
690 * de-encapsulated to Ethernet-II? */
691 static inline int is_ethersnap(void *_hdr
)
695 /* We de-encapsulate all packets which, a) have SNAP headers
696 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
697 * and where b) the OUI of the SNAP header is 00:00:00 or
698 * 00:00:f8 - we need both because different APs appear to use
699 * different OUIs for some reason */
700 return (memcmp(hdr
, &encaps_hdr
, 5) == 0)
701 && ((hdr
[5] == 0x00) || (hdr
[5] == 0xf8));
704 static inline void orinoco_spy_gather(struct net_device
*dev
, u_char
*mac
,
705 int level
, int noise
)
707 struct iw_quality wstats
;
708 wstats
.level
= level
- 0x95;
709 wstats
.noise
= noise
- 0x95;
710 wstats
.qual
= (level
> noise
) ? (level
- noise
) : 0;
711 wstats
.updated
= IW_QUAL_ALL_UPDATED
| IW_QUAL_DBM
;
712 /* Update spy records */
713 wireless_spy_update(dev
, mac
, &wstats
);
716 static void orinoco_stat_gather(struct net_device
*dev
,
718 struct hermes_rx_descriptor
*desc
)
720 struct orinoco_private
*priv
= ndev_priv(dev
);
722 /* Using spy support with lots of Rx packets, like in an
723 * infrastructure (AP), will really slow down everything, because
724 * the MAC address must be compared to each entry of the spy list.
725 * If the user really asks for it (set some address in the
726 * spy list), we do it, but he will pay the price.
727 * Note that to get here, you need both WIRELESS_SPY
728 * compiled in AND some addresses in the list !!!
730 /* Note : gcc will optimise the whole section away if
731 * WIRELESS_SPY is not defined... - Jean II */
732 if (SPY_NUMBER(priv
)) {
733 orinoco_spy_gather(dev
, skb_mac_header(skb
) + ETH_ALEN
,
734 desc
->signal
, desc
->silence
);
739 * orinoco_rx_monitor - handle received monitor frames.
744 * desc rx descriptor of the frame
746 * Call context: interrupt
748 static void orinoco_rx_monitor(struct net_device
*dev
, u16 rxfid
,
749 struct hermes_rx_descriptor
*desc
)
751 u32 hdrlen
= 30; /* return full header by default */
757 struct orinoco_private
*priv
= ndev_priv(dev
);
758 struct net_device_stats
*stats
= &priv
->stats
;
759 hermes_t
*hw
= &priv
->hw
;
761 len
= le16_to_cpu(desc
->data_len
);
763 /* Determine the size of the header and the data */
764 fc
= le16_to_cpu(desc
->frame_ctl
);
765 switch (fc
& IEEE80211_FCTL_FTYPE
) {
766 case IEEE80211_FTYPE_DATA
:
767 if ((fc
& IEEE80211_FCTL_TODS
)
768 && (fc
& IEEE80211_FCTL_FROMDS
))
774 case IEEE80211_FTYPE_MGMT
:
778 case IEEE80211_FTYPE_CTL
:
779 switch (fc
& IEEE80211_FCTL_STYPE
) {
780 case IEEE80211_STYPE_PSPOLL
:
781 case IEEE80211_STYPE_RTS
:
782 case IEEE80211_STYPE_CFEND
:
783 case IEEE80211_STYPE_CFENDACK
:
786 case IEEE80211_STYPE_CTS
:
787 case IEEE80211_STYPE_ACK
:
793 /* Unknown frame type */
797 /* sanity check the length */
798 if (datalen
> IEEE80211_MAX_DATA_LEN
+ 12) {
799 printk(KERN_DEBUG
"%s: oversized monitor frame, "
800 "data length = %d\n", dev
->name
, datalen
);
801 stats
->rx_length_errors
++;
805 skb
= dev_alloc_skb(hdrlen
+ datalen
);
807 printk(KERN_WARNING
"%s: Cannot allocate skb for monitor frame\n",
812 /* Copy the 802.11 header to the skb */
813 memcpy(skb_put(skb
, hdrlen
), &(desc
->frame_ctl
), hdrlen
);
814 skb_reset_mac_header(skb
);
816 /* If any, copy the data from the card to the skb */
818 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, skb_put(skb
, datalen
),
819 ALIGN(datalen
, 2), rxfid
,
820 HERMES_802_2_OFFSET
);
822 printk(KERN_ERR
"%s: error %d reading monitor frame\n",
829 skb
->ip_summed
= CHECKSUM_NONE
;
830 skb
->pkt_type
= PACKET_OTHERHOST
;
831 skb
->protocol
= cpu_to_be16(ETH_P_802_2
);
834 stats
->rx_bytes
+= skb
->len
;
840 dev_kfree_skb_irq(skb
);
846 void __orinoco_ev_rx(struct net_device
*dev
, hermes_t
*hw
)
848 struct orinoco_private
*priv
= ndev_priv(dev
);
849 struct net_device_stats
*stats
= &priv
->stats
;
850 struct iw_statistics
*wstats
= &priv
->wstats
;
851 struct sk_buff
*skb
= NULL
;
854 struct hermes_rx_descriptor
*desc
;
855 struct orinoco_rx_data
*rx_data
;
858 desc
= kmalloc(sizeof(*desc
), GFP_ATOMIC
);
861 "%s: Can't allocate space for RX descriptor\n",
866 rxfid
= hermes_read_regn(hw
, RXFID
);
868 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, desc
, sizeof(*desc
),
871 printk(KERN_ERR
"%s: error %d reading Rx descriptor. "
872 "Frame dropped.\n", dev
->name
, err
);
876 status
= le16_to_cpu(desc
->status
);
878 if (status
& HERMES_RXSTAT_BADCRC
) {
879 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
881 stats
->rx_crc_errors
++;
885 /* Handle frames in monitor mode */
886 if (priv
->iw_mode
== NL80211_IFTYPE_MONITOR
) {
887 orinoco_rx_monitor(dev
, rxfid
, desc
);
891 if (status
& HERMES_RXSTAT_UNDECRYPTABLE
) {
892 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
894 wstats
->discard
.code
++;
898 length
= le16_to_cpu(desc
->data_len
);
901 if (length
< 3) { /* No for even an 802.2 LLC header */
902 /* At least on Symbol firmware with PCF we get quite a
903 lot of these legitimately - Poll frames with no
907 if (length
> IEEE80211_MAX_DATA_LEN
) {
908 printk(KERN_WARNING
"%s: Oversized frame received (%d bytes)\n",
910 stats
->rx_length_errors
++;
914 /* Payload size does not include Michael MIC. Increase payload
915 * size to read it together with the data. */
916 if (status
& HERMES_RXSTAT_MIC
)
917 length
+= MICHAEL_MIC_LEN
;
919 /* We need space for the packet data itself, plus an ethernet
920 header, plus 2 bytes so we can align the IP header on a
921 32bit boundary, plus 1 byte so we can read in odd length
922 packets from the card, which has an IO granularity of 16
924 skb
= dev_alloc_skb(length
+ETH_HLEN
+2+1);
926 printk(KERN_WARNING
"%s: Can't allocate skb for Rx\n",
931 /* We'll prepend the header, so reserve space for it. The worst
932 case is no decapsulation, when 802.3 header is prepended and
933 nothing is removed. 2 is for aligning the IP header. */
934 skb_reserve(skb
, ETH_HLEN
+ 2);
936 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, skb_put(skb
, length
),
937 ALIGN(length
, 2), rxfid
,
938 HERMES_802_2_OFFSET
);
940 printk(KERN_ERR
"%s: error %d reading frame. "
941 "Frame dropped.\n", dev
->name
, err
);
945 /* Add desc and skb to rx queue */
946 rx_data
= kzalloc(sizeof(*rx_data
), GFP_ATOMIC
);
948 printk(KERN_WARNING
"%s: Can't allocate RX packet\n",
952 rx_data
->desc
= desc
;
954 list_add_tail(&rx_data
->list
, &priv
->rx_list
);
955 tasklet_schedule(&priv
->rx_tasklet
);
960 dev_kfree_skb_irq(skb
);
967 EXPORT_SYMBOL(__orinoco_ev_rx
);
969 static void orinoco_rx(struct net_device
*dev
,
970 struct hermes_rx_descriptor
*desc
,
973 struct orinoco_private
*priv
= ndev_priv(dev
);
974 struct net_device_stats
*stats
= &priv
->stats
;
979 status
= le16_to_cpu(desc
->status
);
980 length
= le16_to_cpu(desc
->data_len
);
981 fc
= le16_to_cpu(desc
->frame_ctl
);
983 /* Calculate and check MIC */
984 if (status
& HERMES_RXSTAT_MIC
) {
985 struct orinoco_tkip_key
*key
;
986 int key_id
= ((status
& HERMES_RXSTAT_MIC_KEY_ID
) >>
987 HERMES_MIC_KEY_ID_SHIFT
);
988 u8 mic
[MICHAEL_MIC_LEN
];
990 u8
*src
= (fc
& IEEE80211_FCTL_FROMDS
) ?
991 desc
->addr3
: desc
->addr2
;
993 /* Extract Michael MIC from payload */
994 rxmic
= skb
->data
+ skb
->len
- MICHAEL_MIC_LEN
;
996 skb_trim(skb
, skb
->len
- MICHAEL_MIC_LEN
);
997 length
-= MICHAEL_MIC_LEN
;
999 key
= (struct orinoco_tkip_key
*) priv
->keys
[key_id
].key
;
1002 printk(KERN_WARNING
"%s: Received encrypted frame from "
1003 "%pM using key %i, but key is not installed\n",
1004 dev
->name
, src
, key_id
);
1008 orinoco_mic(priv
->rx_tfm_mic
, key
->rx_mic
, desc
->addr1
, src
,
1009 0, /* priority or QoS? */
1010 skb
->data
, skb
->len
, &mic
[0]);
1012 if (memcmp(mic
, rxmic
,
1014 union iwreq_data wrqu
;
1015 struct iw_michaelmicfailure wxmic
;
1017 printk(KERN_WARNING
"%s: "
1018 "Invalid Michael MIC in data frame from %pM, "
1020 dev
->name
, src
, key_id
);
1022 /* TODO: update stats */
1024 /* Notify userspace */
1025 memset(&wxmic
, 0, sizeof(wxmic
));
1026 wxmic
.flags
= key_id
& IW_MICFAILURE_KEY_ID
;
1027 wxmic
.flags
|= (desc
->addr1
[0] & 1) ?
1028 IW_MICFAILURE_GROUP
: IW_MICFAILURE_PAIRWISE
;
1029 wxmic
.src_addr
.sa_family
= ARPHRD_ETHER
;
1030 memcpy(wxmic
.src_addr
.sa_data
, src
, ETH_ALEN
);
1032 (void) orinoco_hw_get_tkip_iv(priv
, key_id
,
1035 memset(&wrqu
, 0, sizeof(wrqu
));
1036 wrqu
.data
.length
= sizeof(wxmic
);
1037 wireless_send_event(dev
, IWEVMICHAELMICFAILURE
, &wrqu
,
1044 /* Handle decapsulation
1045 * In most cases, the firmware tell us about SNAP frames.
1046 * For some reason, the SNAP frames sent by LinkSys APs
1047 * are not properly recognised by most firmwares.
1048 * So, check ourselves */
1049 if (length
>= ENCAPS_OVERHEAD
&&
1050 (((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_1042
) ||
1051 ((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_TUNNEL
) ||
1052 is_ethersnap(skb
->data
))) {
1053 /* These indicate a SNAP within 802.2 LLC within
1054 802.11 frame which we'll need to de-encapsulate to
1055 the original EthernetII frame. */
1056 hdr
= (struct ethhdr
*)skb_push(skb
,
1057 ETH_HLEN
- ENCAPS_OVERHEAD
);
1059 /* 802.3 frame - prepend 802.3 header as is */
1060 hdr
= (struct ethhdr
*)skb_push(skb
, ETH_HLEN
);
1061 hdr
->h_proto
= htons(length
);
1063 memcpy(hdr
->h_dest
, desc
->addr1
, ETH_ALEN
);
1064 if (fc
& IEEE80211_FCTL_FROMDS
)
1065 memcpy(hdr
->h_source
, desc
->addr3
, ETH_ALEN
);
1067 memcpy(hdr
->h_source
, desc
->addr2
, ETH_ALEN
);
1069 skb
->protocol
= eth_type_trans(skb
, dev
);
1070 skb
->ip_summed
= CHECKSUM_NONE
;
1071 if (fc
& IEEE80211_FCTL_TODS
)
1072 skb
->pkt_type
= PACKET_OTHERHOST
;
1074 /* Process the wireless stats if needed */
1075 orinoco_stat_gather(dev
, skb
, desc
);
1077 /* Pass the packet to the networking stack */
1079 stats
->rx_packets
++;
1080 stats
->rx_bytes
+= length
;
1087 stats
->rx_dropped
++;
1090 static void orinoco_rx_isr_tasklet(unsigned long data
)
1092 struct orinoco_private
*priv
= (struct orinoco_private
*) data
;
1093 struct net_device
*dev
= priv
->ndev
;
1094 struct orinoco_rx_data
*rx_data
, *temp
;
1095 struct hermes_rx_descriptor
*desc
;
1096 struct sk_buff
*skb
;
1097 unsigned long flags
;
1099 /* orinoco_rx requires the driver lock, and we also need to
1100 * protect priv->rx_list, so just hold the lock over the
1103 * If orinoco_lock fails, we've unplugged the card. In this
1104 * case just abort. */
1105 if (orinoco_lock(priv
, &flags
) != 0)
1108 /* extract desc and skb from queue */
1109 list_for_each_entry_safe(rx_data
, temp
, &priv
->rx_list
, list
) {
1110 desc
= rx_data
->desc
;
1112 list_del(&rx_data
->list
);
1115 orinoco_rx(dev
, desc
, skb
);
1120 orinoco_unlock(priv
, &flags
);
1123 /********************************************************************/
1124 /* Rx path (info frames) */
1125 /********************************************************************/
1127 static void print_linkstatus(struct net_device
*dev
, u16 status
)
1131 if (suppress_linkstatus
)
1135 case HERMES_LINKSTATUS_NOT_CONNECTED
:
1136 s
= "Not Connected";
1138 case HERMES_LINKSTATUS_CONNECTED
:
1141 case HERMES_LINKSTATUS_DISCONNECTED
:
1144 case HERMES_LINKSTATUS_AP_CHANGE
:
1147 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE
:
1148 s
= "AP Out of Range";
1150 case HERMES_LINKSTATUS_AP_IN_RANGE
:
1153 case HERMES_LINKSTATUS_ASSOC_FAILED
:
1154 s
= "Association Failed";
1160 printk(KERN_DEBUG
"%s: New link status: %s (%04x)\n",
1161 dev
->name
, s
, status
);
1164 /* Search scan results for requested BSSID, join it if found */
1165 static void orinoco_join_ap(struct work_struct
*work
)
1167 struct orinoco_private
*priv
=
1168 container_of(work
, struct orinoco_private
, join_work
);
1169 struct net_device
*dev
= priv
->ndev
;
1170 struct hermes
*hw
= &priv
->hw
;
1172 unsigned long flags
;
1176 } __attribute__ ((packed
)) req
;
1177 const int atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
1178 struct prism2_scan_apinfo
*atom
= NULL
;
1184 /* Allocate buffer for scan results */
1185 buf
= kmalloc(MAX_SCAN_LEN
, GFP_KERNEL
);
1189 if (orinoco_lock(priv
, &flags
) != 0)
1192 /* Sanity checks in case user changed something in the meantime */
1193 if (!priv
->bssid_fixed
)
1196 if (strlen(priv
->desired_essid
) == 0)
1199 /* Read scan results from the firmware */
1200 err
= hw
->ops
->read_ltv(hw
, USER_BAP
,
1201 HERMES_RID_SCANRESULTSTABLE
,
1202 MAX_SCAN_LEN
, &len
, buf
);
1204 printk(KERN_ERR
"%s: Cannot read scan results\n",
1209 len
= HERMES_RECLEN_TO_BYTES(len
);
1211 /* Go through the scan results looking for the channel of the AP
1212 * we were requested to join */
1213 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
1214 atom
= (struct prism2_scan_apinfo
*) (buf
+ offset
);
1215 if (memcmp(&atom
->bssid
, priv
->desired_bssid
, ETH_ALEN
) == 0) {
1222 DEBUG(1, "%s: Requested AP not found in scan results\n",
1227 memcpy(req
.bssid
, priv
->desired_bssid
, ETH_ALEN
);
1228 req
.channel
= atom
->channel
; /* both are little-endian */
1229 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
, HERMES_RID_CNFJOINREQUEST
,
1232 printk(KERN_ERR
"%s: Error issuing join request\n", dev
->name
);
1235 orinoco_unlock(priv
, &flags
);
1241 /* Send new BSSID to userspace */
1242 static void orinoco_send_bssid_wevent(struct orinoco_private
*priv
)
1244 struct net_device
*dev
= priv
->ndev
;
1245 struct hermes
*hw
= &priv
->hw
;
1246 union iwreq_data wrqu
;
1249 err
= hw
->ops
->read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTBSSID
,
1250 ETH_ALEN
, NULL
, wrqu
.ap_addr
.sa_data
);
1254 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1256 /* Send event to user space */
1257 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
1260 static void orinoco_send_assocreqie_wevent(struct orinoco_private
*priv
)
1262 struct net_device
*dev
= priv
->ndev
;
1263 struct hermes
*hw
= &priv
->hw
;
1264 union iwreq_data wrqu
;
1272 err
= hw
->ops
->read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENT_ASSOC_REQ_INFO
,
1273 sizeof(buf
), NULL
, &buf
);
1277 ie
= orinoco_get_wpa_ie(buf
, sizeof(buf
));
1279 int rem
= sizeof(buf
) - (ie
- &buf
[0]);
1280 wrqu
.data
.length
= ie
[1] + 2;
1281 if (wrqu
.data
.length
> rem
)
1282 wrqu
.data
.length
= rem
;
1284 if (wrqu
.data
.length
)
1285 /* Send event to user space */
1286 wireless_send_event(dev
, IWEVASSOCREQIE
, &wrqu
, ie
);
1290 static void orinoco_send_assocrespie_wevent(struct orinoco_private
*priv
)
1292 struct net_device
*dev
= priv
->ndev
;
1293 struct hermes
*hw
= &priv
->hw
;
1294 union iwreq_data wrqu
;
1296 u8 buf
[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1302 err
= hw
->ops
->read_ltv(hw
, USER_BAP
,
1303 HERMES_RID_CURRENT_ASSOC_RESP_INFO
,
1304 sizeof(buf
), NULL
, &buf
);
1308 ie
= orinoco_get_wpa_ie(buf
, sizeof(buf
));
1310 int rem
= sizeof(buf
) - (ie
- &buf
[0]);
1311 wrqu
.data
.length
= ie
[1] + 2;
1312 if (wrqu
.data
.length
> rem
)
1313 wrqu
.data
.length
= rem
;
1315 if (wrqu
.data
.length
)
1316 /* Send event to user space */
1317 wireless_send_event(dev
, IWEVASSOCRESPIE
, &wrqu
, ie
);
1321 static void orinoco_send_wevents(struct work_struct
*work
)
1323 struct orinoco_private
*priv
=
1324 container_of(work
, struct orinoco_private
, wevent_work
);
1325 unsigned long flags
;
1327 if (orinoco_lock(priv
, &flags
) != 0)
1330 orinoco_send_assocreqie_wevent(priv
);
1331 orinoco_send_assocrespie_wevent(priv
);
1332 orinoco_send_bssid_wevent(priv
);
1334 orinoco_unlock(priv
, &flags
);
1337 static void qbuf_scan(struct orinoco_private
*priv
, void *buf
,
1340 struct orinoco_scan_data
*sd
;
1341 unsigned long flags
;
1343 sd
= kmalloc(sizeof(*sd
), GFP_ATOMIC
);
1348 spin_lock_irqsave(&priv
->scan_lock
, flags
);
1349 list_add_tail(&sd
->list
, &priv
->scan_list
);
1350 spin_unlock_irqrestore(&priv
->scan_lock
, flags
);
1352 schedule_work(&priv
->process_scan
);
1355 static void qabort_scan(struct orinoco_private
*priv
)
1357 struct orinoco_scan_data
*sd
;
1358 unsigned long flags
;
1360 sd
= kmalloc(sizeof(*sd
), GFP_ATOMIC
);
1361 sd
->len
= -1; /* Abort */
1363 spin_lock_irqsave(&priv
->scan_lock
, flags
);
1364 list_add_tail(&sd
->list
, &priv
->scan_list
);
1365 spin_unlock_irqrestore(&priv
->scan_lock
, flags
);
1367 schedule_work(&priv
->process_scan
);
1370 static void orinoco_process_scan_results(struct work_struct
*work
)
1372 struct orinoco_private
*priv
=
1373 container_of(work
, struct orinoco_private
, process_scan
);
1374 struct orinoco_scan_data
*sd
, *temp
;
1375 unsigned long flags
;
1380 spin_lock_irqsave(&priv
->scan_lock
, flags
);
1381 list_for_each_entry_safe(sd
, temp
, &priv
->scan_list
, list
) {
1382 spin_unlock_irqrestore(&priv
->scan_lock
, flags
);
1388 list_del(&sd
->list
);
1392 if (type
== HERMES_INQ_CHANNELINFO
)
1393 orinoco_add_extscan_result(priv
, buf
, len
);
1395 orinoco_add_hostscan_results(priv
, buf
, len
);
1398 } else if (priv
->scan_request
) {
1399 /* Either abort or complete the scan */
1400 cfg80211_scan_done(priv
->scan_request
, (len
< 0));
1401 priv
->scan_request
= NULL
;
1404 spin_lock_irqsave(&priv
->scan_lock
, flags
);
1406 spin_unlock_irqrestore(&priv
->scan_lock
, flags
);
1409 void __orinoco_ev_info(struct net_device
*dev
, hermes_t
*hw
)
1411 struct orinoco_private
*priv
= ndev_priv(dev
);
1416 } __attribute__ ((packed
)) info
;
1420 /* This is an answer to an INQUIRE command that we did earlier,
1421 * or an information "event" generated by the card
1422 * The controller return to us a pseudo frame containing
1423 * the information in question - Jean II */
1424 infofid
= hermes_read_regn(hw
, INFOFID
);
1426 /* Read the info frame header - don't try too hard */
1427 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, &info
, sizeof(info
),
1430 printk(KERN_ERR
"%s: error %d reading info frame. "
1431 "Frame dropped.\n", dev
->name
, err
);
1435 len
= HERMES_RECLEN_TO_BYTES(le16_to_cpu(info
.len
));
1436 type
= le16_to_cpu(info
.type
);
1439 case HERMES_INQ_TALLIES
: {
1440 struct hermes_tallies_frame tallies
;
1441 struct iw_statistics
*wstats
= &priv
->wstats
;
1443 if (len
> sizeof(tallies
)) {
1444 printk(KERN_WARNING
"%s: Tallies frame too long (%d bytes)\n",
1446 len
= sizeof(tallies
);
1449 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, &tallies
, len
,
1450 infofid
, sizeof(info
));
1454 /* Increment our various counters */
1455 /* wstats->discard.nwid - no wrong BSSID stuff */
1456 wstats
->discard
.code
+=
1457 le16_to_cpu(tallies
.RxWEPUndecryptable
);
1458 if (len
== sizeof(tallies
))
1459 wstats
->discard
.code
+=
1460 le16_to_cpu(tallies
.RxDiscards_WEPICVError
) +
1461 le16_to_cpu(tallies
.RxDiscards_WEPExcluded
);
1462 wstats
->discard
.misc
+=
1463 le16_to_cpu(tallies
.TxDiscardsWrongSA
);
1464 wstats
->discard
.fragment
+=
1465 le16_to_cpu(tallies
.RxMsgInBadMsgFragments
);
1466 wstats
->discard
.retries
+=
1467 le16_to_cpu(tallies
.TxRetryLimitExceeded
);
1468 /* wstats->miss.beacon - no match */
1471 case HERMES_INQ_LINKSTATUS
: {
1472 struct hermes_linkstatus linkstatus
;
1476 if (priv
->iw_mode
== NL80211_IFTYPE_MONITOR
)
1479 if (len
!= sizeof(linkstatus
)) {
1480 printk(KERN_WARNING
"%s: Unexpected size for linkstatus frame (%d bytes)\n",
1485 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, &linkstatus
, len
,
1486 infofid
, sizeof(info
));
1489 newstatus
= le16_to_cpu(linkstatus
.linkstatus
);
1491 /* Symbol firmware uses "out of range" to signal that
1492 * the hostscan frame can be requested. */
1493 if (newstatus
== HERMES_LINKSTATUS_AP_OUT_OF_RANGE
&&
1494 priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
&&
1495 priv
->has_hostscan
&& priv
->scan_request
) {
1496 hermes_inquire(hw
, HERMES_INQ_HOSTSCAN_SYMBOL
);
1500 connected
= (newstatus
== HERMES_LINKSTATUS_CONNECTED
)
1501 || (newstatus
== HERMES_LINKSTATUS_AP_CHANGE
)
1502 || (newstatus
== HERMES_LINKSTATUS_AP_IN_RANGE
);
1505 netif_carrier_on(dev
);
1506 else if (!ignore_disconnect
)
1507 netif_carrier_off(dev
);
1509 if (newstatus
!= priv
->last_linkstatus
) {
1510 priv
->last_linkstatus
= newstatus
;
1511 print_linkstatus(dev
, newstatus
);
1512 /* The info frame contains only one word which is the
1513 * status (see hermes.h). The status is pretty boring
1514 * in itself, that's why we export the new BSSID...
1516 schedule_work(&priv
->wevent_work
);
1520 case HERMES_INQ_SCAN
:
1521 if (!priv
->scan_request
&& priv
->bssid_fixed
&&
1522 priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
) {
1523 schedule_work(&priv
->join_work
);
1527 case HERMES_INQ_HOSTSCAN
:
1528 case HERMES_INQ_HOSTSCAN_SYMBOL
: {
1529 /* Result of a scanning. Contains information about
1530 * cells in the vicinity - Jean II */
1535 printk(KERN_WARNING
"%s: Scan results too large (%d bytes)\n",
1541 /* Allocate buffer for results */
1542 buf
= kmalloc(len
, GFP_ATOMIC
);
1544 /* No memory, so can't printk()... */
1549 /* Read scan data */
1550 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, (void *) buf
, len
,
1551 infofid
, sizeof(info
));
1558 #ifdef ORINOCO_DEBUG
1561 printk(KERN_DEBUG
"Scan result [%02X", buf
[0]);
1562 for (i
= 1; i
< (len
* 2); i
++)
1563 printk(":%02X", buf
[i
]);
1566 #endif /* ORINOCO_DEBUG */
1568 qbuf_scan(priv
, buf
, len
, type
);
1571 case HERMES_INQ_CHANNELINFO
:
1573 struct agere_ext_scan_info
*bss
;
1575 if (!priv
->scan_request
) {
1576 printk(KERN_DEBUG
"%s: Got chaninfo without scan, "
1577 "len=%d\n", dev
->name
, len
);
1581 /* An empty result indicates that the scan is complete */
1583 qbuf_scan(priv
, NULL
, len
, type
);
1588 else if (len
< (offsetof(struct agere_ext_scan_info
,
1590 /* Drop this result now so we don't have to
1591 * keep checking later */
1593 "%s: Ext scan results too short (%d bytes)\n",
1598 bss
= kmalloc(len
, GFP_ATOMIC
);
1602 /* Read scan data */
1603 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, (void *) bss
, len
,
1604 infofid
, sizeof(info
));
1608 qbuf_scan(priv
, bss
, len
, type
);
1612 case HERMES_INQ_SEC_STAT_AGERE
:
1613 /* Security status (Agere specific) */
1614 /* Ignore this frame for now */
1615 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
)
1619 printk(KERN_DEBUG
"%s: Unknown information frame received: "
1620 "type 0x%04x, length %d\n", dev
->name
, type
, len
);
1621 /* We don't actually do anything about it */
1627 EXPORT_SYMBOL(__orinoco_ev_info
);
1629 static void __orinoco_ev_infdrop(struct net_device
*dev
, hermes_t
*hw
)
1631 if (net_ratelimit())
1632 printk(KERN_DEBUG
"%s: Information frame lost.\n", dev
->name
);
1635 /********************************************************************/
1636 /* Internal hardware control routines */
1637 /********************************************************************/
1639 static int __orinoco_up(struct orinoco_private
*priv
)
1641 struct net_device
*dev
= priv
->ndev
;
1642 struct hermes
*hw
= &priv
->hw
;
1645 netif_carrier_off(dev
); /* just to make sure */
1647 err
= __orinoco_commit(priv
);
1649 printk(KERN_ERR
"%s: Error %d configuring card\n",
1654 /* Fire things up again */
1655 hermes_set_irqmask(hw
, ORINOCO_INTEN
);
1656 err
= hermes_enable_port(hw
, 0);
1658 printk(KERN_ERR
"%s: Error %d enabling MAC port\n",
1663 netif_start_queue(dev
);
1668 static int __orinoco_down(struct orinoco_private
*priv
)
1670 struct net_device
*dev
= priv
->ndev
;
1671 struct hermes
*hw
= &priv
->hw
;
1674 netif_stop_queue(dev
);
1676 if (!priv
->hw_unavailable
) {
1677 if (!priv
->broken_disableport
) {
1678 err
= hermes_disable_port(hw
, 0);
1680 /* Some firmwares (e.g. Intersil 1.3.x) seem
1681 * to have problems disabling the port, oh
1683 printk(KERN_WARNING
"%s: Error %d disabling MAC port\n",
1685 priv
->broken_disableport
= 1;
1688 hermes_set_irqmask(hw
, 0);
1689 hermes_write_regn(hw
, EVACK
, 0xffff);
1692 /* firmware will have to reassociate */
1693 netif_carrier_off(dev
);
1694 priv
->last_linkstatus
= 0xffff;
1699 static int orinoco_reinit_firmware(struct orinoco_private
*priv
)
1701 struct hermes
*hw
= &priv
->hw
;
1704 err
= hw
->ops
->init(hw
);
1705 if (priv
->do_fw_download
&& !err
) {
1706 err
= orinoco_download(priv
);
1708 priv
->do_fw_download
= 0;
1711 err
= orinoco_hw_allocate_fid(priv
);
1717 __orinoco_set_multicast_list(struct net_device
*dev
)
1719 struct orinoco_private
*priv
= ndev_priv(dev
);
1721 int promisc
, mc_count
;
1723 /* The Hermes doesn't seem to have an allmulti mode, so we go
1724 * into promiscuous mode and let the upper levels deal. */
1725 if ((dev
->flags
& IFF_PROMISC
) || (dev
->flags
& IFF_ALLMULTI
) ||
1726 (dev
->mc_count
> MAX_MULTICAST(priv
))) {
1731 mc_count
= dev
->mc_count
;
1734 err
= __orinoco_hw_set_multicast_list(priv
, dev
->mc_list
, mc_count
,
1740 /* This must be called from user context, without locks held - use
1741 * schedule_work() */
1742 void orinoco_reset(struct work_struct
*work
)
1744 struct orinoco_private
*priv
=
1745 container_of(work
, struct orinoco_private
, reset_work
);
1746 struct net_device
*dev
= priv
->ndev
;
1747 struct hermes
*hw
= &priv
->hw
;
1749 unsigned long flags
;
1751 if (orinoco_lock(priv
, &flags
) != 0)
1752 /* When the hardware becomes available again, whatever
1753 * detects that is responsible for re-initializing
1754 * it. So no need for anything further */
1757 netif_stop_queue(dev
);
1759 /* Shut off interrupts. Depending on what state the hardware
1760 * is in, this might not work, but we'll try anyway */
1761 hermes_set_irqmask(hw
, 0);
1762 hermes_write_regn(hw
, EVACK
, 0xffff);
1764 priv
->hw_unavailable
++;
1765 priv
->last_linkstatus
= 0xffff; /* firmware will have to reassociate */
1766 netif_carrier_off(dev
);
1768 orinoco_unlock(priv
, &flags
);
1770 /* Scanning support: Notify scan cancellation */
1771 if (priv
->scan_request
) {
1772 cfg80211_scan_done(priv
->scan_request
, 1);
1773 priv
->scan_request
= NULL
;
1776 if (priv
->hard_reset
) {
1777 err
= (*priv
->hard_reset
)(priv
);
1779 printk(KERN_ERR
"%s: orinoco_reset: Error %d "
1780 "performing hard reset\n", dev
->name
, err
);
1785 err
= orinoco_reinit_firmware(priv
);
1787 printk(KERN_ERR
"%s: orinoco_reset: Error %d re-initializing firmware\n",
1792 /* This has to be called from user context */
1793 orinoco_lock_irq(priv
);
1795 priv
->hw_unavailable
--;
1797 /* priv->open or priv->hw_unavailable might have changed while
1798 * we dropped the lock */
1799 if (priv
->open
&& (!priv
->hw_unavailable
)) {
1800 err
= __orinoco_up(priv
);
1802 printk(KERN_ERR
"%s: orinoco_reset: Error %d reenabling card\n",
1805 dev
->trans_start
= jiffies
;
1808 orinoco_unlock_irq(priv
);
1812 hermes_set_irqmask(hw
, 0);
1813 netif_device_detach(dev
);
1814 printk(KERN_ERR
"%s: Device has been disabled!\n", dev
->name
);
1817 static int __orinoco_commit(struct orinoco_private
*priv
)
1819 struct net_device
*dev
= priv
->ndev
;
1822 /* If we've called commit, we are reconfiguring or bringing the
1823 * interface up. Maintaining countermeasures across this would
1824 * be confusing, so note that we've disabled them. The port will
1825 * be enabled later in orinoco_commit or __orinoco_up. */
1826 priv
->tkip_cm_active
= 0;
1828 err
= orinoco_hw_program_rids(priv
);
1830 /* FIXME: what about netif_tx_lock */
1831 (void) __orinoco_set_multicast_list(dev
);
1836 /* Ensures configuration changes are applied. May result in a reset.
1837 * The caller should hold priv->lock
1839 int orinoco_commit(struct orinoco_private
*priv
)
1841 struct net_device
*dev
= priv
->ndev
;
1842 hermes_t
*hw
= &priv
->hw
;
1845 if (priv
->broken_disableport
) {
1846 schedule_work(&priv
->reset_work
);
1850 err
= hermes_disable_port(hw
, 0);
1852 printk(KERN_WARNING
"%s: Unable to disable port "
1853 "while reconfiguring card\n", dev
->name
);
1854 priv
->broken_disableport
= 1;
1858 err
= __orinoco_commit(priv
);
1860 printk(KERN_WARNING
"%s: Unable to reconfigure card\n",
1865 err
= hermes_enable_port(hw
, 0);
1867 printk(KERN_WARNING
"%s: Unable to enable port while reconfiguring card\n",
1874 printk(KERN_WARNING
"%s: Resetting instead...\n", dev
->name
);
1875 schedule_work(&priv
->reset_work
);
1881 /********************************************************************/
1882 /* Interrupt handler */
1883 /********************************************************************/
1885 static void __orinoco_ev_tick(struct net_device
*dev
, hermes_t
*hw
)
1887 printk(KERN_DEBUG
"%s: TICK\n", dev
->name
);
1890 static void __orinoco_ev_wterr(struct net_device
*dev
, hermes_t
*hw
)
1892 /* This seems to happen a fair bit under load, but ignoring it
1893 seems to work fine...*/
1894 printk(KERN_DEBUG
"%s: MAC controller error (WTERR). Ignoring.\n",
1898 irqreturn_t
orinoco_interrupt(int irq
, void *dev_id
)
1900 struct orinoco_private
*priv
= dev_id
;
1901 struct net_device
*dev
= priv
->ndev
;
1902 hermes_t
*hw
= &priv
->hw
;
1903 int count
= MAX_IRQLOOPS_PER_IRQ
;
1905 /* These are used to detect a runaway interrupt situation.
1907 * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1908 * we panic and shut down the hardware
1910 /* jiffies value the last time we were called */
1911 static int last_irq_jiffy
; /* = 0 */
1912 static int loops_this_jiffy
; /* = 0 */
1913 unsigned long flags
;
1915 if (orinoco_lock(priv
, &flags
) != 0) {
1916 /* If hw is unavailable - we don't know if the irq was
1921 evstat
= hermes_read_regn(hw
, EVSTAT
);
1922 events
= evstat
& hw
->inten
;
1924 orinoco_unlock(priv
, &flags
);
1928 if (jiffies
!= last_irq_jiffy
)
1929 loops_this_jiffy
= 0;
1930 last_irq_jiffy
= jiffies
;
1932 while (events
&& count
--) {
1933 if (++loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
) {
1934 printk(KERN_WARNING
"%s: IRQ handler is looping too "
1935 "much! Resetting.\n", dev
->name
);
1936 /* Disable interrupts for now */
1937 hermes_set_irqmask(hw
, 0);
1938 schedule_work(&priv
->reset_work
);
1942 /* Check the card hasn't been removed */
1943 if (!hermes_present(hw
)) {
1944 DEBUG(0, "orinoco_interrupt(): card removed\n");
1948 if (events
& HERMES_EV_TICK
)
1949 __orinoco_ev_tick(dev
, hw
);
1950 if (events
& HERMES_EV_WTERR
)
1951 __orinoco_ev_wterr(dev
, hw
);
1952 if (events
& HERMES_EV_INFDROP
)
1953 __orinoco_ev_infdrop(dev
, hw
);
1954 if (events
& HERMES_EV_INFO
)
1955 __orinoco_ev_info(dev
, hw
);
1956 if (events
& HERMES_EV_RX
)
1957 __orinoco_ev_rx(dev
, hw
);
1958 if (events
& HERMES_EV_TXEXC
)
1959 __orinoco_ev_txexc(dev
, hw
);
1960 if (events
& HERMES_EV_TX
)
1961 __orinoco_ev_tx(dev
, hw
);
1962 if (events
& HERMES_EV_ALLOC
)
1963 __orinoco_ev_alloc(dev
, hw
);
1965 hermes_write_regn(hw
, EVACK
, evstat
);
1967 evstat
= hermes_read_regn(hw
, EVSTAT
);
1968 events
= evstat
& hw
->inten
;
1971 orinoco_unlock(priv
, &flags
);
1974 EXPORT_SYMBOL(orinoco_interrupt
);
1976 /********************************************************************/
1977 /* Power management */
1978 /********************************************************************/
1979 #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
1980 static int orinoco_pm_notifier(struct notifier_block
*notifier
,
1981 unsigned long pm_event
,
1984 struct orinoco_private
*priv
= container_of(notifier
,
1985 struct orinoco_private
,
1988 /* All we need to do is cache the firmware before suspend, and
1989 * release it when we come out.
1991 * Only need to do this if we're downloading firmware. */
1992 if (!priv
->do_fw_download
)
1996 case PM_HIBERNATION_PREPARE
:
1997 case PM_SUSPEND_PREPARE
:
1998 orinoco_cache_fw(priv
, 0);
2001 case PM_POST_RESTORE
:
2002 /* Restore from hibernation failed. We need to clean
2003 * up in exactly the same way, so fall through. */
2004 case PM_POST_HIBERNATION
:
2005 case PM_POST_SUSPEND
:
2006 orinoco_uncache_fw(priv
);
2009 case PM_RESTORE_PREPARE
:
2017 static void orinoco_register_pm_notifier(struct orinoco_private
*priv
)
2019 priv
->pm_notifier
.notifier_call
= orinoco_pm_notifier
;
2020 register_pm_notifier(&priv
->pm_notifier
);
2023 static void orinoco_unregister_pm_notifier(struct orinoco_private
*priv
)
2025 unregister_pm_notifier(&priv
->pm_notifier
);
2027 #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
2028 #define orinoco_register_pm_notifier(priv) do { } while(0)
2029 #define orinoco_unregister_pm_notifier(priv) do { } while(0)
2032 /********************************************************************/
2033 /* Initialization */
2034 /********************************************************************/
2036 int orinoco_init(struct orinoco_private
*priv
)
2038 struct device
*dev
= priv
->dev
;
2039 struct wiphy
*wiphy
= priv_to_wiphy(priv
);
2040 hermes_t
*hw
= &priv
->hw
;
2043 /* No need to lock, the hw_unavailable flag is already set in
2044 * alloc_orinocodev() */
2045 priv
->nicbuf_size
= IEEE80211_MAX_FRAME_LEN
+ ETH_HLEN
;
2047 /* Initialize the firmware */
2048 err
= hw
->ops
->init(hw
);
2050 dev_err(dev
, "Failed to initialize firmware (err = %d)\n",
2055 err
= determine_fw_capabilities(priv
);
2057 dev_err(dev
, "Incompatible firmware, aborting\n");
2061 if (priv
->do_fw_download
) {
2062 #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
2063 orinoco_cache_fw(priv
, 0);
2066 err
= orinoco_download(priv
);
2068 priv
->do_fw_download
= 0;
2070 /* Check firmware version again */
2071 err
= determine_fw_capabilities(priv
);
2073 dev_err(dev
, "Incompatible firmware, aborting\n");
2078 if (priv
->has_port3
)
2079 dev_info(dev
, "Ad-hoc demo mode supported\n");
2081 dev_info(dev
, "IEEE standard IBSS ad-hoc mode supported\n");
2083 dev_info(dev
, "WEP supported, %s-bit key\n",
2084 priv
->has_big_wep
? "104" : "40");
2085 if (priv
->has_wpa
) {
2086 dev_info(dev
, "WPA-PSK supported\n");
2087 if (orinoco_mic_init(priv
)) {
2088 dev_err(dev
, "Failed to setup MIC crypto algorithm. "
2089 "Disabling WPA support\n");
2094 err
= orinoco_hw_read_card_settings(priv
, wiphy
->perm_addr
);
2098 err
= orinoco_hw_allocate_fid(priv
);
2100 dev_err(dev
, "Failed to allocate NIC buffer!\n");
2104 /* Set up the default configuration */
2105 priv
->iw_mode
= NL80211_IFTYPE_STATION
;
2106 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2107 priv
->prefer_port3
= priv
->has_port3
&& (!priv
->has_ibss
);
2108 set_port_type(priv
);
2109 priv
->channel
= 0; /* use firmware default */
2111 priv
->promiscuous
= 0;
2112 priv
->encode_alg
= ORINOCO_ALG_NONE
;
2114 priv
->wpa_enabled
= 0;
2115 priv
->tkip_cm_active
= 0;
2117 priv
->wpa_ie_len
= 0;
2118 priv
->wpa_ie
= NULL
;
2120 if (orinoco_wiphy_register(wiphy
)) {
2125 /* Make the hardware available, as long as it hasn't been
2126 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2127 orinoco_lock_irq(priv
);
2128 priv
->hw_unavailable
--;
2129 orinoco_unlock_irq(priv
);
2131 dev_dbg(dev
, "Ready\n");
2136 EXPORT_SYMBOL(orinoco_init
);
2138 static const struct net_device_ops orinoco_netdev_ops
= {
2139 .ndo_open
= orinoco_open
,
2140 .ndo_stop
= orinoco_stop
,
2141 .ndo_start_xmit
= orinoco_xmit
,
2142 .ndo_set_multicast_list
= orinoco_set_multicast_list
,
2143 .ndo_change_mtu
= orinoco_change_mtu
,
2144 .ndo_set_mac_address
= eth_mac_addr
,
2145 .ndo_validate_addr
= eth_validate_addr
,
2146 .ndo_tx_timeout
= orinoco_tx_timeout
,
2147 .ndo_get_stats
= orinoco_get_stats
,
2150 /* Allocate private data.
2152 * This driver has a number of structures associated with it
2153 * netdev - Net device structure for each network interface
2154 * wiphy - structure associated with wireless phy
2155 * wireless_dev (wdev) - structure for each wireless interface
2156 * hw - structure for hermes chip info
2157 * card - card specific structure for use by the card driver
2158 * (airport, orinoco_cs)
2159 * priv - orinoco private data
2160 * device - generic linux device structure
2162 * +---------+ +---------+
2163 * | wiphy | | netdev |
2164 * | +-------+ | +-------+
2165 * | | priv | | | wdev |
2166 * | | +-----+ +-+-------+
2172 * priv has a link to netdev and device
2173 * wdev has a link to wiphy
2175 struct orinoco_private
2176 *alloc_orinocodev(int sizeof_card
,
2177 struct device
*device
,
2178 int (*hard_reset
)(struct orinoco_private
*),
2179 int (*stop_fw
)(struct orinoco_private
*, int))
2181 struct orinoco_private
*priv
;
2182 struct wiphy
*wiphy
;
2185 * NOTE: We only support a single virtual interface
2186 * but this may change when monitor mode is added
2188 wiphy
= wiphy_new(&orinoco_cfg_ops
,
2189 sizeof(struct orinoco_private
) + sizeof_card
);
2193 priv
= wiphy_priv(wiphy
);
2197 priv
->card
= (void *)((unsigned long)priv
2198 + sizeof(struct orinoco_private
));
2202 orinoco_wiphy_init(wiphy
);
2205 priv
->wireless_data
.spy_data
= &priv
->spy_data
;
2208 /* Set up default callbacks */
2209 priv
->hard_reset
= hard_reset
;
2210 priv
->stop_fw
= stop_fw
;
2212 spin_lock_init(&priv
->lock
);
2214 priv
->hw_unavailable
= 1; /* orinoco_init() must clear this
2215 * before anything else touches the
2217 INIT_WORK(&priv
->reset_work
, orinoco_reset
);
2218 INIT_WORK(&priv
->join_work
, orinoco_join_ap
);
2219 INIT_WORK(&priv
->wevent_work
, orinoco_send_wevents
);
2221 INIT_LIST_HEAD(&priv
->rx_list
);
2222 tasklet_init(&priv
->rx_tasklet
, orinoco_rx_isr_tasklet
,
2223 (unsigned long) priv
);
2225 spin_lock_init(&priv
->scan_lock
);
2226 INIT_LIST_HEAD(&priv
->scan_list
);
2227 INIT_WORK(&priv
->process_scan
, orinoco_process_scan_results
);
2229 priv
->last_linkstatus
= 0xffff;
2231 #if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
2232 priv
->cached_pri_fw
= NULL
;
2233 priv
->cached_fw
= NULL
;
2236 /* Register PM notifiers */
2237 orinoco_register_pm_notifier(priv
);
2241 EXPORT_SYMBOL(alloc_orinocodev
);
2243 /* We can only support a single interface. We provide a separate
2244 * function to set it up to distinguish between hardware
2245 * initialisation and interface setup.
2247 * The base_addr and irq parameters are passed on to netdev for use
2250 int orinoco_if_add(struct orinoco_private
*priv
,
2251 unsigned long base_addr
,
2253 const struct net_device_ops
*ops
)
2255 struct wiphy
*wiphy
= priv_to_wiphy(priv
);
2256 struct wireless_dev
*wdev
;
2257 struct net_device
*dev
;
2260 dev
= alloc_etherdev(sizeof(struct wireless_dev
));
2265 /* Initialise wireless_dev */
2266 wdev
= netdev_priv(dev
);
2267 wdev
->wiphy
= wiphy
;
2268 wdev
->iftype
= NL80211_IFTYPE_STATION
;
2270 /* Setup / override net_device fields */
2271 dev
->ieee80211_ptr
= wdev
;
2272 dev
->watchdog_timeo
= HZ
; /* 1 second timeout */
2273 dev
->ethtool_ops
= &orinoco_ethtool_ops
;
2274 dev
->wireless_handlers
= &orinoco_handler_def
;
2276 dev
->wireless_data
= &priv
->wireless_data
;
2278 /* Default to standard ops if not set */
2280 dev
->netdev_ops
= ops
;
2282 dev
->netdev_ops
= &orinoco_netdev_ops
;
2284 /* we use the default eth_mac_addr for setting the MAC addr */
2286 /* Reserve space in skb for the SNAP header */
2287 dev
->needed_headroom
= ENCAPS_OVERHEAD
;
2289 netif_carrier_off(dev
);
2291 memcpy(dev
->dev_addr
, wiphy
->perm_addr
, ETH_ALEN
);
2293 dev
->base_addr
= base_addr
;
2296 SET_NETDEV_DEV(dev
, priv
->dev
);
2297 ret
= register_netdev(dev
);
2303 /* Report what we've done */
2304 dev_dbg(priv
->dev
, "Registerred interface %s.\n", dev
->name
);
2312 EXPORT_SYMBOL(orinoco_if_add
);
2314 void orinoco_if_del(struct orinoco_private
*priv
)
2316 struct net_device
*dev
= priv
->ndev
;
2318 unregister_netdev(dev
);
2321 EXPORT_SYMBOL(orinoco_if_del
);
2323 void free_orinocodev(struct orinoco_private
*priv
)
2325 struct wiphy
*wiphy
= priv_to_wiphy(priv
);
2326 struct orinoco_rx_data
*rx_data
, *temp
;
2327 struct orinoco_scan_data
*sd
, *sdtemp
;
2329 wiphy_unregister(wiphy
);
2331 /* If the tasklet is scheduled when we call tasklet_kill it
2332 * will run one final time. However the tasklet will only
2333 * drain priv->rx_list if the hw is still available. */
2334 tasklet_kill(&priv
->rx_tasklet
);
2336 /* Explicitly drain priv->rx_list */
2337 list_for_each_entry_safe(rx_data
, temp
, &priv
->rx_list
, list
) {
2338 list_del(&rx_data
->list
);
2340 dev_kfree_skb(rx_data
->skb
);
2341 kfree(rx_data
->desc
);
2345 cancel_work_sync(&priv
->process_scan
);
2346 /* Explicitly drain priv->scan_list */
2347 list_for_each_entry_safe(sd
, sdtemp
, &priv
->scan_list
, list
) {
2348 list_del(&sd
->list
);
2350 if ((sd
->len
> 0) && sd
->buf
)
2355 orinoco_unregister_pm_notifier(priv
);
2356 orinoco_uncache_fw(priv
);
2358 priv
->wpa_ie_len
= 0;
2359 kfree(priv
->wpa_ie
);
2360 orinoco_mic_free(priv
);
2363 EXPORT_SYMBOL(free_orinocodev
);
2365 int orinoco_up(struct orinoco_private
*priv
)
2367 struct net_device
*dev
= priv
->ndev
;
2368 unsigned long flags
;
2371 priv
->hw
.ops
->lock_irqsave(&priv
->lock
, &flags
);
2373 err
= orinoco_reinit_firmware(priv
);
2375 printk(KERN_ERR
"%s: Error %d re-initializing firmware\n",
2380 netif_device_attach(dev
);
2381 priv
->hw_unavailable
--;
2383 if (priv
->open
&& !priv
->hw_unavailable
) {
2384 err
= __orinoco_up(priv
);
2386 printk(KERN_ERR
"%s: Error %d restarting card\n",
2391 priv
->hw
.ops
->unlock_irqrestore(&priv
->lock
, &flags
);
2395 EXPORT_SYMBOL(orinoco_up
);
2397 void orinoco_down(struct orinoco_private
*priv
)
2399 struct net_device
*dev
= priv
->ndev
;
2400 unsigned long flags
;
2403 priv
->hw
.ops
->lock_irqsave(&priv
->lock
, &flags
);
2404 err
= __orinoco_down(priv
);
2406 printk(KERN_WARNING
"%s: Error %d downing interface\n",
2409 netif_device_detach(dev
);
2410 priv
->hw_unavailable
++;
2411 priv
->hw
.ops
->unlock_irqrestore(&priv
->lock
, &flags
);
2413 EXPORT_SYMBOL(orinoco_down
);
2415 static void orinoco_get_drvinfo(struct net_device
*dev
,
2416 struct ethtool_drvinfo
*info
)
2418 struct orinoco_private
*priv
= ndev_priv(dev
);
2420 strncpy(info
->driver
, DRIVER_NAME
, sizeof(info
->driver
) - 1);
2421 strncpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
) - 1);
2422 strncpy(info
->fw_version
, priv
->fw_name
, sizeof(info
->fw_version
) - 1);
2425 static const struct ethtool_ops orinoco_ethtool_ops
= {
2426 .get_drvinfo
= orinoco_get_drvinfo
,
2427 .get_link
= ethtool_op_get_link
,
2430 /********************************************************************/
2431 /* Module initialization */
2432 /********************************************************************/
2434 /* Can't be declared "const" or the whole __initdata section will
2436 static char version
[] __initdata
= DRIVER_NAME
" " DRIVER_VERSION
2437 " (David Gibson <hermes@gibson.dropbear.id.au>, "
2438 "Pavel Roskin <proski@gnu.org>, et al)";
2440 static int __init
init_orinoco(void)
2442 printk(KERN_DEBUG
"%s\n", version
);
2446 static void __exit
exit_orinoco(void)
2450 module_init(init_orinoco
);
2451 module_exit(exit_orinoco
);