main.c 72 KB

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