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