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