147445cb95015bef0d54ca799f31e454797378a71David Kilroy/* main.c - (formerly known as dldwd_cs.c, orinoco_cs.c and orinoco.c) 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * A driver for Hermes or Prism 2 chipset based PCMCIA wireless 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * adaptors, with Lucent/Agere, Intersil or Symbol firmware. 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Current maintainers (as of 29 September 2003) are: 7933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin * Pavel Roskin <proski AT gnu.org> 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and David Gibson <hermes AT gibson.dropbear.id.au> 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (C) Copyright David Gibson, IBM Corporation 2001-2003. 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2000 David Gibson, Linuxcare Australia. 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * With some help from : 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2001 Jean Tourrilhes, HP Labs 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2001 Benjamin Herrenschmidt 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Based on dummy_cs.c 1.27 2000/06/12 21:27:25 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * AT fasta.fh-dortmund.de> 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * http://www.stud.fh-dortmund.de/~andy/wvlan/ 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The contents of this file are subject to the Mozilla Public License 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Version 1.1 (the "License"); you may not use this file except in 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * compliance with the License. You may obtain a copy of the License 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * at http://www.mozilla.org/MPL/ 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Software distributed under the License is distributed on an "AS IS" 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the License for the specific language governing rights and 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * limitations under the License. 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The initial developer of the original code is David A. Hinds 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * <dahinds AT users.sourceforge.net>. Portions created by David 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Reserved. 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Alternatively, the contents of this file may be used under the 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * terms of the GNU General Public License version 2 (the "GPL"), in 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * which case the provisions of the GPL are applicable instead of the 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * above. If you wish to allow the use of your version of this file 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * only under the terms of the GPL and not to allow others to use your 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * version of this file under the MPL, indicate your decision by 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * deleting the provisions above and replace them with the notice and 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * other provisions required by the GPL. If you do not delete the 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * provisions above, a recipient may use your version of this file 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * under either the MPL or the GPL. */ 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * TODO 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Handle de-encapsulation within network layer, provide 802.11 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * headers (patch from Thomas 'Dent' Mirlacher) 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Fix possible races in SPY handling. 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o Disconnect wireless extensions from fundamental configuration. 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o (maybe) Software WEP support (patch from Stano Meduna). 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * o (maybe) Use multiple Tx buffers - driver handling queue 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * rather than firmware. 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Locking and synchronization: 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The basic principle is that everything is serialized through a 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * single spinlock, priv->lock. The lock is used in user, bh and irq 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * context, so when taken outside hardirq context it should always be 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * taken with interrupts disabled. The lock protects both the 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * hardware and the struct orinoco_private. 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Another flag, priv->hw_unavailable indicates that the hardware is 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * unavailable for an extended period of time (e.g. suspended, or in 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the middle of a hard reset). This flag is protected by the 701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * spinlock. All code which touches the hardware should check the 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * flag after taking the lock, and if it is set, give up on whatever 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * they are doing and drop the lock again. The orinoco_lock() 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * function handles this (it unlocks and returns -EBUSY if 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * hw_unavailable is non-zero). 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DRIVER_NAME "orinoco" 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h> 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/kernel.h> 815a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/slab.h> 821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h> 83d03032af511c56d3c1580fa4f54f6285f650e638David Kilroy#include <linux/delay.h> 848e638267a896e171e49fb9013f5baf96a4ede754David Kilroy#include <linux/device.h> 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/netdevice.h> 861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/etherdevice.h> 8739d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy#include <linux/suspend.h> 889c974fb1a44dc8d09c16caa4dd174b0403ba585cPavel Roskin#include <linux/if_arp.h> 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/wireless.h> 902c706002fc147decdba2658ea48e4436faca3af2Johannes Berg#include <linux/ieee80211.h> 91620554e406e3cc01434c658a1e597162d7e56fd6Christoph Hellwig#include <net/iw_handler.h> 92ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy#include <net/cfg80211.h> 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "hermes_rid.h" 953994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy#include "hermes_dld.h" 96712a4342a0d89e855a03ba06fb11f7eb29456d45David Kilroy#include "hw.h" 97fb791b1cfb74937332a22d6bf06eed7866fbcc3cDavid Kilroy#include "scan.h" 984adb474b6b7e26e1318acab5e98864aa78f9b233David Kilroy#include "mic.h" 9937a2e566f82de9a88fe119479162f9984af2180dDavid Kilroy#include "fw.h" 100cb1576a829826d56fab59e22aa3af8c5a7db9936David Kilroy#include "wext.h" 101ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy#include "cfg.h" 102cb1576a829826d56fab59e22aa3af8c5a7db9936David Kilroy#include "main.h" 103fb791b1cfb74937332a22d6bf06eed7866fbcc3cDavid Kilroy 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "orinoco.h" 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Module information */ 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 110b2f30a0a2395b6c7e7138fbdabec2cb02ff373a7David KilroyMODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & " 111b2f30a0a2395b6c7e7138fbdabec2cb02ff373a7David Kilroy "David Gibson <hermes@gibson.dropbear.id.au>"); 112b2f30a0a2395b6c7e7138fbdabec2cb02ff373a7David KilroyMODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based " 113b2f30a0a2395b6c7e7138fbdabec2cb02ff373a7David Kilroy "and similar wireless cards"); 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("Dual MPL/GPL"); 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Level of debugging. Used in the macros in orinoco.h */ 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef ORINOCO_DEBUG 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint orinoco_debug = ORINOCO_DEBUG; 1192131266d6e53e8f84f8111323036343d72bcb856David KilroyEXPORT_SYMBOL(orinoco_debug); 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_param(orinoco_debug, int, 0644); 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_PARM_DESC(orinoco_debug, "Debug level"); 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 124eb93992207dadb946a3b5cf4544957dc924a6f58Rusty Russellstatic bool suppress_linkstatus; /* = 0 */ 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_param(suppress_linkstatus, bool, 0644); 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes"); 127b2f30a0a2395b6c7e7138fbdabec2cb02ff373a7David Kilroy 1287bb7c3a326f509acbdaf550b54fba565544ef200David Gibsonstatic int ignore_disconnect; /* = 0 */ 1297bb7c3a326f509acbdaf550b54fba565544ef200David Gibsonmodule_param(ignore_disconnect, int, 0644); 130b2f30a0a2395b6c7e7138fbdabec2cb02ff373a7David KilroyMODULE_PARM_DESC(ignore_disconnect, 131b2f30a0a2395b6c7e7138fbdabec2cb02ff373a7David Kilroy "Don't report lost link to the network layer"); 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 133cb1576a829826d56fab59e22aa3af8c5a7db9936David Kilroyint force_monitor; /* = 0 */ 13498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwigmodule_param(force_monitor, int, 0644); 13598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph HellwigMODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions"); 13698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Internal constants */ 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */ 14295dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwigstatic const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00}; 14395dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2) 14495dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ORINOCO_MIN_MTU 256 1462c706002fc147decdba2658ea48e4436faca3af2Johannes Berg#define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD) 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define MAX_IRQLOOPS_PER_IRQ 10 149933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin#define MAX_IRQLOOPS_PER_JIFFY (20000 / HZ) /* Based on a guestimate of 150933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin * how many events the 151933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin * device could 152933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin * legitimately generate */ 1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DUMMY_FID 0xFFFF 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \ 1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds HERMES_MAX_MULTICAST : 0)*/ 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST) 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 160933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \ 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds | HERMES_EV_TX | HERMES_EV_TXEXC \ 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds | HERMES_EV_WTERR | HERMES_EV_INFO \ 163a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy | HERMES_EV_INFDROP) 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Data types */ 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16930c2d3b48176279b1381b00ae86f3d01147d0915Pavel Roskin/* Beginning of the Tx descriptor, used in TxExc handling */ 17030c2d3b48176279b1381b00ae86f3d01147d0915Pavel Roskinstruct hermes_txexc_data { 17130c2d3b48176279b1381b00ae86f3d01147d0915Pavel Roskin struct hermes_tx_descriptor desc; 172d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le16 frame_ctl; 173d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le16 duration_id; 17495dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig u8 addr1[ETH_ALEN]; 175ba2d3587912f82d1ab4367975b1df460db60fb1eEric Dumazet} __packed; 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1778f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig/* Rx frame header except compatibility 802.3 header */ 1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct hermes_rx_descriptor { 1798f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig /* Control */ 180d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le16 status; 181d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le32 time; 1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 silence; 1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 signal; 1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 rate; 1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 rxflow; 186d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le32 reserved; 1878f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig 1888f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig /* 802.11 header */ 189d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le16 frame_ctl; 190d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le16 duration_id; 1918f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig u8 addr1[ETH_ALEN]; 1928f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig u8 addr2[ETH_ALEN]; 1938f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig u8 addr3[ETH_ALEN]; 194d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le16 seq_ctl; 1958f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig u8 addr4[ETH_ALEN]; 1968f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig 1978f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig /* Data length */ 198d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le16 data_len; 199ba2d3587912f82d1ab4367975b1df460db60fb1eEric Dumazet} __packed; 2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20147166791b7296db5c0a7189401e42b8c7f4cca25David Kilroystruct orinoco_rx_data { 20247166791b7296db5c0a7189401e42b8c7f4cca25David Kilroy struct hermes_rx_descriptor *desc; 20347166791b7296db5c0a7189401e42b8c7f4cca25David Kilroy struct sk_buff *skb; 20447166791b7296db5c0a7189401e42b8c7f4cca25David Kilroy struct list_head list; 20547166791b7296db5c0a7189401e42b8c7f4cca25David Kilroy}; 20647166791b7296db5c0a7189401e42b8c7f4cca25David Kilroy 207c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroystruct orinoco_scan_data { 208c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy void *buf; 209c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy size_t len; 210c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy int type; 211c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy struct list_head list; 212c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy}; 213c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 2141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 2151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Function prototypes */ 2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 218721aa2f75b00399074eb443fdf16d797b4504a36David Kilroystatic int __orinoco_set_multicast_list(struct net_device *dev); 2196415f7df10573bf1ec42644f42bef565127114a1David Kilroystatic int __orinoco_up(struct orinoco_private *priv); 2206415f7df10573bf1ec42644f42bef565127114a1David Kilroystatic int __orinoco_down(struct orinoco_private *priv); 221721aa2f75b00399074eb443fdf16d797b4504a36David Kilroystatic int __orinoco_commit(struct orinoco_private *priv); 2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Internal helper functions */ 2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 227cb1576a829826d56fab59e22aa3af8c5a7db9936David Kilroyvoid set_port_type(struct orinoco_private *priv) 2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (priv->iw_mode) { 2305217c571c898371c540e49671600d54346b2e123David Kilroy case NL80211_IFTYPE_STATION: 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->port_type = 1; 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->createibss = 0; 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 2345217c571c898371c540e49671600d54346b2e123David Kilroy case NL80211_IFTYPE_ADHOC: 2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (priv->prefer_port3) { 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->port_type = 3; 2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->createibss = 0; 2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->port_type = priv->ibss_port; 2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->createibss = 1; 2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 2435217c571c898371c540e49671600d54346b2e123David Kilroy case NL80211_IFTYPE_MONITOR: 24498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig priv->port_type = 3; 24598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig priv->createibss = 0; 24698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig break; 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds default: 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n", 2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->ndev->name); 2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2533994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy/********************************************************************/ 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Device methods */ 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 257593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroyint orinoco_open(struct net_device *dev) 2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 259ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err; 2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (orinoco_lock(priv, &flags) != 0) 2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EBUSY; 2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 266a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroy err = __orinoco_up(priv); 2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 268a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if (!err) 2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->open = 1; 2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds orinoco_unlock(priv, &flags); 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 275593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David KilroyEXPORT_SYMBOL(orinoco_open); 2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 277593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroyint orinoco_stop(struct net_device *dev) 2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 279ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = 0; 2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* We mustn't use orinoco_lock() here, because we need to be 2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds able to close the interface even if hw_unavailable is set 2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (e.g. as we're released after a PC Card removal) */ 285bcad6e80f3fb0d6724c3814cf32258bbcf1d67dbDavid Kilroy orinoco_lock_irq(priv); 2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->open = 0; 2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 289a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroy err = __orinoco_down(priv); 2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 291bcad6e80f3fb0d6724c3814cf32258bbcf1d67dbDavid Kilroy orinoco_unlock_irq(priv); 2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 295593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David KilroyEXPORT_SYMBOL(orinoco_stop); 2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 297593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroystruct net_device_stats *orinoco_get_stats(struct net_device *dev) 2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 299ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 3006fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &priv->stats; 3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 303593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David KilroyEXPORT_SYMBOL(orinoco_get_stats); 3041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 305593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroyvoid orinoco_set_multicast_list(struct net_device *dev) 3061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 307ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (orinoco_lock(priv, &flags) != 0) { 3111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_DEBUG "%s: orinoco_set_multicast_list() " 3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "called when hw_unavailable\n", dev->name); 3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __orinoco_set_multicast_list(dev); 3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds orinoco_unlock(priv, &flags); 3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 319593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David KilroyEXPORT_SYMBOL(orinoco_set_multicast_list); 3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 321593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroyint orinoco_change_mtu(struct net_device *dev, int new_mtu) 3221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 323ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 3241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 325a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU)) 3261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; 3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3282c706002fc147decdba2658ea48e4436faca3af2Johannes Berg /* MTU + encapsulation + header length */ 329a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) > 330a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy (priv->nicbuf_size - ETH_HLEN)) 3311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; 3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->mtu = new_mtu; 3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 3361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 337593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David KilroyEXPORT_SYMBOL(orinoco_change_mtu); 3381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 3401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Tx path */ 3411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 343bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy/* Add encapsulation and MIC to the existing SKB. 344bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * The main xmit routine will then send the whole lot to the card. 345bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * Need 8 bytes headroom 346bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * Need 8 bytes tailroom 347bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * 348bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * With encapsulated ethernet II frame 349bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * -------- 350bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * 803.3 header (14 bytes) 351bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * dst[6] 352bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * -------- src[6] 353bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * 803.3 header (14 bytes) len[2] 354bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * dst[6] 803.2 header (8 bytes) 355bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * src[6] encaps[6] 356bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * len[2] <- leave alone -> len[2] 357bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * -------- -------- <-- 0 358bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * Payload Payload 359bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * ... ... 360bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * 361bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * -------- -------- 362bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * MIC (8 bytes) 363bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * -------- 364bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * 365bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * returns 0 on success, -ENOMEM on error. 366bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy */ 367bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroyint orinoco_process_xmit_skb(struct sk_buff *skb, 368bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy struct net_device *dev, 369bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy struct orinoco_private *priv, 370bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy int *tx_control, 371bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy u8 *mic_buf) 372bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy{ 373bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy struct orinoco_tkip_key *key; 374bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy struct ethhdr *eh; 375bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy int do_mic; 376bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 377bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy key = (struct orinoco_tkip_key *) priv->keys[priv->tx_key].key; 378bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 379bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy do_mic = ((priv->encode_alg == ORINOCO_ALG_TKIP) && 380bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy (key != NULL)); 381bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 382bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy if (do_mic) 383bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy *tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) | 384bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy HERMES_TXCTRL_MIC; 385bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 386bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy eh = (struct ethhdr *)skb->data; 387bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 388bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy /* Encapsulate Ethernet-II frames */ 389bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */ 390bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy struct header_struct { 391bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy struct ethhdr eth; /* 802.3 header */ 392bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy u8 encap[6]; /* 802.2 header */ 393ba2d3587912f82d1ab4367975b1df460db60fb1eEric Dumazet } __packed hdr; 394bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy int len = skb->len + sizeof(encaps_hdr) - (2 * ETH_ALEN); 395bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 396bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy if (skb_headroom(skb) < ENCAPS_OVERHEAD) { 397bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy if (net_ratelimit()) 398bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy printk(KERN_ERR 399bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy "%s: Not enough headroom for 802.2 headers %d\n", 400bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy dev->name, skb_headroom(skb)); 401bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy return -ENOMEM; 402bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy } 403bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 404bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy /* Fill in new header */ 405bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy memcpy(&hdr.eth, eh, 2 * ETH_ALEN); 406bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy hdr.eth.h_proto = htons(len); 407bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr)); 408bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 409bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy /* Make room for the new header, and copy it in */ 410bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy eh = (struct ethhdr *) skb_push(skb, ENCAPS_OVERHEAD); 411bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy memcpy(eh, &hdr, sizeof(hdr)); 412bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy } 413bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 414bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy /* Calculate Michael MIC */ 415bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy if (do_mic) { 416bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy size_t len = skb->len - ETH_HLEN; 417bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy u8 *mic = &mic_buf[0]; 418bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 419bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy /* Have to write to an even address, so copy the spare 420bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy * byte across */ 421bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy if (skb->len % 2) { 422bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy *mic = skb->data[skb->len - 1]; 423bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy mic++; 424bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy } 425bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 426bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy orinoco_mic(priv->tx_tfm_mic, key->tx_mic, 427bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy eh->h_dest, eh->h_source, 0 /* priority */, 428bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy skb->data + ETH_HLEN, 429bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy len, mic); 430bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy } 431bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 432bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy return 0; 433bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy} 434bac6fafd4d6a0af26aeb37277a39607f7ce0be77David KilroyEXPORT_SYMBOL(orinoco_process_xmit_skb); 435bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy 436d0cf9c0dadcdc89a755bcb301cfc9c796eb28ccfStephen Hemmingerstatic netdev_tx_t orinoco_xmit(struct sk_buff *skb, struct net_device *dev) 4371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 438ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 4391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct net_device_stats *stats = &priv->stats; 440933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin struct hermes *hw = &priv->hw; 4411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = 0; 4421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u16 txfid = priv->txfid; 4436eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy int tx_control; 4441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 445933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin u8 mic_buf[MICHAEL_MIC_LEN + 1]; 4461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 447a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if (!netif_running(dev)) { 4481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: Tx on stopped device!\n", 4491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name); 450b34b867e944628418d587367276c9a82e03aba8cPavel Roskin return NETDEV_TX_BUSY; 4511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4526fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 4531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (netif_queue_stopped(dev)) { 4546fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy printk(KERN_DEBUG "%s: Tx while transmitter busy!\n", 4551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name); 456b34b867e944628418d587367276c9a82e03aba8cPavel Roskin return NETDEV_TX_BUSY; 4571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4586fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 4591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (orinoco_lock(priv, &flags) != 0) { 4601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n", 4611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name); 462b34b867e944628418d587367276c9a82e03aba8cPavel Roskin return NETDEV_TX_BUSY; 4631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4655217c571c898371c540e49671600d54346b2e123David Kilroy if (!netif_carrier_ok(dev) || 4665217c571c898371c540e49671600d54346b2e123David Kilroy (priv->iw_mode == NL80211_IFTYPE_MONITOR)) { 4671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Oops, the firmware hasn't established a connection, 4686fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy silently drop the packet (this seems to be the 4696fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy safest approach). */ 470470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin goto drop; 4711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4738d5be088263b0d3dbb7e7959b7c403b3d026a5d3Pavel Roskin /* Check packet length */ 474a28dc81dcd9ca9a451bfcab0a2351b0b07146759Pavel Roskin if (skb->len < ETH_HLEN) 475470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin goto drop; 4761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4776eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX; 4786eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy 479bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy err = orinoco_process_xmit_skb(skb, dev, priv, &tx_control, 480bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy &mic_buf[0]); 481bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy if (err) 482bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy goto drop; 48323edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 4846eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy if (priv->has_alt_txcntl) { 4856eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy /* WPA enabled firmwares have tx_cntl at the end of 4866eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy * the 802.11 header. So write zeroed descriptor and 4876eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy * 802.11 header at the same time 4886eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy */ 4896eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy char desc[HERMES_802_3_OFFSET]; 4906eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET]; 4916eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy 4926eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy memset(&desc, 0, sizeof(desc)); 4936eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy 4946eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy *txcntl = cpu_to_le16(tx_control); 495b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), 496b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy txfid, 0); 4976eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy if (err) { 4986eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy if (net_ratelimit()) 4996eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy printk(KERN_ERR "%s: Error %d writing Tx " 5006eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy "descriptor to BAP\n", dev->name, err); 5016eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy goto busy; 5026eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy } 5036eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy } else { 5046eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy struct hermes_tx_descriptor desc; 5056eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy 5066eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy memset(&desc, 0, sizeof(desc)); 5076eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy 5086eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy desc.tx_control = cpu_to_le16(tx_control); 509b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), 510b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy txfid, 0); 5116eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy if (err) { 5126eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy if (net_ratelimit()) 5136eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy printk(KERN_ERR "%s: Error %d writing Tx " 5146eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy "descriptor to BAP\n", dev->name, err); 5156eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy goto busy; 5166eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy } 5171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5186eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy /* Clear the 802.11 header and data length fields - some 5196eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused 5206eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy * if this isn't done. */ 5216eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy hermes_clear_words(hw, HERMES_DATA0, 5226eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy HERMES_802_3_OFFSET - HERMES_802_11_OFFSET); 5236eecad77861b193bcfc109de12835ca0bddf7c58David Kilroy } 5241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 525b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pwrite(hw, USER_BAP, skb->data, skb->len, 526b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy txfid, HERMES_802_3_OFFSET); 5271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) { 5281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: Error %d writing packet to BAP\n", 5291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, err); 530470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin goto busy; 5311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 533bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy if (tx_control & HERMES_TXCTRL_MIC) { 534bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy size_t offset = HERMES_802_3_OFFSET + skb->len; 535bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy size_t len = MICHAEL_MIC_LEN; 53623edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 537bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy if (offset % 2) { 538bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy offset--; 539bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy len++; 54023edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy } 541b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pwrite(hw, USER_BAP, &mic_buf[0], len, 542bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy txfid, offset); 54323edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy if (err) { 54423edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy printk(KERN_ERR "%s: Error %d writing MIC to BAP\n", 54523edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy dev->name, err); 54623edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy goto busy; 54723edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy } 54823edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy } 54923edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 5501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Finally, we actually initiate the send */ 5511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_stop_queue(dev); 5521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 553b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->cmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL, 5541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds txfid, NULL); 5551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) { 5561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_start_queue(dev); 557c367c21c93ccdaf7e1e124891633d89f9ae77f54Andrew Morton if (net_ratelimit()) 558c367c21c93ccdaf7e1e124891633d89f9ae77f54Andrew Morton printk(KERN_ERR "%s: Error %d transmitting packet\n", 559c367c21c93ccdaf7e1e124891633d89f9ae77f54Andrew Morton dev->name, err); 560470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin goto busy; 5611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 56323edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy stats->tx_bytes += HERMES_802_3_OFFSET + skb->len; 564470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin goto ok; 5651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 566470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin drop: 567470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin stats->tx_errors++; 568470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin stats->tx_dropped++; 5691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 570470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin ok: 571470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin orinoco_unlock(priv, &flags); 5721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev_kfree_skb(skb); 573b34b867e944628418d587367276c9a82e03aba8cPavel Roskin return NETDEV_TX_OK; 5741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 575470e2aa6dbdd2c7eb6562ae365a17a627f7070e8Pavel Roskin busy: 5762c1bd26035491cd0ba7e49be6ed610fc4912fef9Jiri Benc if (err == -EIO) 5772c1bd26035491cd0ba7e49be6ed610fc4912fef9Jiri Benc schedule_work(&priv->reset_work); 5781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds orinoco_unlock(priv, &flags); 579b34b867e944628418d587367276c9a82e03aba8cPavel Roskin return NETDEV_TX_BUSY; 5801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 582933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskinstatic void __orinoco_ev_alloc(struct net_device *dev, struct hermes *hw) 5831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 584ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 5851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u16 fid = hermes_read_regn(hw, ALLOCFID); 5861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fid != priv->txfid) { 5881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fid != DUMMY_FID) 5891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n", 5901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, fid); 5911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 5921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds hermes_write_regn(hw, ALLOCFID, DUMMY_FID); 5951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 597933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskinstatic void __orinoco_ev_tx(struct net_device *dev, struct hermes *hw) 5981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 599ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 6001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct net_device_stats *stats = &priv->stats; 6011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds stats->tx_packets++; 6031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_wake_queue(dev); 6051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID); 6071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 609933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskinstatic void __orinoco_ev_txexc(struct net_device *dev, struct hermes *hw) 6101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 611ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 6121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct net_device_stats *stats = &priv->stats; 6131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u16 fid = hermes_read_regn(hw, TXCOMPLFID); 614d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin u16 status; 61530c2d3b48176279b1381b00ae86f3d01147d0915Pavel Roskin struct hermes_txexc_data hdr; 6161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = 0; 6171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fid == DUMMY_FID) 6191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; /* Nothing's really happened */ 6201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 62148ca703807eba616ad5e384b40e27514bd341a3dPavel Roskin /* Read part of the frame header - we need status and addr1 */ 622b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pread(hw, IRQ_BAP, &hdr, 623b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy sizeof(struct hermes_txexc_data), 624b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy fid, 0); 62595dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 62695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID); 62795dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig stats->tx_errors++; 62895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 6291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) { 6301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_WARNING "%s: Unable to read descriptor on Tx error " 6311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "(FID=%04X error %d)\n", 6321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, fid, err); 63395dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig return; 6341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6356fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 63695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name, 63795dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig err, fid); 6386fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 63995dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* We produce a TXDROP event only for retry or lifetime 64095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * exceeded, because that's the only status that really mean 64195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * that this particular node went away. 64295dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * Other errors means that *we* screwed up. - Jean II */ 64330c2d3b48176279b1381b00ae86f3d01147d0915Pavel Roskin status = le16_to_cpu(hdr.desc.status); 644d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) { 64595dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig union iwreq_data wrqu; 64695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 64795dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* Copy 802.11 dest address. 64895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * We use the 802.11 header because the frame may 64995dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * not be 802.3 or may be mangled... 65095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * In Ad-Hoc mode, it will be the node address. 65195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * In managed mode, it will be most likely the AP addr 65295dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * User space will figure out how to convert it to 65395dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * whatever it needs (IP address or else). 65495dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * - Jean II */ 65595dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN); 65695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig wrqu.addr.sa_family = ARPHRD_ETHER; 65795dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 65895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* Send event to user space */ 65995dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL); 66095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig } 6611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_wake_queue(dev); 6631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 665593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroyvoid orinoco_tx_timeout(struct net_device *dev) 6661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 667ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 6681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct net_device_stats *stats = &priv->stats; 6691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct hermes *hw = &priv->hw; 6701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_WARNING "%s: Tx timeout! " 6721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n", 6731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, hermes_read_regn(hw, ALLOCFID), 6741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT)); 6751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds stats->tx_errors++; 6771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds schedule_work(&priv->reset_work); 6791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 680593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David KilroyEXPORT_SYMBOL(orinoco_tx_timeout); 6811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 6831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Rx path (data frames) */ 6841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 6851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Does the frame have a SNAP header indicating it should be 6871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * de-encapsulated to Ethernet-II? */ 6881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int is_ethersnap(void *_hdr) 6891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 *hdr = _hdr; 6911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* We de-encapsulate all packets which, a) have SNAP headers 6931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header 6941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and where b) the OUI of the SNAP header is 00:00:00 or 6951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 00:00:f8 - we need both because different APs appear to use 6961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * different OUIs for some reason */ 6971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (memcmp(hdr, &encaps_hdr, 5) == 0) 698a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy && ((hdr[5] == 0x00) || (hdr[5] == 0xf8)); 6991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void orinoco_spy_gather(struct net_device *dev, u_char *mac, 7021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int level, int noise) 7031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 704343c686c04eec556645f251f7d6c9b3d7335dae0Pavel Roskin struct iw_quality wstats; 705343c686c04eec556645f251f7d6c9b3d7335dae0Pavel Roskin wstats.level = level - 0x95; 706343c686c04eec556645f251f7d6c9b3d7335dae0Pavel Roskin wstats.noise = noise - 0x95; 707343c686c04eec556645f251f7d6c9b3d7335dae0Pavel Roskin wstats.qual = (level > noise) ? (level - noise) : 0; 708f941f8590c06c6b1a77c4b5a5df59f39a3c7d1e9Andrey Borzenkov wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; 709343c686c04eec556645f251f7d6c9b3d7335dae0Pavel Roskin /* Update spy records */ 710343c686c04eec556645f251f7d6c9b3d7335dae0Pavel Roskin wireless_spy_update(dev, mac, &wstats); 7111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void orinoco_stat_gather(struct net_device *dev, 7141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sk_buff *skb, 7151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct hermes_rx_descriptor *desc) 7161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 717ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 7181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Using spy support with lots of Rx packets, like in an 7201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * infrastructure (AP), will really slow down everything, because 7211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the MAC address must be compared to each entry of the spy list. 7221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If the user really asks for it (set some address in the 7231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * spy list), we do it, but he will pay the price. 7241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Note that to get here, you need both WIRELESS_SPY 7251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * compiled in AND some addresses in the list !!! 7261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 7271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Note : gcc will optimise the whole section away if 7281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * WIRELESS_SPY is not defined... - Jean II */ 7291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (SPY_NUMBER(priv)) { 73098e399f82ab3a6d863d1d4a7ea48925cc91c830eArnaldo Carvalho de Melo orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN, 7311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds desc->signal, desc->silence); 7321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 73598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig/* 73698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig * orinoco_rx_monitor - handle received monitor frames. 73798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig * 73898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig * Arguments: 73998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig * dev network device 74098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig * rxfid received FID 74198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig * desc rx descriptor of the frame 74298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig * 74398c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig * Call context: interrupt 74498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig */ 74598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwigstatic void orinoco_rx_monitor(struct net_device *dev, u16 rxfid, 74698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig struct hermes_rx_descriptor *desc) 74798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig{ 74898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig u32 hdrlen = 30; /* return full header by default */ 74998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig u32 datalen = 0; 75098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig u16 fc; 75198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig int err; 75298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig int len; 75398c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig struct sk_buff *skb; 754ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 75598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig struct net_device_stats *stats = &priv->stats; 756933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin struct hermes *hw = &priv->hw; 75798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 75898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig len = le16_to_cpu(desc->data_len); 75998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 76098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig /* Determine the size of the header and the data */ 76198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig fc = le16_to_cpu(desc->frame_ctl); 76298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig switch (fc & IEEE80211_FCTL_FTYPE) { 76398c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig case IEEE80211_FTYPE_DATA: 76498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig if ((fc & IEEE80211_FCTL_TODS) 76598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig && (fc & IEEE80211_FCTL_FROMDS)) 76698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig hdrlen = 30; 76798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig else 76898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig hdrlen = 24; 76998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig datalen = len; 77098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig break; 77198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig case IEEE80211_FTYPE_MGMT: 77298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig hdrlen = 24; 77398c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig datalen = len; 77498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig break; 77598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig case IEEE80211_FTYPE_CTL: 77698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig switch (fc & IEEE80211_FCTL_STYPE) { 77798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig case IEEE80211_STYPE_PSPOLL: 77898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig case IEEE80211_STYPE_RTS: 77998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig case IEEE80211_STYPE_CFEND: 78098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig case IEEE80211_STYPE_CFENDACK: 78198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig hdrlen = 16; 78298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig break; 78398c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig case IEEE80211_STYPE_CTS: 78498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig case IEEE80211_STYPE_ACK: 78598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig hdrlen = 10; 78698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig break; 78798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig } 78898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig break; 78998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig default: 79098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig /* Unknown frame type */ 79198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig break; 79298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig } 79398c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 79498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig /* sanity check the length */ 7952c706002fc147decdba2658ea48e4436faca3af2Johannes Berg if (datalen > IEEE80211_MAX_DATA_LEN + 12) { 79698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig printk(KERN_DEBUG "%s: oversized monitor frame, " 79798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig "data length = %d\n", dev->name, datalen); 79898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig stats->rx_length_errors++; 79998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig goto update_stats; 80098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig } 80198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 80298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig skb = dev_alloc_skb(hdrlen + datalen); 80398c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig if (!skb) { 80498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n", 80598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig dev->name); 806bb6e093da23ace2724fdadd27738027468eb82b3Florin Malita goto update_stats; 80798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig } 80898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 80998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig /* Copy the 802.11 header to the skb */ 81098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen); 811459a98ed881802dee55897441bc7f77af614368eArnaldo Carvalho de Melo skb_reset_mac_header(skb); 81298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 81398c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig /* If any, copy the data from the card to the skb */ 81498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig if (datalen > 0) { 815b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pread(hw, IRQ_BAP, skb_put(skb, datalen), 816b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy ALIGN(datalen, 2), rxfid, 817b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy HERMES_802_2_OFFSET); 81898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig if (err) { 81998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig printk(KERN_ERR "%s: error %d reading monitor frame\n", 82098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig dev->name, err); 82198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig goto drop; 82298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig } 82398c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig } 82498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 82598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig skb->dev = dev; 82698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig skb->ip_summed = CHECKSUM_NONE; 82798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig skb->pkt_type = PACKET_OTHERHOST; 828c1b4aa3fb619782213af2af6652663c8f9cef373Harvey Harrison skb->protocol = cpu_to_be16(ETH_P_802_2); 8296fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 83098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig stats->rx_packets++; 83198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig stats->rx_bytes += skb->len; 83298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 83398c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig netif_rx(skb); 83498c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig return; 83598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 83698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig drop: 83798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig dev_kfree_skb_irq(skb); 83898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig update_stats: 83998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig stats->rx_errors++; 84098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig stats->rx_dropped++; 84198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig} 84298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig 843933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskinvoid __orinoco_ev_rx(struct net_device *dev, struct hermes *hw) 8441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 845ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 8461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct net_device_stats *stats = &priv->stats; 8471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct iw_statistics *wstats = &priv->wstats; 8481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct sk_buff *skb = NULL; 84931afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy u16 rxfid, status; 8508f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig int length; 85131afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy struct hermes_rx_descriptor *desc; 85231afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy struct orinoco_rx_data *rx_data; 8531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err; 8541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 85531afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy desc = kmalloc(sizeof(*desc), GFP_ATOMIC); 85631afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy if (!desc) { 85731afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy printk(KERN_WARNING 85831afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy "%s: Can't allocate space for RX descriptor\n", 85931afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy dev->name); 86031afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy goto update_stats; 86131afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy } 86231afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy 8631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rxfid = hermes_read_regn(hw, RXFID); 8641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 865b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pread(hw, IRQ_BAP, desc, sizeof(*desc), 866b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy rxfid, 0); 8671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) { 8681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: error %d reading Rx descriptor. " 8691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "Frame dropped.\n", dev->name, err); 87098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig goto update_stats; 8711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 8721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 87331afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy status = le16_to_cpu(desc->status); 8741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 87598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig if (status & HERMES_RXSTAT_BADCRC) { 87698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", 87798c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig dev->name); 87898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig stats->rx_crc_errors++; 87998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig goto update_stats; 8801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 8811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 88298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig /* Handle frames in monitor mode */ 8835217c571c898371c540e49671600d54346b2e123David Kilroy if (priv->iw_mode == NL80211_IFTYPE_MONITOR) { 88431afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy orinoco_rx_monitor(dev, rxfid, desc); 88531afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy goto out; 88698c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig } 8871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 88898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig if (status & HERMES_RXSTAT_UNDECRYPTABLE) { 88998c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n", 89098c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig dev->name); 89198c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig wstats->discard.code++; 89298c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig goto update_stats; 8931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 8941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 89531afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy length = le16_to_cpu(desc->data_len); 8968f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig 8971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Sanity checks */ 8981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (length < 3) { /* No for even an 802.2 LLC header */ 8991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* At least on Symbol firmware with PCF we get quite a 9006fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy lot of these legitimately - Poll frames with no 9016fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy data. */ 90231afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy goto out; 9031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 9042c706002fc147decdba2658ea48e4436faca3af2Johannes Berg if (length > IEEE80211_MAX_DATA_LEN) { 9051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n", 9061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, length); 9071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds stats->rx_length_errors++; 90898c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig goto update_stats; 9091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 9101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 91123edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy /* Payload size does not include Michael MIC. Increase payload 91223edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy * size to read it together with the data. */ 91323edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy if (status & HERMES_RXSTAT_MIC) 91423edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy length += MICHAEL_MIC_LEN; 91523edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 9161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* We need space for the packet data itself, plus an ethernet 9171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds header, plus 2 bytes so we can align the IP header on a 9181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 32bit boundary, plus 1 byte so we can read in odd length 9191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds packets from the card, which has an IO granularity of 16 9206fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy bits */ 921933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin skb = dev_alloc_skb(length + ETH_HLEN + 2 + 1); 9221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!skb) { 9231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_WARNING "%s: Can't allocate skb for Rx\n", 9241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name); 92598c4cae1dafcf1abbfebc0189ff27df586a838b0Christoph Hellwig goto update_stats; 9261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 9271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9288f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig /* We'll prepend the header, so reserve space for it. The worst 9298f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig case is no decapsulation, when 802.3 header is prepended and 9308f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig nothing is removed. 2 is for aligning the IP header. */ 9318f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig skb_reserve(skb, ETH_HLEN + 2); 9328f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig 933b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pread(hw, IRQ_BAP, skb_put(skb, length), 934b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy ALIGN(length, 2), rxfid, 935b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy HERMES_802_2_OFFSET); 9368f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig if (err) { 9378f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig printk(KERN_ERR "%s: error %d reading frame. " 9388f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig "Frame dropped.\n", dev->name, err); 9398f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig goto drop; 9408f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig } 9411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 94231afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy /* Add desc and skb to rx queue */ 94331afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC); 944e404decb0fb017be80552adee894b35307b6c7b4Joe Perches if (!rx_data) 94531afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy goto drop; 946e404decb0fb017be80552adee894b35307b6c7b4Joe Perches 94731afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy rx_data->desc = desc; 94831afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy rx_data->skb = skb; 94931afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy list_add_tail(&rx_data->list, &priv->rx_list); 95031afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy tasklet_schedule(&priv->rx_tasklet); 95131afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy 95231afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy return; 95331afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy 95431afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroydrop: 95531afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy dev_kfree_skb_irq(skb); 95631afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroyupdate_stats: 95731afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy stats->rx_errors++; 95831afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy stats->rx_dropped++; 95931afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroyout: 96031afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy kfree(desc); 96131afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy} 9629afac70a7305817b22327ac23cf2d0eb72388229David KilroyEXPORT_SYMBOL(__orinoco_ev_rx); 96331afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy 96431afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroystatic void orinoco_rx(struct net_device *dev, 96531afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy struct hermes_rx_descriptor *desc, 96631afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy struct sk_buff *skb) 96731afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy{ 968ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 96931afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy struct net_device_stats *stats = &priv->stats; 97031afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy u16 status, fc; 97131afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy int length; 97231afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy struct ethhdr *hdr; 97331afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy 97431afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy status = le16_to_cpu(desc->status); 97531afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy length = le16_to_cpu(desc->data_len); 97631afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy fc = le16_to_cpu(desc->frame_ctl); 97731afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy 97823edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy /* Calculate and check MIC */ 97923edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy if (status & HERMES_RXSTAT_MIC) { 9804af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy struct orinoco_tkip_key *key; 98123edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >> 98223edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy HERMES_MIC_KEY_ID_SHIFT); 98323edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy u8 mic[MICHAEL_MIC_LEN]; 98423edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy u8 *rxmic; 98523edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy u8 *src = (fc & IEEE80211_FCTL_FROMDS) ? 98623edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy desc->addr3 : desc->addr2; 98723edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 98823edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy /* Extract Michael MIC from payload */ 98923edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy rxmic = skb->data + skb->len - MICHAEL_MIC_LEN; 99023edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 99123edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy skb_trim(skb, skb->len - MICHAEL_MIC_LEN); 99223edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy length -= MICHAEL_MIC_LEN; 99323edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 9944af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy key = (struct orinoco_tkip_key *) priv->keys[key_id].key; 9954af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy 9964af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy if (!key) { 9974af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy printk(KERN_WARNING "%s: Received encrypted frame from " 9984af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy "%pM using key %i, but key is not installed\n", 9994af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy dev->name, src, key_id); 10004af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy goto drop; 10014af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy } 10024af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy 10034af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy orinoco_mic(priv->rx_tfm_mic, key->rx_mic, desc->addr1, src, 100423edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 0, /* priority or QoS? */ 10054af198fb7a99b07980b1bd52df550ba3f24688dfDavid Kilroy skb->data, skb->len, &mic[0]); 100623edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 100723edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy if (memcmp(mic, rxmic, 100823edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy MICHAEL_MIC_LEN)) { 100923edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy union iwreq_data wrqu; 101023edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy struct iw_michaelmicfailure wxmic; 101123edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 101223edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy printk(KERN_WARNING "%s: " 1013e174961ca1a0b28f7abf0be47973ad57cb74e5f0Johannes Berg "Invalid Michael MIC in data frame from %pM, " 101423edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy "using key %i\n", 1015e174961ca1a0b28f7abf0be47973ad57cb74e5f0Johannes Berg dev->name, src, key_id); 101623edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 101723edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy /* TODO: update stats */ 101823edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 101923edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy /* Notify userspace */ 102023edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy memset(&wxmic, 0, sizeof(wxmic)); 102123edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy wxmic.flags = key_id & IW_MICFAILURE_KEY_ID; 102223edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy wxmic.flags |= (desc->addr1[0] & 1) ? 102323edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE; 102423edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy wxmic.src_addr.sa_family = ARPHRD_ETHER; 102523edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN); 102623edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 102723edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy (void) orinoco_hw_get_tkip_iv(priv, key_id, 102823edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy &wxmic.tsc[0]); 102923edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 103023edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy memset(&wrqu, 0, sizeof(wrqu)); 103123edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy wrqu.data.length = sizeof(wxmic); 103223edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, 103323edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy (char *) &wxmic); 103423edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 103523edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy goto drop; 103623edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy } 103723edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy } 103823edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 10391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Handle decapsulation 10401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * In most cases, the firmware tell us about SNAP frames. 10411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * For some reason, the SNAP frames sent by LinkSys APs 10421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * are not properly recognised by most firmwares. 10431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * So, check ourselves */ 10448f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig if (length >= ENCAPS_OVERHEAD && 10458f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) || 10468f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) || 10478f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig is_ethersnap(skb->data))) { 10481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* These indicate a SNAP within 802.2 LLC within 10491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 802.11 frame which we'll need to de-encapsulate to 10501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds the original EthernetII frame. */ 1051b2f30a0a2395b6c7e7138fbdabec2cb02ff373a7David Kilroy hdr = (struct ethhdr *)skb_push(skb, 1052b2f30a0a2395b6c7e7138fbdabec2cb02ff373a7David Kilroy ETH_HLEN - ENCAPS_OVERHEAD); 10531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 10548f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig /* 802.3 frame - prepend 802.3 header as is */ 10558f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN); 10568f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig hdr->h_proto = htons(length); 10571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 105831afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy memcpy(hdr->h_dest, desc->addr1, ETH_ALEN); 10598f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig if (fc & IEEE80211_FCTL_FROMDS) 106031afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy memcpy(hdr->h_source, desc->addr3, ETH_ALEN); 10618f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig else 106231afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy memcpy(hdr->h_source, desc->addr2, ETH_ALEN); 10631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds skb->protocol = eth_type_trans(skb, dev); 10651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds skb->ip_summed = CHECKSUM_NONE; 10668f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig if (fc & IEEE80211_FCTL_TODS) 10678f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig skb->pkt_type = PACKET_OTHERHOST; 10686fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 10691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Process the wireless stats if needed */ 107031afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy orinoco_stat_gather(dev, skb, desc); 10711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Pass the packet to the networking stack */ 10731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_rx(skb); 10741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds stats->rx_packets++; 10751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds stats->rx_bytes += length; 10761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 107823edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 107923edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy drop: 108023edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy dev_kfree_skb(skb); 108123edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy stats->rx_errors++; 108223edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy stats->rx_dropped++; 108331afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy} 10841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 108531afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroystatic void orinoco_rx_isr_tasklet(unsigned long data) 108631afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy{ 10875381956b780e82805247c2ec8e32c4c665309394David Kilroy struct orinoco_private *priv = (struct orinoco_private *) data; 10885381956b780e82805247c2ec8e32c4c665309394David Kilroy struct net_device *dev = priv->ndev; 108931afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy struct orinoco_rx_data *rx_data, *temp; 109031afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy struct hermes_rx_descriptor *desc; 109131afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy struct sk_buff *skb; 109220953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy unsigned long flags; 109320953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy 109420953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy /* orinoco_rx requires the driver lock, and we also need to 109520953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy * protect priv->rx_list, so just hold the lock over the 109620953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy * lot. 109720953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy * 109820953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy * If orinoco_lock fails, we've unplugged the card. In this 109920953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy * case just abort. */ 110020953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy if (orinoco_lock(priv, &flags) != 0) 110120953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy return; 110231afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy 110331afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy /* extract desc and skb from queue */ 110431afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) { 110531afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy desc = rx_data->desc; 110631afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy skb = rx_data->skb; 110731afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy list_del(&rx_data->list); 110831afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy kfree(rx_data); 110931afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy 111031afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy orinoco_rx(dev, desc, skb); 111131afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy 111231afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy kfree(desc); 111331afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy } 111420953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy 111520953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy orinoco_unlock(priv, &flags); 11161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 11171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 11191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Rx path (info frames) */ 11201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 11211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void print_linkstatus(struct net_device *dev, u16 status) 11231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 11242131266d6e53e8f84f8111323036343d72bcb856David Kilroy char *s; 11251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (suppress_linkstatus) 11271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 11281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (status) { 11301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case HERMES_LINKSTATUS_NOT_CONNECTED: 11311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s = "Not Connected"; 11321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 11331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case HERMES_LINKSTATUS_CONNECTED: 11341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s = "Connected"; 11351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 11361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case HERMES_LINKSTATUS_DISCONNECTED: 11371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s = "Disconnected"; 11381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 11391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case HERMES_LINKSTATUS_AP_CHANGE: 11401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s = "AP Changed"; 11411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 11421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case HERMES_LINKSTATUS_AP_OUT_OF_RANGE: 11431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s = "AP Out of Range"; 11441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 11451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case HERMES_LINKSTATUS_AP_IN_RANGE: 11461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s = "AP In Range"; 11471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 11481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case HERMES_LINKSTATUS_ASSOC_FAILED: 11491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s = "Association Failed"; 11501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 11511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds default: 11521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s = "UNKNOWN"; 11531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 11546fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 115511eaea416716deebcb18383b201ba8033cbf33dcPavel Roskin printk(KERN_DEBUG "%s: New link status: %s (%04x)\n", 11561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, s, status); 11571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 11581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 115916739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig/* Search scan results for requested BSSID, join it if found */ 1160c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsstatic void orinoco_join_ap(struct work_struct *work) 116116739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig{ 1162c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells struct orinoco_private *priv = 1163c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells container_of(work, struct orinoco_private, join_work); 1164c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells struct net_device *dev = priv->ndev; 116516739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig struct hermes *hw = &priv->hw; 116616739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig int err; 116716739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig unsigned long flags; 116816739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig struct join_req { 116916739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig u8 bssid[ETH_ALEN]; 1170d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le16 channel; 1171ba2d3587912f82d1ab4367975b1df460db60fb1eEric Dumazet } __packed req; 117216739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig const int atom_len = offsetof(struct prism2_scan_apinfo, atim); 1173c89cc225f72ec240196733872fa1a9eb9d8335acPavel Roskin struct prism2_scan_apinfo *atom = NULL; 117416739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig int offset = 4; 1175c89cc225f72ec240196733872fa1a9eb9d8335acPavel Roskin int found = 0; 117616739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig u8 *buf; 117716739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig u16 len; 117816739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 117916739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig /* Allocate buffer for scan results */ 118016739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL); 1181a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if (!buf) 118216739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig return; 118316739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 118416739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig if (orinoco_lock(priv, &flags) != 0) 1185f3cb4cc120177090b0ccc9fb20a12010de39ac8aPavel Roskin goto fail_lock; 118616739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 118716739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig /* Sanity checks in case user changed something in the meantime */ 1188a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if (!priv->bssid_fixed) 118916739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig goto out; 119016739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 119116739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig if (strlen(priv->desired_essid) == 0) 119216739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig goto out; 119316739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 119416739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig /* Read scan results from the firmware */ 1195b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->read_ltv(hw, USER_BAP, 1196b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy HERMES_RID_SCANRESULTSTABLE, 1197b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy MAX_SCAN_LEN, &len, buf); 119816739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig if (err) { 119916739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig printk(KERN_ERR "%s: Cannot read scan results\n", 120016739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig dev->name); 120116739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig goto out; 120216739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig } 120316739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 120416739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig len = HERMES_RECLEN_TO_BYTES(len); 120516739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 120616739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig /* Go through the scan results looking for the channel of the AP 120716739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig * we were requested to join */ 120816739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig for (; offset + atom_len <= len; offset += atom_len) { 120916739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig atom = (struct prism2_scan_apinfo *) (buf + offset); 1210c89cc225f72ec240196733872fa1a9eb9d8335acPavel Roskin if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) { 1211c89cc225f72ec240196733872fa1a9eb9d8335acPavel Roskin found = 1; 1212c89cc225f72ec240196733872fa1a9eb9d8335acPavel Roskin break; 1213c89cc225f72ec240196733872fa1a9eb9d8335acPavel Roskin } 121416739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig } 121516739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 1216a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if (!found) { 1217c89cc225f72ec240196733872fa1a9eb9d8335acPavel Roskin DEBUG(1, "%s: Requested AP not found in scan results\n", 1218c89cc225f72ec240196733872fa1a9eb9d8335acPavel Roskin dev->name); 1219c89cc225f72ec240196733872fa1a9eb9d8335acPavel Roskin goto out; 1220c89cc225f72ec240196733872fa1a9eb9d8335acPavel Roskin } 122116739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 122216739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig memcpy(req.bssid, priv->desired_bssid, ETH_ALEN); 122316739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig req.channel = atom->channel; /* both are little-endian */ 122416739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST, 122516739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig &req); 122616739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig if (err) 122716739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig printk(KERN_ERR "%s: Error issuing join request\n", dev->name); 122816739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 122916739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig out: 123016739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig orinoco_unlock(priv, &flags); 1231f3cb4cc120177090b0ccc9fb20a12010de39ac8aPavel Roskin 1232f3cb4cc120177090b0ccc9fb20a12010de39ac8aPavel Roskin fail_lock: 1233f3cb4cc120177090b0ccc9fb20a12010de39ac8aPavel Roskin kfree(buf); 123416739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig} 123516739b065f4b0965d975f5c756204c7aa911cd61Christoph Hellwig 123695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig/* Send new BSSID to userspace */ 12376cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroystatic void orinoco_send_bssid_wevent(struct orinoco_private *priv) 123895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig{ 1239c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells struct net_device *dev = priv->ndev; 124095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig struct hermes *hw = &priv->hw; 124195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig union iwreq_data wrqu; 124295dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig int err; 124395dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 1244b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID, 1245b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy ETH_ALEN, NULL, wrqu.ap_addr.sa_data); 124695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig if (err != 0) 12476cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy return; 124895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 124995dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig wrqu.ap_addr.sa_family = ARPHRD_ETHER; 125095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 125195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* Send event to user space */ 125295dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); 12536cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy} 12546cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy 125506009fda9fde1b97074ab3d932d0468396bf5d10David Kilroystatic void orinoco_send_assocreqie_wevent(struct orinoco_private *priv) 125606009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy{ 125706009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy struct net_device *dev = priv->ndev; 125806009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy struct hermes *hw = &priv->hw; 125906009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy union iwreq_data wrqu; 126006009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy int err; 126106009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy u8 buf[88]; 126206009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy u8 *ie; 126306009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy 126406009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy if (!priv->has_wpa) 126506009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy return; 126606009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy 1267b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO, 1268b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy sizeof(buf), NULL, &buf); 126906009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy if (err != 0) 127006009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy return; 127106009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy 127206009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy ie = orinoco_get_wpa_ie(buf, sizeof(buf)); 127306009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy if (ie) { 127406009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy int rem = sizeof(buf) - (ie - &buf[0]); 127506009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy wrqu.data.length = ie[1] + 2; 127606009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy if (wrqu.data.length > rem) 127706009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy wrqu.data.length = rem; 127806009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy 127906009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy if (wrqu.data.length) 128006009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy /* Send event to user space */ 128106009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie); 128206009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy } 128306009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy} 128406009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy 128506009fda9fde1b97074ab3d932d0468396bf5d10David Kilroystatic void orinoco_send_assocrespie_wevent(struct orinoco_private *priv) 128606009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy{ 128706009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy struct net_device *dev = priv->ndev; 128806009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy struct hermes *hw = &priv->hw; 128906009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy union iwreq_data wrqu; 129006009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy int err; 129106009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */ 129206009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy u8 *ie; 129306009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy 129406009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy if (!priv->has_wpa) 129506009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy return; 129606009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy 1297b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->read_ltv(hw, USER_BAP, 1298b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy HERMES_RID_CURRENT_ASSOC_RESP_INFO, 1299b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy sizeof(buf), NULL, &buf); 130006009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy if (err != 0) 130106009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy return; 130206009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy 130306009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy ie = orinoco_get_wpa_ie(buf, sizeof(buf)); 130406009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy if (ie) { 130506009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy int rem = sizeof(buf) - (ie - &buf[0]); 130606009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy wrqu.data.length = ie[1] + 2; 130706009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy if (wrqu.data.length > rem) 130806009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy wrqu.data.length = rem; 130906009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy 131006009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy if (wrqu.data.length) 131106009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy /* Send event to user space */ 131206009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie); 131306009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy } 131406009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy} 131506009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy 13166cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroystatic void orinoco_send_wevents(struct work_struct *work) 13176cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy{ 13186cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy struct orinoco_private *priv = 13196cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy container_of(work, struct orinoco_private, wevent_work); 13206cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy unsigned long flags; 13216cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy 13226cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy if (orinoco_lock(priv, &flags) != 0) 13236cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy return; 13246cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy 132506009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy orinoco_send_assocreqie_wevent(priv); 132606009fda9fde1b97074ab3d932d0468396bf5d10David Kilroy orinoco_send_assocrespie_wevent(priv); 13276cd90b1cac290c64a93b7e992bb1ef495988465fDavid Kilroy orinoco_send_bssid_wevent(priv); 13288aeabc375041a5fe9c9be315472497b2e0547eedPavel Roskin 132995dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig orinoco_unlock(priv, &flags); 133095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig} 133195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 1332c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroystatic void qbuf_scan(struct orinoco_private *priv, void *buf, 1333c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy int len, int type) 1334c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy{ 1335c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy struct orinoco_scan_data *sd; 1336c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy unsigned long flags; 1337c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1338c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy sd = kmalloc(sizeof(*sd), GFP_ATOMIC); 1339e90c7e712980bf794f88f749e2a1270e4a4a116eSantosh Nayak if (!sd) { 1340e90c7e712980bf794f88f749e2a1270e4a4a116eSantosh Nayak printk(KERN_ERR "%s: failed to alloc memory\n", __func__); 1341e90c7e712980bf794f88f749e2a1270e4a4a116eSantosh Nayak return; 1342e90c7e712980bf794f88f749e2a1270e4a4a116eSantosh Nayak } 1343c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy sd->buf = buf; 1344c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy sd->len = len; 1345c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy sd->type = type; 1346c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1347c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy spin_lock_irqsave(&priv->scan_lock, flags); 1348c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy list_add_tail(&sd->list, &priv->scan_list); 1349c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy spin_unlock_irqrestore(&priv->scan_lock, flags); 1350c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1351c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy schedule_work(&priv->process_scan); 1352c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy} 1353c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1354c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroystatic void qabort_scan(struct orinoco_private *priv) 1355c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy{ 1356c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy struct orinoco_scan_data *sd; 1357c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy unsigned long flags; 1358c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1359c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy sd = kmalloc(sizeof(*sd), GFP_ATOMIC); 1360e90c7e712980bf794f88f749e2a1270e4a4a116eSantosh Nayak if (!sd) { 1361e90c7e712980bf794f88f749e2a1270e4a4a116eSantosh Nayak printk(KERN_ERR "%s: failed to alloc memory\n", __func__); 1362e90c7e712980bf794f88f749e2a1270e4a4a116eSantosh Nayak return; 1363e90c7e712980bf794f88f749e2a1270e4a4a116eSantosh Nayak } 1364c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy sd->len = -1; /* Abort */ 1365c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1366c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy spin_lock_irqsave(&priv->scan_lock, flags); 1367c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy list_add_tail(&sd->list, &priv->scan_list); 1368c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy spin_unlock_irqrestore(&priv->scan_lock, flags); 1369c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1370c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy schedule_work(&priv->process_scan); 1371c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy} 1372c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1373c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroystatic void orinoco_process_scan_results(struct work_struct *work) 1374c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy{ 1375c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy struct orinoco_private *priv = 1376c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy container_of(work, struct orinoco_private, process_scan); 1377c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy struct orinoco_scan_data *sd, *temp; 1378c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy unsigned long flags; 1379c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy void *buf; 1380c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy int len; 1381c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy int type; 1382c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1383c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy spin_lock_irqsave(&priv->scan_lock, flags); 1384c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy list_for_each_entry_safe(sd, temp, &priv->scan_list, list) { 1385c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1386c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy buf = sd->buf; 1387c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy len = sd->len; 1388c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy type = sd->type; 1389c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1390c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy list_del(&sd->list); 13913bf184a7e96ff21965fa524260f60af8ab4d9133Joe Gunn spin_unlock_irqrestore(&priv->scan_lock, flags); 1392c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy kfree(sd); 1393c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1394c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy if (len > 0) { 1395c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy if (type == HERMES_INQ_CHANNELINFO) 1396c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy orinoco_add_extscan_result(priv, buf, len); 1397c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy else 1398c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy orinoco_add_hostscan_results(priv, buf, len); 1399c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1400c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy kfree(buf); 1401cf63495d0dbe435b475a44672f5dee150da6471bDavid Kilroy } else { 1402c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy /* Either abort or complete the scan */ 1403cf63495d0dbe435b475a44672f5dee150da6471bDavid Kilroy orinoco_scan_done(priv, (len < 0)); 1404c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy } 1405c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1406c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy spin_lock_irqsave(&priv->scan_lock, flags); 1407c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy } 1408c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy spin_unlock_irqrestore(&priv->scan_lock, flags); 1409c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy} 1410c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 1411933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskinvoid __orinoco_ev_info(struct net_device *dev, struct hermes *hw) 14121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1413ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 14141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u16 infofid; 14151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct { 1416d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le16 len; 1417d133ae4cd6a3c75c31b1630f906cc9979a11077fPavel Roskin __le16 type; 1418ba2d3587912f82d1ab4367975b1df460db60fb1eEric Dumazet } __packed info; 14191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int len, type; 14201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err; 14211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* This is an answer to an INQUIRE command that we did earlier, 14231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * or an information "event" generated by the card 14241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The controller return to us a pseudo frame containing 14251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the information in question - Jean II */ 14261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds infofid = hermes_read_regn(hw, INFOFID); 14271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Read the info frame header - don't try too hard */ 1429b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pread(hw, IRQ_BAP, &info, sizeof(info), 1430b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy infofid, 0); 14311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) { 14321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: error %d reading info frame. " 14331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "Frame dropped.\n", dev->name, err); 14341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 14351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 14366fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 14371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len)); 14381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds type = le16_to_cpu(info.type); 14391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (type) { 14411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case HERMES_INQ_TALLIES: { 14421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct hermes_tallies_frame tallies; 14431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct iw_statistics *wstats = &priv->wstats; 14446fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 14451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (len > sizeof(tallies)) { 14461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n", 14471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, len); 14481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len = sizeof(tallies); 14491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 14506fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 1451b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pread(hw, IRQ_BAP, &tallies, len, 1452b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy infofid, sizeof(info)); 145384d8a2fb56b1d3c915591a2c1aa321b783c7d00fChristoph Hellwig if (err) 145484d8a2fb56b1d3c915591a2c1aa321b783c7d00fChristoph Hellwig break; 14556fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 14561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Increment our various counters */ 14571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* wstats->discard.nwid - no wrong BSSID stuff */ 14581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wstats->discard.code += 14591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds le16_to_cpu(tallies.RxWEPUndecryptable); 14606fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy if (len == sizeof(tallies)) 14611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wstats->discard.code += 14621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds le16_to_cpu(tallies.RxDiscards_WEPICVError) + 14631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds le16_to_cpu(tallies.RxDiscards_WEPExcluded); 14641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wstats->discard.misc += 14651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds le16_to_cpu(tallies.TxDiscardsWrongSA); 14661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wstats->discard.fragment += 14671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds le16_to_cpu(tallies.RxMsgInBadMsgFragments); 14681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wstats->discard.retries += 14691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds le16_to_cpu(tallies.TxRetryLimitExceeded); 14701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* wstats->miss.beacon - no match */ 14711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 14721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 14731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case HERMES_INQ_LINKSTATUS: { 14741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct hermes_linkstatus linkstatus; 14751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u16 newstatus; 14761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int connected; 14771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14785217c571c898371c540e49671600d54346b2e123David Kilroy if (priv->iw_mode == NL80211_IFTYPE_MONITOR) 14798f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig break; 14808f2abf4430ef2a131926a537ee6325dc43b0ec28Christoph Hellwig 14811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (len != sizeof(linkstatus)) { 14821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n", 14831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, len); 14841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 14851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 14861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1487b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pread(hw, IRQ_BAP, &linkstatus, len, 1488b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy infofid, sizeof(info)); 148984d8a2fb56b1d3c915591a2c1aa321b783c7d00fChristoph Hellwig if (err) 149084d8a2fb56b1d3c915591a2c1aa321b783c7d00fChristoph Hellwig break; 14911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds newstatus = le16_to_cpu(linkstatus.linkstatus); 14921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 149395dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* Symbol firmware uses "out of range" to signal that 149495dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * the hostscan frame can be requested. */ 149595dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE && 149695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig priv->firmware_type == FIRMWARE_TYPE_SYMBOL && 1497c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy priv->has_hostscan && priv->scan_request) { 149895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL); 149995dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig break; 150095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig } 150195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 15021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds connected = (newstatus == HERMES_LINKSTATUS_CONNECTED) 15031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds || (newstatus == HERMES_LINKSTATUS_AP_CHANGE) 15041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE); 15051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (connected) 15071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_carrier_on(dev); 15087bb7c3a326f509acbdaf550b54fba565544ef200David Gibson else if (!ignore_disconnect) 15091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_carrier_off(dev); 15101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 151195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig if (newstatus != priv->last_linkstatus) { 151295dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig priv->last_linkstatus = newstatus; 15131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds print_linkstatus(dev, newstatus); 151495dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* The info frame contains only one word which is the 151595dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * status (see hermes.h). The status is pretty boring 151695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * in itself, that's why we export the new BSSID... 151795dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * Jean II */ 151895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig schedule_work(&priv->wevent_work); 151995dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig } 152095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig } 152195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig break; 152295dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig case HERMES_INQ_SCAN: 1523c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy if (!priv->scan_request && priv->bssid_fixed && 152495dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig priv->firmware_type == FIRMWARE_TYPE_INTERSIL) { 152595dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig schedule_work(&priv->join_work); 152695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig break; 152795dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig } 152895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* fall through */ 152995dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig case HERMES_INQ_HOSTSCAN: 153095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig case HERMES_INQ_HOSTSCAN_SYMBOL: { 153195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* Result of a scanning. Contains information about 153295dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig * cells in the vicinity - Jean II */ 153395dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig unsigned char *buf; 153495dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 153595dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* Sanity check */ 153695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig if (len > 4096) { 153795dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n", 153895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig dev->name, len); 1539c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy qabort_scan(priv); 154095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig break; 154195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig } 154295dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 154395dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* Allocate buffer for results */ 154495dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig buf = kmalloc(len, GFP_ATOMIC); 1545c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy if (buf == NULL) { 154695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* No memory, so can't printk()... */ 1547c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy qabort_scan(priv); 154895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig break; 1549c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy } 155095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 155195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* Read scan data */ 1552b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pread(hw, IRQ_BAP, (void *) buf, len, 1553b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy infofid, sizeof(info)); 1554708218b064e3ad3d55ac0f9d19b3c8c0fb7af3a4Pavel Roskin if (err) { 1555708218b064e3ad3d55ac0f9d19b3c8c0fb7af3a4Pavel Roskin kfree(buf); 1556c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy qabort_scan(priv); 155795dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig break; 1558708218b064e3ad3d55ac0f9d19b3c8c0fb7af3a4Pavel Roskin } 15591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 156095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig#ifdef ORINOCO_DEBUG 156195dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig { 156295dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig int i; 156395dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig printk(KERN_DEBUG "Scan result [%02X", buf[0]); 1564a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy for (i = 1; i < (len * 2); i++) 156595dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig printk(":%02X", buf[i]); 156695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig printk("]\n"); 156795dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig } 156895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig#endif /* ORINOCO_DEBUG */ 156995dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 1570c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy qbuf_scan(priv, buf, len, type); 15711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 15721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 157301632fa4af34addf78ce999eabb4430f33942ee2David Kilroy case HERMES_INQ_CHANNELINFO: 157401632fa4af34addf78ce999eabb4430f33942ee2David Kilroy { 157501632fa4af34addf78ce999eabb4430f33942ee2David Kilroy struct agere_ext_scan_info *bss; 157601632fa4af34addf78ce999eabb4430f33942ee2David Kilroy 1577c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy if (!priv->scan_request) { 157801632fa4af34addf78ce999eabb4430f33942ee2David Kilroy printk(KERN_DEBUG "%s: Got chaninfo without scan, " 157901632fa4af34addf78ce999eabb4430f33942ee2David Kilroy "len=%d\n", dev->name, len); 158001632fa4af34addf78ce999eabb4430f33942ee2David Kilroy break; 158101632fa4af34addf78ce999eabb4430f33942ee2David Kilroy } 158201632fa4af34addf78ce999eabb4430f33942ee2David Kilroy 158301632fa4af34addf78ce999eabb4430f33942ee2David Kilroy /* An empty result indicates that the scan is complete */ 158401632fa4af34addf78ce999eabb4430f33942ee2David Kilroy if (len == 0) { 1585c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy qbuf_scan(priv, NULL, len, type); 158601632fa4af34addf78ce999eabb4430f33942ee2David Kilroy break; 158701632fa4af34addf78ce999eabb4430f33942ee2David Kilroy } 158801632fa4af34addf78ce999eabb4430f33942ee2David Kilroy 158901632fa4af34addf78ce999eabb4430f33942ee2David Kilroy /* Sanity check */ 1590c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy else if (len < (offsetof(struct agere_ext_scan_info, 159101632fa4af34addf78ce999eabb4430f33942ee2David Kilroy data) + 2)) { 159201632fa4af34addf78ce999eabb4430f33942ee2David Kilroy /* Drop this result now so we don't have to 159301632fa4af34addf78ce999eabb4430f33942ee2David Kilroy * keep checking later */ 159401632fa4af34addf78ce999eabb4430f33942ee2David Kilroy printk(KERN_WARNING 159501632fa4af34addf78ce999eabb4430f33942ee2David Kilroy "%s: Ext scan results too short (%d bytes)\n", 159601632fa4af34addf78ce999eabb4430f33942ee2David Kilroy dev->name, len); 159701632fa4af34addf78ce999eabb4430f33942ee2David Kilroy break; 159801632fa4af34addf78ce999eabb4430f33942ee2David Kilroy } 159901632fa4af34addf78ce999eabb4430f33942ee2David Kilroy 1600c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy bss = kmalloc(len, GFP_ATOMIC); 160101632fa4af34addf78ce999eabb4430f33942ee2David Kilroy if (bss == NULL) 160201632fa4af34addf78ce999eabb4430f33942ee2David Kilroy break; 160301632fa4af34addf78ce999eabb4430f33942ee2David Kilroy 160401632fa4af34addf78ce999eabb4430f33942ee2David Kilroy /* Read scan data */ 1605b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->bap_pread(hw, IRQ_BAP, (void *) bss, len, 1606b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy infofid, sizeof(info)); 1607c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy if (err) 160801632fa4af34addf78ce999eabb4430f33942ee2David Kilroy kfree(bss); 1609c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy else 1610c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy qbuf_scan(priv, bss, len, type); 161101632fa4af34addf78ce999eabb4430f33942ee2David Kilroy 161201632fa4af34addf78ce999eabb4430f33942ee2David Kilroy break; 161301632fa4af34addf78ce999eabb4430f33942ee2David Kilroy } 161495dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig case HERMES_INQ_SEC_STAT_AGERE: 161595dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* Security status (Agere specific) */ 161695dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* Ignore this frame for now */ 161795dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig if (priv->firmware_type == FIRMWARE_TYPE_AGERE) 161895dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig break; 161995dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig /* fall through */ 16201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds default: 16211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_DEBUG "%s: Unknown information frame received: " 16221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "type 0x%04x, length %d\n", dev->name, type, len); 16231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* We don't actually do anything about it */ 16241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 16251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 16261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 16279afac70a7305817b22327ac23cf2d0eb72388229David KilroyEXPORT_SYMBOL(__orinoco_ev_info); 16281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1629933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskinstatic void __orinoco_ev_infdrop(struct net_device *dev, struct hermes *hw) 16301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 16311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (net_ratelimit()) 16321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name); 16331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 16341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 16361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Internal hardware control routines */ 16371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 16381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16396415f7df10573bf1ec42644f42bef565127114a1David Kilroystatic int __orinoco_up(struct orinoco_private *priv) 16401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1641a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroy struct net_device *dev = priv->ndev; 16421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct hermes *hw = &priv->hw; 16431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err; 16441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 164584d8a2fb56b1d3c915591a2c1aa321b783c7d00fChristoph Hellwig netif_carrier_off(dev); /* just to make sure */ 164684d8a2fb56b1d3c915591a2c1aa321b783c7d00fChristoph Hellwig 1647721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy err = __orinoco_commit(priv); 16481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) { 16491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: Error %d configuring card\n", 16501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, err); 16511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 16521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 16531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Fire things up again */ 16551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds hermes_set_irqmask(hw, ORINOCO_INTEN); 16561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = hermes_enable_port(hw, 0); 16571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) { 16581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: Error %d enabling MAC port\n", 16591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, err); 16601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 16611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 16621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_start_queue(dev); 16641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 16661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 16671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16686415f7df10573bf1ec42644f42bef565127114a1David Kilroystatic int __orinoco_down(struct orinoco_private *priv) 16691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1670a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroy struct net_device *dev = priv->ndev; 16711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct hermes *hw = &priv->hw; 16721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err; 16731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_stop_queue(dev); 16751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1676a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if (!priv->hw_unavailable) { 1677a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if (!priv->broken_disableport) { 16781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = hermes_disable_port(hw, 0); 16791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) { 16801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Some firmwares (e.g. Intersil 1.3.x) seem 16811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to have problems disabling the port, oh 16821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * well, too bad. */ 16831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_WARNING "%s: Error %d disabling MAC port\n", 16841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, err); 16851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->broken_disableport = 1; 16861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 16871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 16881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds hermes_set_irqmask(hw, 0); 16891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds hermes_write_regn(hw, EVACK, 0xffff); 16901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 16916fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 1692cf63495d0dbe435b475a44672f5dee150da6471bDavid Kilroy orinoco_scan_done(priv, true); 1693cf63495d0dbe435b475a44672f5dee150da6471bDavid Kilroy 16941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* firmware will have to reassociate */ 16951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_carrier_off(dev); 16961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->last_linkstatus = 0xffff; 16971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 16991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 17001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17016415f7df10573bf1ec42644f42bef565127114a1David Kilroystatic int orinoco_reinit_firmware(struct orinoco_private *priv) 170237a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin{ 170337a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin struct hermes *hw = &priv->hw; 170437a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin int err; 170537a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin 1706b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->init(hw); 17070df6cbb7d8a0a8fea69138e9e463671a8ad99f16Andrey Borzenkov if (priv->do_fw_download && !err) { 17080df6cbb7d8a0a8fea69138e9e463671a8ad99f16Andrey Borzenkov err = orinoco_download(priv); 17090df6cbb7d8a0a8fea69138e9e463671a8ad99f16Andrey Borzenkov if (err) 17100df6cbb7d8a0a8fea69138e9e463671a8ad99f16Andrey Borzenkov priv->do_fw_download = 0; 17110df6cbb7d8a0a8fea69138e9e463671a8ad99f16Andrey Borzenkov } 171237a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin if (!err) 171342a51b933034bbed93fa54009c96a482044e5b43David Kilroy err = orinoco_hw_allocate_fid(priv); 171437a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin 171537a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin return err; 171637a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin} 171737a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin 1718721aa2f75b00399074eb443fdf16d797b4504a36David Kilroystatic int 17195865d015cf85c619a51f8be93d44ec932bc90038David Kilroy__orinoco_set_multicast_list(struct net_device *dev) 17205865d015cf85c619a51f8be93d44ec932bc90038David Kilroy{ 1721ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct orinoco_private *priv = ndev_priv(dev); 17225865d015cf85c619a51f8be93d44ec932bc90038David Kilroy int err = 0; 17235865d015cf85c619a51f8be93d44ec932bc90038David Kilroy int promisc, mc_count; 17245865d015cf85c619a51f8be93d44ec932bc90038David Kilroy 17255865d015cf85c619a51f8be93d44ec932bc90038David Kilroy /* The Hermes doesn't seem to have an allmulti mode, so we go 17265865d015cf85c619a51f8be93d44ec932bc90038David Kilroy * into promiscuous mode and let the upper levels deal. */ 17275865d015cf85c619a51f8be93d44ec932bc90038David Kilroy if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) || 17284cd24eaf0c6ee7f0242e34ee77ec899f255e66b5Jiri Pirko (netdev_mc_count(dev) > MAX_MULTICAST(priv))) { 17295865d015cf85c619a51f8be93d44ec932bc90038David Kilroy promisc = 1; 17305865d015cf85c619a51f8be93d44ec932bc90038David Kilroy mc_count = 0; 17315865d015cf85c619a51f8be93d44ec932bc90038David Kilroy } else { 17325865d015cf85c619a51f8be93d44ec932bc90038David Kilroy promisc = 0; 17334cd24eaf0c6ee7f0242e34ee77ec899f255e66b5Jiri Pirko mc_count = netdev_mc_count(dev); 17345865d015cf85c619a51f8be93d44ec932bc90038David Kilroy } 17355865d015cf85c619a51f8be93d44ec932bc90038David Kilroy 1736655ffee284dfcf9a24ac0343f3e5ee6db85b85c5Jiri Pirko err = __orinoco_hw_set_multicast_list(priv, dev, mc_count, promisc); 1737721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 1738721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy return err; 17391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 17401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* This must be called from user context, without locks held - use 17421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * schedule_work() */ 1743cb1576a829826d56fab59e22aa3af8c5a7db9936David Kilroyvoid orinoco_reset(struct work_struct *work) 17441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1745c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells struct orinoco_private *priv = 1746c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells container_of(work, struct orinoco_private, reset_work); 1747c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells struct net_device *dev = priv->ndev; 17481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct hermes *hw = &priv->hw; 17498551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig int err; 17501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 17511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (orinoco_lock(priv, &flags) != 0) 17531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* When the hardware becomes available again, whatever 17541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * detects that is responsible for re-initializing 17551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it. So no need for anything further */ 17561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 17571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_stop_queue(dev); 17591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Shut off interrupts. Depending on what state the hardware 17611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * is in, this might not work, but we'll try anyway */ 17621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds hermes_set_irqmask(hw, 0); 17631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds hermes_write_regn(hw, EVACK, 0xffff); 17641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->hw_unavailable++; 17661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */ 17671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netif_carrier_off(dev); 17681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds orinoco_unlock(priv, &flags); 17701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1771c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy /* Scanning support: Notify scan cancellation */ 1772cf63495d0dbe435b475a44672f5dee150da6471bDavid Kilroy orinoco_scan_done(priv, true); 177395dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 17748551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig if (priv->hard_reset) { 17751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = (*priv->hard_reset)(priv); 17768551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig if (err) { 17778551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig printk(KERN_ERR "%s: orinoco_reset: Error %d " 17788551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig "performing hard reset\n", dev->name, err); 17798551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig goto disable; 17808551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig } 17811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 17821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1783a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroy err = orinoco_reinit_firmware(priv); 17841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) { 17851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n", 17861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, err); 17878551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig goto disable; 17881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 17891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1790b2f30a0a2395b6c7e7138fbdabec2cb02ff373a7David Kilroy /* This has to be called from user context */ 1791bcad6e80f3fb0d6724c3814cf32258bbcf1d67dbDavid Kilroy orinoco_lock_irq(priv); 17921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->hw_unavailable--; 17941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* priv->open or priv->hw_unavailable might have changed while 17961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * we dropped the lock */ 1797a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if (priv->open && (!priv->hw_unavailable)) { 1798a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroy err = __orinoco_up(priv); 17991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err) { 18001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n", 18011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name, err); 18021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else 18031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->trans_start = jiffies; 18041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 18051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1806bcad6e80f3fb0d6724c3814cf32258bbcf1d67dbDavid Kilroy orinoco_unlock_irq(priv); 18071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 18081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 18098551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig disable: 18108551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig hermes_set_irqmask(hw, 0); 18118551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig netif_device_detach(dev); 18128551cb980086eb9952387a9f135d6f96af3b82eeChristoph Hellwig printk(KERN_ERR "%s: Device has been disabled!\n", dev->name); 18131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 18141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1815721aa2f75b00399074eb443fdf16d797b4504a36David Kilroystatic int __orinoco_commit(struct orinoco_private *priv) 1816721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy{ 1817721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy struct net_device *dev = priv->ndev; 1818721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy int err = 0; 1819721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 1820ba34fcee476d11e7c9df95932787a22a96ff6e68David Kilroy /* If we've called commit, we are reconfiguring or bringing the 1821ba34fcee476d11e7c9df95932787a22a96ff6e68David Kilroy * interface up. Maintaining countermeasures across this would 1822ba34fcee476d11e7c9df95932787a22a96ff6e68David Kilroy * be confusing, so note that we've disabled them. The port will 1823ba34fcee476d11e7c9df95932787a22a96ff6e68David Kilroy * be enabled later in orinoco_commit or __orinoco_up. */ 1824ba34fcee476d11e7c9df95932787a22a96ff6e68David Kilroy priv->tkip_cm_active = 0; 1825ba34fcee476d11e7c9df95932787a22a96ff6e68David Kilroy 1826721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy err = orinoco_hw_program_rids(priv); 1827721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 1828721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy /* FIXME: what about netif_tx_lock */ 1829721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy (void) __orinoco_set_multicast_list(dev); 1830721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 1831721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy return err; 1832721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy} 1833721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 1834721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy/* Ensures configuration changes are applied. May result in a reset. 1835721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy * The caller should hold priv->lock 1836721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy */ 1837721aa2f75b00399074eb443fdf16d797b4504a36David Kilroyint orinoco_commit(struct orinoco_private *priv) 1838721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy{ 1839721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy struct net_device *dev = priv->ndev; 1840933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin struct hermes *hw = &priv->hw; 1841721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy int err; 1842721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 1843721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy if (priv->broken_disableport) { 1844721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy schedule_work(&priv->reset_work); 1845721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy return 0; 1846721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy } 1847721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 1848721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy err = hermes_disable_port(hw, 0); 1849721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy if (err) { 1850721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy printk(KERN_WARNING "%s: Unable to disable port " 1851721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy "while reconfiguring card\n", dev->name); 1852721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy priv->broken_disableport = 1; 1853721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy goto out; 1854721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy } 1855721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 1856721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy err = __orinoco_commit(priv); 1857721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy if (err) { 1858721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy printk(KERN_WARNING "%s: Unable to reconfigure card\n", 1859721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy dev->name); 1860721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy goto out; 1861721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy } 1862721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 1863721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy err = hermes_enable_port(hw, 0); 1864721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy if (err) { 1865721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n", 1866721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy dev->name); 1867721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy goto out; 1868721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy } 1869721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 1870721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy out: 1871721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy if (err) { 1872721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy printk(KERN_WARNING "%s: Resetting instead...\n", dev->name); 1873721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy schedule_work(&priv->reset_work); 1874721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy err = 0; 1875721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy } 1876721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy return err; 1877721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy} 1878721aa2f75b00399074eb443fdf16d797b4504a36David Kilroy 18791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 18801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Interrupt handler */ 18811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 18821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1883933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskinstatic void __orinoco_ev_tick(struct net_device *dev, struct hermes *hw) 18841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 18851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_DEBUG "%s: TICK\n", dev->name); 18861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 18871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1888933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskinstatic void __orinoco_ev_wterr(struct net_device *dev, struct hermes *hw) 18891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 18901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* This seems to happen a fair bit under load, but ignoring it 18911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds seems to work fine...*/ 18921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n", 18931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->name); 18941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 18951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 18967d12e780e003f93433d49ce78cfedf4b4c52adc5David Howellsirqreturn_t orinoco_interrupt(int irq, void *dev_id) 18971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1898a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroy struct orinoco_private *priv = dev_id; 1899a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroy struct net_device *dev = priv->ndev; 1900933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin struct hermes *hw = &priv->hw; 19011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int count = MAX_IRQLOOPS_PER_IRQ; 19021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u16 evstat, events; 19032131266d6e53e8f84f8111323036343d72bcb856David Kilroy /* These are used to detect a runaway interrupt situation. 19042131266d6e53e8f84f8111323036343d72bcb856David Kilroy * 19052131266d6e53e8f84f8111323036343d72bcb856David Kilroy * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy, 19062131266d6e53e8f84f8111323036343d72bcb856David Kilroy * we panic and shut down the hardware 19072131266d6e53e8f84f8111323036343d72bcb856David Kilroy */ 19082131266d6e53e8f84f8111323036343d72bcb856David Kilroy /* jiffies value the last time we were called */ 19092131266d6e53e8f84f8111323036343d72bcb856David Kilroy static int last_irq_jiffy; /* = 0 */ 19102131266d6e53e8f84f8111323036343d72bcb856David Kilroy static int loops_this_jiffy; /* = 0 */ 19111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 19121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (orinoco_lock(priv, &flags) != 0) { 19141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* If hw is unavailable - we don't know if the irq was 19151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * for us or not */ 19161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return IRQ_HANDLED; 19171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 19181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds evstat = hermes_read_regn(hw, EVSTAT); 19201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds events = evstat & hw->inten; 1921a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if (!events) { 19221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds orinoco_unlock(priv, &flags); 19231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return IRQ_NONE; 19241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 19256fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 19261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (jiffies != last_irq_jiffy) 19271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds loops_this_jiffy = 0; 19281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds last_irq_jiffy = jiffies; 19291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (events && count--) { 19311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) { 19321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_WARNING "%s: IRQ handler is looping too " 19331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "much! Resetting.\n", dev->name); 19341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Disable interrupts for now */ 19351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds hermes_set_irqmask(hw, 0); 19361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds schedule_work(&priv->reset_work); 19371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 19381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 19391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Check the card hasn't been removed */ 1941a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy if (!hermes_present(hw)) { 19421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DEBUG(0, "orinoco_interrupt(): card removed\n"); 19431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 19441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 19451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (events & HERMES_EV_TICK) 19471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __orinoco_ev_tick(dev, hw); 19481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (events & HERMES_EV_WTERR) 19491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __orinoco_ev_wterr(dev, hw); 19501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (events & HERMES_EV_INFDROP) 19511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __orinoco_ev_infdrop(dev, hw); 19521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (events & HERMES_EV_INFO) 19531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __orinoco_ev_info(dev, hw); 19541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (events & HERMES_EV_RX) 19551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __orinoco_ev_rx(dev, hw); 19561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (events & HERMES_EV_TXEXC) 19571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __orinoco_ev_txexc(dev, hw); 19581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (events & HERMES_EV_TX) 19591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __orinoco_ev_tx(dev, hw); 19601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (events & HERMES_EV_ALLOC) 19611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __orinoco_ev_alloc(dev, hw); 19626fe9deb1747e1e3b9f626878a9954b9eef8ab17dDavid Kilroy 196384d8a2fb56b1d3c915591a2c1aa321b783c7d00fChristoph Hellwig hermes_write_regn(hw, EVACK, evstat); 19641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds evstat = hermes_read_regn(hw, EVSTAT); 19661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds events = evstat & hw->inten; 19676403eab143205a45a5493166ff8bf7e3646f4a77Joe Perches } 19681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds orinoco_unlock(priv, &flags); 19701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return IRQ_HANDLED; 19711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 19722131266d6e53e8f84f8111323036343d72bcb856David KilroyEXPORT_SYMBOL(orinoco_interrupt); 19731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 197539d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy/* Power management */ 197639d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy/********************************************************************/ 197739d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT) 197839d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroystatic int orinoco_pm_notifier(struct notifier_block *notifier, 197939d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy unsigned long pm_event, 198039d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy void *unused) 198139d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy{ 198239d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy struct orinoco_private *priv = container_of(notifier, 198339d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy struct orinoco_private, 198439d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy pm_notifier); 198539d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy 198639d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy /* All we need to do is cache the firmware before suspend, and 198739d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy * release it when we come out. 198839d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy * 198939d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy * Only need to do this if we're downloading firmware. */ 199039d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy if (!priv->do_fw_download) 199139d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy return NOTIFY_DONE; 199239d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy 199339d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy switch (pm_event) { 199439d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy case PM_HIBERNATION_PREPARE: 199539d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy case PM_SUSPEND_PREPARE: 199639d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy orinoco_cache_fw(priv, 0); 199739d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy break; 199839d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy 199939d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy case PM_POST_RESTORE: 200039d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy /* Restore from hibernation failed. We need to clean 200139d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy * up in exactly the same way, so fall through. */ 200239d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy case PM_POST_HIBERNATION: 200339d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy case PM_POST_SUSPEND: 200439d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy orinoco_uncache_fw(priv); 200539d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy break; 200639d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy 200739d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy case PM_RESTORE_PREPARE: 200839d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy default: 200939d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy break; 201039d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy } 201139d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy 201239d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy return NOTIFY_DONE; 201339d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy} 2014f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller 2015f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Millerstatic void orinoco_register_pm_notifier(struct orinoco_private *priv) 2016f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller{ 2017f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller priv->pm_notifier.notifier_call = orinoco_pm_notifier; 2018f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller register_pm_notifier(&priv->pm_notifier); 2019f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller} 2020f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller 2021f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Millerstatic void orinoco_unregister_pm_notifier(struct orinoco_private *priv) 2022f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller{ 2023f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller unregister_pm_notifier(&priv->pm_notifier); 2024f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller} 202539d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy#else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */ 2026933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin#define orinoco_register_pm_notifier(priv) do { } while (0) 2027933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin#define orinoco_unregister_pm_notifier(priv) do { } while (0) 202839d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy#endif 202939d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy 203039d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy/********************************************************************/ 20311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Initialization */ 20321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 20331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20348e638267a896e171e49fb9013f5baf96a4ede754David Kilroyint orinoco_init(struct orinoco_private *priv) 20351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 20368e638267a896e171e49fb9013f5baf96a4ede754David Kilroy struct device *dev = priv->dev; 2037ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct wiphy *wiphy = priv_to_wiphy(priv); 2038933d594313a5928ffc5325d7bbb6e2383d79622ePavel Roskin struct hermes *hw = &priv->hw; 20391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = 0; 20401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* No need to lock, the hw_unavailable flag is already set in 20421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * alloc_orinocodev() */ 20432c706002fc147decdba2658ea48e4436faca3af2Johannes Berg priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN; 20441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Initialize the firmware */ 2046b42f2074dedef559ecf72dce61a6501f9f9b273aDavid Kilroy err = hw->ops->init(hw); 20471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err != 0) { 20488e638267a896e171e49fb9013f5baf96a4ede754David Kilroy dev_err(dev, "Failed to initialize firmware (err = %d)\n", 20498e638267a896e171e49fb9013f5baf96a4ede754David Kilroy err); 20501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 20511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 20521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20533414fc3f527ce74cfca543c37bcb52c8e63b915eDavid Kilroy err = determine_fw_capabilities(priv, wiphy->fw_version, 20543414fc3f527ce74cfca543c37bcb52c8e63b915eDavid Kilroy sizeof(wiphy->fw_version), 20553414fc3f527ce74cfca543c37bcb52c8e63b915eDavid Kilroy &wiphy->hw_version); 20561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (err != 0) { 20578e638267a896e171e49fb9013f5baf96a4ede754David Kilroy dev_err(dev, "Incompatible firmware, aborting\n"); 20581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 20591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 20601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20613994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy if (priv->do_fw_download) { 206239d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy#ifdef CONFIG_HERMES_CACHE_FW_ON_INIT 20637473431297761fa644a128a497b91e299676f501David Kilroy orinoco_cache_fw(priv, 0); 206439d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy#endif 20657473431297761fa644a128a497b91e299676f501David Kilroy 20663994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy err = orinoco_download(priv); 20673994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy if (err) 20683994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy priv->do_fw_download = 0; 20693994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy 20703994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy /* Check firmware version again */ 20713414fc3f527ce74cfca543c37bcb52c8e63b915eDavid Kilroy err = determine_fw_capabilities(priv, wiphy->fw_version, 20723414fc3f527ce74cfca543c37bcb52c8e63b915eDavid Kilroy sizeof(wiphy->fw_version), 20733414fc3f527ce74cfca543c37bcb52c8e63b915eDavid Kilroy &wiphy->hw_version); 20743994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy if (err != 0) { 20758e638267a896e171e49fb9013f5baf96a4ede754David Kilroy dev_err(dev, "Incompatible firmware, aborting\n"); 20763994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy goto out; 20773994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy } 20783994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy } 20793994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy 20801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (priv->has_port3) 20818e638267a896e171e49fb9013f5baf96a4ede754David Kilroy dev_info(dev, "Ad-hoc demo mode supported\n"); 20821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (priv->has_ibss) 20838e638267a896e171e49fb9013f5baf96a4ede754David Kilroy dev_info(dev, "IEEE standard IBSS ad-hoc mode supported\n"); 20848e638267a896e171e49fb9013f5baf96a4ede754David Kilroy if (priv->has_wep) 20858e638267a896e171e49fb9013f5baf96a4ede754David Kilroy dev_info(dev, "WEP supported, %s-bit key\n", 20868e638267a896e171e49fb9013f5baf96a4ede754David Kilroy priv->has_big_wep ? "104" : "40"); 208723edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy if (priv->has_wpa) { 20888e638267a896e171e49fb9013f5baf96a4ede754David Kilroy dev_info(dev, "WPA-PSK supported\n"); 208923edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy if (orinoco_mic_init(priv)) { 20908e638267a896e171e49fb9013f5baf96a4ede754David Kilroy dev_err(dev, "Failed to setup MIC crypto algorithm. " 20918e638267a896e171e49fb9013f5baf96a4ede754David Kilroy "Disabling WPA support\n"); 209223edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy priv->has_wpa = 0; 209323edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy } 209423edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy } 20951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2096ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy err = orinoco_hw_read_card_settings(priv, wiphy->perm_addr); 2097e9e3d0100eae5f254024bd59229ef1be2b719b84David Kilroy if (err) 20981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto out; 20991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 210042a51b933034bbed93fa54009c96a482044e5b43David Kilroy err = orinoco_hw_allocate_fid(priv); 210137a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin if (err) { 21028e638267a896e171e49fb9013f5baf96a4ede754David Kilroy dev_err(dev, "Failed to allocate NIC buffer!\n"); 210337a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin goto out; 210437a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin } 210537a6c6117db3f10e1923c14dffa089b10600c4b8Pavel Roskin 21061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Set up the default configuration */ 21075217c571c898371c540e49671600d54346b2e123David Kilroy priv->iw_mode = NL80211_IFTYPE_STATION; 21081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* By default use IEEE/IBSS ad-hoc mode if we have it */ 2109a94e8427c8bd358b602288d0b1e0cff83a9401bcDavid Kilroy priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss); 21101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds set_port_type(priv); 2111d51d8b1f249b23a717ae489d6ccf2c25030988e6David Gibson priv->channel = 0; /* use firmware default */ 21121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 21131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->promiscuous = 0; 21145c9f41e285ad60013f0962746192769f899757beDavid Kilroy priv->encode_alg = ORINOCO_ALG_NONE; 21151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->tx_key = 0; 2116d03032af511c56d3c1580fa4f54f6285f650e638David Kilroy priv->wpa_enabled = 0; 2117d03032af511c56d3c1580fa4f54f6285f650e638David Kilroy priv->tkip_cm_active = 0; 2118d03032af511c56d3c1580fa4f54f6285f650e638David Kilroy priv->key_mgmt = 0; 2119d03032af511c56d3c1580fa4f54f6285f650e638David Kilroy priv->wpa_ie_len = 0; 2120d03032af511c56d3c1580fa4f54f6285f650e638David Kilroy priv->wpa_ie = NULL; 21211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2122ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy if (orinoco_wiphy_register(wiphy)) { 2123ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy err = -ENODEV; 2124ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy goto out; 2125ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy } 2126ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy 21271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Make the hardware available, as long as it hasn't been 21281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * removed elsewhere (e.g. by PCMCIA hot unplug) */ 2129bcad6e80f3fb0d6724c3814cf32258bbcf1d67dbDavid Kilroy orinoco_lock_irq(priv); 21301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->hw_unavailable--; 2131bcad6e80f3fb0d6724c3814cf32258bbcf1d67dbDavid Kilroy orinoco_unlock_irq(priv); 21321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 21338e638267a896e171e49fb9013f5baf96a4ede754David Kilroy dev_dbg(dev, "Ready\n"); 21341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 21351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds out: 21361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 21371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 21388e638267a896e171e49fb9013f5baf96a4ede754David KilroyEXPORT_SYMBOL(orinoco_init); 21391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 214089ea40905fb48e2bf92211b57ab6be51c0797657Andrey Borzenkovstatic const struct net_device_ops orinoco_netdev_ops = { 214189ea40905fb48e2bf92211b57ab6be51c0797657Andrey Borzenkov .ndo_open = orinoco_open, 214289ea40905fb48e2bf92211b57ab6be51c0797657Andrey Borzenkov .ndo_stop = orinoco_stop, 214389ea40905fb48e2bf92211b57ab6be51c0797657Andrey Borzenkov .ndo_start_xmit = orinoco_xmit, 2144afc4b13df143122f99a0eb10bfefb216c2806de0Jiri Pirko .ndo_set_rx_mode = orinoco_set_multicast_list, 214589ea40905fb48e2bf92211b57ab6be51c0797657Andrey Borzenkov .ndo_change_mtu = orinoco_change_mtu, 2146240c102d9c54fee7fdc87a4ef2fabc7eb539e00aBen Hutchings .ndo_set_mac_address = eth_mac_addr, 2147240c102d9c54fee7fdc87a4ef2fabc7eb539e00aBen Hutchings .ndo_validate_addr = eth_validate_addr, 214889ea40905fb48e2bf92211b57ab6be51c0797657Andrey Borzenkov .ndo_tx_timeout = orinoco_tx_timeout, 214989ea40905fb48e2bf92211b57ab6be51c0797657Andrey Borzenkov .ndo_get_stats = orinoco_get_stats, 215089ea40905fb48e2bf92211b57ab6be51c0797657Andrey Borzenkov}; 215189ea40905fb48e2bf92211b57ab6be51c0797657Andrey Borzenkov 2152ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy/* Allocate private data. 2153ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * 2154ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * This driver has a number of structures associated with it 2155ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * netdev - Net device structure for each network interface 2156ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * wiphy - structure associated with wireless phy 2157ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * wireless_dev (wdev) - structure for each wireless interface 2158ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * hw - structure for hermes chip info 2159ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * card - card specific structure for use by the card driver 2160ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * (airport, orinoco_cs) 2161ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * priv - orinoco private data 2162ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * device - generic linux device structure 2163ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * 2164ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * +---------+ +---------+ 2165ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * | wiphy | | netdev | 2166ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * | +-------+ | +-------+ 2167ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * | | priv | | | wdev | 2168ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * | | +-----+ +-+-------+ 2169ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * | | | hw | 2170ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * | +-+-----+ 2171ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * | | card | 2172ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * +-+-------+ 2173ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * 2174ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * priv has a link to netdev and device 2175ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * wdev has a link to wiphy 2176ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy */ 2177a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroystruct orinoco_private 21783994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy*alloc_orinocodev(int sizeof_card, 21793994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy struct device *device, 21803994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy int (*hard_reset)(struct orinoco_private *), 21813994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy int (*stop_fw)(struct orinoco_private *, int)) 21821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 21831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct orinoco_private *priv; 2184ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct wiphy *wiphy; 2185ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy 2186ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy /* allocate wiphy 2187ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * NOTE: We only support a single virtual interface 2188ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy * but this may change when monitor mode is added 2189ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy */ 2190ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy wiphy = wiphy_new(&orinoco_cfg_ops, 2191ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy sizeof(struct orinoco_private) + sizeof_card); 2192ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy if (!wiphy) 2193ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy return NULL; 21941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2195ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy priv = wiphy_priv(wiphy); 21965381956b780e82805247c2ec8e32c4c665309394David Kilroy priv->dev = device; 2197ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy 21981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (sizeof_card) 219984d8a2fb56b1d3c915591a2c1aa321b783c7d00fChristoph Hellwig priv->card = (void *)((unsigned long)priv 22001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds + sizeof(struct orinoco_private)); 22011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 22021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->card = NULL; 22031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2204ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy orinoco_wiphy_init(wiphy); 2205ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy 2206343c686c04eec556645f251f7d6c9b3d7335dae0Pavel Roskin#ifdef WIRELESS_SPY 2207343c686c04eec556645f251f7d6c9b3d7335dae0Pavel Roskin priv->wireless_data.spy_data = &priv->spy_data; 2208343c686c04eec556645f251f7d6c9b3d7335dae0Pavel Roskin#endif 220923edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy 22101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Set up default callbacks */ 22111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->hard_reset = hard_reset; 22123994d502017a2239e30152d1231843ad05d04a7bDavid Kilroy priv->stop_fw = stop_fw; 22131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_init(&priv->lock); 22151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->open = 0; 22161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->hw_unavailable = 1; /* orinoco_init() must clear this 22171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * before anything else touches the 22181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * hardware */ 2219c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells INIT_WORK(&priv->reset_work, orinoco_reset); 2220c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells INIT_WORK(&priv->join_work, orinoco_join_ap); 2221c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells INIT_WORK(&priv->wevent_work, orinoco_send_wevents); 22221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 222331afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy INIT_LIST_HEAD(&priv->rx_list); 222431afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet, 22255381956b780e82805247c2ec8e32c4c665309394David Kilroy (unsigned long) priv); 222631afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy 2227c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy spin_lock_init(&priv->scan_lock); 2228c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy INIT_LIST_HEAD(&priv->scan_list); 2229c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy INIT_WORK(&priv->process_scan, orinoco_process_scan_results); 2230c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 22311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->last_linkstatus = 0xffff; 22321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22332bfc5cb57b55ed2204bca7668e082f7bf485760aAndrey Borzenkov#if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP) 22342cea7b261942009e90befbe41d998e2931547026David Kilroy priv->cached_pri_fw = NULL; 22354fb30784c720b863203957f76e3fde0d53932746Andrey Borzenkov priv->cached_fw = NULL; 22362bfc5cb57b55ed2204bca7668e082f7bf485760aAndrey Borzenkov#endif 22374fb30784c720b863203957f76e3fde0d53932746Andrey Borzenkov 223839d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy /* Register PM notifiers */ 2239f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller orinoco_register_pm_notifier(priv); 224039d1ffee57c7ce02c90ec8e9272df8aa8ddf600fDavid Kilroy 2241a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroy return priv; 22421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 22432131266d6e53e8f84f8111323036343d72bcb856David KilroyEXPORT_SYMBOL(alloc_orinocodev); 22441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22455381956b780e82805247c2ec8e32c4c665309394David Kilroy/* We can only support a single interface. We provide a separate 22465381956b780e82805247c2ec8e32c4c665309394David Kilroy * function to set it up to distinguish between hardware 22475381956b780e82805247c2ec8e32c4c665309394David Kilroy * initialisation and interface setup. 22485381956b780e82805247c2ec8e32c4c665309394David Kilroy * 22495381956b780e82805247c2ec8e32c4c665309394David Kilroy * The base_addr and irq parameters are passed on to netdev for use 22505381956b780e82805247c2ec8e32c4c665309394David Kilroy * with SIOCGIFMAP. 22515381956b780e82805247c2ec8e32c4c665309394David Kilroy */ 22525381956b780e82805247c2ec8e32c4c665309394David Kilroyint orinoco_if_add(struct orinoco_private *priv, 22535381956b780e82805247c2ec8e32c4c665309394David Kilroy unsigned long base_addr, 2254593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroy unsigned int irq, 2255593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroy const struct net_device_ops *ops) 22565381956b780e82805247c2ec8e32c4c665309394David Kilroy{ 22575381956b780e82805247c2ec8e32c4c665309394David Kilroy struct wiphy *wiphy = priv_to_wiphy(priv); 22585381956b780e82805247c2ec8e32c4c665309394David Kilroy struct wireless_dev *wdev; 22595381956b780e82805247c2ec8e32c4c665309394David Kilroy struct net_device *dev; 22605381956b780e82805247c2ec8e32c4c665309394David Kilroy int ret; 22615381956b780e82805247c2ec8e32c4c665309394David Kilroy 22625381956b780e82805247c2ec8e32c4c665309394David Kilroy dev = alloc_etherdev(sizeof(struct wireless_dev)); 22635381956b780e82805247c2ec8e32c4c665309394David Kilroy 22645381956b780e82805247c2ec8e32c4c665309394David Kilroy if (!dev) 22655381956b780e82805247c2ec8e32c4c665309394David Kilroy return -ENOMEM; 22665381956b780e82805247c2ec8e32c4c665309394David Kilroy 22675381956b780e82805247c2ec8e32c4c665309394David Kilroy /* Initialise wireless_dev */ 22685381956b780e82805247c2ec8e32c4c665309394David Kilroy wdev = netdev_priv(dev); 22695381956b780e82805247c2ec8e32c4c665309394David Kilroy wdev->wiphy = wiphy; 22705381956b780e82805247c2ec8e32c4c665309394David Kilroy wdev->iftype = NL80211_IFTYPE_STATION; 22715381956b780e82805247c2ec8e32c4c665309394David Kilroy 22725381956b780e82805247c2ec8e32c4c665309394David Kilroy /* Setup / override net_device fields */ 22735381956b780e82805247c2ec8e32c4c665309394David Kilroy dev->ieee80211_ptr = wdev; 22745381956b780e82805247c2ec8e32c4c665309394David Kilroy dev->watchdog_timeo = HZ; /* 1 second timeout */ 22755381956b780e82805247c2ec8e32c4c665309394David Kilroy dev->wireless_handlers = &orinoco_handler_def; 22765381956b780e82805247c2ec8e32c4c665309394David Kilroy#ifdef WIRELESS_SPY 22775381956b780e82805247c2ec8e32c4c665309394David Kilroy dev->wireless_data = &priv->wireless_data; 22785381956b780e82805247c2ec8e32c4c665309394David Kilroy#endif 2279593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroy /* Default to standard ops if not set */ 2280593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroy if (ops) 2281593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroy dev->netdev_ops = ops; 2282593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroy else 2283593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroy dev->netdev_ops = &orinoco_netdev_ops; 2284593ef09c9e70c92c0d76c67a1c03a5d44d3aec82David Kilroy 22855381956b780e82805247c2ec8e32c4c665309394David Kilroy /* we use the default eth_mac_addr for setting the MAC addr */ 22865381956b780e82805247c2ec8e32c4c665309394David Kilroy 22875381956b780e82805247c2ec8e32c4c665309394David Kilroy /* Reserve space in skb for the SNAP header */ 2288bac6fafd4d6a0af26aeb37277a39607f7ce0be77David Kilroy dev->needed_headroom = ENCAPS_OVERHEAD; 22895381956b780e82805247c2ec8e32c4c665309394David Kilroy 22905381956b780e82805247c2ec8e32c4c665309394David Kilroy netif_carrier_off(dev); 22915381956b780e82805247c2ec8e32c4c665309394David Kilroy 22925381956b780e82805247c2ec8e32c4c665309394David Kilroy memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN); 2293cf32ed92432303022be208bb6a173994712f1f23John W. Linville memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN); 22945381956b780e82805247c2ec8e32c4c665309394David Kilroy 22955381956b780e82805247c2ec8e32c4c665309394David Kilroy dev->base_addr = base_addr; 22965381956b780e82805247c2ec8e32c4c665309394David Kilroy dev->irq = irq; 22975381956b780e82805247c2ec8e32c4c665309394David Kilroy 22985381956b780e82805247c2ec8e32c4c665309394David Kilroy SET_NETDEV_DEV(dev, priv->dev); 22995381956b780e82805247c2ec8e32c4c665309394David Kilroy ret = register_netdev(dev); 23005381956b780e82805247c2ec8e32c4c665309394David Kilroy if (ret) 23015381956b780e82805247c2ec8e32c4c665309394David Kilroy goto fail; 23025381956b780e82805247c2ec8e32c4c665309394David Kilroy 23035381956b780e82805247c2ec8e32c4c665309394David Kilroy priv->ndev = dev; 23045381956b780e82805247c2ec8e32c4c665309394David Kilroy 23055381956b780e82805247c2ec8e32c4c665309394David Kilroy /* Report what we've done */ 23065381956b780e82805247c2ec8e32c4c665309394David Kilroy dev_dbg(priv->dev, "Registerred interface %s.\n", dev->name); 23075381956b780e82805247c2ec8e32c4c665309394David Kilroy 23085381956b780e82805247c2ec8e32c4c665309394David Kilroy return 0; 23095381956b780e82805247c2ec8e32c4c665309394David Kilroy 23105381956b780e82805247c2ec8e32c4c665309394David Kilroy fail: 23115381956b780e82805247c2ec8e32c4c665309394David Kilroy free_netdev(dev); 23125381956b780e82805247c2ec8e32c4c665309394David Kilroy return ret; 23135381956b780e82805247c2ec8e32c4c665309394David Kilroy} 23145381956b780e82805247c2ec8e32c4c665309394David KilroyEXPORT_SYMBOL(orinoco_if_add); 23155381956b780e82805247c2ec8e32c4c665309394David Kilroy 23165381956b780e82805247c2ec8e32c4c665309394David Kilroyvoid orinoco_if_del(struct orinoco_private *priv) 23171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2318a2608362b22ade22ef5472a8c9b82687d86f976fDavid Kilroy struct net_device *dev = priv->ndev; 23195381956b780e82805247c2ec8e32c4c665309394David Kilroy 23205381956b780e82805247c2ec8e32c4c665309394David Kilroy unregister_netdev(dev); 23215381956b780e82805247c2ec8e32c4c665309394David Kilroy free_netdev(dev); 23225381956b780e82805247c2ec8e32c4c665309394David Kilroy} 23235381956b780e82805247c2ec8e32c4c665309394David KilroyEXPORT_SYMBOL(orinoco_if_del); 23245381956b780e82805247c2ec8e32c4c665309394David Kilroy 23255381956b780e82805247c2ec8e32c4c665309394David Kilroyvoid free_orinocodev(struct orinoco_private *priv) 23265381956b780e82805247c2ec8e32c4c665309394David Kilroy{ 2327ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy struct wiphy *wiphy = priv_to_wiphy(priv); 232820953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy struct orinoco_rx_data *rx_data, *temp; 2329c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy struct orinoco_scan_data *sd, *sdtemp; 233095dd91fbd8d3c788ef93bc94b4b600889e04dba1Christoph Hellwig 2331ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy wiphy_unregister(wiphy); 2332ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy 233320953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy /* If the tasklet is scheduled when we call tasklet_kill it 233420953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy * will run one final time. However the tasklet will only 233520953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy * drain priv->rx_list if the hw is still available. */ 233631afcef385bb8bf528c6fbe05b359af9f456f02aDavid Kilroy tasklet_kill(&priv->rx_tasklet); 23377473431297761fa644a128a497b91e299676f501David Kilroy 233820953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy /* Explicitly drain priv->rx_list */ 233920953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) { 234020953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy list_del(&rx_data->list); 234120953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy 234220953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy dev_kfree_skb(rx_data->skb); 234320953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy kfree(rx_data->desc); 234420953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy kfree(rx_data); 234520953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy } 234620953ad68ee522f6420b63c200ac9b23f96d937aDavid Kilroy 2347c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy cancel_work_sync(&priv->process_scan); 2348c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy /* Explicitly drain priv->scan_list */ 2349c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy list_for_each_entry_safe(sd, sdtemp, &priv->scan_list, list) { 2350c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy list_del(&sd->list); 2351c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 2352c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy if ((sd->len > 0) && sd->buf) 2353c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy kfree(sd->buf); 2354c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy kfree(sd); 2355c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy } 2356c63cdbe8f80487c372fe0dfe460ed30467029f01David Kilroy 2357f11c179eea77b8afc2fb7cb4b9a8815b85e3c16fDavid S. Miller orinoco_unregister_pm_notifier(priv); 23587473431297761fa644a128a497b91e299676f501David Kilroy orinoco_uncache_fw(priv); 23597473431297761fa644a128a497b91e299676f501David Kilroy 2360d03032af511c56d3c1580fa4f54f6285f650e638David Kilroy priv->wpa_ie_len = 0; 2361d03032af511c56d3c1580fa4f54f6285f650e638David Kilroy kfree(priv->wpa_ie); 236223edcc4147ad36f8d55f0eb79c21e245ffb9f211David Kilroy orinoco_mic_free(priv); 2363ea60a6aaf55984a13a7150568cc103d006e86ab2David Kilroy wiphy_free(wiphy); 23641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 23652131266d6e53e8f84f8111323036343d72bcb856David KilroyEXPORT_SYMBOL(free_orinocodev); 23661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 23676415f7df10573bf1ec42644f42bef565127114a1David Kilroyint orinoco_up(struct orinoco_private *priv) 23686415f7df10573bf1ec42644f42bef565127114a1David Kilroy{ 23696415f7df10573bf1ec42644f42bef565127114a1David Kilroy struct net_device *dev = priv->ndev; 23706415f7df10573bf1ec42644f42bef565127114a1David Kilroy unsigned long flags; 23716415f7df10573bf1ec42644f42bef565127114a1David Kilroy int err; 23726415f7df10573bf1ec42644f42bef565127114a1David Kilroy 2373bcad6e80f3fb0d6724c3814cf32258bbcf1d67dbDavid Kilroy priv->hw.ops->lock_irqsave(&priv->lock, &flags); 23746415f7df10573bf1ec42644f42bef565127114a1David Kilroy 23756415f7df10573bf1ec42644f42bef565127114a1David Kilroy err = orinoco_reinit_firmware(priv); 23766415f7df10573bf1ec42644f42bef565127114a1David Kilroy if (err) { 23776415f7df10573bf1ec42644f42bef565127114a1David Kilroy printk(KERN_ERR "%s: Error %d re-initializing firmware\n", 23786415f7df10573bf1ec42644f42bef565127114a1David Kilroy dev->name, err); 23796415f7df10573bf1ec42644f42bef565127114a1David Kilroy goto exit; 23806415f7df10573bf1ec42644f42bef565127114a1David Kilroy } 23816415f7df10573bf1ec42644f42bef565127114a1David Kilroy 23826415f7df10573bf1ec42644f42bef565127114a1David Kilroy netif_device_attach(dev); 23836415f7df10573bf1ec42644f42bef565127114a1David Kilroy priv->hw_unavailable--; 23846415f7df10573bf1ec42644f42bef565127114a1David Kilroy 23856415f7df10573bf1ec42644f42bef565127114a1David Kilroy if (priv->open && !priv->hw_unavailable) { 23866415f7df10573bf1ec42644f42bef565127114a1David Kilroy err = __orinoco_up(priv); 23876415f7df10573bf1ec42644f42bef565127114a1David Kilroy if (err) 23886415f7df10573bf1ec42644f42bef565127114a1David Kilroy printk(KERN_ERR "%s: Error %d restarting card\n", 23896415f7df10573bf1ec42644f42bef565127114a1David Kilroy dev->name, err); 23906415f7df10573bf1ec42644f42bef565127114a1David Kilroy } 23916415f7df10573bf1ec42644f42bef565127114a1David Kilroy 23926415f7df10573bf1ec42644f42bef565127114a1David Kilroyexit: 2393bcad6e80f3fb0d6724c3814cf32258bbcf1d67dbDavid Kilroy priv->hw.ops->unlock_irqrestore(&priv->lock, &flags); 23946415f7df10573bf1ec42644f42bef565127114a1David Kilroy 23956415f7df10573bf1ec42644f42bef565127114a1David Kilroy return 0; 23966415f7df10573bf1ec42644f42bef565127114a1David Kilroy} 23976415f7df10573bf1ec42644f42bef565127114a1David KilroyEXPORT_SYMBOL(orinoco_up); 23986415f7df10573bf1ec42644f42bef565127114a1David Kilroy 23996415f7df10573bf1ec42644f42bef565127114a1David Kilroyvoid orinoco_down(struct orinoco_private *priv) 24006415f7df10573bf1ec42644f42bef565127114a1David Kilroy{ 24016415f7df10573bf1ec42644f42bef565127114a1David Kilroy struct net_device *dev = priv->ndev; 24026415f7df10573bf1ec42644f42bef565127114a1David Kilroy unsigned long flags; 24036415f7df10573bf1ec42644f42bef565127114a1David Kilroy int err; 24046415f7df10573bf1ec42644f42bef565127114a1David Kilroy 2405bcad6e80f3fb0d6724c3814cf32258bbcf1d67dbDavid Kilroy priv->hw.ops->lock_irqsave(&priv->lock, &flags); 24066415f7df10573bf1ec42644f42bef565127114a1David Kilroy err = __orinoco_down(priv); 24076415f7df10573bf1ec42644f42bef565127114a1David Kilroy if (err) 24086415f7df10573bf1ec42644f42bef565127114a1David Kilroy printk(KERN_WARNING "%s: Error %d downing interface\n", 24096415f7df10573bf1ec42644f42bef565127114a1David Kilroy dev->name, err); 24106415f7df10573bf1ec42644f42bef565127114a1David Kilroy 24116415f7df10573bf1ec42644f42bef565127114a1David Kilroy netif_device_detach(dev); 24126415f7df10573bf1ec42644f42bef565127114a1David Kilroy priv->hw_unavailable++; 2413bcad6e80f3fb0d6724c3814cf32258bbcf1d67dbDavid Kilroy priv->hw.ops->unlock_irqrestore(&priv->lock, &flags); 24146415f7df10573bf1ec42644f42bef565127114a1David Kilroy} 24156415f7df10573bf1ec42644f42bef565127114a1David KilroyEXPORT_SYMBOL(orinoco_down); 24166415f7df10573bf1ec42644f42bef565127114a1David Kilroy 24171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 24181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Module initialization */ 24191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/********************************************************************/ 24201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 24211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Can't be declared "const" or the whole __initdata section will 24221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * become const */ 24231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION 24241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds " (David Gibson <hermes@gibson.dropbear.id.au>, " 24251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "Pavel Roskin <proski@gnu.org>, et al)"; 24261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 24271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int __init init_orinoco(void) 24281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 24291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_DEBUG "%s\n", version); 24301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 24311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 24321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 24331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __exit exit_orinoco(void) 24341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 24351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 24361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 24371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_init(init_orinoco); 24381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_exit(exit_orinoco); 2439