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