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