main.c 65 KB

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