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