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