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