hostap_hw.c 94 KB

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