blob: 0fe9420c4905900d9760f0e49fe5a91d7b5636ce [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#define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
151
152#define DUMMY_FID 0xFFFF
153
154/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
155 HERMES_MAX_MULTICAST : 0)*/
156#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
157
158#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
159 | HERMES_EV_TX | HERMES_EV_TXEXC \
160 | HERMES_EV_WTERR | HERMES_EV_INFO \
David Kilroya94e8422009-02-04 23:05:44 +0000161 | HERMES_EV_INFDROP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Jeff Garzik7282d492006-09-13 14:30:00 -0400163static const struct ethtool_ops orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +0200164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/* Data types */
167/********************************************************************/
168
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400169/* Beginning of the Tx descriptor, used in TxExc handling */
170struct hermes_txexc_data {
171 struct hermes_tx_descriptor desc;
Pavel Roskind133ae42005-09-23 04:18:06 -0400172 __le16 frame_ctl;
173 __le16 duration_id;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200174 u8 addr1[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175} __attribute__ ((packed));
176
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200177/* Rx frame header except compatibility 802.3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178struct hermes_rx_descriptor {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200179 /* Control */
Pavel Roskind133ae42005-09-23 04:18:06 -0400180 __le16 status;
181 __le32 time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 u8 silence;
183 u8 signal;
184 u8 rate;
185 u8 rxflow;
Pavel Roskind133ae42005-09-23 04:18:06 -0400186 __le32 reserved;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200187
188 /* 802.11 header */
Pavel Roskind133ae42005-09-23 04:18:06 -0400189 __le16 frame_ctl;
190 __le16 duration_id;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200191 u8 addr1[ETH_ALEN];
192 u8 addr2[ETH_ALEN];
193 u8 addr3[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400194 __le16 seq_ctl;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200195 u8 addr4[ETH_ALEN];
196
197 /* Data length */
Pavel Roskind133ae42005-09-23 04:18:06 -0400198 __le16 data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199} __attribute__ ((packed));
200
David Kilroy47166792009-01-07 00:43:54 +0000201struct orinoco_rx_data {
202 struct hermes_rx_descriptor *desc;
203 struct sk_buff *skb;
204 struct list_head list;
205};
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/********************************************************************/
208/* Function prototypes */
209/********************************************************************/
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211static void __orinoco_set_multicast_list(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213/********************************************************************/
214/* Internal helper functions */
215/********************************************************************/
216
David Kilroycb1576a2009-02-04 23:05:56 +0000217void set_port_type(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
219 switch (priv->iw_mode) {
220 case IW_MODE_INFRA:
221 priv->port_type = 1;
222 priv->createibss = 0;
223 break;
224 case IW_MODE_ADHOC:
225 if (priv->prefer_port3) {
226 priv->port_type = 3;
227 priv->createibss = 0;
228 } else {
229 priv->port_type = priv->ibss_port;
230 priv->createibss = 1;
231 }
232 break;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200233 case IW_MODE_MONITOR:
234 priv->port_type = 3;
235 priv->createibss = 0;
236 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 default:
238 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
239 priv->ndev->name);
240 }
241}
242
David Kilroy3994d502008-08-21 23:27:54 +0100243/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244/* Device methods */
245/********************************************************************/
246
247static int orinoco_open(struct net_device *dev)
248{
249 struct orinoco_private *priv = netdev_priv(dev);
250 unsigned long flags;
251 int err;
252
253 if (orinoco_lock(priv, &flags) != 0)
254 return -EBUSY;
255
256 err = __orinoco_up(dev);
257
David Kilroya94e8422009-02-04 23:05:44 +0000258 if (!err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 priv->open = 1;
260
261 orinoco_unlock(priv, &flags);
262
263 return err;
264}
265
Christoph Hellwigad8f4512005-05-14 17:30:17 +0200266static int orinoco_stop(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 struct orinoco_private *priv = netdev_priv(dev);
269 int err = 0;
270
271 /* We mustn't use orinoco_lock() here, because we need to be
272 able to close the interface even if hw_unavailable is set
273 (e.g. as we're released after a PC Card removal) */
274 spin_lock_irq(&priv->lock);
275
276 priv->open = 0;
277
278 err = __orinoco_down(dev);
279
280 spin_unlock_irq(&priv->lock);
281
282 return err;
283}
284
285static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
286{
287 struct orinoco_private *priv = netdev_priv(dev);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 return &priv->stats;
290}
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292static void orinoco_set_multicast_list(struct net_device *dev)
293{
294 struct orinoco_private *priv = netdev_priv(dev);
295 unsigned long flags;
296
297 if (orinoco_lock(priv, &flags) != 0) {
298 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
299 "called when hw_unavailable\n", dev->name);
300 return;
301 }
302
303 __orinoco_set_multicast_list(dev);
304 orinoco_unlock(priv, &flags);
305}
306
307static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
308{
309 struct orinoco_private *priv = netdev_priv(dev);
310
David Kilroya94e8422009-02-04 23:05:44 +0000311 if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 return -EINVAL;
313
Johannes Berg2c7060022008-10-30 22:09:54 +0100314 /* MTU + encapsulation + header length */
David Kilroya94e8422009-02-04 23:05:44 +0000315 if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
316 (priv->nicbuf_size - ETH_HLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return -EINVAL;
318
319 dev->mtu = new_mtu;
320
321 return 0;
322}
323
324/********************************************************************/
325/* Tx path */
326/********************************************************************/
327
328static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
329{
330 struct orinoco_private *priv = netdev_priv(dev);
331 struct net_device_stats *stats = &priv->stats;
332 hermes_t *hw = &priv->hw;
333 int err = 0;
334 u16 txfid = priv->txfid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 struct ethhdr *eh;
David Kilroy6eecad72008-08-21 23:27:56 +0100336 int tx_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 unsigned long flags;
338
David Kilroya94e8422009-02-04 23:05:44 +0000339 if (!netif_running(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 printk(KERN_ERR "%s: Tx on stopped device!\n",
341 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400342 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 if (netif_queue_stopped(dev)) {
David Kilroy6fe9deb2009-02-04 23:05:43 +0000346 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400348 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 if (orinoco_lock(priv, &flags) != 0) {
352 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
353 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400354 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356
David Kilroya94e8422009-02-04 23:05:44 +0000357 if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 /* Oops, the firmware hasn't established a connection,
David Kilroy6fe9deb2009-02-04 23:05:43 +0000359 silently drop the packet (this seems to be the
360 safest approach). */
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400361 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
363
Pavel Roskin8d5be082006-04-07 04:10:41 -0400364 /* Check packet length */
Pavel Roskina28dc812006-04-07 04:10:45 -0400365 if (skb->len < ETH_HLEN)
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400366 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
David Kilroy6eecad72008-08-21 23:27:56 +0100368 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
David Kilroy23edcc42008-08-21 23:28:05 +0100370 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
371 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
372 HERMES_TXCTRL_MIC;
373
David Kilroy6eecad72008-08-21 23:27:56 +0100374 if (priv->has_alt_txcntl) {
375 /* WPA enabled firmwares have tx_cntl at the end of
376 * the 802.11 header. So write zeroed descriptor and
377 * 802.11 header at the same time
378 */
379 char desc[HERMES_802_3_OFFSET];
380 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
381
382 memset(&desc, 0, sizeof(desc));
383
384 *txcntl = cpu_to_le16(tx_control);
385 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
386 txfid, 0);
387 if (err) {
388 if (net_ratelimit())
389 printk(KERN_ERR "%s: Error %d writing Tx "
390 "descriptor to BAP\n", dev->name, err);
391 goto busy;
392 }
393 } else {
394 struct hermes_tx_descriptor desc;
395
396 memset(&desc, 0, sizeof(desc));
397
398 desc.tx_control = cpu_to_le16(tx_control);
399 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
400 txfid, 0);
401 if (err) {
402 if (net_ratelimit())
403 printk(KERN_ERR "%s: Error %d writing Tx "
404 "descriptor to BAP\n", dev->name, err);
405 goto busy;
406 }
407
408 /* Clear the 802.11 header and data length fields - some
409 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
410 * if this isn't done. */
411 hermes_clear_words(hw, HERMES_DATA0,
412 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
David Kilroy23edcc42008-08-21 23:28:05 +0100415 eh = (struct ethhdr *)skb->data;
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 /* Encapsulate Ethernet-II frames */
418 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
Pavel Roskina28dc812006-04-07 04:10:45 -0400419 struct header_struct {
420 struct ethhdr eth; /* 802.3 header */
421 u8 encap[6]; /* 802.2 header */
422 } __attribute__ ((packed)) hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Pavel Roskina28dc812006-04-07 04:10:45 -0400424 /* Strip destination and source from the data */
425 skb_pull(skb, 2 * ETH_ALEN);
Pavel Roskina28dc812006-04-07 04:10:45 -0400426
427 /* And move them to a separate header */
428 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
429 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
430 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
431
David Kilroy23edcc42008-08-21 23:28:05 +0100432 /* Insert the SNAP header */
433 if (skb_headroom(skb) < sizeof(hdr)) {
434 printk(KERN_ERR
435 "%s: Not enough headroom for 802.2 headers %d\n",
436 dev->name, skb_headroom(skb));
437 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
David Kilroy23edcc42008-08-21 23:28:05 +0100439 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
440 memcpy(eh, &hdr, sizeof(hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 }
442
Pavel Roskina28dc812006-04-07 04:10:45 -0400443 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
David Kilroy23edcc42008-08-21 23:28:05 +0100444 txfid, HERMES_802_3_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 if (err) {
446 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
447 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400448 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450
David Kilroy23edcc42008-08-21 23:28:05 +0100451 /* Calculate Michael MIC */
452 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
453 u8 mic_buf[MICHAEL_MIC_LEN + 1];
454 u8 *mic;
455 size_t offset;
456 size_t len;
457
458 if (skb->len % 2) {
459 /* MIC start is on an odd boundary */
460 mic_buf[0] = skb->data[skb->len - 1];
461 mic = &mic_buf[1];
462 offset = skb->len - 1;
463 len = MICHAEL_MIC_LEN + 1;
464 } else {
465 mic = &mic_buf[0];
466 offset = skb->len;
467 len = MICHAEL_MIC_LEN;
468 }
469
David Kilroy4adb4742009-02-04 23:05:51 +0000470 orinoco_mic(priv->tx_tfm_mic,
David Kilroy23edcc42008-08-21 23:28:05 +0100471 priv->tkip_key[priv->tx_key].tx_mic,
472 eh->h_dest, eh->h_source, 0 /* priority */,
473 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
474
475 /* Write the MIC */
476 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
477 txfid, HERMES_802_3_OFFSET + offset);
478 if (err) {
479 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
480 dev->name, err);
481 goto busy;
482 }
483 }
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 /* Finally, we actually initiate the send */
486 netif_stop_queue(dev);
487
488 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
489 txfid, NULL);
490 if (err) {
491 netif_start_queue(dev);
Andrew Mortonc367c212005-10-19 21:23:44 -0700492 if (net_ratelimit())
493 printk(KERN_ERR "%s: Error %d transmitting packet\n",
494 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400495 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497
498 dev->trans_start = jiffies;
David Kilroy23edcc42008-08-21 23:28:05 +0100499 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400500 goto ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400502 drop:
503 stats->tx_errors++;
504 stats->tx_dropped++;
505
506 ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 dev_kfree_skb(skb);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400509 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400511 busy:
Jiri Benc2c1bd262006-04-07 04:10:47 -0400512 if (err == -EIO)
513 schedule_work(&priv->reset_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 orinoco_unlock(priv, &flags);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400515 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516}
517
518static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
519{
520 struct orinoco_private *priv = netdev_priv(dev);
521 u16 fid = hermes_read_regn(hw, ALLOCFID);
522
523 if (fid != priv->txfid) {
524 if (fid != DUMMY_FID)
525 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
526 dev->name, fid);
527 return;
528 }
529
530 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
531}
532
533static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
534{
535 struct orinoco_private *priv = netdev_priv(dev);
536 struct net_device_stats *stats = &priv->stats;
537
538 stats->tx_packets++;
539
540 netif_wake_queue(dev);
541
542 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
543}
544
545static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
546{
547 struct orinoco_private *priv = netdev_priv(dev);
548 struct net_device_stats *stats = &priv->stats;
549 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -0400550 u16 status;
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400551 struct hermes_txexc_data hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 int err = 0;
553
554 if (fid == DUMMY_FID)
555 return; /* Nothing's really happened */
556
Pavel Roskin48ca7032005-09-23 04:18:06 -0400557 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200558 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400559 sizeof(struct hermes_txexc_data),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200560 fid, 0);
561
562 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
563 stats->tx_errors++;
564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 if (err) {
566 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
567 "(FID=%04X error %d)\n",
568 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200569 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000571
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200572 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
573 err, fid);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000574
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200575 /* We produce a TXDROP event only for retry or lifetime
576 * exceeded, because that's the only status that really mean
577 * that this particular node went away.
578 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400579 status = le16_to_cpu(hdr.desc.status);
Pavel Roskind133ae42005-09-23 04:18:06 -0400580 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200581 union iwreq_data wrqu;
582
583 /* Copy 802.11 dest address.
584 * We use the 802.11 header because the frame may
585 * not be 802.3 or may be mangled...
586 * In Ad-Hoc mode, it will be the node address.
587 * In managed mode, it will be most likely the AP addr
588 * User space will figure out how to convert it to
589 * whatever it needs (IP address or else).
590 * - Jean II */
591 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
592 wrqu.addr.sa_family = ARPHRD_ETHER;
593
594 /* Send event to user space */
595 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
596 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
601static void orinoco_tx_timeout(struct net_device *dev)
602{
603 struct orinoco_private *priv = netdev_priv(dev);
604 struct net_device_stats *stats = &priv->stats;
605 struct hermes *hw = &priv->hw;
606
607 printk(KERN_WARNING "%s: Tx timeout! "
608 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
609 dev->name, hermes_read_regn(hw, ALLOCFID),
610 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
611
612 stats->tx_errors++;
613
614 schedule_work(&priv->reset_work);
615}
616
617/********************************************************************/
618/* Rx path (data frames) */
619/********************************************************************/
620
621/* Does the frame have a SNAP header indicating it should be
622 * de-encapsulated to Ethernet-II? */
623static inline int is_ethersnap(void *_hdr)
624{
625 u8 *hdr = _hdr;
626
627 /* We de-encapsulate all packets which, a) have SNAP headers
628 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
629 * and where b) the OUI of the SNAP header is 00:00:00 or
630 * 00:00:f8 - we need both because different APs appear to use
631 * different OUIs for some reason */
632 return (memcmp(hdr, &encaps_hdr, 5) == 0)
David Kilroya94e8422009-02-04 23:05:44 +0000633 && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634}
635
636static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
637 int level, int noise)
638{
Pavel Roskin343c6862005-09-09 18:43:02 -0400639 struct iw_quality wstats;
640 wstats.level = level - 0x95;
641 wstats.noise = noise - 0x95;
642 wstats.qual = (level > noise) ? (level - noise) : 0;
Andrey Borzenkovf941f852008-11-15 17:15:09 +0300643 wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
Pavel Roskin343c6862005-09-09 18:43:02 -0400644 /* Update spy records */
645 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646}
647
648static void orinoco_stat_gather(struct net_device *dev,
649 struct sk_buff *skb,
650 struct hermes_rx_descriptor *desc)
651{
652 struct orinoco_private *priv = netdev_priv(dev);
653
654 /* Using spy support with lots of Rx packets, like in an
655 * infrastructure (AP), will really slow down everything, because
656 * the MAC address must be compared to each entry of the spy list.
657 * If the user really asks for it (set some address in the
658 * spy list), we do it, but he will pay the price.
659 * Note that to get here, you need both WIRELESS_SPY
660 * compiled in AND some addresses in the list !!!
661 */
662 /* Note : gcc will optimise the whole section away if
663 * WIRELESS_SPY is not defined... - Jean II */
664 if (SPY_NUMBER(priv)) {
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -0700665 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 desc->signal, desc->silence);
667 }
668}
669
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200670/*
671 * orinoco_rx_monitor - handle received monitor frames.
672 *
673 * Arguments:
674 * dev network device
675 * rxfid received FID
676 * desc rx descriptor of the frame
677 *
678 * Call context: interrupt
679 */
680static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
681 struct hermes_rx_descriptor *desc)
682{
683 u32 hdrlen = 30; /* return full header by default */
684 u32 datalen = 0;
685 u16 fc;
686 int err;
687 int len;
688 struct sk_buff *skb;
689 struct orinoco_private *priv = netdev_priv(dev);
690 struct net_device_stats *stats = &priv->stats;
691 hermes_t *hw = &priv->hw;
692
693 len = le16_to_cpu(desc->data_len);
694
695 /* Determine the size of the header and the data */
696 fc = le16_to_cpu(desc->frame_ctl);
697 switch (fc & IEEE80211_FCTL_FTYPE) {
698 case IEEE80211_FTYPE_DATA:
699 if ((fc & IEEE80211_FCTL_TODS)
700 && (fc & IEEE80211_FCTL_FROMDS))
701 hdrlen = 30;
702 else
703 hdrlen = 24;
704 datalen = len;
705 break;
706 case IEEE80211_FTYPE_MGMT:
707 hdrlen = 24;
708 datalen = len;
709 break;
710 case IEEE80211_FTYPE_CTL:
711 switch (fc & IEEE80211_FCTL_STYPE) {
712 case IEEE80211_STYPE_PSPOLL:
713 case IEEE80211_STYPE_RTS:
714 case IEEE80211_STYPE_CFEND:
715 case IEEE80211_STYPE_CFENDACK:
716 hdrlen = 16;
717 break;
718 case IEEE80211_STYPE_CTS:
719 case IEEE80211_STYPE_ACK:
720 hdrlen = 10;
721 break;
722 }
723 break;
724 default:
725 /* Unknown frame type */
726 break;
727 }
728
729 /* sanity check the length */
Johannes Berg2c7060022008-10-30 22:09:54 +0100730 if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200731 printk(KERN_DEBUG "%s: oversized monitor frame, "
732 "data length = %d\n", dev->name, datalen);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200733 stats->rx_length_errors++;
734 goto update_stats;
735 }
736
737 skb = dev_alloc_skb(hdrlen + datalen);
738 if (!skb) {
739 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
740 dev->name);
Florin Malitabb6e0932006-05-22 22:35:30 -0700741 goto update_stats;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200742 }
743
744 /* Copy the 802.11 header to the skb */
745 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700746 skb_reset_mac_header(skb);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200747
748 /* If any, copy the data from the card to the skb */
749 if (datalen > 0) {
750 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
751 ALIGN(datalen, 2), rxfid,
752 HERMES_802_2_OFFSET);
753 if (err) {
754 printk(KERN_ERR "%s: error %d reading monitor frame\n",
755 dev->name, err);
756 goto drop;
757 }
758 }
759
760 skb->dev = dev;
761 skb->ip_summed = CHECKSUM_NONE;
762 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800763 skb->protocol = cpu_to_be16(ETH_P_802_2);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000764
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200765 stats->rx_packets++;
766 stats->rx_bytes += skb->len;
767
768 netif_rx(skb);
769 return;
770
771 drop:
772 dev_kfree_skb_irq(skb);
773 update_stats:
774 stats->rx_errors++;
775 stats->rx_dropped++;
776}
777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
779{
780 struct orinoco_private *priv = netdev_priv(dev);
781 struct net_device_stats *stats = &priv->stats;
782 struct iw_statistics *wstats = &priv->wstats;
783 struct sk_buff *skb = NULL;
David Kilroy31afcef2008-08-21 23:28:04 +0100784 u16 rxfid, status;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200785 int length;
David Kilroy31afcef2008-08-21 23:28:04 +0100786 struct hermes_rx_descriptor *desc;
787 struct orinoco_rx_data *rx_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 int err;
789
David Kilroy31afcef2008-08-21 23:28:04 +0100790 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
791 if (!desc) {
792 printk(KERN_WARNING
793 "%s: Can't allocate space for RX descriptor\n",
794 dev->name);
795 goto update_stats;
796 }
797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 rxfid = hermes_read_regn(hw, RXFID);
799
David Kilroy31afcef2008-08-21 23:28:04 +0100800 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 rxfid, 0);
802 if (err) {
803 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
804 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200805 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 }
807
David Kilroy31afcef2008-08-21 23:28:04 +0100808 status = le16_to_cpu(desc->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200810 if (status & HERMES_RXSTAT_BADCRC) {
811 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
812 dev->name);
813 stats->rx_crc_errors++;
814 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 }
816
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200817 /* Handle frames in monitor mode */
818 if (priv->iw_mode == IW_MODE_MONITOR) {
David Kilroy31afcef2008-08-21 23:28:04 +0100819 orinoco_rx_monitor(dev, rxfid, desc);
820 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 }
822
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200823 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
824 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
825 dev->name);
826 wstats->discard.code++;
827 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
829
David Kilroy31afcef2008-08-21 23:28:04 +0100830 length = le16_to_cpu(desc->data_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 /* Sanity checks */
833 if (length < 3) { /* No for even an 802.2 LLC header */
834 /* At least on Symbol firmware with PCF we get quite a
David Kilroy6fe9deb2009-02-04 23:05:43 +0000835 lot of these legitimately - Poll frames with no
836 data. */
David Kilroy31afcef2008-08-21 23:28:04 +0100837 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 }
Johannes Berg2c7060022008-10-30 22:09:54 +0100839 if (length > IEEE80211_MAX_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
841 dev->name, length);
842 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200843 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 }
845
David Kilroy23edcc42008-08-21 23:28:05 +0100846 /* Payload size does not include Michael MIC. Increase payload
847 * size to read it together with the data. */
848 if (status & HERMES_RXSTAT_MIC)
849 length += MICHAEL_MIC_LEN;
850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 /* We need space for the packet data itself, plus an ethernet
852 header, plus 2 bytes so we can align the IP header on a
853 32bit boundary, plus 1 byte so we can read in odd length
854 packets from the card, which has an IO granularity of 16
David Kilroy6fe9deb2009-02-04 23:05:43 +0000855 bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
857 if (!skb) {
858 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
859 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200860 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 }
862
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200863 /* We'll prepend the header, so reserve space for it. The worst
864 case is no decapsulation, when 802.3 header is prepended and
865 nothing is removed. 2 is for aligning the IP header. */
866 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200868 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
869 ALIGN(length, 2), rxfid,
870 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 if (err) {
872 printk(KERN_ERR "%s: error %d reading frame. "
873 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 goto drop;
875 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
David Kilroy31afcef2008-08-21 23:28:04 +0100877 /* Add desc and skb to rx queue */
878 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
879 if (!rx_data) {
880 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
881 dev->name);
882 goto drop;
883 }
884 rx_data->desc = desc;
885 rx_data->skb = skb;
886 list_add_tail(&rx_data->list, &priv->rx_list);
887 tasklet_schedule(&priv->rx_tasklet);
888
889 return;
890
891drop:
892 dev_kfree_skb_irq(skb);
893update_stats:
894 stats->rx_errors++;
895 stats->rx_dropped++;
896out:
897 kfree(desc);
898}
899
900static void orinoco_rx(struct net_device *dev,
901 struct hermes_rx_descriptor *desc,
902 struct sk_buff *skb)
903{
904 struct orinoco_private *priv = netdev_priv(dev);
905 struct net_device_stats *stats = &priv->stats;
906 u16 status, fc;
907 int length;
908 struct ethhdr *hdr;
909
910 status = le16_to_cpu(desc->status);
911 length = le16_to_cpu(desc->data_len);
912 fc = le16_to_cpu(desc->frame_ctl);
913
David Kilroy23edcc42008-08-21 23:28:05 +0100914 /* Calculate and check MIC */
915 if (status & HERMES_RXSTAT_MIC) {
916 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
917 HERMES_MIC_KEY_ID_SHIFT);
918 u8 mic[MICHAEL_MIC_LEN];
919 u8 *rxmic;
920 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
921 desc->addr3 : desc->addr2;
922
923 /* Extract Michael MIC from payload */
924 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
925
926 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
927 length -= MICHAEL_MIC_LEN;
928
David Kilroy4adb4742009-02-04 23:05:51 +0000929 orinoco_mic(priv->rx_tfm_mic,
David Kilroy23edcc42008-08-21 23:28:05 +0100930 priv->tkip_key[key_id].rx_mic,
931 desc->addr1,
932 src,
933 0, /* priority or QoS? */
934 skb->data,
935 skb->len,
936 &mic[0]);
937
938 if (memcmp(mic, rxmic,
939 MICHAEL_MIC_LEN)) {
940 union iwreq_data wrqu;
941 struct iw_michaelmicfailure wxmic;
David Kilroy23edcc42008-08-21 23:28:05 +0100942
943 printk(KERN_WARNING "%s: "
Johannes Berge1749612008-10-27 15:59:26 -0700944 "Invalid Michael MIC in data frame from %pM, "
David Kilroy23edcc42008-08-21 23:28:05 +0100945 "using key %i\n",
Johannes Berge1749612008-10-27 15:59:26 -0700946 dev->name, src, key_id);
David Kilroy23edcc42008-08-21 23:28:05 +0100947
948 /* TODO: update stats */
949
950 /* Notify userspace */
951 memset(&wxmic, 0, sizeof(wxmic));
952 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
953 wxmic.flags |= (desc->addr1[0] & 1) ?
954 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
955 wxmic.src_addr.sa_family = ARPHRD_ETHER;
956 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
957
958 (void) orinoco_hw_get_tkip_iv(priv, key_id,
959 &wxmic.tsc[0]);
960
961 memset(&wrqu, 0, sizeof(wrqu));
962 wrqu.data.length = sizeof(wxmic);
963 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
964 (char *) &wxmic);
965
966 goto drop;
967 }
968 }
969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 /* Handle decapsulation
971 * In most cases, the firmware tell us about SNAP frames.
972 * For some reason, the SNAP frames sent by LinkSys APs
973 * are not properly recognised by most firmwares.
974 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200975 if (length >= ENCAPS_OVERHEAD &&
976 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
977 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
978 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 /* These indicate a SNAP within 802.2 LLC within
980 802.11 frame which we'll need to de-encapsulate to
981 the original EthernetII frame. */
David Kilroyb2f30a02009-02-04 23:05:46 +0000982 hdr = (struct ethhdr *)skb_push(skb,
983 ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200985 /* 802.3 frame - prepend 802.3 header as is */
986 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
987 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
David Kilroy31afcef2008-08-21 23:28:04 +0100989 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200990 if (fc & IEEE80211_FCTL_FROMDS)
David Kilroy31afcef2008-08-21 23:28:04 +0100991 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200992 else
David Kilroy31afcef2008-08-21 23:28:04 +0100993 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 skb->protocol = eth_type_trans(skb, dev);
996 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200997 if (fc & IEEE80211_FCTL_TODS)
998 skb->pkt_type = PACKET_OTHERHOST;
David Kilroy6fe9deb2009-02-04 23:05:43 +0000999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 /* Process the wireless stats if needed */
David Kilroy31afcef2008-08-21 23:28:04 +01001001 orinoco_stat_gather(dev, skb, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 /* Pass the packet to the networking stack */
1004 netif_rx(skb);
1005 stats->rx_packets++;
1006 stats->rx_bytes += length;
1007
1008 return;
David Kilroy23edcc42008-08-21 23:28:05 +01001009
1010 drop:
1011 dev_kfree_skb(skb);
1012 stats->rx_errors++;
1013 stats->rx_dropped++;
David Kilroy31afcef2008-08-21 23:28:04 +01001014}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
David Kilroy31afcef2008-08-21 23:28:04 +01001016static void orinoco_rx_isr_tasklet(unsigned long data)
1017{
1018 struct net_device *dev = (struct net_device *) data;
1019 struct orinoco_private *priv = netdev_priv(dev);
1020 struct orinoco_rx_data *rx_data, *temp;
1021 struct hermes_rx_descriptor *desc;
1022 struct sk_buff *skb;
David Kilroy20953ad2009-01-07 00:23:55 +00001023 unsigned long flags;
1024
1025 /* orinoco_rx requires the driver lock, and we also need to
1026 * protect priv->rx_list, so just hold the lock over the
1027 * lot.
1028 *
1029 * If orinoco_lock fails, we've unplugged the card. In this
1030 * case just abort. */
1031 if (orinoco_lock(priv, &flags) != 0)
1032 return;
David Kilroy31afcef2008-08-21 23:28:04 +01001033
1034 /* extract desc and skb from queue */
1035 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1036 desc = rx_data->desc;
1037 skb = rx_data->skb;
1038 list_del(&rx_data->list);
1039 kfree(rx_data);
1040
1041 orinoco_rx(dev, desc, skb);
1042
1043 kfree(desc);
1044 }
David Kilroy20953ad2009-01-07 00:23:55 +00001045
1046 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
1049/********************************************************************/
1050/* Rx path (info frames) */
1051/********************************************************************/
1052
1053static void print_linkstatus(struct net_device *dev, u16 status)
1054{
David Kilroy21312662009-02-04 23:05:47 +00001055 char *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
1057 if (suppress_linkstatus)
1058 return;
1059
1060 switch (status) {
1061 case HERMES_LINKSTATUS_NOT_CONNECTED:
1062 s = "Not Connected";
1063 break;
1064 case HERMES_LINKSTATUS_CONNECTED:
1065 s = "Connected";
1066 break;
1067 case HERMES_LINKSTATUS_DISCONNECTED:
1068 s = "Disconnected";
1069 break;
1070 case HERMES_LINKSTATUS_AP_CHANGE:
1071 s = "AP Changed";
1072 break;
1073 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1074 s = "AP Out of Range";
1075 break;
1076 case HERMES_LINKSTATUS_AP_IN_RANGE:
1077 s = "AP In Range";
1078 break;
1079 case HERMES_LINKSTATUS_ASSOC_FAILED:
1080 s = "Association Failed";
1081 break;
1082 default:
1083 s = "UNKNOWN";
1084 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001085
Pavel Roskin11eaea42009-01-18 23:20:58 -05001086 printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 dev->name, s, status);
1088}
1089
Christoph Hellwig16739b02005-06-19 01:27:51 +02001090/* Search scan results for requested BSSID, join it if found */
David Howellsc4028952006-11-22 14:57:56 +00001091static void orinoco_join_ap(struct work_struct *work)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001092{
David Howellsc4028952006-11-22 14:57:56 +00001093 struct orinoco_private *priv =
1094 container_of(work, struct orinoco_private, join_work);
1095 struct net_device *dev = priv->ndev;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001096 struct hermes *hw = &priv->hw;
1097 int err;
1098 unsigned long flags;
1099 struct join_req {
1100 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -04001101 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001102 } __attribute__ ((packed)) req;
1103 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001104 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001105 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -04001106 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001107 u8 *buf;
1108 u16 len;
1109
1110 /* Allocate buffer for scan results */
1111 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
David Kilroya94e8422009-02-04 23:05:44 +00001112 if (!buf)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001113 return;
1114
1115 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001116 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001117
1118 /* Sanity checks in case user changed something in the meantime */
David Kilroya94e8422009-02-04 23:05:44 +00001119 if (!priv->bssid_fixed)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001120 goto out;
1121
1122 if (strlen(priv->desired_essid) == 0)
1123 goto out;
1124
1125 /* Read scan results from the firmware */
1126 err = hermes_read_ltv(hw, USER_BAP,
1127 HERMES_RID_SCANRESULTSTABLE,
1128 MAX_SCAN_LEN, &len, buf);
1129 if (err) {
1130 printk(KERN_ERR "%s: Cannot read scan results\n",
1131 dev->name);
1132 goto out;
1133 }
1134
1135 len = HERMES_RECLEN_TO_BYTES(len);
1136
1137 /* Go through the scan results looking for the channel of the AP
1138 * we were requested to join */
1139 for (; offset + atom_len <= len; offset += atom_len) {
1140 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001141 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1142 found = 1;
1143 break;
1144 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001145 }
1146
David Kilroya94e8422009-02-04 23:05:44 +00001147 if (!found) {
Pavel Roskinc89cc222005-09-01 20:06:06 -04001148 DEBUG(1, "%s: Requested AP not found in scan results\n",
1149 dev->name);
1150 goto out;
1151 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001152
Christoph Hellwig16739b02005-06-19 01:27:51 +02001153 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1154 req.channel = atom->channel; /* both are little-endian */
1155 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1156 &req);
1157 if (err)
1158 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1159
1160 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001161 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001162
1163 fail_lock:
1164 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001165}
1166
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001167/* Send new BSSID to userspace */
David Kilroy6cd90b12008-08-21 23:28:00 +01001168static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001169{
David Howellsc4028952006-11-22 14:57:56 +00001170 struct net_device *dev = priv->ndev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001171 struct hermes *hw = &priv->hw;
1172 union iwreq_data wrqu;
1173 int err;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001174
David Kilroy499b7022008-12-09 21:46:29 +00001175 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001176 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1177 if (err != 0)
David Kilroy6cd90b12008-08-21 23:28:00 +01001178 return;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001179
1180 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1181
1182 /* Send event to user space */
1183 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001184}
1185
David Kilroy06009fd2008-08-21 23:28:03 +01001186static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1187{
1188 struct net_device *dev = priv->ndev;
1189 struct hermes *hw = &priv->hw;
1190 union iwreq_data wrqu;
1191 int err;
1192 u8 buf[88];
1193 u8 *ie;
1194
1195 if (!priv->has_wpa)
1196 return;
1197
David Kilroy499b7022008-12-09 21:46:29 +00001198 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
David Kilroy06009fd2008-08-21 23:28:03 +01001199 sizeof(buf), NULL, &buf);
1200 if (err != 0)
1201 return;
1202
1203 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1204 if (ie) {
1205 int rem = sizeof(buf) - (ie - &buf[0]);
1206 wrqu.data.length = ie[1] + 2;
1207 if (wrqu.data.length > rem)
1208 wrqu.data.length = rem;
1209
1210 if (wrqu.data.length)
1211 /* Send event to user space */
1212 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1213 }
1214}
1215
1216static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1217{
1218 struct net_device *dev = priv->ndev;
1219 struct hermes *hw = &priv->hw;
1220 union iwreq_data wrqu;
1221 int err;
1222 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1223 u8 *ie;
1224
1225 if (!priv->has_wpa)
1226 return;
1227
David Kilroy499b7022008-12-09 21:46:29 +00001228 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
David Kilroy06009fd2008-08-21 23:28:03 +01001229 sizeof(buf), NULL, &buf);
1230 if (err != 0)
1231 return;
1232
1233 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1234 if (ie) {
1235 int rem = sizeof(buf) - (ie - &buf[0]);
1236 wrqu.data.length = ie[1] + 2;
1237 if (wrqu.data.length > rem)
1238 wrqu.data.length = rem;
1239
1240 if (wrqu.data.length)
1241 /* Send event to user space */
1242 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1243 }
1244}
1245
David Kilroy6cd90b12008-08-21 23:28:00 +01001246static void orinoco_send_wevents(struct work_struct *work)
1247{
1248 struct orinoco_private *priv =
1249 container_of(work, struct orinoco_private, wevent_work);
1250 unsigned long flags;
1251
1252 if (orinoco_lock(priv, &flags) != 0)
1253 return;
1254
David Kilroy06009fd2008-08-21 23:28:03 +01001255 orinoco_send_assocreqie_wevent(priv);
1256 orinoco_send_assocrespie_wevent(priv);
David Kilroy6cd90b12008-08-21 23:28:00 +01001257 orinoco_send_bssid_wevent(priv);
1258
1259 orinoco_unlock(priv, &flags);
1260}
Dan Williams1e3428e2007-10-10 23:56:25 -04001261
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1263{
1264 struct orinoco_private *priv = netdev_priv(dev);
1265 u16 infofid;
1266 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001267 __le16 len;
1268 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 } __attribute__ ((packed)) info;
1270 int len, type;
1271 int err;
1272
1273 /* This is an answer to an INQUIRE command that we did earlier,
1274 * or an information "event" generated by the card
1275 * The controller return to us a pseudo frame containing
1276 * the information in question - Jean II */
1277 infofid = hermes_read_regn(hw, INFOFID);
1278
1279 /* Read the info frame header - don't try too hard */
1280 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1281 infofid, 0);
1282 if (err) {
1283 printk(KERN_ERR "%s: error %d reading info frame. "
1284 "Frame dropped.\n", dev->name, err);
1285 return;
1286 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001287
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1289 type = le16_to_cpu(info.type);
1290
1291 switch (type) {
1292 case HERMES_INQ_TALLIES: {
1293 struct hermes_tallies_frame tallies;
1294 struct iw_statistics *wstats = &priv->wstats;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 if (len > sizeof(tallies)) {
1297 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1298 dev->name, len);
1299 len = sizeof(tallies);
1300 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001301
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001302 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1303 infofid, sizeof(info));
1304 if (err)
1305 break;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001306
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 /* Increment our various counters */
1308 /* wstats->discard.nwid - no wrong BSSID stuff */
1309 wstats->discard.code +=
1310 le16_to_cpu(tallies.RxWEPUndecryptable);
David Kilroy6fe9deb2009-02-04 23:05:43 +00001311 if (len == sizeof(tallies))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 wstats->discard.code +=
1313 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1314 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1315 wstats->discard.misc +=
1316 le16_to_cpu(tallies.TxDiscardsWrongSA);
1317 wstats->discard.fragment +=
1318 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1319 wstats->discard.retries +=
1320 le16_to_cpu(tallies.TxRetryLimitExceeded);
1321 /* wstats->miss.beacon - no match */
1322 }
1323 break;
1324 case HERMES_INQ_LINKSTATUS: {
1325 struct hermes_linkstatus linkstatus;
1326 u16 newstatus;
1327 int connected;
1328
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001329 if (priv->iw_mode == IW_MODE_MONITOR)
1330 break;
1331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 if (len != sizeof(linkstatus)) {
1333 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1334 dev->name, len);
1335 break;
1336 }
1337
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001338 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1339 infofid, sizeof(info));
1340 if (err)
1341 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 newstatus = le16_to_cpu(linkstatus.linkstatus);
1343
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001344 /* Symbol firmware uses "out of range" to signal that
1345 * the hostscan frame can be requested. */
1346 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1347 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1348 priv->has_hostscan && priv->scan_inprogress) {
1349 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1350 break;
1351 }
1352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1354 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1355 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1356
1357 if (connected)
1358 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001359 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 netif_carrier_off(dev);
1361
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001362 if (newstatus != priv->last_linkstatus) {
1363 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001365 /* The info frame contains only one word which is the
1366 * status (see hermes.h). The status is pretty boring
1367 * in itself, that's why we export the new BSSID...
1368 * Jean II */
1369 schedule_work(&priv->wevent_work);
1370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 }
1372 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001373 case HERMES_INQ_SCAN:
1374 if (!priv->scan_inprogress && priv->bssid_fixed &&
1375 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1376 schedule_work(&priv->join_work);
1377 break;
1378 }
1379 /* fall through */
1380 case HERMES_INQ_HOSTSCAN:
1381 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1382 /* Result of a scanning. Contains information about
1383 * cells in the vicinity - Jean II */
1384 union iwreq_data wrqu;
1385 unsigned char *buf;
1386
Dan Williams1e3428e2007-10-10 23:56:25 -04001387 /* Scan is no longer in progress */
1388 priv->scan_inprogress = 0;
1389
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001390 /* Sanity check */
1391 if (len > 4096) {
1392 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1393 dev->name, len);
1394 break;
1395 }
1396
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001397 /* Allocate buffer for results */
1398 buf = kmalloc(len, GFP_ATOMIC);
1399 if (buf == NULL)
1400 /* No memory, so can't printk()... */
1401 break;
1402
1403 /* Read scan data */
1404 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1405 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04001406 if (err) {
1407 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001408 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04001409 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001410
1411#ifdef ORINOCO_DEBUG
1412 {
1413 int i;
1414 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
David Kilroya94e8422009-02-04 23:05:44 +00001415 for (i = 1; i < (len * 2); i++)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001416 printk(":%02X", buf[i]);
1417 printk("]\n");
1418 }
1419#endif /* ORINOCO_DEBUG */
1420
David Kilroyaea48b12009-02-04 23:05:49 +00001421 if (orinoco_process_scan_results(priv, buf, len) == 0) {
Dan Williams1e3428e2007-10-10 23:56:25 -04001422 /* Send an empty event to user space.
1423 * We don't send the received data on the event because
1424 * it would require us to do complex transcoding, and
1425 * we want to minimise the work done in the irq handler
1426 * Use a request to extract the data - Jean II */
1427 wrqu.data.length = 0;
1428 wrqu.data.flags = 0;
1429 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1430 }
1431 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001432 }
1433 break;
David Kilroy01632fa2008-08-21 23:27:58 +01001434 case HERMES_INQ_CHANNELINFO:
1435 {
1436 struct agere_ext_scan_info *bss;
1437
1438 if (!priv->scan_inprogress) {
1439 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
1440 "len=%d\n", dev->name, len);
1441 break;
1442 }
1443
1444 /* An empty result indicates that the scan is complete */
1445 if (len == 0) {
1446 union iwreq_data wrqu;
1447
1448 /* Scan is no longer in progress */
1449 priv->scan_inprogress = 0;
1450
1451 wrqu.data.length = 0;
1452 wrqu.data.flags = 0;
1453 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1454 break;
1455 }
1456
1457 /* Sanity check */
1458 else if (len > sizeof(*bss)) {
1459 printk(KERN_WARNING
1460 "%s: Ext scan results too large (%d bytes). "
1461 "Truncating results to %zd bytes.\n",
1462 dev->name, len, sizeof(*bss));
1463 len = sizeof(*bss);
1464 } else if (len < (offsetof(struct agere_ext_scan_info,
1465 data) + 2)) {
1466 /* Drop this result now so we don't have to
1467 * keep checking later */
1468 printk(KERN_WARNING
1469 "%s: Ext scan results too short (%d bytes)\n",
1470 dev->name, len);
1471 break;
1472 }
1473
1474 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
1475 if (bss == NULL)
1476 break;
1477
1478 /* Read scan data */
1479 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
1480 infofid, sizeof(info));
1481 if (err) {
1482 kfree(bss);
1483 break;
1484 }
1485
1486 orinoco_add_ext_scan_result(priv, bss);
1487
1488 kfree(bss);
1489 break;
1490 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001491 case HERMES_INQ_SEC_STAT_AGERE:
1492 /* Security status (Agere specific) */
1493 /* Ignore this frame for now */
1494 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1495 break;
1496 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 default:
1498 printk(KERN_DEBUG "%s: Unknown information frame received: "
1499 "type 0x%04x, length %d\n", dev->name, type, len);
1500 /* We don't actually do anything about it */
1501 break;
1502 }
1503}
1504
1505static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1506{
1507 if (net_ratelimit())
1508 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1509}
1510
1511/********************************************************************/
1512/* Internal hardware control routines */
1513/********************************************************************/
1514
1515int __orinoco_up(struct net_device *dev)
1516{
1517 struct orinoco_private *priv = netdev_priv(dev);
1518 struct hermes *hw = &priv->hw;
1519 int err;
1520
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001521 netif_carrier_off(dev); /* just to make sure */
1522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 err = __orinoco_program_rids(dev);
1524 if (err) {
1525 printk(KERN_ERR "%s: Error %d configuring card\n",
1526 dev->name, err);
1527 return err;
1528 }
1529
1530 /* Fire things up again */
1531 hermes_set_irqmask(hw, ORINOCO_INTEN);
1532 err = hermes_enable_port(hw, 0);
1533 if (err) {
1534 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1535 dev->name, err);
1536 return err;
1537 }
1538
1539 netif_start_queue(dev);
1540
1541 return 0;
1542}
David Kilroy21312662009-02-04 23:05:47 +00001543EXPORT_SYMBOL(__orinoco_up);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544
1545int __orinoco_down(struct net_device *dev)
1546{
1547 struct orinoco_private *priv = netdev_priv(dev);
1548 struct hermes *hw = &priv->hw;
1549 int err;
1550
1551 netif_stop_queue(dev);
1552
David Kilroya94e8422009-02-04 23:05:44 +00001553 if (!priv->hw_unavailable) {
1554 if (!priv->broken_disableport) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 err = hermes_disable_port(hw, 0);
1556 if (err) {
1557 /* Some firmwares (e.g. Intersil 1.3.x) seem
1558 * to have problems disabling the port, oh
1559 * well, too bad. */
1560 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1561 dev->name, err);
1562 priv->broken_disableport = 1;
1563 }
1564 }
1565 hermes_set_irqmask(hw, 0);
1566 hermes_write_regn(hw, EVACK, 0xffff);
1567 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001568
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 /* firmware will have to reassociate */
1570 netif_carrier_off(dev);
1571 priv->last_linkstatus = 0xffff;
1572
1573 return 0;
1574}
David Kilroy21312662009-02-04 23:05:47 +00001575EXPORT_SYMBOL(__orinoco_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Pavel Roskin37a6c612006-04-07 04:10:49 -04001577static int orinoco_allocate_fid(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578{
1579 struct orinoco_private *priv = netdev_priv(dev);
1580 struct hermes *hw = &priv->hw;
1581 int err;
1582
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Gibsonb24d4582005-05-12 20:04:16 -04001584 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 /* Try workaround for old Symbol firmware bug */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1587 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Kilroy21312662009-02-04 23:05:47 +00001588
1589 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1590 "(old Symbol firmware?). Work around %s\n",
1591 dev->name, err ? "failed!" : "ok.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 }
1593
1594 return err;
1595}
1596
Pavel Roskin37a6c612006-04-07 04:10:49 -04001597int orinoco_reinit_firmware(struct net_device *dev)
1598{
1599 struct orinoco_private *priv = netdev_priv(dev);
1600 struct hermes *hw = &priv->hw;
1601 int err;
1602
1603 err = hermes_init(hw);
Andrey Borzenkov0df6cbb2008-10-12 20:15:43 +04001604 if (priv->do_fw_download && !err) {
1605 err = orinoco_download(priv);
1606 if (err)
1607 priv->do_fw_download = 0;
1608 }
Pavel Roskin37a6c612006-04-07 04:10:49 -04001609 if (!err)
1610 err = orinoco_allocate_fid(dev);
1611
1612 return err;
1613}
David Kilroy21312662009-02-04 23:05:47 +00001614EXPORT_SYMBOL(orinoco_reinit_firmware);
Pavel Roskin37a6c612006-04-07 04:10:49 -04001615
David Kilroycb1576a2009-02-04 23:05:56 +00001616int __orinoco_program_rids(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
1618 struct orinoco_private *priv = netdev_priv(dev);
1619 hermes_t *hw = &priv->hw;
1620 int err;
1621 struct hermes_idstring idbuf;
1622
1623 /* Set the MAC address */
1624 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1625 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1626 if (err) {
1627 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1628 dev->name, err);
1629 return err;
1630 }
1631
1632 /* Set up the link mode */
1633 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1634 priv->port_type);
1635 if (err) {
1636 printk(KERN_ERR "%s: Error %d setting port type\n",
1637 dev->name, err);
1638 return err;
1639 }
1640 /* Set the channel/frequency */
David Gibsond51d8b12005-05-12 20:03:36 -04001641 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1642 err = hermes_write_wordrec(hw, USER_BAP,
1643 HERMES_RID_CNFOWNCHANNEL,
1644 priv->channel);
1645 if (err) {
1646 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1647 dev->name, err, priv->channel);
1648 return err;
1649 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 }
1651
1652 if (priv->has_ibss) {
1653 u16 createibss;
1654
1655 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1656 printk(KERN_WARNING "%s: This firmware requires an "
1657 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1658 /* With wvlan_cs, in this case, we would crash.
1659 * hopefully, this driver will behave better...
1660 * Jean II */
1661 createibss = 0;
1662 } else {
1663 createibss = priv->createibss;
1664 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001665
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 err = hermes_write_wordrec(hw, USER_BAP,
1667 HERMES_RID_CNFCREATEIBSS,
1668 createibss);
1669 if (err) {
1670 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1671 dev->name, err);
1672 return err;
1673 }
1674 }
1675
Christoph Hellwig16739b02005-06-19 01:27:51 +02001676 /* Set the desired BSSID */
1677 err = __orinoco_hw_set_wap(priv);
1678 if (err) {
1679 printk(KERN_ERR "%s: Error %d setting AP address\n",
1680 dev->name, err);
1681 return err;
1682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 /* Set the desired ESSID */
1684 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1685 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1686 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1687 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
David Kilroyb2f30a02009-02-04 23:05:46 +00001688 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1689 &idbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 if (err) {
1691 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1692 dev->name, err);
1693 return err;
1694 }
1695 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
David Kilroyb2f30a02009-02-04 23:05:46 +00001696 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1697 &idbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 if (err) {
1699 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1700 dev->name, err);
1701 return err;
1702 }
1703
1704 /* Set the station name */
1705 idbuf.len = cpu_to_le16(strlen(priv->nick));
1706 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1707 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1708 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1709 &idbuf);
1710 if (err) {
1711 printk(KERN_ERR "%s: Error %d setting nickname\n",
1712 dev->name, err);
1713 return err;
1714 }
1715
1716 /* Set AP density */
1717 if (priv->has_sensitivity) {
1718 err = hermes_write_wordrec(hw, USER_BAP,
1719 HERMES_RID_CNFSYSTEMSCALE,
1720 priv->ap_density);
1721 if (err) {
David Kilroyb2f30a02009-02-04 23:05:46 +00001722 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 "Disabling sensitivity control\n",
1724 dev->name, err);
1725
1726 priv->has_sensitivity = 0;
1727 }
1728 }
1729
1730 /* Set RTS threshold */
1731 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1732 priv->rts_thresh);
1733 if (err) {
1734 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1735 dev->name, err);
1736 return err;
1737 }
1738
1739 /* Set fragmentation threshold or MWO robustness */
1740 if (priv->has_mwo)
1741 err = hermes_write_wordrec(hw, USER_BAP,
1742 HERMES_RID_CNFMWOROBUST_AGERE,
1743 priv->mwo_robust);
1744 else
1745 err = hermes_write_wordrec(hw, USER_BAP,
1746 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1747 priv->frag_thresh);
1748 if (err) {
1749 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1750 dev->name, err);
1751 return err;
1752 }
1753
1754 /* Set bitrate */
1755 err = __orinoco_hw_set_bitrate(priv);
1756 if (err) {
1757 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1758 dev->name, err);
1759 return err;
1760 }
1761
1762 /* Set power management */
1763 if (priv->has_pm) {
1764 err = hermes_write_wordrec(hw, USER_BAP,
1765 HERMES_RID_CNFPMENABLED,
1766 priv->pm_on);
1767 if (err) {
1768 printk(KERN_ERR "%s: Error %d setting up PM\n",
1769 dev->name, err);
1770 return err;
1771 }
1772
1773 err = hermes_write_wordrec(hw, USER_BAP,
1774 HERMES_RID_CNFMULTICASTRECEIVE,
1775 priv->pm_mcast);
1776 if (err) {
1777 printk(KERN_ERR "%s: Error %d setting up PM\n",
1778 dev->name, err);
1779 return err;
1780 }
1781 err = hermes_write_wordrec(hw, USER_BAP,
1782 HERMES_RID_CNFMAXSLEEPDURATION,
1783 priv->pm_period);
1784 if (err) {
1785 printk(KERN_ERR "%s: Error %d setting up PM\n",
1786 dev->name, err);
1787 return err;
1788 }
1789 err = hermes_write_wordrec(hw, USER_BAP,
1790 HERMES_RID_CNFPMHOLDOVERDURATION,
1791 priv->pm_timeout);
1792 if (err) {
1793 printk(KERN_ERR "%s: Error %d setting up PM\n",
1794 dev->name, err);
1795 return err;
1796 }
1797 }
1798
1799 /* Set preamble - only for Symbol so far... */
1800 if (priv->has_preamble) {
1801 err = hermes_write_wordrec(hw, USER_BAP,
1802 HERMES_RID_CNFPREAMBLE_SYMBOL,
1803 priv->preamble);
1804 if (err) {
1805 printk(KERN_ERR "%s: Error %d setting preamble\n",
1806 dev->name, err);
1807 return err;
1808 }
1809 }
1810
1811 /* Set up encryption */
David Kilroyd03032a2008-08-21 23:28:02 +01001812 if (priv->has_wep || priv->has_wpa) {
1813 err = __orinoco_hw_setup_enc(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 if (err) {
David Kilroyd03032a2008-08-21 23:28:02 +01001815 printk(KERN_ERR "%s: Error %d activating encryption\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 dev->name, err);
1817 return err;
1818 }
1819 }
1820
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001821 if (priv->iw_mode == IW_MODE_MONITOR) {
1822 /* Enable monitor mode */
1823 dev->type = ARPHRD_IEEE80211;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001824 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001825 HERMES_TEST_MONITOR, 0, NULL);
1826 } else {
1827 /* Disable monitor mode */
1828 dev->type = ARPHRD_ETHER;
1829 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1830 HERMES_TEST_STOP, 0, NULL);
1831 }
1832 if (err)
1833 return err;
1834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 /* Set promiscuity / multicast*/
1836 priv->promiscuous = 0;
1837 priv->mc_count = 0;
Herbert Xu932ff272006-06-09 12:20:56 -07001838
1839 /* FIXME: what about netif_tx_lock */
1840 __orinoco_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
1842 return 0;
1843}
1844
David Kilroy5865d012009-02-04 23:05:54 +00001845/* FIXME: return int? */
1846static void
1847__orinoco_set_multicast_list(struct net_device *dev)
1848{
1849 struct orinoco_private *priv = netdev_priv(dev);
1850 int err = 0;
1851 int promisc, mc_count;
1852
1853 /* The Hermes doesn't seem to have an allmulti mode, so we go
1854 * into promiscuous mode and let the upper levels deal. */
1855 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1856 (dev->mc_count > MAX_MULTICAST(priv))) {
1857 promisc = 1;
1858 mc_count = 0;
1859 } else {
1860 promisc = 0;
1861 mc_count = dev->mc_count;
1862 }
1863
1864 err = __orinoco_hw_set_multicast_list(priv, dev->mc_list, mc_count,
1865 promisc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866}
1867
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868/* This must be called from user context, without locks held - use
1869 * schedule_work() */
David Kilroycb1576a2009-02-04 23:05:56 +00001870void orinoco_reset(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871{
David Howellsc4028952006-11-22 14:57:56 +00001872 struct orinoco_private *priv =
1873 container_of(work, struct orinoco_private, reset_work);
1874 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001876 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 unsigned long flags;
1878
1879 if (orinoco_lock(priv, &flags) != 0)
1880 /* When the hardware becomes available again, whatever
1881 * detects that is responsible for re-initializing
1882 * it. So no need for anything further */
1883 return;
1884
1885 netif_stop_queue(dev);
1886
1887 /* Shut off interrupts. Depending on what state the hardware
1888 * is in, this might not work, but we'll try anyway */
1889 hermes_set_irqmask(hw, 0);
1890 hermes_write_regn(hw, EVACK, 0xffff);
1891
1892 priv->hw_unavailable++;
1893 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1894 netif_carrier_off(dev);
1895
1896 orinoco_unlock(priv, &flags);
1897
David Kilroy6fe9deb2009-02-04 23:05:43 +00001898 /* Scanning support: Cleanup of driver struct */
Dan Williams1e3428e2007-10-10 23:56:25 -04001899 orinoco_clear_scan_results(priv, 0);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001900 priv->scan_inprogress = 0;
1901
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001902 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001904 if (err) {
1905 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1906 "performing hard reset\n", dev->name, err);
1907 goto disable;
1908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 }
1910
1911 err = orinoco_reinit_firmware(dev);
1912 if (err) {
1913 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1914 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001915 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 }
1917
David Kilroyb2f30a02009-02-04 23:05:46 +00001918 /* This has to be called from user context */
1919 spin_lock_irq(&priv->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
1921 priv->hw_unavailable--;
1922
1923 /* priv->open or priv->hw_unavailable might have changed while
1924 * we dropped the lock */
David Kilroya94e8422009-02-04 23:05:44 +00001925 if (priv->open && (!priv->hw_unavailable)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 err = __orinoco_up(dev);
1927 if (err) {
1928 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1929 dev->name, err);
1930 } else
1931 dev->trans_start = jiffies;
1932 }
1933
1934 spin_unlock_irq(&priv->lock);
1935
1936 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001937 disable:
1938 hermes_set_irqmask(hw, 0);
1939 netif_device_detach(dev);
1940 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941}
1942
1943/********************************************************************/
1944/* Interrupt handler */
1945/********************************************************************/
1946
1947static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1948{
1949 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1950}
1951
1952static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1953{
1954 /* This seems to happen a fair bit under load, but ignoring it
1955 seems to work fine...*/
1956 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1957 dev->name);
1958}
1959
David Howells7d12e782006-10-05 14:55:46 +01001960irqreturn_t orinoco_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961{
Jeff Garzikc31f28e2006-10-06 14:56:04 -04001962 struct net_device *dev = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 struct orinoco_private *priv = netdev_priv(dev);
1964 hermes_t *hw = &priv->hw;
1965 int count = MAX_IRQLOOPS_PER_IRQ;
1966 u16 evstat, events;
David Kilroy21312662009-02-04 23:05:47 +00001967 /* These are used to detect a runaway interrupt situation.
1968 *
1969 * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1970 * we panic and shut down the hardware
1971 */
1972 /* jiffies value the last time we were called */
1973 static int last_irq_jiffy; /* = 0 */
1974 static int loops_this_jiffy; /* = 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 unsigned long flags;
1976
1977 if (orinoco_lock(priv, &flags) != 0) {
1978 /* If hw is unavailable - we don't know if the irq was
1979 * for us or not */
1980 return IRQ_HANDLED;
1981 }
1982
1983 evstat = hermes_read_regn(hw, EVSTAT);
1984 events = evstat & hw->inten;
David Kilroya94e8422009-02-04 23:05:44 +00001985 if (!events) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 orinoco_unlock(priv, &flags);
1987 return IRQ_NONE;
1988 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001989
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 if (jiffies != last_irq_jiffy)
1991 loops_this_jiffy = 0;
1992 last_irq_jiffy = jiffies;
1993
1994 while (events && count--) {
1995 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
1996 printk(KERN_WARNING "%s: IRQ handler is looping too "
1997 "much! Resetting.\n", dev->name);
1998 /* Disable interrupts for now */
1999 hermes_set_irqmask(hw, 0);
2000 schedule_work(&priv->reset_work);
2001 break;
2002 }
2003
2004 /* Check the card hasn't been removed */
David Kilroya94e8422009-02-04 23:05:44 +00002005 if (!hermes_present(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 DEBUG(0, "orinoco_interrupt(): card removed\n");
2007 break;
2008 }
2009
2010 if (events & HERMES_EV_TICK)
2011 __orinoco_ev_tick(dev, hw);
2012 if (events & HERMES_EV_WTERR)
2013 __orinoco_ev_wterr(dev, hw);
2014 if (events & HERMES_EV_INFDROP)
2015 __orinoco_ev_infdrop(dev, hw);
2016 if (events & HERMES_EV_INFO)
2017 __orinoco_ev_info(dev, hw);
2018 if (events & HERMES_EV_RX)
2019 __orinoco_ev_rx(dev, hw);
2020 if (events & HERMES_EV_TXEXC)
2021 __orinoco_ev_txexc(dev, hw);
2022 if (events & HERMES_EV_TX)
2023 __orinoco_ev_tx(dev, hw);
2024 if (events & HERMES_EV_ALLOC)
2025 __orinoco_ev_alloc(dev, hw);
David Kilroy6fe9deb2009-02-04 23:05:43 +00002026
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002027 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
2029 evstat = hermes_read_regn(hw, EVSTAT);
2030 events = evstat & hw->inten;
2031 };
2032
2033 orinoco_unlock(priv, &flags);
2034 return IRQ_HANDLED;
2035}
David Kilroy21312662009-02-04 23:05:47 +00002036EXPORT_SYMBOL(orinoco_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
2038/********************************************************************/
David Kilroy39d1ffe2008-11-22 10:37:28 +00002039/* Power management */
2040/********************************************************************/
2041#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
2042static int orinoco_pm_notifier(struct notifier_block *notifier,
2043 unsigned long pm_event,
2044 void *unused)
2045{
2046 struct orinoco_private *priv = container_of(notifier,
2047 struct orinoco_private,
2048 pm_notifier);
2049
2050 /* All we need to do is cache the firmware before suspend, and
2051 * release it when we come out.
2052 *
2053 * Only need to do this if we're downloading firmware. */
2054 if (!priv->do_fw_download)
2055 return NOTIFY_DONE;
2056
2057 switch (pm_event) {
2058 case PM_HIBERNATION_PREPARE:
2059 case PM_SUSPEND_PREPARE:
2060 orinoco_cache_fw(priv, 0);
2061 break;
2062
2063 case PM_POST_RESTORE:
2064 /* Restore from hibernation failed. We need to clean
2065 * up in exactly the same way, so fall through. */
2066 case PM_POST_HIBERNATION:
2067 case PM_POST_SUSPEND:
2068 orinoco_uncache_fw(priv);
2069 break;
2070
2071 case PM_RESTORE_PREPARE:
2072 default:
2073 break;
2074 }
2075
2076 return NOTIFY_DONE;
2077}
David S. Millerf11c1792009-02-25 00:02:05 -08002078
2079static void orinoco_register_pm_notifier(struct orinoco_private *priv)
2080{
2081 priv->pm_notifier.notifier_call = orinoco_pm_notifier;
2082 register_pm_notifier(&priv->pm_notifier);
2083}
2084
2085static void orinoco_unregister_pm_notifier(struct orinoco_private *priv)
2086{
2087 unregister_pm_notifier(&priv->pm_notifier);
2088}
David Kilroy39d1ffe2008-11-22 10:37:28 +00002089#else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
David S. Millerf11c1792009-02-25 00:02:05 -08002090#define orinoco_register_pm_notifier(priv) do { } while(0)
2091#define orinoco_unregister_pm_notifier(priv) do { } while(0)
David Kilroy39d1ffe2008-11-22 10:37:28 +00002092#endif
2093
2094/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095/* Initialization */
2096/********************************************************************/
2097
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098static int orinoco_init(struct net_device *dev)
2099{
2100 struct orinoco_private *priv = netdev_priv(dev);
2101 hermes_t *hw = &priv->hw;
2102 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 /* No need to lock, the hw_unavailable flag is already set in
2105 * alloc_orinocodev() */
Johannes Berg2c7060022008-10-30 22:09:54 +01002106 priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
2108 /* Initialize the firmware */
Pavel Roskin37a6c612006-04-07 04:10:49 -04002109 err = hermes_init(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 if (err != 0) {
2111 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2112 dev->name, err);
2113 goto out;
2114 }
2115
David Kilroya2d1a422009-06-18 23:21:18 +01002116 err = determine_fw_capabilities(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 if (err != 0) {
2118 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2119 dev->name);
2120 goto out;
2121 }
2122
David Kilroy3994d502008-08-21 23:27:54 +01002123 if (priv->do_fw_download) {
David Kilroy39d1ffe2008-11-22 10:37:28 +00002124#ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
David Kilroy74734312008-11-22 10:37:25 +00002125 orinoco_cache_fw(priv, 0);
David Kilroy39d1ffe2008-11-22 10:37:28 +00002126#endif
David Kilroy74734312008-11-22 10:37:25 +00002127
David Kilroy3994d502008-08-21 23:27:54 +01002128 err = orinoco_download(priv);
2129 if (err)
2130 priv->do_fw_download = 0;
2131
2132 /* Check firmware version again */
David Kilroya2d1a422009-06-18 23:21:18 +01002133 err = determine_fw_capabilities(priv);
David Kilroy3994d502008-08-21 23:27:54 +01002134 if (err != 0) {
2135 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2136 dev->name);
2137 goto out;
2138 }
2139 }
2140
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 if (priv->has_port3)
David Kilroyb2f30a02009-02-04 23:05:46 +00002142 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n",
2143 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 if (priv->has_ibss)
2145 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2146 dev->name);
2147 if (priv->has_wep) {
David Kilroy21312662009-02-04 23:05:47 +00002148 printk(KERN_DEBUG "%s: WEP supported, %s-bit key\n", dev->name,
2149 priv->has_big_wep ? "104" : "40");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 }
David Kilroy23edcc42008-08-21 23:28:05 +01002151 if (priv->has_wpa) {
David Kilroyd03032a2008-08-21 23:28:02 +01002152 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
David Kilroy23edcc42008-08-21 23:28:05 +01002153 if (orinoco_mic_init(priv)) {
2154 printk(KERN_ERR "%s: Failed to setup MIC crypto "
2155 "algorithm. Disabling WPA support\n", dev->name);
2156 priv->has_wpa = 0;
2157 }
2158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
David Kilroy01632fa2008-08-21 23:27:58 +01002160 /* Now we have the firmware capabilities, allocate appropiate
2161 * sized scan buffers */
2162 if (orinoco_bss_data_allocate(priv))
2163 goto out;
2164 orinoco_bss_data_init(priv);
2165
David Kilroye9e3d012009-06-18 23:21:19 +01002166 err = orinoco_hw_read_card_settings(priv, dev->dev_addr);
2167 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
Pavel Roskin37a6c612006-04-07 04:10:49 -04002170 err = orinoco_allocate_fid(dev);
2171 if (err) {
2172 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2173 dev->name);
2174 goto out;
2175 }
2176
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 /* Set up the default configuration */
2178 priv->iw_mode = IW_MODE_INFRA;
2179 /* By default use IEEE/IBSS ad-hoc mode if we have it */
David Kilroya94e8422009-02-04 23:05:44 +00002180 priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04002182 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
2184 priv->promiscuous = 0;
David Kilroy4ae6ee22008-08-21 23:27:59 +01002185 priv->encode_alg = IW_ENCODE_ALG_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 priv->tx_key = 0;
David Kilroyd03032a2008-08-21 23:28:02 +01002187 priv->wpa_enabled = 0;
2188 priv->tkip_cm_active = 0;
2189 priv->key_mgmt = 0;
2190 priv->wpa_ie_len = 0;
2191 priv->wpa_ie = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 /* Make the hardware available, as long as it hasn't been
2194 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2195 spin_lock_irq(&priv->lock);
2196 priv->hw_unavailable--;
2197 spin_unlock_irq(&priv->lock);
2198
2199 printk(KERN_DEBUG "%s: ready\n", dev->name);
2200
2201 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 return err;
2203}
2204
Andrey Borzenkov89ea4092009-01-21 20:46:46 +03002205static const struct net_device_ops orinoco_netdev_ops = {
2206 .ndo_init = orinoco_init,
2207 .ndo_open = orinoco_open,
2208 .ndo_stop = orinoco_stop,
2209 .ndo_start_xmit = orinoco_xmit,
2210 .ndo_set_multicast_list = orinoco_set_multicast_list,
2211 .ndo_change_mtu = orinoco_change_mtu,
2212 .ndo_tx_timeout = orinoco_tx_timeout,
2213 .ndo_get_stats = orinoco_get_stats,
2214};
2215
David Kilroy3994d502008-08-21 23:27:54 +01002216struct net_device
2217*alloc_orinocodev(int sizeof_card,
2218 struct device *device,
2219 int (*hard_reset)(struct orinoco_private *),
2220 int (*stop_fw)(struct orinoco_private *, int))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221{
2222 struct net_device *dev;
2223 struct orinoco_private *priv;
2224
2225 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
Andrey Borzenkove129a942009-01-21 21:55:29 +03002226 if (!dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 return NULL;
2228 priv = netdev_priv(dev);
2229 priv->ndev = dev;
2230 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002231 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 + sizeof(struct orinoco_private));
2233 else
2234 priv->card = NULL;
David Kilroy3994d502008-08-21 23:27:54 +01002235 priv->dev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
2237 /* Setup / override net_device fields */
Andrey Borzenkov89ea4092009-01-21 20:46:46 +03002238 dev->netdev_ops = &orinoco_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 dev->watchdog_timeo = HZ; /* 1 second timeout */
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002240 dev->ethtool_ops = &orinoco_ethtool_ops;
Andrey Borzenkove129a942009-01-21 21:55:29 +03002241 dev->wireless_handlers = &orinoco_handler_def;
Pavel Roskin343c6862005-09-09 18:43:02 -04002242#ifdef WIRELESS_SPY
2243 priv->wireless_data.spy_data = &priv->spy_data;
2244 dev->wireless_data = &priv->wireless_data;
2245#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 /* we use the default eth_mac_addr for setting the MAC addr */
2247
David Kilroy23edcc42008-08-21 23:28:05 +01002248 /* Reserve space in skb for the SNAP header */
2249 dev->hard_header_len += ENCAPS_OVERHEAD;
2250
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 /* Set up default callbacks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 priv->hard_reset = hard_reset;
David Kilroy3994d502008-08-21 23:27:54 +01002253 priv->stop_fw = stop_fw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
2255 spin_lock_init(&priv->lock);
2256 priv->open = 0;
2257 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2258 * before anything else touches the
2259 * hardware */
David Howellsc4028952006-11-22 14:57:56 +00002260 INIT_WORK(&priv->reset_work, orinoco_reset);
2261 INIT_WORK(&priv->join_work, orinoco_join_ap);
2262 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
David Kilroy31afcef2008-08-21 23:28:04 +01002264 INIT_LIST_HEAD(&priv->rx_list);
2265 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
2266 (unsigned long) dev);
2267
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 netif_carrier_off(dev);
2269 priv->last_linkstatus = 0xffff;
2270
Andrey Borzenkov2bfc5cb2009-02-28 23:09:09 +03002271#if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
David Kilroy2cea7b22008-11-22 10:37:26 +00002272 priv->cached_pri_fw = NULL;
Andrey Borzenkov4fb30782008-10-19 12:06:11 +04002273 priv->cached_fw = NULL;
Andrey Borzenkov2bfc5cb2009-02-28 23:09:09 +03002274#endif
Andrey Borzenkov4fb30782008-10-19 12:06:11 +04002275
David Kilroy39d1ffe2008-11-22 10:37:28 +00002276 /* Register PM notifiers */
David S. Millerf11c1792009-02-25 00:02:05 -08002277 orinoco_register_pm_notifier(priv);
David Kilroy39d1ffe2008-11-22 10:37:28 +00002278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 return dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280}
David Kilroy21312662009-02-04 23:05:47 +00002281EXPORT_SYMBOL(alloc_orinocodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
2283void free_orinocodev(struct net_device *dev)
2284{
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002285 struct orinoco_private *priv = netdev_priv(dev);
David Kilroy20953ad2009-01-07 00:23:55 +00002286 struct orinoco_rx_data *rx_data, *temp;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002287
David Kilroy20953ad2009-01-07 00:23:55 +00002288 /* If the tasklet is scheduled when we call tasklet_kill it
2289 * will run one final time. However the tasklet will only
2290 * drain priv->rx_list if the hw is still available. */
David Kilroy31afcef2008-08-21 23:28:04 +01002291 tasklet_kill(&priv->rx_tasklet);
David Kilroy74734312008-11-22 10:37:25 +00002292
David Kilroy20953ad2009-01-07 00:23:55 +00002293 /* Explicitly drain priv->rx_list */
2294 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
2295 list_del(&rx_data->list);
2296
2297 dev_kfree_skb(rx_data->skb);
2298 kfree(rx_data->desc);
2299 kfree(rx_data);
2300 }
2301
David S. Millerf11c1792009-02-25 00:02:05 -08002302 orinoco_unregister_pm_notifier(priv);
David Kilroy74734312008-11-22 10:37:25 +00002303 orinoco_uncache_fw(priv);
2304
David Kilroyd03032a2008-08-21 23:28:02 +01002305 priv->wpa_ie_len = 0;
2306 kfree(priv->wpa_ie);
David Kilroy23edcc42008-08-21 23:28:05 +01002307 orinoco_mic_free(priv);
Dan Williams1e3428e2007-10-10 23:56:25 -04002308 orinoco_bss_data_free(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 free_netdev(dev);
2310}
David Kilroy21312662009-02-04 23:05:47 +00002311EXPORT_SYMBOL(free_orinocodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002313static void orinoco_get_drvinfo(struct net_device *dev,
2314 struct ethtool_drvinfo *info)
2315{
2316 struct orinoco_private *priv = netdev_priv(dev);
2317
2318 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
2319 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
2320 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07002321 if (dev->dev.parent)
Kay Sieversfb28ad32008-11-10 13:55:14 -08002322 strncpy(info->bus_info, dev_name(dev->dev.parent),
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002323 sizeof(info->bus_info) - 1);
2324 else
2325 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
2326 "PCMCIA %p", priv->hw.iobase);
2327}
2328
Jeff Garzik7282d492006-09-13 14:30:00 -04002329static const struct ethtool_ops orinoco_ethtool_ops = {
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002330 .get_drvinfo = orinoco_get_drvinfo,
2331 .get_link = ethtool_op_get_link,
2332};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
2334/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335/* Module initialization */
2336/********************************************************************/
2337
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338/* Can't be declared "const" or the whole __initdata section will
2339 * become const */
2340static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
2341 " (David Gibson <hermes@gibson.dropbear.id.au>, "
2342 "Pavel Roskin <proski@gnu.org>, et al)";
2343
2344static int __init init_orinoco(void)
2345{
2346 printk(KERN_DEBUG "%s\n", version);
2347 return 0;
2348}
2349
2350static void __exit exit_orinoco(void)
2351{
2352}
2353
2354module_init(init_orinoco);
2355module_exit(exit_orinoco);