hostap_hw.c 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458
  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. /* Some firmwares lose antenna selection settings on reset */
  877. (void) hostap_set_antsel(local);
  878. return res;
  879. }
  880. static int prism2_get_version_info(struct net_device *dev, u16 rid,
  881. const char *txt)
  882. {
  883. struct hfa384x_comp_ident comp;
  884. struct hostap_interface *iface;
  885. local_info_t *local;
  886. iface = netdev_priv(dev);
  887. local = iface->local;
  888. if (local->no_pri) {
  889. /* PRI f/w not yet available - cannot read RIDs */
  890. return -1;
  891. }
  892. if (hfa384x_get_rid(dev, rid, &comp, sizeof(comp), 1) < 0) {
  893. printk(KERN_DEBUG "Could not get RID for component %s\n", txt);
  894. return -1;
  895. }
  896. printk(KERN_INFO "%s: %s: id=0x%02x v%d.%d.%d\n", dev->name, txt,
  897. __le16_to_cpu(comp.id), __le16_to_cpu(comp.major),
  898. __le16_to_cpu(comp.minor), __le16_to_cpu(comp.variant));
  899. return 0;
  900. }
  901. static int prism2_setup_rids(struct net_device *dev)
  902. {
  903. struct hostap_interface *iface;
  904. local_info_t *local;
  905. u16 tmp;
  906. int ret = 0;
  907. iface = netdev_priv(dev);
  908. local = iface->local;
  909. hostap_set_word(dev, HFA384X_RID_TICKTIME, 2000);
  910. if (!local->fw_ap) {
  911. tmp = hostap_get_porttype(local);
  912. ret = hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, tmp);
  913. if (ret) {
  914. printk("%s: Port type setting to %d failed\n",
  915. dev->name, tmp);
  916. goto fail;
  917. }
  918. }
  919. /* Setting SSID to empty string seems to kill the card in Host AP mode
  920. */
  921. if (local->iw_mode != IW_MODE_MASTER || local->essid[0] != '\0') {
  922. ret = hostap_set_string(dev, HFA384X_RID_CNFOWNSSID,
  923. local->essid);
  924. if (ret) {
  925. printk("%s: AP own SSID setting failed\n", dev->name);
  926. goto fail;
  927. }
  928. }
  929. ret = hostap_set_word(dev, HFA384X_RID_CNFMAXDATALEN,
  930. PRISM2_DATA_MAXLEN);
  931. if (ret) {
  932. printk("%s: MAC data length setting to %d failed\n",
  933. dev->name, PRISM2_DATA_MAXLEN);
  934. goto fail;
  935. }
  936. if (hfa384x_get_rid(dev, HFA384X_RID_CHANNELLIST, &tmp, 2, 1) < 0) {
  937. printk("%s: Channel list read failed\n", dev->name);
  938. ret = -EINVAL;
  939. goto fail;
  940. }
  941. local->channel_mask = __le16_to_cpu(tmp);
  942. if (local->channel < 1 || local->channel > 14 ||
  943. !(local->channel_mask & (1 << (local->channel - 1)))) {
  944. printk(KERN_WARNING "%s: Channel setting out of range "
  945. "(%d)!\n", dev->name, local->channel);
  946. ret = -EBUSY;
  947. goto fail;
  948. }
  949. ret = hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel);
  950. if (ret) {
  951. printk("%s: Channel setting to %d failed\n",
  952. dev->name, local->channel);
  953. goto fail;
  954. }
  955. ret = hostap_set_word(dev, HFA384X_RID_CNFBEACONINT,
  956. local->beacon_int);
  957. if (ret) {
  958. printk("%s: Beacon interval setting to %d failed\n",
  959. dev->name, local->beacon_int);
  960. /* this may fail with Symbol/Lucent firmware */
  961. if (ret == -ETIMEDOUT)
  962. goto fail;
  963. }
  964. ret = hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD,
  965. local->dtim_period);
  966. if (ret) {
  967. printk("%s: DTIM period setting to %d failed\n",
  968. dev->name, local->dtim_period);
  969. /* this may fail with Symbol/Lucent firmware */
  970. if (ret == -ETIMEDOUT)
  971. goto fail;
  972. }
  973. ret = hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
  974. local->is_promisc);
  975. if (ret)
  976. printk(KERN_INFO "%s: Setting promiscuous mode (%d) failed\n",
  977. dev->name, local->is_promisc);
  978. if (!local->fw_ap) {
  979. ret = hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID,
  980. local->essid);
  981. if (ret) {
  982. printk("%s: Desired SSID setting failed\n", dev->name);
  983. goto fail;
  984. }
  985. }
  986. /* Setup TXRateControl, defaults to allow use of 1, 2, 5.5, and
  987. * 11 Mbps in automatic TX rate fallback and 1 and 2 Mbps as basic
  988. * rates */
  989. if (local->tx_rate_control == 0) {
  990. local->tx_rate_control =
  991. HFA384X_RATES_1MBPS |
  992. HFA384X_RATES_2MBPS |
  993. HFA384X_RATES_5MBPS |
  994. HFA384X_RATES_11MBPS;
  995. }
  996. if (local->basic_rates == 0)
  997. local->basic_rates = HFA384X_RATES_1MBPS | HFA384X_RATES_2MBPS;
  998. if (!local->fw_ap) {
  999. ret = hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
  1000. local->tx_rate_control);
  1001. if (ret) {
  1002. printk("%s: TXRateControl setting to %d failed\n",
  1003. dev->name, local->tx_rate_control);
  1004. goto fail;
  1005. }
  1006. ret = hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
  1007. local->tx_rate_control);
  1008. if (ret) {
  1009. printk("%s: cnfSupportedRates setting to %d failed\n",
  1010. dev->name, local->tx_rate_control);
  1011. }
  1012. ret = hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
  1013. local->basic_rates);
  1014. if (ret) {
  1015. printk("%s: cnfBasicRates setting to %d failed\n",
  1016. dev->name, local->basic_rates);
  1017. }
  1018. ret = hostap_set_word(dev, HFA384X_RID_CREATEIBSS, 1);
  1019. if (ret) {
  1020. printk("%s: Create IBSS setting to 1 failed\n",
  1021. dev->name);
  1022. }
  1023. }
  1024. if (local->name_set)
  1025. (void) hostap_set_string(dev, HFA384X_RID_CNFOWNNAME,
  1026. local->name);
  1027. if (hostap_set_encryption(local)) {
  1028. printk(KERN_INFO "%s: could not configure encryption\n",
  1029. dev->name);
  1030. }
  1031. (void) hostap_set_antsel(local);
  1032. if (hostap_set_roaming(local)) {
  1033. printk(KERN_INFO "%s: could not set host roaming\n",
  1034. dev->name);
  1035. }
  1036. if (local->sta_fw_ver >= PRISM2_FW_VER(1,6,3) &&
  1037. hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY, local->enh_sec))
  1038. printk(KERN_INFO "%s: cnfEnhSecurity setting to 0x%x failed\n",
  1039. dev->name, local->enh_sec);
  1040. /* 32-bit tallies were added in STA f/w 0.8.0, but they were apparently
  1041. * not working correctly (last seven counters report bogus values).
  1042. * This has been fixed in 0.8.2, so enable 32-bit tallies only
  1043. * beginning with that firmware version. Another bug fix for 32-bit
  1044. * tallies in 1.4.0; should 16-bit tallies be used for some other
  1045. * versions, too? */
  1046. if (local->sta_fw_ver >= PRISM2_FW_VER(0,8,2)) {
  1047. if (hostap_set_word(dev, HFA384X_RID_CNFTHIRTY2TALLY, 1)) {
  1048. printk(KERN_INFO "%s: cnfThirty2Tally setting "
  1049. "failed\n", dev->name);
  1050. local->tallies32 = 0;
  1051. } else
  1052. local->tallies32 = 1;
  1053. } else
  1054. local->tallies32 = 0;
  1055. hostap_set_auth_algs(local);
  1056. if (hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
  1057. local->fragm_threshold)) {
  1058. printk(KERN_INFO "%s: setting FragmentationThreshold to %d "
  1059. "failed\n", dev->name, local->fragm_threshold);
  1060. }
  1061. if (hostap_set_word(dev, HFA384X_RID_RTSTHRESHOLD,
  1062. local->rts_threshold)) {
  1063. printk(KERN_INFO "%s: setting RTSThreshold to %d failed\n",
  1064. dev->name, local->rts_threshold);
  1065. }
  1066. if (local->manual_retry_count >= 0 &&
  1067. hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
  1068. local->manual_retry_count)) {
  1069. printk(KERN_INFO "%s: setting cnfAltRetryCount to %d failed\n",
  1070. dev->name, local->manual_retry_count);
  1071. }
  1072. if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1) &&
  1073. hfa384x_get_rid(dev, HFA384X_RID_CNFDBMADJUST, &tmp, 2, 1) == 2) {
  1074. local->rssi_to_dBm = le16_to_cpu(tmp);
  1075. }
  1076. if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->wpa &&
  1077. hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1)) {
  1078. printk(KERN_INFO "%s: setting ssnHandlingMode to 1 failed\n",
  1079. dev->name);
  1080. }
  1081. if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->generic_elem &&
  1082. hfa384x_set_rid(dev, HFA384X_RID_GENERICELEMENT,
  1083. local->generic_elem, local->generic_elem_len)) {
  1084. printk(KERN_INFO "%s: setting genericElement failed\n",
  1085. dev->name);
  1086. }
  1087. fail:
  1088. return ret;
  1089. }
  1090. static int prism2_hw_init(struct net_device *dev, int initial)
  1091. {
  1092. struct hostap_interface *iface;
  1093. local_info_t *local;
  1094. int ret, first = 1;
  1095. unsigned long start, delay;
  1096. PDEBUG(DEBUG_FLOW, "prism2_hw_init()\n");
  1097. iface = netdev_priv(dev);
  1098. local = iface->local;
  1099. clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits);
  1100. init:
  1101. /* initialize HFA 384x */
  1102. ret = hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_INIT, 0);
  1103. if (ret) {
  1104. printk(KERN_INFO "%s: first command failed - assuming card "
  1105. "does not have primary firmware\n", dev_info);
  1106. }
  1107. if (first && (HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
  1108. /* EvStat has Cmd bit set in some cases, so retry once if no
  1109. * wait was needed */
  1110. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  1111. printk(KERN_DEBUG "%s: init command completed too quickly - "
  1112. "retrying\n", dev->name);
  1113. first = 0;
  1114. goto init;
  1115. }
  1116. start = jiffies;
  1117. delay = jiffies + HFA384X_INIT_TIMEOUT;
  1118. while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
  1119. time_before(jiffies, delay))
  1120. yield();
  1121. if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
  1122. printk(KERN_DEBUG "%s: assuming no Primary image in "
  1123. "flash - card initialization not completed\n",
  1124. dev_info);
  1125. local->no_pri = 1;
  1126. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1127. if (local->sram_type == -1)
  1128. local->sram_type = prism2_get_ram_size(local);
  1129. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1130. return 1;
  1131. }
  1132. local->no_pri = 0;
  1133. printk(KERN_DEBUG "prism2_hw_init: initialized in %lu ms\n",
  1134. (jiffies - start) * 1000 / HZ);
  1135. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  1136. return 0;
  1137. }
  1138. static int prism2_hw_init2(struct net_device *dev, int initial)
  1139. {
  1140. struct hostap_interface *iface;
  1141. local_info_t *local;
  1142. int i;
  1143. iface = netdev_priv(dev);
  1144. local = iface->local;
  1145. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1146. kfree(local->pda);
  1147. if (local->no_pri)
  1148. local->pda = NULL;
  1149. else
  1150. local->pda = prism2_read_pda(dev);
  1151. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1152. hfa384x_disable_interrupts(dev);
  1153. #ifndef final_version
  1154. HFA384X_OUTW(HFA384X_MAGIC, HFA384X_SWSUPPORT0_OFF);
  1155. if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
  1156. printk("SWSUPPORT0 write/read failed: %04X != %04X\n",
  1157. HFA384X_INW(HFA384X_SWSUPPORT0_OFF), HFA384X_MAGIC);
  1158. goto failed;
  1159. }
  1160. #endif
  1161. if (initial || local->pri_only) {
  1162. hfa384x_events_only_cmd(dev);
  1163. /* get card version information */
  1164. if (prism2_get_version_info(dev, HFA384X_RID_NICID, "NIC") ||
  1165. prism2_get_version_info(dev, HFA384X_RID_PRIID, "PRI")) {
  1166. hfa384x_disable_interrupts(dev);
  1167. goto failed;
  1168. }
  1169. if (prism2_get_version_info(dev, HFA384X_RID_STAID, "STA")) {
  1170. printk(KERN_DEBUG "%s: Failed to read STA f/w version "
  1171. "- only Primary f/w present\n", dev->name);
  1172. local->pri_only = 1;
  1173. return 0;
  1174. }
  1175. local->pri_only = 0;
  1176. hfa384x_disable_interrupts(dev);
  1177. }
  1178. /* FIX: could convert allocate_fid to use sleeping CmdCompl wait and
  1179. * enable interrupts before this. This would also require some sort of
  1180. * sleeping AllocEv waiting */
  1181. /* allocate TX FIDs */
  1182. local->txfid_len = PRISM2_TXFID_LEN;
  1183. for (i = 0; i < PRISM2_TXFID_COUNT; i++) {
  1184. local->txfid[i] = hfa384x_allocate_fid(dev, local->txfid_len);
  1185. if (local->txfid[i] == 0xffff && local->txfid_len > 1600) {
  1186. local->txfid[i] = hfa384x_allocate_fid(dev, 1600);
  1187. if (local->txfid[i] != 0xffff) {
  1188. printk(KERN_DEBUG "%s: Using shorter TX FID "
  1189. "(1600 bytes)\n", dev->name);
  1190. local->txfid_len = 1600;
  1191. }
  1192. }
  1193. if (local->txfid[i] == 0xffff)
  1194. goto failed;
  1195. local->intransmitfid[i] = PRISM2_TXFID_EMPTY;
  1196. }
  1197. hfa384x_events_only_cmd(dev);
  1198. if (initial) {
  1199. struct list_head *ptr;
  1200. prism2_check_sta_fw_version(local);
  1201. if (hfa384x_get_rid(dev, HFA384X_RID_CNFOWNMACADDR,
  1202. &dev->dev_addr, 6, 1) < 0) {
  1203. printk("%s: could not get own MAC address\n",
  1204. dev->name);
  1205. }
  1206. list_for_each(ptr, &local->hostap_interfaces) {
  1207. iface = list_entry(ptr, struct hostap_interface, list);
  1208. memcpy(iface->dev->dev_addr, dev->dev_addr, ETH_ALEN);
  1209. }
  1210. } else if (local->fw_ap)
  1211. prism2_check_sta_fw_version(local);
  1212. prism2_setup_rids(dev);
  1213. /* MAC is now configured, but port 0 is not yet enabled */
  1214. return 0;
  1215. failed:
  1216. if (!local->no_pri)
  1217. printk(KERN_WARNING "%s: Initialization failed\n", dev_info);
  1218. return 1;
  1219. }
  1220. static int prism2_hw_enable(struct net_device *dev, int initial)
  1221. {
  1222. struct hostap_interface *iface;
  1223. local_info_t *local;
  1224. int was_resetting;
  1225. iface = netdev_priv(dev);
  1226. local = iface->local;
  1227. was_resetting = local->hw_resetting;
  1228. if (hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL, NULL)) {
  1229. printk("%s: MAC port 0 enabling failed\n", dev->name);
  1230. return 1;
  1231. }
  1232. local->hw_ready = 1;
  1233. local->hw_reset_tries = 0;
  1234. local->hw_resetting = 0;
  1235. hfa384x_enable_interrupts(dev);
  1236. /* at least D-Link DWL-650 seems to require additional port reset
  1237. * before it starts acting as an AP, so reset port automatically
  1238. * here just in case */
  1239. if (initial && prism2_reset_port(dev)) {
  1240. printk("%s: MAC port 0 reseting failed\n", dev->name);
  1241. return 1;
  1242. }
  1243. if (was_resetting && netif_queue_stopped(dev)) {
  1244. /* If hw_reset() was called during pending transmit, netif
  1245. * queue was stopped. Wake it up now since the wlan card has
  1246. * been resetted. */
  1247. netif_wake_queue(dev);
  1248. }
  1249. return 0;
  1250. }
  1251. static int prism2_hw_config(struct net_device *dev, int initial)
  1252. {
  1253. struct hostap_interface *iface;
  1254. local_info_t *local;
  1255. iface = netdev_priv(dev);
  1256. local = iface->local;
  1257. if (local->hw_downloading)
  1258. return 1;
  1259. if (prism2_hw_init(dev, initial)) {
  1260. return local->no_pri ? 0 : 1;
  1261. }
  1262. if (prism2_hw_init2(dev, initial))
  1263. return 1;
  1264. /* Enable firmware if secondary image is loaded and at least one of the
  1265. * netdevices is up. */
  1266. if (!local->pri_only &&
  1267. (initial == 0 || (initial == 2 && local->num_dev_open > 0))) {
  1268. if (!local->dev_enabled)
  1269. prism2_callback(local, PRISM2_CALLBACK_ENABLE);
  1270. local->dev_enabled = 1;
  1271. return prism2_hw_enable(dev, initial);
  1272. }
  1273. return 0;
  1274. }
  1275. static void prism2_hw_shutdown(struct net_device *dev, int no_disable)
  1276. {
  1277. struct hostap_interface *iface;
  1278. local_info_t *local;
  1279. iface = netdev_priv(dev);
  1280. local = iface->local;
  1281. /* Allow only command completion events during disable */
  1282. hfa384x_events_only_cmd(dev);
  1283. local->hw_ready = 0;
  1284. if (local->dev_enabled)
  1285. prism2_callback(local, PRISM2_CALLBACK_DISABLE);
  1286. local->dev_enabled = 0;
  1287. if (local->func->card_present && !local->func->card_present(local)) {
  1288. printk(KERN_DEBUG "%s: card already removed or not configured "
  1289. "during shutdown\n", dev->name);
  1290. return;
  1291. }
  1292. if ((no_disable & HOSTAP_HW_NO_DISABLE) == 0 &&
  1293. hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL, NULL))
  1294. printk(KERN_WARNING "%s: Shutdown failed\n", dev_info);
  1295. hfa384x_disable_interrupts(dev);
  1296. if (no_disable & HOSTAP_HW_ENABLE_CMDCOMPL)
  1297. hfa384x_events_only_cmd(dev);
  1298. else
  1299. prism2_clear_cmd_queue(local);
  1300. }
  1301. static void prism2_hw_reset(struct net_device *dev)
  1302. {
  1303. struct hostap_interface *iface;
  1304. local_info_t *local;
  1305. #if 0
  1306. static long last_reset = 0;
  1307. /* do not reset card more than once per second to avoid ending up in a
  1308. * busy loop reseting the card */
  1309. if (time_before_eq(jiffies, last_reset + HZ))
  1310. return;
  1311. last_reset = jiffies;
  1312. #endif
  1313. iface = netdev_priv(dev);
  1314. local = iface->local;
  1315. if (in_interrupt()) {
  1316. printk(KERN_DEBUG "%s: driver bug - prism2_hw_reset() called "
  1317. "in interrupt context\n", dev->name);
  1318. return;
  1319. }
  1320. if (local->hw_downloading)
  1321. return;
  1322. if (local->hw_resetting) {
  1323. printk(KERN_WARNING "%s: %s: already resetting card - "
  1324. "ignoring reset request\n", dev_info, dev->name);
  1325. return;
  1326. }
  1327. local->hw_reset_tries++;
  1328. if (local->hw_reset_tries > 10) {
  1329. printk(KERN_WARNING "%s: too many reset tries, skipping\n",
  1330. dev->name);
  1331. return;
  1332. }
  1333. printk(KERN_WARNING "%s: %s: resetting card\n", dev_info, dev->name);
  1334. hfa384x_disable_interrupts(dev);
  1335. local->hw_resetting = 1;
  1336. if (local->func->cor_sreset) {
  1337. /* Host system seems to hang in some cases with high traffic
  1338. * load or shared interrupts during COR sreset. Disable shared
  1339. * interrupts during reset to avoid these crashes. COS sreset
  1340. * takes quite a long time, so it is unfortunate that this
  1341. * seems to be needed. Anyway, I do not know of any better way
  1342. * of avoiding the crash. */
  1343. disable_irq(dev->irq);
  1344. local->func->cor_sreset(local);
  1345. enable_irq(dev->irq);
  1346. }
  1347. prism2_hw_shutdown(dev, 1);
  1348. prism2_hw_config(dev, 0);
  1349. local->hw_resetting = 0;
  1350. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1351. if (local->dl_pri) {
  1352. printk(KERN_DEBUG "%s: persistent download of primary "
  1353. "firmware\n", dev->name);
  1354. if (prism2_download_genesis(local, local->dl_pri) < 0)
  1355. printk(KERN_WARNING "%s: download (PRI) failed\n",
  1356. dev->name);
  1357. }
  1358. if (local->dl_sec) {
  1359. printk(KERN_DEBUG "%s: persistent download of secondary "
  1360. "firmware\n", dev->name);
  1361. if (prism2_download_volatile(local, local->dl_sec) < 0)
  1362. printk(KERN_WARNING "%s: download (SEC) failed\n",
  1363. dev->name);
  1364. }
  1365. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1366. /* TODO: restore beacon TIM bits for STAs that have buffered frames */
  1367. }
  1368. static void prism2_schedule_reset(local_info_t *local)
  1369. {
  1370. schedule_work(&local->reset_queue);
  1371. }
  1372. /* Called only as scheduled task after noticing card timeout in interrupt
  1373. * context */
  1374. static void handle_reset_queue(void *data)
  1375. {
  1376. local_info_t *local = (local_info_t *) data;
  1377. printk(KERN_DEBUG "%s: scheduled card reset\n", local->dev->name);
  1378. prism2_hw_reset(local->dev);
  1379. if (netif_queue_stopped(local->dev)) {
  1380. int i;
  1381. for (i = 0; i < PRISM2_TXFID_COUNT; i++)
  1382. if (local->intransmitfid[i] == PRISM2_TXFID_EMPTY) {
  1383. PDEBUG(DEBUG_EXTRA, "prism2_tx_timeout: "
  1384. "wake up queue\n");
  1385. netif_wake_queue(local->dev);
  1386. break;
  1387. }
  1388. }
  1389. }
  1390. static int prism2_get_txfid_idx(local_info_t *local)
  1391. {
  1392. int idx, end;
  1393. unsigned long flags;
  1394. spin_lock_irqsave(&local->txfidlock, flags);
  1395. end = idx = local->next_txfid;
  1396. do {
  1397. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
  1398. local->intransmitfid[idx] = PRISM2_TXFID_RESERVED;
  1399. spin_unlock_irqrestore(&local->txfidlock, flags);
  1400. return idx;
  1401. }
  1402. idx++;
  1403. if (idx >= PRISM2_TXFID_COUNT)
  1404. idx = 0;
  1405. } while (idx != end);
  1406. spin_unlock_irqrestore(&local->txfidlock, flags);
  1407. PDEBUG(DEBUG_EXTRA2, "prism2_get_txfid_idx: no room in txfid buf: "
  1408. "packet dropped\n");
  1409. local->stats.tx_dropped++;
  1410. return -1;
  1411. }
  1412. /* Called only from hardware IRQ */
  1413. static void prism2_transmit_cb(struct net_device *dev, long context,
  1414. u16 resp0, u16 res)
  1415. {
  1416. struct hostap_interface *iface;
  1417. local_info_t *local;
  1418. int idx = (int) context;
  1419. iface = netdev_priv(dev);
  1420. local = iface->local;
  1421. if (res) {
  1422. printk(KERN_DEBUG "%s: prism2_transmit_cb - res=0x%02x\n",
  1423. dev->name, res);
  1424. return;
  1425. }
  1426. if (idx < 0 || idx >= PRISM2_TXFID_COUNT) {
  1427. printk(KERN_DEBUG "%s: prism2_transmit_cb called with invalid "
  1428. "idx=%d\n", dev->name, idx);
  1429. return;
  1430. }
  1431. if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  1432. printk(KERN_DEBUG "%s: driver bug: prism2_transmit_cb called "
  1433. "with no pending transmit\n", dev->name);
  1434. }
  1435. if (netif_queue_stopped(dev)) {
  1436. /* ready for next TX, so wake up queue that was stopped in
  1437. * prism2_transmit() */
  1438. netif_wake_queue(dev);
  1439. }
  1440. spin_lock(&local->txfidlock);
  1441. /* With reclaim, Resp0 contains new txfid for transmit; the old txfid
  1442. * will be automatically allocated for the next TX frame */
  1443. local->intransmitfid[idx] = resp0;
  1444. PDEBUG(DEBUG_FID, "%s: prism2_transmit_cb: txfid[%d]=0x%04x, "
  1445. "resp0=0x%04x, transmit_txfid=0x%04x\n",
  1446. dev->name, idx, local->txfid[idx],
  1447. resp0, local->intransmitfid[local->next_txfid]);
  1448. idx++;
  1449. if (idx >= PRISM2_TXFID_COUNT)
  1450. idx = 0;
  1451. local->next_txfid = idx;
  1452. /* check if all TX buffers are occupied */
  1453. do {
  1454. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
  1455. spin_unlock(&local->txfidlock);
  1456. return;
  1457. }
  1458. idx++;
  1459. if (idx >= PRISM2_TXFID_COUNT)
  1460. idx = 0;
  1461. } while (idx != local->next_txfid);
  1462. spin_unlock(&local->txfidlock);
  1463. /* no empty TX buffers, stop queue */
  1464. netif_stop_queue(dev);
  1465. }
  1466. /* Called only from software IRQ if PCI bus master is not used (with bus master
  1467. * this can be called both from software and hardware IRQ) */
  1468. static int prism2_transmit(struct net_device *dev, int idx)
  1469. {
  1470. struct hostap_interface *iface;
  1471. local_info_t *local;
  1472. int res;
  1473. iface = netdev_priv(dev);
  1474. local = iface->local;
  1475. /* The driver tries to stop netif queue so that there would not be
  1476. * more than one attempt to transmit frames going on; check that this
  1477. * is really the case */
  1478. if (test_and_set_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  1479. printk(KERN_DEBUG "%s: driver bug - prism2_transmit() called "
  1480. "when previous TX was pending\n", dev->name);
  1481. return -1;
  1482. }
  1483. /* stop the queue for the time that transmit is pending */
  1484. netif_stop_queue(dev);
  1485. /* transmit packet */
  1486. res = hfa384x_cmd_callback(
  1487. dev,
  1488. HFA384X_CMDCODE_TRANSMIT | HFA384X_CMD_TX_RECLAIM,
  1489. local->txfid[idx],
  1490. prism2_transmit_cb, (long) idx);
  1491. if (res) {
  1492. struct net_device_stats *stats;
  1493. printk(KERN_DEBUG "%s: prism2_transmit: CMDCODE_TRANSMIT "
  1494. "failed (res=%d)\n", dev->name, res);
  1495. stats = hostap_get_stats(dev);
  1496. stats->tx_dropped++;
  1497. netif_wake_queue(dev);
  1498. return -1;
  1499. }
  1500. dev->trans_start = jiffies;
  1501. /* Since we did not wait for command completion, the card continues
  1502. * to process on the background and we will finish handling when
  1503. * command completion event is handled (prism2_cmd_ev() function) */
  1504. return 0;
  1505. }
  1506. /* Send IEEE 802.11 frame (convert the header into Prism2 TX descriptor and
  1507. * send the payload with this descriptor) */
  1508. /* Called only from software IRQ */
  1509. static int prism2_tx_80211(struct sk_buff *skb, struct net_device *dev)
  1510. {
  1511. struct hostap_interface *iface;
  1512. local_info_t *local;
  1513. struct hfa384x_tx_frame txdesc;
  1514. struct hostap_skb_tx_data *meta;
  1515. int hdr_len, data_len, idx, res, ret = -1;
  1516. u16 tx_control, fc;
  1517. iface = netdev_priv(dev);
  1518. local = iface->local;
  1519. meta = (struct hostap_skb_tx_data *) skb->cb;
  1520. prism2_callback(local, PRISM2_CALLBACK_TX_START);
  1521. if ((local->func->card_present && !local->func->card_present(local)) ||
  1522. !local->hw_ready || local->hw_downloading || local->pri_only) {
  1523. if (net_ratelimit()) {
  1524. printk(KERN_DEBUG "%s: prism2_tx_80211: hw not ready -"
  1525. " skipping\n", dev->name);
  1526. }
  1527. goto fail;
  1528. }
  1529. memset(&txdesc, 0, sizeof(txdesc));
  1530. /* skb->data starts with txdesc->frame_control */
  1531. hdr_len = 24;
  1532. memcpy(&txdesc.frame_control, skb->data, hdr_len);
  1533. fc = le16_to_cpu(txdesc.frame_control);
  1534. if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA &&
  1535. (fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS) &&
  1536. skb->len >= 30) {
  1537. /* Addr4 */
  1538. memcpy(txdesc.addr4, skb->data + hdr_len, ETH_ALEN);
  1539. hdr_len += ETH_ALEN;
  1540. }
  1541. tx_control = local->tx_control;
  1542. if (meta->tx_cb_idx) {
  1543. tx_control |= HFA384X_TX_CTRL_TX_OK;
  1544. txdesc.sw_support = cpu_to_le16(meta->tx_cb_idx);
  1545. }
  1546. txdesc.tx_control = cpu_to_le16(tx_control);
  1547. txdesc.tx_rate = meta->rate;
  1548. data_len = skb->len - hdr_len;
  1549. txdesc.data_len = cpu_to_le16(data_len);
  1550. txdesc.len = cpu_to_be16(data_len);
  1551. idx = prism2_get_txfid_idx(local);
  1552. if (idx < 0)
  1553. goto fail;
  1554. if (local->frame_dump & PRISM2_DUMP_TX_HDR)
  1555. hostap_dump_tx_header(dev->name, &txdesc);
  1556. spin_lock(&local->baplock);
  1557. res = hfa384x_setup_bap(dev, BAP0, local->txfid[idx], 0);
  1558. if (!res)
  1559. res = hfa384x_to_bap(dev, BAP0, &txdesc, sizeof(txdesc));
  1560. if (!res)
  1561. res = hfa384x_to_bap(dev, BAP0, skb->data + hdr_len,
  1562. skb->len - hdr_len);
  1563. spin_unlock(&local->baplock);
  1564. if (!res)
  1565. res = prism2_transmit(dev, idx);
  1566. if (res) {
  1567. printk(KERN_DEBUG "%s: prism2_tx_80211 - to BAP0 failed\n",
  1568. dev->name);
  1569. local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
  1570. schedule_work(&local->reset_queue);
  1571. goto fail;
  1572. }
  1573. ret = 0;
  1574. fail:
  1575. prism2_callback(local, PRISM2_CALLBACK_TX_END);
  1576. return ret;
  1577. }
  1578. /* Some SMP systems have reported number of odd errors with hostap_pci. fid
  1579. * register has changed values between consecutive reads for an unknown reason.
  1580. * This should really not happen, so more debugging is needed. This test
  1581. * version is a big slower, but it will detect most of such register changes
  1582. * and will try to get the correct fid eventually. */
  1583. #define EXTRA_FID_READ_TESTS
  1584. static u16 prism2_read_fid_reg(struct net_device *dev, u16 reg)
  1585. {
  1586. #ifdef EXTRA_FID_READ_TESTS
  1587. u16 val, val2, val3;
  1588. int i;
  1589. for (i = 0; i < 10; i++) {
  1590. val = HFA384X_INW(reg);
  1591. val2 = HFA384X_INW(reg);
  1592. val3 = HFA384X_INW(reg);
  1593. if (val == val2 && val == val3)
  1594. return val;
  1595. printk(KERN_DEBUG "%s: detected fid change (try=%d, reg=%04x):"
  1596. " %04x %04x %04x\n",
  1597. dev->name, i, reg, val, val2, val3);
  1598. if ((val == val2 || val == val3) && val != 0)
  1599. return val;
  1600. if (val2 == val3 && val2 != 0)
  1601. return val2;
  1602. }
  1603. printk(KERN_WARNING "%s: Uhhuh.. could not read good fid from reg "
  1604. "%04x (%04x %04x %04x)\n", dev->name, reg, val, val2, val3);
  1605. return val;
  1606. #else /* EXTRA_FID_READ_TESTS */
  1607. return HFA384X_INW(reg);
  1608. #endif /* EXTRA_FID_READ_TESTS */
  1609. }
  1610. /* Called only as a tasklet (software IRQ) */
  1611. static void prism2_rx(local_info_t *local)
  1612. {
  1613. struct net_device *dev = local->dev;
  1614. int res, rx_pending = 0;
  1615. u16 len, hdr_len, rxfid, status, macport;
  1616. struct net_device_stats *stats;
  1617. struct hfa384x_rx_frame rxdesc;
  1618. struct sk_buff *skb = NULL;
  1619. prism2_callback(local, PRISM2_CALLBACK_RX_START);
  1620. stats = hostap_get_stats(dev);
  1621. rxfid = prism2_read_fid_reg(dev, HFA384X_RXFID_OFF);
  1622. #ifndef final_version
  1623. if (rxfid == 0) {
  1624. rxfid = HFA384X_INW(HFA384X_RXFID_OFF);
  1625. printk(KERN_DEBUG "prism2_rx: rxfid=0 (next 0x%04x)\n",
  1626. rxfid);
  1627. if (rxfid == 0) {
  1628. schedule_work(&local->reset_queue);
  1629. goto rx_dropped;
  1630. }
  1631. /* try to continue with the new rxfid value */
  1632. }
  1633. #endif
  1634. spin_lock(&local->baplock);
  1635. res = hfa384x_setup_bap(dev, BAP0, rxfid, 0);
  1636. if (!res)
  1637. res = hfa384x_from_bap(dev, BAP0, &rxdesc, sizeof(rxdesc));
  1638. if (res) {
  1639. spin_unlock(&local->baplock);
  1640. printk(KERN_DEBUG "%s: copy from BAP0 failed %d\n", dev->name,
  1641. res);
  1642. if (res == -ETIMEDOUT) {
  1643. schedule_work(&local->reset_queue);
  1644. }
  1645. goto rx_dropped;
  1646. }
  1647. len = le16_to_cpu(rxdesc.data_len);
  1648. hdr_len = sizeof(rxdesc);
  1649. status = le16_to_cpu(rxdesc.status);
  1650. macport = (status >> 8) & 0x07;
  1651. /* Drop frames with too large reported payload length. Monitor mode
  1652. * seems to sometimes pass frames (e.g., ctrl::ack) with signed and
  1653. * negative value, so allow also values 65522 .. 65534 (-14 .. -2) for
  1654. * macport 7 */
  1655. if (len > PRISM2_DATA_MAXLEN + 8 /* WEP */) {
  1656. if (macport == 7 && local->iw_mode == IW_MODE_MONITOR) {
  1657. if (len >= (u16) -14) {
  1658. hdr_len -= 65535 - len;
  1659. hdr_len--;
  1660. }
  1661. len = 0;
  1662. } else {
  1663. spin_unlock(&local->baplock);
  1664. printk(KERN_DEBUG "%s: Received frame with invalid "
  1665. "length 0x%04x\n", dev->name, len);
  1666. hostap_dump_rx_header(dev->name, &rxdesc);
  1667. goto rx_dropped;
  1668. }
  1669. }
  1670. skb = dev_alloc_skb(len + hdr_len);
  1671. if (!skb) {
  1672. spin_unlock(&local->baplock);
  1673. printk(KERN_DEBUG "%s: RX failed to allocate skb\n",
  1674. dev->name);
  1675. goto rx_dropped;
  1676. }
  1677. skb->dev = dev;
  1678. memcpy(skb_put(skb, hdr_len), &rxdesc, hdr_len);
  1679. if (len > 0)
  1680. res = hfa384x_from_bap(dev, BAP0, skb_put(skb, len), len);
  1681. spin_unlock(&local->baplock);
  1682. if (res) {
  1683. printk(KERN_DEBUG "%s: RX failed to read "
  1684. "frame data\n", dev->name);
  1685. goto rx_dropped;
  1686. }
  1687. skb_queue_tail(&local->rx_list, skb);
  1688. tasklet_schedule(&local->rx_tasklet);
  1689. rx_exit:
  1690. prism2_callback(local, PRISM2_CALLBACK_RX_END);
  1691. if (!rx_pending) {
  1692. HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
  1693. }
  1694. return;
  1695. rx_dropped:
  1696. stats->rx_dropped++;
  1697. if (skb)
  1698. dev_kfree_skb(skb);
  1699. goto rx_exit;
  1700. }
  1701. /* Called only as a tasklet (software IRQ) */
  1702. static void hostap_rx_skb(local_info_t *local, struct sk_buff *skb)
  1703. {
  1704. struct hfa384x_rx_frame *rxdesc;
  1705. struct net_device *dev = skb->dev;
  1706. struct hostap_80211_rx_status stats;
  1707. int hdrlen, rx_hdrlen;
  1708. rx_hdrlen = sizeof(*rxdesc);
  1709. if (skb->len < sizeof(*rxdesc)) {
  1710. /* Allow monitor mode to receive shorter frames */
  1711. if (local->iw_mode == IW_MODE_MONITOR &&
  1712. skb->len >= sizeof(*rxdesc) - 30) {
  1713. rx_hdrlen = skb->len;
  1714. } else {
  1715. dev_kfree_skb(skb);
  1716. return;
  1717. }
  1718. }
  1719. rxdesc = (struct hfa384x_rx_frame *) skb->data;
  1720. if (local->frame_dump & PRISM2_DUMP_RX_HDR &&
  1721. skb->len >= sizeof(*rxdesc))
  1722. hostap_dump_rx_header(dev->name, rxdesc);
  1723. if (le16_to_cpu(rxdesc->status) & HFA384X_RX_STATUS_FCSERR &&
  1724. (!local->monitor_allow_fcserr ||
  1725. local->iw_mode != IW_MODE_MONITOR))
  1726. goto drop;
  1727. if (skb->len > PRISM2_DATA_MAXLEN) {
  1728. printk(KERN_DEBUG "%s: RX: len(%d) > MAX(%d)\n",
  1729. dev->name, skb->len, PRISM2_DATA_MAXLEN);
  1730. goto drop;
  1731. }
  1732. stats.mac_time = le32_to_cpu(rxdesc->time);
  1733. stats.signal = rxdesc->signal - local->rssi_to_dBm;
  1734. stats.noise = rxdesc->silence - local->rssi_to_dBm;
  1735. stats.rate = rxdesc->rate;
  1736. /* Convert Prism2 RX structure into IEEE 802.11 header */
  1737. hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(rxdesc->frame_control));
  1738. if (hdrlen > rx_hdrlen)
  1739. hdrlen = rx_hdrlen;
  1740. memmove(skb_pull(skb, rx_hdrlen - hdrlen),
  1741. &rxdesc->frame_control, hdrlen);
  1742. hostap_80211_rx(dev, skb, &stats);
  1743. return;
  1744. drop:
  1745. dev_kfree_skb(skb);
  1746. }
  1747. /* Called only as a tasklet (software IRQ) */
  1748. static void hostap_rx_tasklet(unsigned long data)
  1749. {
  1750. local_info_t *local = (local_info_t *) data;
  1751. struct sk_buff *skb;
  1752. while ((skb = skb_dequeue(&local->rx_list)) != NULL)
  1753. hostap_rx_skb(local, skb);
  1754. }
  1755. /* Called only from hardware IRQ */
  1756. static void prism2_alloc_ev(struct net_device *dev)
  1757. {
  1758. struct hostap_interface *iface;
  1759. local_info_t *local;
  1760. int idx;
  1761. u16 fid;
  1762. iface = netdev_priv(dev);
  1763. local = iface->local;
  1764. fid = prism2_read_fid_reg(dev, HFA384X_ALLOCFID_OFF);
  1765. PDEBUG(DEBUG_FID, "FID: interrupt: ALLOC - fid=0x%04x\n", fid);
  1766. spin_lock(&local->txfidlock);
  1767. idx = local->next_alloc;
  1768. do {
  1769. if (local->txfid[idx] == fid) {
  1770. PDEBUG(DEBUG_FID, "FID: found matching txfid[%d]\n",
  1771. idx);
  1772. #ifndef final_version
  1773. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY)
  1774. printk("Already released txfid found at idx "
  1775. "%d\n", idx);
  1776. if (local->intransmitfid[idx] == PRISM2_TXFID_RESERVED)
  1777. printk("Already reserved txfid found at idx "
  1778. "%d\n", idx);
  1779. #endif
  1780. local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
  1781. idx++;
  1782. local->next_alloc = idx >= PRISM2_TXFID_COUNT ? 0 :
  1783. idx;
  1784. if (!test_bit(HOSTAP_BITS_TRANSMIT, &local->bits) &&
  1785. netif_queue_stopped(dev))
  1786. netif_wake_queue(dev);
  1787. spin_unlock(&local->txfidlock);
  1788. return;
  1789. }
  1790. idx++;
  1791. if (idx >= PRISM2_TXFID_COUNT)
  1792. idx = 0;
  1793. } while (idx != local->next_alloc);
  1794. printk(KERN_WARNING "%s: could not find matching txfid (0x%04x, new "
  1795. "read 0x%04x) for alloc event\n", dev->name, fid,
  1796. HFA384X_INW(HFA384X_ALLOCFID_OFF));
  1797. printk(KERN_DEBUG "TXFIDs:");
  1798. for (idx = 0; idx < PRISM2_TXFID_COUNT; idx++)
  1799. printk(" %04x[%04x]", local->txfid[idx],
  1800. local->intransmitfid[idx]);
  1801. printk("\n");
  1802. spin_unlock(&local->txfidlock);
  1803. /* FIX: should probably schedule reset; reference to one txfid was lost
  1804. * completely.. Bad things will happen if we run out of txfids
  1805. * Actually, this will cause netdev watchdog to notice TX timeout and
  1806. * then card reset after all txfids have been leaked. */
  1807. }
  1808. /* Called only as a tasklet (software IRQ) */
  1809. static void hostap_tx_callback(local_info_t *local,
  1810. struct hfa384x_tx_frame *txdesc, int ok,
  1811. char *payload)
  1812. {
  1813. u16 sw_support, hdrlen, len;
  1814. struct sk_buff *skb;
  1815. struct hostap_tx_callback_info *cb;
  1816. /* Make sure that frame was from us. */
  1817. if (memcmp(txdesc->addr2, local->dev->dev_addr, ETH_ALEN)) {
  1818. printk(KERN_DEBUG "%s: TX callback - foreign frame\n",
  1819. local->dev->name);
  1820. return;
  1821. }
  1822. sw_support = le16_to_cpu(txdesc->sw_support);
  1823. spin_lock(&local->lock);
  1824. cb = local->tx_callback;
  1825. while (cb != NULL && cb->idx != sw_support)
  1826. cb = cb->next;
  1827. spin_unlock(&local->lock);
  1828. if (cb == NULL) {
  1829. printk(KERN_DEBUG "%s: could not find TX callback (idx %d)\n",
  1830. local->dev->name, sw_support);
  1831. return;
  1832. }
  1833. hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(txdesc->frame_control));
  1834. len = le16_to_cpu(txdesc->data_len);
  1835. skb = dev_alloc_skb(hdrlen + len);
  1836. if (skb == NULL) {
  1837. printk(KERN_DEBUG "%s: hostap_tx_callback failed to allocate "
  1838. "skb\n", local->dev->name);
  1839. return;
  1840. }
  1841. memcpy(skb_put(skb, hdrlen), (void *) &txdesc->frame_control, hdrlen);
  1842. if (payload)
  1843. memcpy(skb_put(skb, len), payload, len);
  1844. skb->dev = local->dev;
  1845. skb->mac.raw = skb->data;
  1846. cb->func(skb, ok, cb->data);
  1847. }
  1848. /* Called only as a tasklet (software IRQ) */
  1849. static int hostap_tx_compl_read(local_info_t *local, int error,
  1850. struct hfa384x_tx_frame *txdesc,
  1851. char **payload)
  1852. {
  1853. u16 fid, len;
  1854. int res, ret = 0;
  1855. struct net_device *dev = local->dev;
  1856. fid = prism2_read_fid_reg(dev, HFA384X_TXCOMPLFID_OFF);
  1857. PDEBUG(DEBUG_FID, "interrupt: TX (err=%d) - fid=0x%04x\n", fid, error);
  1858. spin_lock(&local->baplock);
  1859. res = hfa384x_setup_bap(dev, BAP0, fid, 0);
  1860. if (!res)
  1861. res = hfa384x_from_bap(dev, BAP0, txdesc, sizeof(*txdesc));
  1862. if (res) {
  1863. PDEBUG(DEBUG_EXTRA, "%s: TX (err=%d) - fid=0x%04x - could not "
  1864. "read txdesc\n", dev->name, error, fid);
  1865. if (res == -ETIMEDOUT) {
  1866. schedule_work(&local->reset_queue);
  1867. }
  1868. ret = -1;
  1869. goto fail;
  1870. }
  1871. if (txdesc->sw_support) {
  1872. len = le16_to_cpu(txdesc->data_len);
  1873. if (len < PRISM2_DATA_MAXLEN) {
  1874. *payload = (char *) kmalloc(len, GFP_ATOMIC);
  1875. if (*payload == NULL ||
  1876. hfa384x_from_bap(dev, BAP0, *payload, len)) {
  1877. PDEBUG(DEBUG_EXTRA, "%s: could not read TX "
  1878. "frame payload\n", dev->name);
  1879. kfree(*payload);
  1880. *payload = NULL;
  1881. ret = -1;
  1882. goto fail;
  1883. }
  1884. }
  1885. }
  1886. fail:
  1887. spin_unlock(&local->baplock);
  1888. return ret;
  1889. }
  1890. /* Called only as a tasklet (software IRQ) */
  1891. static void prism2_tx_ev(local_info_t *local)
  1892. {
  1893. struct net_device *dev = local->dev;
  1894. char *payload = NULL;
  1895. struct hfa384x_tx_frame txdesc;
  1896. if (hostap_tx_compl_read(local, 0, &txdesc, &payload))
  1897. goto fail;
  1898. if (local->frame_dump & PRISM2_DUMP_TX_HDR) {
  1899. PDEBUG(DEBUG_EXTRA, "%s: TX - status=0x%04x "
  1900. "retry_count=%d tx_rate=%d seq_ctrl=%d "
  1901. "duration_id=%d\n",
  1902. dev->name, le16_to_cpu(txdesc.status),
  1903. txdesc.retry_count, txdesc.tx_rate,
  1904. le16_to_cpu(txdesc.seq_ctrl),
  1905. le16_to_cpu(txdesc.duration_id));
  1906. }
  1907. if (txdesc.sw_support)
  1908. hostap_tx_callback(local, &txdesc, 1, payload);
  1909. kfree(payload);
  1910. fail:
  1911. HFA384X_OUTW(HFA384X_EV_TX, HFA384X_EVACK_OFF);
  1912. }
  1913. /* Called only as a tasklet (software IRQ) */
  1914. static void hostap_sta_tx_exc_tasklet(unsigned long data)
  1915. {
  1916. local_info_t *local = (local_info_t *) data;
  1917. struct sk_buff *skb;
  1918. while ((skb = skb_dequeue(&local->sta_tx_exc_list)) != NULL) {
  1919. struct hfa384x_tx_frame *txdesc =
  1920. (struct hfa384x_tx_frame *) skb->data;
  1921. if (skb->len >= sizeof(*txdesc)) {
  1922. /* Convert Prism2 RX structure into IEEE 802.11 header
  1923. */
  1924. u16 fc = le16_to_cpu(txdesc->frame_control);
  1925. int hdrlen = hostap_80211_get_hdrlen(fc);
  1926. memmove(skb_pull(skb, sizeof(*txdesc) - hdrlen),
  1927. &txdesc->frame_control, hdrlen);
  1928. hostap_handle_sta_tx_exc(local, skb);
  1929. }
  1930. dev_kfree_skb(skb);
  1931. }
  1932. }
  1933. /* Called only as a tasklet (software IRQ) */
  1934. static void prism2_txexc(local_info_t *local)
  1935. {
  1936. struct net_device *dev = local->dev;
  1937. u16 status, fc;
  1938. int show_dump, res;
  1939. char *payload = NULL;
  1940. struct hfa384x_tx_frame txdesc;
  1941. show_dump = local->frame_dump & PRISM2_DUMP_TXEXC_HDR;
  1942. local->stats.tx_errors++;
  1943. res = hostap_tx_compl_read(local, 1, &txdesc, &payload);
  1944. HFA384X_OUTW(HFA384X_EV_TXEXC, HFA384X_EVACK_OFF);
  1945. if (res)
  1946. return;
  1947. status = le16_to_cpu(txdesc.status);
  1948. /* We produce a TXDROP event only for retry or lifetime
  1949. * exceeded, because that's the only status that really mean
  1950. * that this particular node went away.
  1951. * Other errors means that *we* screwed up. - Jean II */
  1952. if (status & (HFA384X_TX_STATUS_RETRYERR | HFA384X_TX_STATUS_AGEDERR))
  1953. {
  1954. union iwreq_data wrqu;
  1955. /* Copy 802.11 dest address. */
  1956. memcpy(wrqu.addr.sa_data, txdesc.addr1, ETH_ALEN);
  1957. wrqu.addr.sa_family = ARPHRD_ETHER;
  1958. wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
  1959. } else
  1960. show_dump = 1;
  1961. if (local->iw_mode == IW_MODE_MASTER ||
  1962. local->iw_mode == IW_MODE_REPEAT ||
  1963. local->wds_type & HOSTAP_WDS_AP_CLIENT) {
  1964. struct sk_buff *skb;
  1965. skb = dev_alloc_skb(sizeof(txdesc));
  1966. if (skb) {
  1967. memcpy(skb_put(skb, sizeof(txdesc)), &txdesc,
  1968. sizeof(txdesc));
  1969. skb_queue_tail(&local->sta_tx_exc_list, skb);
  1970. tasklet_schedule(&local->sta_tx_exc_tasklet);
  1971. }
  1972. }
  1973. if (txdesc.sw_support)
  1974. hostap_tx_callback(local, &txdesc, 0, payload);
  1975. kfree(payload);
  1976. if (!show_dump)
  1977. return;
  1978. PDEBUG(DEBUG_EXTRA, "%s: TXEXC - status=0x%04x (%s%s%s%s)"
  1979. " tx_control=%04x\n",
  1980. dev->name, status,
  1981. status & HFA384X_TX_STATUS_RETRYERR ? "[RetryErr]" : "",
  1982. status & HFA384X_TX_STATUS_AGEDERR ? "[AgedErr]" : "",
  1983. status & HFA384X_TX_STATUS_DISCON ? "[Discon]" : "",
  1984. status & HFA384X_TX_STATUS_FORMERR ? "[FormErr]" : "",
  1985. le16_to_cpu(txdesc.tx_control));
  1986. fc = le16_to_cpu(txdesc.frame_control);
  1987. PDEBUG(DEBUG_EXTRA, " retry_count=%d tx_rate=%d fc=0x%04x "
  1988. "(%s%s%s::%d%s%s)\n",
  1989. txdesc.retry_count, txdesc.tx_rate, fc,
  1990. WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_MGMT ? "Mgmt" : "",
  1991. WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_CTL ? "Ctrl" : "",
  1992. WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA ? "Data" : "",
  1993. WLAN_FC_GET_STYPE(fc) >> 4,
  1994. fc & IEEE80211_FCTL_TODS ? " ToDS" : "",
  1995. fc & IEEE80211_FCTL_FROMDS ? " FromDS" : "");
  1996. PDEBUG(DEBUG_EXTRA, " A1=" MACSTR " A2=" MACSTR " A3="
  1997. MACSTR " A4=" MACSTR "\n",
  1998. MAC2STR(txdesc.addr1), MAC2STR(txdesc.addr2),
  1999. MAC2STR(txdesc.addr3), MAC2STR(txdesc.addr4));
  2000. }
  2001. /* Called only as a tasklet (software IRQ) */
  2002. static void hostap_info_tasklet(unsigned long data)
  2003. {
  2004. local_info_t *local = (local_info_t *) data;
  2005. struct sk_buff *skb;
  2006. while ((skb = skb_dequeue(&local->info_list)) != NULL) {
  2007. hostap_info_process(local, skb);
  2008. dev_kfree_skb(skb);
  2009. }
  2010. }
  2011. /* Called only as a tasklet (software IRQ) */
  2012. static void prism2_info(local_info_t *local)
  2013. {
  2014. struct net_device *dev = local->dev;
  2015. u16 fid;
  2016. int res, left;
  2017. struct hfa384x_info_frame info;
  2018. struct sk_buff *skb;
  2019. fid = HFA384X_INW(HFA384X_INFOFID_OFF);
  2020. spin_lock(&local->baplock);
  2021. res = hfa384x_setup_bap(dev, BAP0, fid, 0);
  2022. if (!res)
  2023. res = hfa384x_from_bap(dev, BAP0, &info, sizeof(info));
  2024. if (res) {
  2025. spin_unlock(&local->baplock);
  2026. printk(KERN_DEBUG "Could not get info frame (fid=0x%04x)\n",
  2027. fid);
  2028. if (res == -ETIMEDOUT) {
  2029. schedule_work(&local->reset_queue);
  2030. }
  2031. goto out;
  2032. }
  2033. le16_to_cpus(&info.len);
  2034. le16_to_cpus(&info.type);
  2035. left = (info.len - 1) * 2;
  2036. if (info.len & 0x8000 || info.len == 0 || left > 2060) {
  2037. /* data register seems to give 0x8000 in some error cases even
  2038. * though busy bit is not set in offset register;
  2039. * in addition, length must be at least 1 due to type field */
  2040. spin_unlock(&local->baplock);
  2041. printk(KERN_DEBUG "%s: Received info frame with invalid "
  2042. "length 0x%04x (type 0x%04x)\n", dev->name, info.len,
  2043. info.type);
  2044. goto out;
  2045. }
  2046. skb = dev_alloc_skb(sizeof(info) + left);
  2047. if (skb == NULL) {
  2048. spin_unlock(&local->baplock);
  2049. printk(KERN_DEBUG "%s: Could not allocate skb for info "
  2050. "frame\n", dev->name);
  2051. goto out;
  2052. }
  2053. memcpy(skb_put(skb, sizeof(info)), &info, sizeof(info));
  2054. if (left > 0 && hfa384x_from_bap(dev, BAP0, skb_put(skb, left), left))
  2055. {
  2056. spin_unlock(&local->baplock);
  2057. printk(KERN_WARNING "%s: Info frame read failed (fid=0x%04x, "
  2058. "len=0x%04x, type=0x%04x\n",
  2059. dev->name, fid, info.len, info.type);
  2060. dev_kfree_skb(skb);
  2061. goto out;
  2062. }
  2063. spin_unlock(&local->baplock);
  2064. skb_queue_tail(&local->info_list, skb);
  2065. tasklet_schedule(&local->info_tasklet);
  2066. out:
  2067. HFA384X_OUTW(HFA384X_EV_INFO, HFA384X_EVACK_OFF);
  2068. }
  2069. /* Called only as a tasklet (software IRQ) */
  2070. static void hostap_bap_tasklet(unsigned long data)
  2071. {
  2072. local_info_t *local = (local_info_t *) data;
  2073. struct net_device *dev = local->dev;
  2074. u16 ev;
  2075. int frames = 30;
  2076. if (local->func->card_present && !local->func->card_present(local))
  2077. return;
  2078. set_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
  2079. /* Process all pending BAP events without generating new interrupts
  2080. * for them */
  2081. while (frames-- > 0) {
  2082. ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2083. if (ev == 0xffff || !(ev & HFA384X_BAP0_EVENTS))
  2084. break;
  2085. if (ev & HFA384X_EV_RX)
  2086. prism2_rx(local);
  2087. if (ev & HFA384X_EV_INFO)
  2088. prism2_info(local);
  2089. if (ev & HFA384X_EV_TX)
  2090. prism2_tx_ev(local);
  2091. if (ev & HFA384X_EV_TXEXC)
  2092. prism2_txexc(local);
  2093. }
  2094. set_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
  2095. clear_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
  2096. /* Enable interrupts for new BAP events */
  2097. hfa384x_events_all(dev);
  2098. clear_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
  2099. }
  2100. /* Called only from hardware IRQ */
  2101. static void prism2_infdrop(struct net_device *dev)
  2102. {
  2103. static unsigned long last_inquire = 0;
  2104. PDEBUG(DEBUG_EXTRA, "%s: INFDROP event\n", dev->name);
  2105. /* some firmware versions seem to get stuck with
  2106. * full CommTallies in high traffic load cases; every
  2107. * packet will then cause INFDROP event and CommTallies
  2108. * info frame will not be sent automatically. Try to
  2109. * get out of this state by inquiring CommTallies. */
  2110. if (!last_inquire || time_after(jiffies, last_inquire + HZ)) {
  2111. hfa384x_cmd_callback(dev, HFA384X_CMDCODE_INQUIRE,
  2112. HFA384X_INFO_COMMTALLIES, NULL, 0);
  2113. last_inquire = jiffies;
  2114. }
  2115. }
  2116. /* Called only from hardware IRQ */
  2117. static void prism2_ev_tick(struct net_device *dev)
  2118. {
  2119. struct hostap_interface *iface;
  2120. local_info_t *local;
  2121. u16 evstat, inten;
  2122. static int prev_stuck = 0;
  2123. iface = netdev_priv(dev);
  2124. local = iface->local;
  2125. if (time_after(jiffies, local->last_tick_timer + 5 * HZ) &&
  2126. local->last_tick_timer) {
  2127. evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2128. inten = HFA384X_INW(HFA384X_INTEN_OFF);
  2129. if (!prev_stuck) {
  2130. printk(KERN_INFO "%s: SW TICK stuck? "
  2131. "bits=0x%lx EvStat=%04x IntEn=%04x\n",
  2132. dev->name, local->bits, evstat, inten);
  2133. }
  2134. local->sw_tick_stuck++;
  2135. if ((evstat & HFA384X_BAP0_EVENTS) &&
  2136. (inten & HFA384X_BAP0_EVENTS)) {
  2137. printk(KERN_INFO "%s: trying to recover from IRQ "
  2138. "hang\n", dev->name);
  2139. hfa384x_events_no_bap0(dev);
  2140. }
  2141. prev_stuck = 1;
  2142. } else
  2143. prev_stuck = 0;
  2144. }
  2145. /* Called only from hardware IRQ */
  2146. static void prism2_check_magic(local_info_t *local)
  2147. {
  2148. /* at least PCI Prism2.5 with bus mastering seems to sometimes
  2149. * return 0x0000 in SWSUPPORT0 for unknown reason, but re-reading the
  2150. * register once or twice seems to get the correct value.. PCI cards
  2151. * cannot anyway be removed during normal operation, so there is not
  2152. * really any need for this verification with them. */
  2153. #ifndef PRISM2_PCI
  2154. #ifndef final_version
  2155. static unsigned long last_magic_err = 0;
  2156. struct net_device *dev = local->dev;
  2157. if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
  2158. if (!local->hw_ready)
  2159. return;
  2160. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  2161. if (time_after(jiffies, last_magic_err + 10 * HZ)) {
  2162. printk("%s: Interrupt, but SWSUPPORT0 does not match: "
  2163. "%04X != %04X - card removed?\n", dev->name,
  2164. HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
  2165. HFA384X_MAGIC);
  2166. last_magic_err = jiffies;
  2167. } else if (net_ratelimit()) {
  2168. printk(KERN_DEBUG "%s: interrupt - SWSUPPORT0=%04x "
  2169. "MAGIC=%04x\n", dev->name,
  2170. HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
  2171. HFA384X_MAGIC);
  2172. }
  2173. if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != 0xffff)
  2174. schedule_work(&local->reset_queue);
  2175. return;
  2176. }
  2177. #endif /* final_version */
  2178. #endif /* !PRISM2_PCI */
  2179. }
  2180. /* Called only from hardware IRQ */
  2181. static irqreturn_t prism2_interrupt(int irq, void *dev_id)
  2182. {
  2183. struct net_device *dev = (struct net_device *) dev_id;
  2184. struct hostap_interface *iface;
  2185. local_info_t *local;
  2186. int events = 0;
  2187. u16 ev;
  2188. iface = netdev_priv(dev);
  2189. local = iface->local;
  2190. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 0);
  2191. if (local->func->card_present && !local->func->card_present(local)) {
  2192. if (net_ratelimit()) {
  2193. printk(KERN_DEBUG "%s: Interrupt, but dev not OK\n",
  2194. dev->name);
  2195. }
  2196. return IRQ_HANDLED;
  2197. }
  2198. prism2_check_magic(local);
  2199. for (;;) {
  2200. ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2201. if (ev == 0xffff) {
  2202. if (local->shutdown)
  2203. return IRQ_HANDLED;
  2204. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  2205. printk(KERN_DEBUG "%s: prism2_interrupt: ev=0xffff\n",
  2206. dev->name);
  2207. return IRQ_HANDLED;
  2208. }
  2209. ev &= HFA384X_INW(HFA384X_INTEN_OFF);
  2210. if (ev == 0)
  2211. break;
  2212. if (ev & HFA384X_EV_CMD) {
  2213. prism2_cmd_ev(dev);
  2214. }
  2215. /* Above events are needed even before hw is ready, but other
  2216. * events should be skipped during initialization. This may
  2217. * change for AllocEv if allocate_fid is implemented without
  2218. * busy waiting. */
  2219. if (!local->hw_ready || local->hw_resetting ||
  2220. !local->dev_enabled) {
  2221. ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2222. if (ev & HFA384X_EV_CMD)
  2223. goto next_event;
  2224. if ((ev & HFA384X_EVENT_MASK) == 0)
  2225. return IRQ_HANDLED;
  2226. if (local->dev_enabled && (ev & ~HFA384X_EV_TICK) &&
  2227. net_ratelimit()) {
  2228. printk(KERN_DEBUG "%s: prism2_interrupt: hw "
  2229. "not ready; skipping events 0x%04x "
  2230. "(IntEn=0x%04x)%s%s%s\n",
  2231. dev->name, ev,
  2232. HFA384X_INW(HFA384X_INTEN_OFF),
  2233. !local->hw_ready ? " (!hw_ready)" : "",
  2234. local->hw_resetting ?
  2235. " (hw_resetting)" : "",
  2236. !local->dev_enabled ?
  2237. " (!dev_enabled)" : "");
  2238. }
  2239. HFA384X_OUTW(ev, HFA384X_EVACK_OFF);
  2240. return IRQ_HANDLED;
  2241. }
  2242. if (ev & HFA384X_EV_TICK) {
  2243. prism2_ev_tick(dev);
  2244. HFA384X_OUTW(HFA384X_EV_TICK, HFA384X_EVACK_OFF);
  2245. }
  2246. if (ev & HFA384X_EV_ALLOC) {
  2247. prism2_alloc_ev(dev);
  2248. HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
  2249. }
  2250. /* Reading data from the card is quite time consuming, so do it
  2251. * in tasklets. TX, TXEXC, RX, and INFO events will be ACKed
  2252. * and unmasked after needed data has been read completely. */
  2253. if (ev & HFA384X_BAP0_EVENTS) {
  2254. hfa384x_events_no_bap0(dev);
  2255. tasklet_schedule(&local->bap_tasklet);
  2256. }
  2257. #ifndef final_version
  2258. if (ev & HFA384X_EV_WTERR) {
  2259. PDEBUG(DEBUG_EXTRA, "%s: WTERR event\n", dev->name);
  2260. HFA384X_OUTW(HFA384X_EV_WTERR, HFA384X_EVACK_OFF);
  2261. }
  2262. #endif /* final_version */
  2263. if (ev & HFA384X_EV_INFDROP) {
  2264. prism2_infdrop(dev);
  2265. HFA384X_OUTW(HFA384X_EV_INFDROP, HFA384X_EVACK_OFF);
  2266. }
  2267. next_event:
  2268. events++;
  2269. if (events >= PRISM2_MAX_INTERRUPT_EVENTS) {
  2270. PDEBUG(DEBUG_EXTRA, "prism2_interrupt: >%d events "
  2271. "(EvStat=0x%04x)\n",
  2272. PRISM2_MAX_INTERRUPT_EVENTS,
  2273. HFA384X_INW(HFA384X_EVSTAT_OFF));
  2274. break;
  2275. }
  2276. }
  2277. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 1);
  2278. return IRQ_RETVAL(events);
  2279. }
  2280. static void prism2_check_sta_fw_version(local_info_t *local)
  2281. {
  2282. struct hfa384x_comp_ident comp;
  2283. int id, variant, major, minor;
  2284. if (hfa384x_get_rid(local->dev, HFA384X_RID_STAID,
  2285. &comp, sizeof(comp), 1) < 0)
  2286. return;
  2287. local->fw_ap = 0;
  2288. id = le16_to_cpu(comp.id);
  2289. if (id != HFA384X_COMP_ID_STA) {
  2290. if (id == HFA384X_COMP_ID_FW_AP)
  2291. local->fw_ap = 1;
  2292. return;
  2293. }
  2294. major = __le16_to_cpu(comp.major);
  2295. minor = __le16_to_cpu(comp.minor);
  2296. variant = __le16_to_cpu(comp.variant);
  2297. local->sta_fw_ver = PRISM2_FW_VER(major, minor, variant);
  2298. /* Station firmware versions before 1.4.x seem to have a bug in
  2299. * firmware-based WEP encryption when using Host AP mode, so use
  2300. * host_encrypt as a default for them. Firmware version 1.4.9 is the
  2301. * first one that has been seen to produce correct encryption, but the
  2302. * bug might be fixed before that (although, at least 1.4.2 is broken).
  2303. */
  2304. local->fw_encrypt_ok = local->sta_fw_ver >= PRISM2_FW_VER(1,4,9);
  2305. if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
  2306. !local->fw_encrypt_ok) {
  2307. printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
  2308. "a workaround for firmware bug in Host AP mode WEP\n",
  2309. local->dev->name);
  2310. local->host_encrypt = 1;
  2311. }
  2312. /* IEEE 802.11 standard compliant WDS frames (4 addresses) were broken
  2313. * in station firmware versions before 1.5.x. With these versions, the
  2314. * driver uses a workaround with bogus frame format (4th address after
  2315. * the payload). This is not compatible with other AP devices. Since
  2316. * the firmware bug is fixed in the latest station firmware versions,
  2317. * automatically enable standard compliant mode for cards using station
  2318. * firmware version 1.5.0 or newer. */
  2319. if (local->sta_fw_ver >= PRISM2_FW_VER(1,5,0))
  2320. local->wds_type |= HOSTAP_WDS_STANDARD_FRAME;
  2321. else {
  2322. printk(KERN_DEBUG "%s: defaulting to bogus WDS frame as a "
  2323. "workaround for firmware bug in Host AP mode WDS\n",
  2324. local->dev->name);
  2325. }
  2326. hostap_check_sta_fw_version(local->ap, local->sta_fw_ver);
  2327. }
  2328. static void prism2_crypt_deinit_entries(local_info_t *local, int force)
  2329. {
  2330. struct list_head *ptr, *n;
  2331. struct ieee80211_crypt_data *entry;
  2332. for (ptr = local->crypt_deinit_list.next, n = ptr->next;
  2333. ptr != &local->crypt_deinit_list; ptr = n, n = ptr->next) {
  2334. entry = list_entry(ptr, struct ieee80211_crypt_data, list);
  2335. if (atomic_read(&entry->refcnt) != 0 && !force)
  2336. continue;
  2337. list_del(ptr);
  2338. if (entry->ops)
  2339. entry->ops->deinit(entry->priv);
  2340. kfree(entry);
  2341. }
  2342. }
  2343. static void prism2_crypt_deinit_handler(unsigned long data)
  2344. {
  2345. local_info_t *local = (local_info_t *) data;
  2346. unsigned long flags;
  2347. spin_lock_irqsave(&local->lock, flags);
  2348. prism2_crypt_deinit_entries(local, 0);
  2349. if (!list_empty(&local->crypt_deinit_list)) {
  2350. printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
  2351. "deletion list\n", local->dev->name);
  2352. local->crypt_deinit_timer.expires = jiffies + HZ;
  2353. add_timer(&local->crypt_deinit_timer);
  2354. }
  2355. spin_unlock_irqrestore(&local->lock, flags);
  2356. }
  2357. static void hostap_passive_scan(unsigned long data)
  2358. {
  2359. local_info_t *local = (local_info_t *) data;
  2360. struct net_device *dev = local->dev;
  2361. u16 channel;
  2362. if (local->passive_scan_interval <= 0)
  2363. return;
  2364. if (local->passive_scan_state == PASSIVE_SCAN_LISTEN) {
  2365. int max_tries = 16;
  2366. /* Even though host system does not really know when the WLAN
  2367. * MAC is sending frames, try to avoid changing channels for
  2368. * passive scanning when a host-generated frame is being
  2369. * transmitted */
  2370. if (test_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  2371. printk(KERN_DEBUG "%s: passive scan detected pending "
  2372. "TX - delaying\n", dev->name);
  2373. local->passive_scan_timer.expires = jiffies + HZ / 10;
  2374. add_timer(&local->passive_scan_timer);
  2375. return;
  2376. }
  2377. do {
  2378. local->passive_scan_channel++;
  2379. if (local->passive_scan_channel > 14)
  2380. local->passive_scan_channel = 1;
  2381. max_tries--;
  2382. } while (!(local->channel_mask &
  2383. (1 << (local->passive_scan_channel - 1))) &&
  2384. max_tries > 0);
  2385. if (max_tries == 0) {
  2386. printk(KERN_INFO "%s: no allowed passive scan channels"
  2387. " found\n", dev->name);
  2388. return;
  2389. }
  2390. printk(KERN_DEBUG "%s: passive scan channel %d\n",
  2391. dev->name, local->passive_scan_channel);
  2392. channel = local->passive_scan_channel;
  2393. local->passive_scan_state = PASSIVE_SCAN_WAIT;
  2394. local->passive_scan_timer.expires = jiffies + HZ / 10;
  2395. } else {
  2396. channel = local->channel;
  2397. local->passive_scan_state = PASSIVE_SCAN_LISTEN;
  2398. local->passive_scan_timer.expires = jiffies +
  2399. local->passive_scan_interval * HZ;
  2400. }
  2401. if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_TEST |
  2402. (HFA384X_TEST_CHANGE_CHANNEL << 8),
  2403. channel, NULL, 0))
  2404. printk(KERN_ERR "%s: passive scan channel set %d "
  2405. "failed\n", dev->name, channel);
  2406. add_timer(&local->passive_scan_timer);
  2407. }
  2408. /* Called only as a scheduled task when communications quality values should
  2409. * be updated. */
  2410. static void handle_comms_qual_update(void *data)
  2411. {
  2412. local_info_t *local = data;
  2413. prism2_update_comms_qual(local->dev);
  2414. }
  2415. /* Software watchdog - called as a timer. Hardware interrupt (Tick event) is
  2416. * used to monitor that local->last_tick_timer is being updated. If not,
  2417. * interrupt busy-loop is assumed and driver tries to recover by masking out
  2418. * some events. */
  2419. static void hostap_tick_timer(unsigned long data)
  2420. {
  2421. static unsigned long last_inquire = 0;
  2422. local_info_t *local = (local_info_t *) data;
  2423. local->last_tick_timer = jiffies;
  2424. /* Inquire CommTallies every 10 seconds to keep the statistics updated
  2425. * more often during low load and when using 32-bit tallies. */
  2426. if ((!last_inquire || time_after(jiffies, last_inquire + 10 * HZ)) &&
  2427. !local->hw_downloading && local->hw_ready &&
  2428. !local->hw_resetting && local->dev_enabled) {
  2429. hfa384x_cmd_callback(local->dev, HFA384X_CMDCODE_INQUIRE,
  2430. HFA384X_INFO_COMMTALLIES, NULL, 0);
  2431. last_inquire = jiffies;
  2432. }
  2433. if ((local->last_comms_qual_update == 0 ||
  2434. time_after(jiffies, local->last_comms_qual_update + 10 * HZ)) &&
  2435. (local->iw_mode == IW_MODE_INFRA ||
  2436. local->iw_mode == IW_MODE_ADHOC)) {
  2437. schedule_work(&local->comms_qual_update);
  2438. }
  2439. local->tick_timer.expires = jiffies + 2 * HZ;
  2440. add_timer(&local->tick_timer);
  2441. }
  2442. #ifndef PRISM2_NO_PROCFS_DEBUG
  2443. static int prism2_registers_proc_read(char *page, char **start, off_t off,
  2444. int count, int *eof, void *data)
  2445. {
  2446. char *p = page;
  2447. local_info_t *local = (local_info_t *) data;
  2448. if (off != 0) {
  2449. *eof = 1;
  2450. return 0;
  2451. }
  2452. #define SHOW_REG(n) \
  2453. p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF))
  2454. SHOW_REG(CMD);
  2455. SHOW_REG(PARAM0);
  2456. SHOW_REG(PARAM1);
  2457. SHOW_REG(PARAM2);
  2458. SHOW_REG(STATUS);
  2459. SHOW_REG(RESP0);
  2460. SHOW_REG(RESP1);
  2461. SHOW_REG(RESP2);
  2462. SHOW_REG(INFOFID);
  2463. SHOW_REG(CONTROL);
  2464. SHOW_REG(SELECT0);
  2465. SHOW_REG(SELECT1);
  2466. SHOW_REG(OFFSET0);
  2467. SHOW_REG(OFFSET1);
  2468. SHOW_REG(RXFID);
  2469. SHOW_REG(ALLOCFID);
  2470. SHOW_REG(TXCOMPLFID);
  2471. SHOW_REG(SWSUPPORT0);
  2472. SHOW_REG(SWSUPPORT1);
  2473. SHOW_REG(SWSUPPORT2);
  2474. SHOW_REG(EVSTAT);
  2475. SHOW_REG(INTEN);
  2476. SHOW_REG(EVACK);
  2477. /* Do not read data registers, because they change the state of the
  2478. * MAC (offset += 2) */
  2479. /* SHOW_REG(DATA0); */
  2480. /* SHOW_REG(DATA1); */
  2481. SHOW_REG(AUXPAGE);
  2482. SHOW_REG(AUXOFFSET);
  2483. /* SHOW_REG(AUXDATA); */
  2484. #ifdef PRISM2_PCI
  2485. SHOW_REG(PCICOR);
  2486. SHOW_REG(PCIHCR);
  2487. SHOW_REG(PCI_M0_ADDRH);
  2488. SHOW_REG(PCI_M0_ADDRL);
  2489. SHOW_REG(PCI_M0_LEN);
  2490. SHOW_REG(PCI_M0_CTL);
  2491. SHOW_REG(PCI_STATUS);
  2492. SHOW_REG(PCI_M1_ADDRH);
  2493. SHOW_REG(PCI_M1_ADDRL);
  2494. SHOW_REG(PCI_M1_LEN);
  2495. SHOW_REG(PCI_M1_CTL);
  2496. #endif /* PRISM2_PCI */
  2497. return (p - page);
  2498. }
  2499. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2500. struct set_tim_data {
  2501. struct list_head list;
  2502. int aid;
  2503. int set;
  2504. };
  2505. static int prism2_set_tim(struct net_device *dev, int aid, int set)
  2506. {
  2507. struct list_head *ptr;
  2508. struct set_tim_data *new_entry;
  2509. struct hostap_interface *iface;
  2510. local_info_t *local;
  2511. iface = netdev_priv(dev);
  2512. local = iface->local;
  2513. new_entry = (struct set_tim_data *)
  2514. kmalloc(sizeof(*new_entry), GFP_ATOMIC);
  2515. if (new_entry == NULL) {
  2516. printk(KERN_DEBUG "%s: prism2_set_tim: kmalloc failed\n",
  2517. local->dev->name);
  2518. return -ENOMEM;
  2519. }
  2520. memset(new_entry, 0, sizeof(*new_entry));
  2521. new_entry->aid = aid;
  2522. new_entry->set = set;
  2523. spin_lock_bh(&local->set_tim_lock);
  2524. list_for_each(ptr, &local->set_tim_list) {
  2525. struct set_tim_data *entry =
  2526. list_entry(ptr, struct set_tim_data, list);
  2527. if (entry->aid == aid) {
  2528. PDEBUG(DEBUG_PS2, "%s: prism2_set_tim: aid=%d "
  2529. "set=%d ==> %d\n",
  2530. local->dev->name, aid, entry->set, set);
  2531. entry->set = set;
  2532. kfree(new_entry);
  2533. new_entry = NULL;
  2534. break;
  2535. }
  2536. }
  2537. if (new_entry)
  2538. list_add_tail(&new_entry->list, &local->set_tim_list);
  2539. spin_unlock_bh(&local->set_tim_lock);
  2540. schedule_work(&local->set_tim_queue);
  2541. return 0;
  2542. }
  2543. static void handle_set_tim_queue(void *data)
  2544. {
  2545. local_info_t *local = (local_info_t *) data;
  2546. struct set_tim_data *entry;
  2547. u16 val;
  2548. for (;;) {
  2549. entry = NULL;
  2550. spin_lock_bh(&local->set_tim_lock);
  2551. if (!list_empty(&local->set_tim_list)) {
  2552. entry = list_entry(local->set_tim_list.next,
  2553. struct set_tim_data, list);
  2554. list_del(&entry->list);
  2555. }
  2556. spin_unlock_bh(&local->set_tim_lock);
  2557. if (!entry)
  2558. break;
  2559. PDEBUG(DEBUG_PS2, "%s: handle_set_tim_queue: aid=%d set=%d\n",
  2560. local->dev->name, entry->aid, entry->set);
  2561. val = entry->aid;
  2562. if (entry->set)
  2563. val |= 0x8000;
  2564. if (hostap_set_word(local->dev, HFA384X_RID_CNFTIMCTRL, val)) {
  2565. printk(KERN_DEBUG "%s: set_tim failed (aid=%d "
  2566. "set=%d)\n",
  2567. local->dev->name, entry->aid, entry->set);
  2568. }
  2569. kfree(entry);
  2570. }
  2571. }
  2572. static void prism2_clear_set_tim_queue(local_info_t *local)
  2573. {
  2574. struct list_head *ptr, *n;
  2575. list_for_each_safe(ptr, n, &local->set_tim_list) {
  2576. struct set_tim_data *entry;
  2577. entry = list_entry(ptr, struct set_tim_data, list);
  2578. list_del(&entry->list);
  2579. kfree(entry);
  2580. }
  2581. }
  2582. /*
  2583. * HostAP uses two layers of net devices, where the inner
  2584. * layer gets called all the time from the outer layer.
  2585. * This is a natural nesting, which needs a split lock type.
  2586. */
  2587. static struct lock_class_key hostap_netdev_xmit_lock_key;
  2588. static struct net_device *
  2589. prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx,
  2590. struct device *sdev)
  2591. {
  2592. struct net_device *dev;
  2593. struct hostap_interface *iface;
  2594. struct local_info *local;
  2595. int len, i, ret;
  2596. if (funcs == NULL)
  2597. return NULL;
  2598. len = strlen(dev_template);
  2599. if (len >= IFNAMSIZ || strstr(dev_template, "%d") == NULL) {
  2600. printk(KERN_WARNING "hostap: Invalid dev_template='%s'\n",
  2601. dev_template);
  2602. return NULL;
  2603. }
  2604. len = sizeof(struct hostap_interface) +
  2605. 3 + sizeof(struct local_info) +
  2606. 3 + sizeof(struct ap_data);
  2607. dev = alloc_etherdev(len);
  2608. if (dev == NULL)
  2609. return NULL;
  2610. iface = netdev_priv(dev);
  2611. local = (struct local_info *) ((((long) (iface + 1)) + 3) & ~3);
  2612. local->ap = (struct ap_data *) ((((long) (local + 1)) + 3) & ~3);
  2613. local->dev = iface->dev = dev;
  2614. iface->local = local;
  2615. iface->type = HOSTAP_INTERFACE_MASTER;
  2616. INIT_LIST_HEAD(&local->hostap_interfaces);
  2617. local->hw_module = THIS_MODULE;
  2618. #ifdef PRISM2_IO_DEBUG
  2619. local->io_debug_enabled = 1;
  2620. #endif /* PRISM2_IO_DEBUG */
  2621. local->func = funcs;
  2622. local->func->cmd = hfa384x_cmd;
  2623. local->func->read_regs = hfa384x_read_regs;
  2624. local->func->get_rid = hfa384x_get_rid;
  2625. local->func->set_rid = hfa384x_set_rid;
  2626. local->func->hw_enable = prism2_hw_enable;
  2627. local->func->hw_config = prism2_hw_config;
  2628. local->func->hw_reset = prism2_hw_reset;
  2629. local->func->hw_shutdown = prism2_hw_shutdown;
  2630. local->func->reset_port = prism2_reset_port;
  2631. local->func->schedule_reset = prism2_schedule_reset;
  2632. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2633. local->func->read_aux = prism2_download_aux_dump;
  2634. local->func->download = prism2_download;
  2635. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2636. local->func->tx = prism2_tx_80211;
  2637. local->func->set_tim = prism2_set_tim;
  2638. local->func->need_tx_headroom = 0; /* no need to add txdesc in
  2639. * skb->data (FIX: maybe for DMA bus
  2640. * mastering? */
  2641. local->mtu = mtu;
  2642. rwlock_init(&local->iface_lock);
  2643. spin_lock_init(&local->txfidlock);
  2644. spin_lock_init(&local->cmdlock);
  2645. spin_lock_init(&local->baplock);
  2646. spin_lock_init(&local->lock);
  2647. init_MUTEX(&local->rid_bap_sem);
  2648. if (card_idx < 0 || card_idx >= MAX_PARM_DEVICES)
  2649. card_idx = 0;
  2650. local->card_idx = card_idx;
  2651. len = strlen(essid);
  2652. memcpy(local->essid, essid,
  2653. len > MAX_SSID_LEN ? MAX_SSID_LEN : len);
  2654. local->essid[MAX_SSID_LEN] = '\0';
  2655. i = GET_INT_PARM(iw_mode, card_idx);
  2656. if ((i >= IW_MODE_ADHOC && i <= IW_MODE_REPEAT) ||
  2657. i == IW_MODE_MONITOR) {
  2658. local->iw_mode = i;
  2659. } else {
  2660. printk(KERN_WARNING "prism2: Unknown iw_mode %d; using "
  2661. "IW_MODE_MASTER\n", i);
  2662. local->iw_mode = IW_MODE_MASTER;
  2663. }
  2664. local->channel = GET_INT_PARM(channel, card_idx);
  2665. local->beacon_int = GET_INT_PARM(beacon_int, card_idx);
  2666. local->dtim_period = GET_INT_PARM(dtim_period, card_idx);
  2667. local->wds_max_connections = 16;
  2668. local->tx_control = HFA384X_TX_CTRL_FLAGS;
  2669. local->manual_retry_count = -1;
  2670. local->rts_threshold = 2347;
  2671. local->fragm_threshold = 2346;
  2672. local->rssi_to_dBm = 100; /* default; to be overriden by
  2673. * cnfDbmAdjust, if available */
  2674. local->auth_algs = PRISM2_AUTH_OPEN | PRISM2_AUTH_SHARED_KEY;
  2675. local->sram_type = -1;
  2676. local->scan_channel_mask = 0xffff;
  2677. /* Initialize task queue structures */
  2678. INIT_WORK(&local->reset_queue, handle_reset_queue, local);
  2679. INIT_WORK(&local->set_multicast_list_queue,
  2680. hostap_set_multicast_list_queue, local->dev);
  2681. INIT_WORK(&local->set_tim_queue, handle_set_tim_queue, local);
  2682. INIT_LIST_HEAD(&local->set_tim_list);
  2683. spin_lock_init(&local->set_tim_lock);
  2684. INIT_WORK(&local->comms_qual_update, handle_comms_qual_update, local);
  2685. /* Initialize tasklets for handling hardware IRQ related operations
  2686. * outside hw IRQ handler */
  2687. #define HOSTAP_TASKLET_INIT(q, f, d) \
  2688. do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \
  2689. while (0)
  2690. HOSTAP_TASKLET_INIT(&local->bap_tasklet, hostap_bap_tasklet,
  2691. (unsigned long) local);
  2692. HOSTAP_TASKLET_INIT(&local->info_tasklet, hostap_info_tasklet,
  2693. (unsigned long) local);
  2694. hostap_info_init(local);
  2695. HOSTAP_TASKLET_INIT(&local->rx_tasklet,
  2696. hostap_rx_tasklet, (unsigned long) local);
  2697. skb_queue_head_init(&local->rx_list);
  2698. HOSTAP_TASKLET_INIT(&local->sta_tx_exc_tasklet,
  2699. hostap_sta_tx_exc_tasklet, (unsigned long) local);
  2700. skb_queue_head_init(&local->sta_tx_exc_list);
  2701. INIT_LIST_HEAD(&local->cmd_queue);
  2702. init_waitqueue_head(&local->hostscan_wq);
  2703. INIT_LIST_HEAD(&local->crypt_deinit_list);
  2704. init_timer(&local->crypt_deinit_timer);
  2705. local->crypt_deinit_timer.data = (unsigned long) local;
  2706. local->crypt_deinit_timer.function = prism2_crypt_deinit_handler;
  2707. init_timer(&local->passive_scan_timer);
  2708. local->passive_scan_timer.data = (unsigned long) local;
  2709. local->passive_scan_timer.function = hostap_passive_scan;
  2710. init_timer(&local->tick_timer);
  2711. local->tick_timer.data = (unsigned long) local;
  2712. local->tick_timer.function = hostap_tick_timer;
  2713. local->tick_timer.expires = jiffies + 2 * HZ;
  2714. add_timer(&local->tick_timer);
  2715. INIT_LIST_HEAD(&local->bss_list);
  2716. hostap_setup_dev(dev, local, 1);
  2717. local->saved_eth_header_parse = dev->hard_header_parse;
  2718. dev->hard_start_xmit = hostap_master_start_xmit;
  2719. dev->type = ARPHRD_IEEE80211;
  2720. dev->hard_header_parse = hostap_80211_header_parse;
  2721. rtnl_lock();
  2722. ret = dev_alloc_name(dev, "wifi%d");
  2723. SET_NETDEV_DEV(dev, sdev);
  2724. if (ret >= 0)
  2725. ret = register_netdevice(dev);
  2726. lockdep_set_class(&dev->_xmit_lock, &hostap_netdev_xmit_lock_key);
  2727. rtnl_unlock();
  2728. if (ret < 0) {
  2729. printk(KERN_WARNING "%s: register netdevice failed!\n",
  2730. dev_info);
  2731. goto fail;
  2732. }
  2733. printk(KERN_INFO "%s: Registered netdevice %s\n", dev_info, dev->name);
  2734. #ifndef PRISM2_NO_PROCFS_DEBUG
  2735. create_proc_read_entry("registers", 0, local->proc,
  2736. prism2_registers_proc_read, local);
  2737. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2738. hostap_init_data(local);
  2739. return dev;
  2740. fail:
  2741. free_netdev(dev);
  2742. return NULL;
  2743. }
  2744. static int hostap_hw_ready(struct net_device *dev)
  2745. {
  2746. struct hostap_interface *iface;
  2747. struct local_info *local;
  2748. iface = netdev_priv(dev);
  2749. local = iface->local;
  2750. local->ddev = hostap_add_interface(local, HOSTAP_INTERFACE_MAIN, 0,
  2751. "", dev_template);
  2752. if (local->ddev) {
  2753. if (local->iw_mode == IW_MODE_INFRA ||
  2754. local->iw_mode == IW_MODE_ADHOC) {
  2755. netif_carrier_off(local->dev);
  2756. netif_carrier_off(local->ddev);
  2757. }
  2758. hostap_init_proc(local);
  2759. hostap_init_ap_proc(local);
  2760. return 0;
  2761. }
  2762. return -1;
  2763. }
  2764. static void prism2_free_local_data(struct net_device *dev)
  2765. {
  2766. struct hostap_tx_callback_info *tx_cb, *tx_cb_prev;
  2767. int i;
  2768. struct hostap_interface *iface;
  2769. struct local_info *local;
  2770. struct list_head *ptr, *n;
  2771. if (dev == NULL)
  2772. return;
  2773. iface = netdev_priv(dev);
  2774. local = iface->local;
  2775. /* Unregister all netdevs before freeing local data. */
  2776. list_for_each_safe(ptr, n, &local->hostap_interfaces) {
  2777. iface = list_entry(ptr, struct hostap_interface, list);
  2778. if (iface->type == HOSTAP_INTERFACE_MASTER) {
  2779. /* special handling for this interface below */
  2780. continue;
  2781. }
  2782. hostap_remove_interface(iface->dev, 0, 1);
  2783. }
  2784. unregister_netdev(local->dev);
  2785. flush_scheduled_work();
  2786. if (timer_pending(&local->crypt_deinit_timer))
  2787. del_timer(&local->crypt_deinit_timer);
  2788. prism2_crypt_deinit_entries(local, 1);
  2789. if (timer_pending(&local->passive_scan_timer))
  2790. del_timer(&local->passive_scan_timer);
  2791. if (timer_pending(&local->tick_timer))
  2792. del_timer(&local->tick_timer);
  2793. prism2_clear_cmd_queue(local);
  2794. skb_queue_purge(&local->info_list);
  2795. skb_queue_purge(&local->rx_list);
  2796. skb_queue_purge(&local->sta_tx_exc_list);
  2797. if (local->dev_enabled)
  2798. prism2_callback(local, PRISM2_CALLBACK_DISABLE);
  2799. for (i = 0; i < WEP_KEYS; i++) {
  2800. struct ieee80211_crypt_data *crypt = local->crypt[i];
  2801. if (crypt) {
  2802. if (crypt->ops)
  2803. crypt->ops->deinit(crypt->priv);
  2804. kfree(crypt);
  2805. local->crypt[i] = NULL;
  2806. }
  2807. }
  2808. if (local->ap != NULL)
  2809. hostap_free_data(local->ap);
  2810. #ifndef PRISM2_NO_PROCFS_DEBUG
  2811. if (local->proc != NULL)
  2812. remove_proc_entry("registers", local->proc);
  2813. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2814. hostap_remove_proc(local);
  2815. tx_cb = local->tx_callback;
  2816. while (tx_cb != NULL) {
  2817. tx_cb_prev = tx_cb;
  2818. tx_cb = tx_cb->next;
  2819. kfree(tx_cb_prev);
  2820. }
  2821. hostap_set_hostapd(local, 0, 0);
  2822. hostap_set_hostapd_sta(local, 0, 0);
  2823. for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
  2824. if (local->frag_cache[i].skb != NULL)
  2825. dev_kfree_skb(local->frag_cache[i].skb);
  2826. }
  2827. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2828. prism2_download_free_data(local->dl_pri);
  2829. prism2_download_free_data(local->dl_sec);
  2830. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2831. prism2_clear_set_tim_queue(local);
  2832. list_for_each_safe(ptr, n, &local->bss_list) {
  2833. struct hostap_bss_info *bss =
  2834. list_entry(ptr, struct hostap_bss_info, list);
  2835. kfree(bss);
  2836. }
  2837. kfree(local->pda);
  2838. kfree(local->last_scan_results);
  2839. kfree(local->generic_elem);
  2840. free_netdev(local->dev);
  2841. }
  2842. #ifndef PRISM2_PLX
  2843. static void prism2_suspend(struct net_device *dev)
  2844. {
  2845. struct hostap_interface *iface;
  2846. struct local_info *local;
  2847. union iwreq_data wrqu;
  2848. iface = dev->priv;
  2849. local = iface->local;
  2850. /* Send disconnect event, e.g., to trigger reassociation after resume
  2851. * if wpa_supplicant is used. */
  2852. memset(&wrqu, 0, sizeof(wrqu));
  2853. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  2854. wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
  2855. /* Disable hardware and firmware */
  2856. prism2_hw_shutdown(dev, 0);
  2857. }
  2858. #endif /* PRISM2_PLX */
  2859. /* These might at some point be compiled separately and used as separate
  2860. * kernel modules or linked into one */
  2861. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2862. #include "hostap_download.c"
  2863. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2864. #ifdef PRISM2_CALLBACK
  2865. /* External hostap_callback.c file can be used to, e.g., blink activity led.
  2866. * This can use platform specific code and must define prism2_callback()
  2867. * function (if PRISM2_CALLBACK is not defined, these function calls are not
  2868. * used. */
  2869. #include "hostap_callback.c"
  2870. #endif /* PRISM2_CALLBACK */