David Kilroy | 47445cb | 2009-02-04 23:05:48 +0000 | [diff] [blame] | 1 | /* main.c - (formerly known as dldwd_cs.c, orinoco_cs.c and orinoco.c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | * TODO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | * o Handle de-encapsulation within network layer, provide 802.11 |
| 51 | * headers (patch from Thomas 'Dent' Mirlacher) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * o Fix possible races in SPY handling. |
| 53 | * o Disconnect wireless extensions from fundamental configuration. |
| 54 | * o (maybe) Software WEP support (patch from Stano Meduna). |
| 55 | * o (maybe) Use multiple Tx buffers - driver handling queue |
| 56 | * rather than firmware. |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #include <linux/module.h> |
| 80 | #include <linux/kernel.h> |
| 81 | #include <linux/init.h> |
David Kilroy | d03032a | 2008-08-21 23:28:02 +0100 | [diff] [blame] | 82 | #include <linux/delay.h> |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 83 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #include <linux/netdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #include <linux/etherdevice.h> |
Christoph Hellwig | 1fab2e8 | 2005-06-19 01:27:40 +0200 | [diff] [blame] | 86 | #include <linux/ethtool.h> |
David Kilroy | 39d1ffe | 2008-11-22 10:37:28 +0000 | [diff] [blame] | 87 | #include <linux/suspend.h> |
Pavel Roskin | 9c974fb | 2006-08-15 20:45:03 -0400 | [diff] [blame] | 88 | #include <linux/if_arp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #include <linux/wireless.h> |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 90 | #include <linux/ieee80211.h> |
Christoph Hellwig | 620554e | 2005-06-19 01:27:33 +0200 | [diff] [blame] | 91 | #include <net/iw_handler.h> |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 92 | #include <net/cfg80211.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #include "hermes_rid.h" |
David Kilroy | 3994d50 | 2008-08-21 23:27:54 +0100 | [diff] [blame] | 95 | #include "hermes_dld.h" |
David Kilroy | 712a434 | 2009-02-04 23:05:55 +0000 | [diff] [blame] | 96 | #include "hw.h" |
David Kilroy | fb791b1 | 2009-02-04 23:05:50 +0000 | [diff] [blame] | 97 | #include "scan.h" |
David Kilroy | 4adb474 | 2009-02-04 23:05:51 +0000 | [diff] [blame] | 98 | #include "mic.h" |
David Kilroy | 37a2e56 | 2009-02-04 23:05:52 +0000 | [diff] [blame] | 99 | #include "fw.h" |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 100 | #include "wext.h" |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 101 | #include "cfg.h" |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 102 | #include "main.h" |
David Kilroy | fb791b1 | 2009-02-04 23:05:50 +0000 | [diff] [blame] | 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | #include "orinoco.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /********************************************************************/ |
| 107 | /* Module information */ |
| 108 | /********************************************************************/ |
| 109 | |
David Kilroy | b2f30a0 | 2009-02-04 23:05:46 +0000 | [diff] [blame] | 110 | MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & " |
| 111 | "David Gibson <hermes@gibson.dropbear.id.au>"); |
| 112 | MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based " |
| 113 | "and similar wireless cards"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | MODULE_LICENSE("Dual MPL/GPL"); |
| 115 | |
| 116 | /* Level of debugging. Used in the macros in orinoco.h */ |
| 117 | #ifdef ORINOCO_DEBUG |
| 118 | int orinoco_debug = ORINOCO_DEBUG; |
David Kilroy | 2131266 | 2009-02-04 23:05:47 +0000 | [diff] [blame] | 119 | EXPORT_SYMBOL(orinoco_debug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | module_param(orinoco_debug, int, 0644); |
| 121 | MODULE_PARM_DESC(orinoco_debug, "Debug level"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | #endif |
| 123 | |
| 124 | static int suppress_linkstatus; /* = 0 */ |
| 125 | module_param(suppress_linkstatus, bool, 0644); |
| 126 | MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes"); |
David Kilroy | b2f30a0 | 2009-02-04 23:05:46 +0000 | [diff] [blame] | 127 | |
David Gibson | 7bb7c3a | 2005-05-12 20:02:10 -0400 | [diff] [blame] | 128 | static int ignore_disconnect; /* = 0 */ |
| 129 | module_param(ignore_disconnect, int, 0644); |
David Kilroy | b2f30a0 | 2009-02-04 23:05:46 +0000 | [diff] [blame] | 130 | MODULE_PARM_DESC(ignore_disconnect, |
| 131 | "Don't report lost link to the network layer"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 133 | int force_monitor; /* = 0 */ |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 134 | module_param(force_monitor, int, 0644); |
| 135 | MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions"); |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /********************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* Internal constants */ |
| 139 | /********************************************************************/ |
| 140 | |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 141 | /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */ |
| 142 | static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00}; |
| 143 | #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2) |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | #define ORINOCO_MIN_MTU 256 |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 146 | #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | #define MAX_IRQLOOPS_PER_IRQ 10 |
| 149 | #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of |
| 150 | * how many events the |
| 151 | * device could |
| 152 | * legitimately generate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 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 Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 163 | | HERMES_EV_INFDROP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 165 | static const struct ethtool_ops orinoco_ethtool_ops; |
Christoph Hellwig | 620554e | 2005-06-19 01:27:33 +0200 | [diff] [blame] | 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /********************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* Data types */ |
| 169 | /********************************************************************/ |
| 170 | |
Pavel Roskin | 30c2d3b | 2006-04-07 04:10:34 -0400 | [diff] [blame] | 171 | /* Beginning of the Tx descriptor, used in TxExc handling */ |
| 172 | struct hermes_txexc_data { |
| 173 | struct hermes_tx_descriptor desc; |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 174 | __le16 frame_ctl; |
| 175 | __le16 duration_id; |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 176 | u8 addr1[ETH_ALEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } __attribute__ ((packed)); |
| 178 | |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 179 | /* Rx frame header except compatibility 802.3 header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | struct hermes_rx_descriptor { |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 181 | /* Control */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 182 | __le16 status; |
| 183 | __le32 time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | u8 silence; |
| 185 | u8 signal; |
| 186 | u8 rate; |
| 187 | u8 rxflow; |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 188 | __le32 reserved; |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 189 | |
| 190 | /* 802.11 header */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 191 | __le16 frame_ctl; |
| 192 | __le16 duration_id; |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 193 | u8 addr1[ETH_ALEN]; |
| 194 | u8 addr2[ETH_ALEN]; |
| 195 | u8 addr3[ETH_ALEN]; |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 196 | __le16 seq_ctl; |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 197 | u8 addr4[ETH_ALEN]; |
| 198 | |
| 199 | /* Data length */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 200 | __le16 data_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } __attribute__ ((packed)); |
| 202 | |
David Kilroy | 4716679 | 2009-01-07 00:43:54 +0000 | [diff] [blame] | 203 | struct orinoco_rx_data { |
| 204 | struct hermes_rx_descriptor *desc; |
| 205 | struct sk_buff *skb; |
| 206 | struct list_head list; |
| 207 | }; |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /********************************************************************/ |
| 210 | /* Function prototypes */ |
| 211 | /********************************************************************/ |
| 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | static void __orinoco_set_multicast_list(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | /********************************************************************/ |
| 216 | /* Internal helper functions */ |
| 217 | /********************************************************************/ |
| 218 | |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 219 | void set_port_type(struct orinoco_private *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
| 221 | switch (priv->iw_mode) { |
| 222 | case IW_MODE_INFRA: |
| 223 | priv->port_type = 1; |
| 224 | priv->createibss = 0; |
| 225 | break; |
| 226 | case IW_MODE_ADHOC: |
| 227 | if (priv->prefer_port3) { |
| 228 | priv->port_type = 3; |
| 229 | priv->createibss = 0; |
| 230 | } else { |
| 231 | priv->port_type = priv->ibss_port; |
| 232 | priv->createibss = 1; |
| 233 | } |
| 234 | break; |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 235 | case IW_MODE_MONITOR: |
| 236 | priv->port_type = 3; |
| 237 | priv->createibss = 0; |
| 238 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | default: |
| 240 | printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n", |
| 241 | priv->ndev->name); |
| 242 | } |
| 243 | } |
| 244 | |
David Kilroy | 3994d50 | 2008-08-21 23:27:54 +0100 | [diff] [blame] | 245 | /********************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | /* Device methods */ |
| 247 | /********************************************************************/ |
| 248 | |
| 249 | static int orinoco_open(struct net_device *dev) |
| 250 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 251 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | unsigned long flags; |
| 253 | int err; |
| 254 | |
| 255 | if (orinoco_lock(priv, &flags) != 0) |
| 256 | return -EBUSY; |
| 257 | |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 258 | err = __orinoco_up(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 260 | if (!err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | priv->open = 1; |
| 262 | |
| 263 | orinoco_unlock(priv, &flags); |
| 264 | |
| 265 | return err; |
| 266 | } |
| 267 | |
Christoph Hellwig | ad8f451 | 2005-05-14 17:30:17 +0200 | [diff] [blame] | 268 | static int orinoco_stop(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 270 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | int err = 0; |
| 272 | |
| 273 | /* We mustn't use orinoco_lock() here, because we need to be |
| 274 | able to close the interface even if hw_unavailable is set |
| 275 | (e.g. as we're released after a PC Card removal) */ |
| 276 | spin_lock_irq(&priv->lock); |
| 277 | |
| 278 | priv->open = 0; |
| 279 | |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 280 | err = __orinoco_down(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | spin_unlock_irq(&priv->lock); |
| 283 | |
| 284 | return err; |
| 285 | } |
| 286 | |
| 287 | static struct net_device_stats *orinoco_get_stats(struct net_device *dev) |
| 288 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 289 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return &priv->stats; |
| 292 | } |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | static void orinoco_set_multicast_list(struct net_device *dev) |
| 295 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 296 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | unsigned long flags; |
| 298 | |
| 299 | if (orinoco_lock(priv, &flags) != 0) { |
| 300 | printk(KERN_DEBUG "%s: orinoco_set_multicast_list() " |
| 301 | "called when hw_unavailable\n", dev->name); |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | __orinoco_set_multicast_list(dev); |
| 306 | orinoco_unlock(priv, &flags); |
| 307 | } |
| 308 | |
| 309 | static int orinoco_change_mtu(struct net_device *dev, int new_mtu) |
| 310 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 311 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 313 | if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | return -EINVAL; |
| 315 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 316 | /* MTU + encapsulation + header length */ |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 317 | if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) > |
| 318 | (priv->nicbuf_size - ETH_HLEN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | return -EINVAL; |
| 320 | |
| 321 | dev->mtu = new_mtu; |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | /********************************************************************/ |
| 327 | /* Tx path */ |
| 328 | /********************************************************************/ |
| 329 | |
| 330 | static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev) |
| 331 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 332 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | struct net_device_stats *stats = &priv->stats; |
| 334 | hermes_t *hw = &priv->hw; |
| 335 | int err = 0; |
| 336 | u16 txfid = priv->txfid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | struct ethhdr *eh; |
David Kilroy | 6eecad7 | 2008-08-21 23:27:56 +0100 | [diff] [blame] | 338 | int tx_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | unsigned long flags; |
| 340 | |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 341 | if (!netif_running(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | printk(KERN_ERR "%s: Tx on stopped device!\n", |
| 343 | dev->name); |
Pavel Roskin | b34b867 | 2006-04-07 04:10:36 -0400 | [diff] [blame] | 344 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | if (netif_queue_stopped(dev)) { |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 348 | printk(KERN_DEBUG "%s: Tx while transmitter busy!\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | dev->name); |
Pavel Roskin | b34b867 | 2006-04-07 04:10:36 -0400 | [diff] [blame] | 350 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (orinoco_lock(priv, &flags) != 0) { |
| 354 | printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n", |
| 355 | dev->name); |
Pavel Roskin | b34b867 | 2006-04-07 04:10:36 -0400 | [diff] [blame] | 356 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 359 | if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | /* Oops, the firmware hasn't established a connection, |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 361 | silently drop the packet (this seems to be the |
| 362 | safest approach). */ |
Pavel Roskin | 470e2aa | 2006-04-07 04:10:43 -0400 | [diff] [blame] | 363 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Pavel Roskin | 8d5be08 | 2006-04-07 04:10:41 -0400 | [diff] [blame] | 366 | /* Check packet length */ |
Pavel Roskin | a28dc81 | 2006-04-07 04:10:45 -0400 | [diff] [blame] | 367 | if (skb->len < ETH_HLEN) |
Pavel Roskin | 470e2aa | 2006-04-07 04:10:43 -0400 | [diff] [blame] | 368 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
David Kilroy | 6eecad7 | 2008-08-21 23:27:56 +0100 | [diff] [blame] | 370 | tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 372 | if (priv->encode_alg == IW_ENCODE_ALG_TKIP) |
| 373 | tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) | |
| 374 | HERMES_TXCTRL_MIC; |
| 375 | |
David Kilroy | 6eecad7 | 2008-08-21 23:27:56 +0100 | [diff] [blame] | 376 | if (priv->has_alt_txcntl) { |
| 377 | /* WPA enabled firmwares have tx_cntl at the end of |
| 378 | * the 802.11 header. So write zeroed descriptor and |
| 379 | * 802.11 header at the same time |
| 380 | */ |
| 381 | char desc[HERMES_802_3_OFFSET]; |
| 382 | __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET]; |
| 383 | |
| 384 | memset(&desc, 0, sizeof(desc)); |
| 385 | |
| 386 | *txcntl = cpu_to_le16(tx_control); |
| 387 | err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), |
| 388 | txfid, 0); |
| 389 | if (err) { |
| 390 | if (net_ratelimit()) |
| 391 | printk(KERN_ERR "%s: Error %d writing Tx " |
| 392 | "descriptor to BAP\n", dev->name, err); |
| 393 | goto busy; |
| 394 | } |
| 395 | } else { |
| 396 | struct hermes_tx_descriptor desc; |
| 397 | |
| 398 | memset(&desc, 0, sizeof(desc)); |
| 399 | |
| 400 | desc.tx_control = cpu_to_le16(tx_control); |
| 401 | err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), |
| 402 | txfid, 0); |
| 403 | if (err) { |
| 404 | if (net_ratelimit()) |
| 405 | printk(KERN_ERR "%s: Error %d writing Tx " |
| 406 | "descriptor to BAP\n", dev->name, err); |
| 407 | goto busy; |
| 408 | } |
| 409 | |
| 410 | /* Clear the 802.11 header and data length fields - some |
| 411 | * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused |
| 412 | * if this isn't done. */ |
| 413 | hermes_clear_words(hw, HERMES_DATA0, |
| 414 | HERMES_802_3_OFFSET - HERMES_802_11_OFFSET); |
| 415 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 417 | eh = (struct ethhdr *)skb->data; |
| 418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | /* Encapsulate Ethernet-II frames */ |
| 420 | if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */ |
Pavel Roskin | a28dc81 | 2006-04-07 04:10:45 -0400 | [diff] [blame] | 421 | struct header_struct { |
| 422 | struct ethhdr eth; /* 802.3 header */ |
| 423 | u8 encap[6]; /* 802.2 header */ |
| 424 | } __attribute__ ((packed)) hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Pavel Roskin | a28dc81 | 2006-04-07 04:10:45 -0400 | [diff] [blame] | 426 | /* Strip destination and source from the data */ |
| 427 | skb_pull(skb, 2 * ETH_ALEN); |
Pavel Roskin | a28dc81 | 2006-04-07 04:10:45 -0400 | [diff] [blame] | 428 | |
| 429 | /* And move them to a separate header */ |
| 430 | memcpy(&hdr.eth, eh, 2 * ETH_ALEN); |
| 431 | hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len); |
| 432 | memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr)); |
| 433 | |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 434 | /* Insert the SNAP header */ |
| 435 | if (skb_headroom(skb) < sizeof(hdr)) { |
| 436 | printk(KERN_ERR |
| 437 | "%s: Not enough headroom for 802.2 headers %d\n", |
| 438 | dev->name, skb_headroom(skb)); |
| 439 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 441 | eh = (struct ethhdr *) skb_push(skb, sizeof(hdr)); |
| 442 | memcpy(eh, &hdr, sizeof(hdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Pavel Roskin | a28dc81 | 2006-04-07 04:10:45 -0400 | [diff] [blame] | 445 | err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len, |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 446 | txfid, HERMES_802_3_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | if (err) { |
| 448 | printk(KERN_ERR "%s: Error %d writing packet to BAP\n", |
| 449 | dev->name, err); |
Pavel Roskin | 470e2aa | 2006-04-07 04:10:43 -0400 | [diff] [blame] | 450 | goto busy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 453 | /* Calculate Michael MIC */ |
| 454 | if (priv->encode_alg == IW_ENCODE_ALG_TKIP) { |
| 455 | u8 mic_buf[MICHAEL_MIC_LEN + 1]; |
| 456 | u8 *mic; |
| 457 | size_t offset; |
| 458 | size_t len; |
| 459 | |
| 460 | if (skb->len % 2) { |
| 461 | /* MIC start is on an odd boundary */ |
| 462 | mic_buf[0] = skb->data[skb->len - 1]; |
| 463 | mic = &mic_buf[1]; |
| 464 | offset = skb->len - 1; |
| 465 | len = MICHAEL_MIC_LEN + 1; |
| 466 | } else { |
| 467 | mic = &mic_buf[0]; |
| 468 | offset = skb->len; |
| 469 | len = MICHAEL_MIC_LEN; |
| 470 | } |
| 471 | |
David Kilroy | 4adb474 | 2009-02-04 23:05:51 +0000 | [diff] [blame] | 472 | orinoco_mic(priv->tx_tfm_mic, |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 473 | priv->tkip_key[priv->tx_key].tx_mic, |
| 474 | eh->h_dest, eh->h_source, 0 /* priority */, |
| 475 | skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic); |
| 476 | |
| 477 | /* Write the MIC */ |
| 478 | err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len, |
| 479 | txfid, HERMES_802_3_OFFSET + offset); |
| 480 | if (err) { |
| 481 | printk(KERN_ERR "%s: Error %d writing MIC to BAP\n", |
| 482 | dev->name, err); |
| 483 | goto busy; |
| 484 | } |
| 485 | } |
| 486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | /* Finally, we actually initiate the send */ |
| 488 | netif_stop_queue(dev); |
| 489 | |
| 490 | err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL, |
| 491 | txfid, NULL); |
| 492 | if (err) { |
| 493 | netif_start_queue(dev); |
Andrew Morton | c367c21 | 2005-10-19 21:23:44 -0700 | [diff] [blame] | 494 | if (net_ratelimit()) |
| 495 | printk(KERN_ERR "%s: Error %d transmitting packet\n", |
| 496 | dev->name, err); |
Pavel Roskin | 470e2aa | 2006-04-07 04:10:43 -0400 | [diff] [blame] | 497 | goto busy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | dev->trans_start = jiffies; |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 501 | stats->tx_bytes += HERMES_802_3_OFFSET + skb->len; |
Pavel Roskin | 470e2aa | 2006-04-07 04:10:43 -0400 | [diff] [blame] | 502 | goto ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Pavel Roskin | 470e2aa | 2006-04-07 04:10:43 -0400 | [diff] [blame] | 504 | drop: |
| 505 | stats->tx_errors++; |
| 506 | stats->tx_dropped++; |
| 507 | |
| 508 | ok: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | orinoco_unlock(priv, &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | dev_kfree_skb(skb); |
Pavel Roskin | b34b867 | 2006-04-07 04:10:36 -0400 | [diff] [blame] | 511 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Pavel Roskin | 470e2aa | 2006-04-07 04:10:43 -0400 | [diff] [blame] | 513 | busy: |
Jiri Benc | 2c1bd26 | 2006-04-07 04:10:47 -0400 | [diff] [blame] | 514 | if (err == -EIO) |
| 515 | schedule_work(&priv->reset_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | orinoco_unlock(priv, &flags); |
Pavel Roskin | b34b867 | 2006-04-07 04:10:36 -0400 | [diff] [blame] | 517 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw) |
| 521 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 522 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | u16 fid = hermes_read_regn(hw, ALLOCFID); |
| 524 | |
| 525 | if (fid != priv->txfid) { |
| 526 | if (fid != DUMMY_FID) |
| 527 | printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n", |
| 528 | dev->name, fid); |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | hermes_write_regn(hw, ALLOCFID, DUMMY_FID); |
| 533 | } |
| 534 | |
| 535 | static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw) |
| 536 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 537 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | struct net_device_stats *stats = &priv->stats; |
| 539 | |
| 540 | stats->tx_packets++; |
| 541 | |
| 542 | netif_wake_queue(dev); |
| 543 | |
| 544 | hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID); |
| 545 | } |
| 546 | |
| 547 | static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw) |
| 548 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 549 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | struct net_device_stats *stats = &priv->stats; |
| 551 | u16 fid = hermes_read_regn(hw, TXCOMPLFID); |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 552 | u16 status; |
Pavel Roskin | 30c2d3b | 2006-04-07 04:10:34 -0400 | [diff] [blame] | 553 | struct hermes_txexc_data hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | int err = 0; |
| 555 | |
| 556 | if (fid == DUMMY_FID) |
| 557 | return; /* Nothing's really happened */ |
| 558 | |
Pavel Roskin | 48ca703 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 559 | /* Read part of the frame header - we need status and addr1 */ |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 560 | err = hermes_bap_pread(hw, IRQ_BAP, &hdr, |
Pavel Roskin | 30c2d3b | 2006-04-07 04:10:34 -0400 | [diff] [blame] | 561 | sizeof(struct hermes_txexc_data), |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 562 | fid, 0); |
| 563 | |
| 564 | hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID); |
| 565 | stats->tx_errors++; |
| 566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | if (err) { |
| 568 | printk(KERN_WARNING "%s: Unable to read descriptor on Tx error " |
| 569 | "(FID=%04X error %d)\n", |
| 570 | dev->name, fid, err); |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 571 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | } |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 573 | |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 574 | DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name, |
| 575 | err, fid); |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 576 | |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 577 | /* We produce a TXDROP event only for retry or lifetime |
| 578 | * exceeded, because that's the only status that really mean |
| 579 | * that this particular node went away. |
| 580 | * Other errors means that *we* screwed up. - Jean II */ |
Pavel Roskin | 30c2d3b | 2006-04-07 04:10:34 -0400 | [diff] [blame] | 581 | status = le16_to_cpu(hdr.desc.status); |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 582 | if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) { |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 583 | union iwreq_data wrqu; |
| 584 | |
| 585 | /* Copy 802.11 dest address. |
| 586 | * We use the 802.11 header because the frame may |
| 587 | * not be 802.3 or may be mangled... |
| 588 | * In Ad-Hoc mode, it will be the node address. |
| 589 | * In managed mode, it will be most likely the AP addr |
| 590 | * User space will figure out how to convert it to |
| 591 | * whatever it needs (IP address or else). |
| 592 | * - Jean II */ |
| 593 | memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN); |
| 594 | wrqu.addr.sa_family = ARPHRD_ETHER; |
| 595 | |
| 596 | /* Send event to user space */ |
| 597 | wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL); |
| 598 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
| 600 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static void orinoco_tx_timeout(struct net_device *dev) |
| 604 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 605 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | struct net_device_stats *stats = &priv->stats; |
| 607 | struct hermes *hw = &priv->hw; |
| 608 | |
| 609 | printk(KERN_WARNING "%s: Tx timeout! " |
| 610 | "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n", |
| 611 | dev->name, hermes_read_regn(hw, ALLOCFID), |
| 612 | hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT)); |
| 613 | |
| 614 | stats->tx_errors++; |
| 615 | |
| 616 | schedule_work(&priv->reset_work); |
| 617 | } |
| 618 | |
| 619 | /********************************************************************/ |
| 620 | /* Rx path (data frames) */ |
| 621 | /********************************************************************/ |
| 622 | |
| 623 | /* Does the frame have a SNAP header indicating it should be |
| 624 | * de-encapsulated to Ethernet-II? */ |
| 625 | static inline int is_ethersnap(void *_hdr) |
| 626 | { |
| 627 | u8 *hdr = _hdr; |
| 628 | |
| 629 | /* We de-encapsulate all packets which, a) have SNAP headers |
| 630 | * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header |
| 631 | * and where b) the OUI of the SNAP header is 00:00:00 or |
| 632 | * 00:00:f8 - we need both because different APs appear to use |
| 633 | * different OUIs for some reason */ |
| 634 | return (memcmp(hdr, &encaps_hdr, 5) == 0) |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 635 | && ((hdr[5] == 0x00) || (hdr[5] == 0xf8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac, |
| 639 | int level, int noise) |
| 640 | { |
Pavel Roskin | 343c686 | 2005-09-09 18:43:02 -0400 | [diff] [blame] | 641 | struct iw_quality wstats; |
| 642 | wstats.level = level - 0x95; |
| 643 | wstats.noise = noise - 0x95; |
| 644 | wstats.qual = (level > noise) ? (level - noise) : 0; |
Andrey Borzenkov | f941f85 | 2008-11-15 17:15:09 +0300 | [diff] [blame] | 645 | wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
Pavel Roskin | 343c686 | 2005-09-09 18:43:02 -0400 | [diff] [blame] | 646 | /* Update spy records */ |
| 647 | wireless_spy_update(dev, mac, &wstats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | static void orinoco_stat_gather(struct net_device *dev, |
| 651 | struct sk_buff *skb, |
| 652 | struct hermes_rx_descriptor *desc) |
| 653 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 654 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
| 656 | /* Using spy support with lots of Rx packets, like in an |
| 657 | * infrastructure (AP), will really slow down everything, because |
| 658 | * the MAC address must be compared to each entry of the spy list. |
| 659 | * If the user really asks for it (set some address in the |
| 660 | * spy list), we do it, but he will pay the price. |
| 661 | * Note that to get here, you need both WIRELESS_SPY |
| 662 | * compiled in AND some addresses in the list !!! |
| 663 | */ |
| 664 | /* Note : gcc will optimise the whole section away if |
| 665 | * WIRELESS_SPY is not defined... - Jean II */ |
| 666 | if (SPY_NUMBER(priv)) { |
Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 667 | orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | desc->signal, desc->silence); |
| 669 | } |
| 670 | } |
| 671 | |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 672 | /* |
| 673 | * orinoco_rx_monitor - handle received monitor frames. |
| 674 | * |
| 675 | * Arguments: |
| 676 | * dev network device |
| 677 | * rxfid received FID |
| 678 | * desc rx descriptor of the frame |
| 679 | * |
| 680 | * Call context: interrupt |
| 681 | */ |
| 682 | static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid, |
| 683 | struct hermes_rx_descriptor *desc) |
| 684 | { |
| 685 | u32 hdrlen = 30; /* return full header by default */ |
| 686 | u32 datalen = 0; |
| 687 | u16 fc; |
| 688 | int err; |
| 689 | int len; |
| 690 | struct sk_buff *skb; |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 691 | struct orinoco_private *priv = ndev_priv(dev); |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 692 | struct net_device_stats *stats = &priv->stats; |
| 693 | hermes_t *hw = &priv->hw; |
| 694 | |
| 695 | len = le16_to_cpu(desc->data_len); |
| 696 | |
| 697 | /* Determine the size of the header and the data */ |
| 698 | fc = le16_to_cpu(desc->frame_ctl); |
| 699 | switch (fc & IEEE80211_FCTL_FTYPE) { |
| 700 | case IEEE80211_FTYPE_DATA: |
| 701 | if ((fc & IEEE80211_FCTL_TODS) |
| 702 | && (fc & IEEE80211_FCTL_FROMDS)) |
| 703 | hdrlen = 30; |
| 704 | else |
| 705 | hdrlen = 24; |
| 706 | datalen = len; |
| 707 | break; |
| 708 | case IEEE80211_FTYPE_MGMT: |
| 709 | hdrlen = 24; |
| 710 | datalen = len; |
| 711 | break; |
| 712 | case IEEE80211_FTYPE_CTL: |
| 713 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 714 | case IEEE80211_STYPE_PSPOLL: |
| 715 | case IEEE80211_STYPE_RTS: |
| 716 | case IEEE80211_STYPE_CFEND: |
| 717 | case IEEE80211_STYPE_CFENDACK: |
| 718 | hdrlen = 16; |
| 719 | break; |
| 720 | case IEEE80211_STYPE_CTS: |
| 721 | case IEEE80211_STYPE_ACK: |
| 722 | hdrlen = 10; |
| 723 | break; |
| 724 | } |
| 725 | break; |
| 726 | default: |
| 727 | /* Unknown frame type */ |
| 728 | break; |
| 729 | } |
| 730 | |
| 731 | /* sanity check the length */ |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 732 | if (datalen > IEEE80211_MAX_DATA_LEN + 12) { |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 733 | printk(KERN_DEBUG "%s: oversized monitor frame, " |
| 734 | "data length = %d\n", dev->name, datalen); |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 735 | stats->rx_length_errors++; |
| 736 | goto update_stats; |
| 737 | } |
| 738 | |
| 739 | skb = dev_alloc_skb(hdrlen + datalen); |
| 740 | if (!skb) { |
| 741 | printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n", |
| 742 | dev->name); |
Florin Malita | bb6e093 | 2006-05-22 22:35:30 -0700 | [diff] [blame] | 743 | goto update_stats; |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /* Copy the 802.11 header to the skb */ |
| 747 | memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen); |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 748 | skb_reset_mac_header(skb); |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 749 | |
| 750 | /* If any, copy the data from the card to the skb */ |
| 751 | if (datalen > 0) { |
| 752 | err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen), |
| 753 | ALIGN(datalen, 2), rxfid, |
| 754 | HERMES_802_2_OFFSET); |
| 755 | if (err) { |
| 756 | printk(KERN_ERR "%s: error %d reading monitor frame\n", |
| 757 | dev->name, err); |
| 758 | goto drop; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | skb->dev = dev; |
| 763 | skb->ip_summed = CHECKSUM_NONE; |
| 764 | skb->pkt_type = PACKET_OTHERHOST; |
Harvey Harrison | c1b4aa3 | 2009-01-29 13:26:44 -0800 | [diff] [blame] | 765 | skb->protocol = cpu_to_be16(ETH_P_802_2); |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 766 | |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 767 | stats->rx_packets++; |
| 768 | stats->rx_bytes += skb->len; |
| 769 | |
| 770 | netif_rx(skb); |
| 771 | return; |
| 772 | |
| 773 | drop: |
| 774 | dev_kfree_skb_irq(skb); |
| 775 | update_stats: |
| 776 | stats->rx_errors++; |
| 777 | stats->rx_dropped++; |
| 778 | } |
| 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw) |
| 781 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 782 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | struct net_device_stats *stats = &priv->stats; |
| 784 | struct iw_statistics *wstats = &priv->wstats; |
| 785 | struct sk_buff *skb = NULL; |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 786 | u16 rxfid, status; |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 787 | int length; |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 788 | struct hermes_rx_descriptor *desc; |
| 789 | struct orinoco_rx_data *rx_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | int err; |
| 791 | |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 792 | desc = kmalloc(sizeof(*desc), GFP_ATOMIC); |
| 793 | if (!desc) { |
| 794 | printk(KERN_WARNING |
| 795 | "%s: Can't allocate space for RX descriptor\n", |
| 796 | dev->name); |
| 797 | goto update_stats; |
| 798 | } |
| 799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | rxfid = hermes_read_regn(hw, RXFID); |
| 801 | |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 802 | err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | rxfid, 0); |
| 804 | if (err) { |
| 805 | printk(KERN_ERR "%s: error %d reading Rx descriptor. " |
| 806 | "Frame dropped.\n", dev->name, err); |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 807 | goto update_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 810 | status = le16_to_cpu(desc->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 812 | if (status & HERMES_RXSTAT_BADCRC) { |
| 813 | DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", |
| 814 | dev->name); |
| 815 | stats->rx_crc_errors++; |
| 816 | goto update_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 819 | /* Handle frames in monitor mode */ |
| 820 | if (priv->iw_mode == IW_MODE_MONITOR) { |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 821 | orinoco_rx_monitor(dev, rxfid, desc); |
| 822 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 825 | if (status & HERMES_RXSTAT_UNDECRYPTABLE) { |
| 826 | DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n", |
| 827 | dev->name); |
| 828 | wstats->discard.code++; |
| 829 | goto update_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
| 831 | |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 832 | length = le16_to_cpu(desc->data_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | /* Sanity checks */ |
| 835 | if (length < 3) { /* No for even an 802.2 LLC header */ |
| 836 | /* At least on Symbol firmware with PCF we get quite a |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 837 | lot of these legitimately - Poll frames with no |
| 838 | data. */ |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 839 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 841 | if (length > IEEE80211_MAX_DATA_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n", |
| 843 | dev->name, length); |
| 844 | stats->rx_length_errors++; |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 845 | goto update_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | } |
| 847 | |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 848 | /* Payload size does not include Michael MIC. Increase payload |
| 849 | * size to read it together with the data. */ |
| 850 | if (status & HERMES_RXSTAT_MIC) |
| 851 | length += MICHAEL_MIC_LEN; |
| 852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | /* We need space for the packet data itself, plus an ethernet |
| 854 | header, plus 2 bytes so we can align the IP header on a |
| 855 | 32bit boundary, plus 1 byte so we can read in odd length |
| 856 | packets from the card, which has an IO granularity of 16 |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 857 | bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | skb = dev_alloc_skb(length+ETH_HLEN+2+1); |
| 859 | if (!skb) { |
| 860 | printk(KERN_WARNING "%s: Can't allocate skb for Rx\n", |
| 861 | dev->name); |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 862 | goto update_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 865 | /* We'll prepend the header, so reserve space for it. The worst |
| 866 | case is no decapsulation, when 802.3 header is prepended and |
| 867 | nothing is removed. 2 is for aligning the IP header. */ |
| 868 | skb_reserve(skb, ETH_HLEN + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 870 | err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length), |
| 871 | ALIGN(length, 2), rxfid, |
| 872 | HERMES_802_2_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | if (err) { |
| 874 | printk(KERN_ERR "%s: error %d reading frame. " |
| 875 | "Frame dropped.\n", dev->name, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | goto drop; |
| 877 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 879 | /* Add desc and skb to rx queue */ |
| 880 | rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC); |
| 881 | if (!rx_data) { |
| 882 | printk(KERN_WARNING "%s: Can't allocate RX packet\n", |
| 883 | dev->name); |
| 884 | goto drop; |
| 885 | } |
| 886 | rx_data->desc = desc; |
| 887 | rx_data->skb = skb; |
| 888 | list_add_tail(&rx_data->list, &priv->rx_list); |
| 889 | tasklet_schedule(&priv->rx_tasklet); |
| 890 | |
| 891 | return; |
| 892 | |
| 893 | drop: |
| 894 | dev_kfree_skb_irq(skb); |
| 895 | update_stats: |
| 896 | stats->rx_errors++; |
| 897 | stats->rx_dropped++; |
| 898 | out: |
| 899 | kfree(desc); |
| 900 | } |
| 901 | |
| 902 | static void orinoco_rx(struct net_device *dev, |
| 903 | struct hermes_rx_descriptor *desc, |
| 904 | struct sk_buff *skb) |
| 905 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 906 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 907 | struct net_device_stats *stats = &priv->stats; |
| 908 | u16 status, fc; |
| 909 | int length; |
| 910 | struct ethhdr *hdr; |
| 911 | |
| 912 | status = le16_to_cpu(desc->status); |
| 913 | length = le16_to_cpu(desc->data_len); |
| 914 | fc = le16_to_cpu(desc->frame_ctl); |
| 915 | |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 916 | /* Calculate and check MIC */ |
| 917 | if (status & HERMES_RXSTAT_MIC) { |
| 918 | int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >> |
| 919 | HERMES_MIC_KEY_ID_SHIFT); |
| 920 | u8 mic[MICHAEL_MIC_LEN]; |
| 921 | u8 *rxmic; |
| 922 | u8 *src = (fc & IEEE80211_FCTL_FROMDS) ? |
| 923 | desc->addr3 : desc->addr2; |
| 924 | |
| 925 | /* Extract Michael MIC from payload */ |
| 926 | rxmic = skb->data + skb->len - MICHAEL_MIC_LEN; |
| 927 | |
| 928 | skb_trim(skb, skb->len - MICHAEL_MIC_LEN); |
| 929 | length -= MICHAEL_MIC_LEN; |
| 930 | |
David Kilroy | 4adb474 | 2009-02-04 23:05:51 +0000 | [diff] [blame] | 931 | orinoco_mic(priv->rx_tfm_mic, |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 932 | priv->tkip_key[key_id].rx_mic, |
| 933 | desc->addr1, |
| 934 | src, |
| 935 | 0, /* priority or QoS? */ |
| 936 | skb->data, |
| 937 | skb->len, |
| 938 | &mic[0]); |
| 939 | |
| 940 | if (memcmp(mic, rxmic, |
| 941 | MICHAEL_MIC_LEN)) { |
| 942 | union iwreq_data wrqu; |
| 943 | struct iw_michaelmicfailure wxmic; |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 944 | |
| 945 | printk(KERN_WARNING "%s: " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 946 | "Invalid Michael MIC in data frame from %pM, " |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 947 | "using key %i\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 948 | dev->name, src, key_id); |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 949 | |
| 950 | /* TODO: update stats */ |
| 951 | |
| 952 | /* Notify userspace */ |
| 953 | memset(&wxmic, 0, sizeof(wxmic)); |
| 954 | wxmic.flags = key_id & IW_MICFAILURE_KEY_ID; |
| 955 | wxmic.flags |= (desc->addr1[0] & 1) ? |
| 956 | IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE; |
| 957 | wxmic.src_addr.sa_family = ARPHRD_ETHER; |
| 958 | memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN); |
| 959 | |
| 960 | (void) orinoco_hw_get_tkip_iv(priv, key_id, |
| 961 | &wxmic.tsc[0]); |
| 962 | |
| 963 | memset(&wrqu, 0, sizeof(wrqu)); |
| 964 | wrqu.data.length = sizeof(wxmic); |
| 965 | wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, |
| 966 | (char *) &wxmic); |
| 967 | |
| 968 | goto drop; |
| 969 | } |
| 970 | } |
| 971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | /* Handle decapsulation |
| 973 | * In most cases, the firmware tell us about SNAP frames. |
| 974 | * For some reason, the SNAP frames sent by LinkSys APs |
| 975 | * are not properly recognised by most firmwares. |
| 976 | * So, check ourselves */ |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 977 | if (length >= ENCAPS_OVERHEAD && |
| 978 | (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) || |
| 979 | ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) || |
| 980 | is_ethersnap(skb->data))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | /* These indicate a SNAP within 802.2 LLC within |
| 982 | 802.11 frame which we'll need to de-encapsulate to |
| 983 | the original EthernetII frame. */ |
David Kilroy | b2f30a0 | 2009-02-04 23:05:46 +0000 | [diff] [blame] | 984 | hdr = (struct ethhdr *)skb_push(skb, |
| 985 | ETH_HLEN - ENCAPS_OVERHEAD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | } else { |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 987 | /* 802.3 frame - prepend 802.3 header as is */ |
| 988 | hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN); |
| 989 | hdr->h_proto = htons(length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 991 | memcpy(hdr->h_dest, desc->addr1, ETH_ALEN); |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 992 | if (fc & IEEE80211_FCTL_FROMDS) |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 993 | memcpy(hdr->h_source, desc->addr3, ETH_ALEN); |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 994 | else |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 995 | memcpy(hdr->h_source, desc->addr2, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | skb->protocol = eth_type_trans(skb, dev); |
| 998 | skb->ip_summed = CHECKSUM_NONE; |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 999 | if (fc & IEEE80211_FCTL_TODS) |
| 1000 | skb->pkt_type = PACKET_OTHERHOST; |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | /* Process the wireless stats if needed */ |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 1003 | orinoco_stat_gather(dev, skb, desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
| 1005 | /* Pass the packet to the networking stack */ |
| 1006 | netif_rx(skb); |
| 1007 | stats->rx_packets++; |
| 1008 | stats->rx_bytes += length; |
| 1009 | |
| 1010 | return; |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 1011 | |
| 1012 | drop: |
| 1013 | dev_kfree_skb(skb); |
| 1014 | stats->rx_errors++; |
| 1015 | stats->rx_dropped++; |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 1016 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 1018 | static void orinoco_rx_isr_tasklet(unsigned long data) |
| 1019 | { |
David Kilroy | 5381956 | 2009-06-18 23:21:28 +0100 | [diff] [blame^] | 1020 | struct orinoco_private *priv = (struct orinoco_private *) data; |
| 1021 | struct net_device *dev = priv->ndev; |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 1022 | struct orinoco_rx_data *rx_data, *temp; |
| 1023 | struct hermes_rx_descriptor *desc; |
| 1024 | struct sk_buff *skb; |
David Kilroy | 20953ad | 2009-01-07 00:23:55 +0000 | [diff] [blame] | 1025 | unsigned long flags; |
| 1026 | |
| 1027 | /* orinoco_rx requires the driver lock, and we also need to |
| 1028 | * protect priv->rx_list, so just hold the lock over the |
| 1029 | * lot. |
| 1030 | * |
| 1031 | * If orinoco_lock fails, we've unplugged the card. In this |
| 1032 | * case just abort. */ |
| 1033 | if (orinoco_lock(priv, &flags) != 0) |
| 1034 | return; |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 1035 | |
| 1036 | /* extract desc and skb from queue */ |
| 1037 | list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) { |
| 1038 | desc = rx_data->desc; |
| 1039 | skb = rx_data->skb; |
| 1040 | list_del(&rx_data->list); |
| 1041 | kfree(rx_data); |
| 1042 | |
| 1043 | orinoco_rx(dev, desc, skb); |
| 1044 | |
| 1045 | kfree(desc); |
| 1046 | } |
David Kilroy | 20953ad | 2009-01-07 00:23:55 +0000 | [diff] [blame] | 1047 | |
| 1048 | orinoco_unlock(priv, &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | /********************************************************************/ |
| 1052 | /* Rx path (info frames) */ |
| 1053 | /********************************************************************/ |
| 1054 | |
| 1055 | static void print_linkstatus(struct net_device *dev, u16 status) |
| 1056 | { |
David Kilroy | 2131266 | 2009-02-04 23:05:47 +0000 | [diff] [blame] | 1057 | char *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | |
| 1059 | if (suppress_linkstatus) |
| 1060 | return; |
| 1061 | |
| 1062 | switch (status) { |
| 1063 | case HERMES_LINKSTATUS_NOT_CONNECTED: |
| 1064 | s = "Not Connected"; |
| 1065 | break; |
| 1066 | case HERMES_LINKSTATUS_CONNECTED: |
| 1067 | s = "Connected"; |
| 1068 | break; |
| 1069 | case HERMES_LINKSTATUS_DISCONNECTED: |
| 1070 | s = "Disconnected"; |
| 1071 | break; |
| 1072 | case HERMES_LINKSTATUS_AP_CHANGE: |
| 1073 | s = "AP Changed"; |
| 1074 | break; |
| 1075 | case HERMES_LINKSTATUS_AP_OUT_OF_RANGE: |
| 1076 | s = "AP Out of Range"; |
| 1077 | break; |
| 1078 | case HERMES_LINKSTATUS_AP_IN_RANGE: |
| 1079 | s = "AP In Range"; |
| 1080 | break; |
| 1081 | case HERMES_LINKSTATUS_ASSOC_FAILED: |
| 1082 | s = "Association Failed"; |
| 1083 | break; |
| 1084 | default: |
| 1085 | s = "UNKNOWN"; |
| 1086 | } |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1087 | |
Pavel Roskin | 11eaea4 | 2009-01-18 23:20:58 -0500 | [diff] [blame] | 1088 | printk(KERN_DEBUG "%s: New link status: %s (%04x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | dev->name, s, status); |
| 1090 | } |
| 1091 | |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1092 | /* Search scan results for requested BSSID, join it if found */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1093 | static void orinoco_join_ap(struct work_struct *work) |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1094 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1095 | struct orinoco_private *priv = |
| 1096 | container_of(work, struct orinoco_private, join_work); |
| 1097 | struct net_device *dev = priv->ndev; |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1098 | struct hermes *hw = &priv->hw; |
| 1099 | int err; |
| 1100 | unsigned long flags; |
| 1101 | struct join_req { |
| 1102 | u8 bssid[ETH_ALEN]; |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 1103 | __le16 channel; |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1104 | } __attribute__ ((packed)) req; |
| 1105 | const int atom_len = offsetof(struct prism2_scan_apinfo, atim); |
Pavel Roskin | c89cc22 | 2005-09-01 20:06:06 -0400 | [diff] [blame] | 1106 | struct prism2_scan_apinfo *atom = NULL; |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1107 | int offset = 4; |
Pavel Roskin | c89cc22 | 2005-09-01 20:06:06 -0400 | [diff] [blame] | 1108 | int found = 0; |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1109 | u8 *buf; |
| 1110 | u16 len; |
| 1111 | |
| 1112 | /* Allocate buffer for scan results */ |
| 1113 | buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL); |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 1114 | if (!buf) |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1115 | return; |
| 1116 | |
| 1117 | if (orinoco_lock(priv, &flags) != 0) |
Pavel Roskin | f3cb4cc | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 1118 | goto fail_lock; |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1119 | |
| 1120 | /* Sanity checks in case user changed something in the meantime */ |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 1121 | if (!priv->bssid_fixed) |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1122 | goto out; |
| 1123 | |
| 1124 | if (strlen(priv->desired_essid) == 0) |
| 1125 | goto out; |
| 1126 | |
| 1127 | /* Read scan results from the firmware */ |
| 1128 | err = hermes_read_ltv(hw, USER_BAP, |
| 1129 | HERMES_RID_SCANRESULTSTABLE, |
| 1130 | MAX_SCAN_LEN, &len, buf); |
| 1131 | if (err) { |
| 1132 | printk(KERN_ERR "%s: Cannot read scan results\n", |
| 1133 | dev->name); |
| 1134 | goto out; |
| 1135 | } |
| 1136 | |
| 1137 | len = HERMES_RECLEN_TO_BYTES(len); |
| 1138 | |
| 1139 | /* Go through the scan results looking for the channel of the AP |
| 1140 | * we were requested to join */ |
| 1141 | for (; offset + atom_len <= len; offset += atom_len) { |
| 1142 | atom = (struct prism2_scan_apinfo *) (buf + offset); |
Pavel Roskin | c89cc22 | 2005-09-01 20:06:06 -0400 | [diff] [blame] | 1143 | if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) { |
| 1144 | found = 1; |
| 1145 | break; |
| 1146 | } |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1147 | } |
| 1148 | |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 1149 | if (!found) { |
Pavel Roskin | c89cc22 | 2005-09-01 20:06:06 -0400 | [diff] [blame] | 1150 | DEBUG(1, "%s: Requested AP not found in scan results\n", |
| 1151 | dev->name); |
| 1152 | goto out; |
| 1153 | } |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1154 | |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1155 | memcpy(req.bssid, priv->desired_bssid, ETH_ALEN); |
| 1156 | req.channel = atom->channel; /* both are little-endian */ |
| 1157 | err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST, |
| 1158 | &req); |
| 1159 | if (err) |
| 1160 | printk(KERN_ERR "%s: Error issuing join request\n", dev->name); |
| 1161 | |
| 1162 | out: |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1163 | orinoco_unlock(priv, &flags); |
Pavel Roskin | f3cb4cc | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 1164 | |
| 1165 | fail_lock: |
| 1166 | kfree(buf); |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1167 | } |
| 1168 | |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1169 | /* Send new BSSID to userspace */ |
David Kilroy | 6cd90b1 | 2008-08-21 23:28:00 +0100 | [diff] [blame] | 1170 | static void orinoco_send_bssid_wevent(struct orinoco_private *priv) |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1171 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1172 | struct net_device *dev = priv->ndev; |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1173 | struct hermes *hw = &priv->hw; |
| 1174 | union iwreq_data wrqu; |
| 1175 | int err; |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1176 | |
David Kilroy | 499b702 | 2008-12-09 21:46:29 +0000 | [diff] [blame] | 1177 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID, |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1178 | ETH_ALEN, NULL, wrqu.ap_addr.sa_data); |
| 1179 | if (err != 0) |
David Kilroy | 6cd90b1 | 2008-08-21 23:28:00 +0100 | [diff] [blame] | 1180 | return; |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1181 | |
| 1182 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1183 | |
| 1184 | /* Send event to user space */ |
| 1185 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1186 | } |
| 1187 | |
David Kilroy | 06009fd | 2008-08-21 23:28:03 +0100 | [diff] [blame] | 1188 | static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv) |
| 1189 | { |
| 1190 | struct net_device *dev = priv->ndev; |
| 1191 | struct hermes *hw = &priv->hw; |
| 1192 | union iwreq_data wrqu; |
| 1193 | int err; |
| 1194 | u8 buf[88]; |
| 1195 | u8 *ie; |
| 1196 | |
| 1197 | if (!priv->has_wpa) |
| 1198 | return; |
| 1199 | |
David Kilroy | 499b702 | 2008-12-09 21:46:29 +0000 | [diff] [blame] | 1200 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO, |
David Kilroy | 06009fd | 2008-08-21 23:28:03 +0100 | [diff] [blame] | 1201 | sizeof(buf), NULL, &buf); |
| 1202 | if (err != 0) |
| 1203 | return; |
| 1204 | |
| 1205 | ie = orinoco_get_wpa_ie(buf, sizeof(buf)); |
| 1206 | if (ie) { |
| 1207 | int rem = sizeof(buf) - (ie - &buf[0]); |
| 1208 | wrqu.data.length = ie[1] + 2; |
| 1209 | if (wrqu.data.length > rem) |
| 1210 | wrqu.data.length = rem; |
| 1211 | |
| 1212 | if (wrqu.data.length) |
| 1213 | /* Send event to user space */ |
| 1214 | wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie); |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv) |
| 1219 | { |
| 1220 | struct net_device *dev = priv->ndev; |
| 1221 | struct hermes *hw = &priv->hw; |
| 1222 | union iwreq_data wrqu; |
| 1223 | int err; |
| 1224 | u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */ |
| 1225 | u8 *ie; |
| 1226 | |
| 1227 | if (!priv->has_wpa) |
| 1228 | return; |
| 1229 | |
David Kilroy | 499b702 | 2008-12-09 21:46:29 +0000 | [diff] [blame] | 1230 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO, |
David Kilroy | 06009fd | 2008-08-21 23:28:03 +0100 | [diff] [blame] | 1231 | sizeof(buf), NULL, &buf); |
| 1232 | if (err != 0) |
| 1233 | return; |
| 1234 | |
| 1235 | ie = orinoco_get_wpa_ie(buf, sizeof(buf)); |
| 1236 | if (ie) { |
| 1237 | int rem = sizeof(buf) - (ie - &buf[0]); |
| 1238 | wrqu.data.length = ie[1] + 2; |
| 1239 | if (wrqu.data.length > rem) |
| 1240 | wrqu.data.length = rem; |
| 1241 | |
| 1242 | if (wrqu.data.length) |
| 1243 | /* Send event to user space */ |
| 1244 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie); |
| 1245 | } |
| 1246 | } |
| 1247 | |
David Kilroy | 6cd90b1 | 2008-08-21 23:28:00 +0100 | [diff] [blame] | 1248 | static void orinoco_send_wevents(struct work_struct *work) |
| 1249 | { |
| 1250 | struct orinoco_private *priv = |
| 1251 | container_of(work, struct orinoco_private, wevent_work); |
| 1252 | unsigned long flags; |
| 1253 | |
| 1254 | if (orinoco_lock(priv, &flags) != 0) |
| 1255 | return; |
| 1256 | |
David Kilroy | 06009fd | 2008-08-21 23:28:03 +0100 | [diff] [blame] | 1257 | orinoco_send_assocreqie_wevent(priv); |
| 1258 | orinoco_send_assocrespie_wevent(priv); |
David Kilroy | 6cd90b1 | 2008-08-21 23:28:00 +0100 | [diff] [blame] | 1259 | orinoco_send_bssid_wevent(priv); |
| 1260 | |
| 1261 | orinoco_unlock(priv, &flags); |
| 1262 | } |
Dan Williams | 1e3428e | 2007-10-10 23:56:25 -0400 | [diff] [blame] | 1263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw) |
| 1265 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1266 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | u16 infofid; |
| 1268 | struct { |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 1269 | __le16 len; |
| 1270 | __le16 type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | } __attribute__ ((packed)) info; |
| 1272 | int len, type; |
| 1273 | int err; |
| 1274 | |
| 1275 | /* This is an answer to an INQUIRE command that we did earlier, |
| 1276 | * or an information "event" generated by the card |
| 1277 | * The controller return to us a pseudo frame containing |
| 1278 | * the information in question - Jean II */ |
| 1279 | infofid = hermes_read_regn(hw, INFOFID); |
| 1280 | |
| 1281 | /* Read the info frame header - don't try too hard */ |
| 1282 | err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info), |
| 1283 | infofid, 0); |
| 1284 | if (err) { |
| 1285 | printk(KERN_ERR "%s: error %d reading info frame. " |
| 1286 | "Frame dropped.\n", dev->name, err); |
| 1287 | return; |
| 1288 | } |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len)); |
| 1291 | type = le16_to_cpu(info.type); |
| 1292 | |
| 1293 | switch (type) { |
| 1294 | case HERMES_INQ_TALLIES: { |
| 1295 | struct hermes_tallies_frame tallies; |
| 1296 | struct iw_statistics *wstats = &priv->wstats; |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | if (len > sizeof(tallies)) { |
| 1299 | printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n", |
| 1300 | dev->name, len); |
| 1301 | len = sizeof(tallies); |
| 1302 | } |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1303 | |
Christoph Hellwig | 84d8a2f | 2005-05-14 17:30:22 +0200 | [diff] [blame] | 1304 | err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len, |
| 1305 | infofid, sizeof(info)); |
| 1306 | if (err) |
| 1307 | break; |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | /* Increment our various counters */ |
| 1310 | /* wstats->discard.nwid - no wrong BSSID stuff */ |
| 1311 | wstats->discard.code += |
| 1312 | le16_to_cpu(tallies.RxWEPUndecryptable); |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1313 | if (len == sizeof(tallies)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | wstats->discard.code += |
| 1315 | le16_to_cpu(tallies.RxDiscards_WEPICVError) + |
| 1316 | le16_to_cpu(tallies.RxDiscards_WEPExcluded); |
| 1317 | wstats->discard.misc += |
| 1318 | le16_to_cpu(tallies.TxDiscardsWrongSA); |
| 1319 | wstats->discard.fragment += |
| 1320 | le16_to_cpu(tallies.RxMsgInBadMsgFragments); |
| 1321 | wstats->discard.retries += |
| 1322 | le16_to_cpu(tallies.TxRetryLimitExceeded); |
| 1323 | /* wstats->miss.beacon - no match */ |
| 1324 | } |
| 1325 | break; |
| 1326 | case HERMES_INQ_LINKSTATUS: { |
| 1327 | struct hermes_linkstatus linkstatus; |
| 1328 | u16 newstatus; |
| 1329 | int connected; |
| 1330 | |
Christoph Hellwig | 8f2abf4 | 2005-06-19 01:28:02 +0200 | [diff] [blame] | 1331 | if (priv->iw_mode == IW_MODE_MONITOR) |
| 1332 | break; |
| 1333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | if (len != sizeof(linkstatus)) { |
| 1335 | printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n", |
| 1336 | dev->name, len); |
| 1337 | break; |
| 1338 | } |
| 1339 | |
Christoph Hellwig | 84d8a2f | 2005-05-14 17:30:22 +0200 | [diff] [blame] | 1340 | err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len, |
| 1341 | infofid, sizeof(info)); |
| 1342 | if (err) |
| 1343 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | newstatus = le16_to_cpu(linkstatus.linkstatus); |
| 1345 | |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1346 | /* Symbol firmware uses "out of range" to signal that |
| 1347 | * the hostscan frame can be requested. */ |
| 1348 | if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE && |
| 1349 | priv->firmware_type == FIRMWARE_TYPE_SYMBOL && |
| 1350 | priv->has_hostscan && priv->scan_inprogress) { |
| 1351 | hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL); |
| 1352 | break; |
| 1353 | } |
| 1354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | connected = (newstatus == HERMES_LINKSTATUS_CONNECTED) |
| 1356 | || (newstatus == HERMES_LINKSTATUS_AP_CHANGE) |
| 1357 | || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE); |
| 1358 | |
| 1359 | if (connected) |
| 1360 | netif_carrier_on(dev); |
David Gibson | 7bb7c3a | 2005-05-12 20:02:10 -0400 | [diff] [blame] | 1361 | else if (!ignore_disconnect) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | netif_carrier_off(dev); |
| 1363 | |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1364 | if (newstatus != priv->last_linkstatus) { |
| 1365 | priv->last_linkstatus = newstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | print_linkstatus(dev, newstatus); |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1367 | /* The info frame contains only one word which is the |
| 1368 | * status (see hermes.h). The status is pretty boring |
| 1369 | * in itself, that's why we export the new BSSID... |
| 1370 | * Jean II */ |
| 1371 | schedule_work(&priv->wevent_work); |
| 1372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | } |
| 1374 | break; |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1375 | case HERMES_INQ_SCAN: |
| 1376 | if (!priv->scan_inprogress && priv->bssid_fixed && |
| 1377 | priv->firmware_type == FIRMWARE_TYPE_INTERSIL) { |
| 1378 | schedule_work(&priv->join_work); |
| 1379 | break; |
| 1380 | } |
| 1381 | /* fall through */ |
| 1382 | case HERMES_INQ_HOSTSCAN: |
| 1383 | case HERMES_INQ_HOSTSCAN_SYMBOL: { |
| 1384 | /* Result of a scanning. Contains information about |
| 1385 | * cells in the vicinity - Jean II */ |
| 1386 | union iwreq_data wrqu; |
| 1387 | unsigned char *buf; |
| 1388 | |
Dan Williams | 1e3428e | 2007-10-10 23:56:25 -0400 | [diff] [blame] | 1389 | /* Scan is no longer in progress */ |
| 1390 | priv->scan_inprogress = 0; |
| 1391 | |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1392 | /* Sanity check */ |
| 1393 | if (len > 4096) { |
| 1394 | printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n", |
| 1395 | dev->name, len); |
| 1396 | break; |
| 1397 | } |
| 1398 | |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1399 | /* Allocate buffer for results */ |
| 1400 | buf = kmalloc(len, GFP_ATOMIC); |
| 1401 | if (buf == NULL) |
| 1402 | /* No memory, so can't printk()... */ |
| 1403 | break; |
| 1404 | |
| 1405 | /* Read scan data */ |
| 1406 | err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len, |
| 1407 | infofid, sizeof(info)); |
Pavel Roskin | 708218b | 2005-09-01 20:05:19 -0400 | [diff] [blame] | 1408 | if (err) { |
| 1409 | kfree(buf); |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1410 | break; |
Pavel Roskin | 708218b | 2005-09-01 20:05:19 -0400 | [diff] [blame] | 1411 | } |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1412 | |
| 1413 | #ifdef ORINOCO_DEBUG |
| 1414 | { |
| 1415 | int i; |
| 1416 | printk(KERN_DEBUG "Scan result [%02X", buf[0]); |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 1417 | for (i = 1; i < (len * 2); i++) |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1418 | printk(":%02X", buf[i]); |
| 1419 | printk("]\n"); |
| 1420 | } |
| 1421 | #endif /* ORINOCO_DEBUG */ |
| 1422 | |
David Kilroy | aea48b1 | 2009-02-04 23:05:49 +0000 | [diff] [blame] | 1423 | if (orinoco_process_scan_results(priv, buf, len) == 0) { |
Dan Williams | 1e3428e | 2007-10-10 23:56:25 -0400 | [diff] [blame] | 1424 | /* Send an empty event to user space. |
| 1425 | * We don't send the received data on the event because |
| 1426 | * it would require us to do complex transcoding, and |
| 1427 | * we want to minimise the work done in the irq handler |
| 1428 | * Use a request to extract the data - Jean II */ |
| 1429 | wrqu.data.length = 0; |
| 1430 | wrqu.data.flags = 0; |
| 1431 | wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL); |
| 1432 | } |
| 1433 | kfree(buf); |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1434 | } |
| 1435 | break; |
David Kilroy | 01632fa | 2008-08-21 23:27:58 +0100 | [diff] [blame] | 1436 | case HERMES_INQ_CHANNELINFO: |
| 1437 | { |
| 1438 | struct agere_ext_scan_info *bss; |
| 1439 | |
| 1440 | if (!priv->scan_inprogress) { |
| 1441 | printk(KERN_DEBUG "%s: Got chaninfo without scan, " |
| 1442 | "len=%d\n", dev->name, len); |
| 1443 | break; |
| 1444 | } |
| 1445 | |
| 1446 | /* An empty result indicates that the scan is complete */ |
| 1447 | if (len == 0) { |
| 1448 | union iwreq_data wrqu; |
| 1449 | |
| 1450 | /* Scan is no longer in progress */ |
| 1451 | priv->scan_inprogress = 0; |
| 1452 | |
| 1453 | wrqu.data.length = 0; |
| 1454 | wrqu.data.flags = 0; |
| 1455 | wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL); |
| 1456 | break; |
| 1457 | } |
| 1458 | |
| 1459 | /* Sanity check */ |
| 1460 | else if (len > sizeof(*bss)) { |
| 1461 | printk(KERN_WARNING |
| 1462 | "%s: Ext scan results too large (%d bytes). " |
| 1463 | "Truncating results to %zd bytes.\n", |
| 1464 | dev->name, len, sizeof(*bss)); |
| 1465 | len = sizeof(*bss); |
| 1466 | } else if (len < (offsetof(struct agere_ext_scan_info, |
| 1467 | data) + 2)) { |
| 1468 | /* Drop this result now so we don't have to |
| 1469 | * keep checking later */ |
| 1470 | printk(KERN_WARNING |
| 1471 | "%s: Ext scan results too short (%d bytes)\n", |
| 1472 | dev->name, len); |
| 1473 | break; |
| 1474 | } |
| 1475 | |
| 1476 | bss = kmalloc(sizeof(*bss), GFP_ATOMIC); |
| 1477 | if (bss == NULL) |
| 1478 | break; |
| 1479 | |
| 1480 | /* Read scan data */ |
| 1481 | err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len, |
| 1482 | infofid, sizeof(info)); |
| 1483 | if (err) { |
| 1484 | kfree(bss); |
| 1485 | break; |
| 1486 | } |
| 1487 | |
| 1488 | orinoco_add_ext_scan_result(priv, bss); |
| 1489 | |
| 1490 | kfree(bss); |
| 1491 | break; |
| 1492 | } |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1493 | case HERMES_INQ_SEC_STAT_AGERE: |
| 1494 | /* Security status (Agere specific) */ |
| 1495 | /* Ignore this frame for now */ |
| 1496 | if (priv->firmware_type == FIRMWARE_TYPE_AGERE) |
| 1497 | break; |
| 1498 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | default: |
| 1500 | printk(KERN_DEBUG "%s: Unknown information frame received: " |
| 1501 | "type 0x%04x, length %d\n", dev->name, type, len); |
| 1502 | /* We don't actually do anything about it */ |
| 1503 | break; |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw) |
| 1508 | { |
| 1509 | if (net_ratelimit()) |
| 1510 | printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name); |
| 1511 | } |
| 1512 | |
| 1513 | /********************************************************************/ |
| 1514 | /* Internal hardware control routines */ |
| 1515 | /********************************************************************/ |
| 1516 | |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 1517 | int __orinoco_up(struct orinoco_private *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | { |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 1519 | struct net_device *dev = priv->ndev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | struct hermes *hw = &priv->hw; |
| 1521 | int err; |
| 1522 | |
Christoph Hellwig | 84d8a2f | 2005-05-14 17:30:22 +0200 | [diff] [blame] | 1523 | netif_carrier_off(dev); /* just to make sure */ |
| 1524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | err = __orinoco_program_rids(dev); |
| 1526 | if (err) { |
| 1527 | printk(KERN_ERR "%s: Error %d configuring card\n", |
| 1528 | dev->name, err); |
| 1529 | return err; |
| 1530 | } |
| 1531 | |
| 1532 | /* Fire things up again */ |
| 1533 | hermes_set_irqmask(hw, ORINOCO_INTEN); |
| 1534 | err = hermes_enable_port(hw, 0); |
| 1535 | if (err) { |
| 1536 | printk(KERN_ERR "%s: Error %d enabling MAC port\n", |
| 1537 | dev->name, err); |
| 1538 | return err; |
| 1539 | } |
| 1540 | |
| 1541 | netif_start_queue(dev); |
| 1542 | |
| 1543 | return 0; |
| 1544 | } |
David Kilroy | 2131266 | 2009-02-04 23:05:47 +0000 | [diff] [blame] | 1545 | EXPORT_SYMBOL(__orinoco_up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 1547 | int __orinoco_down(struct orinoco_private *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | { |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 1549 | struct net_device *dev = priv->ndev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | struct hermes *hw = &priv->hw; |
| 1551 | int err; |
| 1552 | |
| 1553 | netif_stop_queue(dev); |
| 1554 | |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 1555 | if (!priv->hw_unavailable) { |
| 1556 | if (!priv->broken_disableport) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | err = hermes_disable_port(hw, 0); |
| 1558 | if (err) { |
| 1559 | /* Some firmwares (e.g. Intersil 1.3.x) seem |
| 1560 | * to have problems disabling the port, oh |
| 1561 | * well, too bad. */ |
| 1562 | printk(KERN_WARNING "%s: Error %d disabling MAC port\n", |
| 1563 | dev->name, err); |
| 1564 | priv->broken_disableport = 1; |
| 1565 | } |
| 1566 | } |
| 1567 | hermes_set_irqmask(hw, 0); |
| 1568 | hermes_write_regn(hw, EVACK, 0xffff); |
| 1569 | } |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | /* firmware will have to reassociate */ |
| 1572 | netif_carrier_off(dev); |
| 1573 | priv->last_linkstatus = 0xffff; |
| 1574 | |
| 1575 | return 0; |
| 1576 | } |
David Kilroy | 2131266 | 2009-02-04 23:05:47 +0000 | [diff] [blame] | 1577 | EXPORT_SYMBOL(__orinoco_down); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 1579 | int orinoco_reinit_firmware(struct orinoco_private *priv) |
Pavel Roskin | 37a6c61 | 2006-04-07 04:10:49 -0400 | [diff] [blame] | 1580 | { |
Pavel Roskin | 37a6c61 | 2006-04-07 04:10:49 -0400 | [diff] [blame] | 1581 | struct hermes *hw = &priv->hw; |
| 1582 | int err; |
| 1583 | |
| 1584 | err = hermes_init(hw); |
Andrey Borzenkov | 0df6cbb | 2008-10-12 20:15:43 +0400 | [diff] [blame] | 1585 | if (priv->do_fw_download && !err) { |
| 1586 | err = orinoco_download(priv); |
| 1587 | if (err) |
| 1588 | priv->do_fw_download = 0; |
| 1589 | } |
Pavel Roskin | 37a6c61 | 2006-04-07 04:10:49 -0400 | [diff] [blame] | 1590 | if (!err) |
David Kilroy | 42a51b9 | 2009-06-18 23:21:20 +0100 | [diff] [blame] | 1591 | err = orinoco_hw_allocate_fid(priv); |
Pavel Roskin | 37a6c61 | 2006-04-07 04:10:49 -0400 | [diff] [blame] | 1592 | |
| 1593 | return err; |
| 1594 | } |
David Kilroy | 2131266 | 2009-02-04 23:05:47 +0000 | [diff] [blame] | 1595 | EXPORT_SYMBOL(orinoco_reinit_firmware); |
Pavel Roskin | 37a6c61 | 2006-04-07 04:10:49 -0400 | [diff] [blame] | 1596 | |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1597 | int __orinoco_program_rids(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1599 | struct orinoco_private *priv = ndev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | hermes_t *hw = &priv->hw; |
| 1601 | int err; |
| 1602 | struct hermes_idstring idbuf; |
| 1603 | |
| 1604 | /* Set the MAC address */ |
| 1605 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR, |
| 1606 | HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr); |
| 1607 | if (err) { |
| 1608 | printk(KERN_ERR "%s: Error %d setting MAC address\n", |
| 1609 | dev->name, err); |
| 1610 | return err; |
| 1611 | } |
| 1612 | |
| 1613 | /* Set up the link mode */ |
| 1614 | err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE, |
| 1615 | priv->port_type); |
| 1616 | if (err) { |
| 1617 | printk(KERN_ERR "%s: Error %d setting port type\n", |
| 1618 | dev->name, err); |
| 1619 | return err; |
| 1620 | } |
| 1621 | /* Set the channel/frequency */ |
David Gibson | d51d8b1 | 2005-05-12 20:03:36 -0400 | [diff] [blame] | 1622 | if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) { |
| 1623 | err = hermes_write_wordrec(hw, USER_BAP, |
| 1624 | HERMES_RID_CNFOWNCHANNEL, |
| 1625 | priv->channel); |
| 1626 | if (err) { |
| 1627 | printk(KERN_ERR "%s: Error %d setting channel %d\n", |
| 1628 | dev->name, err, priv->channel); |
| 1629 | return err; |
| 1630 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | if (priv->has_ibss) { |
| 1634 | u16 createibss; |
| 1635 | |
| 1636 | if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) { |
| 1637 | printk(KERN_WARNING "%s: This firmware requires an " |
| 1638 | "ESSID in IBSS-Ad-Hoc mode.\n", dev->name); |
| 1639 | /* With wvlan_cs, in this case, we would crash. |
| 1640 | * hopefully, this driver will behave better... |
| 1641 | * Jean II */ |
| 1642 | createibss = 0; |
| 1643 | } else { |
| 1644 | createibss = priv->createibss; |
| 1645 | } |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | err = hermes_write_wordrec(hw, USER_BAP, |
| 1648 | HERMES_RID_CNFCREATEIBSS, |
| 1649 | createibss); |
| 1650 | if (err) { |
| 1651 | printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n", |
| 1652 | dev->name, err); |
| 1653 | return err; |
| 1654 | } |
| 1655 | } |
| 1656 | |
Christoph Hellwig | 16739b0 | 2005-06-19 01:27:51 +0200 | [diff] [blame] | 1657 | /* Set the desired BSSID */ |
| 1658 | err = __orinoco_hw_set_wap(priv); |
| 1659 | if (err) { |
| 1660 | printk(KERN_ERR "%s: Error %d setting AP address\n", |
| 1661 | dev->name, err); |
| 1662 | return err; |
| 1663 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | /* Set the desired ESSID */ |
| 1665 | idbuf.len = cpu_to_le16(strlen(priv->desired_essid)); |
| 1666 | memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val)); |
| 1667 | /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */ |
| 1668 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID, |
David Kilroy | b2f30a0 | 2009-02-04 23:05:46 +0000 | [diff] [blame] | 1669 | HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2), |
| 1670 | &idbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | if (err) { |
| 1672 | printk(KERN_ERR "%s: Error %d setting OWNSSID\n", |
| 1673 | dev->name, err); |
| 1674 | return err; |
| 1675 | } |
| 1676 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID, |
David Kilroy | b2f30a0 | 2009-02-04 23:05:46 +0000 | [diff] [blame] | 1677 | HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2), |
| 1678 | &idbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | if (err) { |
| 1680 | printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n", |
| 1681 | dev->name, err); |
| 1682 | return err; |
| 1683 | } |
| 1684 | |
| 1685 | /* Set the station name */ |
| 1686 | idbuf.len = cpu_to_le16(strlen(priv->nick)); |
| 1687 | memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val)); |
| 1688 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME, |
| 1689 | HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2), |
| 1690 | &idbuf); |
| 1691 | if (err) { |
| 1692 | printk(KERN_ERR "%s: Error %d setting nickname\n", |
| 1693 | dev->name, err); |
| 1694 | return err; |
| 1695 | } |
| 1696 | |
| 1697 | /* Set AP density */ |
| 1698 | if (priv->has_sensitivity) { |
| 1699 | err = hermes_write_wordrec(hw, USER_BAP, |
| 1700 | HERMES_RID_CNFSYSTEMSCALE, |
| 1701 | priv->ap_density); |
| 1702 | if (err) { |
David Kilroy | b2f30a0 | 2009-02-04 23:05:46 +0000 | [diff] [blame] | 1703 | printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | "Disabling sensitivity control\n", |
| 1705 | dev->name, err); |
| 1706 | |
| 1707 | priv->has_sensitivity = 0; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | /* Set RTS threshold */ |
| 1712 | err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD, |
| 1713 | priv->rts_thresh); |
| 1714 | if (err) { |
| 1715 | printk(KERN_ERR "%s: Error %d setting RTS threshold\n", |
| 1716 | dev->name, err); |
| 1717 | return err; |
| 1718 | } |
| 1719 | |
| 1720 | /* Set fragmentation threshold or MWO robustness */ |
| 1721 | if (priv->has_mwo) |
| 1722 | err = hermes_write_wordrec(hw, USER_BAP, |
| 1723 | HERMES_RID_CNFMWOROBUST_AGERE, |
| 1724 | priv->mwo_robust); |
| 1725 | else |
| 1726 | err = hermes_write_wordrec(hw, USER_BAP, |
| 1727 | HERMES_RID_CNFFRAGMENTATIONTHRESHOLD, |
| 1728 | priv->frag_thresh); |
| 1729 | if (err) { |
| 1730 | printk(KERN_ERR "%s: Error %d setting fragmentation\n", |
| 1731 | dev->name, err); |
| 1732 | return err; |
| 1733 | } |
| 1734 | |
| 1735 | /* Set bitrate */ |
| 1736 | err = __orinoco_hw_set_bitrate(priv); |
| 1737 | if (err) { |
| 1738 | printk(KERN_ERR "%s: Error %d setting bitrate\n", |
| 1739 | dev->name, err); |
| 1740 | return err; |
| 1741 | } |
| 1742 | |
| 1743 | /* Set power management */ |
| 1744 | if (priv->has_pm) { |
| 1745 | err = hermes_write_wordrec(hw, USER_BAP, |
| 1746 | HERMES_RID_CNFPMENABLED, |
| 1747 | priv->pm_on); |
| 1748 | if (err) { |
| 1749 | printk(KERN_ERR "%s: Error %d setting up PM\n", |
| 1750 | dev->name, err); |
| 1751 | return err; |
| 1752 | } |
| 1753 | |
| 1754 | err = hermes_write_wordrec(hw, USER_BAP, |
| 1755 | HERMES_RID_CNFMULTICASTRECEIVE, |
| 1756 | priv->pm_mcast); |
| 1757 | if (err) { |
| 1758 | printk(KERN_ERR "%s: Error %d setting up PM\n", |
| 1759 | dev->name, err); |
| 1760 | return err; |
| 1761 | } |
| 1762 | err = hermes_write_wordrec(hw, USER_BAP, |
| 1763 | HERMES_RID_CNFMAXSLEEPDURATION, |
| 1764 | priv->pm_period); |
| 1765 | if (err) { |
| 1766 | printk(KERN_ERR "%s: Error %d setting up PM\n", |
| 1767 | dev->name, err); |
| 1768 | return err; |
| 1769 | } |
| 1770 | err = hermes_write_wordrec(hw, USER_BAP, |
| 1771 | HERMES_RID_CNFPMHOLDOVERDURATION, |
| 1772 | priv->pm_timeout); |
| 1773 | if (err) { |
| 1774 | printk(KERN_ERR "%s: Error %d setting up PM\n", |
| 1775 | dev->name, err); |
| 1776 | return err; |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | /* Set preamble - only for Symbol so far... */ |
| 1781 | if (priv->has_preamble) { |
| 1782 | err = hermes_write_wordrec(hw, USER_BAP, |
| 1783 | HERMES_RID_CNFPREAMBLE_SYMBOL, |
| 1784 | priv->preamble); |
| 1785 | if (err) { |
| 1786 | printk(KERN_ERR "%s: Error %d setting preamble\n", |
| 1787 | dev->name, err); |
| 1788 | return err; |
| 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | /* Set up encryption */ |
David Kilroy | d03032a | 2008-08-21 23:28:02 +0100 | [diff] [blame] | 1793 | if (priv->has_wep || priv->has_wpa) { |
| 1794 | err = __orinoco_hw_setup_enc(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | if (err) { |
David Kilroy | d03032a | 2008-08-21 23:28:02 +0100 | [diff] [blame] | 1796 | printk(KERN_ERR "%s: Error %d activating encryption\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | dev->name, err); |
| 1798 | return err; |
| 1799 | } |
| 1800 | } |
| 1801 | |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 1802 | if (priv->iw_mode == IW_MODE_MONITOR) { |
| 1803 | /* Enable monitor mode */ |
| 1804 | dev->type = ARPHRD_IEEE80211; |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1805 | err = hermes_docmd_wait(hw, HERMES_CMD_TEST | |
Christoph Hellwig | 98c4cae | 2005-06-19 01:28:06 +0200 | [diff] [blame] | 1806 | HERMES_TEST_MONITOR, 0, NULL); |
| 1807 | } else { |
| 1808 | /* Disable monitor mode */ |
| 1809 | dev->type = ARPHRD_ETHER; |
| 1810 | err = hermes_docmd_wait(hw, HERMES_CMD_TEST | |
| 1811 | HERMES_TEST_STOP, 0, NULL); |
| 1812 | } |
| 1813 | if (err) |
| 1814 | return err; |
| 1815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | /* Set promiscuity / multicast*/ |
| 1817 | priv->promiscuous = 0; |
| 1818 | priv->mc_count = 0; |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 1819 | |
| 1820 | /* FIXME: what about netif_tx_lock */ |
| 1821 | __orinoco_set_multicast_list(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | |
| 1823 | return 0; |
| 1824 | } |
| 1825 | |
David Kilroy | 5865d01 | 2009-02-04 23:05:54 +0000 | [diff] [blame] | 1826 | /* FIXME: return int? */ |
| 1827 | static void |
| 1828 | __orinoco_set_multicast_list(struct net_device *dev) |
| 1829 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1830 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | 5865d01 | 2009-02-04 23:05:54 +0000 | [diff] [blame] | 1831 | int err = 0; |
| 1832 | int promisc, mc_count; |
| 1833 | |
| 1834 | /* The Hermes doesn't seem to have an allmulti mode, so we go |
| 1835 | * into promiscuous mode and let the upper levels deal. */ |
| 1836 | if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) || |
| 1837 | (dev->mc_count > MAX_MULTICAST(priv))) { |
| 1838 | promisc = 1; |
| 1839 | mc_count = 0; |
| 1840 | } else { |
| 1841 | promisc = 0; |
| 1842 | mc_count = dev->mc_count; |
| 1843 | } |
| 1844 | |
| 1845 | err = __orinoco_hw_set_multicast_list(priv, dev->mc_list, mc_count, |
| 1846 | promisc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | /* This must be called from user context, without locks held - use |
| 1850 | * schedule_work() */ |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1851 | void orinoco_reset(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1853 | struct orinoco_private *priv = |
| 1854 | container_of(work, struct orinoco_private, reset_work); |
| 1855 | struct net_device *dev = priv->ndev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | struct hermes *hw = &priv->hw; |
Christoph Hellwig | 8551cb9 | 2005-05-14 17:30:04 +0200 | [diff] [blame] | 1857 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | unsigned long flags; |
| 1859 | |
| 1860 | if (orinoco_lock(priv, &flags) != 0) |
| 1861 | /* When the hardware becomes available again, whatever |
| 1862 | * detects that is responsible for re-initializing |
| 1863 | * it. So no need for anything further */ |
| 1864 | return; |
| 1865 | |
| 1866 | netif_stop_queue(dev); |
| 1867 | |
| 1868 | /* Shut off interrupts. Depending on what state the hardware |
| 1869 | * is in, this might not work, but we'll try anyway */ |
| 1870 | hermes_set_irqmask(hw, 0); |
| 1871 | hermes_write_regn(hw, EVACK, 0xffff); |
| 1872 | |
| 1873 | priv->hw_unavailable++; |
| 1874 | priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */ |
| 1875 | netif_carrier_off(dev); |
| 1876 | |
| 1877 | orinoco_unlock(priv, &flags); |
| 1878 | |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1879 | /* Scanning support: Cleanup of driver struct */ |
Dan Williams | 1e3428e | 2007-10-10 23:56:25 -0400 | [diff] [blame] | 1880 | orinoco_clear_scan_results(priv, 0); |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 1881 | priv->scan_inprogress = 0; |
| 1882 | |
Christoph Hellwig | 8551cb9 | 2005-05-14 17:30:04 +0200 | [diff] [blame] | 1883 | if (priv->hard_reset) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | err = (*priv->hard_reset)(priv); |
Christoph Hellwig | 8551cb9 | 2005-05-14 17:30:04 +0200 | [diff] [blame] | 1885 | if (err) { |
| 1886 | printk(KERN_ERR "%s: orinoco_reset: Error %d " |
| 1887 | "performing hard reset\n", dev->name, err); |
| 1888 | goto disable; |
| 1889 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 1892 | err = orinoco_reinit_firmware(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | if (err) { |
| 1894 | printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n", |
| 1895 | dev->name, err); |
Christoph Hellwig | 8551cb9 | 2005-05-14 17:30:04 +0200 | [diff] [blame] | 1896 | goto disable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
David Kilroy | b2f30a0 | 2009-02-04 23:05:46 +0000 | [diff] [blame] | 1899 | /* This has to be called from user context */ |
| 1900 | spin_lock_irq(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | |
| 1902 | priv->hw_unavailable--; |
| 1903 | |
| 1904 | /* priv->open or priv->hw_unavailable might have changed while |
| 1905 | * we dropped the lock */ |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 1906 | if (priv->open && (!priv->hw_unavailable)) { |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 1907 | err = __orinoco_up(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | if (err) { |
| 1909 | printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n", |
| 1910 | dev->name, err); |
| 1911 | } else |
| 1912 | dev->trans_start = jiffies; |
| 1913 | } |
| 1914 | |
| 1915 | spin_unlock_irq(&priv->lock); |
| 1916 | |
| 1917 | return; |
Christoph Hellwig | 8551cb9 | 2005-05-14 17:30:04 +0200 | [diff] [blame] | 1918 | disable: |
| 1919 | hermes_set_irqmask(hw, 0); |
| 1920 | netif_device_detach(dev); |
| 1921 | printk(KERN_ERR "%s: Device has been disabled!\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | /********************************************************************/ |
| 1925 | /* Interrupt handler */ |
| 1926 | /********************************************************************/ |
| 1927 | |
| 1928 | static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw) |
| 1929 | { |
| 1930 | printk(KERN_DEBUG "%s: TICK\n", dev->name); |
| 1931 | } |
| 1932 | |
| 1933 | static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw) |
| 1934 | { |
| 1935 | /* This seems to happen a fair bit under load, but ignoring it |
| 1936 | seems to work fine...*/ |
| 1937 | printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n", |
| 1938 | dev->name); |
| 1939 | } |
| 1940 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1941 | irqreturn_t orinoco_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | { |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 1943 | struct orinoco_private *priv = dev_id; |
| 1944 | struct net_device *dev = priv->ndev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | hermes_t *hw = &priv->hw; |
| 1946 | int count = MAX_IRQLOOPS_PER_IRQ; |
| 1947 | u16 evstat, events; |
David Kilroy | 2131266 | 2009-02-04 23:05:47 +0000 | [diff] [blame] | 1948 | /* These are used to detect a runaway interrupt situation. |
| 1949 | * |
| 1950 | * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy, |
| 1951 | * we panic and shut down the hardware |
| 1952 | */ |
| 1953 | /* jiffies value the last time we were called */ |
| 1954 | static int last_irq_jiffy; /* = 0 */ |
| 1955 | static int loops_this_jiffy; /* = 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | unsigned long flags; |
| 1957 | |
| 1958 | if (orinoco_lock(priv, &flags) != 0) { |
| 1959 | /* If hw is unavailable - we don't know if the irq was |
| 1960 | * for us or not */ |
| 1961 | return IRQ_HANDLED; |
| 1962 | } |
| 1963 | |
| 1964 | evstat = hermes_read_regn(hw, EVSTAT); |
| 1965 | events = evstat & hw->inten; |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 1966 | if (!events) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | orinoco_unlock(priv, &flags); |
| 1968 | return IRQ_NONE; |
| 1969 | } |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 1970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | if (jiffies != last_irq_jiffy) |
| 1972 | loops_this_jiffy = 0; |
| 1973 | last_irq_jiffy = jiffies; |
| 1974 | |
| 1975 | while (events && count--) { |
| 1976 | if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) { |
| 1977 | printk(KERN_WARNING "%s: IRQ handler is looping too " |
| 1978 | "much! Resetting.\n", dev->name); |
| 1979 | /* Disable interrupts for now */ |
| 1980 | hermes_set_irqmask(hw, 0); |
| 1981 | schedule_work(&priv->reset_work); |
| 1982 | break; |
| 1983 | } |
| 1984 | |
| 1985 | /* Check the card hasn't been removed */ |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 1986 | if (!hermes_present(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | DEBUG(0, "orinoco_interrupt(): card removed\n"); |
| 1988 | break; |
| 1989 | } |
| 1990 | |
| 1991 | if (events & HERMES_EV_TICK) |
| 1992 | __orinoco_ev_tick(dev, hw); |
| 1993 | if (events & HERMES_EV_WTERR) |
| 1994 | __orinoco_ev_wterr(dev, hw); |
| 1995 | if (events & HERMES_EV_INFDROP) |
| 1996 | __orinoco_ev_infdrop(dev, hw); |
| 1997 | if (events & HERMES_EV_INFO) |
| 1998 | __orinoco_ev_info(dev, hw); |
| 1999 | if (events & HERMES_EV_RX) |
| 2000 | __orinoco_ev_rx(dev, hw); |
| 2001 | if (events & HERMES_EV_TXEXC) |
| 2002 | __orinoco_ev_txexc(dev, hw); |
| 2003 | if (events & HERMES_EV_TX) |
| 2004 | __orinoco_ev_tx(dev, hw); |
| 2005 | if (events & HERMES_EV_ALLOC) |
| 2006 | __orinoco_ev_alloc(dev, hw); |
David Kilroy | 6fe9deb | 2009-02-04 23:05:43 +0000 | [diff] [blame] | 2007 | |
Christoph Hellwig | 84d8a2f | 2005-05-14 17:30:22 +0200 | [diff] [blame] | 2008 | hermes_write_regn(hw, EVACK, evstat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | |
| 2010 | evstat = hermes_read_regn(hw, EVSTAT); |
| 2011 | events = evstat & hw->inten; |
| 2012 | }; |
| 2013 | |
| 2014 | orinoco_unlock(priv, &flags); |
| 2015 | return IRQ_HANDLED; |
| 2016 | } |
David Kilroy | 2131266 | 2009-02-04 23:05:47 +0000 | [diff] [blame] | 2017 | EXPORT_SYMBOL(orinoco_interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | |
| 2019 | /********************************************************************/ |
David Kilroy | 39d1ffe | 2008-11-22 10:37:28 +0000 | [diff] [blame] | 2020 | /* Power management */ |
| 2021 | /********************************************************************/ |
| 2022 | #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT) |
| 2023 | static int orinoco_pm_notifier(struct notifier_block *notifier, |
| 2024 | unsigned long pm_event, |
| 2025 | void *unused) |
| 2026 | { |
| 2027 | struct orinoco_private *priv = container_of(notifier, |
| 2028 | struct orinoco_private, |
| 2029 | pm_notifier); |
| 2030 | |
| 2031 | /* All we need to do is cache the firmware before suspend, and |
| 2032 | * release it when we come out. |
| 2033 | * |
| 2034 | * Only need to do this if we're downloading firmware. */ |
| 2035 | if (!priv->do_fw_download) |
| 2036 | return NOTIFY_DONE; |
| 2037 | |
| 2038 | switch (pm_event) { |
| 2039 | case PM_HIBERNATION_PREPARE: |
| 2040 | case PM_SUSPEND_PREPARE: |
| 2041 | orinoco_cache_fw(priv, 0); |
| 2042 | break; |
| 2043 | |
| 2044 | case PM_POST_RESTORE: |
| 2045 | /* Restore from hibernation failed. We need to clean |
| 2046 | * up in exactly the same way, so fall through. */ |
| 2047 | case PM_POST_HIBERNATION: |
| 2048 | case PM_POST_SUSPEND: |
| 2049 | orinoco_uncache_fw(priv); |
| 2050 | break; |
| 2051 | |
| 2052 | case PM_RESTORE_PREPARE: |
| 2053 | default: |
| 2054 | break; |
| 2055 | } |
| 2056 | |
| 2057 | return NOTIFY_DONE; |
| 2058 | } |
David S. Miller | f11c179 | 2009-02-25 00:02:05 -0800 | [diff] [blame] | 2059 | |
| 2060 | static void orinoco_register_pm_notifier(struct orinoco_private *priv) |
| 2061 | { |
| 2062 | priv->pm_notifier.notifier_call = orinoco_pm_notifier; |
| 2063 | register_pm_notifier(&priv->pm_notifier); |
| 2064 | } |
| 2065 | |
| 2066 | static void orinoco_unregister_pm_notifier(struct orinoco_private *priv) |
| 2067 | { |
| 2068 | unregister_pm_notifier(&priv->pm_notifier); |
| 2069 | } |
David Kilroy | 39d1ffe | 2008-11-22 10:37:28 +0000 | [diff] [blame] | 2070 | #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */ |
David S. Miller | f11c179 | 2009-02-25 00:02:05 -0800 | [diff] [blame] | 2071 | #define orinoco_register_pm_notifier(priv) do { } while(0) |
| 2072 | #define orinoco_unregister_pm_notifier(priv) do { } while(0) |
David Kilroy | 39d1ffe | 2008-11-22 10:37:28 +0000 | [diff] [blame] | 2073 | #endif |
| 2074 | |
| 2075 | /********************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | /* Initialization */ |
| 2077 | /********************************************************************/ |
| 2078 | |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2079 | int orinoco_init(struct orinoco_private *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | { |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2081 | struct device *dev = priv->dev; |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2082 | struct wiphy *wiphy = priv_to_wiphy(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | hermes_t *hw = &priv->hw; |
| 2084 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | /* No need to lock, the hw_unavailable flag is already set in |
| 2087 | * alloc_orinocodev() */ |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 2088 | priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | |
| 2090 | /* Initialize the firmware */ |
Pavel Roskin | 37a6c61 | 2006-04-07 04:10:49 -0400 | [diff] [blame] | 2091 | err = hermes_init(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | if (err != 0) { |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2093 | dev_err(dev, "Failed to initialize firmware (err = %d)\n", |
| 2094 | err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | goto out; |
| 2096 | } |
| 2097 | |
David Kilroy | a2d1a42 | 2009-06-18 23:21:18 +0100 | [diff] [blame] | 2098 | err = determine_fw_capabilities(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | if (err != 0) { |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2100 | dev_err(dev, "Incompatible firmware, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | goto out; |
| 2102 | } |
| 2103 | |
David Kilroy | 3994d50 | 2008-08-21 23:27:54 +0100 | [diff] [blame] | 2104 | if (priv->do_fw_download) { |
David Kilroy | 39d1ffe | 2008-11-22 10:37:28 +0000 | [diff] [blame] | 2105 | #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT |
David Kilroy | 7473431 | 2008-11-22 10:37:25 +0000 | [diff] [blame] | 2106 | orinoco_cache_fw(priv, 0); |
David Kilroy | 39d1ffe | 2008-11-22 10:37:28 +0000 | [diff] [blame] | 2107 | #endif |
David Kilroy | 7473431 | 2008-11-22 10:37:25 +0000 | [diff] [blame] | 2108 | |
David Kilroy | 3994d50 | 2008-08-21 23:27:54 +0100 | [diff] [blame] | 2109 | err = orinoco_download(priv); |
| 2110 | if (err) |
| 2111 | priv->do_fw_download = 0; |
| 2112 | |
| 2113 | /* Check firmware version again */ |
David Kilroy | a2d1a42 | 2009-06-18 23:21:18 +0100 | [diff] [blame] | 2114 | err = determine_fw_capabilities(priv); |
David Kilroy | 3994d50 | 2008-08-21 23:27:54 +0100 | [diff] [blame] | 2115 | if (err != 0) { |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2116 | dev_err(dev, "Incompatible firmware, aborting\n"); |
David Kilroy | 3994d50 | 2008-08-21 23:27:54 +0100 | [diff] [blame] | 2117 | goto out; |
| 2118 | } |
| 2119 | } |
| 2120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | if (priv->has_port3) |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2122 | dev_info(dev, "Ad-hoc demo mode supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | if (priv->has_ibss) |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2124 | dev_info(dev, "IEEE standard IBSS ad-hoc mode supported\n"); |
| 2125 | if (priv->has_wep) |
| 2126 | dev_info(dev, "WEP supported, %s-bit key\n", |
| 2127 | priv->has_big_wep ? "104" : "40"); |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 2128 | if (priv->has_wpa) { |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2129 | dev_info(dev, "WPA-PSK supported\n"); |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 2130 | if (orinoco_mic_init(priv)) { |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2131 | dev_err(dev, "Failed to setup MIC crypto algorithm. " |
| 2132 | "Disabling WPA support\n"); |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 2133 | priv->has_wpa = 0; |
| 2134 | } |
| 2135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | |
David Kilroy | 01632fa | 2008-08-21 23:27:58 +0100 | [diff] [blame] | 2137 | /* Now we have the firmware capabilities, allocate appropiate |
| 2138 | * sized scan buffers */ |
| 2139 | if (orinoco_bss_data_allocate(priv)) |
| 2140 | goto out; |
| 2141 | orinoco_bss_data_init(priv); |
| 2142 | |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2143 | err = orinoco_hw_read_card_settings(priv, wiphy->perm_addr); |
David Kilroy | e9e3d01 | 2009-06-18 23:21:19 +0100 | [diff] [blame] | 2144 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | |
David Kilroy | 42a51b9 | 2009-06-18 23:21:20 +0100 | [diff] [blame] | 2147 | err = orinoco_hw_allocate_fid(priv); |
Pavel Roskin | 37a6c61 | 2006-04-07 04:10:49 -0400 | [diff] [blame] | 2148 | if (err) { |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2149 | dev_err(dev, "Failed to allocate NIC buffer!\n"); |
Pavel Roskin | 37a6c61 | 2006-04-07 04:10:49 -0400 | [diff] [blame] | 2150 | goto out; |
| 2151 | } |
| 2152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | /* Set up the default configuration */ |
| 2154 | priv->iw_mode = IW_MODE_INFRA; |
| 2155 | /* By default use IEEE/IBSS ad-hoc mode if we have it */ |
David Kilroy | a94e842 | 2009-02-04 23:05:44 +0000 | [diff] [blame] | 2156 | priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | set_port_type(priv); |
David Gibson | d51d8b1 | 2005-05-12 20:03:36 -0400 | [diff] [blame] | 2158 | priv->channel = 0; /* use firmware default */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | |
| 2160 | priv->promiscuous = 0; |
David Kilroy | 4ae6ee2 | 2008-08-21 23:27:59 +0100 | [diff] [blame] | 2161 | priv->encode_alg = IW_ENCODE_ALG_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | priv->tx_key = 0; |
David Kilroy | d03032a | 2008-08-21 23:28:02 +0100 | [diff] [blame] | 2163 | priv->wpa_enabled = 0; |
| 2164 | priv->tkip_cm_active = 0; |
| 2165 | priv->key_mgmt = 0; |
| 2166 | priv->wpa_ie_len = 0; |
| 2167 | priv->wpa_ie = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2169 | if (orinoco_wiphy_register(wiphy)) { |
| 2170 | err = -ENODEV; |
| 2171 | goto out; |
| 2172 | } |
| 2173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | /* Make the hardware available, as long as it hasn't been |
| 2175 | * removed elsewhere (e.g. by PCMCIA hot unplug) */ |
| 2176 | spin_lock_irq(&priv->lock); |
| 2177 | priv->hw_unavailable--; |
| 2178 | spin_unlock_irq(&priv->lock); |
| 2179 | |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2180 | dev_dbg(dev, "Ready\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | |
| 2182 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | return err; |
| 2184 | } |
David Kilroy | 8e63826 | 2009-06-18 23:21:24 +0100 | [diff] [blame] | 2185 | EXPORT_SYMBOL(orinoco_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | |
Andrey Borzenkov | 89ea409 | 2009-01-21 20:46:46 +0300 | [diff] [blame] | 2187 | static const struct net_device_ops orinoco_netdev_ops = { |
Andrey Borzenkov | 89ea409 | 2009-01-21 20:46:46 +0300 | [diff] [blame] | 2188 | .ndo_open = orinoco_open, |
| 2189 | .ndo_stop = orinoco_stop, |
| 2190 | .ndo_start_xmit = orinoco_xmit, |
| 2191 | .ndo_set_multicast_list = orinoco_set_multicast_list, |
| 2192 | .ndo_change_mtu = orinoco_change_mtu, |
| 2193 | .ndo_tx_timeout = orinoco_tx_timeout, |
| 2194 | .ndo_get_stats = orinoco_get_stats, |
| 2195 | }; |
| 2196 | |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2197 | /* Allocate private data. |
| 2198 | * |
| 2199 | * This driver has a number of structures associated with it |
| 2200 | * netdev - Net device structure for each network interface |
| 2201 | * wiphy - structure associated with wireless phy |
| 2202 | * wireless_dev (wdev) - structure for each wireless interface |
| 2203 | * hw - structure for hermes chip info |
| 2204 | * card - card specific structure for use by the card driver |
| 2205 | * (airport, orinoco_cs) |
| 2206 | * priv - orinoco private data |
| 2207 | * device - generic linux device structure |
| 2208 | * |
| 2209 | * +---------+ +---------+ |
| 2210 | * | wiphy | | netdev | |
| 2211 | * | +-------+ | +-------+ |
| 2212 | * | | priv | | | wdev | |
| 2213 | * | | +-----+ +-+-------+ |
| 2214 | * | | | hw | |
| 2215 | * | +-+-----+ |
| 2216 | * | | card | |
| 2217 | * +-+-------+ |
| 2218 | * |
| 2219 | * priv has a link to netdev and device |
| 2220 | * wdev has a link to wiphy |
| 2221 | */ |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 2222 | struct orinoco_private |
David Kilroy | 3994d50 | 2008-08-21 23:27:54 +0100 | [diff] [blame] | 2223 | *alloc_orinocodev(int sizeof_card, |
| 2224 | struct device *device, |
| 2225 | int (*hard_reset)(struct orinoco_private *), |
| 2226 | int (*stop_fw)(struct orinoco_private *, int)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | struct orinoco_private *priv; |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2229 | struct wiphy *wiphy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2231 | /* allocate wiphy |
| 2232 | * NOTE: We only support a single virtual interface |
| 2233 | * but this may change when monitor mode is added |
| 2234 | */ |
| 2235 | wiphy = wiphy_new(&orinoco_cfg_ops, |
| 2236 | sizeof(struct orinoco_private) + sizeof_card); |
| 2237 | if (!wiphy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | return NULL; |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2239 | |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2240 | priv = wiphy_priv(wiphy); |
David Kilroy | 5381956 | 2009-06-18 23:21:28 +0100 | [diff] [blame^] | 2241 | priv->dev = device; |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | if (sizeof_card) |
Christoph Hellwig | 84d8a2f | 2005-05-14 17:30:22 +0200 | [diff] [blame] | 2244 | priv->card = (void *)((unsigned long)priv |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | + sizeof(struct orinoco_private)); |
| 2246 | else |
| 2247 | priv->card = NULL; |
| 2248 | |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2249 | orinoco_wiphy_init(wiphy); |
| 2250 | |
Pavel Roskin | 343c686 | 2005-09-09 18:43:02 -0400 | [diff] [blame] | 2251 | #ifdef WIRELESS_SPY |
| 2252 | priv->wireless_data.spy_data = &priv->spy_data; |
Pavel Roskin | 343c686 | 2005-09-09 18:43:02 -0400 | [diff] [blame] | 2253 | #endif |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 2254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | /* Set up default callbacks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | priv->hard_reset = hard_reset; |
David Kilroy | 3994d50 | 2008-08-21 23:27:54 +0100 | [diff] [blame] | 2257 | priv->stop_fw = stop_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | |
| 2259 | spin_lock_init(&priv->lock); |
| 2260 | priv->open = 0; |
| 2261 | priv->hw_unavailable = 1; /* orinoco_init() must clear this |
| 2262 | * before anything else touches the |
| 2263 | * hardware */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2264 | INIT_WORK(&priv->reset_work, orinoco_reset); |
| 2265 | INIT_WORK(&priv->join_work, orinoco_join_ap); |
| 2266 | INIT_WORK(&priv->wevent_work, orinoco_send_wevents); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 2268 | INIT_LIST_HEAD(&priv->rx_list); |
| 2269 | tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet, |
David Kilroy | 5381956 | 2009-06-18 23:21:28 +0100 | [diff] [blame^] | 2270 | (unsigned long) priv); |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 2271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | priv->last_linkstatus = 0xffff; |
| 2273 | |
Andrey Borzenkov | 2bfc5cb | 2009-02-28 23:09:09 +0300 | [diff] [blame] | 2274 | #if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP) |
David Kilroy | 2cea7b2 | 2008-11-22 10:37:26 +0000 | [diff] [blame] | 2275 | priv->cached_pri_fw = NULL; |
Andrey Borzenkov | 4fb3078 | 2008-10-19 12:06:11 +0400 | [diff] [blame] | 2276 | priv->cached_fw = NULL; |
Andrey Borzenkov | 2bfc5cb | 2009-02-28 23:09:09 +0300 | [diff] [blame] | 2277 | #endif |
Andrey Borzenkov | 4fb3078 | 2008-10-19 12:06:11 +0400 | [diff] [blame] | 2278 | |
David Kilroy | 39d1ffe | 2008-11-22 10:37:28 +0000 | [diff] [blame] | 2279 | /* Register PM notifiers */ |
David S. Miller | f11c179 | 2009-02-25 00:02:05 -0800 | [diff] [blame] | 2280 | orinoco_register_pm_notifier(priv); |
David Kilroy | 39d1ffe | 2008-11-22 10:37:28 +0000 | [diff] [blame] | 2281 | |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 2282 | return priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | } |
David Kilroy | 2131266 | 2009-02-04 23:05:47 +0000 | [diff] [blame] | 2284 | EXPORT_SYMBOL(alloc_orinocodev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | |
David Kilroy | 5381956 | 2009-06-18 23:21:28 +0100 | [diff] [blame^] | 2286 | /* We can only support a single interface. We provide a separate |
| 2287 | * function to set it up to distinguish between hardware |
| 2288 | * initialisation and interface setup. |
| 2289 | * |
| 2290 | * The base_addr and irq parameters are passed on to netdev for use |
| 2291 | * with SIOCGIFMAP. |
| 2292 | */ |
| 2293 | int orinoco_if_add(struct orinoco_private *priv, |
| 2294 | unsigned long base_addr, |
| 2295 | unsigned int irq) |
| 2296 | { |
| 2297 | struct wiphy *wiphy = priv_to_wiphy(priv); |
| 2298 | struct wireless_dev *wdev; |
| 2299 | struct net_device *dev; |
| 2300 | int ret; |
| 2301 | |
| 2302 | dev = alloc_etherdev(sizeof(struct wireless_dev)); |
| 2303 | |
| 2304 | if (!dev) |
| 2305 | return -ENOMEM; |
| 2306 | |
| 2307 | /* Initialise wireless_dev */ |
| 2308 | wdev = netdev_priv(dev); |
| 2309 | wdev->wiphy = wiphy; |
| 2310 | wdev->iftype = NL80211_IFTYPE_STATION; |
| 2311 | |
| 2312 | /* Setup / override net_device fields */ |
| 2313 | dev->ieee80211_ptr = wdev; |
| 2314 | dev->netdev_ops = &orinoco_netdev_ops; |
| 2315 | dev->watchdog_timeo = HZ; /* 1 second timeout */ |
| 2316 | dev->ethtool_ops = &orinoco_ethtool_ops; |
| 2317 | dev->wireless_handlers = &orinoco_handler_def; |
| 2318 | #ifdef WIRELESS_SPY |
| 2319 | dev->wireless_data = &priv->wireless_data; |
| 2320 | #endif |
| 2321 | /* we use the default eth_mac_addr for setting the MAC addr */ |
| 2322 | |
| 2323 | /* Reserve space in skb for the SNAP header */ |
| 2324 | dev->hard_header_len += ENCAPS_OVERHEAD; |
| 2325 | |
| 2326 | netif_carrier_off(dev); |
| 2327 | |
| 2328 | memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN); |
| 2329 | |
| 2330 | dev->base_addr = base_addr; |
| 2331 | dev->irq = irq; |
| 2332 | |
| 2333 | SET_NETDEV_DEV(dev, priv->dev); |
| 2334 | ret = register_netdev(dev); |
| 2335 | if (ret) |
| 2336 | goto fail; |
| 2337 | |
| 2338 | priv->ndev = dev; |
| 2339 | |
| 2340 | /* Report what we've done */ |
| 2341 | dev_dbg(priv->dev, "Registerred interface %s.\n", dev->name); |
| 2342 | |
| 2343 | return 0; |
| 2344 | |
| 2345 | fail: |
| 2346 | free_netdev(dev); |
| 2347 | return ret; |
| 2348 | } |
| 2349 | EXPORT_SYMBOL(orinoco_if_add); |
| 2350 | |
| 2351 | void orinoco_if_del(struct orinoco_private *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | { |
David Kilroy | a260836 | 2009-06-18 23:21:23 +0100 | [diff] [blame] | 2353 | struct net_device *dev = priv->ndev; |
David Kilroy | 5381956 | 2009-06-18 23:21:28 +0100 | [diff] [blame^] | 2354 | |
| 2355 | unregister_netdev(dev); |
| 2356 | free_netdev(dev); |
| 2357 | } |
| 2358 | EXPORT_SYMBOL(orinoco_if_del); |
| 2359 | |
| 2360 | void free_orinocodev(struct orinoco_private *priv) |
| 2361 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2362 | struct wiphy *wiphy = priv_to_wiphy(priv); |
David Kilroy | 20953ad | 2009-01-07 00:23:55 +0000 | [diff] [blame] | 2363 | struct orinoco_rx_data *rx_data, *temp; |
Christoph Hellwig | 95dd91f | 2005-06-19 01:27:56 +0200 | [diff] [blame] | 2364 | |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2365 | wiphy_unregister(wiphy); |
| 2366 | |
David Kilroy | 20953ad | 2009-01-07 00:23:55 +0000 | [diff] [blame] | 2367 | /* If the tasklet is scheduled when we call tasklet_kill it |
| 2368 | * will run one final time. However the tasklet will only |
| 2369 | * drain priv->rx_list if the hw is still available. */ |
David Kilroy | 31afcef | 2008-08-21 23:28:04 +0100 | [diff] [blame] | 2370 | tasklet_kill(&priv->rx_tasklet); |
David Kilroy | 7473431 | 2008-11-22 10:37:25 +0000 | [diff] [blame] | 2371 | |
David Kilroy | 20953ad | 2009-01-07 00:23:55 +0000 | [diff] [blame] | 2372 | /* Explicitly drain priv->rx_list */ |
| 2373 | list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) { |
| 2374 | list_del(&rx_data->list); |
| 2375 | |
| 2376 | dev_kfree_skb(rx_data->skb); |
| 2377 | kfree(rx_data->desc); |
| 2378 | kfree(rx_data); |
| 2379 | } |
| 2380 | |
David S. Miller | f11c179 | 2009-02-25 00:02:05 -0800 | [diff] [blame] | 2381 | orinoco_unregister_pm_notifier(priv); |
David Kilroy | 7473431 | 2008-11-22 10:37:25 +0000 | [diff] [blame] | 2382 | orinoco_uncache_fw(priv); |
| 2383 | |
David Kilroy | d03032a | 2008-08-21 23:28:02 +0100 | [diff] [blame] | 2384 | priv->wpa_ie_len = 0; |
| 2385 | kfree(priv->wpa_ie); |
David Kilroy | 23edcc4 | 2008-08-21 23:28:05 +0100 | [diff] [blame] | 2386 | orinoco_mic_free(priv); |
Dan Williams | 1e3428e | 2007-10-10 23:56:25 -0400 | [diff] [blame] | 2387 | orinoco_bss_data_free(priv); |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2388 | wiphy_free(wiphy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | } |
David Kilroy | 2131266 | 2009-02-04 23:05:47 +0000 | [diff] [blame] | 2390 | EXPORT_SYMBOL(free_orinocodev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | |
Christoph Hellwig | 1fab2e8 | 2005-06-19 01:27:40 +0200 | [diff] [blame] | 2392 | static void orinoco_get_drvinfo(struct net_device *dev, |
| 2393 | struct ethtool_drvinfo *info) |
| 2394 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 2395 | struct orinoco_private *priv = ndev_priv(dev); |
Christoph Hellwig | 1fab2e8 | 2005-06-19 01:27:40 +0200 | [diff] [blame] | 2396 | |
| 2397 | strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1); |
| 2398 | strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1); |
| 2399 | strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1); |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 2400 | if (dev->dev.parent) |
Kay Sievers | fb28ad35 | 2008-11-10 13:55:14 -0800 | [diff] [blame] | 2401 | strncpy(info->bus_info, dev_name(dev->dev.parent), |
Christoph Hellwig | 1fab2e8 | 2005-06-19 01:27:40 +0200 | [diff] [blame] | 2402 | sizeof(info->bus_info) - 1); |
| 2403 | else |
| 2404 | snprintf(info->bus_info, sizeof(info->bus_info) - 1, |
| 2405 | "PCMCIA %p", priv->hw.iobase); |
| 2406 | } |
| 2407 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2408 | static const struct ethtool_ops orinoco_ethtool_ops = { |
Christoph Hellwig | 1fab2e8 | 2005-06-19 01:27:40 +0200 | [diff] [blame] | 2409 | .get_drvinfo = orinoco_get_drvinfo, |
| 2410 | .get_link = ethtool_op_get_link, |
| 2411 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | |
| 2413 | /********************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | /* Module initialization */ |
| 2415 | /********************************************************************/ |
| 2416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | /* Can't be declared "const" or the whole __initdata section will |
| 2418 | * become const */ |
| 2419 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION |
| 2420 | " (David Gibson <hermes@gibson.dropbear.id.au>, " |
| 2421 | "Pavel Roskin <proski@gnu.org>, et al)"; |
| 2422 | |
| 2423 | static int __init init_orinoco(void) |
| 2424 | { |
| 2425 | printk(KERN_DEBUG "%s\n", version); |
| 2426 | return 0; |
| 2427 | } |
| 2428 | |
| 2429 | static void __exit exit_orinoco(void) |
| 2430 | { |
| 2431 | } |
| 2432 | |
| 2433 | module_init(init_orinoco); |
| 2434 | module_exit(exit_orinoco); |