blob: dab6649ad0cbcc05e7dd4b552b9245aa942b27c3 [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>
David Kilroy8e638262009-06-18 23:21:24 +010083#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#include <linux/netdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#include <linux/etherdevice.h>
Christoph Hellwig1fab2e82005-06-19 01:27:40 +020086#include <linux/ethtool.h>
David Kilroy39d1ffe2008-11-22 10:37:28 +000087#include <linux/suspend.h>
Pavel Roskin9c974fb2006-08-15 20:45:03 -040088#include <linux/if_arp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#include <linux/wireless.h>
Johannes Berg2c7060022008-10-30 22:09:54 +010090#include <linux/ieee80211.h>
Christoph Hellwig620554e2005-06-19 01:27:33 +020091#include <net/iw_handler.h>
David Kilroyea60a6a2009-06-18 23:21:26 +010092#include <net/cfg80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#include "hermes_rid.h"
David Kilroy3994d502008-08-21 23:27:54 +010095#include "hermes_dld.h"
David Kilroy712a4342009-02-04 23:05:55 +000096#include "hw.h"
David Kilroyfb791b12009-02-04 23:05:50 +000097#include "scan.h"
David Kilroy4adb4742009-02-04 23:05:51 +000098#include "mic.h"
David Kilroy37a2e562009-02-04 23:05:52 +000099#include "fw.h"
David Kilroycb1576a2009-02-04 23:05:56 +0000100#include "wext.h"
David Kilroyea60a6a2009-06-18 23:21:26 +0100101#include "cfg.h"
David Kilroycb1576a2009-02-04 23:05:56 +0000102#include "main.h"
David Kilroyfb791b12009-02-04 23:05:50 +0000103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#include "orinoco.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106/********************************************************************/
107/* Module information */
108/********************************************************************/
109
David Kilroyb2f30a02009-02-04 23:05:46 +0000110MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
111 "David Gibson <hermes@gibson.dropbear.id.au>");
112MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
113 "and similar wireless cards");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114MODULE_LICENSE("Dual MPL/GPL");
115
116/* Level of debugging. Used in the macros in orinoco.h */
117#ifdef ORINOCO_DEBUG
118int orinoco_debug = ORINOCO_DEBUG;
David Kilroy21312662009-02-04 23:05:47 +0000119EXPORT_SYMBOL(orinoco_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120module_param(orinoco_debug, int, 0644);
121MODULE_PARM_DESC(orinoco_debug, "Debug level");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#endif
123
124static int suppress_linkstatus; /* = 0 */
125module_param(suppress_linkstatus, bool, 0644);
126MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
David Kilroyb2f30a02009-02-04 23:05:46 +0000127
David Gibson7bb7c3a2005-05-12 20:02:10 -0400128static int ignore_disconnect; /* = 0 */
129module_param(ignore_disconnect, int, 0644);
David Kilroyb2f30a02009-02-04 23:05:46 +0000130MODULE_PARM_DESC(ignore_disconnect,
131 "Don't report lost link to the network layer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
David Kilroycb1576a2009-02-04 23:05:56 +0000133int force_monitor; /* = 0 */
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200134module_param(force_monitor, int, 0644);
135MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/* Internal constants */
139/********************************************************************/
140
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200141/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
142static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
143#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define ORINOCO_MIN_MTU 256
Johannes Berg2c7060022008-10-30 22:09:54 +0100146#define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define MAX_IRQLOOPS_PER_IRQ 10
149#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
150 * how many events the
151 * device could
152 * legitimately generate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154#define DUMMY_FID 0xFFFF
155
156/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
157 HERMES_MAX_MULTICAST : 0)*/
158#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
159
160#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
161 | HERMES_EV_TX | HERMES_EV_TXEXC \
162 | HERMES_EV_WTERR | HERMES_EV_INFO \
David Kilroya94e8422009-02-04 23:05:44 +0000163 | HERMES_EV_INFDROP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Jeff Garzik7282d492006-09-13 14:30:00 -0400165static const struct ethtool_ops orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +0200166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168/* Data types */
169/********************************************************************/
170
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400171/* Beginning of the Tx descriptor, used in TxExc handling */
172struct hermes_txexc_data {
173 struct hermes_tx_descriptor desc;
Pavel Roskind133ae42005-09-23 04:18:06 -0400174 __le16 frame_ctl;
175 __le16 duration_id;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200176 u8 addr1[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177} __attribute__ ((packed));
178
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200179/* Rx frame header except compatibility 802.3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180struct hermes_rx_descriptor {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200181 /* Control */
Pavel Roskind133ae42005-09-23 04:18:06 -0400182 __le16 status;
183 __le32 time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 u8 silence;
185 u8 signal;
186 u8 rate;
187 u8 rxflow;
Pavel Roskind133ae42005-09-23 04:18:06 -0400188 __le32 reserved;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200189
190 /* 802.11 header */
Pavel Roskind133ae42005-09-23 04:18:06 -0400191 __le16 frame_ctl;
192 __le16 duration_id;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200193 u8 addr1[ETH_ALEN];
194 u8 addr2[ETH_ALEN];
195 u8 addr3[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400196 __le16 seq_ctl;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200197 u8 addr4[ETH_ALEN];
198
199 /* Data length */
Pavel Roskind133ae42005-09-23 04:18:06 -0400200 __le16 data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201} __attribute__ ((packed));
202
David Kilroy47166792009-01-07 00:43:54 +0000203struct orinoco_rx_data {
204 struct hermes_rx_descriptor *desc;
205 struct sk_buff *skb;
206 struct list_head list;
207};
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209/********************************************************************/
210/* Function prototypes */
211/********************************************************************/
212
David Kilroy721aa2f2009-06-18 23:21:31 +0100213static int __orinoco_set_multicast_list(struct net_device *dev);
David Kilroy6415f7d2009-06-18 23:21:30 +0100214static int __orinoco_up(struct orinoco_private *priv);
215static int __orinoco_down(struct orinoco_private *priv);
David Kilroy721aa2f2009-06-18 23:21:31 +0100216static int __orinoco_commit(struct orinoco_private *priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218/********************************************************************/
219/* Internal helper functions */
220/********************************************************************/
221
David Kilroycb1576a2009-02-04 23:05:56 +0000222void set_port_type(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224 switch (priv->iw_mode) {
225 case IW_MODE_INFRA:
226 priv->port_type = 1;
227 priv->createibss = 0;
228 break;
229 case IW_MODE_ADHOC:
230 if (priv->prefer_port3) {
231 priv->port_type = 3;
232 priv->createibss = 0;
233 } else {
234 priv->port_type = priv->ibss_port;
235 priv->createibss = 1;
236 }
237 break;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200238 case IW_MODE_MONITOR:
239 priv->port_type = 3;
240 priv->createibss = 0;
241 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 default:
243 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
244 priv->ndev->name);
245 }
246}
247
David Kilroy3994d502008-08-21 23:27:54 +0100248/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249/* Device methods */
250/********************************************************************/
251
252static int orinoco_open(struct net_device *dev)
253{
David Kilroyea60a6a2009-06-18 23:21:26 +0100254 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 unsigned long flags;
256 int err;
257
258 if (orinoco_lock(priv, &flags) != 0)
259 return -EBUSY;
260
David Kilroya2608362009-06-18 23:21:23 +0100261 err = __orinoco_up(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
David Kilroya94e8422009-02-04 23:05:44 +0000263 if (!err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 priv->open = 1;
265
266 orinoco_unlock(priv, &flags);
267
268 return err;
269}
270
Christoph Hellwigad8f4512005-05-14 17:30:17 +0200271static int orinoco_stop(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
David Kilroyea60a6a2009-06-18 23:21:26 +0100273 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 int err = 0;
275
276 /* We mustn't use orinoco_lock() here, because we need to be
277 able to close the interface even if hw_unavailable is set
278 (e.g. as we're released after a PC Card removal) */
279 spin_lock_irq(&priv->lock);
280
281 priv->open = 0;
282
David Kilroya2608362009-06-18 23:21:23 +0100283 err = __orinoco_down(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 spin_unlock_irq(&priv->lock);
286
287 return err;
288}
289
290static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
291{
David Kilroyea60a6a2009-06-18 23:21:26 +0100292 struct orinoco_private *priv = ndev_priv(dev);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 return &priv->stats;
295}
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297static void orinoco_set_multicast_list(struct net_device *dev)
298{
David Kilroyea60a6a2009-06-18 23:21:26 +0100299 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 unsigned long flags;
301
302 if (orinoco_lock(priv, &flags) != 0) {
303 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
304 "called when hw_unavailable\n", dev->name);
305 return;
306 }
307
308 __orinoco_set_multicast_list(dev);
309 orinoco_unlock(priv, &flags);
310}
311
312static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
313{
David Kilroyea60a6a2009-06-18 23:21:26 +0100314 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
David Kilroya94e8422009-02-04 23:05:44 +0000316 if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return -EINVAL;
318
Johannes Berg2c7060022008-10-30 22:09:54 +0100319 /* MTU + encapsulation + header length */
David Kilroya94e8422009-02-04 23:05:44 +0000320 if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
321 (priv->nicbuf_size - ETH_HLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 return -EINVAL;
323
324 dev->mtu = new_mtu;
325
326 return 0;
327}
328
329/********************************************************************/
330/* Tx path */
331/********************************************************************/
332
333static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
334{
David Kilroyea60a6a2009-06-18 23:21:26 +0100335 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 struct net_device_stats *stats = &priv->stats;
337 hermes_t *hw = &priv->hw;
338 int err = 0;
339 u16 txfid = priv->txfid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 struct ethhdr *eh;
David Kilroy6eecad72008-08-21 23:27:56 +0100341 int tx_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 unsigned long flags;
343
David Kilroya94e8422009-02-04 23:05:44 +0000344 if (!netif_running(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 printk(KERN_ERR "%s: Tx on stopped device!\n",
346 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400347 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (netif_queue_stopped(dev)) {
David Kilroy6fe9deb2009-02-04 23:05:43 +0000351 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400353 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 if (orinoco_lock(priv, &flags) != 0) {
357 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
358 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400359 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 }
361
David Kilroya94e8422009-02-04 23:05:44 +0000362 if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /* Oops, the firmware hasn't established a connection,
David Kilroy6fe9deb2009-02-04 23:05:43 +0000364 silently drop the packet (this seems to be the
365 safest approach). */
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400366 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
368
Pavel Roskin8d5be082006-04-07 04:10:41 -0400369 /* Check packet length */
Pavel Roskina28dc812006-04-07 04:10:45 -0400370 if (skb->len < ETH_HLEN)
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400371 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
David Kilroy6eecad72008-08-21 23:27:56 +0100373 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
David Kilroy23edcc42008-08-21 23:28:05 +0100375 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
376 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
377 HERMES_TXCTRL_MIC;
378
David Kilroy6eecad72008-08-21 23:27:56 +0100379 if (priv->has_alt_txcntl) {
380 /* WPA enabled firmwares have tx_cntl at the end of
381 * the 802.11 header. So write zeroed descriptor and
382 * 802.11 header at the same time
383 */
384 char desc[HERMES_802_3_OFFSET];
385 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
386
387 memset(&desc, 0, sizeof(desc));
388
389 *txcntl = cpu_to_le16(tx_control);
390 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
391 txfid, 0);
392 if (err) {
393 if (net_ratelimit())
394 printk(KERN_ERR "%s: Error %d writing Tx "
395 "descriptor to BAP\n", dev->name, err);
396 goto busy;
397 }
398 } else {
399 struct hermes_tx_descriptor desc;
400
401 memset(&desc, 0, sizeof(desc));
402
403 desc.tx_control = cpu_to_le16(tx_control);
404 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
405 txfid, 0);
406 if (err) {
407 if (net_ratelimit())
408 printk(KERN_ERR "%s: Error %d writing Tx "
409 "descriptor to BAP\n", dev->name, err);
410 goto busy;
411 }
412
413 /* Clear the 802.11 header and data length fields - some
414 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
415 * if this isn't done. */
416 hermes_clear_words(hw, HERMES_DATA0,
417 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
418 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
David Kilroy23edcc42008-08-21 23:28:05 +0100420 eh = (struct ethhdr *)skb->data;
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 /* Encapsulate Ethernet-II frames */
423 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
Pavel Roskina28dc812006-04-07 04:10:45 -0400424 struct header_struct {
425 struct ethhdr eth; /* 802.3 header */
426 u8 encap[6]; /* 802.2 header */
427 } __attribute__ ((packed)) hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Pavel Roskina28dc812006-04-07 04:10:45 -0400429 /* Strip destination and source from the data */
430 skb_pull(skb, 2 * ETH_ALEN);
Pavel Roskina28dc812006-04-07 04:10:45 -0400431
432 /* And move them to a separate header */
433 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
434 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
435 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
436
David Kilroy23edcc42008-08-21 23:28:05 +0100437 /* Insert the SNAP header */
438 if (skb_headroom(skb) < sizeof(hdr)) {
439 printk(KERN_ERR
440 "%s: Not enough headroom for 802.2 headers %d\n",
441 dev->name, skb_headroom(skb));
442 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
David Kilroy23edcc42008-08-21 23:28:05 +0100444 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
445 memcpy(eh, &hdr, sizeof(hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 }
447
Pavel Roskina28dc812006-04-07 04:10:45 -0400448 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
David Kilroy23edcc42008-08-21 23:28:05 +0100449 txfid, HERMES_802_3_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (err) {
451 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
452 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400453 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455
David Kilroy23edcc42008-08-21 23:28:05 +0100456 /* Calculate Michael MIC */
457 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
458 u8 mic_buf[MICHAEL_MIC_LEN + 1];
459 u8 *mic;
460 size_t offset;
461 size_t len;
462
463 if (skb->len % 2) {
464 /* MIC start is on an odd boundary */
465 mic_buf[0] = skb->data[skb->len - 1];
466 mic = &mic_buf[1];
467 offset = skb->len - 1;
468 len = MICHAEL_MIC_LEN + 1;
469 } else {
470 mic = &mic_buf[0];
471 offset = skb->len;
472 len = MICHAEL_MIC_LEN;
473 }
474
David Kilroy4adb4742009-02-04 23:05:51 +0000475 orinoco_mic(priv->tx_tfm_mic,
David Kilroy23edcc42008-08-21 23:28:05 +0100476 priv->tkip_key[priv->tx_key].tx_mic,
477 eh->h_dest, eh->h_source, 0 /* priority */,
478 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
479
480 /* Write the MIC */
481 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
482 txfid, HERMES_802_3_OFFSET + offset);
483 if (err) {
484 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
485 dev->name, err);
486 goto busy;
487 }
488 }
489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 /* Finally, we actually initiate the send */
491 netif_stop_queue(dev);
492
493 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
494 txfid, NULL);
495 if (err) {
496 netif_start_queue(dev);
Andrew Mortonc367c212005-10-19 21:23:44 -0700497 if (net_ratelimit())
498 printk(KERN_ERR "%s: Error %d transmitting packet\n",
499 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400500 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502
503 dev->trans_start = jiffies;
David Kilroy23edcc42008-08-21 23:28:05 +0100504 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400505 goto ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400507 drop:
508 stats->tx_errors++;
509 stats->tx_dropped++;
510
511 ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 dev_kfree_skb(skb);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400514 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400516 busy:
Jiri Benc2c1bd262006-04-07 04:10:47 -0400517 if (err == -EIO)
518 schedule_work(&priv->reset_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 orinoco_unlock(priv, &flags);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400520 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521}
522
523static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
524{
David Kilroyea60a6a2009-06-18 23:21:26 +0100525 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 u16 fid = hermes_read_regn(hw, ALLOCFID);
527
528 if (fid != priv->txfid) {
529 if (fid != DUMMY_FID)
530 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
531 dev->name, fid);
532 return;
533 }
534
535 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
536}
537
538static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
539{
David Kilroyea60a6a2009-06-18 23:21:26 +0100540 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 struct net_device_stats *stats = &priv->stats;
542
543 stats->tx_packets++;
544
545 netif_wake_queue(dev);
546
547 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
548}
549
550static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
551{
David Kilroyea60a6a2009-06-18 23:21:26 +0100552 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 struct net_device_stats *stats = &priv->stats;
554 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -0400555 u16 status;
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400556 struct hermes_txexc_data hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 int err = 0;
558
559 if (fid == DUMMY_FID)
560 return; /* Nothing's really happened */
561
Pavel Roskin48ca7032005-09-23 04:18:06 -0400562 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200563 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400564 sizeof(struct hermes_txexc_data),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200565 fid, 0);
566
567 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
568 stats->tx_errors++;
569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 if (err) {
571 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
572 "(FID=%04X error %d)\n",
573 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200574 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000576
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200577 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
578 err, fid);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000579
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200580 /* We produce a TXDROP event only for retry or lifetime
581 * exceeded, because that's the only status that really mean
582 * that this particular node went away.
583 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400584 status = le16_to_cpu(hdr.desc.status);
Pavel Roskind133ae42005-09-23 04:18:06 -0400585 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200586 union iwreq_data wrqu;
587
588 /* Copy 802.11 dest address.
589 * We use the 802.11 header because the frame may
590 * not be 802.3 or may be mangled...
591 * In Ad-Hoc mode, it will be the node address.
592 * In managed mode, it will be most likely the AP addr
593 * User space will figure out how to convert it to
594 * whatever it needs (IP address or else).
595 * - Jean II */
596 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
597 wrqu.addr.sa_family = ARPHRD_ETHER;
598
599 /* Send event to user space */
600 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
606static void orinoco_tx_timeout(struct net_device *dev)
607{
David Kilroyea60a6a2009-06-18 23:21:26 +0100608 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 struct net_device_stats *stats = &priv->stats;
610 struct hermes *hw = &priv->hw;
611
612 printk(KERN_WARNING "%s: Tx timeout! "
613 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
614 dev->name, hermes_read_regn(hw, ALLOCFID),
615 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
616
617 stats->tx_errors++;
618
619 schedule_work(&priv->reset_work);
620}
621
622/********************************************************************/
623/* Rx path (data frames) */
624/********************************************************************/
625
626/* Does the frame have a SNAP header indicating it should be
627 * de-encapsulated to Ethernet-II? */
628static inline int is_ethersnap(void *_hdr)
629{
630 u8 *hdr = _hdr;
631
632 /* We de-encapsulate all packets which, a) have SNAP headers
633 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
634 * and where b) the OUI of the SNAP header is 00:00:00 or
635 * 00:00:f8 - we need both because different APs appear to use
636 * different OUIs for some reason */
637 return (memcmp(hdr, &encaps_hdr, 5) == 0)
David Kilroya94e8422009-02-04 23:05:44 +0000638 && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639}
640
641static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
642 int level, int noise)
643{
Pavel Roskin343c6862005-09-09 18:43:02 -0400644 struct iw_quality wstats;
645 wstats.level = level - 0x95;
646 wstats.noise = noise - 0x95;
647 wstats.qual = (level > noise) ? (level - noise) : 0;
Andrey Borzenkovf941f852008-11-15 17:15:09 +0300648 wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
Pavel Roskin343c6862005-09-09 18:43:02 -0400649 /* Update spy records */
650 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651}
652
653static void orinoco_stat_gather(struct net_device *dev,
654 struct sk_buff *skb,
655 struct hermes_rx_descriptor *desc)
656{
David Kilroyea60a6a2009-06-18 23:21:26 +0100657 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 /* Using spy support with lots of Rx packets, like in an
660 * infrastructure (AP), will really slow down everything, because
661 * the MAC address must be compared to each entry of the spy list.
662 * If the user really asks for it (set some address in the
663 * spy list), we do it, but he will pay the price.
664 * Note that to get here, you need both WIRELESS_SPY
665 * compiled in AND some addresses in the list !!!
666 */
667 /* Note : gcc will optimise the whole section away if
668 * WIRELESS_SPY is not defined... - Jean II */
669 if (SPY_NUMBER(priv)) {
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -0700670 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 desc->signal, desc->silence);
672 }
673}
674
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200675/*
676 * orinoco_rx_monitor - handle received monitor frames.
677 *
678 * Arguments:
679 * dev network device
680 * rxfid received FID
681 * desc rx descriptor of the frame
682 *
683 * Call context: interrupt
684 */
685static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
686 struct hermes_rx_descriptor *desc)
687{
688 u32 hdrlen = 30; /* return full header by default */
689 u32 datalen = 0;
690 u16 fc;
691 int err;
692 int len;
693 struct sk_buff *skb;
David Kilroyea60a6a2009-06-18 23:21:26 +0100694 struct orinoco_private *priv = ndev_priv(dev);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200695 struct net_device_stats *stats = &priv->stats;
696 hermes_t *hw = &priv->hw;
697
698 len = le16_to_cpu(desc->data_len);
699
700 /* Determine the size of the header and the data */
701 fc = le16_to_cpu(desc->frame_ctl);
702 switch (fc & IEEE80211_FCTL_FTYPE) {
703 case IEEE80211_FTYPE_DATA:
704 if ((fc & IEEE80211_FCTL_TODS)
705 && (fc & IEEE80211_FCTL_FROMDS))
706 hdrlen = 30;
707 else
708 hdrlen = 24;
709 datalen = len;
710 break;
711 case IEEE80211_FTYPE_MGMT:
712 hdrlen = 24;
713 datalen = len;
714 break;
715 case IEEE80211_FTYPE_CTL:
716 switch (fc & IEEE80211_FCTL_STYPE) {
717 case IEEE80211_STYPE_PSPOLL:
718 case IEEE80211_STYPE_RTS:
719 case IEEE80211_STYPE_CFEND:
720 case IEEE80211_STYPE_CFENDACK:
721 hdrlen = 16;
722 break;
723 case IEEE80211_STYPE_CTS:
724 case IEEE80211_STYPE_ACK:
725 hdrlen = 10;
726 break;
727 }
728 break;
729 default:
730 /* Unknown frame type */
731 break;
732 }
733
734 /* sanity check the length */
Johannes Berg2c7060022008-10-30 22:09:54 +0100735 if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200736 printk(KERN_DEBUG "%s: oversized monitor frame, "
737 "data length = %d\n", dev->name, datalen);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200738 stats->rx_length_errors++;
739 goto update_stats;
740 }
741
742 skb = dev_alloc_skb(hdrlen + datalen);
743 if (!skb) {
744 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
745 dev->name);
Florin Malitabb6e0932006-05-22 22:35:30 -0700746 goto update_stats;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200747 }
748
749 /* Copy the 802.11 header to the skb */
750 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700751 skb_reset_mac_header(skb);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200752
753 /* If any, copy the data from the card to the skb */
754 if (datalen > 0) {
755 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
756 ALIGN(datalen, 2), rxfid,
757 HERMES_802_2_OFFSET);
758 if (err) {
759 printk(KERN_ERR "%s: error %d reading monitor frame\n",
760 dev->name, err);
761 goto drop;
762 }
763 }
764
765 skb->dev = dev;
766 skb->ip_summed = CHECKSUM_NONE;
767 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800768 skb->protocol = cpu_to_be16(ETH_P_802_2);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000769
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200770 stats->rx_packets++;
771 stats->rx_bytes += skb->len;
772
773 netif_rx(skb);
774 return;
775
776 drop:
777 dev_kfree_skb_irq(skb);
778 update_stats:
779 stats->rx_errors++;
780 stats->rx_dropped++;
781}
782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
784{
David Kilroyea60a6a2009-06-18 23:21:26 +0100785 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 struct net_device_stats *stats = &priv->stats;
787 struct iw_statistics *wstats = &priv->wstats;
788 struct sk_buff *skb = NULL;
David Kilroy31afcef2008-08-21 23:28:04 +0100789 u16 rxfid, status;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200790 int length;
David Kilroy31afcef2008-08-21 23:28:04 +0100791 struct hermes_rx_descriptor *desc;
792 struct orinoco_rx_data *rx_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 int err;
794
David Kilroy31afcef2008-08-21 23:28:04 +0100795 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
796 if (!desc) {
797 printk(KERN_WARNING
798 "%s: Can't allocate space for RX descriptor\n",
799 dev->name);
800 goto update_stats;
801 }
802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 rxfid = hermes_read_regn(hw, RXFID);
804
David Kilroy31afcef2008-08-21 23:28:04 +0100805 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 rxfid, 0);
807 if (err) {
808 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
809 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200810 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 }
812
David Kilroy31afcef2008-08-21 23:28:04 +0100813 status = le16_to_cpu(desc->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200815 if (status & HERMES_RXSTAT_BADCRC) {
816 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
817 dev->name);
818 stats->rx_crc_errors++;
819 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 }
821
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200822 /* Handle frames in monitor mode */
823 if (priv->iw_mode == IW_MODE_MONITOR) {
David Kilroy31afcef2008-08-21 23:28:04 +0100824 orinoco_rx_monitor(dev, rxfid, desc);
825 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 }
827
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200828 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
829 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
830 dev->name);
831 wstats->discard.code++;
832 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 }
834
David Kilroy31afcef2008-08-21 23:28:04 +0100835 length = le16_to_cpu(desc->data_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 /* Sanity checks */
838 if (length < 3) { /* No for even an 802.2 LLC header */
839 /* At least on Symbol firmware with PCF we get quite a
David Kilroy6fe9deb2009-02-04 23:05:43 +0000840 lot of these legitimately - Poll frames with no
841 data. */
David Kilroy31afcef2008-08-21 23:28:04 +0100842 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 }
Johannes Berg2c7060022008-10-30 22:09:54 +0100844 if (length > IEEE80211_MAX_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
846 dev->name, length);
847 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200848 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850
David Kilroy23edcc42008-08-21 23:28:05 +0100851 /* Payload size does not include Michael MIC. Increase payload
852 * size to read it together with the data. */
853 if (status & HERMES_RXSTAT_MIC)
854 length += MICHAEL_MIC_LEN;
855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 /* We need space for the packet data itself, plus an ethernet
857 header, plus 2 bytes so we can align the IP header on a
858 32bit boundary, plus 1 byte so we can read in odd length
859 packets from the card, which has an IO granularity of 16
David Kilroy6fe9deb2009-02-04 23:05:43 +0000860 bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
862 if (!skb) {
863 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
864 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200865 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
867
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200868 /* We'll prepend the header, so reserve space for it. The worst
869 case is no decapsulation, when 802.3 header is prepended and
870 nothing is removed. 2 is for aligning the IP header. */
871 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200873 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
874 ALIGN(length, 2), rxfid,
875 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 if (err) {
877 printk(KERN_ERR "%s: error %d reading frame. "
878 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 goto drop;
880 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
David Kilroy31afcef2008-08-21 23:28:04 +0100882 /* Add desc and skb to rx queue */
883 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
884 if (!rx_data) {
885 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
886 dev->name);
887 goto drop;
888 }
889 rx_data->desc = desc;
890 rx_data->skb = skb;
891 list_add_tail(&rx_data->list, &priv->rx_list);
892 tasklet_schedule(&priv->rx_tasklet);
893
894 return;
895
896drop:
897 dev_kfree_skb_irq(skb);
898update_stats:
899 stats->rx_errors++;
900 stats->rx_dropped++;
901out:
902 kfree(desc);
903}
904
905static void orinoco_rx(struct net_device *dev,
906 struct hermes_rx_descriptor *desc,
907 struct sk_buff *skb)
908{
David Kilroyea60a6a2009-06-18 23:21:26 +0100909 struct orinoco_private *priv = ndev_priv(dev);
David Kilroy31afcef2008-08-21 23:28:04 +0100910 struct net_device_stats *stats = &priv->stats;
911 u16 status, fc;
912 int length;
913 struct ethhdr *hdr;
914
915 status = le16_to_cpu(desc->status);
916 length = le16_to_cpu(desc->data_len);
917 fc = le16_to_cpu(desc->frame_ctl);
918
David Kilroy23edcc42008-08-21 23:28:05 +0100919 /* Calculate and check MIC */
920 if (status & HERMES_RXSTAT_MIC) {
921 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
922 HERMES_MIC_KEY_ID_SHIFT);
923 u8 mic[MICHAEL_MIC_LEN];
924 u8 *rxmic;
925 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
926 desc->addr3 : desc->addr2;
927
928 /* Extract Michael MIC from payload */
929 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
930
931 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
932 length -= MICHAEL_MIC_LEN;
933
David Kilroy4adb4742009-02-04 23:05:51 +0000934 orinoco_mic(priv->rx_tfm_mic,
David Kilroy23edcc42008-08-21 23:28:05 +0100935 priv->tkip_key[key_id].rx_mic,
936 desc->addr1,
937 src,
938 0, /* priority or QoS? */
939 skb->data,
940 skb->len,
941 &mic[0]);
942
943 if (memcmp(mic, rxmic,
944 MICHAEL_MIC_LEN)) {
945 union iwreq_data wrqu;
946 struct iw_michaelmicfailure wxmic;
David Kilroy23edcc42008-08-21 23:28:05 +0100947
948 printk(KERN_WARNING "%s: "
Johannes Berge1749612008-10-27 15:59:26 -0700949 "Invalid Michael MIC in data frame from %pM, "
David Kilroy23edcc42008-08-21 23:28:05 +0100950 "using key %i\n",
Johannes Berge1749612008-10-27 15:59:26 -0700951 dev->name, src, key_id);
David Kilroy23edcc42008-08-21 23:28:05 +0100952
953 /* TODO: update stats */
954
955 /* Notify userspace */
956 memset(&wxmic, 0, sizeof(wxmic));
957 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
958 wxmic.flags |= (desc->addr1[0] & 1) ?
959 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
960 wxmic.src_addr.sa_family = ARPHRD_ETHER;
961 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
962
963 (void) orinoco_hw_get_tkip_iv(priv, key_id,
964 &wxmic.tsc[0]);
965
966 memset(&wrqu, 0, sizeof(wrqu));
967 wrqu.data.length = sizeof(wxmic);
968 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
969 (char *) &wxmic);
970
971 goto drop;
972 }
973 }
974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 /* Handle decapsulation
976 * In most cases, the firmware tell us about SNAP frames.
977 * For some reason, the SNAP frames sent by LinkSys APs
978 * are not properly recognised by most firmwares.
979 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200980 if (length >= ENCAPS_OVERHEAD &&
981 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
982 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
983 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 /* These indicate a SNAP within 802.2 LLC within
985 802.11 frame which we'll need to de-encapsulate to
986 the original EthernetII frame. */
David Kilroyb2f30a02009-02-04 23:05:46 +0000987 hdr = (struct ethhdr *)skb_push(skb,
988 ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200990 /* 802.3 frame - prepend 802.3 header as is */
991 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
992 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 }
David Kilroy31afcef2008-08-21 23:28:04 +0100994 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200995 if (fc & IEEE80211_FCTL_FROMDS)
David Kilroy31afcef2008-08-21 23:28:04 +0100996 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200997 else
David Kilroy31afcef2008-08-21 23:28:04 +0100998 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 skb->protocol = eth_type_trans(skb, dev);
1001 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001002 if (fc & IEEE80211_FCTL_TODS)
1003 skb->pkt_type = PACKET_OTHERHOST;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 /* Process the wireless stats if needed */
David Kilroy31afcef2008-08-21 23:28:04 +01001006 orinoco_stat_gather(dev, skb, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
1008 /* Pass the packet to the networking stack */
1009 netif_rx(skb);
1010 stats->rx_packets++;
1011 stats->rx_bytes += length;
1012
1013 return;
David Kilroy23edcc42008-08-21 23:28:05 +01001014
1015 drop:
1016 dev_kfree_skb(skb);
1017 stats->rx_errors++;
1018 stats->rx_dropped++;
David Kilroy31afcef2008-08-21 23:28:04 +01001019}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
David Kilroy31afcef2008-08-21 23:28:04 +01001021static void orinoco_rx_isr_tasklet(unsigned long data)
1022{
David Kilroy53819562009-06-18 23:21:28 +01001023 struct orinoco_private *priv = (struct orinoco_private *) data;
1024 struct net_device *dev = priv->ndev;
David Kilroy31afcef2008-08-21 23:28:04 +01001025 struct orinoco_rx_data *rx_data, *temp;
1026 struct hermes_rx_descriptor *desc;
1027 struct sk_buff *skb;
David Kilroy20953ad2009-01-07 00:23:55 +00001028 unsigned long flags;
1029
1030 /* orinoco_rx requires the driver lock, and we also need to
1031 * protect priv->rx_list, so just hold the lock over the
1032 * lot.
1033 *
1034 * If orinoco_lock fails, we've unplugged the card. In this
1035 * case just abort. */
1036 if (orinoco_lock(priv, &flags) != 0)
1037 return;
David Kilroy31afcef2008-08-21 23:28:04 +01001038
1039 /* extract desc and skb from queue */
1040 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1041 desc = rx_data->desc;
1042 skb = rx_data->skb;
1043 list_del(&rx_data->list);
1044 kfree(rx_data);
1045
1046 orinoco_rx(dev, desc, skb);
1047
1048 kfree(desc);
1049 }
David Kilroy20953ad2009-01-07 00:23:55 +00001050
1051 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052}
1053
1054/********************************************************************/
1055/* Rx path (info frames) */
1056/********************************************************************/
1057
1058static void print_linkstatus(struct net_device *dev, u16 status)
1059{
David Kilroy21312662009-02-04 23:05:47 +00001060 char *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062 if (suppress_linkstatus)
1063 return;
1064
1065 switch (status) {
1066 case HERMES_LINKSTATUS_NOT_CONNECTED:
1067 s = "Not Connected";
1068 break;
1069 case HERMES_LINKSTATUS_CONNECTED:
1070 s = "Connected";
1071 break;
1072 case HERMES_LINKSTATUS_DISCONNECTED:
1073 s = "Disconnected";
1074 break;
1075 case HERMES_LINKSTATUS_AP_CHANGE:
1076 s = "AP Changed";
1077 break;
1078 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1079 s = "AP Out of Range";
1080 break;
1081 case HERMES_LINKSTATUS_AP_IN_RANGE:
1082 s = "AP In Range";
1083 break;
1084 case HERMES_LINKSTATUS_ASSOC_FAILED:
1085 s = "Association Failed";
1086 break;
1087 default:
1088 s = "UNKNOWN";
1089 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001090
Pavel Roskin11eaea42009-01-18 23:20:58 -05001091 printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 dev->name, s, status);
1093}
1094
Christoph Hellwig16739b02005-06-19 01:27:51 +02001095/* Search scan results for requested BSSID, join it if found */
David Howellsc4028952006-11-22 14:57:56 +00001096static void orinoco_join_ap(struct work_struct *work)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001097{
David Howellsc4028952006-11-22 14:57:56 +00001098 struct orinoco_private *priv =
1099 container_of(work, struct orinoco_private, join_work);
1100 struct net_device *dev = priv->ndev;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001101 struct hermes *hw = &priv->hw;
1102 int err;
1103 unsigned long flags;
1104 struct join_req {
1105 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -04001106 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001107 } __attribute__ ((packed)) req;
1108 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001109 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001110 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -04001111 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001112 u8 *buf;
1113 u16 len;
1114
1115 /* Allocate buffer for scan results */
1116 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
David Kilroya94e8422009-02-04 23:05:44 +00001117 if (!buf)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001118 return;
1119
1120 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001121 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001122
1123 /* Sanity checks in case user changed something in the meantime */
David Kilroya94e8422009-02-04 23:05:44 +00001124 if (!priv->bssid_fixed)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001125 goto out;
1126
1127 if (strlen(priv->desired_essid) == 0)
1128 goto out;
1129
1130 /* Read scan results from the firmware */
1131 err = hermes_read_ltv(hw, USER_BAP,
1132 HERMES_RID_SCANRESULTSTABLE,
1133 MAX_SCAN_LEN, &len, buf);
1134 if (err) {
1135 printk(KERN_ERR "%s: Cannot read scan results\n",
1136 dev->name);
1137 goto out;
1138 }
1139
1140 len = HERMES_RECLEN_TO_BYTES(len);
1141
1142 /* Go through the scan results looking for the channel of the AP
1143 * we were requested to join */
1144 for (; offset + atom_len <= len; offset += atom_len) {
1145 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001146 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1147 found = 1;
1148 break;
1149 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001150 }
1151
David Kilroya94e8422009-02-04 23:05:44 +00001152 if (!found) {
Pavel Roskinc89cc222005-09-01 20:06:06 -04001153 DEBUG(1, "%s: Requested AP not found in scan results\n",
1154 dev->name);
1155 goto out;
1156 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001157
Christoph Hellwig16739b02005-06-19 01:27:51 +02001158 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1159 req.channel = atom->channel; /* both are little-endian */
1160 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1161 &req);
1162 if (err)
1163 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1164
1165 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001166 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001167
1168 fail_lock:
1169 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001170}
1171
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001172/* Send new BSSID to userspace */
David Kilroy6cd90b12008-08-21 23:28:00 +01001173static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001174{
David Howellsc4028952006-11-22 14:57:56 +00001175 struct net_device *dev = priv->ndev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001176 struct hermes *hw = &priv->hw;
1177 union iwreq_data wrqu;
1178 int err;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001179
David Kilroy499b7022008-12-09 21:46:29 +00001180 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001181 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1182 if (err != 0)
David Kilroy6cd90b12008-08-21 23:28:00 +01001183 return;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001184
1185 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1186
1187 /* Send event to user space */
1188 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001189}
1190
David Kilroy06009fd2008-08-21 23:28:03 +01001191static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1192{
1193 struct net_device *dev = priv->ndev;
1194 struct hermes *hw = &priv->hw;
1195 union iwreq_data wrqu;
1196 int err;
1197 u8 buf[88];
1198 u8 *ie;
1199
1200 if (!priv->has_wpa)
1201 return;
1202
David Kilroy499b7022008-12-09 21:46:29 +00001203 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
David Kilroy06009fd2008-08-21 23:28:03 +01001204 sizeof(buf), NULL, &buf);
1205 if (err != 0)
1206 return;
1207
1208 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1209 if (ie) {
1210 int rem = sizeof(buf) - (ie - &buf[0]);
1211 wrqu.data.length = ie[1] + 2;
1212 if (wrqu.data.length > rem)
1213 wrqu.data.length = rem;
1214
1215 if (wrqu.data.length)
1216 /* Send event to user space */
1217 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1218 }
1219}
1220
1221static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1222{
1223 struct net_device *dev = priv->ndev;
1224 struct hermes *hw = &priv->hw;
1225 union iwreq_data wrqu;
1226 int err;
1227 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1228 u8 *ie;
1229
1230 if (!priv->has_wpa)
1231 return;
1232
David Kilroy499b7022008-12-09 21:46:29 +00001233 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
David Kilroy06009fd2008-08-21 23:28:03 +01001234 sizeof(buf), NULL, &buf);
1235 if (err != 0)
1236 return;
1237
1238 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1239 if (ie) {
1240 int rem = sizeof(buf) - (ie - &buf[0]);
1241 wrqu.data.length = ie[1] + 2;
1242 if (wrqu.data.length > rem)
1243 wrqu.data.length = rem;
1244
1245 if (wrqu.data.length)
1246 /* Send event to user space */
1247 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1248 }
1249}
1250
David Kilroy6cd90b12008-08-21 23:28:00 +01001251static void orinoco_send_wevents(struct work_struct *work)
1252{
1253 struct orinoco_private *priv =
1254 container_of(work, struct orinoco_private, wevent_work);
1255 unsigned long flags;
1256
1257 if (orinoco_lock(priv, &flags) != 0)
1258 return;
1259
David Kilroy06009fd2008-08-21 23:28:03 +01001260 orinoco_send_assocreqie_wevent(priv);
1261 orinoco_send_assocrespie_wevent(priv);
David Kilroy6cd90b12008-08-21 23:28:00 +01001262 orinoco_send_bssid_wevent(priv);
1263
1264 orinoco_unlock(priv, &flags);
1265}
Dan Williams1e3428e2007-10-10 23:56:25 -04001266
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1268{
David Kilroyea60a6a2009-06-18 23:21:26 +01001269 struct orinoco_private *priv = ndev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 u16 infofid;
1271 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001272 __le16 len;
1273 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 } __attribute__ ((packed)) info;
1275 int len, type;
1276 int err;
1277
1278 /* This is an answer to an INQUIRE command that we did earlier,
1279 * or an information "event" generated by the card
1280 * The controller return to us a pseudo frame containing
1281 * the information in question - Jean II */
1282 infofid = hermes_read_regn(hw, INFOFID);
1283
1284 /* Read the info frame header - don't try too hard */
1285 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1286 infofid, 0);
1287 if (err) {
1288 printk(KERN_ERR "%s: error %d reading info frame. "
1289 "Frame dropped.\n", dev->name, err);
1290 return;
1291 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1294 type = le16_to_cpu(info.type);
1295
1296 switch (type) {
1297 case HERMES_INQ_TALLIES: {
1298 struct hermes_tallies_frame tallies;
1299 struct iw_statistics *wstats = &priv->wstats;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001300
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 if (len > sizeof(tallies)) {
1302 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1303 dev->name, len);
1304 len = sizeof(tallies);
1305 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001306
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001307 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1308 infofid, sizeof(info));
1309 if (err)
1310 break;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001311
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 /* Increment our various counters */
1313 /* wstats->discard.nwid - no wrong BSSID stuff */
1314 wstats->discard.code +=
1315 le16_to_cpu(tallies.RxWEPUndecryptable);
David Kilroy6fe9deb2009-02-04 23:05:43 +00001316 if (len == sizeof(tallies))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 wstats->discard.code +=
1318 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1319 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1320 wstats->discard.misc +=
1321 le16_to_cpu(tallies.TxDiscardsWrongSA);
1322 wstats->discard.fragment +=
1323 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1324 wstats->discard.retries +=
1325 le16_to_cpu(tallies.TxRetryLimitExceeded);
1326 /* wstats->miss.beacon - no match */
1327 }
1328 break;
1329 case HERMES_INQ_LINKSTATUS: {
1330 struct hermes_linkstatus linkstatus;
1331 u16 newstatus;
1332 int connected;
1333
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001334 if (priv->iw_mode == IW_MODE_MONITOR)
1335 break;
1336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 if (len != sizeof(linkstatus)) {
1338 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1339 dev->name, len);
1340 break;
1341 }
1342
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001343 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1344 infofid, sizeof(info));
1345 if (err)
1346 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 newstatus = le16_to_cpu(linkstatus.linkstatus);
1348
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001349 /* Symbol firmware uses "out of range" to signal that
1350 * the hostscan frame can be requested. */
1351 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1352 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1353 priv->has_hostscan && priv->scan_inprogress) {
1354 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1355 break;
1356 }
1357
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1359 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1360 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1361
1362 if (connected)
1363 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001364 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 netif_carrier_off(dev);
1366
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001367 if (newstatus != priv->last_linkstatus) {
1368 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001370 /* The info frame contains only one word which is the
1371 * status (see hermes.h). The status is pretty boring
1372 * in itself, that's why we export the new BSSID...
1373 * Jean II */
1374 schedule_work(&priv->wevent_work);
1375 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 }
1377 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001378 case HERMES_INQ_SCAN:
1379 if (!priv->scan_inprogress && priv->bssid_fixed &&
1380 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1381 schedule_work(&priv->join_work);
1382 break;
1383 }
1384 /* fall through */
1385 case HERMES_INQ_HOSTSCAN:
1386 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1387 /* Result of a scanning. Contains information about
1388 * cells in the vicinity - Jean II */
1389 union iwreq_data wrqu;
1390 unsigned char *buf;
1391
Dan Williams1e3428e2007-10-10 23:56:25 -04001392 /* Scan is no longer in progress */
1393 priv->scan_inprogress = 0;
1394
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001395 /* Sanity check */
1396 if (len > 4096) {
1397 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1398 dev->name, len);
1399 break;
1400 }
1401
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001402 /* Allocate buffer for results */
1403 buf = kmalloc(len, GFP_ATOMIC);
1404 if (buf == NULL)
1405 /* No memory, so can't printk()... */
1406 break;
1407
1408 /* Read scan data */
1409 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1410 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04001411 if (err) {
1412 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001413 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04001414 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001415
1416#ifdef ORINOCO_DEBUG
1417 {
1418 int i;
1419 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
David Kilroya94e8422009-02-04 23:05:44 +00001420 for (i = 1; i < (len * 2); i++)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001421 printk(":%02X", buf[i]);
1422 printk("]\n");
1423 }
1424#endif /* ORINOCO_DEBUG */
1425
David Kilroyaea48b12009-02-04 23:05:49 +00001426 if (orinoco_process_scan_results(priv, buf, len) == 0) {
Dan Williams1e3428e2007-10-10 23:56:25 -04001427 /* Send an empty event to user space.
1428 * We don't send the received data on the event because
1429 * it would require us to do complex transcoding, and
1430 * we want to minimise the work done in the irq handler
1431 * Use a request to extract the data - Jean II */
1432 wrqu.data.length = 0;
1433 wrqu.data.flags = 0;
1434 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1435 }
1436 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001437 }
1438 break;
David Kilroy01632fa2008-08-21 23:27:58 +01001439 case HERMES_INQ_CHANNELINFO:
1440 {
1441 struct agere_ext_scan_info *bss;
1442
1443 if (!priv->scan_inprogress) {
1444 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
1445 "len=%d\n", dev->name, len);
1446 break;
1447 }
1448
1449 /* An empty result indicates that the scan is complete */
1450 if (len == 0) {
1451 union iwreq_data wrqu;
1452
1453 /* Scan is no longer in progress */
1454 priv->scan_inprogress = 0;
1455
1456 wrqu.data.length = 0;
1457 wrqu.data.flags = 0;
1458 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1459 break;
1460 }
1461
1462 /* Sanity check */
1463 else if (len > sizeof(*bss)) {
1464 printk(KERN_WARNING
1465 "%s: Ext scan results too large (%d bytes). "
1466 "Truncating results to %zd bytes.\n",
1467 dev->name, len, sizeof(*bss));
1468 len = sizeof(*bss);
1469 } else if (len < (offsetof(struct agere_ext_scan_info,
1470 data) + 2)) {
1471 /* Drop this result now so we don't have to
1472 * keep checking later */
1473 printk(KERN_WARNING
1474 "%s: Ext scan results too short (%d bytes)\n",
1475 dev->name, len);
1476 break;
1477 }
1478
1479 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
1480 if (bss == NULL)
1481 break;
1482
1483 /* Read scan data */
1484 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
1485 infofid, sizeof(info));
1486 if (err) {
1487 kfree(bss);
1488 break;
1489 }
1490
1491 orinoco_add_ext_scan_result(priv, bss);
1492
1493 kfree(bss);
1494 break;
1495 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001496 case HERMES_INQ_SEC_STAT_AGERE:
1497 /* Security status (Agere specific) */
1498 /* Ignore this frame for now */
1499 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1500 break;
1501 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 default:
1503 printk(KERN_DEBUG "%s: Unknown information frame received: "
1504 "type 0x%04x, length %d\n", dev->name, type, len);
1505 /* We don't actually do anything about it */
1506 break;
1507 }
1508}
1509
1510static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1511{
1512 if (net_ratelimit())
1513 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1514}
1515
1516/********************************************************************/
1517/* Internal hardware control routines */
1518/********************************************************************/
1519
David Kilroy6415f7d2009-06-18 23:21:30 +01001520static int __orinoco_up(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
David Kilroya2608362009-06-18 23:21:23 +01001522 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 struct hermes *hw = &priv->hw;
1524 int err;
1525
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001526 netif_carrier_off(dev); /* just to make sure */
1527
David Kilroy721aa2f2009-06-18 23:21:31 +01001528 err = __orinoco_commit(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 if (err) {
1530 printk(KERN_ERR "%s: Error %d configuring card\n",
1531 dev->name, err);
1532 return err;
1533 }
1534
1535 /* Fire things up again */
1536 hermes_set_irqmask(hw, ORINOCO_INTEN);
1537 err = hermes_enable_port(hw, 0);
1538 if (err) {
1539 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1540 dev->name, err);
1541 return err;
1542 }
1543
1544 netif_start_queue(dev);
1545
1546 return 0;
1547}
1548
David Kilroy6415f7d2009-06-18 23:21:30 +01001549static int __orinoco_down(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
David Kilroya2608362009-06-18 23:21:23 +01001551 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 struct hermes *hw = &priv->hw;
1553 int err;
1554
1555 netif_stop_queue(dev);
1556
David Kilroya94e8422009-02-04 23:05:44 +00001557 if (!priv->hw_unavailable) {
1558 if (!priv->broken_disableport) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 err = hermes_disable_port(hw, 0);
1560 if (err) {
1561 /* Some firmwares (e.g. Intersil 1.3.x) seem
1562 * to have problems disabling the port, oh
1563 * well, too bad. */
1564 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1565 dev->name, err);
1566 priv->broken_disableport = 1;
1567 }
1568 }
1569 hermes_set_irqmask(hw, 0);
1570 hermes_write_regn(hw, EVACK, 0xffff);
1571 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001572
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 /* firmware will have to reassociate */
1574 netif_carrier_off(dev);
1575 priv->last_linkstatus = 0xffff;
1576
1577 return 0;
1578}
1579
David Kilroy6415f7d2009-06-18 23:21:30 +01001580static int orinoco_reinit_firmware(struct orinoco_private *priv)
Pavel Roskin37a6c612006-04-07 04:10:49 -04001581{
Pavel Roskin37a6c612006-04-07 04:10:49 -04001582 struct hermes *hw = &priv->hw;
1583 int err;
1584
1585 err = hermes_init(hw);
Andrey Borzenkov0df6cbb2008-10-12 20:15:43 +04001586 if (priv->do_fw_download && !err) {
1587 err = orinoco_download(priv);
1588 if (err)
1589 priv->do_fw_download = 0;
1590 }
Pavel Roskin37a6c612006-04-07 04:10:49 -04001591 if (!err)
David Kilroy42a51b92009-06-18 23:21:20 +01001592 err = orinoco_hw_allocate_fid(priv);
Pavel Roskin37a6c612006-04-07 04:10:49 -04001593
1594 return err;
1595}
1596
David Kilroy721aa2f2009-06-18 23:21:31 +01001597static int
David Kilroy5865d012009-02-04 23:05:54 +00001598__orinoco_set_multicast_list(struct net_device *dev)
1599{
David Kilroyea60a6a2009-06-18 23:21:26 +01001600 struct orinoco_private *priv = ndev_priv(dev);
David Kilroy5865d012009-02-04 23:05:54 +00001601 int err = 0;
1602 int promisc, mc_count;
1603
1604 /* The Hermes doesn't seem to have an allmulti mode, so we go
1605 * into promiscuous mode and let the upper levels deal. */
1606 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1607 (dev->mc_count > MAX_MULTICAST(priv))) {
1608 promisc = 1;
1609 mc_count = 0;
1610 } else {
1611 promisc = 0;
1612 mc_count = dev->mc_count;
1613 }
1614
1615 err = __orinoco_hw_set_multicast_list(priv, dev->mc_list, mc_count,
1616 promisc);
David Kilroy721aa2f2009-06-18 23:21:31 +01001617
1618 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619}
1620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621/* This must be called from user context, without locks held - use
1622 * schedule_work() */
David Kilroycb1576a2009-02-04 23:05:56 +00001623void orinoco_reset(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
David Howellsc4028952006-11-22 14:57:56 +00001625 struct orinoco_private *priv =
1626 container_of(work, struct orinoco_private, reset_work);
1627 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001629 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 unsigned long flags;
1631
1632 if (orinoco_lock(priv, &flags) != 0)
1633 /* When the hardware becomes available again, whatever
1634 * detects that is responsible for re-initializing
1635 * it. So no need for anything further */
1636 return;
1637
1638 netif_stop_queue(dev);
1639
1640 /* Shut off interrupts. Depending on what state the hardware
1641 * is in, this might not work, but we'll try anyway */
1642 hermes_set_irqmask(hw, 0);
1643 hermes_write_regn(hw, EVACK, 0xffff);
1644
1645 priv->hw_unavailable++;
1646 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1647 netif_carrier_off(dev);
1648
1649 orinoco_unlock(priv, &flags);
1650
David Kilroy6fe9deb2009-02-04 23:05:43 +00001651 /* Scanning support: Cleanup of driver struct */
Dan Williams1e3428e2007-10-10 23:56:25 -04001652 orinoco_clear_scan_results(priv, 0);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001653 priv->scan_inprogress = 0;
1654
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001655 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001657 if (err) {
1658 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1659 "performing hard reset\n", dev->name, err);
1660 goto disable;
1661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 }
1663
David Kilroya2608362009-06-18 23:21:23 +01001664 err = orinoco_reinit_firmware(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 if (err) {
1666 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1667 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001668 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 }
1670
David Kilroyb2f30a02009-02-04 23:05:46 +00001671 /* This has to be called from user context */
1672 spin_lock_irq(&priv->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
1674 priv->hw_unavailable--;
1675
1676 /* priv->open or priv->hw_unavailable might have changed while
1677 * we dropped the lock */
David Kilroya94e8422009-02-04 23:05:44 +00001678 if (priv->open && (!priv->hw_unavailable)) {
David Kilroya2608362009-06-18 23:21:23 +01001679 err = __orinoco_up(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 if (err) {
1681 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1682 dev->name, err);
1683 } else
1684 dev->trans_start = jiffies;
1685 }
1686
1687 spin_unlock_irq(&priv->lock);
1688
1689 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001690 disable:
1691 hermes_set_irqmask(hw, 0);
1692 netif_device_detach(dev);
1693 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694}
1695
David Kilroy721aa2f2009-06-18 23:21:31 +01001696static int __orinoco_commit(struct orinoco_private *priv)
1697{
1698 struct net_device *dev = priv->ndev;
1699 int err = 0;
1700
1701 err = orinoco_hw_program_rids(priv);
1702
1703 /* FIXME: what about netif_tx_lock */
1704 (void) __orinoco_set_multicast_list(dev);
1705
1706 return err;
1707}
1708
1709/* Ensures configuration changes are applied. May result in a reset.
1710 * The caller should hold priv->lock
1711 */
1712int orinoco_commit(struct orinoco_private *priv)
1713{
1714 struct net_device *dev = priv->ndev;
1715 hermes_t *hw = &priv->hw;
1716 int err;
1717
1718 if (priv->broken_disableport) {
1719 schedule_work(&priv->reset_work);
1720 return 0;
1721 }
1722
1723 err = hermes_disable_port(hw, 0);
1724 if (err) {
1725 printk(KERN_WARNING "%s: Unable to disable port "
1726 "while reconfiguring card\n", dev->name);
1727 priv->broken_disableport = 1;
1728 goto out;
1729 }
1730
1731 err = __orinoco_commit(priv);
1732 if (err) {
1733 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
1734 dev->name);
1735 goto out;
1736 }
1737
1738 err = hermes_enable_port(hw, 0);
1739 if (err) {
1740 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
1741 dev->name);
1742 goto out;
1743 }
1744
1745 out:
1746 if (err) {
1747 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
1748 schedule_work(&priv->reset_work);
1749 err = 0;
1750 }
1751 return err;
1752}
1753
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754/********************************************************************/
1755/* Interrupt handler */
1756/********************************************************************/
1757
1758static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1759{
1760 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1761}
1762
1763static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1764{
1765 /* This seems to happen a fair bit under load, but ignoring it
1766 seems to work fine...*/
1767 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1768 dev->name);
1769}
1770
David Howells7d12e782006-10-05 14:55:46 +01001771irqreturn_t orinoco_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772{
David Kilroya2608362009-06-18 23:21:23 +01001773 struct orinoco_private *priv = dev_id;
1774 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 hermes_t *hw = &priv->hw;
1776 int count = MAX_IRQLOOPS_PER_IRQ;
1777 u16 evstat, events;
David Kilroy21312662009-02-04 23:05:47 +00001778 /* These are used to detect a runaway interrupt situation.
1779 *
1780 * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1781 * we panic and shut down the hardware
1782 */
1783 /* jiffies value the last time we were called */
1784 static int last_irq_jiffy; /* = 0 */
1785 static int loops_this_jiffy; /* = 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 unsigned long flags;
1787
1788 if (orinoco_lock(priv, &flags) != 0) {
1789 /* If hw is unavailable - we don't know if the irq was
1790 * for us or not */
1791 return IRQ_HANDLED;
1792 }
1793
1794 evstat = hermes_read_regn(hw, EVSTAT);
1795 events = evstat & hw->inten;
David Kilroya94e8422009-02-04 23:05:44 +00001796 if (!events) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 orinoco_unlock(priv, &flags);
1798 return IRQ_NONE;
1799 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 if (jiffies != last_irq_jiffy)
1802 loops_this_jiffy = 0;
1803 last_irq_jiffy = jiffies;
1804
1805 while (events && count--) {
1806 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
1807 printk(KERN_WARNING "%s: IRQ handler is looping too "
1808 "much! Resetting.\n", dev->name);
1809 /* Disable interrupts for now */
1810 hermes_set_irqmask(hw, 0);
1811 schedule_work(&priv->reset_work);
1812 break;
1813 }
1814
1815 /* Check the card hasn't been removed */
David Kilroya94e8422009-02-04 23:05:44 +00001816 if (!hermes_present(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 DEBUG(0, "orinoco_interrupt(): card removed\n");
1818 break;
1819 }
1820
1821 if (events & HERMES_EV_TICK)
1822 __orinoco_ev_tick(dev, hw);
1823 if (events & HERMES_EV_WTERR)
1824 __orinoco_ev_wterr(dev, hw);
1825 if (events & HERMES_EV_INFDROP)
1826 __orinoco_ev_infdrop(dev, hw);
1827 if (events & HERMES_EV_INFO)
1828 __orinoco_ev_info(dev, hw);
1829 if (events & HERMES_EV_RX)
1830 __orinoco_ev_rx(dev, hw);
1831 if (events & HERMES_EV_TXEXC)
1832 __orinoco_ev_txexc(dev, hw);
1833 if (events & HERMES_EV_TX)
1834 __orinoco_ev_tx(dev, hw);
1835 if (events & HERMES_EV_ALLOC)
1836 __orinoco_ev_alloc(dev, hw);
David Kilroy6fe9deb2009-02-04 23:05:43 +00001837
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001838 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
1840 evstat = hermes_read_regn(hw, EVSTAT);
1841 events = evstat & hw->inten;
1842 };
1843
1844 orinoco_unlock(priv, &flags);
1845 return IRQ_HANDLED;
1846}
David Kilroy21312662009-02-04 23:05:47 +00001847EXPORT_SYMBOL(orinoco_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
1849/********************************************************************/
David Kilroy39d1ffe2008-11-22 10:37:28 +00001850/* Power management */
1851/********************************************************************/
1852#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
1853static int orinoco_pm_notifier(struct notifier_block *notifier,
1854 unsigned long pm_event,
1855 void *unused)
1856{
1857 struct orinoco_private *priv = container_of(notifier,
1858 struct orinoco_private,
1859 pm_notifier);
1860
1861 /* All we need to do is cache the firmware before suspend, and
1862 * release it when we come out.
1863 *
1864 * Only need to do this if we're downloading firmware. */
1865 if (!priv->do_fw_download)
1866 return NOTIFY_DONE;
1867
1868 switch (pm_event) {
1869 case PM_HIBERNATION_PREPARE:
1870 case PM_SUSPEND_PREPARE:
1871 orinoco_cache_fw(priv, 0);
1872 break;
1873
1874 case PM_POST_RESTORE:
1875 /* Restore from hibernation failed. We need to clean
1876 * up in exactly the same way, so fall through. */
1877 case PM_POST_HIBERNATION:
1878 case PM_POST_SUSPEND:
1879 orinoco_uncache_fw(priv);
1880 break;
1881
1882 case PM_RESTORE_PREPARE:
1883 default:
1884 break;
1885 }
1886
1887 return NOTIFY_DONE;
1888}
David S. Millerf11c1792009-02-25 00:02:05 -08001889
1890static void orinoco_register_pm_notifier(struct orinoco_private *priv)
1891{
1892 priv->pm_notifier.notifier_call = orinoco_pm_notifier;
1893 register_pm_notifier(&priv->pm_notifier);
1894}
1895
1896static void orinoco_unregister_pm_notifier(struct orinoco_private *priv)
1897{
1898 unregister_pm_notifier(&priv->pm_notifier);
1899}
David Kilroy39d1ffe2008-11-22 10:37:28 +00001900#else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
David S. Millerf11c1792009-02-25 00:02:05 -08001901#define orinoco_register_pm_notifier(priv) do { } while(0)
1902#define orinoco_unregister_pm_notifier(priv) do { } while(0)
David Kilroy39d1ffe2008-11-22 10:37:28 +00001903#endif
1904
1905/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906/* Initialization */
1907/********************************************************************/
1908
David Kilroy8e638262009-06-18 23:21:24 +01001909int orinoco_init(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910{
David Kilroy8e638262009-06-18 23:21:24 +01001911 struct device *dev = priv->dev;
David Kilroyea60a6a2009-06-18 23:21:26 +01001912 struct wiphy *wiphy = priv_to_wiphy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 hermes_t *hw = &priv->hw;
1914 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 /* No need to lock, the hw_unavailable flag is already set in
1917 * alloc_orinocodev() */
Johannes Berg2c7060022008-10-30 22:09:54 +01001918 priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
1920 /* Initialize the firmware */
Pavel Roskin37a6c612006-04-07 04:10:49 -04001921 err = hermes_init(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 if (err != 0) {
David Kilroy8e638262009-06-18 23:21:24 +01001923 dev_err(dev, "Failed to initialize firmware (err = %d)\n",
1924 err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 goto out;
1926 }
1927
David Kilroya2d1a422009-06-18 23:21:18 +01001928 err = determine_fw_capabilities(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 if (err != 0) {
David Kilroy8e638262009-06-18 23:21:24 +01001930 dev_err(dev, "Incompatible firmware, aborting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 goto out;
1932 }
1933
David Kilroy3994d502008-08-21 23:27:54 +01001934 if (priv->do_fw_download) {
David Kilroy39d1ffe2008-11-22 10:37:28 +00001935#ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
David Kilroy74734312008-11-22 10:37:25 +00001936 orinoco_cache_fw(priv, 0);
David Kilroy39d1ffe2008-11-22 10:37:28 +00001937#endif
David Kilroy74734312008-11-22 10:37:25 +00001938
David Kilroy3994d502008-08-21 23:27:54 +01001939 err = orinoco_download(priv);
1940 if (err)
1941 priv->do_fw_download = 0;
1942
1943 /* Check firmware version again */
David Kilroya2d1a422009-06-18 23:21:18 +01001944 err = determine_fw_capabilities(priv);
David Kilroy3994d502008-08-21 23:27:54 +01001945 if (err != 0) {
David Kilroy8e638262009-06-18 23:21:24 +01001946 dev_err(dev, "Incompatible firmware, aborting\n");
David Kilroy3994d502008-08-21 23:27:54 +01001947 goto out;
1948 }
1949 }
1950
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 if (priv->has_port3)
David Kilroy8e638262009-06-18 23:21:24 +01001952 dev_info(dev, "Ad-hoc demo mode supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 if (priv->has_ibss)
David Kilroy8e638262009-06-18 23:21:24 +01001954 dev_info(dev, "IEEE standard IBSS ad-hoc mode supported\n");
1955 if (priv->has_wep)
1956 dev_info(dev, "WEP supported, %s-bit key\n",
1957 priv->has_big_wep ? "104" : "40");
David Kilroy23edcc42008-08-21 23:28:05 +01001958 if (priv->has_wpa) {
David Kilroy8e638262009-06-18 23:21:24 +01001959 dev_info(dev, "WPA-PSK supported\n");
David Kilroy23edcc42008-08-21 23:28:05 +01001960 if (orinoco_mic_init(priv)) {
David Kilroy8e638262009-06-18 23:21:24 +01001961 dev_err(dev, "Failed to setup MIC crypto algorithm. "
1962 "Disabling WPA support\n");
David Kilroy23edcc42008-08-21 23:28:05 +01001963 priv->has_wpa = 0;
1964 }
1965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
David Kilroy01632fa2008-08-21 23:27:58 +01001967 /* Now we have the firmware capabilities, allocate appropiate
1968 * sized scan buffers */
1969 if (orinoco_bss_data_allocate(priv))
1970 goto out;
1971 orinoco_bss_data_init(priv);
1972
David Kilroyea60a6a2009-06-18 23:21:26 +01001973 err = orinoco_hw_read_card_settings(priv, wiphy->perm_addr);
David Kilroye9e3d012009-06-18 23:21:19 +01001974 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
David Kilroy42a51b92009-06-18 23:21:20 +01001977 err = orinoco_hw_allocate_fid(priv);
Pavel Roskin37a6c612006-04-07 04:10:49 -04001978 if (err) {
David Kilroy8e638262009-06-18 23:21:24 +01001979 dev_err(dev, "Failed to allocate NIC buffer!\n");
Pavel Roskin37a6c612006-04-07 04:10:49 -04001980 goto out;
1981 }
1982
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 /* Set up the default configuration */
1984 priv->iw_mode = IW_MODE_INFRA;
1985 /* By default use IEEE/IBSS ad-hoc mode if we have it */
David Kilroya94e8422009-02-04 23:05:44 +00001986 priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04001988 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
1990 priv->promiscuous = 0;
David Kilroy4ae6ee22008-08-21 23:27:59 +01001991 priv->encode_alg = IW_ENCODE_ALG_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 priv->tx_key = 0;
David Kilroyd03032a2008-08-21 23:28:02 +01001993 priv->wpa_enabled = 0;
1994 priv->tkip_cm_active = 0;
1995 priv->key_mgmt = 0;
1996 priv->wpa_ie_len = 0;
1997 priv->wpa_ie = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
David Kilroyea60a6a2009-06-18 23:21:26 +01001999 if (orinoco_wiphy_register(wiphy)) {
2000 err = -ENODEV;
2001 goto out;
2002 }
2003
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 /* Make the hardware available, as long as it hasn't been
2005 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2006 spin_lock_irq(&priv->lock);
2007 priv->hw_unavailable--;
2008 spin_unlock_irq(&priv->lock);
2009
David Kilroy8e638262009-06-18 23:21:24 +01002010 dev_dbg(dev, "Ready\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
2012 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 return err;
2014}
David Kilroy8e638262009-06-18 23:21:24 +01002015EXPORT_SYMBOL(orinoco_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
Andrey Borzenkov89ea4092009-01-21 20:46:46 +03002017static const struct net_device_ops orinoco_netdev_ops = {
Andrey Borzenkov89ea4092009-01-21 20:46:46 +03002018 .ndo_open = orinoco_open,
2019 .ndo_stop = orinoco_stop,
2020 .ndo_start_xmit = orinoco_xmit,
2021 .ndo_set_multicast_list = orinoco_set_multicast_list,
2022 .ndo_change_mtu = orinoco_change_mtu,
2023 .ndo_tx_timeout = orinoco_tx_timeout,
2024 .ndo_get_stats = orinoco_get_stats,
2025};
2026
David Kilroyea60a6a2009-06-18 23:21:26 +01002027/* Allocate private data.
2028 *
2029 * This driver has a number of structures associated with it
2030 * netdev - Net device structure for each network interface
2031 * wiphy - structure associated with wireless phy
2032 * wireless_dev (wdev) - structure for each wireless interface
2033 * hw - structure for hermes chip info
2034 * card - card specific structure for use by the card driver
2035 * (airport, orinoco_cs)
2036 * priv - orinoco private data
2037 * device - generic linux device structure
2038 *
2039 * +---------+ +---------+
2040 * | wiphy | | netdev |
2041 * | +-------+ | +-------+
2042 * | | priv | | | wdev |
2043 * | | +-----+ +-+-------+
2044 * | | | hw |
2045 * | +-+-----+
2046 * | | card |
2047 * +-+-------+
2048 *
2049 * priv has a link to netdev and device
2050 * wdev has a link to wiphy
2051 */
David Kilroya2608362009-06-18 23:21:23 +01002052struct orinoco_private
David Kilroy3994d502008-08-21 23:27:54 +01002053*alloc_orinocodev(int sizeof_card,
2054 struct device *device,
2055 int (*hard_reset)(struct orinoco_private *),
2056 int (*stop_fw)(struct orinoco_private *, int))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 struct orinoco_private *priv;
David Kilroyea60a6a2009-06-18 23:21:26 +01002059 struct wiphy *wiphy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
David Kilroyea60a6a2009-06-18 23:21:26 +01002061 /* allocate wiphy
2062 * NOTE: We only support a single virtual interface
2063 * but this may change when monitor mode is added
2064 */
2065 wiphy = wiphy_new(&orinoco_cfg_ops,
2066 sizeof(struct orinoco_private) + sizeof_card);
2067 if (!wiphy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 return NULL;
David Kilroyea60a6a2009-06-18 23:21:26 +01002069
David Kilroyea60a6a2009-06-18 23:21:26 +01002070 priv = wiphy_priv(wiphy);
David Kilroy53819562009-06-18 23:21:28 +01002071 priv->dev = device;
David Kilroyea60a6a2009-06-18 23:21:26 +01002072
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002074 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 + sizeof(struct orinoco_private));
2076 else
2077 priv->card = NULL;
2078
David Kilroyea60a6a2009-06-18 23:21:26 +01002079 orinoco_wiphy_init(wiphy);
2080
Pavel Roskin343c6862005-09-09 18:43:02 -04002081#ifdef WIRELESS_SPY
2082 priv->wireless_data.spy_data = &priv->spy_data;
Pavel Roskin343c6862005-09-09 18:43:02 -04002083#endif
David Kilroy23edcc42008-08-21 23:28:05 +01002084
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 /* Set up default callbacks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 priv->hard_reset = hard_reset;
David Kilroy3994d502008-08-21 23:27:54 +01002087 priv->stop_fw = stop_fw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
2089 spin_lock_init(&priv->lock);
2090 priv->open = 0;
2091 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2092 * before anything else touches the
2093 * hardware */
David Howellsc4028952006-11-22 14:57:56 +00002094 INIT_WORK(&priv->reset_work, orinoco_reset);
2095 INIT_WORK(&priv->join_work, orinoco_join_ap);
2096 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
David Kilroy31afcef2008-08-21 23:28:04 +01002098 INIT_LIST_HEAD(&priv->rx_list);
2099 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
David Kilroy53819562009-06-18 23:21:28 +01002100 (unsigned long) priv);
David Kilroy31afcef2008-08-21 23:28:04 +01002101
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 priv->last_linkstatus = 0xffff;
2103
Andrey Borzenkov2bfc5cb2009-02-28 23:09:09 +03002104#if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
David Kilroy2cea7b22008-11-22 10:37:26 +00002105 priv->cached_pri_fw = NULL;
Andrey Borzenkov4fb30782008-10-19 12:06:11 +04002106 priv->cached_fw = NULL;
Andrey Borzenkov2bfc5cb2009-02-28 23:09:09 +03002107#endif
Andrey Borzenkov4fb30782008-10-19 12:06:11 +04002108
David Kilroy39d1ffe2008-11-22 10:37:28 +00002109 /* Register PM notifiers */
David S. Millerf11c1792009-02-25 00:02:05 -08002110 orinoco_register_pm_notifier(priv);
David Kilroy39d1ffe2008-11-22 10:37:28 +00002111
David Kilroya2608362009-06-18 23:21:23 +01002112 return priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113}
David Kilroy21312662009-02-04 23:05:47 +00002114EXPORT_SYMBOL(alloc_orinocodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
David Kilroy53819562009-06-18 23:21:28 +01002116/* We can only support a single interface. We provide a separate
2117 * function to set it up to distinguish between hardware
2118 * initialisation and interface setup.
2119 *
2120 * The base_addr and irq parameters are passed on to netdev for use
2121 * with SIOCGIFMAP.
2122 */
2123int orinoco_if_add(struct orinoco_private *priv,
2124 unsigned long base_addr,
2125 unsigned int irq)
2126{
2127 struct wiphy *wiphy = priv_to_wiphy(priv);
2128 struct wireless_dev *wdev;
2129 struct net_device *dev;
2130 int ret;
2131
2132 dev = alloc_etherdev(sizeof(struct wireless_dev));
2133
2134 if (!dev)
2135 return -ENOMEM;
2136
2137 /* Initialise wireless_dev */
2138 wdev = netdev_priv(dev);
2139 wdev->wiphy = wiphy;
2140 wdev->iftype = NL80211_IFTYPE_STATION;
2141
2142 /* Setup / override net_device fields */
2143 dev->ieee80211_ptr = wdev;
2144 dev->netdev_ops = &orinoco_netdev_ops;
2145 dev->watchdog_timeo = HZ; /* 1 second timeout */
2146 dev->ethtool_ops = &orinoco_ethtool_ops;
2147 dev->wireless_handlers = &orinoco_handler_def;
2148#ifdef WIRELESS_SPY
2149 dev->wireless_data = &priv->wireless_data;
2150#endif
2151 /* we use the default eth_mac_addr for setting the MAC addr */
2152
2153 /* Reserve space in skb for the SNAP header */
2154 dev->hard_header_len += ENCAPS_OVERHEAD;
2155
2156 netif_carrier_off(dev);
2157
2158 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
2159
2160 dev->base_addr = base_addr;
2161 dev->irq = irq;
2162
2163 SET_NETDEV_DEV(dev, priv->dev);
2164 ret = register_netdev(dev);
2165 if (ret)
2166 goto fail;
2167
2168 priv->ndev = dev;
2169
2170 /* Report what we've done */
2171 dev_dbg(priv->dev, "Registerred interface %s.\n", dev->name);
2172
2173 return 0;
2174
2175 fail:
2176 free_netdev(dev);
2177 return ret;
2178}
2179EXPORT_SYMBOL(orinoco_if_add);
2180
2181void orinoco_if_del(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182{
David Kilroya2608362009-06-18 23:21:23 +01002183 struct net_device *dev = priv->ndev;
David Kilroy53819562009-06-18 23:21:28 +01002184
2185 unregister_netdev(dev);
2186 free_netdev(dev);
2187}
2188EXPORT_SYMBOL(orinoco_if_del);
2189
2190void free_orinocodev(struct orinoco_private *priv)
2191{
David Kilroyea60a6a2009-06-18 23:21:26 +01002192 struct wiphy *wiphy = priv_to_wiphy(priv);
David Kilroy20953ad2009-01-07 00:23:55 +00002193 struct orinoco_rx_data *rx_data, *temp;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002194
David Kilroyea60a6a2009-06-18 23:21:26 +01002195 wiphy_unregister(wiphy);
2196
David Kilroy20953ad2009-01-07 00:23:55 +00002197 /* If the tasklet is scheduled when we call tasklet_kill it
2198 * will run one final time. However the tasklet will only
2199 * drain priv->rx_list if the hw is still available. */
David Kilroy31afcef2008-08-21 23:28:04 +01002200 tasklet_kill(&priv->rx_tasklet);
David Kilroy74734312008-11-22 10:37:25 +00002201
David Kilroy20953ad2009-01-07 00:23:55 +00002202 /* Explicitly drain priv->rx_list */
2203 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
2204 list_del(&rx_data->list);
2205
2206 dev_kfree_skb(rx_data->skb);
2207 kfree(rx_data->desc);
2208 kfree(rx_data);
2209 }
2210
David S. Millerf11c1792009-02-25 00:02:05 -08002211 orinoco_unregister_pm_notifier(priv);
David Kilroy74734312008-11-22 10:37:25 +00002212 orinoco_uncache_fw(priv);
2213
David Kilroyd03032a2008-08-21 23:28:02 +01002214 priv->wpa_ie_len = 0;
2215 kfree(priv->wpa_ie);
David Kilroy23edcc42008-08-21 23:28:05 +01002216 orinoco_mic_free(priv);
Dan Williams1e3428e2007-10-10 23:56:25 -04002217 orinoco_bss_data_free(priv);
David Kilroyea60a6a2009-06-18 23:21:26 +01002218 wiphy_free(wiphy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219}
David Kilroy21312662009-02-04 23:05:47 +00002220EXPORT_SYMBOL(free_orinocodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
David Kilroy6415f7d2009-06-18 23:21:30 +01002222int orinoco_up(struct orinoco_private *priv)
2223{
2224 struct net_device *dev = priv->ndev;
2225 unsigned long flags;
2226 int err;
2227
2228 spin_lock_irqsave(&priv->lock, flags);
2229
2230 err = orinoco_reinit_firmware(priv);
2231 if (err) {
2232 printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
2233 dev->name, err);
2234 goto exit;
2235 }
2236
2237 netif_device_attach(dev);
2238 priv->hw_unavailable--;
2239
2240 if (priv->open && !priv->hw_unavailable) {
2241 err = __orinoco_up(priv);
2242 if (err)
2243 printk(KERN_ERR "%s: Error %d restarting card\n",
2244 dev->name, err);
2245 }
2246
2247exit:
2248 spin_unlock_irqrestore(&priv->lock, flags);
2249
2250 return 0;
2251}
2252EXPORT_SYMBOL(orinoco_up);
2253
2254void orinoco_down(struct orinoco_private *priv)
2255{
2256 struct net_device *dev = priv->ndev;
2257 unsigned long flags;
2258 int err;
2259
2260 spin_lock_irqsave(&priv->lock, flags);
2261 err = __orinoco_down(priv);
2262 if (err)
2263 printk(KERN_WARNING "%s: Error %d downing interface\n",
2264 dev->name, err);
2265
2266 netif_device_detach(dev);
2267 priv->hw_unavailable++;
2268 spin_unlock_irqrestore(&priv->lock, flags);
2269}
2270EXPORT_SYMBOL(orinoco_down);
2271
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002272static void orinoco_get_drvinfo(struct net_device *dev,
2273 struct ethtool_drvinfo *info)
2274{
David Kilroyea60a6a2009-06-18 23:21:26 +01002275 struct orinoco_private *priv = ndev_priv(dev);
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002276
2277 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
2278 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
2279 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07002280 if (dev->dev.parent)
Kay Sieversfb28ad32008-11-10 13:55:14 -08002281 strncpy(info->bus_info, dev_name(dev->dev.parent),
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002282 sizeof(info->bus_info) - 1);
2283 else
2284 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
2285 "PCMCIA %p", priv->hw.iobase);
2286}
2287
Jeff Garzik7282d492006-09-13 14:30:00 -04002288static const struct ethtool_ops orinoco_ethtool_ops = {
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002289 .get_drvinfo = orinoco_get_drvinfo,
2290 .get_link = ethtool_op_get_link,
2291};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
2293/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294/* Module initialization */
2295/********************************************************************/
2296
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297/* Can't be declared "const" or the whole __initdata section will
2298 * become const */
2299static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
2300 " (David Gibson <hermes@gibson.dropbear.id.au>, "
2301 "Pavel Roskin <proski@gnu.org>, et al)";
2302
2303static int __init init_orinoco(void)
2304{
2305 printk(KERN_DEBUG "%s\n", version);
2306 return 0;
2307}
2308
2309static void __exit exit_orinoco(void)
2310{
2311}
2312
2313module_init(init_orinoco);
2314module_exit(exit_orinoco);