blob: 4fa8264a400f4b92d75ea96a855128bbc763ba31 [file] [log] [blame]
David Kilroy47445cb2009-02-04 23:05:48 +00001/* main.c - (formerly known as dldwd_cs.c, orinoco_cs.c and orinoco.c)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
5 *
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>
9 *
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
15 *
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
17 *
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/
21 *
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/
26 *
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.
31 *
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
35 * Reserved.
36 *
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. */
47
48/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 * 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.
57 */
58
59/* Locking and synchronization:
60 *
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.
66 *
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).
75 */
76
77#define DRIVER_NAME "orinoco"
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <linux/module.h>
80#include <linux/kernel.h>
81#include <linux/init.h>
David Kilroyd03032a2008-08-21 23:28:02 +010082#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#include <linux/netdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#include <linux/etherdevice.h>
Christoph Hellwig1fab2e82005-06-19 01:27:40 +020085#include <linux/ethtool.h>
David Kilroy39d1ffe2008-11-22 10:37:28 +000086#include <linux/suspend.h>
Pavel Roskin9c974fb2006-08-15 20:45:03 -040087#include <linux/if_arp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#include <linux/wireless.h>
Johannes Berg2c7060022008-10-30 22:09:54 +010089#include <linux/ieee80211.h>
Christoph Hellwig620554e2005-06-19 01:27:33 +020090#include <net/iw_handler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#include "hermes_rid.h"
David Kilroy3994d502008-08-21 23:27:54 +010093#include "hermes_dld.h"
David Kilroy712a4342009-02-04 23:05:55 +000094#include "hw.h"
David Kilroyfb791b12009-02-04 23:05:50 +000095#include "scan.h"
David Kilroy4adb4742009-02-04 23:05:51 +000096#include "mic.h"
David Kilroy37a2e562009-02-04 23:05:52 +000097#include "fw.h"
David Kilroycb1576a2009-02-04 23:05:56 +000098#include "wext.h"
99#include "main.h"
David Kilroyfb791b12009-02-04 23:05:50 +0000100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#include "orinoco.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103/********************************************************************/
104/* Module information */
105/********************************************************************/
106
David Kilroyb2f30a02009-02-04 23:05:46 +0000107MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
108 "David Gibson <hermes@gibson.dropbear.id.au>");
109MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
110 "and similar wireless cards");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111MODULE_LICENSE("Dual MPL/GPL");
112
113/* Level of debugging. Used in the macros in orinoco.h */
114#ifdef ORINOCO_DEBUG
115int orinoco_debug = ORINOCO_DEBUG;
David Kilroy21312662009-02-04 23:05:47 +0000116EXPORT_SYMBOL(orinoco_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117module_param(orinoco_debug, int, 0644);
118MODULE_PARM_DESC(orinoco_debug, "Debug level");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#endif
120
121static int suppress_linkstatus; /* = 0 */
122module_param(suppress_linkstatus, bool, 0644);
123MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
David Kilroyb2f30a02009-02-04 23:05:46 +0000124
David Gibson7bb7c3a2005-05-12 20:02:10 -0400125static int ignore_disconnect; /* = 0 */
126module_param(ignore_disconnect, int, 0644);
David Kilroyb2f30a02009-02-04 23:05:46 +0000127MODULE_PARM_DESC(ignore_disconnect,
128 "Don't report lost link to the network layer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
David Kilroycb1576a2009-02-04 23:05:56 +0000130int force_monitor; /* = 0 */
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200131module_param(force_monitor, int, 0644);
132MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/* Internal constants */
136/********************************************************************/
137
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200138/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
139static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
140#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define ORINOCO_MIN_MTU 256
Johannes Berg2c7060022008-10-30 22:09:54 +0100143#define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define MAX_IRQLOOPS_PER_IRQ 10
146#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
147 * how many events the
148 * device could
149 * legitimately generate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151#define DUMMY_FID 0xFFFF
152
153/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
154 HERMES_MAX_MULTICAST : 0)*/
155#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
156
157#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
158 | HERMES_EV_TX | HERMES_EV_TXEXC \
159 | HERMES_EV_WTERR | HERMES_EV_INFO \
David Kilroya94e8422009-02-04 23:05:44 +0000160 | HERMES_EV_INFDROP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Jeff Garzik7282d492006-09-13 14:30:00 -0400162static const struct ethtool_ops orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +0200163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165/* Data types */
166/********************************************************************/
167
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400168/* Beginning of the Tx descriptor, used in TxExc handling */
169struct hermes_txexc_data {
170 struct hermes_tx_descriptor desc;
Pavel Roskind133ae42005-09-23 04:18:06 -0400171 __le16 frame_ctl;
172 __le16 duration_id;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200173 u8 addr1[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174} __attribute__ ((packed));
175
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200176/* Rx frame header except compatibility 802.3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177struct hermes_rx_descriptor {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200178 /* Control */
Pavel Roskind133ae42005-09-23 04:18:06 -0400179 __le16 status;
180 __le32 time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 u8 silence;
182 u8 signal;
183 u8 rate;
184 u8 rxflow;
Pavel Roskind133ae42005-09-23 04:18:06 -0400185 __le32 reserved;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200186
187 /* 802.11 header */
Pavel Roskind133ae42005-09-23 04:18:06 -0400188 __le16 frame_ctl;
189 __le16 duration_id;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200190 u8 addr1[ETH_ALEN];
191 u8 addr2[ETH_ALEN];
192 u8 addr3[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400193 __le16 seq_ctl;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200194 u8 addr4[ETH_ALEN];
195
196 /* Data length */
Pavel Roskind133ae42005-09-23 04:18:06 -0400197 __le16 data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198} __attribute__ ((packed));
199
David Kilroy47166792009-01-07 00:43:54 +0000200struct orinoco_rx_data {
201 struct hermes_rx_descriptor *desc;
202 struct sk_buff *skb;
203 struct list_head list;
204};
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/********************************************************************/
207/* Function prototypes */
208/********************************************************************/
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static void __orinoco_set_multicast_list(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212/********************************************************************/
213/* Internal helper functions */
214/********************************************************************/
215
David Kilroycb1576a2009-02-04 23:05:56 +0000216void set_port_type(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
218 switch (priv->iw_mode) {
219 case IW_MODE_INFRA:
220 priv->port_type = 1;
221 priv->createibss = 0;
222 break;
223 case IW_MODE_ADHOC:
224 if (priv->prefer_port3) {
225 priv->port_type = 3;
226 priv->createibss = 0;
227 } else {
228 priv->port_type = priv->ibss_port;
229 priv->createibss = 1;
230 }
231 break;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200232 case IW_MODE_MONITOR:
233 priv->port_type = 3;
234 priv->createibss = 0;
235 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 default:
237 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
238 priv->ndev->name);
239 }
240}
241
David Kilroy3994d502008-08-21 23:27:54 +0100242/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243/* Device methods */
244/********************************************************************/
245
246static int orinoco_open(struct net_device *dev)
247{
248 struct orinoco_private *priv = netdev_priv(dev);
249 unsigned long flags;
250 int err;
251
252 if (orinoco_lock(priv, &flags) != 0)
253 return -EBUSY;
254
David Kilroya2608362009-06-18 23:21:23 +0100255 err = __orinoco_up(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
David Kilroya94e8422009-02-04 23:05:44 +0000257 if (!err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 priv->open = 1;
259
260 orinoco_unlock(priv, &flags);
261
262 return err;
263}
264
Christoph Hellwigad8f4512005-05-14 17:30:17 +0200265static int orinoco_stop(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
267 struct orinoco_private *priv = netdev_priv(dev);
268 int err = 0;
269
270 /* We mustn't use orinoco_lock() here, because we need to be
271 able to close the interface even if hw_unavailable is set
272 (e.g. as we're released after a PC Card removal) */
273 spin_lock_irq(&priv->lock);
274
275 priv->open = 0;
276
David Kilroya2608362009-06-18 23:21:23 +0100277 err = __orinoco_down(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 spin_unlock_irq(&priv->lock);
280
281 return err;
282}
283
284static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
285{
286 struct orinoco_private *priv = netdev_priv(dev);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 return &priv->stats;
289}
290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291static void orinoco_set_multicast_list(struct net_device *dev)
292{
293 struct orinoco_private *priv = netdev_priv(dev);
294 unsigned long flags;
295
296 if (orinoco_lock(priv, &flags) != 0) {
297 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
298 "called when hw_unavailable\n", dev->name);
299 return;
300 }
301
302 __orinoco_set_multicast_list(dev);
303 orinoco_unlock(priv, &flags);
304}
305
306static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
307{
308 struct orinoco_private *priv = netdev_priv(dev);
309
David Kilroya94e8422009-02-04 23:05:44 +0000310 if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 return -EINVAL;
312
Johannes Berg2c7060022008-10-30 22:09:54 +0100313 /* MTU + encapsulation + header length */
David Kilroya94e8422009-02-04 23:05:44 +0000314 if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
315 (priv->nicbuf_size - ETH_HLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return -EINVAL;
317
318 dev->mtu = new_mtu;
319
320 return 0;
321}
322
323/********************************************************************/
324/* Tx path */
325/********************************************************************/
326
327static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
328{
329 struct orinoco_private *priv = netdev_priv(dev);
330 struct net_device_stats *stats = &priv->stats;
331 hermes_t *hw = &priv->hw;
332 int err = 0;
333 u16 txfid = priv->txfid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 struct ethhdr *eh;
David Kilroy6eecad72008-08-21 23:27:56 +0100335 int tx_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 unsigned long flags;
337
David Kilroya94e8422009-02-04 23:05:44 +0000338 if (!netif_running(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 printk(KERN_ERR "%s: Tx on stopped device!\n",
340 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400341 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 if (netif_queue_stopped(dev)) {
David Kilroy6fe9deb2009-02-04 23:05:43 +0000345 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400347 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (orinoco_lock(priv, &flags) != 0) {
351 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
352 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400353 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
355
David Kilroya94e8422009-02-04 23:05:44 +0000356 if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 /* Oops, the firmware hasn't established a connection,
David Kilroy6fe9deb2009-02-04 23:05:43 +0000358 silently drop the packet (this seems to be the
359 safest approach). */
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400360 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362
Pavel Roskin8d5be082006-04-07 04:10:41 -0400363 /* Check packet length */
Pavel Roskina28dc812006-04-07 04:10:45 -0400364 if (skb->len < ETH_HLEN)
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400365 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
David Kilroy6eecad72008-08-21 23:27:56 +0100367 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
David Kilroy23edcc42008-08-21 23:28:05 +0100369 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
370 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
371 HERMES_TXCTRL_MIC;
372
David Kilroy6eecad72008-08-21 23:27:56 +0100373 if (priv->has_alt_txcntl) {
374 /* WPA enabled firmwares have tx_cntl at the end of
375 * the 802.11 header. So write zeroed descriptor and
376 * 802.11 header at the same time
377 */
378 char desc[HERMES_802_3_OFFSET];
379 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
380
381 memset(&desc, 0, sizeof(desc));
382
383 *txcntl = cpu_to_le16(tx_control);
384 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
385 txfid, 0);
386 if (err) {
387 if (net_ratelimit())
388 printk(KERN_ERR "%s: Error %d writing Tx "
389 "descriptor to BAP\n", dev->name, err);
390 goto busy;
391 }
392 } else {
393 struct hermes_tx_descriptor desc;
394
395 memset(&desc, 0, sizeof(desc));
396
397 desc.tx_control = cpu_to_le16(tx_control);
398 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
399 txfid, 0);
400 if (err) {
401 if (net_ratelimit())
402 printk(KERN_ERR "%s: Error %d writing Tx "
403 "descriptor to BAP\n", dev->name, err);
404 goto busy;
405 }
406
407 /* Clear the 802.11 header and data length fields - some
408 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
409 * if this isn't done. */
410 hermes_clear_words(hw, HERMES_DATA0,
411 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
David Kilroy23edcc42008-08-21 23:28:05 +0100414 eh = (struct ethhdr *)skb->data;
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 /* Encapsulate Ethernet-II frames */
417 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
Pavel Roskina28dc812006-04-07 04:10:45 -0400418 struct header_struct {
419 struct ethhdr eth; /* 802.3 header */
420 u8 encap[6]; /* 802.2 header */
421 } __attribute__ ((packed)) hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Pavel Roskina28dc812006-04-07 04:10:45 -0400423 /* Strip destination and source from the data */
424 skb_pull(skb, 2 * ETH_ALEN);
Pavel Roskina28dc812006-04-07 04:10:45 -0400425
426 /* And move them to a separate header */
427 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
428 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
429 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
430
David Kilroy23edcc42008-08-21 23:28:05 +0100431 /* Insert the SNAP header */
432 if (skb_headroom(skb) < sizeof(hdr)) {
433 printk(KERN_ERR
434 "%s: Not enough headroom for 802.2 headers %d\n",
435 dev->name, skb_headroom(skb));
436 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
David Kilroy23edcc42008-08-21 23:28:05 +0100438 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
439 memcpy(eh, &hdr, sizeof(hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 }
441
Pavel Roskina28dc812006-04-07 04:10:45 -0400442 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
David Kilroy23edcc42008-08-21 23:28:05 +0100443 txfid, HERMES_802_3_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 if (err) {
445 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
446 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400447 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 }
449
David Kilroy23edcc42008-08-21 23:28:05 +0100450 /* Calculate Michael MIC */
451 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
452 u8 mic_buf[MICHAEL_MIC_LEN + 1];
453 u8 *mic;
454 size_t offset;
455 size_t len;
456
457 if (skb->len % 2) {
458 /* MIC start is on an odd boundary */
459 mic_buf[0] = skb->data[skb->len - 1];
460 mic = &mic_buf[1];
461 offset = skb->len - 1;
462 len = MICHAEL_MIC_LEN + 1;
463 } else {
464 mic = &mic_buf[0];
465 offset = skb->len;
466 len = MICHAEL_MIC_LEN;
467 }
468
David Kilroy4adb4742009-02-04 23:05:51 +0000469 orinoco_mic(priv->tx_tfm_mic,
David Kilroy23edcc42008-08-21 23:28:05 +0100470 priv->tkip_key[priv->tx_key].tx_mic,
471 eh->h_dest, eh->h_source, 0 /* priority */,
472 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
473
474 /* Write the MIC */
475 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
476 txfid, HERMES_802_3_OFFSET + offset);
477 if (err) {
478 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
479 dev->name, err);
480 goto busy;
481 }
482 }
483
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 /* Finally, we actually initiate the send */
485 netif_stop_queue(dev);
486
487 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
488 txfid, NULL);
489 if (err) {
490 netif_start_queue(dev);
Andrew Mortonc367c212005-10-19 21:23:44 -0700491 if (net_ratelimit())
492 printk(KERN_ERR "%s: Error %d transmitting packet\n",
493 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400494 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
496
497 dev->trans_start = jiffies;
David Kilroy23edcc42008-08-21 23:28:05 +0100498 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400499 goto ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400501 drop:
502 stats->tx_errors++;
503 stats->tx_dropped++;
504
505 ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 dev_kfree_skb(skb);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400508 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400510 busy:
Jiri Benc2c1bd262006-04-07 04:10:47 -0400511 if (err == -EIO)
512 schedule_work(&priv->reset_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 orinoco_unlock(priv, &flags);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400514 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515}
516
517static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
518{
519 struct orinoco_private *priv = netdev_priv(dev);
520 u16 fid = hermes_read_regn(hw, ALLOCFID);
521
522 if (fid != priv->txfid) {
523 if (fid != DUMMY_FID)
524 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
525 dev->name, fid);
526 return;
527 }
528
529 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
530}
531
532static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
533{
534 struct orinoco_private *priv = netdev_priv(dev);
535 struct net_device_stats *stats = &priv->stats;
536
537 stats->tx_packets++;
538
539 netif_wake_queue(dev);
540
541 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
542}
543
544static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
545{
546 struct orinoco_private *priv = netdev_priv(dev);
547 struct net_device_stats *stats = &priv->stats;
548 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -0400549 u16 status;
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400550 struct hermes_txexc_data hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 int err = 0;
552
553 if (fid == DUMMY_FID)
554 return; /* Nothing's really happened */
555
Pavel Roskin48ca7032005-09-23 04:18:06 -0400556 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200557 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400558 sizeof(struct hermes_txexc_data),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200559 fid, 0);
560
561 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
562 stats->tx_errors++;
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 if (err) {
565 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
566 "(FID=%04X error %d)\n",
567 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200568 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000570
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200571 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
572 err, fid);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000573
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200574 /* We produce a TXDROP event only for retry or lifetime
575 * exceeded, because that's the only status that really mean
576 * that this particular node went away.
577 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400578 status = le16_to_cpu(hdr.desc.status);
Pavel Roskind133ae42005-09-23 04:18:06 -0400579 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200580 union iwreq_data wrqu;
581
582 /* Copy 802.11 dest address.
583 * We use the 802.11 header because the frame may
584 * not be 802.3 or may be mangled...
585 * In Ad-Hoc mode, it will be the node address.
586 * In managed mode, it will be most likely the AP addr
587 * User space will figure out how to convert it to
588 * whatever it needs (IP address or else).
589 * - Jean II */
590 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
591 wrqu.addr.sa_family = ARPHRD_ETHER;
592
593 /* Send event to user space */
594 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599
600static void orinoco_tx_timeout(struct net_device *dev)
601{
602 struct orinoco_private *priv = netdev_priv(dev);
603 struct net_device_stats *stats = &priv->stats;
604 struct hermes *hw = &priv->hw;
605
606 printk(KERN_WARNING "%s: Tx timeout! "
607 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
608 dev->name, hermes_read_regn(hw, ALLOCFID),
609 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
610
611 stats->tx_errors++;
612
613 schedule_work(&priv->reset_work);
614}
615
616/********************************************************************/
617/* Rx path (data frames) */
618/********************************************************************/
619
620/* Does the frame have a SNAP header indicating it should be
621 * de-encapsulated to Ethernet-II? */
622static inline int is_ethersnap(void *_hdr)
623{
624 u8 *hdr = _hdr;
625
626 /* We de-encapsulate all packets which, a) have SNAP headers
627 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
628 * and where b) the OUI of the SNAP header is 00:00:00 or
629 * 00:00:f8 - we need both because different APs appear to use
630 * different OUIs for some reason */
631 return (memcmp(hdr, &encaps_hdr, 5) == 0)
David Kilroya94e8422009-02-04 23:05:44 +0000632 && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633}
634
635static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
636 int level, int noise)
637{
Pavel Roskin343c6862005-09-09 18:43:02 -0400638 struct iw_quality wstats;
639 wstats.level = level - 0x95;
640 wstats.noise = noise - 0x95;
641 wstats.qual = (level > noise) ? (level - noise) : 0;
Andrey Borzenkovf941f852008-11-15 17:15:09 +0300642 wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
Pavel Roskin343c6862005-09-09 18:43:02 -0400643 /* Update spy records */
644 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645}
646
647static void orinoco_stat_gather(struct net_device *dev,
648 struct sk_buff *skb,
649 struct hermes_rx_descriptor *desc)
650{
651 struct orinoco_private *priv = netdev_priv(dev);
652
653 /* Using spy support with lots of Rx packets, like in an
654 * infrastructure (AP), will really slow down everything, because
655 * the MAC address must be compared to each entry of the spy list.
656 * If the user really asks for it (set some address in the
657 * spy list), we do it, but he will pay the price.
658 * Note that to get here, you need both WIRELESS_SPY
659 * compiled in AND some addresses in the list !!!
660 */
661 /* Note : gcc will optimise the whole section away if
662 * WIRELESS_SPY is not defined... - Jean II */
663 if (SPY_NUMBER(priv)) {
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -0700664 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 desc->signal, desc->silence);
666 }
667}
668
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200669/*
670 * orinoco_rx_monitor - handle received monitor frames.
671 *
672 * Arguments:
673 * dev network device
674 * rxfid received FID
675 * desc rx descriptor of the frame
676 *
677 * Call context: interrupt
678 */
679static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
680 struct hermes_rx_descriptor *desc)
681{
682 u32 hdrlen = 30; /* return full header by default */
683 u32 datalen = 0;
684 u16 fc;
685 int err;
686 int len;
687 struct sk_buff *skb;
688 struct orinoco_private *priv = netdev_priv(dev);
689 struct net_device_stats *stats = &priv->stats;
690 hermes_t *hw = &priv->hw;
691
692 len = le16_to_cpu(desc->data_len);
693
694 /* Determine the size of the header and the data */
695 fc = le16_to_cpu(desc->frame_ctl);
696 switch (fc & IEEE80211_FCTL_FTYPE) {
697 case IEEE80211_FTYPE_DATA:
698 if ((fc & IEEE80211_FCTL_TODS)
699 && (fc & IEEE80211_FCTL_FROMDS))
700 hdrlen = 30;
701 else
702 hdrlen = 24;
703 datalen = len;
704 break;
705 case IEEE80211_FTYPE_MGMT:
706 hdrlen = 24;
707 datalen = len;
708 break;
709 case IEEE80211_FTYPE_CTL:
710 switch (fc & IEEE80211_FCTL_STYPE) {
711 case IEEE80211_STYPE_PSPOLL:
712 case IEEE80211_STYPE_RTS:
713 case IEEE80211_STYPE_CFEND:
714 case IEEE80211_STYPE_CFENDACK:
715 hdrlen = 16;
716 break;
717 case IEEE80211_STYPE_CTS:
718 case IEEE80211_STYPE_ACK:
719 hdrlen = 10;
720 break;
721 }
722 break;
723 default:
724 /* Unknown frame type */
725 break;
726 }
727
728 /* sanity check the length */
Johannes Berg2c7060022008-10-30 22:09:54 +0100729 if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200730 printk(KERN_DEBUG "%s: oversized monitor frame, "
731 "data length = %d\n", dev->name, datalen);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200732 stats->rx_length_errors++;
733 goto update_stats;
734 }
735
736 skb = dev_alloc_skb(hdrlen + datalen);
737 if (!skb) {
738 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
739 dev->name);
Florin Malitabb6e0932006-05-22 22:35:30 -0700740 goto update_stats;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200741 }
742
743 /* Copy the 802.11 header to the skb */
744 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700745 skb_reset_mac_header(skb);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200746
747 /* If any, copy the data from the card to the skb */
748 if (datalen > 0) {
749 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
750 ALIGN(datalen, 2), rxfid,
751 HERMES_802_2_OFFSET);
752 if (err) {
753 printk(KERN_ERR "%s: error %d reading monitor frame\n",
754 dev->name, err);
755 goto drop;
756 }
757 }
758
759 skb->dev = dev;
760 skb->ip_summed = CHECKSUM_NONE;
761 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800762 skb->protocol = cpu_to_be16(ETH_P_802_2);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000763
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200764 stats->rx_packets++;
765 stats->rx_bytes += skb->len;
766
767 netif_rx(skb);
768 return;
769
770 drop:
771 dev_kfree_skb_irq(skb);
772 update_stats:
773 stats->rx_errors++;
774 stats->rx_dropped++;
775}
776
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
778{
779 struct orinoco_private *priv = netdev_priv(dev);
780 struct net_device_stats *stats = &priv->stats;
781 struct iw_statistics *wstats = &priv->wstats;
782 struct sk_buff *skb = NULL;
David Kilroy31afcef2008-08-21 23:28:04 +0100783 u16 rxfid, status;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200784 int length;
David Kilroy31afcef2008-08-21 23:28:04 +0100785 struct hermes_rx_descriptor *desc;
786 struct orinoco_rx_data *rx_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 int err;
788
David Kilroy31afcef2008-08-21 23:28:04 +0100789 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
790 if (!desc) {
791 printk(KERN_WARNING
792 "%s: Can't allocate space for RX descriptor\n",
793 dev->name);
794 goto update_stats;
795 }
796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 rxfid = hermes_read_regn(hw, RXFID);
798
David Kilroy31afcef2008-08-21 23:28:04 +0100799 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 rxfid, 0);
801 if (err) {
802 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
803 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200804 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 }
806
David Kilroy31afcef2008-08-21 23:28:04 +0100807 status = le16_to_cpu(desc->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200809 if (status & HERMES_RXSTAT_BADCRC) {
810 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
811 dev->name);
812 stats->rx_crc_errors++;
813 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 }
815
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200816 /* Handle frames in monitor mode */
817 if (priv->iw_mode == IW_MODE_MONITOR) {
David Kilroy31afcef2008-08-21 23:28:04 +0100818 orinoco_rx_monitor(dev, rxfid, desc);
819 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 }
821
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200822 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
823 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
824 dev->name);
825 wstats->discard.code++;
826 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
828
David Kilroy31afcef2008-08-21 23:28:04 +0100829 length = le16_to_cpu(desc->data_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 /* Sanity checks */
832 if (length < 3) { /* No for even an 802.2 LLC header */
833 /* At least on Symbol firmware with PCF we get quite a
David Kilroy6fe9deb2009-02-04 23:05:43 +0000834 lot of these legitimately - Poll frames with no
835 data. */
David Kilroy31afcef2008-08-21 23:28:04 +0100836 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
Johannes Berg2c7060022008-10-30 22:09:54 +0100838 if (length > IEEE80211_MAX_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
840 dev->name, length);
841 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200842 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 }
844
David Kilroy23edcc42008-08-21 23:28:05 +0100845 /* Payload size does not include Michael MIC. Increase payload
846 * size to read it together with the data. */
847 if (status & HERMES_RXSTAT_MIC)
848 length += MICHAEL_MIC_LEN;
849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 /* We need space for the packet data itself, plus an ethernet
851 header, plus 2 bytes so we can align the IP header on a
852 32bit boundary, plus 1 byte so we can read in odd length
853 packets from the card, which has an IO granularity of 16
David Kilroy6fe9deb2009-02-04 23:05:43 +0000854 bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
856 if (!skb) {
857 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
858 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200859 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 }
861
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200862 /* We'll prepend the header, so reserve space for it. The worst
863 case is no decapsulation, when 802.3 header is prepended and
864 nothing is removed. 2 is for aligning the IP header. */
865 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200867 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
868 ALIGN(length, 2), rxfid,
869 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 if (err) {
871 printk(KERN_ERR "%s: error %d reading frame. "
872 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 goto drop;
874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
David Kilroy31afcef2008-08-21 23:28:04 +0100876 /* Add desc and skb to rx queue */
877 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
878 if (!rx_data) {
879 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
880 dev->name);
881 goto drop;
882 }
883 rx_data->desc = desc;
884 rx_data->skb = skb;
885 list_add_tail(&rx_data->list, &priv->rx_list);
886 tasklet_schedule(&priv->rx_tasklet);
887
888 return;
889
890drop:
891 dev_kfree_skb_irq(skb);
892update_stats:
893 stats->rx_errors++;
894 stats->rx_dropped++;
895out:
896 kfree(desc);
897}
898
899static void orinoco_rx(struct net_device *dev,
900 struct hermes_rx_descriptor *desc,
901 struct sk_buff *skb)
902{
903 struct orinoco_private *priv = netdev_priv(dev);
904 struct net_device_stats *stats = &priv->stats;
905 u16 status, fc;
906 int length;
907 struct ethhdr *hdr;
908
909 status = le16_to_cpu(desc->status);
910 length = le16_to_cpu(desc->data_len);
911 fc = le16_to_cpu(desc->frame_ctl);
912
David Kilroy23edcc42008-08-21 23:28:05 +0100913 /* Calculate and check MIC */
914 if (status & HERMES_RXSTAT_MIC) {
915 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
916 HERMES_MIC_KEY_ID_SHIFT);
917 u8 mic[MICHAEL_MIC_LEN];
918 u8 *rxmic;
919 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
920 desc->addr3 : desc->addr2;
921
922 /* Extract Michael MIC from payload */
923 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
924
925 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
926 length -= MICHAEL_MIC_LEN;
927
David Kilroy4adb4742009-02-04 23:05:51 +0000928 orinoco_mic(priv->rx_tfm_mic,
David Kilroy23edcc42008-08-21 23:28:05 +0100929 priv->tkip_key[key_id].rx_mic,
930 desc->addr1,
931 src,
932 0, /* priority or QoS? */
933 skb->data,
934 skb->len,
935 &mic[0]);
936
937 if (memcmp(mic, rxmic,
938 MICHAEL_MIC_LEN)) {
939 union iwreq_data wrqu;
940 struct iw_michaelmicfailure wxmic;
David Kilroy23edcc42008-08-21 23:28:05 +0100941
942 printk(KERN_WARNING "%s: "
Johannes Berge1749612008-10-27 15:59:26 -0700943 "Invalid Michael MIC in data frame from %pM, "
David Kilroy23edcc42008-08-21 23:28:05 +0100944 "using key %i\n",
Johannes Berge1749612008-10-27 15:59:26 -0700945 dev->name, src, key_id);
David Kilroy23edcc42008-08-21 23:28:05 +0100946
947 /* TODO: update stats */
948
949 /* Notify userspace */
950 memset(&wxmic, 0, sizeof(wxmic));
951 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
952 wxmic.flags |= (desc->addr1[0] & 1) ?
953 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
954 wxmic.src_addr.sa_family = ARPHRD_ETHER;
955 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
956
957 (void) orinoco_hw_get_tkip_iv(priv, key_id,
958 &wxmic.tsc[0]);
959
960 memset(&wrqu, 0, sizeof(wrqu));
961 wrqu.data.length = sizeof(wxmic);
962 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
963 (char *) &wxmic);
964
965 goto drop;
966 }
967 }
968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 /* Handle decapsulation
970 * In most cases, the firmware tell us about SNAP frames.
971 * For some reason, the SNAP frames sent by LinkSys APs
972 * are not properly recognised by most firmwares.
973 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200974 if (length >= ENCAPS_OVERHEAD &&
975 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
976 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
977 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 /* These indicate a SNAP within 802.2 LLC within
979 802.11 frame which we'll need to de-encapsulate to
980 the original EthernetII frame. */
David Kilroyb2f30a02009-02-04 23:05:46 +0000981 hdr = (struct ethhdr *)skb_push(skb,
982 ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200984 /* 802.3 frame - prepend 802.3 header as is */
985 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
986 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 }
David Kilroy31afcef2008-08-21 23:28:04 +0100988 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200989 if (fc & IEEE80211_FCTL_FROMDS)
David Kilroy31afcef2008-08-21 23:28:04 +0100990 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200991 else
David Kilroy31afcef2008-08-21 23:28:04 +0100992 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 skb->protocol = eth_type_trans(skb, dev);
995 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200996 if (fc & IEEE80211_FCTL_TODS)
997 skb->pkt_type = PACKET_OTHERHOST;
David Kilroy6fe9deb2009-02-04 23:05:43 +0000998
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 /* Process the wireless stats if needed */
David Kilroy31afcef2008-08-21 23:28:04 +01001000 orinoco_stat_gather(dev, skb, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 /* Pass the packet to the networking stack */
1003 netif_rx(skb);
1004 stats->rx_packets++;
1005 stats->rx_bytes += length;
1006
1007 return;
David Kilroy23edcc42008-08-21 23:28:05 +01001008
1009 drop:
1010 dev_kfree_skb(skb);
1011 stats->rx_errors++;
1012 stats->rx_dropped++;
David Kilroy31afcef2008-08-21 23:28:04 +01001013}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
David Kilroy31afcef2008-08-21 23:28:04 +01001015static void orinoco_rx_isr_tasklet(unsigned long data)
1016{
1017 struct net_device *dev = (struct net_device *) data;
1018 struct orinoco_private *priv = netdev_priv(dev);
1019 struct orinoco_rx_data *rx_data, *temp;
1020 struct hermes_rx_descriptor *desc;
1021 struct sk_buff *skb;
David Kilroy20953ad2009-01-07 00:23:55 +00001022 unsigned long flags;
1023
1024 /* orinoco_rx requires the driver lock, and we also need to
1025 * protect priv->rx_list, so just hold the lock over the
1026 * lot.
1027 *
1028 * If orinoco_lock fails, we've unplugged the card. In this
1029 * case just abort. */
1030 if (orinoco_lock(priv, &flags) != 0)
1031 return;
David Kilroy31afcef2008-08-21 23:28:04 +01001032
1033 /* extract desc and skb from queue */
1034 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1035 desc = rx_data->desc;
1036 skb = rx_data->skb;
1037 list_del(&rx_data->list);
1038 kfree(rx_data);
1039
1040 orinoco_rx(dev, desc, skb);
1041
1042 kfree(desc);
1043 }
David Kilroy20953ad2009-01-07 00:23:55 +00001044
1045 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046}
1047
1048/********************************************************************/
1049/* Rx path (info frames) */
1050/********************************************************************/
1051
1052static void print_linkstatus(struct net_device *dev, u16 status)
1053{
David Kilroy21312662009-02-04 23:05:47 +00001054 char *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
1056 if (suppress_linkstatus)
1057 return;
1058
1059 switch (status) {
1060 case HERMES_LINKSTATUS_NOT_CONNECTED:
1061 s = "Not Connected";
1062 break;
1063 case HERMES_LINKSTATUS_CONNECTED:
1064 s = "Connected";
1065 break;
1066 case HERMES_LINKSTATUS_DISCONNECTED:
1067 s = "Disconnected";
1068 break;
1069 case HERMES_LINKSTATUS_AP_CHANGE:
1070 s = "AP Changed";
1071 break;
1072 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1073 s = "AP Out of Range";
1074 break;
1075 case HERMES_LINKSTATUS_AP_IN_RANGE:
1076 s = "AP In Range";
1077 break;
1078 case HERMES_LINKSTATUS_ASSOC_FAILED:
1079 s = "Association Failed";
1080 break;
1081 default:
1082 s = "UNKNOWN";
1083 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001084
Pavel Roskin11eaea42009-01-18 23:20:58 -05001085 printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 dev->name, s, status);
1087}
1088
Christoph Hellwig16739b02005-06-19 01:27:51 +02001089/* Search scan results for requested BSSID, join it if found */
David Howellsc4028952006-11-22 14:57:56 +00001090static void orinoco_join_ap(struct work_struct *work)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001091{
David Howellsc4028952006-11-22 14:57:56 +00001092 struct orinoco_private *priv =
1093 container_of(work, struct orinoco_private, join_work);
1094 struct net_device *dev = priv->ndev;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001095 struct hermes *hw = &priv->hw;
1096 int err;
1097 unsigned long flags;
1098 struct join_req {
1099 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -04001100 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001101 } __attribute__ ((packed)) req;
1102 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001103 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001104 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -04001105 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001106 u8 *buf;
1107 u16 len;
1108
1109 /* Allocate buffer for scan results */
1110 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
David Kilroya94e8422009-02-04 23:05:44 +00001111 if (!buf)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001112 return;
1113
1114 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001115 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001116
1117 /* Sanity checks in case user changed something in the meantime */
David Kilroya94e8422009-02-04 23:05:44 +00001118 if (!priv->bssid_fixed)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001119 goto out;
1120
1121 if (strlen(priv->desired_essid) == 0)
1122 goto out;
1123
1124 /* Read scan results from the firmware */
1125 err = hermes_read_ltv(hw, USER_BAP,
1126 HERMES_RID_SCANRESULTSTABLE,
1127 MAX_SCAN_LEN, &len, buf);
1128 if (err) {
1129 printk(KERN_ERR "%s: Cannot read scan results\n",
1130 dev->name);
1131 goto out;
1132 }
1133
1134 len = HERMES_RECLEN_TO_BYTES(len);
1135
1136 /* Go through the scan results looking for the channel of the AP
1137 * we were requested to join */
1138 for (; offset + atom_len <= len; offset += atom_len) {
1139 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001140 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1141 found = 1;
1142 break;
1143 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001144 }
1145
David Kilroya94e8422009-02-04 23:05:44 +00001146 if (!found) {
Pavel Roskinc89cc222005-09-01 20:06:06 -04001147 DEBUG(1, "%s: Requested AP not found in scan results\n",
1148 dev->name);
1149 goto out;
1150 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001151
Christoph Hellwig16739b02005-06-19 01:27:51 +02001152 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1153 req.channel = atom->channel; /* both are little-endian */
1154 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1155 &req);
1156 if (err)
1157 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1158
1159 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001160 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001161
1162 fail_lock:
1163 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001164}
1165
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001166/* Send new BSSID to userspace */
David Kilroy6cd90b12008-08-21 23:28:00 +01001167static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001168{
David Howellsc4028952006-11-22 14:57:56 +00001169 struct net_device *dev = priv->ndev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001170 struct hermes *hw = &priv->hw;
1171 union iwreq_data wrqu;
1172 int err;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001173
David Kilroy499b7022008-12-09 21:46:29 +00001174 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001175 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1176 if (err != 0)
David Kilroy6cd90b12008-08-21 23:28:00 +01001177 return;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001178
1179 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1180
1181 /* Send event to user space */
1182 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001183}
1184
David Kilroy06009fd2008-08-21 23:28:03 +01001185static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1186{
1187 struct net_device *dev = priv->ndev;
1188 struct hermes *hw = &priv->hw;
1189 union iwreq_data wrqu;
1190 int err;
1191 u8 buf[88];
1192 u8 *ie;
1193
1194 if (!priv->has_wpa)
1195 return;
1196
David Kilroy499b7022008-12-09 21:46:29 +00001197 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
David Kilroy06009fd2008-08-21 23:28:03 +01001198 sizeof(buf), NULL, &buf);
1199 if (err != 0)
1200 return;
1201
1202 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1203 if (ie) {
1204 int rem = sizeof(buf) - (ie - &buf[0]);
1205 wrqu.data.length = ie[1] + 2;
1206 if (wrqu.data.length > rem)
1207 wrqu.data.length = rem;
1208
1209 if (wrqu.data.length)
1210 /* Send event to user space */
1211 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1212 }
1213}
1214
1215static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1216{
1217 struct net_device *dev = priv->ndev;
1218 struct hermes *hw = &priv->hw;
1219 union iwreq_data wrqu;
1220 int err;
1221 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1222 u8 *ie;
1223
1224 if (!priv->has_wpa)
1225 return;
1226
David Kilroy499b7022008-12-09 21:46:29 +00001227 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
David Kilroy06009fd2008-08-21 23:28:03 +01001228 sizeof(buf), NULL, &buf);
1229 if (err != 0)
1230 return;
1231
1232 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1233 if (ie) {
1234 int rem = sizeof(buf) - (ie - &buf[0]);
1235 wrqu.data.length = ie[1] + 2;
1236 if (wrqu.data.length > rem)
1237 wrqu.data.length = rem;
1238
1239 if (wrqu.data.length)
1240 /* Send event to user space */
1241 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1242 }
1243}
1244
David Kilroy6cd90b12008-08-21 23:28:00 +01001245static void orinoco_send_wevents(struct work_struct *work)
1246{
1247 struct orinoco_private *priv =
1248 container_of(work, struct orinoco_private, wevent_work);
1249 unsigned long flags;
1250
1251 if (orinoco_lock(priv, &flags) != 0)
1252 return;
1253
David Kilroy06009fd2008-08-21 23:28:03 +01001254 orinoco_send_assocreqie_wevent(priv);
1255 orinoco_send_assocrespie_wevent(priv);
David Kilroy6cd90b12008-08-21 23:28:00 +01001256 orinoco_send_bssid_wevent(priv);
1257
1258 orinoco_unlock(priv, &flags);
1259}
Dan Williams1e3428e2007-10-10 23:56:25 -04001260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1262{
1263 struct orinoco_private *priv = netdev_priv(dev);
1264 u16 infofid;
1265 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001266 __le16 len;
1267 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 } __attribute__ ((packed)) info;
1269 int len, type;
1270 int err;
1271
1272 /* This is an answer to an INQUIRE command that we did earlier,
1273 * or an information "event" generated by the card
1274 * The controller return to us a pseudo frame containing
1275 * the information in question - Jean II */
1276 infofid = hermes_read_regn(hw, INFOFID);
1277
1278 /* Read the info frame header - don't try too hard */
1279 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1280 infofid, 0);
1281 if (err) {
1282 printk(KERN_ERR "%s: error %d reading info frame. "
1283 "Frame dropped.\n", dev->name, err);
1284 return;
1285 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1288 type = le16_to_cpu(info.type);
1289
1290 switch (type) {
1291 case HERMES_INQ_TALLIES: {
1292 struct hermes_tallies_frame tallies;
1293 struct iw_statistics *wstats = &priv->wstats;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 if (len > sizeof(tallies)) {
1296 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1297 dev->name, len);
1298 len = sizeof(tallies);
1299 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001300
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001301 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1302 infofid, sizeof(info));
1303 if (err)
1304 break;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 /* Increment our various counters */
1307 /* wstats->discard.nwid - no wrong BSSID stuff */
1308 wstats->discard.code +=
1309 le16_to_cpu(tallies.RxWEPUndecryptable);
David Kilroy6fe9deb2009-02-04 23:05:43 +00001310 if (len == sizeof(tallies))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 wstats->discard.code +=
1312 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1313 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1314 wstats->discard.misc +=
1315 le16_to_cpu(tallies.TxDiscardsWrongSA);
1316 wstats->discard.fragment +=
1317 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1318 wstats->discard.retries +=
1319 le16_to_cpu(tallies.TxRetryLimitExceeded);
1320 /* wstats->miss.beacon - no match */
1321 }
1322 break;
1323 case HERMES_INQ_LINKSTATUS: {
1324 struct hermes_linkstatus linkstatus;
1325 u16 newstatus;
1326 int connected;
1327
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001328 if (priv->iw_mode == IW_MODE_MONITOR)
1329 break;
1330
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 if (len != sizeof(linkstatus)) {
1332 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1333 dev->name, len);
1334 break;
1335 }
1336
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001337 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1338 infofid, sizeof(info));
1339 if (err)
1340 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 newstatus = le16_to_cpu(linkstatus.linkstatus);
1342
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001343 /* Symbol firmware uses "out of range" to signal that
1344 * the hostscan frame can be requested. */
1345 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1346 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1347 priv->has_hostscan && priv->scan_inprogress) {
1348 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1349 break;
1350 }
1351
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1353 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1354 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1355
1356 if (connected)
1357 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001358 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 netif_carrier_off(dev);
1360
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001361 if (newstatus != priv->last_linkstatus) {
1362 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001364 /* The info frame contains only one word which is the
1365 * status (see hermes.h). The status is pretty boring
1366 * in itself, that's why we export the new BSSID...
1367 * Jean II */
1368 schedule_work(&priv->wevent_work);
1369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 }
1371 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001372 case HERMES_INQ_SCAN:
1373 if (!priv->scan_inprogress && priv->bssid_fixed &&
1374 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1375 schedule_work(&priv->join_work);
1376 break;
1377 }
1378 /* fall through */
1379 case HERMES_INQ_HOSTSCAN:
1380 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1381 /* Result of a scanning. Contains information about
1382 * cells in the vicinity - Jean II */
1383 union iwreq_data wrqu;
1384 unsigned char *buf;
1385
Dan Williams1e3428e2007-10-10 23:56:25 -04001386 /* Scan is no longer in progress */
1387 priv->scan_inprogress = 0;
1388
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001389 /* Sanity check */
1390 if (len > 4096) {
1391 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1392 dev->name, len);
1393 break;
1394 }
1395
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001396 /* Allocate buffer for results */
1397 buf = kmalloc(len, GFP_ATOMIC);
1398 if (buf == NULL)
1399 /* No memory, so can't printk()... */
1400 break;
1401
1402 /* Read scan data */
1403 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1404 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04001405 if (err) {
1406 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001407 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04001408 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001409
1410#ifdef ORINOCO_DEBUG
1411 {
1412 int i;
1413 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
David Kilroya94e8422009-02-04 23:05:44 +00001414 for (i = 1; i < (len * 2); i++)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001415 printk(":%02X", buf[i]);
1416 printk("]\n");
1417 }
1418#endif /* ORINOCO_DEBUG */
1419
David Kilroyaea48b12009-02-04 23:05:49 +00001420 if (orinoco_process_scan_results(priv, buf, len) == 0) {
Dan Williams1e3428e2007-10-10 23:56:25 -04001421 /* Send an empty event to user space.
1422 * We don't send the received data on the event because
1423 * it would require us to do complex transcoding, and
1424 * we want to minimise the work done in the irq handler
1425 * Use a request to extract the data - Jean II */
1426 wrqu.data.length = 0;
1427 wrqu.data.flags = 0;
1428 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1429 }
1430 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001431 }
1432 break;
David Kilroy01632fa2008-08-21 23:27:58 +01001433 case HERMES_INQ_CHANNELINFO:
1434 {
1435 struct agere_ext_scan_info *bss;
1436
1437 if (!priv->scan_inprogress) {
1438 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
1439 "len=%d\n", dev->name, len);
1440 break;
1441 }
1442
1443 /* An empty result indicates that the scan is complete */
1444 if (len == 0) {
1445 union iwreq_data wrqu;
1446
1447 /* Scan is no longer in progress */
1448 priv->scan_inprogress = 0;
1449
1450 wrqu.data.length = 0;
1451 wrqu.data.flags = 0;
1452 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1453 break;
1454 }
1455
1456 /* Sanity check */
1457 else if (len > sizeof(*bss)) {
1458 printk(KERN_WARNING
1459 "%s: Ext scan results too large (%d bytes). "
1460 "Truncating results to %zd bytes.\n",
1461 dev->name, len, sizeof(*bss));
1462 len = sizeof(*bss);
1463 } else if (len < (offsetof(struct agere_ext_scan_info,
1464 data) + 2)) {
1465 /* Drop this result now so we don't have to
1466 * keep checking later */
1467 printk(KERN_WARNING
1468 "%s: Ext scan results too short (%d bytes)\n",
1469 dev->name, len);
1470 break;
1471 }
1472
1473 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
1474 if (bss == NULL)
1475 break;
1476
1477 /* Read scan data */
1478 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
1479 infofid, sizeof(info));
1480 if (err) {
1481 kfree(bss);
1482 break;
1483 }
1484
1485 orinoco_add_ext_scan_result(priv, bss);
1486
1487 kfree(bss);
1488 break;
1489 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001490 case HERMES_INQ_SEC_STAT_AGERE:
1491 /* Security status (Agere specific) */
1492 /* Ignore this frame for now */
1493 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1494 break;
1495 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 default:
1497 printk(KERN_DEBUG "%s: Unknown information frame received: "
1498 "type 0x%04x, length %d\n", dev->name, type, len);
1499 /* We don't actually do anything about it */
1500 break;
1501 }
1502}
1503
1504static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1505{
1506 if (net_ratelimit())
1507 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1508}
1509
1510/********************************************************************/
1511/* Internal hardware control routines */
1512/********************************************************************/
1513
David Kilroya2608362009-06-18 23:21:23 +01001514int __orinoco_up(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
David Kilroya2608362009-06-18 23:21:23 +01001516 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 struct hermes *hw = &priv->hw;
1518 int err;
1519
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001520 netif_carrier_off(dev); /* just to make sure */
1521
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 err = __orinoco_program_rids(dev);
1523 if (err) {
1524 printk(KERN_ERR "%s: Error %d configuring card\n",
1525 dev->name, err);
1526 return err;
1527 }
1528
1529 /* Fire things up again */
1530 hermes_set_irqmask(hw, ORINOCO_INTEN);
1531 err = hermes_enable_port(hw, 0);
1532 if (err) {
1533 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1534 dev->name, err);
1535 return err;
1536 }
1537
1538 netif_start_queue(dev);
1539
1540 return 0;
1541}
David Kilroy21312662009-02-04 23:05:47 +00001542EXPORT_SYMBOL(__orinoco_up);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
David Kilroya2608362009-06-18 23:21:23 +01001544int __orinoco_down(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
David Kilroya2608362009-06-18 23:21:23 +01001546 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 struct hermes *hw = &priv->hw;
1548 int err;
1549
1550 netif_stop_queue(dev);
1551
David Kilroya94e8422009-02-04 23:05:44 +00001552 if (!priv->hw_unavailable) {
1553 if (!priv->broken_disableport) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 err = hermes_disable_port(hw, 0);
1555 if (err) {
1556 /* Some firmwares (e.g. Intersil 1.3.x) seem
1557 * to have problems disabling the port, oh
1558 * well, too bad. */
1559 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1560 dev->name, err);
1561 priv->broken_disableport = 1;
1562 }
1563 }
1564 hermes_set_irqmask(hw, 0);
1565 hermes_write_regn(hw, EVACK, 0xffff);
1566 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001567
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 /* firmware will have to reassociate */
1569 netif_carrier_off(dev);
1570 priv->last_linkstatus = 0xffff;
1571
1572 return 0;
1573}
David Kilroy21312662009-02-04 23:05:47 +00001574EXPORT_SYMBOL(__orinoco_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
David Kilroya2608362009-06-18 23:21:23 +01001576int orinoco_reinit_firmware(struct orinoco_private *priv)
Pavel Roskin37a6c612006-04-07 04:10:49 -04001577{
Pavel Roskin37a6c612006-04-07 04:10:49 -04001578 struct hermes *hw = &priv->hw;
1579 int err;
1580
1581 err = hermes_init(hw);
Andrey Borzenkov0df6cbb2008-10-12 20:15:43 +04001582 if (priv->do_fw_download && !err) {
1583 err = orinoco_download(priv);
1584 if (err)
1585 priv->do_fw_download = 0;
1586 }
Pavel Roskin37a6c612006-04-07 04:10:49 -04001587 if (!err)
David Kilroy42a51b92009-06-18 23:21:20 +01001588 err = orinoco_hw_allocate_fid(priv);
Pavel Roskin37a6c612006-04-07 04:10:49 -04001589
1590 return err;
1591}
David Kilroy21312662009-02-04 23:05:47 +00001592EXPORT_SYMBOL(orinoco_reinit_firmware);
Pavel Roskin37a6c612006-04-07 04:10:49 -04001593
David Kilroycb1576a2009-02-04 23:05:56 +00001594int __orinoco_program_rids(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595{
1596 struct orinoco_private *priv = netdev_priv(dev);
1597 hermes_t *hw = &priv->hw;
1598 int err;
1599 struct hermes_idstring idbuf;
1600
1601 /* Set the MAC address */
1602 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1603 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1604 if (err) {
1605 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1606 dev->name, err);
1607 return err;
1608 }
1609
1610 /* Set up the link mode */
1611 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1612 priv->port_type);
1613 if (err) {
1614 printk(KERN_ERR "%s: Error %d setting port type\n",
1615 dev->name, err);
1616 return err;
1617 }
1618 /* Set the channel/frequency */
David Gibsond51d8b12005-05-12 20:03:36 -04001619 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1620 err = hermes_write_wordrec(hw, USER_BAP,
1621 HERMES_RID_CNFOWNCHANNEL,
1622 priv->channel);
1623 if (err) {
1624 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1625 dev->name, err, priv->channel);
1626 return err;
1627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 }
1629
1630 if (priv->has_ibss) {
1631 u16 createibss;
1632
1633 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1634 printk(KERN_WARNING "%s: This firmware requires an "
1635 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1636 /* With wvlan_cs, in this case, we would crash.
1637 * hopefully, this driver will behave better...
1638 * Jean II */
1639 createibss = 0;
1640 } else {
1641 createibss = priv->createibss;
1642 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 err = hermes_write_wordrec(hw, USER_BAP,
1645 HERMES_RID_CNFCREATEIBSS,
1646 createibss);
1647 if (err) {
1648 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1649 dev->name, err);
1650 return err;
1651 }
1652 }
1653
Christoph Hellwig16739b02005-06-19 01:27:51 +02001654 /* Set the desired BSSID */
1655 err = __orinoco_hw_set_wap(priv);
1656 if (err) {
1657 printk(KERN_ERR "%s: Error %d setting AP address\n",
1658 dev->name, err);
1659 return err;
1660 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 /* Set the desired ESSID */
1662 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1663 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1664 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1665 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
David Kilroyb2f30a02009-02-04 23:05:46 +00001666 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1667 &idbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 if (err) {
1669 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1670 dev->name, err);
1671 return err;
1672 }
1673 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
David Kilroyb2f30a02009-02-04 23:05:46 +00001674 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1675 &idbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 if (err) {
1677 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1678 dev->name, err);
1679 return err;
1680 }
1681
1682 /* Set the station name */
1683 idbuf.len = cpu_to_le16(strlen(priv->nick));
1684 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1685 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1686 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1687 &idbuf);
1688 if (err) {
1689 printk(KERN_ERR "%s: Error %d setting nickname\n",
1690 dev->name, err);
1691 return err;
1692 }
1693
1694 /* Set AP density */
1695 if (priv->has_sensitivity) {
1696 err = hermes_write_wordrec(hw, USER_BAP,
1697 HERMES_RID_CNFSYSTEMSCALE,
1698 priv->ap_density);
1699 if (err) {
David Kilroyb2f30a02009-02-04 23:05:46 +00001700 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 "Disabling sensitivity control\n",
1702 dev->name, err);
1703
1704 priv->has_sensitivity = 0;
1705 }
1706 }
1707
1708 /* Set RTS threshold */
1709 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1710 priv->rts_thresh);
1711 if (err) {
1712 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1713 dev->name, err);
1714 return err;
1715 }
1716
1717 /* Set fragmentation threshold or MWO robustness */
1718 if (priv->has_mwo)
1719 err = hermes_write_wordrec(hw, USER_BAP,
1720 HERMES_RID_CNFMWOROBUST_AGERE,
1721 priv->mwo_robust);
1722 else
1723 err = hermes_write_wordrec(hw, USER_BAP,
1724 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1725 priv->frag_thresh);
1726 if (err) {
1727 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1728 dev->name, err);
1729 return err;
1730 }
1731
1732 /* Set bitrate */
1733 err = __orinoco_hw_set_bitrate(priv);
1734 if (err) {
1735 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1736 dev->name, err);
1737 return err;
1738 }
1739
1740 /* Set power management */
1741 if (priv->has_pm) {
1742 err = hermes_write_wordrec(hw, USER_BAP,
1743 HERMES_RID_CNFPMENABLED,
1744 priv->pm_on);
1745 if (err) {
1746 printk(KERN_ERR "%s: Error %d setting up PM\n",
1747 dev->name, err);
1748 return err;
1749 }
1750
1751 err = hermes_write_wordrec(hw, USER_BAP,
1752 HERMES_RID_CNFMULTICASTRECEIVE,
1753 priv->pm_mcast);
1754 if (err) {
1755 printk(KERN_ERR "%s: Error %d setting up PM\n",
1756 dev->name, err);
1757 return err;
1758 }
1759 err = hermes_write_wordrec(hw, USER_BAP,
1760 HERMES_RID_CNFMAXSLEEPDURATION,
1761 priv->pm_period);
1762 if (err) {
1763 printk(KERN_ERR "%s: Error %d setting up PM\n",
1764 dev->name, err);
1765 return err;
1766 }
1767 err = hermes_write_wordrec(hw, USER_BAP,
1768 HERMES_RID_CNFPMHOLDOVERDURATION,
1769 priv->pm_timeout);
1770 if (err) {
1771 printk(KERN_ERR "%s: Error %d setting up PM\n",
1772 dev->name, err);
1773 return err;
1774 }
1775 }
1776
1777 /* Set preamble - only for Symbol so far... */
1778 if (priv->has_preamble) {
1779 err = hermes_write_wordrec(hw, USER_BAP,
1780 HERMES_RID_CNFPREAMBLE_SYMBOL,
1781 priv->preamble);
1782 if (err) {
1783 printk(KERN_ERR "%s: Error %d setting preamble\n",
1784 dev->name, err);
1785 return err;
1786 }
1787 }
1788
1789 /* Set up encryption */
David Kilroyd03032a2008-08-21 23:28:02 +01001790 if (priv->has_wep || priv->has_wpa) {
1791 err = __orinoco_hw_setup_enc(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 if (err) {
David Kilroyd03032a2008-08-21 23:28:02 +01001793 printk(KERN_ERR "%s: Error %d activating encryption\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 dev->name, err);
1795 return err;
1796 }
1797 }
1798
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001799 if (priv->iw_mode == IW_MODE_MONITOR) {
1800 /* Enable monitor mode */
1801 dev->type = ARPHRD_IEEE80211;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001802 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001803 HERMES_TEST_MONITOR, 0, NULL);
1804 } else {
1805 /* Disable monitor mode */
1806 dev->type = ARPHRD_ETHER;
1807 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1808 HERMES_TEST_STOP, 0, NULL);
1809 }
1810 if (err)
1811 return err;
1812
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 /* Set promiscuity / multicast*/
1814 priv->promiscuous = 0;
1815 priv->mc_count = 0;
Herbert Xu932ff272006-06-09 12:20:56 -07001816
1817 /* FIXME: what about netif_tx_lock */
1818 __orinoco_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
1820 return 0;
1821}
1822
David Kilroy5865d012009-02-04 23:05:54 +00001823/* FIXME: return int? */
1824static void
1825__orinoco_set_multicast_list(struct net_device *dev)
1826{
1827 struct orinoco_private *priv = netdev_priv(dev);
1828 int err = 0;
1829 int promisc, mc_count;
1830
1831 /* The Hermes doesn't seem to have an allmulti mode, so we go
1832 * into promiscuous mode and let the upper levels deal. */
1833 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1834 (dev->mc_count > MAX_MULTICAST(priv))) {
1835 promisc = 1;
1836 mc_count = 0;
1837 } else {
1838 promisc = 0;
1839 mc_count = dev->mc_count;
1840 }
1841
1842 err = __orinoco_hw_set_multicast_list(priv, dev->mc_list, mc_count,
1843 promisc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844}
1845
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846/* This must be called from user context, without locks held - use
1847 * schedule_work() */
David Kilroycb1576a2009-02-04 23:05:56 +00001848void orinoco_reset(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849{
David Howellsc4028952006-11-22 14:57:56 +00001850 struct orinoco_private *priv =
1851 container_of(work, struct orinoco_private, reset_work);
1852 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001854 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 unsigned long flags;
1856
1857 if (orinoco_lock(priv, &flags) != 0)
1858 /* When the hardware becomes available again, whatever
1859 * detects that is responsible for re-initializing
1860 * it. So no need for anything further */
1861 return;
1862
1863 netif_stop_queue(dev);
1864
1865 /* Shut off interrupts. Depending on what state the hardware
1866 * is in, this might not work, but we'll try anyway */
1867 hermes_set_irqmask(hw, 0);
1868 hermes_write_regn(hw, EVACK, 0xffff);
1869
1870 priv->hw_unavailable++;
1871 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1872 netif_carrier_off(dev);
1873
1874 orinoco_unlock(priv, &flags);
1875
David Kilroy6fe9deb2009-02-04 23:05:43 +00001876 /* Scanning support: Cleanup of driver struct */
Dan Williams1e3428e2007-10-10 23:56:25 -04001877 orinoco_clear_scan_results(priv, 0);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001878 priv->scan_inprogress = 0;
1879
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001880 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001882 if (err) {
1883 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1884 "performing hard reset\n", dev->name, err);
1885 goto disable;
1886 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 }
1888
David Kilroya2608362009-06-18 23:21:23 +01001889 err = orinoco_reinit_firmware(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 if (err) {
1891 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1892 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001893 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 }
1895
David Kilroyb2f30a02009-02-04 23:05:46 +00001896 /* This has to be called from user context */
1897 spin_lock_irq(&priv->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
1899 priv->hw_unavailable--;
1900
1901 /* priv->open or priv->hw_unavailable might have changed while
1902 * we dropped the lock */
David Kilroya94e8422009-02-04 23:05:44 +00001903 if (priv->open && (!priv->hw_unavailable)) {
David Kilroya2608362009-06-18 23:21:23 +01001904 err = __orinoco_up(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 if (err) {
1906 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1907 dev->name, err);
1908 } else
1909 dev->trans_start = jiffies;
1910 }
1911
1912 spin_unlock_irq(&priv->lock);
1913
1914 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001915 disable:
1916 hermes_set_irqmask(hw, 0);
1917 netif_device_detach(dev);
1918 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919}
1920
1921/********************************************************************/
1922/* Interrupt handler */
1923/********************************************************************/
1924
1925static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1926{
1927 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1928}
1929
1930static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1931{
1932 /* This seems to happen a fair bit under load, but ignoring it
1933 seems to work fine...*/
1934 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1935 dev->name);
1936}
1937
David Howells7d12e782006-10-05 14:55:46 +01001938irqreturn_t orinoco_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939{
David Kilroya2608362009-06-18 23:21:23 +01001940 struct orinoco_private *priv = dev_id;
1941 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 hermes_t *hw = &priv->hw;
1943 int count = MAX_IRQLOOPS_PER_IRQ;
1944 u16 evstat, events;
David Kilroy21312662009-02-04 23:05:47 +00001945 /* These are used to detect a runaway interrupt situation.
1946 *
1947 * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1948 * we panic and shut down the hardware
1949 */
1950 /* jiffies value the last time we were called */
1951 static int last_irq_jiffy; /* = 0 */
1952 static int loops_this_jiffy; /* = 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 unsigned long flags;
1954
1955 if (orinoco_lock(priv, &flags) != 0) {
1956 /* If hw is unavailable - we don't know if the irq was
1957 * for us or not */
1958 return IRQ_HANDLED;
1959 }
1960
1961 evstat = hermes_read_regn(hw, EVSTAT);
1962 events = evstat & hw->inten;
David Kilroya94e8422009-02-04 23:05:44 +00001963 if (!events) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 orinoco_unlock(priv, &flags);
1965 return IRQ_NONE;
1966 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001967
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 if (jiffies != last_irq_jiffy)
1969 loops_this_jiffy = 0;
1970 last_irq_jiffy = jiffies;
1971
1972 while (events && count--) {
1973 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
1974 printk(KERN_WARNING "%s: IRQ handler is looping too "
1975 "much! Resetting.\n", dev->name);
1976 /* Disable interrupts for now */
1977 hermes_set_irqmask(hw, 0);
1978 schedule_work(&priv->reset_work);
1979 break;
1980 }
1981
1982 /* Check the card hasn't been removed */
David Kilroya94e8422009-02-04 23:05:44 +00001983 if (!hermes_present(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 DEBUG(0, "orinoco_interrupt(): card removed\n");
1985 break;
1986 }
1987
1988 if (events & HERMES_EV_TICK)
1989 __orinoco_ev_tick(dev, hw);
1990 if (events & HERMES_EV_WTERR)
1991 __orinoco_ev_wterr(dev, hw);
1992 if (events & HERMES_EV_INFDROP)
1993 __orinoco_ev_infdrop(dev, hw);
1994 if (events & HERMES_EV_INFO)
1995 __orinoco_ev_info(dev, hw);
1996 if (events & HERMES_EV_RX)
1997 __orinoco_ev_rx(dev, hw);
1998 if (events & HERMES_EV_TXEXC)
1999 __orinoco_ev_txexc(dev, hw);
2000 if (events & HERMES_EV_TX)
2001 __orinoco_ev_tx(dev, hw);
2002 if (events & HERMES_EV_ALLOC)
2003 __orinoco_ev_alloc(dev, hw);
David Kilroy6fe9deb2009-02-04 23:05:43 +00002004
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002005 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 evstat = hermes_read_regn(hw, EVSTAT);
2008 events = evstat & hw->inten;
2009 };
2010
2011 orinoco_unlock(priv, &flags);
2012 return IRQ_HANDLED;
2013}
David Kilroy21312662009-02-04 23:05:47 +00002014EXPORT_SYMBOL(orinoco_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
2016/********************************************************************/
David Kilroy39d1ffe2008-11-22 10:37:28 +00002017/* Power management */
2018/********************************************************************/
2019#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
2020static int orinoco_pm_notifier(struct notifier_block *notifier,
2021 unsigned long pm_event,
2022 void *unused)
2023{
2024 struct orinoco_private *priv = container_of(notifier,
2025 struct orinoco_private,
2026 pm_notifier);
2027
2028 /* All we need to do is cache the firmware before suspend, and
2029 * release it when we come out.
2030 *
2031 * Only need to do this if we're downloading firmware. */
2032 if (!priv->do_fw_download)
2033 return NOTIFY_DONE;
2034
2035 switch (pm_event) {
2036 case PM_HIBERNATION_PREPARE:
2037 case PM_SUSPEND_PREPARE:
2038 orinoco_cache_fw(priv, 0);
2039 break;
2040
2041 case PM_POST_RESTORE:
2042 /* Restore from hibernation failed. We need to clean
2043 * up in exactly the same way, so fall through. */
2044 case PM_POST_HIBERNATION:
2045 case PM_POST_SUSPEND:
2046 orinoco_uncache_fw(priv);
2047 break;
2048
2049 case PM_RESTORE_PREPARE:
2050 default:
2051 break;
2052 }
2053
2054 return NOTIFY_DONE;
2055}
David S. Millerf11c1792009-02-25 00:02:05 -08002056
2057static void orinoco_register_pm_notifier(struct orinoco_private *priv)
2058{
2059 priv->pm_notifier.notifier_call = orinoco_pm_notifier;
2060 register_pm_notifier(&priv->pm_notifier);
2061}
2062
2063static void orinoco_unregister_pm_notifier(struct orinoco_private *priv)
2064{
2065 unregister_pm_notifier(&priv->pm_notifier);
2066}
David Kilroy39d1ffe2008-11-22 10:37:28 +00002067#else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
David S. Millerf11c1792009-02-25 00:02:05 -08002068#define orinoco_register_pm_notifier(priv) do { } while(0)
2069#define orinoco_unregister_pm_notifier(priv) do { } while(0)
David Kilroy39d1ffe2008-11-22 10:37:28 +00002070#endif
2071
2072/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073/* Initialization */
2074/********************************************************************/
2075
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076static int orinoco_init(struct net_device *dev)
2077{
2078 struct orinoco_private *priv = netdev_priv(dev);
2079 hermes_t *hw = &priv->hw;
2080 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 /* No need to lock, the hw_unavailable flag is already set in
2083 * alloc_orinocodev() */
Johannes Berg2c7060022008-10-30 22:09:54 +01002084 priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
2086 /* Initialize the firmware */
Pavel Roskin37a6c612006-04-07 04:10:49 -04002087 err = hermes_init(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 if (err != 0) {
2089 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2090 dev->name, err);
2091 goto out;
2092 }
2093
David Kilroya2d1a422009-06-18 23:21:18 +01002094 err = determine_fw_capabilities(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 if (err != 0) {
2096 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2097 dev->name);
2098 goto out;
2099 }
2100
David Kilroy3994d502008-08-21 23:27:54 +01002101 if (priv->do_fw_download) {
David Kilroy39d1ffe2008-11-22 10:37:28 +00002102#ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
David Kilroy74734312008-11-22 10:37:25 +00002103 orinoco_cache_fw(priv, 0);
David Kilroy39d1ffe2008-11-22 10:37:28 +00002104#endif
David Kilroy74734312008-11-22 10:37:25 +00002105
David Kilroy3994d502008-08-21 23:27:54 +01002106 err = orinoco_download(priv);
2107 if (err)
2108 priv->do_fw_download = 0;
2109
2110 /* Check firmware version again */
David Kilroya2d1a422009-06-18 23:21:18 +01002111 err = determine_fw_capabilities(priv);
David Kilroy3994d502008-08-21 23:27:54 +01002112 if (err != 0) {
2113 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2114 dev->name);
2115 goto out;
2116 }
2117 }
2118
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 if (priv->has_port3)
David Kilroyb2f30a02009-02-04 23:05:46 +00002120 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n",
2121 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 if (priv->has_ibss)
2123 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2124 dev->name);
2125 if (priv->has_wep) {
David Kilroy21312662009-02-04 23:05:47 +00002126 printk(KERN_DEBUG "%s: WEP supported, %s-bit key\n", dev->name,
2127 priv->has_big_wep ? "104" : "40");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 }
David Kilroy23edcc42008-08-21 23:28:05 +01002129 if (priv->has_wpa) {
David Kilroyd03032a2008-08-21 23:28:02 +01002130 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
David Kilroy23edcc42008-08-21 23:28:05 +01002131 if (orinoco_mic_init(priv)) {
2132 printk(KERN_ERR "%s: Failed to setup MIC crypto "
2133 "algorithm. Disabling WPA support\n", dev->name);
2134 priv->has_wpa = 0;
2135 }
2136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
David Kilroy01632fa2008-08-21 23:27:58 +01002138 /* Now we have the firmware capabilities, allocate appropiate
2139 * sized scan buffers */
2140 if (orinoco_bss_data_allocate(priv))
2141 goto out;
2142 orinoco_bss_data_init(priv);
2143
David Kilroye9e3d012009-06-18 23:21:19 +01002144 err = orinoco_hw_read_card_settings(priv, dev->dev_addr);
2145 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
David Kilroy42a51b92009-06-18 23:21:20 +01002148 err = orinoco_hw_allocate_fid(priv);
Pavel Roskin37a6c612006-04-07 04:10:49 -04002149 if (err) {
2150 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2151 dev->name);
2152 goto out;
2153 }
2154
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 /* Set up the default configuration */
2156 priv->iw_mode = IW_MODE_INFRA;
2157 /* By default use IEEE/IBSS ad-hoc mode if we have it */
David Kilroya94e8422009-02-04 23:05:44 +00002158 priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04002160 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
2162 priv->promiscuous = 0;
David Kilroy4ae6ee22008-08-21 23:27:59 +01002163 priv->encode_alg = IW_ENCODE_ALG_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 priv->tx_key = 0;
David Kilroyd03032a2008-08-21 23:28:02 +01002165 priv->wpa_enabled = 0;
2166 priv->tkip_cm_active = 0;
2167 priv->key_mgmt = 0;
2168 priv->wpa_ie_len = 0;
2169 priv->wpa_ie = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 /* Make the hardware available, as long as it hasn't been
2172 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2173 spin_lock_irq(&priv->lock);
2174 priv->hw_unavailable--;
2175 spin_unlock_irq(&priv->lock);
2176
2177 printk(KERN_DEBUG "%s: ready\n", dev->name);
2178
2179 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 return err;
2181}
2182
Andrey Borzenkov89ea4092009-01-21 20:46:46 +03002183static const struct net_device_ops orinoco_netdev_ops = {
2184 .ndo_init = orinoco_init,
2185 .ndo_open = orinoco_open,
2186 .ndo_stop = orinoco_stop,
2187 .ndo_start_xmit = orinoco_xmit,
2188 .ndo_set_multicast_list = orinoco_set_multicast_list,
2189 .ndo_change_mtu = orinoco_change_mtu,
2190 .ndo_tx_timeout = orinoco_tx_timeout,
2191 .ndo_get_stats = orinoco_get_stats,
2192};
2193
David Kilroya2608362009-06-18 23:21:23 +01002194struct orinoco_private
David Kilroy3994d502008-08-21 23:27:54 +01002195*alloc_orinocodev(int sizeof_card,
2196 struct device *device,
2197 int (*hard_reset)(struct orinoco_private *),
2198 int (*stop_fw)(struct orinoco_private *, int))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
2200 struct net_device *dev;
2201 struct orinoco_private *priv;
2202
2203 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
Andrey Borzenkove129a942009-01-21 21:55:29 +03002204 if (!dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 return NULL;
2206 priv = netdev_priv(dev);
2207 priv->ndev = dev;
2208 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002209 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 + sizeof(struct orinoco_private));
2211 else
2212 priv->card = NULL;
David Kilroy3994d502008-08-21 23:27:54 +01002213 priv->dev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
2215 /* Setup / override net_device fields */
Andrey Borzenkov89ea4092009-01-21 20:46:46 +03002216 dev->netdev_ops = &orinoco_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 dev->watchdog_timeo = HZ; /* 1 second timeout */
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002218 dev->ethtool_ops = &orinoco_ethtool_ops;
Andrey Borzenkove129a942009-01-21 21:55:29 +03002219 dev->wireless_handlers = &orinoco_handler_def;
Pavel Roskin343c6862005-09-09 18:43:02 -04002220#ifdef WIRELESS_SPY
2221 priv->wireless_data.spy_data = &priv->spy_data;
2222 dev->wireless_data = &priv->wireless_data;
2223#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 /* we use the default eth_mac_addr for setting the MAC addr */
2225
David Kilroy23edcc42008-08-21 23:28:05 +01002226 /* Reserve space in skb for the SNAP header */
2227 dev->hard_header_len += ENCAPS_OVERHEAD;
2228
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 /* Set up default callbacks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 priv->hard_reset = hard_reset;
David Kilroy3994d502008-08-21 23:27:54 +01002231 priv->stop_fw = stop_fw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233 spin_lock_init(&priv->lock);
2234 priv->open = 0;
2235 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2236 * before anything else touches the
2237 * hardware */
David Howellsc4028952006-11-22 14:57:56 +00002238 INIT_WORK(&priv->reset_work, orinoco_reset);
2239 INIT_WORK(&priv->join_work, orinoco_join_ap);
2240 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
David Kilroy31afcef2008-08-21 23:28:04 +01002242 INIT_LIST_HEAD(&priv->rx_list);
2243 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
2244 (unsigned long) dev);
2245
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 netif_carrier_off(dev);
2247 priv->last_linkstatus = 0xffff;
2248
Andrey Borzenkov2bfc5cb2009-02-28 23:09:09 +03002249#if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
David Kilroy2cea7b22008-11-22 10:37:26 +00002250 priv->cached_pri_fw = NULL;
Andrey Borzenkov4fb30782008-10-19 12:06:11 +04002251 priv->cached_fw = NULL;
Andrey Borzenkov2bfc5cb2009-02-28 23:09:09 +03002252#endif
Andrey Borzenkov4fb30782008-10-19 12:06:11 +04002253
David Kilroy39d1ffe2008-11-22 10:37:28 +00002254 /* Register PM notifiers */
David S. Millerf11c1792009-02-25 00:02:05 -08002255 orinoco_register_pm_notifier(priv);
David Kilroy39d1ffe2008-11-22 10:37:28 +00002256
David Kilroya2608362009-06-18 23:21:23 +01002257 return priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258}
David Kilroy21312662009-02-04 23:05:47 +00002259EXPORT_SYMBOL(alloc_orinocodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
David Kilroya2608362009-06-18 23:21:23 +01002261void free_orinocodev(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262{
David Kilroya2608362009-06-18 23:21:23 +01002263 struct net_device *dev = priv->ndev;
David Kilroy20953ad2009-01-07 00:23:55 +00002264 struct orinoco_rx_data *rx_data, *temp;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002265
David Kilroy20953ad2009-01-07 00:23:55 +00002266 /* If the tasklet is scheduled when we call tasklet_kill it
2267 * will run one final time. However the tasklet will only
2268 * drain priv->rx_list if the hw is still available. */
David Kilroy31afcef2008-08-21 23:28:04 +01002269 tasklet_kill(&priv->rx_tasklet);
David Kilroy74734312008-11-22 10:37:25 +00002270
David Kilroy20953ad2009-01-07 00:23:55 +00002271 /* Explicitly drain priv->rx_list */
2272 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
2273 list_del(&rx_data->list);
2274
2275 dev_kfree_skb(rx_data->skb);
2276 kfree(rx_data->desc);
2277 kfree(rx_data);
2278 }
2279
David S. Millerf11c1792009-02-25 00:02:05 -08002280 orinoco_unregister_pm_notifier(priv);
David Kilroy74734312008-11-22 10:37:25 +00002281 orinoco_uncache_fw(priv);
2282
David Kilroyd03032a2008-08-21 23:28:02 +01002283 priv->wpa_ie_len = 0;
2284 kfree(priv->wpa_ie);
David Kilroy23edcc42008-08-21 23:28:05 +01002285 orinoco_mic_free(priv);
Dan Williams1e3428e2007-10-10 23:56:25 -04002286 orinoco_bss_data_free(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 free_netdev(dev);
2288}
David Kilroy21312662009-02-04 23:05:47 +00002289EXPORT_SYMBOL(free_orinocodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002291static void orinoco_get_drvinfo(struct net_device *dev,
2292 struct ethtool_drvinfo *info)
2293{
2294 struct orinoco_private *priv = netdev_priv(dev);
2295
2296 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
2297 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
2298 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07002299 if (dev->dev.parent)
Kay Sieversfb28ad32008-11-10 13:55:14 -08002300 strncpy(info->bus_info, dev_name(dev->dev.parent),
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002301 sizeof(info->bus_info) - 1);
2302 else
2303 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
2304 "PCMCIA %p", priv->hw.iobase);
2305}
2306
Jeff Garzik7282d492006-09-13 14:30:00 -04002307static const struct ethtool_ops orinoco_ethtool_ops = {
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002308 .get_drvinfo = orinoco_get_drvinfo,
2309 .get_link = ethtool_op_get_link,
2310};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
2312/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313/* Module initialization */
2314/********************************************************************/
2315
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316/* Can't be declared "const" or the whole __initdata section will
2317 * become const */
2318static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
2319 " (David Gibson <hermes@gibson.dropbear.id.au>, "
2320 "Pavel Roskin <proski@gnu.org>, et al)";
2321
2322static int __init init_orinoco(void)
2323{
2324 printk(KERN_DEBUG "%s\n", version);
2325 return 0;
2326}
2327
2328static void __exit exit_orinoco(void)
2329{
2330}
2331
2332module_init(init_orinoco);
2333module_exit(exit_orinoco);