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