hostap_hw.c 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446
  1. /*
  2. * Host AP (software wireless LAN access point) driver for
  3. * Intersil Prism2/2.5/3.
  4. *
  5. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  6. * <jkmaline@cc.hut.fi>
  7. * Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation. See README and COPYING for
  12. * more details.
  13. *
  14. * FIX:
  15. * - there is currently no way of associating TX packets to correct wds device
  16. * when TX Exc/OK event occurs, so all tx_packets and some
  17. * tx_errors/tx_dropped are added to the main netdevice; using sw_support
  18. * field in txdesc might be used to fix this (using Alloc event to increment
  19. * tx_packets would need some further info in txfid table)
  20. *
  21. * Buffer Access Path (BAP) usage:
  22. * Prism2 cards have two separate BAPs for accessing the card memory. These
  23. * should allow concurrent access to two different frames and the driver
  24. * previously used BAP0 for sending data and BAP1 for receiving data.
  25. * However, there seems to be number of issues with concurrent access and at
  26. * least one know hardware bug in using BAP0 and BAP1 concurrently with PCI
  27. * Prism2.5. Therefore, the driver now only uses BAP0 for moving data between
  28. * host and card memories. BAP0 accesses are protected with local->baplock
  29. * (spin_lock_bh) to prevent concurrent use.
  30. */
  31. #include <linux/config.h>
  32. #include <linux/version.h>
  33. #include <asm/delay.h>
  34. #include <asm/uaccess.h>
  35. #include <linux/slab.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/proc_fs.h>
  39. #include <linux/if_arp.h>
  40. #include <linux/delay.h>
  41. #include <linux/random.h>
  42. #include <linux/wait.h>
  43. #include <linux/sched.h>
  44. #include <linux/rtnetlink.h>
  45. #include <linux/wireless.h>
  46. #include <net/iw_handler.h>
  47. #include <net/ieee80211.h>
  48. #include <net/ieee80211_crypt.h>
  49. #include <asm/irq.h>
  50. #include "hostap_80211.h"
  51. #include "hostap.h"
  52. #include "hostap_ap.h"
  53. /* #define final_version */
  54. static int mtu = 1500;
  55. module_param(mtu, int, 0444);
  56. MODULE_PARM_DESC(mtu, "Maximum transfer unit");
  57. static int channel[MAX_PARM_DEVICES] = { 3, DEF_INTS };
  58. module_param_array(channel, int, NULL, 0444);
  59. MODULE_PARM_DESC(channel, "Initial channel");
  60. static char essid[33] = "test";
  61. module_param_string(essid, essid, sizeof(essid), 0444);
  62. MODULE_PARM_DESC(essid, "Host AP's ESSID");
  63. static int iw_mode[MAX_PARM_DEVICES] = { IW_MODE_MASTER, DEF_INTS };
  64. module_param_array(iw_mode, int, NULL, 0444);
  65. MODULE_PARM_DESC(iw_mode, "Initial operation mode");
  66. static int beacon_int[MAX_PARM_DEVICES] = { 100, DEF_INTS };
  67. module_param_array(beacon_int, int, NULL, 0444);
  68. MODULE_PARM_DESC(beacon_int, "Beacon interval (1 = 1024 usec)");
  69. static int dtim_period[MAX_PARM_DEVICES] = { 1, DEF_INTS };
  70. module_param_array(dtim_period, int, NULL, 0444);
  71. MODULE_PARM_DESC(dtim_period, "DTIM period");
  72. static char dev_template[16] = "wlan%d";
  73. module_param_string(dev_template, dev_template, sizeof(dev_template), 0444);
  74. MODULE_PARM_DESC(dev_template, "Prefix for network device name (default: "
  75. "wlan%d)");
  76. #ifdef final_version
  77. #define EXTRA_EVENTS_WTERR 0
  78. #else
  79. /* check WTERR events (Wait Time-out) in development versions */
  80. #define EXTRA_EVENTS_WTERR HFA384X_EV_WTERR
  81. #endif
  82. /* Events that will be using BAP0 */
  83. #define HFA384X_BAP0_EVENTS \
  84. (HFA384X_EV_TXEXC | HFA384X_EV_RX | HFA384X_EV_INFO | HFA384X_EV_TX)
  85. /* event mask, i.e., events that will result in an interrupt */
  86. #define HFA384X_EVENT_MASK \
  87. (HFA384X_BAP0_EVENTS | HFA384X_EV_ALLOC | HFA384X_EV_INFDROP | \
  88. HFA384X_EV_CMD | HFA384X_EV_TICK | \
  89. EXTRA_EVENTS_WTERR)
  90. /* Default TX control flags: use 802.11 headers and request interrupt for
  91. * failed transmits. Frames that request ACK callback, will add
  92. * _TX_OK flag and _ALT_RTRY flag may be used to select different retry policy.
  93. */
  94. #define HFA384X_TX_CTRL_FLAGS \
  95. (HFA384X_TX_CTRL_802_11 | HFA384X_TX_CTRL_TX_EX)
  96. /* ca. 1 usec */
  97. #define HFA384X_CMD_BUSY_TIMEOUT 5000
  98. #define HFA384X_BAP_BUSY_TIMEOUT 50000
  99. /* ca. 10 usec */
  100. #define HFA384X_CMD_COMPL_TIMEOUT 20000
  101. #define HFA384X_DL_COMPL_TIMEOUT 1000000
  102. /* Wait times for initialization; yield to other processes to avoid busy
  103. * waiting for long time. */
  104. #define HFA384X_INIT_TIMEOUT (HZ / 2) /* 500 ms */
  105. #define HFA384X_ALLOC_COMPL_TIMEOUT (HZ / 20) /* 50 ms */
  106. static void prism2_hw_reset(struct net_device *dev);
  107. static void prism2_check_sta_fw_version(local_info_t *local);
  108. #ifdef PRISM2_DOWNLOAD_SUPPORT
  109. /* hostap_download.c */
  110. static int prism2_download_aux_dump(struct net_device *dev,
  111. unsigned int addr, int len, u8 *buf);
  112. static u8 * prism2_read_pda(struct net_device *dev);
  113. static int prism2_download(local_info_t *local,
  114. struct prism2_download_param *param);
  115. static void prism2_download_free_data(struct prism2_download_data *dl);
  116. static int prism2_download_volatile(local_info_t *local,
  117. struct prism2_download_data *param);
  118. static int prism2_download_genesis(local_info_t *local,
  119. struct prism2_download_data *param);
  120. static int prism2_get_ram_size(local_info_t *local);
  121. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  122. #ifndef final_version
  123. /* magic value written to SWSUPPORT0 reg. for detecting whether card is still
  124. * present */
  125. #define HFA384X_MAGIC 0x8A32
  126. #endif
  127. static u16 hfa384x_read_reg(struct net_device *dev, u16 reg)
  128. {
  129. return HFA384X_INW(reg);
  130. }
  131. static void hfa384x_read_regs(struct net_device *dev,
  132. struct hfa384x_regs *regs)
  133. {
  134. regs->cmd = HFA384X_INW(HFA384X_CMD_OFF);
  135. regs->evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
  136. regs->offset0 = HFA384X_INW(HFA384X_OFFSET0_OFF);
  137. regs->offset1 = HFA384X_INW(HFA384X_OFFSET1_OFF);
  138. regs->swsupport0 = HFA384X_INW(HFA384X_SWSUPPORT0_OFF);
  139. }
  140. /**
  141. * __hostap_cmd_queue_free - Free Prism2 command queue entry (private)
  142. * @local: pointer to private Host AP driver data
  143. * @entry: Prism2 command queue entry to be freed
  144. * @del_req: request the entry to be removed
  145. *
  146. * Internal helper function for freeing Prism2 command queue entries.
  147. * Caller must have acquired local->cmdlock before calling this function.
  148. */
  149. static inline void __hostap_cmd_queue_free(local_info_t *local,
  150. struct hostap_cmd_queue *entry,
  151. int del_req)
  152. {
  153. if (del_req) {
  154. entry->del_req = 1;
  155. if (!list_empty(&entry->list)) {
  156. list_del_init(&entry->list);
  157. local->cmd_queue_len--;
  158. }
  159. }
  160. if (atomic_dec_and_test(&entry->usecnt) && entry->del_req)
  161. kfree(entry);
  162. }
  163. /**
  164. * hostap_cmd_queue_free - Free Prism2 command queue entry
  165. * @local: pointer to private Host AP driver data
  166. * @entry: Prism2 command queue entry to be freed
  167. * @del_req: request the entry to be removed
  168. *
  169. * Free a Prism2 command queue entry.
  170. */
  171. static inline void hostap_cmd_queue_free(local_info_t *local,
  172. struct hostap_cmd_queue *entry,
  173. int del_req)
  174. {
  175. unsigned long flags;
  176. spin_lock_irqsave(&local->cmdlock, flags);
  177. __hostap_cmd_queue_free(local, entry, del_req);
  178. spin_unlock_irqrestore(&local->cmdlock, flags);
  179. }
  180. /**
  181. * prism2_clear_cmd_queue - Free all pending Prism2 command queue entries
  182. * @local: pointer to private Host AP driver data
  183. */
  184. static void prism2_clear_cmd_queue(local_info_t *local)
  185. {
  186. struct list_head *ptr, *n;
  187. unsigned long flags;
  188. struct hostap_cmd_queue *entry;
  189. spin_lock_irqsave(&local->cmdlock, flags);
  190. list_for_each_safe(ptr, n, &local->cmd_queue) {
  191. entry = list_entry(ptr, struct hostap_cmd_queue, list);
  192. atomic_inc(&entry->usecnt);
  193. printk(KERN_DEBUG "%s: removed pending cmd_queue entry "
  194. "(type=%d, cmd=0x%04x, param0=0x%04x)\n",
  195. local->dev->name, entry->type, entry->cmd,
  196. entry->param0);
  197. __hostap_cmd_queue_free(local, entry, 1);
  198. }
  199. if (local->cmd_queue_len) {
  200. /* This should not happen; print debug message and clear
  201. * queue length. */
  202. printk(KERN_DEBUG "%s: cmd_queue_len (%d) not zero after "
  203. "flush\n", local->dev->name, local->cmd_queue_len);
  204. local->cmd_queue_len = 0;
  205. }
  206. spin_unlock_irqrestore(&local->cmdlock, flags);
  207. }
  208. /**
  209. * hfa384x_cmd_issue - Issue a Prism2 command to the hardware
  210. * @dev: pointer to net_device
  211. * @entry: Prism2 command queue entry to be issued
  212. */
  213. static inline int hfa384x_cmd_issue(struct net_device *dev,
  214. struct hostap_cmd_queue *entry)
  215. {
  216. struct hostap_interface *iface;
  217. local_info_t *local;
  218. int tries;
  219. u16 reg;
  220. unsigned long flags;
  221. iface = netdev_priv(dev);
  222. local = iface->local;
  223. if (local->func->card_present && !local->func->card_present(local))
  224. return -ENODEV;
  225. if (entry->issued) {
  226. printk(KERN_DEBUG "%s: driver bug - re-issuing command @%p\n",
  227. dev->name, entry);
  228. }
  229. /* wait until busy bit is clear; this should always be clear since the
  230. * commands are serialized */
  231. tries = HFA384X_CMD_BUSY_TIMEOUT;
  232. while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
  233. tries--;
  234. udelay(1);
  235. }
  236. #ifndef final_version
  237. if (tries != HFA384X_CMD_BUSY_TIMEOUT) {
  238. prism2_io_debug_error(dev, 1);
  239. printk(KERN_DEBUG "%s: hfa384x_cmd_issue: cmd reg was busy "
  240. "for %d usec\n", dev->name,
  241. HFA384X_CMD_BUSY_TIMEOUT - tries);
  242. }
  243. #endif
  244. if (tries == 0) {
  245. reg = HFA384X_INW(HFA384X_CMD_OFF);
  246. prism2_io_debug_error(dev, 2);
  247. printk(KERN_DEBUG "%s: hfa384x_cmd_issue - timeout - "
  248. "reg=0x%04x\n", dev->name, reg);
  249. return -ETIMEDOUT;
  250. }
  251. /* write command */
  252. spin_lock_irqsave(&local->cmdlock, flags);
  253. HFA384X_OUTW(entry->param0, HFA384X_PARAM0_OFF);
  254. HFA384X_OUTW(entry->param1, HFA384X_PARAM1_OFF);
  255. HFA384X_OUTW(entry->cmd, HFA384X_CMD_OFF);
  256. entry->issued = 1;
  257. spin_unlock_irqrestore(&local->cmdlock, flags);
  258. return 0;
  259. }
  260. /**
  261. * hfa384x_cmd - Issue a Prism2 command and wait (sleep) for completion
  262. * @dev: pointer to net_device
  263. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  264. * @param0: value for Param0 register
  265. * @param1: value for Param1 register (pointer; %NULL if not used)
  266. * @resp0: pointer for Resp0 data or %NULL if Resp0 is not needed
  267. *
  268. * Issue given command (possibly after waiting in command queue) and sleep
  269. * until the command is completed (or timed out or interrupted). This can be
  270. * called only from user process context.
  271. */
  272. static int hfa384x_cmd(struct net_device *dev, u16 cmd, u16 param0,
  273. u16 *param1, u16 *resp0)
  274. {
  275. struct hostap_interface *iface;
  276. local_info_t *local;
  277. int err, res, issue, issued = 0;
  278. unsigned long flags;
  279. struct hostap_cmd_queue *entry;
  280. DECLARE_WAITQUEUE(wait, current);
  281. iface = netdev_priv(dev);
  282. local = iface->local;
  283. if (in_interrupt()) {
  284. printk(KERN_DEBUG "%s: hfa384x_cmd called from interrupt "
  285. "context\n", dev->name);
  286. return -1;
  287. }
  288. if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN) {
  289. printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
  290. dev->name);
  291. return -1;
  292. }
  293. if (signal_pending(current))
  294. return -EINTR;
  295. entry = (struct hostap_cmd_queue *)
  296. kmalloc(sizeof(*entry), GFP_ATOMIC);
  297. if (entry == NULL) {
  298. printk(KERN_DEBUG "%s: hfa384x_cmd - kmalloc failed\n",
  299. dev->name);
  300. return -ENOMEM;
  301. }
  302. memset(entry, 0, sizeof(*entry));
  303. atomic_set(&entry->usecnt, 1);
  304. entry->type = CMD_SLEEP;
  305. entry->cmd = cmd;
  306. entry->param0 = param0;
  307. if (param1)
  308. entry->param1 = *param1;
  309. init_waitqueue_head(&entry->compl);
  310. /* prepare to wait for command completion event, but do not sleep yet
  311. */
  312. add_wait_queue(&entry->compl, &wait);
  313. set_current_state(TASK_INTERRUPTIBLE);
  314. spin_lock_irqsave(&local->cmdlock, flags);
  315. issue = list_empty(&local->cmd_queue);
  316. if (issue)
  317. entry->issuing = 1;
  318. list_add_tail(&entry->list, &local->cmd_queue);
  319. local->cmd_queue_len++;
  320. spin_unlock_irqrestore(&local->cmdlock, flags);
  321. err = 0;
  322. if (!issue)
  323. goto wait_completion;
  324. if (signal_pending(current))
  325. err = -EINTR;
  326. if (!err) {
  327. if (hfa384x_cmd_issue(dev, entry))
  328. err = -ETIMEDOUT;
  329. else
  330. issued = 1;
  331. }
  332. wait_completion:
  333. if (!err && entry->type != CMD_COMPLETED) {
  334. /* sleep until command is completed or timed out */
  335. res = schedule_timeout(2 * HZ);
  336. } else
  337. res = -1;
  338. if (!err && signal_pending(current))
  339. err = -EINTR;
  340. if (err && issued) {
  341. /* the command was issued, so a CmdCompl event should occur
  342. * soon; however, there's a pending signal and
  343. * schedule_timeout() would be interrupted; wait a short period
  344. * of time to avoid removing entry from the list before
  345. * CmdCompl event */
  346. udelay(300);
  347. }
  348. set_current_state(TASK_RUNNING);
  349. remove_wait_queue(&entry->compl, &wait);
  350. /* If entry->list is still in the list, it must be removed
  351. * first and in this case prism2_cmd_ev() does not yet have
  352. * local reference to it, and the data can be kfree()'d
  353. * here. If the command completion event is still generated,
  354. * it will be assigned to next (possibly) pending command, but
  355. * the driver will reset the card anyway due to timeout
  356. *
  357. * If the entry is not in the list prism2_cmd_ev() has a local
  358. * reference to it, but keeps cmdlock as long as the data is
  359. * needed, so the data can be kfree()'d here. */
  360. /* FIX: if the entry->list is in the list, it has not been completed
  361. * yet, so removing it here is somewhat wrong.. this could cause
  362. * references to freed memory and next list_del() causing NULL pointer
  363. * dereference.. it would probably be better to leave the entry in the
  364. * list and the list should be emptied during hw reset */
  365. spin_lock_irqsave(&local->cmdlock, flags);
  366. if (!list_empty(&entry->list)) {
  367. printk(KERN_DEBUG "%s: hfa384x_cmd: entry still in list? "
  368. "(entry=%p, type=%d, res=%d)\n", dev->name, entry,
  369. entry->type, res);
  370. list_del_init(&entry->list);
  371. local->cmd_queue_len--;
  372. }
  373. spin_unlock_irqrestore(&local->cmdlock, flags);
  374. if (err) {
  375. printk(KERN_DEBUG "%s: hfa384x_cmd: interrupted; err=%d\n",
  376. dev->name, err);
  377. res = err;
  378. goto done;
  379. }
  380. if (entry->type != CMD_COMPLETED) {
  381. u16 reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
  382. printk(KERN_DEBUG "%s: hfa384x_cmd: command was not "
  383. "completed (res=%d, entry=%p, type=%d, cmd=0x%04x, "
  384. "param0=0x%04x, EVSTAT=%04x INTEN=%04x)\n", dev->name,
  385. res, entry, entry->type, entry->cmd, entry->param0, reg,
  386. HFA384X_INW(HFA384X_INTEN_OFF));
  387. if (reg & HFA384X_EV_CMD) {
  388. /* Command completion event is pending, but the
  389. * interrupt was not delivered - probably an issue
  390. * with pcmcia-cs configuration. */
  391. printk(KERN_WARNING "%s: interrupt delivery does not "
  392. "seem to work\n", dev->name);
  393. }
  394. prism2_io_debug_error(dev, 3);
  395. res = -ETIMEDOUT;
  396. goto done;
  397. }
  398. if (resp0 != NULL)
  399. *resp0 = entry->resp0;
  400. #ifndef final_version
  401. if (entry->res) {
  402. printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x, "
  403. "resp0=0x%04x\n",
  404. dev->name, cmd, entry->res, entry->resp0);
  405. }
  406. #endif /* final_version */
  407. res = entry->res;
  408. done:
  409. hostap_cmd_queue_free(local, entry, 1);
  410. return res;
  411. }
  412. /**
  413. * hfa384x_cmd_callback - Issue a Prism2 command; callback when completed
  414. * @dev: pointer to net_device
  415. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  416. * @param0: value for Param0 register
  417. * @callback: command completion callback function (%NULL = no callback)
  418. * @context: context data to be given to the callback function
  419. *
  420. * Issue given command (possibly after waiting in command queue) and use
  421. * callback function to indicate command completion. This can be called both
  422. * from user and interrupt context. The callback function will be called in
  423. * hardware IRQ context. It can be %NULL, when no function is called when
  424. * command is completed.
  425. */
  426. static int hfa384x_cmd_callback(struct net_device *dev, u16 cmd, u16 param0,
  427. void (*callback)(struct net_device *dev,
  428. long context, u16 resp0,
  429. u16 status),
  430. long context)
  431. {
  432. struct hostap_interface *iface;
  433. local_info_t *local;
  434. int issue, ret;
  435. unsigned long flags;
  436. struct hostap_cmd_queue *entry;
  437. iface = netdev_priv(dev);
  438. local = iface->local;
  439. if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN + 2) {
  440. printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
  441. dev->name);
  442. return -1;
  443. }
  444. entry = (struct hostap_cmd_queue *)
  445. kmalloc(sizeof(*entry), GFP_ATOMIC);
  446. if (entry == NULL) {
  447. printk(KERN_DEBUG "%s: hfa384x_cmd_callback - kmalloc "
  448. "failed\n", dev->name);
  449. return -ENOMEM;
  450. }
  451. memset(entry, 0, sizeof(*entry));
  452. atomic_set(&entry->usecnt, 1);
  453. entry->type = CMD_CALLBACK;
  454. entry->cmd = cmd;
  455. entry->param0 = param0;
  456. entry->callback = callback;
  457. entry->context = context;
  458. spin_lock_irqsave(&local->cmdlock, flags);
  459. issue = list_empty(&local->cmd_queue);
  460. if (issue)
  461. entry->issuing = 1;
  462. list_add_tail(&entry->list, &local->cmd_queue);
  463. local->cmd_queue_len++;
  464. spin_unlock_irqrestore(&local->cmdlock, flags);
  465. if (issue && hfa384x_cmd_issue(dev, entry))
  466. ret = -ETIMEDOUT;
  467. else
  468. ret = 0;
  469. hostap_cmd_queue_free(local, entry, ret);
  470. return ret;
  471. }
  472. /**
  473. * __hfa384x_cmd_no_wait - Issue a Prism2 command (private)
  474. * @dev: pointer to net_device
  475. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  476. * @param0: value for Param0 register
  477. * @io_debug_num: I/O debug error number
  478. *
  479. * Shared helper function for hfa384x_cmd_wait() and hfa384x_cmd_no_wait().
  480. */
  481. static int __hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd, u16 param0,
  482. int io_debug_num)
  483. {
  484. int tries;
  485. u16 reg;
  486. /* wait until busy bit is clear; this should always be clear since the
  487. * commands are serialized */
  488. tries = HFA384X_CMD_BUSY_TIMEOUT;
  489. while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
  490. tries--;
  491. udelay(1);
  492. }
  493. if (tries == 0) {
  494. reg = HFA384X_INW(HFA384X_CMD_OFF);
  495. prism2_io_debug_error(dev, io_debug_num);
  496. printk(KERN_DEBUG "%s: __hfa384x_cmd_no_wait(%d) - timeout - "
  497. "reg=0x%04x\n", dev->name, io_debug_num, reg);
  498. return -ETIMEDOUT;
  499. }
  500. /* write command */
  501. HFA384X_OUTW(param0, HFA384X_PARAM0_OFF);
  502. HFA384X_OUTW(cmd, HFA384X_CMD_OFF);
  503. return 0;
  504. }
  505. /**
  506. * hfa384x_cmd_wait - Issue a Prism2 command and busy wait for completion
  507. * @dev: pointer to net_device
  508. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  509. * @param0: value for Param0 register
  510. */
  511. static int hfa384x_cmd_wait(struct net_device *dev, u16 cmd, u16 param0)
  512. {
  513. int res, tries;
  514. u16 reg;
  515. res = __hfa384x_cmd_no_wait(dev, cmd, param0, 4);
  516. if (res)
  517. return res;
  518. /* wait for command completion */
  519. if ((cmd & HFA384X_CMDCODE_MASK) == HFA384X_CMDCODE_DOWNLOAD)
  520. tries = HFA384X_DL_COMPL_TIMEOUT;
  521. else
  522. tries = HFA384X_CMD_COMPL_TIMEOUT;
  523. while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
  524. tries > 0) {
  525. tries--;
  526. udelay(10);
  527. }
  528. if (tries == 0) {
  529. reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
  530. prism2_io_debug_error(dev, 5);
  531. printk(KERN_DEBUG "%s: hfa384x_cmd_wait - timeout2 - "
  532. "reg=0x%04x\n", dev->name, reg);
  533. return -ETIMEDOUT;
  534. }
  535. res = (HFA384X_INW(HFA384X_STATUS_OFF) &
  536. (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) | BIT(9) |
  537. BIT(8))) >> 8;
  538. #ifndef final_version
  539. if (res) {
  540. printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x\n",
  541. dev->name, cmd, res);
  542. }
  543. #endif
  544. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  545. return res;
  546. }
  547. /**
  548. * hfa384x_cmd_no_wait - Issue a Prism2 command; do not wait for completion
  549. * @dev: pointer to net_device
  550. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  551. * @param0: value for Param0 register
  552. */
  553. static inline int hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd,
  554. u16 param0)
  555. {
  556. return __hfa384x_cmd_no_wait(dev, cmd, param0, 6);
  557. }
  558. /**
  559. * prism2_cmd_ev - Prism2 command completion event handler
  560. * @dev: pointer to net_device
  561. *
  562. * Interrupt handler for command completion events. Called by the main
  563. * interrupt handler in hardware IRQ context. Read Resp0 and status registers
  564. * from the hardware and ACK the event. Depending on the issued command type
  565. * either wake up the sleeping process that is waiting for command completion
  566. * or call the callback function. Issue the next command, if one is pending.
  567. */
  568. static void prism2_cmd_ev(struct net_device *dev)
  569. {
  570. struct hostap_interface *iface;
  571. local_info_t *local;
  572. struct hostap_cmd_queue *entry = NULL;
  573. iface = netdev_priv(dev);
  574. local = iface->local;
  575. spin_lock(&local->cmdlock);
  576. if (!list_empty(&local->cmd_queue)) {
  577. entry = list_entry(local->cmd_queue.next,
  578. struct hostap_cmd_queue, list);
  579. atomic_inc(&entry->usecnt);
  580. list_del_init(&entry->list);
  581. local->cmd_queue_len--;
  582. if (!entry->issued) {
  583. printk(KERN_DEBUG "%s: Command completion event, but "
  584. "cmd not issued\n", dev->name);
  585. __hostap_cmd_queue_free(local, entry, 1);
  586. entry = NULL;
  587. }
  588. }
  589. spin_unlock(&local->cmdlock);
  590. if (!entry) {
  591. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  592. printk(KERN_DEBUG "%s: Command completion event, but no "
  593. "pending commands\n", dev->name);
  594. return;
  595. }
  596. entry->resp0 = HFA384X_INW(HFA384X_RESP0_OFF);
  597. entry->res = (HFA384X_INW(HFA384X_STATUS_OFF) &
  598. (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) |
  599. BIT(9) | BIT(8))) >> 8;
  600. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  601. /* TODO: rest of the CmdEv handling could be moved to tasklet */
  602. if (entry->type == CMD_SLEEP) {
  603. entry->type = CMD_COMPLETED;
  604. wake_up_interruptible(&entry->compl);
  605. } else if (entry->type == CMD_CALLBACK) {
  606. if (entry->callback)
  607. entry->callback(dev, entry->context, entry->resp0,
  608. entry->res);
  609. } else {
  610. printk(KERN_DEBUG "%s: Invalid command completion type %d\n",
  611. dev->name, entry->type);
  612. }
  613. hostap_cmd_queue_free(local, entry, 1);
  614. /* issue next command, if pending */
  615. entry = NULL;
  616. spin_lock(&local->cmdlock);
  617. if (!list_empty(&local->cmd_queue)) {
  618. entry = list_entry(local->cmd_queue.next,
  619. struct hostap_cmd_queue, list);
  620. if (entry->issuing) {
  621. /* hfa384x_cmd() has already started issuing this
  622. * command, so do not start here */
  623. entry = NULL;
  624. }
  625. if (entry)
  626. atomic_inc(&entry->usecnt);
  627. }
  628. spin_unlock(&local->cmdlock);
  629. if (entry) {
  630. /* issue next command; if command issuing fails, remove the
  631. * entry from cmd_queue */
  632. int res = hfa384x_cmd_issue(dev, entry);
  633. spin_lock(&local->cmdlock);
  634. __hostap_cmd_queue_free(local, entry, res);
  635. spin_unlock(&local->cmdlock);
  636. }
  637. }
  638. static inline int hfa384x_wait_offset(struct net_device *dev, u16 o_off)
  639. {
  640. int tries = HFA384X_BAP_BUSY_TIMEOUT;
  641. int res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
  642. while (res && tries > 0) {
  643. tries--;
  644. udelay(1);
  645. res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
  646. }
  647. return res;
  648. }
  649. /* Offset must be even */
  650. static int hfa384x_setup_bap(struct net_device *dev, u16 bap, u16 id,
  651. int offset)
  652. {
  653. u16 o_off, s_off;
  654. int ret = 0;
  655. if (offset % 2 || bap > 1)
  656. return -EINVAL;
  657. if (bap == BAP1) {
  658. o_off = HFA384X_OFFSET1_OFF;
  659. s_off = HFA384X_SELECT1_OFF;
  660. } else {
  661. o_off = HFA384X_OFFSET0_OFF;
  662. s_off = HFA384X_SELECT0_OFF;
  663. }
  664. if (hfa384x_wait_offset(dev, o_off)) {
  665. prism2_io_debug_error(dev, 7);
  666. printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout before\n",
  667. dev->name);
  668. ret = -ETIMEDOUT;
  669. goto out;
  670. }
  671. HFA384X_OUTW(id, s_off);
  672. HFA384X_OUTW(offset, o_off);
  673. if (hfa384x_wait_offset(dev, o_off)) {
  674. prism2_io_debug_error(dev, 8);
  675. printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout after\n",
  676. dev->name);
  677. ret = -ETIMEDOUT;
  678. goto out;
  679. }
  680. #ifndef final_version
  681. if (HFA384X_INW(o_off) & HFA384X_OFFSET_ERR) {
  682. prism2_io_debug_error(dev, 9);
  683. printk(KERN_DEBUG "%s: hfa384x_setup_bap - offset error "
  684. "(%d,0x04%x,%d); reg=0x%04x\n",
  685. dev->name, bap, id, offset, HFA384X_INW(o_off));
  686. ret = -EINVAL;
  687. }
  688. #endif
  689. out:
  690. return ret;
  691. }
  692. static int hfa384x_get_rid(struct net_device *dev, u16 rid, void *buf, int len,
  693. int exact_len)
  694. {
  695. struct hostap_interface *iface;
  696. local_info_t *local;
  697. int res, rlen = 0;
  698. struct hfa384x_rid_hdr rec;
  699. iface = netdev_priv(dev);
  700. local = iface->local;
  701. if (local->no_pri) {
  702. printk(KERN_DEBUG "%s: cannot get RID %04x (len=%d) - no PRI "
  703. "f/w\n", dev->name, rid, len);
  704. return -ENOTTY; /* Well.. not really correct, but return
  705. * something unique enough.. */
  706. }
  707. if ((local->func->card_present && !local->func->card_present(local)) ||
  708. local->hw_downloading)
  709. return -ENODEV;
  710. res = down_interruptible(&local->rid_bap_sem);
  711. if (res)
  712. return res;
  713. res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS, rid, NULL, NULL);
  714. if (res) {
  715. printk(KERN_DEBUG "%s: hfa384x_get_rid: CMDCODE_ACCESS failed "
  716. "(res=%d, rid=%04x, len=%d)\n",
  717. dev->name, res, rid, len);
  718. up(&local->rid_bap_sem);
  719. return res;
  720. }
  721. spin_lock_bh(&local->baplock);
  722. res = hfa384x_setup_bap(dev, BAP0, rid, 0);
  723. if (!res)
  724. res = hfa384x_from_bap(dev, BAP0, &rec, sizeof(rec));
  725. if (le16_to_cpu(rec.len) == 0) {
  726. /* RID not available */
  727. res = -ENODATA;
  728. }
  729. rlen = (le16_to_cpu(rec.len) - 1) * 2;
  730. if (!res && exact_len && rlen != len) {
  731. printk(KERN_DEBUG "%s: hfa384x_get_rid - RID len mismatch: "
  732. "rid=0x%04x, len=%d (expected %d)\n",
  733. dev->name, rid, rlen, len);
  734. res = -ENODATA;
  735. }
  736. if (!res)
  737. res = hfa384x_from_bap(dev, BAP0, buf, len);
  738. spin_unlock_bh(&local->baplock);
  739. up(&local->rid_bap_sem);
  740. if (res) {
  741. if (res != -ENODATA)
  742. printk(KERN_DEBUG "%s: hfa384x_get_rid (rid=%04x, "
  743. "len=%d) - failed - res=%d\n", dev->name, rid,
  744. len, res);
  745. if (res == -ETIMEDOUT)
  746. prism2_hw_reset(dev);
  747. return res;
  748. }
  749. return rlen;
  750. }
  751. static int hfa384x_set_rid(struct net_device *dev, u16 rid, void *buf, int len)
  752. {
  753. struct hostap_interface *iface;
  754. local_info_t *local;
  755. struct hfa384x_rid_hdr rec;
  756. int res;
  757. iface = netdev_priv(dev);
  758. local = iface->local;
  759. if (local->no_pri) {
  760. printk(KERN_DEBUG "%s: cannot set RID %04x (len=%d) - no PRI "
  761. "f/w\n", dev->name, rid, len);
  762. return -ENOTTY; /* Well.. not really correct, but return
  763. * something unique enough.. */
  764. }
  765. if ((local->func->card_present && !local->func->card_present(local)) ||
  766. local->hw_downloading)
  767. return -ENODEV;
  768. rec.rid = cpu_to_le16(rid);
  769. /* RID len in words and +1 for rec.rid */
  770. rec.len = cpu_to_le16(len / 2 + len % 2 + 1);
  771. res = down_interruptible(&local->rid_bap_sem);
  772. if (res)
  773. return res;
  774. spin_lock_bh(&local->baplock);
  775. res = hfa384x_setup_bap(dev, BAP0, rid, 0);
  776. if (!res)
  777. res = hfa384x_to_bap(dev, BAP0, &rec, sizeof(rec));
  778. if (!res)
  779. res = hfa384x_to_bap(dev, BAP0, buf, len);
  780. spin_unlock_bh(&local->baplock);
  781. if (res) {
  782. printk(KERN_DEBUG "%s: hfa384x_set_rid (rid=%04x, len=%d) - "
  783. "failed - res=%d\n", dev->name, rid, len, res);
  784. up(&local->rid_bap_sem);
  785. return res;
  786. }
  787. res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS_WRITE, rid, NULL, NULL);
  788. up(&local->rid_bap_sem);
  789. if (res) {
  790. printk(KERN_DEBUG "%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE "
  791. "failed (res=%d, rid=%04x, len=%d)\n",
  792. dev->name, res, rid, len);
  793. return res;
  794. }
  795. if (res == -ETIMEDOUT)
  796. prism2_hw_reset(dev);
  797. return res;
  798. }
  799. static void hfa384x_disable_interrupts(struct net_device *dev)
  800. {
  801. /* disable interrupts and clear event status */
  802. HFA384X_OUTW(0, HFA384X_INTEN_OFF);
  803. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  804. }
  805. static void hfa384x_enable_interrupts(struct net_device *dev)
  806. {
  807. /* ack pending events and enable interrupts from selected events */
  808. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  809. HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
  810. }
  811. static void hfa384x_events_no_bap0(struct net_device *dev)
  812. {
  813. HFA384X_OUTW(HFA384X_EVENT_MASK & ~HFA384X_BAP0_EVENTS,
  814. HFA384X_INTEN_OFF);
  815. }
  816. static void hfa384x_events_all(struct net_device *dev)
  817. {
  818. HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
  819. }
  820. static void hfa384x_events_only_cmd(struct net_device *dev)
  821. {
  822. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_INTEN_OFF);
  823. }
  824. static u16 hfa384x_allocate_fid(struct net_device *dev, int len)
  825. {
  826. u16 fid;
  827. unsigned long delay;
  828. /* FIX: this could be replace with hfa384x_cmd() if the Alloc event
  829. * below would be handled like CmdCompl event (sleep here, wake up from
  830. * interrupt handler */
  831. if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_ALLOC, len)) {
  832. printk(KERN_DEBUG "%s: cannot allocate fid, len=%d\n",
  833. dev->name, len);
  834. return 0xffff;
  835. }
  836. delay = jiffies + HFA384X_ALLOC_COMPL_TIMEOUT;
  837. while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC) &&
  838. time_before(jiffies, delay))
  839. yield();
  840. if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC)) {
  841. printk("%s: fid allocate, len=%d - timeout\n", dev->name, len);
  842. return 0xffff;
  843. }
  844. fid = HFA384X_INW(HFA384X_ALLOCFID_OFF);
  845. HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
  846. return fid;
  847. }
  848. static int prism2_reset_port(struct net_device *dev)
  849. {
  850. struct hostap_interface *iface;
  851. local_info_t *local;
  852. int res;
  853. iface = netdev_priv(dev);
  854. local = iface->local;
  855. if (!local->dev_enabled)
  856. return 0;
  857. res = hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0,
  858. NULL, NULL);
  859. if (res)
  860. printk(KERN_DEBUG "%s: reset port failed to disable port\n",
  861. dev->name);
  862. else {
  863. res = hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0,
  864. NULL, NULL);
  865. if (res)
  866. printk(KERN_DEBUG "%s: reset port failed to enable "
  867. "port\n", dev->name);
  868. }
  869. /* It looks like at least some STA firmware versions reset
  870. * fragmentation threshold back to 2346 after enable command. Restore
  871. * the configured value, if it differs from this default. */
  872. if (local->fragm_threshold != 2346 &&
  873. hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
  874. local->fragm_threshold)) {
  875. printk(KERN_DEBUG "%s: failed to restore fragmentation "
  876. "threshold (%d) after Port0 enable\n",
  877. dev->name, local->fragm_threshold);
  878. }
  879. return res;
  880. }
  881. static int prism2_get_version_info(struct net_device *dev, u16 rid,
  882. const char *txt)
  883. {
  884. struct hfa384x_comp_ident comp;
  885. struct hostap_interface *iface;
  886. local_info_t *local;
  887. iface = netdev_priv(dev);
  888. local = iface->local;
  889. if (local->no_pri) {
  890. /* PRI f/w not yet available - cannot read RIDs */
  891. return -1;
  892. }
  893. if (hfa384x_get_rid(dev, rid, &comp, sizeof(comp), 1) < 0) {
  894. printk(KERN_DEBUG "Could not get RID for component %s\n", txt);
  895. return -1;
  896. }
  897. printk(KERN_INFO "%s: %s: id=0x%02x v%d.%d.%d\n", dev->name, txt,
  898. __le16_to_cpu(comp.id), __le16_to_cpu(comp.major),
  899. __le16_to_cpu(comp.minor), __le16_to_cpu(comp.variant));
  900. return 0;
  901. }
  902. static int prism2_setup_rids(struct net_device *dev)
  903. {
  904. struct hostap_interface *iface;
  905. local_info_t *local;
  906. u16 tmp;
  907. int ret = 0;
  908. iface = netdev_priv(dev);
  909. local = iface->local;
  910. hostap_set_word(dev, HFA384X_RID_TICKTIME, 2000);
  911. if (!local->fw_ap) {
  912. tmp = hostap_get_porttype(local);
  913. ret = hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, tmp);
  914. if (ret) {
  915. printk("%s: Port type setting to %d failed\n",
  916. dev->name, tmp);
  917. goto fail;
  918. }
  919. }
  920. /* Setting SSID to empty string seems to kill the card in Host AP mode
  921. */
  922. if (local->iw_mode != IW_MODE_MASTER || local->essid[0] != '\0') {
  923. ret = hostap_set_string(dev, HFA384X_RID_CNFOWNSSID,
  924. local->essid);
  925. if (ret) {
  926. printk("%s: AP own SSID setting failed\n", dev->name);
  927. goto fail;
  928. }
  929. }
  930. ret = hostap_set_word(dev, HFA384X_RID_CNFMAXDATALEN,
  931. PRISM2_DATA_MAXLEN);
  932. if (ret) {
  933. printk("%s: MAC data length setting to %d failed\n",
  934. dev->name, PRISM2_DATA_MAXLEN);
  935. goto fail;
  936. }
  937. if (hfa384x_get_rid(dev, HFA384X_RID_CHANNELLIST, &tmp, 2, 1) < 0) {
  938. printk("%s: Channel list read failed\n", dev->name);
  939. ret = -EINVAL;
  940. goto fail;
  941. }
  942. local->channel_mask = __le16_to_cpu(tmp);
  943. if (local->channel < 1 || local->channel > 14 ||
  944. !(local->channel_mask & (1 << (local->channel - 1)))) {
  945. printk(KERN_WARNING "%s: Channel setting out of range "
  946. "(%d)!\n", dev->name, local->channel);
  947. ret = -EBUSY;
  948. goto fail;
  949. }
  950. ret = hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel);
  951. if (ret) {
  952. printk("%s: Channel setting to %d failed\n",
  953. dev->name, local->channel);
  954. goto fail;
  955. }
  956. ret = hostap_set_word(dev, HFA384X_RID_CNFBEACONINT,
  957. local->beacon_int);
  958. if (ret) {
  959. printk("%s: Beacon interval setting to %d failed\n",
  960. dev->name, local->beacon_int);
  961. /* this may fail with Symbol/Lucent firmware */
  962. if (ret == -ETIMEDOUT)
  963. goto fail;
  964. }
  965. ret = hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD,
  966. local->dtim_period);
  967. if (ret) {
  968. printk("%s: DTIM period setting to %d failed\n",
  969. dev->name, local->dtim_period);
  970. /* this may fail with Symbol/Lucent firmware */
  971. if (ret == -ETIMEDOUT)
  972. goto fail;
  973. }
  974. ret = hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
  975. local->is_promisc);
  976. if (ret)
  977. printk(KERN_INFO "%s: Setting promiscuous mode (%d) failed\n",
  978. dev->name, local->is_promisc);
  979. if (!local->fw_ap) {
  980. ret = hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID,
  981. local->essid);
  982. if (ret) {
  983. printk("%s: Desired SSID setting failed\n", dev->name);
  984. goto fail;
  985. }
  986. }
  987. /* Setup TXRateControl, defaults to allow use of 1, 2, 5.5, and
  988. * 11 Mbps in automatic TX rate fallback and 1 and 2 Mbps as basic
  989. * rates */
  990. if (local->tx_rate_control == 0) {
  991. local->tx_rate_control =
  992. HFA384X_RATES_1MBPS |
  993. HFA384X_RATES_2MBPS |
  994. HFA384X_RATES_5MBPS |
  995. HFA384X_RATES_11MBPS;
  996. }
  997. if (local->basic_rates == 0)
  998. local->basic_rates = HFA384X_RATES_1MBPS | HFA384X_RATES_2MBPS;
  999. if (!local->fw_ap) {
  1000. ret = hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
  1001. local->tx_rate_control);
  1002. if (ret) {
  1003. printk("%s: TXRateControl setting to %d failed\n",
  1004. dev->name, local->tx_rate_control);
  1005. goto fail;
  1006. }
  1007. ret = hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
  1008. local->tx_rate_control);
  1009. if (ret) {
  1010. printk("%s: cnfSupportedRates setting to %d failed\n",
  1011. dev->name, local->tx_rate_control);
  1012. }
  1013. ret = hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
  1014. local->basic_rates);
  1015. if (ret) {
  1016. printk("%s: cnfBasicRates setting to %d failed\n",
  1017. dev->name, local->basic_rates);
  1018. }
  1019. ret = hostap_set_word(dev, HFA384X_RID_CREATEIBSS, 1);
  1020. if (ret) {
  1021. printk("%s: Create IBSS setting to 1 failed\n",
  1022. dev->name);
  1023. }
  1024. }
  1025. if (local->name_set)
  1026. (void) hostap_set_string(dev, HFA384X_RID_CNFOWNNAME,
  1027. local->name);
  1028. if (hostap_set_encryption(local)) {
  1029. printk(KERN_INFO "%s: could not configure encryption\n",
  1030. dev->name);
  1031. }
  1032. (void) hostap_set_antsel(local);
  1033. if (hostap_set_roaming(local)) {
  1034. printk(KERN_INFO "%s: could not set host roaming\n",
  1035. dev->name);
  1036. }
  1037. if (local->sta_fw_ver >= PRISM2_FW_VER(1,6,3) &&
  1038. hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY, local->enh_sec))
  1039. printk(KERN_INFO "%s: cnfEnhSecurity setting to 0x%x failed\n",
  1040. dev->name, local->enh_sec);
  1041. /* 32-bit tallies were added in STA f/w 0.8.0, but they were apparently
  1042. * not working correctly (last seven counters report bogus values).
  1043. * This has been fixed in 0.8.2, so enable 32-bit tallies only
  1044. * beginning with that firmware version. Another bug fix for 32-bit
  1045. * tallies in 1.4.0; should 16-bit tallies be used for some other
  1046. * versions, too? */
  1047. if (local->sta_fw_ver >= PRISM2_FW_VER(0,8,2)) {
  1048. if (hostap_set_word(dev, HFA384X_RID_CNFTHIRTY2TALLY, 1)) {
  1049. printk(KERN_INFO "%s: cnfThirty2Tally setting "
  1050. "failed\n", dev->name);
  1051. local->tallies32 = 0;
  1052. } else
  1053. local->tallies32 = 1;
  1054. } else
  1055. local->tallies32 = 0;
  1056. hostap_set_auth_algs(local);
  1057. if (hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
  1058. local->fragm_threshold)) {
  1059. printk(KERN_INFO "%s: setting FragmentationThreshold to %d "
  1060. "failed\n", dev->name, local->fragm_threshold);
  1061. }
  1062. if (hostap_set_word(dev, HFA384X_RID_RTSTHRESHOLD,
  1063. local->rts_threshold)) {
  1064. printk(KERN_INFO "%s: setting RTSThreshold to %d failed\n",
  1065. dev->name, local->rts_threshold);
  1066. }
  1067. if (local->manual_retry_count >= 0 &&
  1068. hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
  1069. local->manual_retry_count)) {
  1070. printk(KERN_INFO "%s: setting cnfAltRetryCount to %d failed\n",
  1071. dev->name, local->manual_retry_count);
  1072. }
  1073. if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1) &&
  1074. hfa384x_get_rid(dev, HFA384X_RID_CNFDBMADJUST, &tmp, 2, 1) == 2) {
  1075. local->rssi_to_dBm = le16_to_cpu(tmp);
  1076. }
  1077. if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->wpa &&
  1078. hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1)) {
  1079. printk(KERN_INFO "%s: setting ssnHandlingMode to 1 failed\n",
  1080. dev->name);
  1081. }
  1082. if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->generic_elem &&
  1083. hfa384x_set_rid(dev, HFA384X_RID_GENERICELEMENT,
  1084. local->generic_elem, local->generic_elem_len)) {
  1085. printk(KERN_INFO "%s: setting genericElement failed\n",
  1086. dev->name);
  1087. }
  1088. fail:
  1089. return ret;
  1090. }
  1091. static int prism2_hw_init(struct net_device *dev, int initial)
  1092. {
  1093. struct hostap_interface *iface;
  1094. local_info_t *local;
  1095. int ret, first = 1;
  1096. unsigned long start, delay;
  1097. PDEBUG(DEBUG_FLOW, "prism2_hw_init()\n");
  1098. iface = netdev_priv(dev);
  1099. local = iface->local;
  1100. clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits);
  1101. init:
  1102. /* initialize HFA 384x */
  1103. ret = hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_INIT, 0);
  1104. if (ret) {
  1105. printk(KERN_INFO "%s: first command failed - assuming card "
  1106. "does not have primary firmware\n", dev_info);
  1107. }
  1108. if (first && (HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
  1109. /* EvStat has Cmd bit set in some cases, so retry once if no
  1110. * wait was needed */
  1111. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  1112. printk(KERN_DEBUG "%s: init command completed too quickly - "
  1113. "retrying\n", dev->name);
  1114. first = 0;
  1115. goto init;
  1116. }
  1117. start = jiffies;
  1118. delay = jiffies + HFA384X_INIT_TIMEOUT;
  1119. while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
  1120. time_before(jiffies, delay))
  1121. yield();
  1122. if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
  1123. printk(KERN_DEBUG "%s: assuming no Primary image in "
  1124. "flash - card initialization not completed\n",
  1125. dev_info);
  1126. local->no_pri = 1;
  1127. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1128. if (local->sram_type == -1)
  1129. local->sram_type = prism2_get_ram_size(local);
  1130. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1131. return 1;
  1132. }
  1133. local->no_pri = 0;
  1134. printk(KERN_DEBUG "prism2_hw_init: initialized in %lu ms\n",
  1135. (jiffies - start) * 1000 / HZ);
  1136. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  1137. return 0;
  1138. }
  1139. static int prism2_hw_init2(struct net_device *dev, int initial)
  1140. {
  1141. struct hostap_interface *iface;
  1142. local_info_t *local;
  1143. int i;
  1144. iface = netdev_priv(dev);
  1145. local = iface->local;
  1146. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1147. kfree(local->pda);
  1148. if (local->no_pri)
  1149. local->pda = NULL;
  1150. else
  1151. local->pda = prism2_read_pda(dev);
  1152. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1153. hfa384x_disable_interrupts(dev);
  1154. #ifndef final_version
  1155. HFA384X_OUTW(HFA384X_MAGIC, HFA384X_SWSUPPORT0_OFF);
  1156. if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
  1157. printk("SWSUPPORT0 write/read failed: %04X != %04X\n",
  1158. HFA384X_INW(HFA384X_SWSUPPORT0_OFF), HFA384X_MAGIC);
  1159. goto failed;
  1160. }
  1161. #endif
  1162. if (initial || local->pri_only) {
  1163. hfa384x_events_only_cmd(dev);
  1164. /* get card version information */
  1165. if (prism2_get_version_info(dev, HFA384X_RID_NICID, "NIC") ||
  1166. prism2_get_version_info(dev, HFA384X_RID_PRIID, "PRI")) {
  1167. hfa384x_disable_interrupts(dev);
  1168. goto failed;
  1169. }
  1170. if (prism2_get_version_info(dev, HFA384X_RID_STAID, "STA")) {
  1171. printk(KERN_DEBUG "%s: Failed to read STA f/w version "
  1172. "- only Primary f/w present\n", dev->name);
  1173. local->pri_only = 1;
  1174. return 0;
  1175. }
  1176. local->pri_only = 0;
  1177. hfa384x_disable_interrupts(dev);
  1178. }
  1179. /* FIX: could convert allocate_fid to use sleeping CmdCompl wait and
  1180. * enable interrupts before this. This would also require some sort of
  1181. * sleeping AllocEv waiting */
  1182. /* allocate TX FIDs */
  1183. local->txfid_len = PRISM2_TXFID_LEN;
  1184. for (i = 0; i < PRISM2_TXFID_COUNT; i++) {
  1185. local->txfid[i] = hfa384x_allocate_fid(dev, local->txfid_len);
  1186. if (local->txfid[i] == 0xffff && local->txfid_len > 1600) {
  1187. local->txfid[i] = hfa384x_allocate_fid(dev, 1600);
  1188. if (local->txfid[i] != 0xffff) {
  1189. printk(KERN_DEBUG "%s: Using shorter TX FID "
  1190. "(1600 bytes)\n", dev->name);
  1191. local->txfid_len = 1600;
  1192. }
  1193. }
  1194. if (local->txfid[i] == 0xffff)
  1195. goto failed;
  1196. local->intransmitfid[i] = PRISM2_TXFID_EMPTY;
  1197. }
  1198. hfa384x_events_only_cmd(dev);
  1199. if (initial) {
  1200. struct list_head *ptr;
  1201. prism2_check_sta_fw_version(local);
  1202. if (hfa384x_get_rid(dev, HFA384X_RID_CNFOWNMACADDR,
  1203. &dev->dev_addr, 6, 1) < 0) {
  1204. printk("%s: could not get own MAC address\n",
  1205. dev->name);
  1206. }
  1207. list_for_each(ptr, &local->hostap_interfaces) {
  1208. iface = list_entry(ptr, struct hostap_interface, list);
  1209. memcpy(iface->dev->dev_addr, dev->dev_addr, ETH_ALEN);
  1210. }
  1211. } else if (local->fw_ap)
  1212. prism2_check_sta_fw_version(local);
  1213. prism2_setup_rids(dev);
  1214. /* MAC is now configured, but port 0 is not yet enabled */
  1215. return 0;
  1216. failed:
  1217. if (!local->no_pri)
  1218. printk(KERN_WARNING "%s: Initialization failed\n", dev_info);
  1219. return 1;
  1220. }
  1221. static int prism2_hw_enable(struct net_device *dev, int initial)
  1222. {
  1223. struct hostap_interface *iface;
  1224. local_info_t *local;
  1225. int was_resetting;
  1226. iface = netdev_priv(dev);
  1227. local = iface->local;
  1228. was_resetting = local->hw_resetting;
  1229. if (hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL, NULL)) {
  1230. printk("%s: MAC port 0 enabling failed\n", dev->name);
  1231. return 1;
  1232. }
  1233. local->hw_ready = 1;
  1234. local->hw_reset_tries = 0;
  1235. local->hw_resetting = 0;
  1236. hfa384x_enable_interrupts(dev);
  1237. /* at least D-Link DWL-650 seems to require additional port reset
  1238. * before it starts acting as an AP, so reset port automatically
  1239. * here just in case */
  1240. if (initial && prism2_reset_port(dev)) {
  1241. printk("%s: MAC port 0 reseting failed\n", dev->name);
  1242. return 1;
  1243. }
  1244. if (was_resetting && netif_queue_stopped(dev)) {
  1245. /* If hw_reset() was called during pending transmit, netif
  1246. * queue was stopped. Wake it up now since the wlan card has
  1247. * been resetted. */
  1248. netif_wake_queue(dev);
  1249. }
  1250. return 0;
  1251. }
  1252. static int prism2_hw_config(struct net_device *dev, int initial)
  1253. {
  1254. struct hostap_interface *iface;
  1255. local_info_t *local;
  1256. iface = netdev_priv(dev);
  1257. local = iface->local;
  1258. if (local->hw_downloading)
  1259. return 1;
  1260. if (prism2_hw_init(dev, initial)) {
  1261. return local->no_pri ? 0 : 1;
  1262. }
  1263. if (prism2_hw_init2(dev, initial))
  1264. return 1;
  1265. /* Enable firmware if secondary image is loaded and at least one of the
  1266. * netdevices is up. */
  1267. if (!local->pri_only &&
  1268. (initial == 0 || (initial == 2 && local->num_dev_open > 0))) {
  1269. if (!local->dev_enabled)
  1270. prism2_callback(local, PRISM2_CALLBACK_ENABLE);
  1271. local->dev_enabled = 1;
  1272. return prism2_hw_enable(dev, initial);
  1273. }
  1274. return 0;
  1275. }
  1276. static void prism2_hw_shutdown(struct net_device *dev, int no_disable)
  1277. {
  1278. struct hostap_interface *iface;
  1279. local_info_t *local;
  1280. iface = netdev_priv(dev);
  1281. local = iface->local;
  1282. /* Allow only command completion events during disable */
  1283. hfa384x_events_only_cmd(dev);
  1284. local->hw_ready = 0;
  1285. if (local->dev_enabled)
  1286. prism2_callback(local, PRISM2_CALLBACK_DISABLE);
  1287. local->dev_enabled = 0;
  1288. if (local->func->card_present && !local->func->card_present(local)) {
  1289. printk(KERN_DEBUG "%s: card already removed or not configured "
  1290. "during shutdown\n", dev->name);
  1291. return;
  1292. }
  1293. if ((no_disable & HOSTAP_HW_NO_DISABLE) == 0 &&
  1294. hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL, NULL))
  1295. printk(KERN_WARNING "%s: Shutdown failed\n", dev_info);
  1296. hfa384x_disable_interrupts(dev);
  1297. if (no_disable & HOSTAP_HW_ENABLE_CMDCOMPL)
  1298. hfa384x_events_only_cmd(dev);
  1299. else
  1300. prism2_clear_cmd_queue(local);
  1301. }
  1302. static void prism2_hw_reset(struct net_device *dev)
  1303. {
  1304. struct hostap_interface *iface;
  1305. local_info_t *local;
  1306. #if 0
  1307. static long last_reset = 0;
  1308. /* do not reset card more than once per second to avoid ending up in a
  1309. * busy loop reseting the card */
  1310. if (time_before_eq(jiffies, last_reset + HZ))
  1311. return;
  1312. last_reset = jiffies;
  1313. #endif
  1314. iface = netdev_priv(dev);
  1315. local = iface->local;
  1316. if (in_interrupt()) {
  1317. printk(KERN_DEBUG "%s: driver bug - prism2_hw_reset() called "
  1318. "in interrupt context\n", dev->name);
  1319. return;
  1320. }
  1321. if (local->hw_downloading)
  1322. return;
  1323. if (local->hw_resetting) {
  1324. printk(KERN_WARNING "%s: %s: already resetting card - "
  1325. "ignoring reset request\n", dev_info, dev->name);
  1326. return;
  1327. }
  1328. local->hw_reset_tries++;
  1329. if (local->hw_reset_tries > 10) {
  1330. printk(KERN_WARNING "%s: too many reset tries, skipping\n",
  1331. dev->name);
  1332. return;
  1333. }
  1334. printk(KERN_WARNING "%s: %s: resetting card\n", dev_info, dev->name);
  1335. hfa384x_disable_interrupts(dev);
  1336. local->hw_resetting = 1;
  1337. if (local->func->cor_sreset) {
  1338. /* Host system seems to hang in some cases with high traffic
  1339. * load or shared interrupts during COR sreset. Disable shared
  1340. * interrupts during reset to avoid these crashes. COS sreset
  1341. * takes quite a long time, so it is unfortunate that this
  1342. * seems to be needed. Anyway, I do not know of any better way
  1343. * of avoiding the crash. */
  1344. disable_irq(dev->irq);
  1345. local->func->cor_sreset(local);
  1346. enable_irq(dev->irq);
  1347. }
  1348. prism2_hw_shutdown(dev, 1);
  1349. prism2_hw_config(dev, 0);
  1350. local->hw_resetting = 0;
  1351. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1352. if (local->dl_pri) {
  1353. printk(KERN_DEBUG "%s: persistent download of primary "
  1354. "firmware\n", dev->name);
  1355. if (prism2_download_genesis(local, local->dl_pri) < 0)
  1356. printk(KERN_WARNING "%s: download (PRI) failed\n",
  1357. dev->name);
  1358. }
  1359. if (local->dl_sec) {
  1360. printk(KERN_DEBUG "%s: persistent download of secondary "
  1361. "firmware\n", dev->name);
  1362. if (prism2_download_volatile(local, local->dl_sec) < 0)
  1363. printk(KERN_WARNING "%s: download (SEC) failed\n",
  1364. dev->name);
  1365. }
  1366. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1367. /* TODO: restore beacon TIM bits for STAs that have buffered frames */
  1368. }
  1369. static void prism2_schedule_reset(local_info_t *local)
  1370. {
  1371. schedule_work(&local->reset_queue);
  1372. }
  1373. /* Called only as scheduled task after noticing card timeout in interrupt
  1374. * context */
  1375. static void handle_reset_queue(void *data)
  1376. {
  1377. local_info_t *local = (local_info_t *) data;
  1378. printk(KERN_DEBUG "%s: scheduled card reset\n", local->dev->name);
  1379. prism2_hw_reset(local->dev);
  1380. if (netif_queue_stopped(local->dev)) {
  1381. int i;
  1382. for (i = 0; i < PRISM2_TXFID_COUNT; i++)
  1383. if (local->intransmitfid[i] == PRISM2_TXFID_EMPTY) {
  1384. PDEBUG(DEBUG_EXTRA, "prism2_tx_timeout: "
  1385. "wake up queue\n");
  1386. netif_wake_queue(local->dev);
  1387. break;
  1388. }
  1389. }
  1390. }
  1391. static int prism2_get_txfid_idx(local_info_t *local)
  1392. {
  1393. int idx, end;
  1394. unsigned long flags;
  1395. spin_lock_irqsave(&local->txfidlock, flags);
  1396. end = idx = local->next_txfid;
  1397. do {
  1398. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
  1399. local->intransmitfid[idx] = PRISM2_TXFID_RESERVED;
  1400. spin_unlock_irqrestore(&local->txfidlock, flags);
  1401. return idx;
  1402. }
  1403. idx++;
  1404. if (idx >= PRISM2_TXFID_COUNT)
  1405. idx = 0;
  1406. } while (idx != end);
  1407. spin_unlock_irqrestore(&local->txfidlock, flags);
  1408. PDEBUG(DEBUG_EXTRA2, "prism2_get_txfid_idx: no room in txfid buf: "
  1409. "packet dropped\n");
  1410. local->stats.tx_dropped++;
  1411. return -1;
  1412. }
  1413. /* Called only from hardware IRQ */
  1414. static void prism2_transmit_cb(struct net_device *dev, long context,
  1415. u16 resp0, u16 res)
  1416. {
  1417. struct hostap_interface *iface;
  1418. local_info_t *local;
  1419. int idx = (int) context;
  1420. iface = netdev_priv(dev);
  1421. local = iface->local;
  1422. if (res) {
  1423. printk(KERN_DEBUG "%s: prism2_transmit_cb - res=0x%02x\n",
  1424. dev->name, res);
  1425. return;
  1426. }
  1427. if (idx < 0 || idx >= PRISM2_TXFID_COUNT) {
  1428. printk(KERN_DEBUG "%s: prism2_transmit_cb called with invalid "
  1429. "idx=%d\n", dev->name, idx);
  1430. return;
  1431. }
  1432. if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  1433. printk(KERN_DEBUG "%s: driver bug: prism2_transmit_cb called "
  1434. "with no pending transmit\n", dev->name);
  1435. }
  1436. if (netif_queue_stopped(dev)) {
  1437. /* ready for next TX, so wake up queue that was stopped in
  1438. * prism2_transmit() */
  1439. netif_wake_queue(dev);
  1440. }
  1441. spin_lock(&local->txfidlock);
  1442. /* With reclaim, Resp0 contains new txfid for transmit; the old txfid
  1443. * will be automatically allocated for the next TX frame */
  1444. local->intransmitfid[idx] = resp0;
  1445. PDEBUG(DEBUG_FID, "%s: prism2_transmit_cb: txfid[%d]=0x%04x, "
  1446. "resp0=0x%04x, transmit_txfid=0x%04x\n",
  1447. dev->name, idx, local->txfid[idx],
  1448. resp0, local->intransmitfid[local->next_txfid]);
  1449. idx++;
  1450. if (idx >= PRISM2_TXFID_COUNT)
  1451. idx = 0;
  1452. local->next_txfid = idx;
  1453. /* check if all TX buffers are occupied */
  1454. do {
  1455. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
  1456. spin_unlock(&local->txfidlock);
  1457. return;
  1458. }
  1459. idx++;
  1460. if (idx >= PRISM2_TXFID_COUNT)
  1461. idx = 0;
  1462. } while (idx != local->next_txfid);
  1463. spin_unlock(&local->txfidlock);
  1464. /* no empty TX buffers, stop queue */
  1465. netif_stop_queue(dev);
  1466. }
  1467. /* Called only from software IRQ if PCI bus master is not used (with bus master
  1468. * this can be called both from software and hardware IRQ) */
  1469. static int prism2_transmit(struct net_device *dev, int idx)
  1470. {
  1471. struct hostap_interface *iface;
  1472. local_info_t *local;
  1473. int res;
  1474. iface = netdev_priv(dev);
  1475. local = iface->local;
  1476. /* The driver tries to stop netif queue so that there would not be
  1477. * more than one attempt to transmit frames going on; check that this
  1478. * is really the case */
  1479. if (test_and_set_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  1480. printk(KERN_DEBUG "%s: driver bug - prism2_transmit() called "
  1481. "when previous TX was pending\n", dev->name);
  1482. return -1;
  1483. }
  1484. /* stop the queue for the time that transmit is pending */
  1485. netif_stop_queue(dev);
  1486. /* transmit packet */
  1487. res = hfa384x_cmd_callback(
  1488. dev,
  1489. HFA384X_CMDCODE_TRANSMIT | HFA384X_CMD_TX_RECLAIM,
  1490. local->txfid[idx],
  1491. prism2_transmit_cb, (long) idx);
  1492. if (res) {
  1493. struct net_device_stats *stats;
  1494. printk(KERN_DEBUG "%s: prism2_transmit: CMDCODE_TRANSMIT "
  1495. "failed (res=%d)\n", dev->name, res);
  1496. stats = hostap_get_stats(dev);
  1497. stats->tx_dropped++;
  1498. netif_wake_queue(dev);
  1499. return -1;
  1500. }
  1501. dev->trans_start = jiffies;
  1502. /* Since we did not wait for command completion, the card continues
  1503. * to process on the background and we will finish handling when
  1504. * command completion event is handled (prism2_cmd_ev() function) */
  1505. return 0;
  1506. }
  1507. /* Send IEEE 802.11 frame (convert the header into Prism2 TX descriptor and
  1508. * send the payload with this descriptor) */
  1509. /* Called only from software IRQ */
  1510. static int prism2_tx_80211(struct sk_buff *skb, struct net_device *dev)
  1511. {
  1512. struct hostap_interface *iface;
  1513. local_info_t *local;
  1514. struct hfa384x_tx_frame txdesc;
  1515. struct hostap_ieee80211_hdr *hdr;
  1516. struct hostap_skb_tx_data *meta;
  1517. int hdr_len, data_len, idx, res, ret = -1;
  1518. u16 tx_control, fc;
  1519. iface = netdev_priv(dev);
  1520. local = iface->local;
  1521. meta = (struct hostap_skb_tx_data *) skb->cb;
  1522. hdr = (struct hostap_ieee80211_hdr *) skb->data;
  1523. prism2_callback(local, PRISM2_CALLBACK_TX_START);
  1524. if ((local->func->card_present && !local->func->card_present(local)) ||
  1525. !local->hw_ready || local->hw_downloading || local->pri_only) {
  1526. if (net_ratelimit()) {
  1527. printk(KERN_DEBUG "%s: prism2_tx_80211: hw not ready -"
  1528. " skipping\n", dev->name);
  1529. }
  1530. goto fail;
  1531. }
  1532. memset(&txdesc, 0, sizeof(txdesc));
  1533. /* skb->data starts with txdesc->frame_control */
  1534. hdr_len = 24;
  1535. memcpy(&txdesc.frame_control, skb->data, hdr_len);
  1536. fc = le16_to_cpu(txdesc.frame_control);
  1537. if (HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
  1538. (fc & WLAN_FC_FROMDS) && (fc & WLAN_FC_TODS) && skb->len >= 30) {
  1539. /* Addr4 */
  1540. memcpy(txdesc.addr4, skb->data + hdr_len, ETH_ALEN);
  1541. hdr_len += ETH_ALEN;
  1542. }
  1543. tx_control = local->tx_control;
  1544. if (meta->tx_cb_idx) {
  1545. tx_control |= HFA384X_TX_CTRL_TX_OK;
  1546. txdesc.sw_support = cpu_to_le16(meta->tx_cb_idx);
  1547. }
  1548. txdesc.tx_control = cpu_to_le16(tx_control);
  1549. txdesc.tx_rate = meta->rate;
  1550. data_len = skb->len - hdr_len;
  1551. txdesc.data_len = cpu_to_le16(data_len);
  1552. txdesc.len = cpu_to_be16(data_len);
  1553. idx = prism2_get_txfid_idx(local);
  1554. if (idx < 0)
  1555. goto fail;
  1556. if (local->frame_dump & PRISM2_DUMP_TX_HDR)
  1557. hostap_dump_tx_header(dev->name, &txdesc);
  1558. spin_lock(&local->baplock);
  1559. res = hfa384x_setup_bap(dev, BAP0, local->txfid[idx], 0);
  1560. if (!res)
  1561. res = hfa384x_to_bap(dev, BAP0, &txdesc, sizeof(txdesc));
  1562. if (!res)
  1563. res = hfa384x_to_bap(dev, BAP0, skb->data + hdr_len,
  1564. skb->len - hdr_len);
  1565. spin_unlock(&local->baplock);
  1566. if (!res)
  1567. res = prism2_transmit(dev, idx);
  1568. if (res) {
  1569. printk(KERN_DEBUG "%s: prism2_tx_80211 - to BAP0 failed\n",
  1570. dev->name);
  1571. local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
  1572. schedule_work(&local->reset_queue);
  1573. goto fail;
  1574. }
  1575. ret = 0;
  1576. fail:
  1577. prism2_callback(local, PRISM2_CALLBACK_TX_END);
  1578. return ret;
  1579. }
  1580. /* Some SMP systems have reported number of odd errors with hostap_pci. fid
  1581. * register has changed values between consecutive reads for an unknown reason.
  1582. * This should really not happen, so more debugging is needed. This test
  1583. * version is a big slower, but it will detect most of such register changes
  1584. * and will try to get the correct fid eventually. */
  1585. #define EXTRA_FID_READ_TESTS
  1586. static inline u16 prism2_read_fid_reg(struct net_device *dev, u16 reg)
  1587. {
  1588. #ifdef EXTRA_FID_READ_TESTS
  1589. u16 val, val2, val3;
  1590. int i;
  1591. for (i = 0; i < 10; i++) {
  1592. val = HFA384X_INW(reg);
  1593. val2 = HFA384X_INW(reg);
  1594. val3 = HFA384X_INW(reg);
  1595. if (val == val2 && val == val3)
  1596. return val;
  1597. printk(KERN_DEBUG "%s: detected fid change (try=%d, reg=%04x):"
  1598. " %04x %04x %04x\n",
  1599. dev->name, i, reg, val, val2, val3);
  1600. if ((val == val2 || val == val3) && val != 0)
  1601. return val;
  1602. if (val2 == val3 && val2 != 0)
  1603. return val2;
  1604. }
  1605. printk(KERN_WARNING "%s: Uhhuh.. could not read good fid from reg "
  1606. "%04x (%04x %04x %04x)\n", dev->name, reg, val, val2, val3);
  1607. return val;
  1608. #else /* EXTRA_FID_READ_TESTS */
  1609. return HFA384X_INW(reg);
  1610. #endif /* EXTRA_FID_READ_TESTS */
  1611. }
  1612. /* Called only as a tasklet (software IRQ) */
  1613. static void prism2_rx(local_info_t *local)
  1614. {
  1615. struct net_device *dev = local->dev;
  1616. int res, rx_pending = 0;
  1617. u16 len, hdr_len, rxfid, status, macport;
  1618. struct net_device_stats *stats;
  1619. struct hfa384x_rx_frame rxdesc;
  1620. struct sk_buff *skb = NULL;
  1621. prism2_callback(local, PRISM2_CALLBACK_RX_START);
  1622. stats = hostap_get_stats(dev);
  1623. rxfid = prism2_read_fid_reg(dev, HFA384X_RXFID_OFF);
  1624. #ifndef final_version
  1625. if (rxfid == 0) {
  1626. rxfid = HFA384X_INW(HFA384X_RXFID_OFF);
  1627. printk(KERN_DEBUG "prism2_rx: rxfid=0 (next 0x%04x)\n",
  1628. rxfid);
  1629. if (rxfid == 0) {
  1630. schedule_work(&local->reset_queue);
  1631. goto rx_dropped;
  1632. }
  1633. /* try to continue with the new rxfid value */
  1634. }
  1635. #endif
  1636. spin_lock(&local->baplock);
  1637. res = hfa384x_setup_bap(dev, BAP0, rxfid, 0);
  1638. if (!res)
  1639. res = hfa384x_from_bap(dev, BAP0, &rxdesc, sizeof(rxdesc));
  1640. if (res) {
  1641. spin_unlock(&local->baplock);
  1642. printk(KERN_DEBUG "%s: copy from BAP0 failed %d\n", dev->name,
  1643. res);
  1644. if (res == -ETIMEDOUT) {
  1645. schedule_work(&local->reset_queue);
  1646. }
  1647. goto rx_dropped;
  1648. }
  1649. len = le16_to_cpu(rxdesc.data_len);
  1650. hdr_len = sizeof(rxdesc);
  1651. status = le16_to_cpu(rxdesc.status);
  1652. macport = (status >> 8) & 0x07;
  1653. /* Drop frames with too large reported payload length. Monitor mode
  1654. * seems to sometimes pass frames (e.g., ctrl::ack) with signed and
  1655. * negative value, so allow also values 65522 .. 65534 (-14 .. -2) for
  1656. * macport 7 */
  1657. if (len > PRISM2_DATA_MAXLEN + 8 /* WEP */) {
  1658. if (macport == 7 && local->iw_mode == IW_MODE_MONITOR) {
  1659. if (len >= (u16) -14) {
  1660. hdr_len -= 65535 - len;
  1661. hdr_len--;
  1662. }
  1663. len = 0;
  1664. } else {
  1665. spin_unlock(&local->baplock);
  1666. printk(KERN_DEBUG "%s: Received frame with invalid "
  1667. "length 0x%04x\n", dev->name, len);
  1668. hostap_dump_rx_header(dev->name, &rxdesc);
  1669. goto rx_dropped;
  1670. }
  1671. }
  1672. skb = dev_alloc_skb(len + hdr_len);
  1673. if (!skb) {
  1674. spin_unlock(&local->baplock);
  1675. printk(KERN_DEBUG "%s: RX failed to allocate skb\n",
  1676. dev->name);
  1677. goto rx_dropped;
  1678. }
  1679. skb->dev = dev;
  1680. memcpy(skb_put(skb, hdr_len), &rxdesc, hdr_len);
  1681. if (len > 0)
  1682. res = hfa384x_from_bap(dev, BAP0, skb_put(skb, len), len);
  1683. spin_unlock(&local->baplock);
  1684. if (res) {
  1685. printk(KERN_DEBUG "%s: RX failed to read "
  1686. "frame data\n", dev->name);
  1687. goto rx_dropped;
  1688. }
  1689. skb_queue_tail(&local->rx_list, skb);
  1690. tasklet_schedule(&local->rx_tasklet);
  1691. rx_exit:
  1692. prism2_callback(local, PRISM2_CALLBACK_RX_END);
  1693. if (!rx_pending) {
  1694. HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
  1695. }
  1696. return;
  1697. rx_dropped:
  1698. stats->rx_dropped++;
  1699. if (skb)
  1700. dev_kfree_skb(skb);
  1701. goto rx_exit;
  1702. }
  1703. /* Called only as a tasklet (software IRQ) */
  1704. static void hostap_rx_skb(local_info_t *local, struct sk_buff *skb)
  1705. {
  1706. struct hfa384x_rx_frame *rxdesc;
  1707. struct net_device *dev = skb->dev;
  1708. struct hostap_80211_rx_status stats;
  1709. int hdrlen, rx_hdrlen;
  1710. rx_hdrlen = sizeof(*rxdesc);
  1711. if (skb->len < sizeof(*rxdesc)) {
  1712. /* Allow monitor mode to receive shorter frames */
  1713. if (local->iw_mode == IW_MODE_MONITOR &&
  1714. skb->len >= sizeof(*rxdesc) - 30) {
  1715. rx_hdrlen = skb->len;
  1716. } else {
  1717. dev_kfree_skb(skb);
  1718. return;
  1719. }
  1720. }
  1721. rxdesc = (struct hfa384x_rx_frame *) skb->data;
  1722. if (local->frame_dump & PRISM2_DUMP_RX_HDR &&
  1723. skb->len >= sizeof(*rxdesc))
  1724. hostap_dump_rx_header(dev->name, rxdesc);
  1725. if (le16_to_cpu(rxdesc->status) & HFA384X_RX_STATUS_FCSERR &&
  1726. (!local->monitor_allow_fcserr ||
  1727. local->iw_mode != IW_MODE_MONITOR))
  1728. goto drop;
  1729. if (skb->len > PRISM2_DATA_MAXLEN) {
  1730. printk(KERN_DEBUG "%s: RX: len(%d) > MAX(%d)\n",
  1731. dev->name, skb->len, PRISM2_DATA_MAXLEN);
  1732. goto drop;
  1733. }
  1734. stats.mac_time = le32_to_cpu(rxdesc->time);
  1735. stats.signal = rxdesc->signal - local->rssi_to_dBm;
  1736. stats.noise = rxdesc->silence - local->rssi_to_dBm;
  1737. stats.rate = rxdesc->rate;
  1738. /* Convert Prism2 RX structure into IEEE 802.11 header */
  1739. hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(rxdesc->frame_control));
  1740. if (hdrlen > rx_hdrlen)
  1741. hdrlen = rx_hdrlen;
  1742. memmove(skb_pull(skb, rx_hdrlen - hdrlen),
  1743. &rxdesc->frame_control, hdrlen);
  1744. hostap_80211_rx(dev, skb, &stats);
  1745. return;
  1746. drop:
  1747. dev_kfree_skb(skb);
  1748. }
  1749. /* Called only as a tasklet (software IRQ) */
  1750. static void hostap_rx_tasklet(unsigned long data)
  1751. {
  1752. local_info_t *local = (local_info_t *) data;
  1753. struct sk_buff *skb;
  1754. while ((skb = skb_dequeue(&local->rx_list)) != NULL)
  1755. hostap_rx_skb(local, skb);
  1756. }
  1757. /* Called only from hardware IRQ */
  1758. static void prism2_alloc_ev(struct net_device *dev)
  1759. {
  1760. struct hostap_interface *iface;
  1761. local_info_t *local;
  1762. int idx;
  1763. u16 fid;
  1764. iface = netdev_priv(dev);
  1765. local = iface->local;
  1766. fid = prism2_read_fid_reg(dev, HFA384X_ALLOCFID_OFF);
  1767. PDEBUG(DEBUG_FID, "FID: interrupt: ALLOC - fid=0x%04x\n", fid);
  1768. spin_lock(&local->txfidlock);
  1769. idx = local->next_alloc;
  1770. do {
  1771. if (local->txfid[idx] == fid) {
  1772. PDEBUG(DEBUG_FID, "FID: found matching txfid[%d]\n",
  1773. idx);
  1774. #ifndef final_version
  1775. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY)
  1776. printk("Already released txfid found at idx "
  1777. "%d\n", idx);
  1778. if (local->intransmitfid[idx] == PRISM2_TXFID_RESERVED)
  1779. printk("Already reserved txfid found at idx "
  1780. "%d\n", idx);
  1781. #endif
  1782. local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
  1783. idx++;
  1784. local->next_alloc = idx >= PRISM2_TXFID_COUNT ? 0 :
  1785. idx;
  1786. if (!test_bit(HOSTAP_BITS_TRANSMIT, &local->bits) &&
  1787. netif_queue_stopped(dev))
  1788. netif_wake_queue(dev);
  1789. spin_unlock(&local->txfidlock);
  1790. return;
  1791. }
  1792. idx++;
  1793. if (idx >= PRISM2_TXFID_COUNT)
  1794. idx = 0;
  1795. } while (idx != local->next_alloc);
  1796. printk(KERN_WARNING "%s: could not find matching txfid (0x%04x, new "
  1797. "read 0x%04x) for alloc event\n", dev->name, fid,
  1798. HFA384X_INW(HFA384X_ALLOCFID_OFF));
  1799. printk(KERN_DEBUG "TXFIDs:");
  1800. for (idx = 0; idx < PRISM2_TXFID_COUNT; idx++)
  1801. printk(" %04x[%04x]", local->txfid[idx],
  1802. local->intransmitfid[idx]);
  1803. printk("\n");
  1804. spin_unlock(&local->txfidlock);
  1805. /* FIX: should probably schedule reset; reference to one txfid was lost
  1806. * completely.. Bad things will happen if we run out of txfids
  1807. * Actually, this will cause netdev watchdog to notice TX timeout and
  1808. * then card reset after all txfids have been leaked. */
  1809. }
  1810. /* Called only as a tasklet (software IRQ) */
  1811. static void hostap_tx_callback(local_info_t *local,
  1812. struct hfa384x_tx_frame *txdesc, int ok,
  1813. char *payload)
  1814. {
  1815. u16 sw_support, hdrlen, len;
  1816. struct sk_buff *skb;
  1817. struct hostap_tx_callback_info *cb;
  1818. /* Make sure that frame was from us. */
  1819. if (memcmp(txdesc->addr2, local->dev->dev_addr, ETH_ALEN)) {
  1820. printk(KERN_DEBUG "%s: TX callback - foreign frame\n",
  1821. local->dev->name);
  1822. return;
  1823. }
  1824. sw_support = le16_to_cpu(txdesc->sw_support);
  1825. spin_lock(&local->lock);
  1826. cb = local->tx_callback;
  1827. while (cb != NULL && cb->idx != sw_support)
  1828. cb = cb->next;
  1829. spin_unlock(&local->lock);
  1830. if (cb == NULL) {
  1831. printk(KERN_DEBUG "%s: could not find TX callback (idx %d)\n",
  1832. local->dev->name, sw_support);
  1833. return;
  1834. }
  1835. hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(txdesc->frame_control));
  1836. len = le16_to_cpu(txdesc->data_len);
  1837. skb = dev_alloc_skb(hdrlen + len);
  1838. if (skb == NULL) {
  1839. printk(KERN_DEBUG "%s: hostap_tx_callback failed to allocate "
  1840. "skb\n", local->dev->name);
  1841. return;
  1842. }
  1843. memcpy(skb_put(skb, hdrlen), (void *) &txdesc->frame_control, hdrlen);
  1844. if (payload)
  1845. memcpy(skb_put(skb, len), payload, len);
  1846. skb->dev = local->dev;
  1847. skb->mac.raw = skb->data;
  1848. cb->func(skb, ok, cb->data);
  1849. }
  1850. /* Called only as a tasklet (software IRQ) */
  1851. static int hostap_tx_compl_read(local_info_t *local, int error,
  1852. struct hfa384x_tx_frame *txdesc,
  1853. char **payload)
  1854. {
  1855. u16 fid, len;
  1856. int res, ret = 0;
  1857. struct net_device *dev = local->dev;
  1858. fid = prism2_read_fid_reg(dev, HFA384X_TXCOMPLFID_OFF);
  1859. PDEBUG(DEBUG_FID, "interrupt: TX (err=%d) - fid=0x%04x\n", fid, error);
  1860. spin_lock(&local->baplock);
  1861. res = hfa384x_setup_bap(dev, BAP0, fid, 0);
  1862. if (!res)
  1863. res = hfa384x_from_bap(dev, BAP0, txdesc, sizeof(*txdesc));
  1864. if (res) {
  1865. PDEBUG(DEBUG_EXTRA, "%s: TX (err=%d) - fid=0x%04x - could not "
  1866. "read txdesc\n", dev->name, error, fid);
  1867. if (res == -ETIMEDOUT) {
  1868. schedule_work(&local->reset_queue);
  1869. }
  1870. ret = -1;
  1871. goto fail;
  1872. }
  1873. if (txdesc->sw_support) {
  1874. len = le16_to_cpu(txdesc->data_len);
  1875. if (len < PRISM2_DATA_MAXLEN) {
  1876. *payload = (char *) kmalloc(len, GFP_ATOMIC);
  1877. if (*payload == NULL ||
  1878. hfa384x_from_bap(dev, BAP0, *payload, len)) {
  1879. PDEBUG(DEBUG_EXTRA, "%s: could not read TX "
  1880. "frame payload\n", dev->name);
  1881. kfree(*payload);
  1882. *payload = NULL;
  1883. ret = -1;
  1884. goto fail;
  1885. }
  1886. }
  1887. }
  1888. fail:
  1889. spin_unlock(&local->baplock);
  1890. return ret;
  1891. }
  1892. /* Called only as a tasklet (software IRQ) */
  1893. static void prism2_tx_ev(local_info_t *local)
  1894. {
  1895. struct net_device *dev = local->dev;
  1896. char *payload = NULL;
  1897. struct hfa384x_tx_frame txdesc;
  1898. if (hostap_tx_compl_read(local, 0, &txdesc, &payload))
  1899. goto fail;
  1900. if (local->frame_dump & PRISM2_DUMP_TX_HDR) {
  1901. PDEBUG(DEBUG_EXTRA, "%s: TX - status=0x%04x "
  1902. "retry_count=%d tx_rate=%d seq_ctrl=%d "
  1903. "duration_id=%d\n",
  1904. dev->name, le16_to_cpu(txdesc.status),
  1905. txdesc.retry_count, txdesc.tx_rate,
  1906. le16_to_cpu(txdesc.seq_ctrl),
  1907. le16_to_cpu(txdesc.duration_id));
  1908. }
  1909. if (txdesc.sw_support)
  1910. hostap_tx_callback(local, &txdesc, 1, payload);
  1911. kfree(payload);
  1912. fail:
  1913. HFA384X_OUTW(HFA384X_EV_TX, HFA384X_EVACK_OFF);
  1914. }
  1915. /* Called only as a tasklet (software IRQ) */
  1916. static void hostap_sta_tx_exc_tasklet(unsigned long data)
  1917. {
  1918. local_info_t *local = (local_info_t *) data;
  1919. struct sk_buff *skb;
  1920. while ((skb = skb_dequeue(&local->sta_tx_exc_list)) != NULL) {
  1921. struct hfa384x_tx_frame *txdesc =
  1922. (struct hfa384x_tx_frame *) skb->data;
  1923. if (skb->len >= sizeof(*txdesc)) {
  1924. /* Convert Prism2 RX structure into IEEE 802.11 header
  1925. */
  1926. u16 fc = le16_to_cpu(txdesc->frame_control);
  1927. int hdrlen = hostap_80211_get_hdrlen(fc);
  1928. memmove(skb_pull(skb, sizeof(*txdesc) - hdrlen),
  1929. &txdesc->frame_control, hdrlen);
  1930. hostap_handle_sta_tx_exc(local, skb);
  1931. }
  1932. dev_kfree_skb(skb);
  1933. }
  1934. }
  1935. /* Called only as a tasklet (software IRQ) */
  1936. static void prism2_txexc(local_info_t *local)
  1937. {
  1938. struct net_device *dev = local->dev;
  1939. u16 status, fc;
  1940. int show_dump, res;
  1941. char *payload = NULL;
  1942. struct hfa384x_tx_frame txdesc;
  1943. show_dump = local->frame_dump & PRISM2_DUMP_TXEXC_HDR;
  1944. local->stats.tx_errors++;
  1945. res = hostap_tx_compl_read(local, 1, &txdesc, &payload);
  1946. HFA384X_OUTW(HFA384X_EV_TXEXC, HFA384X_EVACK_OFF);
  1947. if (res)
  1948. return;
  1949. status = le16_to_cpu(txdesc.status);
  1950. /* We produce a TXDROP event only for retry or lifetime
  1951. * exceeded, because that's the only status that really mean
  1952. * that this particular node went away.
  1953. * Other errors means that *we* screwed up. - Jean II */
  1954. if (status & (HFA384X_TX_STATUS_RETRYERR | HFA384X_TX_STATUS_AGEDERR))
  1955. {
  1956. union iwreq_data wrqu;
  1957. /* Copy 802.11 dest address. */
  1958. memcpy(wrqu.addr.sa_data, txdesc.addr1, ETH_ALEN);
  1959. wrqu.addr.sa_family = ARPHRD_ETHER;
  1960. wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
  1961. } else
  1962. show_dump = 1;
  1963. if (local->iw_mode == IW_MODE_MASTER ||
  1964. local->iw_mode == IW_MODE_REPEAT ||
  1965. local->wds_type & HOSTAP_WDS_AP_CLIENT) {
  1966. struct sk_buff *skb;
  1967. skb = dev_alloc_skb(sizeof(txdesc));
  1968. if (skb) {
  1969. memcpy(skb_put(skb, sizeof(txdesc)), &txdesc,
  1970. sizeof(txdesc));
  1971. skb_queue_tail(&local->sta_tx_exc_list, skb);
  1972. tasklet_schedule(&local->sta_tx_exc_tasklet);
  1973. }
  1974. }
  1975. if (txdesc.sw_support)
  1976. hostap_tx_callback(local, &txdesc, 0, payload);
  1977. kfree(payload);
  1978. if (!show_dump)
  1979. return;
  1980. PDEBUG(DEBUG_EXTRA, "%s: TXEXC - status=0x%04x (%s%s%s%s)"
  1981. " tx_control=%04x\n",
  1982. dev->name, status,
  1983. status & HFA384X_TX_STATUS_RETRYERR ? "[RetryErr]" : "",
  1984. status & HFA384X_TX_STATUS_AGEDERR ? "[AgedErr]" : "",
  1985. status & HFA384X_TX_STATUS_DISCON ? "[Discon]" : "",
  1986. status & HFA384X_TX_STATUS_FORMERR ? "[FormErr]" : "",
  1987. le16_to_cpu(txdesc.tx_control));
  1988. fc = le16_to_cpu(txdesc.frame_control);
  1989. PDEBUG(DEBUG_EXTRA, " retry_count=%d tx_rate=%d fc=0x%04x "
  1990. "(%s%s%s::%d%s%s)\n",
  1991. txdesc.retry_count, txdesc.tx_rate, fc,
  1992. HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT ? "Mgmt" : "",
  1993. HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_CTRL ? "Ctrl" : "",
  1994. HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA ? "Data" : "",
  1995. HOSTAP_FC_GET_STYPE(fc),
  1996. fc & WLAN_FC_TODS ? " ToDS" : "",
  1997. fc & WLAN_FC_FROMDS ? " FromDS" : "");
  1998. PDEBUG(DEBUG_EXTRA, " A1=" MACSTR " A2=" MACSTR " A3="
  1999. MACSTR " A4=" MACSTR "\n",
  2000. MAC2STR(txdesc.addr1), MAC2STR(txdesc.addr2),
  2001. MAC2STR(txdesc.addr3), MAC2STR(txdesc.addr4));
  2002. }
  2003. /* Called only as a tasklet (software IRQ) */
  2004. static void hostap_info_tasklet(unsigned long data)
  2005. {
  2006. local_info_t *local = (local_info_t *) data;
  2007. struct sk_buff *skb;
  2008. while ((skb = skb_dequeue(&local->info_list)) != NULL) {
  2009. hostap_info_process(local, skb);
  2010. dev_kfree_skb(skb);
  2011. }
  2012. }
  2013. /* Called only as a tasklet (software IRQ) */
  2014. static void prism2_info(local_info_t *local)
  2015. {
  2016. struct net_device *dev = local->dev;
  2017. u16 fid;
  2018. int res, left;
  2019. struct hfa384x_info_frame info;
  2020. struct sk_buff *skb;
  2021. fid = HFA384X_INW(HFA384X_INFOFID_OFF);
  2022. spin_lock(&local->baplock);
  2023. res = hfa384x_setup_bap(dev, BAP0, fid, 0);
  2024. if (!res)
  2025. res = hfa384x_from_bap(dev, BAP0, &info, sizeof(info));
  2026. if (res) {
  2027. spin_unlock(&local->baplock);
  2028. printk(KERN_DEBUG "Could not get info frame (fid=0x%04x)\n",
  2029. fid);
  2030. if (res == -ETIMEDOUT) {
  2031. schedule_work(&local->reset_queue);
  2032. }
  2033. goto out;
  2034. }
  2035. le16_to_cpus(&info.len);
  2036. le16_to_cpus(&info.type);
  2037. left = (info.len - 1) * 2;
  2038. if (info.len & 0x8000 || info.len == 0 || left > 2060) {
  2039. /* data register seems to give 0x8000 in some error cases even
  2040. * though busy bit is not set in offset register;
  2041. * in addition, length must be at least 1 due to type field */
  2042. spin_unlock(&local->baplock);
  2043. printk(KERN_DEBUG "%s: Received info frame with invalid "
  2044. "length 0x%04x (type 0x%04x)\n", dev->name, info.len,
  2045. info.type);
  2046. goto out;
  2047. }
  2048. skb = dev_alloc_skb(sizeof(info) + left);
  2049. if (skb == NULL) {
  2050. spin_unlock(&local->baplock);
  2051. printk(KERN_DEBUG "%s: Could not allocate skb for info "
  2052. "frame\n", dev->name);
  2053. goto out;
  2054. }
  2055. memcpy(skb_put(skb, sizeof(info)), &info, sizeof(info));
  2056. if (left > 0 && hfa384x_from_bap(dev, BAP0, skb_put(skb, left), left))
  2057. {
  2058. spin_unlock(&local->baplock);
  2059. printk(KERN_WARNING "%s: Info frame read failed (fid=0x%04x, "
  2060. "len=0x%04x, type=0x%04x\n",
  2061. dev->name, fid, info.len, info.type);
  2062. dev_kfree_skb(skb);
  2063. goto out;
  2064. }
  2065. spin_unlock(&local->baplock);
  2066. skb_queue_tail(&local->info_list, skb);
  2067. tasklet_schedule(&local->info_tasklet);
  2068. out:
  2069. HFA384X_OUTW(HFA384X_EV_INFO, HFA384X_EVACK_OFF);
  2070. }
  2071. /* Called only as a tasklet (software IRQ) */
  2072. static void hostap_bap_tasklet(unsigned long data)
  2073. {
  2074. local_info_t *local = (local_info_t *) data;
  2075. struct net_device *dev = local->dev;
  2076. u16 ev;
  2077. int frames = 30;
  2078. if (local->func->card_present && !local->func->card_present(local))
  2079. return;
  2080. set_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
  2081. /* Process all pending BAP events without generating new interrupts
  2082. * for them */
  2083. while (frames-- > 0) {
  2084. ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2085. if (ev == 0xffff || !(ev & HFA384X_BAP0_EVENTS))
  2086. break;
  2087. if (ev & HFA384X_EV_RX)
  2088. prism2_rx(local);
  2089. if (ev & HFA384X_EV_INFO)
  2090. prism2_info(local);
  2091. if (ev & HFA384X_EV_TX)
  2092. prism2_tx_ev(local);
  2093. if (ev & HFA384X_EV_TXEXC)
  2094. prism2_txexc(local);
  2095. }
  2096. set_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
  2097. clear_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
  2098. /* Enable interrupts for new BAP events */
  2099. hfa384x_events_all(dev);
  2100. clear_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
  2101. }
  2102. /* Called only from hardware IRQ */
  2103. static void prism2_infdrop(struct net_device *dev)
  2104. {
  2105. static unsigned long last_inquire = 0;
  2106. PDEBUG(DEBUG_EXTRA, "%s: INFDROP event\n", dev->name);
  2107. /* some firmware versions seem to get stuck with
  2108. * full CommTallies in high traffic load cases; every
  2109. * packet will then cause INFDROP event and CommTallies
  2110. * info frame will not be sent automatically. Try to
  2111. * get out of this state by inquiring CommTallies. */
  2112. if (!last_inquire || time_after(jiffies, last_inquire + HZ)) {
  2113. hfa384x_cmd_callback(dev, HFA384X_CMDCODE_INQUIRE,
  2114. HFA384X_INFO_COMMTALLIES, NULL, 0);
  2115. last_inquire = jiffies;
  2116. }
  2117. }
  2118. /* Called only from hardware IRQ */
  2119. static void prism2_ev_tick(struct net_device *dev)
  2120. {
  2121. struct hostap_interface *iface;
  2122. local_info_t *local;
  2123. u16 evstat, inten;
  2124. static int prev_stuck = 0;
  2125. iface = netdev_priv(dev);
  2126. local = iface->local;
  2127. if (time_after(jiffies, local->last_tick_timer + 5 * HZ) &&
  2128. local->last_tick_timer) {
  2129. evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2130. inten = HFA384X_INW(HFA384X_INTEN_OFF);
  2131. if (!prev_stuck) {
  2132. printk(KERN_INFO "%s: SW TICK stuck? "
  2133. "bits=0x%lx EvStat=%04x IntEn=%04x\n",
  2134. dev->name, local->bits, evstat, inten);
  2135. }
  2136. local->sw_tick_stuck++;
  2137. if ((evstat & HFA384X_BAP0_EVENTS) &&
  2138. (inten & HFA384X_BAP0_EVENTS)) {
  2139. printk(KERN_INFO "%s: trying to recover from IRQ "
  2140. "hang\n", dev->name);
  2141. hfa384x_events_no_bap0(dev);
  2142. }
  2143. prev_stuck = 1;
  2144. } else
  2145. prev_stuck = 0;
  2146. }
  2147. /* Called only from hardware IRQ */
  2148. static inline void prism2_check_magic(local_info_t *local)
  2149. {
  2150. /* at least PCI Prism2.5 with bus mastering seems to sometimes
  2151. * return 0x0000 in SWSUPPORT0 for unknown reason, but re-reading the
  2152. * register once or twice seems to get the correct value.. PCI cards
  2153. * cannot anyway be removed during normal operation, so there is not
  2154. * really any need for this verification with them. */
  2155. #ifndef PRISM2_PCI
  2156. #ifndef final_version
  2157. static unsigned long last_magic_err = 0;
  2158. struct net_device *dev = local->dev;
  2159. if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
  2160. if (!local->hw_ready)
  2161. return;
  2162. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  2163. if (time_after(jiffies, last_magic_err + 10 * HZ)) {
  2164. printk("%s: Interrupt, but SWSUPPORT0 does not match: "
  2165. "%04X != %04X - card removed?\n", dev->name,
  2166. HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
  2167. HFA384X_MAGIC);
  2168. last_magic_err = jiffies;
  2169. } else if (net_ratelimit()) {
  2170. printk(KERN_DEBUG "%s: interrupt - SWSUPPORT0=%04x "
  2171. "MAGIC=%04x\n", dev->name,
  2172. HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
  2173. HFA384X_MAGIC);
  2174. }
  2175. if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != 0xffff)
  2176. schedule_work(&local->reset_queue);
  2177. return;
  2178. }
  2179. #endif /* final_version */
  2180. #endif /* !PRISM2_PCI */
  2181. }
  2182. /* Called only from hardware IRQ */
  2183. static irqreturn_t prism2_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  2184. {
  2185. struct net_device *dev = (struct net_device *) dev_id;
  2186. struct hostap_interface *iface;
  2187. local_info_t *local;
  2188. int events = 0;
  2189. u16 ev;
  2190. iface = netdev_priv(dev);
  2191. local = iface->local;
  2192. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 0);
  2193. if (local->func->card_present && !local->func->card_present(local)) {
  2194. if (net_ratelimit()) {
  2195. printk(KERN_DEBUG "%s: Interrupt, but dev not OK\n",
  2196. dev->name);
  2197. }
  2198. return IRQ_HANDLED;
  2199. }
  2200. prism2_check_magic(local);
  2201. for (;;) {
  2202. ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2203. if (ev == 0xffff) {
  2204. if (local->shutdown)
  2205. return IRQ_HANDLED;
  2206. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  2207. printk(KERN_DEBUG "%s: prism2_interrupt: ev=0xffff\n",
  2208. dev->name);
  2209. return IRQ_HANDLED;
  2210. }
  2211. ev &= HFA384X_INW(HFA384X_INTEN_OFF);
  2212. if (ev == 0)
  2213. break;
  2214. if (ev & HFA384X_EV_CMD) {
  2215. prism2_cmd_ev(dev);
  2216. }
  2217. /* Above events are needed even before hw is ready, but other
  2218. * events should be skipped during initialization. This may
  2219. * change for AllocEv if allocate_fid is implemented without
  2220. * busy waiting. */
  2221. if (!local->hw_ready || local->hw_resetting ||
  2222. !local->dev_enabled) {
  2223. ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2224. if (ev & HFA384X_EV_CMD)
  2225. goto next_event;
  2226. if ((ev & HFA384X_EVENT_MASK) == 0)
  2227. return IRQ_HANDLED;
  2228. if (local->dev_enabled && (ev & ~HFA384X_EV_TICK) &&
  2229. net_ratelimit()) {
  2230. printk(KERN_DEBUG "%s: prism2_interrupt: hw "
  2231. "not ready; skipping events 0x%04x "
  2232. "(IntEn=0x%04x)%s%s%s\n",
  2233. dev->name, ev,
  2234. HFA384X_INW(HFA384X_INTEN_OFF),
  2235. !local->hw_ready ? " (!hw_ready)" : "",
  2236. local->hw_resetting ?
  2237. " (hw_resetting)" : "",
  2238. !local->dev_enabled ?
  2239. " (!dev_enabled)" : "");
  2240. }
  2241. HFA384X_OUTW(ev, HFA384X_EVACK_OFF);
  2242. return IRQ_HANDLED;
  2243. }
  2244. if (ev & HFA384X_EV_TICK) {
  2245. prism2_ev_tick(dev);
  2246. HFA384X_OUTW(HFA384X_EV_TICK, HFA384X_EVACK_OFF);
  2247. }
  2248. if (ev & HFA384X_EV_ALLOC) {
  2249. prism2_alloc_ev(dev);
  2250. HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
  2251. }
  2252. /* Reading data from the card is quite time consuming, so do it
  2253. * in tasklets. TX, TXEXC, RX, and INFO events will be ACKed
  2254. * and unmasked after needed data has been read completely. */
  2255. if (ev & HFA384X_BAP0_EVENTS) {
  2256. hfa384x_events_no_bap0(dev);
  2257. tasklet_schedule(&local->bap_tasklet);
  2258. }
  2259. #ifndef final_version
  2260. if (ev & HFA384X_EV_WTERR) {
  2261. PDEBUG(DEBUG_EXTRA, "%s: WTERR event\n", dev->name);
  2262. HFA384X_OUTW(HFA384X_EV_WTERR, HFA384X_EVACK_OFF);
  2263. }
  2264. #endif /* final_version */
  2265. if (ev & HFA384X_EV_INFDROP) {
  2266. prism2_infdrop(dev);
  2267. HFA384X_OUTW(HFA384X_EV_INFDROP, HFA384X_EVACK_OFF);
  2268. }
  2269. next_event:
  2270. events++;
  2271. if (events >= PRISM2_MAX_INTERRUPT_EVENTS) {
  2272. PDEBUG(DEBUG_EXTRA, "prism2_interrupt: >%d events "
  2273. "(EvStat=0x%04x)\n",
  2274. PRISM2_MAX_INTERRUPT_EVENTS,
  2275. HFA384X_INW(HFA384X_EVSTAT_OFF));
  2276. break;
  2277. }
  2278. }
  2279. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 1);
  2280. return IRQ_RETVAL(events);
  2281. }
  2282. static void prism2_check_sta_fw_version(local_info_t *local)
  2283. {
  2284. struct hfa384x_comp_ident comp;
  2285. int id, variant, major, minor;
  2286. if (hfa384x_get_rid(local->dev, HFA384X_RID_STAID,
  2287. &comp, sizeof(comp), 1) < 0)
  2288. return;
  2289. local->fw_ap = 0;
  2290. id = le16_to_cpu(comp.id);
  2291. if (id != HFA384X_COMP_ID_STA) {
  2292. if (id == HFA384X_COMP_ID_FW_AP)
  2293. local->fw_ap = 1;
  2294. return;
  2295. }
  2296. major = __le16_to_cpu(comp.major);
  2297. minor = __le16_to_cpu(comp.minor);
  2298. variant = __le16_to_cpu(comp.variant);
  2299. local->sta_fw_ver = PRISM2_FW_VER(major, minor, variant);
  2300. /* Station firmware versions before 1.4.x seem to have a bug in
  2301. * firmware-based WEP encryption when using Host AP mode, so use
  2302. * host_encrypt as a default for them. Firmware version 1.4.9 is the
  2303. * first one that has been seen to produce correct encryption, but the
  2304. * bug might be fixed before that (although, at least 1.4.2 is broken).
  2305. */
  2306. local->fw_encrypt_ok = local->sta_fw_ver >= PRISM2_FW_VER(1,4,9);
  2307. if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
  2308. !local->fw_encrypt_ok) {
  2309. printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
  2310. "a workaround for firmware bug in Host AP mode WEP\n",
  2311. local->dev->name);
  2312. local->host_encrypt = 1;
  2313. }
  2314. /* IEEE 802.11 standard compliant WDS frames (4 addresses) were broken
  2315. * in station firmware versions before 1.5.x. With these versions, the
  2316. * driver uses a workaround with bogus frame format (4th address after
  2317. * the payload). This is not compatible with other AP devices. Since
  2318. * the firmware bug is fixed in the latest station firmware versions,
  2319. * automatically enable standard compliant mode for cards using station
  2320. * firmware version 1.5.0 or newer. */
  2321. if (local->sta_fw_ver >= PRISM2_FW_VER(1,5,0))
  2322. local->wds_type |= HOSTAP_WDS_STANDARD_FRAME;
  2323. else {
  2324. printk(KERN_DEBUG "%s: defaulting to bogus WDS frame as a "
  2325. "workaround for firmware bug in Host AP mode WDS\n",
  2326. local->dev->name);
  2327. }
  2328. hostap_check_sta_fw_version(local->ap, local->sta_fw_ver);
  2329. }
  2330. static void prism2_crypt_deinit_entries(local_info_t *local, int force)
  2331. {
  2332. struct list_head *ptr, *n;
  2333. struct ieee80211_crypt_data *entry;
  2334. for (ptr = local->crypt_deinit_list.next, n = ptr->next;
  2335. ptr != &local->crypt_deinit_list; ptr = n, n = ptr->next) {
  2336. entry = list_entry(ptr, struct ieee80211_crypt_data, list);
  2337. if (atomic_read(&entry->refcnt) != 0 && !force)
  2338. continue;
  2339. list_del(ptr);
  2340. if (entry->ops)
  2341. entry->ops->deinit(entry->priv);
  2342. kfree(entry);
  2343. }
  2344. }
  2345. static void prism2_crypt_deinit_handler(unsigned long data)
  2346. {
  2347. local_info_t *local = (local_info_t *) data;
  2348. unsigned long flags;
  2349. spin_lock_irqsave(&local->lock, flags);
  2350. prism2_crypt_deinit_entries(local, 0);
  2351. if (!list_empty(&local->crypt_deinit_list)) {
  2352. printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
  2353. "deletion list\n", local->dev->name);
  2354. local->crypt_deinit_timer.expires = jiffies + HZ;
  2355. add_timer(&local->crypt_deinit_timer);
  2356. }
  2357. spin_unlock_irqrestore(&local->lock, flags);
  2358. }
  2359. static void hostap_passive_scan(unsigned long data)
  2360. {
  2361. local_info_t *local = (local_info_t *) data;
  2362. struct net_device *dev = local->dev;
  2363. u16 channel;
  2364. if (local->passive_scan_interval <= 0)
  2365. return;
  2366. if (local->passive_scan_state == PASSIVE_SCAN_LISTEN) {
  2367. int max_tries = 16;
  2368. /* Even though host system does not really know when the WLAN
  2369. * MAC is sending frames, try to avoid changing channels for
  2370. * passive scanning when a host-generated frame is being
  2371. * transmitted */
  2372. if (test_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  2373. printk(KERN_DEBUG "%s: passive scan detected pending "
  2374. "TX - delaying\n", dev->name);
  2375. local->passive_scan_timer.expires = jiffies + HZ / 10;
  2376. add_timer(&local->passive_scan_timer);
  2377. return;
  2378. }
  2379. do {
  2380. local->passive_scan_channel++;
  2381. if (local->passive_scan_channel > 14)
  2382. local->passive_scan_channel = 1;
  2383. max_tries--;
  2384. } while (!(local->channel_mask &
  2385. (1 << (local->passive_scan_channel - 1))) &&
  2386. max_tries > 0);
  2387. if (max_tries == 0) {
  2388. printk(KERN_INFO "%s: no allowed passive scan channels"
  2389. " found\n", dev->name);
  2390. return;
  2391. }
  2392. printk(KERN_DEBUG "%s: passive scan channel %d\n",
  2393. dev->name, local->passive_scan_channel);
  2394. channel = local->passive_scan_channel;
  2395. local->passive_scan_state = PASSIVE_SCAN_WAIT;
  2396. local->passive_scan_timer.expires = jiffies + HZ / 10;
  2397. } else {
  2398. channel = local->channel;
  2399. local->passive_scan_state = PASSIVE_SCAN_LISTEN;
  2400. local->passive_scan_timer.expires = jiffies +
  2401. local->passive_scan_interval * HZ;
  2402. }
  2403. if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_TEST |
  2404. (HFA384X_TEST_CHANGE_CHANNEL << 8),
  2405. channel, NULL, 0))
  2406. printk(KERN_ERR "%s: passive scan channel set %d "
  2407. "failed\n", dev->name, channel);
  2408. add_timer(&local->passive_scan_timer);
  2409. }
  2410. /* Called only as a scheduled task when communications quality values should
  2411. * be updated. */
  2412. static void handle_comms_qual_update(void *data)
  2413. {
  2414. local_info_t *local = data;
  2415. prism2_update_comms_qual(local->dev);
  2416. }
  2417. /* Software watchdog - called as a timer. Hardware interrupt (Tick event) is
  2418. * used to monitor that local->last_tick_timer is being updated. If not,
  2419. * interrupt busy-loop is assumed and driver tries to recover by masking out
  2420. * some events. */
  2421. static void hostap_tick_timer(unsigned long data)
  2422. {
  2423. static unsigned long last_inquire = 0;
  2424. local_info_t *local = (local_info_t *) data;
  2425. local->last_tick_timer = jiffies;
  2426. /* Inquire CommTallies every 10 seconds to keep the statistics updated
  2427. * more often during low load and when using 32-bit tallies. */
  2428. if ((!last_inquire || time_after(jiffies, last_inquire + 10 * HZ)) &&
  2429. !local->hw_downloading && local->hw_ready &&
  2430. !local->hw_resetting && local->dev_enabled) {
  2431. hfa384x_cmd_callback(local->dev, HFA384X_CMDCODE_INQUIRE,
  2432. HFA384X_INFO_COMMTALLIES, NULL, 0);
  2433. last_inquire = jiffies;
  2434. }
  2435. if ((local->last_comms_qual_update == 0 ||
  2436. time_after(jiffies, local->last_comms_qual_update + 10 * HZ)) &&
  2437. (local->iw_mode == IW_MODE_INFRA ||
  2438. local->iw_mode == IW_MODE_ADHOC)) {
  2439. schedule_work(&local->comms_qual_update);
  2440. }
  2441. local->tick_timer.expires = jiffies + 2 * HZ;
  2442. add_timer(&local->tick_timer);
  2443. }
  2444. #ifndef PRISM2_NO_PROCFS_DEBUG
  2445. static int prism2_registers_proc_read(char *page, char **start, off_t off,
  2446. int count, int *eof, void *data)
  2447. {
  2448. char *p = page;
  2449. local_info_t *local = (local_info_t *) data;
  2450. if (off != 0) {
  2451. *eof = 1;
  2452. return 0;
  2453. }
  2454. #define SHOW_REG(n) \
  2455. p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF))
  2456. SHOW_REG(CMD);
  2457. SHOW_REG(PARAM0);
  2458. SHOW_REG(PARAM1);
  2459. SHOW_REG(PARAM2);
  2460. SHOW_REG(STATUS);
  2461. SHOW_REG(RESP0);
  2462. SHOW_REG(RESP1);
  2463. SHOW_REG(RESP2);
  2464. SHOW_REG(INFOFID);
  2465. SHOW_REG(CONTROL);
  2466. SHOW_REG(SELECT0);
  2467. SHOW_REG(SELECT1);
  2468. SHOW_REG(OFFSET0);
  2469. SHOW_REG(OFFSET1);
  2470. SHOW_REG(RXFID);
  2471. SHOW_REG(ALLOCFID);
  2472. SHOW_REG(TXCOMPLFID);
  2473. SHOW_REG(SWSUPPORT0);
  2474. SHOW_REG(SWSUPPORT1);
  2475. SHOW_REG(SWSUPPORT2);
  2476. SHOW_REG(EVSTAT);
  2477. SHOW_REG(INTEN);
  2478. SHOW_REG(EVACK);
  2479. /* Do not read data registers, because they change the state of the
  2480. * MAC (offset += 2) */
  2481. /* SHOW_REG(DATA0); */
  2482. /* SHOW_REG(DATA1); */
  2483. SHOW_REG(AUXPAGE);
  2484. SHOW_REG(AUXOFFSET);
  2485. /* SHOW_REG(AUXDATA); */
  2486. #ifdef PRISM2_PCI
  2487. SHOW_REG(PCICOR);
  2488. SHOW_REG(PCIHCR);
  2489. SHOW_REG(PCI_M0_ADDRH);
  2490. SHOW_REG(PCI_M0_ADDRL);
  2491. SHOW_REG(PCI_M0_LEN);
  2492. SHOW_REG(PCI_M0_CTL);
  2493. SHOW_REG(PCI_STATUS);
  2494. SHOW_REG(PCI_M1_ADDRH);
  2495. SHOW_REG(PCI_M1_ADDRL);
  2496. SHOW_REG(PCI_M1_LEN);
  2497. SHOW_REG(PCI_M1_CTL);
  2498. #endif /* PRISM2_PCI */
  2499. return (p - page);
  2500. }
  2501. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2502. struct set_tim_data {
  2503. struct list_head list;
  2504. int aid;
  2505. int set;
  2506. };
  2507. static int prism2_set_tim(struct net_device *dev, int aid, int set)
  2508. {
  2509. struct list_head *ptr;
  2510. struct set_tim_data *new_entry;
  2511. struct hostap_interface *iface;
  2512. local_info_t *local;
  2513. iface = netdev_priv(dev);
  2514. local = iface->local;
  2515. new_entry = (struct set_tim_data *)
  2516. kmalloc(sizeof(*new_entry), GFP_ATOMIC);
  2517. if (new_entry == NULL) {
  2518. printk(KERN_DEBUG "%s: prism2_set_tim: kmalloc failed\n",
  2519. local->dev->name);
  2520. return -ENOMEM;
  2521. }
  2522. memset(new_entry, 0, sizeof(*new_entry));
  2523. new_entry->aid = aid;
  2524. new_entry->set = set;
  2525. spin_lock_bh(&local->set_tim_lock);
  2526. list_for_each(ptr, &local->set_tim_list) {
  2527. struct set_tim_data *entry =
  2528. list_entry(ptr, struct set_tim_data, list);
  2529. if (entry->aid == aid) {
  2530. PDEBUG(DEBUG_PS2, "%s: prism2_set_tim: aid=%d "
  2531. "set=%d ==> %d\n",
  2532. local->dev->name, aid, entry->set, set);
  2533. entry->set = set;
  2534. kfree(new_entry);
  2535. new_entry = NULL;
  2536. break;
  2537. }
  2538. }
  2539. if (new_entry)
  2540. list_add_tail(&new_entry->list, &local->set_tim_list);
  2541. spin_unlock_bh(&local->set_tim_lock);
  2542. schedule_work(&local->set_tim_queue);
  2543. return 0;
  2544. }
  2545. static void handle_set_tim_queue(void *data)
  2546. {
  2547. local_info_t *local = (local_info_t *) data;
  2548. struct set_tim_data *entry;
  2549. u16 val;
  2550. for (;;) {
  2551. entry = NULL;
  2552. spin_lock_bh(&local->set_tim_lock);
  2553. if (!list_empty(&local->set_tim_list)) {
  2554. entry = list_entry(local->set_tim_list.next,
  2555. struct set_tim_data, list);
  2556. list_del(&entry->list);
  2557. }
  2558. spin_unlock_bh(&local->set_tim_lock);
  2559. if (!entry)
  2560. break;
  2561. PDEBUG(DEBUG_PS2, "%s: handle_set_tim_queue: aid=%d set=%d\n",
  2562. local->dev->name, entry->aid, entry->set);
  2563. val = entry->aid;
  2564. if (entry->set)
  2565. val |= 0x8000;
  2566. if (hostap_set_word(local->dev, HFA384X_RID_CNFTIMCTRL, val)) {
  2567. printk(KERN_DEBUG "%s: set_tim failed (aid=%d "
  2568. "set=%d)\n",
  2569. local->dev->name, entry->aid, entry->set);
  2570. }
  2571. kfree(entry);
  2572. }
  2573. }
  2574. static void prism2_clear_set_tim_queue(local_info_t *local)
  2575. {
  2576. struct list_head *ptr, *n;
  2577. list_for_each_safe(ptr, n, &local->set_tim_list) {
  2578. struct set_tim_data *entry;
  2579. entry = list_entry(ptr, struct set_tim_data, list);
  2580. list_del(&entry->list);
  2581. kfree(entry);
  2582. }
  2583. }
  2584. static struct net_device *
  2585. prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx,
  2586. struct device *sdev)
  2587. {
  2588. struct net_device *dev;
  2589. struct hostap_interface *iface;
  2590. struct local_info *local;
  2591. int len, i, ret;
  2592. if (funcs == NULL)
  2593. return NULL;
  2594. len = strlen(dev_template);
  2595. if (len >= IFNAMSIZ || strstr(dev_template, "%d") == NULL) {
  2596. printk(KERN_WARNING "hostap: Invalid dev_template='%s'\n",
  2597. dev_template);
  2598. return NULL;
  2599. }
  2600. len = sizeof(struct hostap_interface) +
  2601. 3 + sizeof(struct local_info) +
  2602. 3 + sizeof(struct ap_data);
  2603. dev = alloc_etherdev(len);
  2604. if (dev == NULL)
  2605. return NULL;
  2606. iface = netdev_priv(dev);
  2607. local = (struct local_info *) ((((long) (iface + 1)) + 3) & ~3);
  2608. local->ap = (struct ap_data *) ((((long) (local + 1)) + 3) & ~3);
  2609. local->dev = iface->dev = dev;
  2610. iface->local = local;
  2611. iface->type = HOSTAP_INTERFACE_MASTER;
  2612. INIT_LIST_HEAD(&local->hostap_interfaces);
  2613. local->hw_module = THIS_MODULE;
  2614. #ifdef PRISM2_IO_DEBUG
  2615. local->io_debug_enabled = 1;
  2616. #endif /* PRISM2_IO_DEBUG */
  2617. local->func = funcs;
  2618. local->func->cmd = hfa384x_cmd;
  2619. local->func->read_regs = hfa384x_read_regs;
  2620. local->func->get_rid = hfa384x_get_rid;
  2621. local->func->set_rid = hfa384x_set_rid;
  2622. local->func->hw_enable = prism2_hw_enable;
  2623. local->func->hw_config = prism2_hw_config;
  2624. local->func->hw_reset = prism2_hw_reset;
  2625. local->func->hw_shutdown = prism2_hw_shutdown;
  2626. local->func->reset_port = prism2_reset_port;
  2627. local->func->schedule_reset = prism2_schedule_reset;
  2628. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2629. local->func->read_aux = prism2_download_aux_dump;
  2630. local->func->download = prism2_download;
  2631. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2632. local->func->tx = prism2_tx_80211;
  2633. local->func->set_tim = prism2_set_tim;
  2634. local->func->need_tx_headroom = 0; /* no need to add txdesc in
  2635. * skb->data (FIX: maybe for DMA bus
  2636. * mastering? */
  2637. local->mtu = mtu;
  2638. rwlock_init(&local->iface_lock);
  2639. spin_lock_init(&local->txfidlock);
  2640. spin_lock_init(&local->cmdlock);
  2641. spin_lock_init(&local->baplock);
  2642. spin_lock_init(&local->lock);
  2643. init_MUTEX(&local->rid_bap_sem);
  2644. if (card_idx < 0 || card_idx >= MAX_PARM_DEVICES)
  2645. card_idx = 0;
  2646. local->card_idx = card_idx;
  2647. len = strlen(essid);
  2648. memcpy(local->essid, essid,
  2649. len > MAX_SSID_LEN ? MAX_SSID_LEN : len);
  2650. local->essid[MAX_SSID_LEN] = '\0';
  2651. i = GET_INT_PARM(iw_mode, card_idx);
  2652. if ((i >= IW_MODE_ADHOC && i <= IW_MODE_REPEAT) ||
  2653. i == IW_MODE_MONITOR) {
  2654. local->iw_mode = i;
  2655. } else {
  2656. printk(KERN_WARNING "prism2: Unknown iw_mode %d; using "
  2657. "IW_MODE_MASTER\n", i);
  2658. local->iw_mode = IW_MODE_MASTER;
  2659. }
  2660. local->channel = GET_INT_PARM(channel, card_idx);
  2661. local->beacon_int = GET_INT_PARM(beacon_int, card_idx);
  2662. local->dtim_period = GET_INT_PARM(dtim_period, card_idx);
  2663. local->wds_max_connections = 16;
  2664. local->tx_control = HFA384X_TX_CTRL_FLAGS;
  2665. local->manual_retry_count = -1;
  2666. local->rts_threshold = 2347;
  2667. local->fragm_threshold = 2346;
  2668. local->rssi_to_dBm = 100; /* default; to be overriden by
  2669. * cnfDbmAdjust, if available */
  2670. local->auth_algs = PRISM2_AUTH_OPEN | PRISM2_AUTH_SHARED_KEY;
  2671. local->sram_type = -1;
  2672. local->scan_channel_mask = 0xffff;
  2673. /* Initialize task queue structures */
  2674. INIT_WORK(&local->reset_queue, handle_reset_queue, local);
  2675. INIT_WORK(&local->set_multicast_list_queue,
  2676. hostap_set_multicast_list_queue, local->dev);
  2677. INIT_WORK(&local->set_tim_queue, handle_set_tim_queue, local);
  2678. INIT_LIST_HEAD(&local->set_tim_list);
  2679. spin_lock_init(&local->set_tim_lock);
  2680. INIT_WORK(&local->comms_qual_update, handle_comms_qual_update, local);
  2681. /* Initialize tasklets for handling hardware IRQ related operations
  2682. * outside hw IRQ handler */
  2683. #define HOSTAP_TASKLET_INIT(q, f, d) \
  2684. do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \
  2685. while (0)
  2686. HOSTAP_TASKLET_INIT(&local->bap_tasklet, hostap_bap_tasklet,
  2687. (unsigned long) local);
  2688. HOSTAP_TASKLET_INIT(&local->info_tasklet, hostap_info_tasklet,
  2689. (unsigned long) local);
  2690. hostap_info_init(local);
  2691. HOSTAP_TASKLET_INIT(&local->rx_tasklet,
  2692. hostap_rx_tasklet, (unsigned long) local);
  2693. skb_queue_head_init(&local->rx_list);
  2694. HOSTAP_TASKLET_INIT(&local->sta_tx_exc_tasklet,
  2695. hostap_sta_tx_exc_tasklet, (unsigned long) local);
  2696. skb_queue_head_init(&local->sta_tx_exc_list);
  2697. INIT_LIST_HEAD(&local->cmd_queue);
  2698. init_waitqueue_head(&local->hostscan_wq);
  2699. INIT_LIST_HEAD(&local->crypt_deinit_list);
  2700. init_timer(&local->crypt_deinit_timer);
  2701. local->crypt_deinit_timer.data = (unsigned long) local;
  2702. local->crypt_deinit_timer.function = prism2_crypt_deinit_handler;
  2703. init_timer(&local->passive_scan_timer);
  2704. local->passive_scan_timer.data = (unsigned long) local;
  2705. local->passive_scan_timer.function = hostap_passive_scan;
  2706. init_timer(&local->tick_timer);
  2707. local->tick_timer.data = (unsigned long) local;
  2708. local->tick_timer.function = hostap_tick_timer;
  2709. local->tick_timer.expires = jiffies + 2 * HZ;
  2710. add_timer(&local->tick_timer);
  2711. INIT_LIST_HEAD(&local->bss_list);
  2712. hostap_setup_dev(dev, local, 1);
  2713. local->saved_eth_header_parse = dev->hard_header_parse;
  2714. dev->hard_start_xmit = hostap_master_start_xmit;
  2715. dev->type = ARPHRD_IEEE80211;
  2716. dev->hard_header_parse = hostap_80211_header_parse;
  2717. rtnl_lock();
  2718. ret = dev_alloc_name(dev, "wifi%d");
  2719. SET_NETDEV_DEV(dev, sdev);
  2720. if (ret >= 0)
  2721. ret = register_netdevice(dev);
  2722. rtnl_unlock();
  2723. if (ret < 0) {
  2724. printk(KERN_WARNING "%s: register netdevice failed!\n",
  2725. dev_info);
  2726. goto fail;
  2727. }
  2728. printk(KERN_INFO "%s: Registered netdevice %s\n", dev_info, dev->name);
  2729. #ifndef PRISM2_NO_PROCFS_DEBUG
  2730. create_proc_read_entry("registers", 0, local->proc,
  2731. prism2_registers_proc_read, local);
  2732. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2733. hostap_init_data(local);
  2734. return dev;
  2735. fail:
  2736. free_netdev(dev);
  2737. return NULL;
  2738. }
  2739. static int hostap_hw_ready(struct net_device *dev)
  2740. {
  2741. struct hostap_interface *iface;
  2742. struct local_info *local;
  2743. iface = netdev_priv(dev);
  2744. local = iface->local;
  2745. local->ddev = hostap_add_interface(local, HOSTAP_INTERFACE_MAIN, 0,
  2746. "", dev_template);
  2747. if (local->ddev) {
  2748. if (local->iw_mode == IW_MODE_INFRA ||
  2749. local->iw_mode == IW_MODE_ADHOC) {
  2750. netif_carrier_off(local->dev);
  2751. netif_carrier_off(local->ddev);
  2752. }
  2753. hostap_init_proc(local);
  2754. hostap_init_ap_proc(local);
  2755. return 0;
  2756. }
  2757. return -1;
  2758. }
  2759. static void prism2_free_local_data(struct net_device *dev)
  2760. {
  2761. struct hostap_tx_callback_info *tx_cb, *tx_cb_prev;
  2762. int i;
  2763. struct hostap_interface *iface;
  2764. struct local_info *local;
  2765. struct list_head *ptr, *n;
  2766. if (dev == NULL)
  2767. return;
  2768. iface = netdev_priv(dev);
  2769. local = iface->local;
  2770. flush_scheduled_work();
  2771. if (timer_pending(&local->crypt_deinit_timer))
  2772. del_timer(&local->crypt_deinit_timer);
  2773. prism2_crypt_deinit_entries(local, 1);
  2774. if (timer_pending(&local->passive_scan_timer))
  2775. del_timer(&local->passive_scan_timer);
  2776. if (timer_pending(&local->tick_timer))
  2777. del_timer(&local->tick_timer);
  2778. prism2_clear_cmd_queue(local);
  2779. skb_queue_purge(&local->info_list);
  2780. skb_queue_purge(&local->rx_list);
  2781. skb_queue_purge(&local->sta_tx_exc_list);
  2782. if (local->dev_enabled)
  2783. prism2_callback(local, PRISM2_CALLBACK_DISABLE);
  2784. for (i = 0; i < WEP_KEYS; i++) {
  2785. struct ieee80211_crypt_data *crypt = local->crypt[i];
  2786. if (crypt) {
  2787. if (crypt->ops)
  2788. crypt->ops->deinit(crypt->priv);
  2789. kfree(crypt);
  2790. local->crypt[i] = NULL;
  2791. }
  2792. }
  2793. if (local->ap != NULL)
  2794. hostap_free_data(local->ap);
  2795. #ifndef PRISM2_NO_PROCFS_DEBUG
  2796. if (local->proc != NULL)
  2797. remove_proc_entry("registers", local->proc);
  2798. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2799. hostap_remove_proc(local);
  2800. tx_cb = local->tx_callback;
  2801. while (tx_cb != NULL) {
  2802. tx_cb_prev = tx_cb;
  2803. tx_cb = tx_cb->next;
  2804. kfree(tx_cb_prev);
  2805. }
  2806. hostap_set_hostapd(local, 0, 0);
  2807. hostap_set_hostapd_sta(local, 0, 0);
  2808. for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
  2809. if (local->frag_cache[i].skb != NULL)
  2810. dev_kfree_skb(local->frag_cache[i].skb);
  2811. }
  2812. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2813. prism2_download_free_data(local->dl_pri);
  2814. prism2_download_free_data(local->dl_sec);
  2815. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2816. list_for_each_safe(ptr, n, &local->hostap_interfaces) {
  2817. iface = list_entry(ptr, struct hostap_interface, list);
  2818. if (iface->type == HOSTAP_INTERFACE_MASTER) {
  2819. /* special handling for this interface below */
  2820. continue;
  2821. }
  2822. hostap_remove_interface(iface->dev, 0, 1);
  2823. }
  2824. prism2_clear_set_tim_queue(local);
  2825. list_for_each_safe(ptr, n, &local->bss_list) {
  2826. struct hostap_bss_info *bss =
  2827. list_entry(ptr, struct hostap_bss_info, list);
  2828. kfree(bss);
  2829. }
  2830. kfree(local->pda);
  2831. kfree(local->last_scan_results);
  2832. kfree(local->generic_elem);
  2833. unregister_netdev(local->dev);
  2834. free_netdev(local->dev);
  2835. }
  2836. #ifndef PRISM2_PLX
  2837. static void prism2_suspend(struct net_device *dev)
  2838. {
  2839. struct hostap_interface *iface;
  2840. struct local_info *local;
  2841. union iwreq_data wrqu;
  2842. iface = dev->priv;
  2843. local = iface->local;
  2844. /* Send disconnect event, e.g., to trigger reassociation after resume
  2845. * if wpa_supplicant is used. */
  2846. memset(&wrqu, 0, sizeof(wrqu));
  2847. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  2848. wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
  2849. /* Disable hardware and firmware */
  2850. prism2_hw_shutdown(dev, 0);
  2851. }
  2852. #endif /* PRISM2_PLX */
  2853. /* These might at some point be compiled separately and used as separate
  2854. * kernel modules or linked into one */
  2855. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2856. #include "hostap_download.c"
  2857. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2858. #ifdef PRISM2_CALLBACK
  2859. /* External hostap_callback.c file can be used to, e.g., blink activity led.
  2860. * This can use platform specific code and must define prism2_callback()
  2861. * function (if PRISM2_CALLBACK is not defined, these function calls are not
  2862. * used. */
  2863. #include "hostap_callback.c"
  2864. #endif /* PRISM2_CALLBACK */