hostap_hw.c 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444
  1. /*
  2. * Host AP (software wireless LAN access point) driver for
  3. * Intersil Prism2/2.5/3.
  4. *
  5. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  6. * <jkmaline@cc.hut.fi>
  7. * Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation. See README and COPYING for
  12. * more details.
  13. *
  14. * FIX:
  15. * - there is currently no way of associating TX packets to correct wds device
  16. * when TX Exc/OK event occurs, so all tx_packets and some
  17. * tx_errors/tx_dropped are added to the main netdevice; using sw_support
  18. * field in txdesc might be used to fix this (using Alloc event to increment
  19. * tx_packets would need some further info in txfid table)
  20. *
  21. * Buffer Access Path (BAP) usage:
  22. * Prism2 cards have two separate BAPs for accessing the card memory. These
  23. * should allow concurrent access to two different frames and the driver
  24. * previously used BAP0 for sending data and BAP1 for receiving data.
  25. * However, there seems to be number of issues with concurrent access and at
  26. * least one know hardware bug in using BAP0 and BAP1 concurrently with PCI
  27. * Prism2.5. Therefore, the driver now only uses BAP0 for moving data between
  28. * host and card memories. BAP0 accesses are protected with local->baplock
  29. * (spin_lock_bh) to prevent concurrent use.
  30. */
  31. #include <linux/config.h>
  32. #include <linux/version.h>
  33. #include <asm/delay.h>
  34. #include <asm/uaccess.h>
  35. #include <linux/slab.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/proc_fs.h>
  39. #include <linux/if_arp.h>
  40. #include <linux/delay.h>
  41. #include <linux/random.h>
  42. #include <linux/wait.h>
  43. #include <linux/sched.h>
  44. #include <linux/rtnetlink.h>
  45. #include <linux/wireless.h>
  46. #include <net/iw_handler.h>
  47. #include <net/ieee80211.h>
  48. #include <net/ieee80211_crypt.h>
  49. #include <asm/irq.h>
  50. #include "hostap_80211.h"
  51. #include "hostap.h"
  52. #include "hostap_ap.h"
  53. /* #define final_version */
  54. static int mtu = 1500;
  55. module_param(mtu, int, 0444);
  56. MODULE_PARM_DESC(mtu, "Maximum transfer unit");
  57. static int channel[MAX_PARM_DEVICES] = { 3, DEF_INTS };
  58. module_param_array(channel, int, NULL, 0444);
  59. MODULE_PARM_DESC(channel, "Initial channel");
  60. static char essid[33] = "test";
  61. module_param_string(essid, essid, sizeof(essid), 0444);
  62. MODULE_PARM_DESC(essid, "Host AP's ESSID");
  63. static int iw_mode[MAX_PARM_DEVICES] = { IW_MODE_MASTER, DEF_INTS };
  64. module_param_array(iw_mode, int, NULL, 0444);
  65. MODULE_PARM_DESC(iw_mode, "Initial operation mode");
  66. static int beacon_int[MAX_PARM_DEVICES] = { 100, DEF_INTS };
  67. module_param_array(beacon_int, int, NULL, 0444);
  68. MODULE_PARM_DESC(beacon_int, "Beacon interval (1 = 1024 usec)");
  69. static int dtim_period[MAX_PARM_DEVICES] = { 1, DEF_INTS };
  70. module_param_array(dtim_period, int, NULL, 0444);
  71. MODULE_PARM_DESC(dtim_period, "DTIM period");
  72. static char dev_template[16] = "wlan%d";
  73. module_param_string(dev_template, dev_template, sizeof(dev_template), 0444);
  74. MODULE_PARM_DESC(dev_template, "Prefix for network device name (default: "
  75. "wlan%d)");
  76. #ifdef final_version
  77. #define EXTRA_EVENTS_WTERR 0
  78. #else
  79. /* check WTERR events (Wait Time-out) in development versions */
  80. #define EXTRA_EVENTS_WTERR HFA384X_EV_WTERR
  81. #endif
  82. /* Events that will be using BAP0 */
  83. #define HFA384X_BAP0_EVENTS \
  84. (HFA384X_EV_TXEXC | HFA384X_EV_RX | HFA384X_EV_INFO | HFA384X_EV_TX)
  85. /* event mask, i.e., events that will result in an interrupt */
  86. #define HFA384X_EVENT_MASK \
  87. (HFA384X_BAP0_EVENTS | HFA384X_EV_ALLOC | HFA384X_EV_INFDROP | \
  88. HFA384X_EV_CMD | HFA384X_EV_TICK | \
  89. EXTRA_EVENTS_WTERR)
  90. /* Default TX control flags: use 802.11 headers and request interrupt for
  91. * failed transmits. Frames that request ACK callback, will add
  92. * _TX_OK flag and _ALT_RTRY flag may be used to select different retry policy.
  93. */
  94. #define HFA384X_TX_CTRL_FLAGS \
  95. (HFA384X_TX_CTRL_802_11 | HFA384X_TX_CTRL_TX_EX)
  96. /* ca. 1 usec */
  97. #define HFA384X_CMD_BUSY_TIMEOUT 5000
  98. #define HFA384X_BAP_BUSY_TIMEOUT 50000
  99. /* ca. 10 usec */
  100. #define HFA384X_CMD_COMPL_TIMEOUT 20000
  101. #define HFA384X_DL_COMPL_TIMEOUT 1000000
  102. /* Wait times for initialization; yield to other processes to avoid busy
  103. * waiting for long time. */
  104. #define HFA384X_INIT_TIMEOUT (HZ / 2) /* 500 ms */
  105. #define HFA384X_ALLOC_COMPL_TIMEOUT (HZ / 20) /* 50 ms */
  106. static void prism2_hw_reset(struct net_device *dev);
  107. static void prism2_check_sta_fw_version(local_info_t *local);
  108. #ifdef PRISM2_DOWNLOAD_SUPPORT
  109. /* hostap_download.c */
  110. static int prism2_download_aux_dump(struct net_device *dev,
  111. unsigned int addr, int len, u8 *buf);
  112. static u8 * prism2_read_pda(struct net_device *dev);
  113. static int prism2_download(local_info_t *local,
  114. struct prism2_download_param *param);
  115. static void prism2_download_free_data(struct prism2_download_data *dl);
  116. static int prism2_download_volatile(local_info_t *local,
  117. struct prism2_download_data *param);
  118. static int prism2_download_genesis(local_info_t *local,
  119. struct prism2_download_data *param);
  120. static int prism2_get_ram_size(local_info_t *local);
  121. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  122. #ifndef final_version
  123. /* magic value written to SWSUPPORT0 reg. for detecting whether card is still
  124. * present */
  125. #define HFA384X_MAGIC 0x8A32
  126. #endif
  127. static u16 hfa384x_read_reg(struct net_device *dev, u16 reg)
  128. {
  129. return HFA384X_INW(reg);
  130. }
  131. static void hfa384x_read_regs(struct net_device *dev,
  132. struct hfa384x_regs *regs)
  133. {
  134. regs->cmd = HFA384X_INW(HFA384X_CMD_OFF);
  135. regs->evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
  136. regs->offset0 = HFA384X_INW(HFA384X_OFFSET0_OFF);
  137. regs->offset1 = HFA384X_INW(HFA384X_OFFSET1_OFF);
  138. regs->swsupport0 = HFA384X_INW(HFA384X_SWSUPPORT0_OFF);
  139. }
  140. /**
  141. * __hostap_cmd_queue_free - Free Prism2 command queue entry (private)
  142. * @local: pointer to private Host AP driver data
  143. * @entry: Prism2 command queue entry to be freed
  144. * @del_req: request the entry to be removed
  145. *
  146. * Internal helper function for freeing Prism2 command queue entries.
  147. * Caller must have acquired local->cmdlock before calling this function.
  148. */
  149. static inline void __hostap_cmd_queue_free(local_info_t *local,
  150. struct hostap_cmd_queue *entry,
  151. int del_req)
  152. {
  153. if (del_req) {
  154. entry->del_req = 1;
  155. if (!list_empty(&entry->list)) {
  156. list_del_init(&entry->list);
  157. local->cmd_queue_len--;
  158. }
  159. }
  160. if (atomic_dec_and_test(&entry->usecnt) && entry->del_req)
  161. kfree(entry);
  162. }
  163. /**
  164. * hostap_cmd_queue_free - Free Prism2 command queue entry
  165. * @local: pointer to private Host AP driver data
  166. * @entry: Prism2 command queue entry to be freed
  167. * @del_req: request the entry to be removed
  168. *
  169. * Free a Prism2 command queue entry.
  170. */
  171. static inline void hostap_cmd_queue_free(local_info_t *local,
  172. struct hostap_cmd_queue *entry,
  173. int del_req)
  174. {
  175. unsigned long flags;
  176. spin_lock_irqsave(&local->cmdlock, flags);
  177. __hostap_cmd_queue_free(local, entry, del_req);
  178. spin_unlock_irqrestore(&local->cmdlock, flags);
  179. }
  180. /**
  181. * prism2_clear_cmd_queue - Free all pending Prism2 command queue entries
  182. * @local: pointer to private Host AP driver data
  183. */
  184. static void prism2_clear_cmd_queue(local_info_t *local)
  185. {
  186. struct list_head *ptr, *n;
  187. unsigned long flags;
  188. struct hostap_cmd_queue *entry;
  189. spin_lock_irqsave(&local->cmdlock, flags);
  190. list_for_each_safe(ptr, n, &local->cmd_queue) {
  191. entry = list_entry(ptr, struct hostap_cmd_queue, list);
  192. atomic_inc(&entry->usecnt);
  193. printk(KERN_DEBUG "%s: removed pending cmd_queue entry "
  194. "(type=%d, cmd=0x%04x, param0=0x%04x)\n",
  195. local->dev->name, entry->type, entry->cmd,
  196. entry->param0);
  197. __hostap_cmd_queue_free(local, entry, 1);
  198. }
  199. if (local->cmd_queue_len) {
  200. /* This should not happen; print debug message and clear
  201. * queue length. */
  202. printk(KERN_DEBUG "%s: cmd_queue_len (%d) not zero after "
  203. "flush\n", local->dev->name, local->cmd_queue_len);
  204. local->cmd_queue_len = 0;
  205. }
  206. spin_unlock_irqrestore(&local->cmdlock, flags);
  207. }
  208. /**
  209. * hfa384x_cmd_issue - Issue a Prism2 command to the hardware
  210. * @dev: pointer to net_device
  211. * @entry: Prism2 command queue entry to be issued
  212. */
  213. static inline int hfa384x_cmd_issue(struct net_device *dev,
  214. struct hostap_cmd_queue *entry)
  215. {
  216. struct hostap_interface *iface;
  217. local_info_t *local;
  218. int tries;
  219. u16 reg;
  220. unsigned long flags;
  221. iface = netdev_priv(dev);
  222. local = iface->local;
  223. if (local->func->card_present && !local->func->card_present(local))
  224. return -ENODEV;
  225. if (entry->issued) {
  226. printk(KERN_DEBUG "%s: driver bug - re-issuing command @%p\n",
  227. dev->name, entry);
  228. }
  229. /* wait until busy bit is clear; this should always be clear since the
  230. * commands are serialized */
  231. tries = HFA384X_CMD_BUSY_TIMEOUT;
  232. while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
  233. tries--;
  234. udelay(1);
  235. }
  236. #ifndef final_version
  237. if (tries != HFA384X_CMD_BUSY_TIMEOUT) {
  238. prism2_io_debug_error(dev, 1);
  239. printk(KERN_DEBUG "%s: hfa384x_cmd_issue: cmd reg was busy "
  240. "for %d usec\n", dev->name,
  241. HFA384X_CMD_BUSY_TIMEOUT - tries);
  242. }
  243. #endif
  244. if (tries == 0) {
  245. reg = HFA384X_INW(HFA384X_CMD_OFF);
  246. prism2_io_debug_error(dev, 2);
  247. printk(KERN_DEBUG "%s: hfa384x_cmd_issue - timeout - "
  248. "reg=0x%04x\n", dev->name, reg);
  249. return -ETIMEDOUT;
  250. }
  251. /* write command */
  252. spin_lock_irqsave(&local->cmdlock, flags);
  253. HFA384X_OUTW(entry->param0, HFA384X_PARAM0_OFF);
  254. HFA384X_OUTW(entry->param1, HFA384X_PARAM1_OFF);
  255. HFA384X_OUTW(entry->cmd, HFA384X_CMD_OFF);
  256. entry->issued = 1;
  257. spin_unlock_irqrestore(&local->cmdlock, flags);
  258. return 0;
  259. }
  260. /**
  261. * hfa384x_cmd - Issue a Prism2 command and wait (sleep) for completion
  262. * @dev: pointer to net_device
  263. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  264. * @param0: value for Param0 register
  265. * @param1: value for Param1 register (pointer; %NULL if not used)
  266. * @resp0: pointer for Resp0 data or %NULL if Resp0 is not needed
  267. *
  268. * Issue given command (possibly after waiting in command queue) and sleep
  269. * until the command is completed (or timed out or interrupted). This can be
  270. * called only from user process context.
  271. */
  272. static int hfa384x_cmd(struct net_device *dev, u16 cmd, u16 param0,
  273. u16 *param1, u16 *resp0)
  274. {
  275. struct hostap_interface *iface;
  276. local_info_t *local;
  277. int err, res, issue, issued = 0;
  278. unsigned long flags;
  279. struct hostap_cmd_queue *entry;
  280. DECLARE_WAITQUEUE(wait, current);
  281. iface = netdev_priv(dev);
  282. local = iface->local;
  283. if (in_interrupt()) {
  284. printk(KERN_DEBUG "%s: hfa384x_cmd called from interrupt "
  285. "context\n", dev->name);
  286. return -1;
  287. }
  288. if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN) {
  289. printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
  290. dev->name);
  291. return -1;
  292. }
  293. if (signal_pending(current))
  294. return -EINTR;
  295. entry = (struct hostap_cmd_queue *)
  296. kmalloc(sizeof(*entry), GFP_ATOMIC);
  297. if (entry == NULL) {
  298. printk(KERN_DEBUG "%s: hfa384x_cmd - kmalloc failed\n",
  299. dev->name);
  300. return -ENOMEM;
  301. }
  302. memset(entry, 0, sizeof(*entry));
  303. atomic_set(&entry->usecnt, 1);
  304. entry->type = CMD_SLEEP;
  305. entry->cmd = cmd;
  306. entry->param0 = param0;
  307. if (param1)
  308. entry->param1 = *param1;
  309. init_waitqueue_head(&entry->compl);
  310. /* prepare to wait for command completion event, but do not sleep yet
  311. */
  312. add_wait_queue(&entry->compl, &wait);
  313. set_current_state(TASK_INTERRUPTIBLE);
  314. spin_lock_irqsave(&local->cmdlock, flags);
  315. issue = list_empty(&local->cmd_queue);
  316. if (issue)
  317. entry->issuing = 1;
  318. list_add_tail(&entry->list, &local->cmd_queue);
  319. local->cmd_queue_len++;
  320. spin_unlock_irqrestore(&local->cmdlock, flags);
  321. err = 0;
  322. if (!issue)
  323. goto wait_completion;
  324. if (signal_pending(current))
  325. err = -EINTR;
  326. if (!err) {
  327. if (hfa384x_cmd_issue(dev, entry))
  328. err = -ETIMEDOUT;
  329. else
  330. issued = 1;
  331. }
  332. wait_completion:
  333. if (!err && entry->type != CMD_COMPLETED) {
  334. /* sleep until command is completed or timed out */
  335. res = schedule_timeout(2 * HZ);
  336. } else
  337. res = -1;
  338. if (!err && signal_pending(current))
  339. err = -EINTR;
  340. if (err && issued) {
  341. /* the command was issued, so a CmdCompl event should occur
  342. * soon; however, there's a pending signal and
  343. * schedule_timeout() would be interrupted; wait a short period
  344. * of time to avoid removing entry from the list before
  345. * CmdCompl event */
  346. udelay(300);
  347. }
  348. set_current_state(TASK_RUNNING);
  349. remove_wait_queue(&entry->compl, &wait);
  350. /* If entry->list is still in the list, it must be removed
  351. * first and in this case prism2_cmd_ev() does not yet have
  352. * local reference to it, and the data can be kfree()'d
  353. * here. If the command completion event is still generated,
  354. * it will be assigned to next (possibly) pending command, but
  355. * the driver will reset the card anyway due to timeout
  356. *
  357. * If the entry is not in the list prism2_cmd_ev() has a local
  358. * reference to it, but keeps cmdlock as long as the data is
  359. * needed, so the data can be kfree()'d here. */
  360. /* FIX: if the entry->list is in the list, it has not been completed
  361. * yet, so removing it here is somewhat wrong.. this could cause
  362. * references to freed memory and next list_del() causing NULL pointer
  363. * dereference.. it would probably be better to leave the entry in the
  364. * list and the list should be emptied during hw reset */
  365. spin_lock_irqsave(&local->cmdlock, flags);
  366. if (!list_empty(&entry->list)) {
  367. printk(KERN_DEBUG "%s: hfa384x_cmd: entry still in list? "
  368. "(entry=%p, type=%d, res=%d)\n", dev->name, entry,
  369. entry->type, res);
  370. list_del_init(&entry->list);
  371. local->cmd_queue_len--;
  372. }
  373. spin_unlock_irqrestore(&local->cmdlock, flags);
  374. if (err) {
  375. printk(KERN_DEBUG "%s: hfa384x_cmd: interrupted; err=%d\n",
  376. dev->name, err);
  377. res = err;
  378. goto done;
  379. }
  380. if (entry->type != CMD_COMPLETED) {
  381. u16 reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
  382. printk(KERN_DEBUG "%s: hfa384x_cmd: command was not "
  383. "completed (res=%d, entry=%p, type=%d, cmd=0x%04x, "
  384. "param0=0x%04x, EVSTAT=%04x INTEN=%04x)\n", dev->name,
  385. res, entry, entry->type, entry->cmd, entry->param0, reg,
  386. HFA384X_INW(HFA384X_INTEN_OFF));
  387. if (reg & HFA384X_EV_CMD) {
  388. /* Command completion event is pending, but the
  389. * interrupt was not delivered - probably an issue
  390. * with pcmcia-cs configuration. */
  391. printk(KERN_WARNING "%s: interrupt delivery does not "
  392. "seem to work\n", dev->name);
  393. }
  394. prism2_io_debug_error(dev, 3);
  395. res = -ETIMEDOUT;
  396. goto done;
  397. }
  398. if (resp0 != NULL)
  399. *resp0 = entry->resp0;
  400. #ifndef final_version
  401. if (entry->res) {
  402. printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x, "
  403. "resp0=0x%04x\n",
  404. dev->name, cmd, entry->res, entry->resp0);
  405. }
  406. #endif /* final_version */
  407. res = entry->res;
  408. done:
  409. hostap_cmd_queue_free(local, entry, 1);
  410. return res;
  411. }
  412. /**
  413. * hfa384x_cmd_callback - Issue a Prism2 command; callback when completed
  414. * @dev: pointer to net_device
  415. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  416. * @param0: value for Param0 register
  417. * @callback: command completion callback function (%NULL = no callback)
  418. * @context: context data to be given to the callback function
  419. *
  420. * Issue given command (possibly after waiting in command queue) and use
  421. * callback function to indicate command completion. This can be called both
  422. * from user and interrupt context. The callback function will be called in
  423. * hardware IRQ context. It can be %NULL, when no function is called when
  424. * command is completed.
  425. */
  426. static int hfa384x_cmd_callback(struct net_device *dev, u16 cmd, u16 param0,
  427. void (*callback)(struct net_device *dev,
  428. long context, u16 resp0,
  429. u16 status),
  430. long context)
  431. {
  432. struct hostap_interface *iface;
  433. local_info_t *local;
  434. int issue, ret;
  435. unsigned long flags;
  436. struct hostap_cmd_queue *entry;
  437. iface = netdev_priv(dev);
  438. local = iface->local;
  439. if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN + 2) {
  440. printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
  441. dev->name);
  442. return -1;
  443. }
  444. entry = (struct hostap_cmd_queue *)
  445. kmalloc(sizeof(*entry), GFP_ATOMIC);
  446. if (entry == NULL) {
  447. printk(KERN_DEBUG "%s: hfa384x_cmd_callback - kmalloc "
  448. "failed\n", dev->name);
  449. return -ENOMEM;
  450. }
  451. memset(entry, 0, sizeof(*entry));
  452. atomic_set(&entry->usecnt, 1);
  453. entry->type = CMD_CALLBACK;
  454. entry->cmd = cmd;
  455. entry->param0 = param0;
  456. entry->callback = callback;
  457. entry->context = context;
  458. spin_lock_irqsave(&local->cmdlock, flags);
  459. issue = list_empty(&local->cmd_queue);
  460. if (issue)
  461. entry->issuing = 1;
  462. list_add_tail(&entry->list, &local->cmd_queue);
  463. local->cmd_queue_len++;
  464. spin_unlock_irqrestore(&local->cmdlock, flags);
  465. if (issue && hfa384x_cmd_issue(dev, entry))
  466. ret = -ETIMEDOUT;
  467. else
  468. ret = 0;
  469. hostap_cmd_queue_free(local, entry, ret);
  470. return ret;
  471. }
  472. /**
  473. * __hfa384x_cmd_no_wait - Issue a Prism2 command (private)
  474. * @dev: pointer to net_device
  475. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  476. * @param0: value for Param0 register
  477. * @io_debug_num: I/O debug error number
  478. *
  479. * Shared helper function for hfa384x_cmd_wait() and hfa384x_cmd_no_wait().
  480. */
  481. static int __hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd, u16 param0,
  482. int io_debug_num)
  483. {
  484. int tries;
  485. u16 reg;
  486. /* wait until busy bit is clear; this should always be clear since the
  487. * commands are serialized */
  488. tries = HFA384X_CMD_BUSY_TIMEOUT;
  489. while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
  490. tries--;
  491. udelay(1);
  492. }
  493. if (tries == 0) {
  494. reg = HFA384X_INW(HFA384X_CMD_OFF);
  495. prism2_io_debug_error(dev, io_debug_num);
  496. printk(KERN_DEBUG "%s: __hfa384x_cmd_no_wait(%d) - timeout - "
  497. "reg=0x%04x\n", dev->name, io_debug_num, reg);
  498. return -ETIMEDOUT;
  499. }
  500. /* write command */
  501. HFA384X_OUTW(param0, HFA384X_PARAM0_OFF);
  502. HFA384X_OUTW(cmd, HFA384X_CMD_OFF);
  503. return 0;
  504. }
  505. /**
  506. * hfa384x_cmd_wait - Issue a Prism2 command and busy wait for completion
  507. * @dev: pointer to net_device
  508. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  509. * @param0: value for Param0 register
  510. */
  511. static int hfa384x_cmd_wait(struct net_device *dev, u16 cmd, u16 param0)
  512. {
  513. int res, tries;
  514. u16 reg;
  515. res = __hfa384x_cmd_no_wait(dev, cmd, param0, 4);
  516. if (res)
  517. return res;
  518. /* wait for command completion */
  519. if ((cmd & HFA384X_CMDCODE_MASK) == HFA384X_CMDCODE_DOWNLOAD)
  520. tries = HFA384X_DL_COMPL_TIMEOUT;
  521. else
  522. tries = HFA384X_CMD_COMPL_TIMEOUT;
  523. while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
  524. tries > 0) {
  525. tries--;
  526. udelay(10);
  527. }
  528. if (tries == 0) {
  529. reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
  530. prism2_io_debug_error(dev, 5);
  531. printk(KERN_DEBUG "%s: hfa384x_cmd_wait - timeout2 - "
  532. "reg=0x%04x\n", dev->name, reg);
  533. return -ETIMEDOUT;
  534. }
  535. res = (HFA384X_INW(HFA384X_STATUS_OFF) &
  536. (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) | BIT(9) |
  537. BIT(8))) >> 8;
  538. #ifndef final_version
  539. if (res) {
  540. printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x\n",
  541. dev->name, cmd, res);
  542. }
  543. #endif
  544. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  545. return res;
  546. }
  547. /**
  548. * hfa384x_cmd_no_wait - Issue a Prism2 command; do not wait for completion
  549. * @dev: pointer to net_device
  550. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  551. * @param0: value for Param0 register
  552. */
  553. static inline int hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd,
  554. u16 param0)
  555. {
  556. return __hfa384x_cmd_no_wait(dev, cmd, param0, 6);
  557. }
  558. /**
  559. * prism2_cmd_ev - Prism2 command completion event handler
  560. * @dev: pointer to net_device
  561. *
  562. * Interrupt handler for command completion events. Called by the main
  563. * interrupt handler in hardware IRQ context. Read Resp0 and status registers
  564. * from the hardware and ACK the event. Depending on the issued command type
  565. * either wake up the sleeping process that is waiting for command completion
  566. * or call the callback function. Issue the next command, if one is pending.
  567. */
  568. static void prism2_cmd_ev(struct net_device *dev)
  569. {
  570. struct hostap_interface *iface;
  571. local_info_t *local;
  572. struct hostap_cmd_queue *entry = NULL;
  573. iface = netdev_priv(dev);
  574. local = iface->local;
  575. spin_lock(&local->cmdlock);
  576. if (!list_empty(&local->cmd_queue)) {
  577. entry = list_entry(local->cmd_queue.next,
  578. struct hostap_cmd_queue, list);
  579. atomic_inc(&entry->usecnt);
  580. list_del_init(&entry->list);
  581. local->cmd_queue_len--;
  582. if (!entry->issued) {
  583. printk(KERN_DEBUG "%s: Command completion event, but "
  584. "cmd not issued\n", dev->name);
  585. __hostap_cmd_queue_free(local, entry, 1);
  586. entry = NULL;
  587. }
  588. }
  589. spin_unlock(&local->cmdlock);
  590. if (!entry) {
  591. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  592. printk(KERN_DEBUG "%s: Command completion event, but no "
  593. "pending commands\n", dev->name);
  594. return;
  595. }
  596. entry->resp0 = HFA384X_INW(HFA384X_RESP0_OFF);
  597. entry->res = (HFA384X_INW(HFA384X_STATUS_OFF) &
  598. (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) |
  599. BIT(9) | BIT(8))) >> 8;
  600. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  601. /* TODO: rest of the CmdEv handling could be moved to tasklet */
  602. if (entry->type == CMD_SLEEP) {
  603. entry->type = CMD_COMPLETED;
  604. wake_up_interruptible(&entry->compl);
  605. } else if (entry->type == CMD_CALLBACK) {
  606. if (entry->callback)
  607. entry->callback(dev, entry->context, entry->resp0,
  608. entry->res);
  609. } else {
  610. printk(KERN_DEBUG "%s: Invalid command completion type %d\n",
  611. dev->name, entry->type);
  612. }
  613. hostap_cmd_queue_free(local, entry, 1);
  614. /* issue next command, if pending */
  615. entry = NULL;
  616. spin_lock(&local->cmdlock);
  617. if (!list_empty(&local->cmd_queue)) {
  618. entry = list_entry(local->cmd_queue.next,
  619. struct hostap_cmd_queue, list);
  620. if (entry->issuing) {
  621. /* hfa384x_cmd() has already started issuing this
  622. * command, so do not start here */
  623. entry = NULL;
  624. }
  625. if (entry)
  626. atomic_inc(&entry->usecnt);
  627. }
  628. spin_unlock(&local->cmdlock);
  629. if (entry) {
  630. /* issue next command; if command issuing fails, remove the
  631. * entry from cmd_queue */
  632. int res = hfa384x_cmd_issue(dev, entry);
  633. spin_lock(&local->cmdlock);
  634. __hostap_cmd_queue_free(local, entry, res);
  635. spin_unlock(&local->cmdlock);
  636. }
  637. }
  638. static inline int hfa384x_wait_offset(struct net_device *dev, u16 o_off)
  639. {
  640. int tries = HFA384X_BAP_BUSY_TIMEOUT;
  641. int res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
  642. while (res && tries > 0) {
  643. tries--;
  644. udelay(1);
  645. res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
  646. }
  647. return res;
  648. }
  649. /* Offset must be even */
  650. static int hfa384x_setup_bap(struct net_device *dev, u16 bap, u16 id,
  651. int offset)
  652. {
  653. u16 o_off, s_off;
  654. int ret = 0;
  655. if (offset % 2 || bap > 1)
  656. return -EINVAL;
  657. if (bap == BAP1) {
  658. o_off = HFA384X_OFFSET1_OFF;
  659. s_off = HFA384X_SELECT1_OFF;
  660. } else {
  661. o_off = HFA384X_OFFSET0_OFF;
  662. s_off = HFA384X_SELECT0_OFF;
  663. }
  664. if (hfa384x_wait_offset(dev, o_off)) {
  665. prism2_io_debug_error(dev, 7);
  666. printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout before\n",
  667. dev->name);
  668. ret = -ETIMEDOUT;
  669. goto out;
  670. }
  671. HFA384X_OUTW(id, s_off);
  672. HFA384X_OUTW(offset, o_off);
  673. if (hfa384x_wait_offset(dev, o_off)) {
  674. prism2_io_debug_error(dev, 8);
  675. printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout after\n",
  676. dev->name);
  677. ret = -ETIMEDOUT;
  678. goto out;
  679. }
  680. #ifndef final_version
  681. if (HFA384X_INW(o_off) & HFA384X_OFFSET_ERR) {
  682. prism2_io_debug_error(dev, 9);
  683. printk(KERN_DEBUG "%s: hfa384x_setup_bap - offset error "
  684. "(%d,0x04%x,%d); reg=0x%04x\n",
  685. dev->name, bap, id, offset, HFA384X_INW(o_off));
  686. ret = -EINVAL;
  687. }
  688. #endif
  689. out:
  690. return ret;
  691. }
  692. static int hfa384x_get_rid(struct net_device *dev, u16 rid, void *buf, int len,
  693. int exact_len)
  694. {
  695. struct hostap_interface *iface;
  696. local_info_t *local;
  697. int res, rlen = 0;
  698. struct hfa384x_rid_hdr rec;
  699. iface = netdev_priv(dev);
  700. local = iface->local;
  701. if (local->no_pri) {
  702. printk(KERN_DEBUG "%s: cannot get RID %04x (len=%d) - no PRI "
  703. "f/w\n", dev->name, rid, len);
  704. return -ENOTTY; /* Well.. not really correct, but return
  705. * something unique enough.. */
  706. }
  707. if ((local->func->card_present && !local->func->card_present(local)) ||
  708. local->hw_downloading)
  709. return -ENODEV;
  710. res = down_interruptible(&local->rid_bap_sem);
  711. if (res)
  712. return res;
  713. res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS, rid, NULL, NULL);
  714. if (res) {
  715. printk(KERN_DEBUG "%s: hfa384x_get_rid: CMDCODE_ACCESS failed "
  716. "(res=%d, rid=%04x, len=%d)\n",
  717. dev->name, res, rid, len);
  718. up(&local->rid_bap_sem);
  719. return res;
  720. }
  721. spin_lock_bh(&local->baplock);
  722. res = hfa384x_setup_bap(dev, BAP0, rid, 0);
  723. if (!res)
  724. res = hfa384x_from_bap(dev, BAP0, &rec, sizeof(rec));
  725. if (le16_to_cpu(rec.len) == 0) {
  726. /* RID not available */
  727. res = -ENODATA;
  728. }
  729. rlen = (le16_to_cpu(rec.len) - 1) * 2;
  730. if (!res && exact_len && rlen != len) {
  731. printk(KERN_DEBUG "%s: hfa384x_get_rid - RID len mismatch: "
  732. "rid=0x%04x, len=%d (expected %d)\n",
  733. dev->name, rid, rlen, len);
  734. res = -ENODATA;
  735. }
  736. if (!res)
  737. res = hfa384x_from_bap(dev, BAP0, buf, len);
  738. spin_unlock_bh(&local->baplock);
  739. up(&local->rid_bap_sem);
  740. if (res) {
  741. if (res != -ENODATA)
  742. printk(KERN_DEBUG "%s: hfa384x_get_rid (rid=%04x, "
  743. "len=%d) - failed - res=%d\n", dev->name, rid,
  744. len, res);
  745. if (res == -ETIMEDOUT)
  746. prism2_hw_reset(dev);
  747. return res;
  748. }
  749. return rlen;
  750. }
  751. static int hfa384x_set_rid(struct net_device *dev, u16 rid, void *buf, int len)
  752. {
  753. struct hostap_interface *iface;
  754. local_info_t *local;
  755. struct hfa384x_rid_hdr rec;
  756. int res;
  757. iface = netdev_priv(dev);
  758. local = iface->local;
  759. if (local->no_pri) {
  760. printk(KERN_DEBUG "%s: cannot set RID %04x (len=%d) - no PRI "
  761. "f/w\n", dev->name, rid, len);
  762. return -ENOTTY; /* Well.. not really correct, but return
  763. * something unique enough.. */
  764. }
  765. if ((local->func->card_present && !local->func->card_present(local)) ||
  766. local->hw_downloading)
  767. return -ENODEV;
  768. rec.rid = cpu_to_le16(rid);
  769. /* RID len in words and +1 for rec.rid */
  770. rec.len = cpu_to_le16(len / 2 + len % 2 + 1);
  771. res = down_interruptible(&local->rid_bap_sem);
  772. if (res)
  773. return res;
  774. spin_lock_bh(&local->baplock);
  775. res = hfa384x_setup_bap(dev, BAP0, rid, 0);
  776. if (!res)
  777. res = hfa384x_to_bap(dev, BAP0, &rec, sizeof(rec));
  778. if (!res)
  779. res = hfa384x_to_bap(dev, BAP0, buf, len);
  780. spin_unlock_bh(&local->baplock);
  781. if (res) {
  782. printk(KERN_DEBUG "%s: hfa384x_set_rid (rid=%04x, len=%d) - "
  783. "failed - res=%d\n", dev->name, rid, len, res);
  784. up(&local->rid_bap_sem);
  785. return res;
  786. }
  787. res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS_WRITE, rid, NULL, NULL);
  788. up(&local->rid_bap_sem);
  789. if (res) {
  790. printk(KERN_DEBUG "%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE "
  791. "failed (res=%d, rid=%04x, len=%d)\n",
  792. dev->name, res, rid, len);
  793. return res;
  794. }
  795. if (res == -ETIMEDOUT)
  796. prism2_hw_reset(dev);
  797. return res;
  798. }
  799. static void hfa384x_disable_interrupts(struct net_device *dev)
  800. {
  801. /* disable interrupts and clear event status */
  802. HFA384X_OUTW(0, HFA384X_INTEN_OFF);
  803. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  804. }
  805. static void hfa384x_enable_interrupts(struct net_device *dev)
  806. {
  807. /* ack pending events and enable interrupts from selected events */
  808. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  809. HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
  810. }
  811. static void hfa384x_events_no_bap0(struct net_device *dev)
  812. {
  813. HFA384X_OUTW(HFA384X_EVENT_MASK & ~HFA384X_BAP0_EVENTS,
  814. HFA384X_INTEN_OFF);
  815. }
  816. static void hfa384x_events_all(struct net_device *dev)
  817. {
  818. HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
  819. }
  820. static void hfa384x_events_only_cmd(struct net_device *dev)
  821. {
  822. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_INTEN_OFF);
  823. }
  824. static u16 hfa384x_allocate_fid(struct net_device *dev, int len)
  825. {
  826. u16 fid;
  827. unsigned long delay;
  828. /* FIX: this could be replace with hfa384x_cmd() if the Alloc event
  829. * below would be handled like CmdCompl event (sleep here, wake up from
  830. * interrupt handler */
  831. if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_ALLOC, len)) {
  832. printk(KERN_DEBUG "%s: cannot allocate fid, len=%d\n",
  833. dev->name, len);
  834. return 0xffff;
  835. }
  836. delay = jiffies + HFA384X_ALLOC_COMPL_TIMEOUT;
  837. while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC) &&
  838. time_before(jiffies, delay))
  839. yield();
  840. if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC)) {
  841. printk("%s: fid allocate, len=%d - timeout\n", dev->name, len);
  842. return 0xffff;
  843. }
  844. fid = HFA384X_INW(HFA384X_ALLOCFID_OFF);
  845. HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
  846. return fid;
  847. }
  848. static int prism2_reset_port(struct net_device *dev)
  849. {
  850. struct hostap_interface *iface;
  851. local_info_t *local;
  852. int res;
  853. iface = netdev_priv(dev);
  854. local = iface->local;
  855. if (!local->dev_enabled)
  856. return 0;
  857. res = hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0,
  858. NULL, NULL);
  859. if (res)
  860. printk(KERN_DEBUG "%s: reset port failed to disable port\n",
  861. dev->name);
  862. else {
  863. res = hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0,
  864. NULL, NULL);
  865. if (res)
  866. printk(KERN_DEBUG "%s: reset port failed to enable "
  867. "port\n", dev->name);
  868. }
  869. /* It looks like at least some STA firmware versions reset
  870. * fragmentation threshold back to 2346 after enable command. Restore
  871. * the configured value, if it differs from this default. */
  872. if (local->fragm_threshold != 2346 &&
  873. hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
  874. local->fragm_threshold)) {
  875. printk(KERN_DEBUG "%s: failed to restore fragmentation "
  876. "threshold (%d) after Port0 enable\n",
  877. dev->name, local->fragm_threshold);
  878. }
  879. return res;
  880. }
  881. static int prism2_get_version_info(struct net_device *dev, u16 rid,
  882. const char *txt)
  883. {
  884. struct hfa384x_comp_ident comp;
  885. struct hostap_interface *iface;
  886. local_info_t *local;
  887. iface = netdev_priv(dev);
  888. local = iface->local;
  889. if (local->no_pri) {
  890. /* PRI f/w not yet available - cannot read RIDs */
  891. return -1;
  892. }
  893. if (hfa384x_get_rid(dev, rid, &comp, sizeof(comp), 1) < 0) {
  894. printk(KERN_DEBUG "Could not get RID for component %s\n", txt);
  895. return -1;
  896. }
  897. printk(KERN_INFO "%s: %s: id=0x%02x v%d.%d.%d\n", dev->name, txt,
  898. __le16_to_cpu(comp.id), __le16_to_cpu(comp.major),
  899. __le16_to_cpu(comp.minor), __le16_to_cpu(comp.variant));
  900. return 0;
  901. }
  902. static int prism2_setup_rids(struct net_device *dev)
  903. {
  904. struct hostap_interface *iface;
  905. local_info_t *local;
  906. u16 tmp;
  907. int ret = 0;
  908. iface = netdev_priv(dev);
  909. local = iface->local;
  910. hostap_set_word(dev, HFA384X_RID_TICKTIME, 2000);
  911. if (!local->fw_ap) {
  912. tmp = hostap_get_porttype(local);
  913. ret = hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, tmp);
  914. if (ret) {
  915. printk("%s: Port type setting to %d failed\n",
  916. dev->name, tmp);
  917. goto fail;
  918. }
  919. }
  920. /* Setting SSID to empty string seems to kill the card in Host AP mode
  921. */
  922. if (local->iw_mode != IW_MODE_MASTER || local->essid[0] != '\0') {
  923. ret = hostap_set_string(dev, HFA384X_RID_CNFOWNSSID,
  924. local->essid);
  925. if (ret) {
  926. printk("%s: AP own SSID setting failed\n", dev->name);
  927. goto fail;
  928. }
  929. }
  930. ret = hostap_set_word(dev, HFA384X_RID_CNFMAXDATALEN,
  931. PRISM2_DATA_MAXLEN);
  932. if (ret) {
  933. printk("%s: MAC data length setting to %d failed\n",
  934. dev->name, PRISM2_DATA_MAXLEN);
  935. goto fail;
  936. }
  937. if (hfa384x_get_rid(dev, HFA384X_RID_CHANNELLIST, &tmp, 2, 1) < 0) {
  938. printk("%s: Channel list read failed\n", dev->name);
  939. ret = -EINVAL;
  940. goto fail;
  941. }
  942. local->channel_mask = __le16_to_cpu(tmp);
  943. if (local->channel < 1 || local->channel > 14 ||
  944. !(local->channel_mask & (1 << (local->channel - 1)))) {
  945. printk(KERN_WARNING "%s: Channel setting out of range "
  946. "(%d)!\n", dev->name, local->channel);
  947. ret = -EBUSY;
  948. goto fail;
  949. }
  950. ret = hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel);
  951. if (ret) {
  952. printk("%s: Channel setting to %d failed\n",
  953. dev->name, local->channel);
  954. goto fail;
  955. }
  956. ret = hostap_set_word(dev, HFA384X_RID_CNFBEACONINT,
  957. local->beacon_int);
  958. if (ret) {
  959. printk("%s: Beacon interval setting to %d failed\n",
  960. dev->name, local->beacon_int);
  961. /* this may fail with Symbol/Lucent firmware */
  962. if (ret == -ETIMEDOUT)
  963. goto fail;
  964. }
  965. ret = hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD,
  966. local->dtim_period);
  967. if (ret) {
  968. printk("%s: DTIM period setting to %d failed\n",
  969. dev->name, local->dtim_period);
  970. /* this may fail with Symbol/Lucent firmware */
  971. if (ret == -ETIMEDOUT)
  972. goto fail;
  973. }
  974. ret = hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
  975. local->is_promisc);
  976. if (ret)
  977. printk(KERN_INFO "%s: Setting promiscuous mode (%d) failed\n",
  978. dev->name, local->is_promisc);
  979. if (!local->fw_ap) {
  980. ret = hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID,
  981. local->essid);
  982. if (ret) {
  983. printk("%s: Desired SSID setting failed\n", dev->name);
  984. goto fail;
  985. }
  986. }
  987. /* Setup TXRateControl, defaults to allow use of 1, 2, 5.5, and
  988. * 11 Mbps in automatic TX rate fallback and 1 and 2 Mbps as basic
  989. * rates */
  990. if (local->tx_rate_control == 0) {
  991. local->tx_rate_control =
  992. HFA384X_RATES_1MBPS |
  993. HFA384X_RATES_2MBPS |
  994. HFA384X_RATES_5MBPS |
  995. HFA384X_RATES_11MBPS;
  996. }
  997. if (local->basic_rates == 0)
  998. local->basic_rates = HFA384X_RATES_1MBPS | HFA384X_RATES_2MBPS;
  999. if (!local->fw_ap) {
  1000. ret = hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
  1001. local->tx_rate_control);
  1002. if (ret) {
  1003. printk("%s: TXRateControl setting to %d failed\n",
  1004. dev->name, local->tx_rate_control);
  1005. goto fail;
  1006. }
  1007. ret = hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
  1008. local->tx_rate_control);
  1009. if (ret) {
  1010. printk("%s: cnfSupportedRates setting to %d failed\n",
  1011. dev->name, local->tx_rate_control);
  1012. }
  1013. ret = hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
  1014. local->basic_rates);
  1015. if (ret) {
  1016. printk("%s: cnfBasicRates setting to %d failed\n",
  1017. dev->name, local->basic_rates);
  1018. }
  1019. ret = hostap_set_word(dev, HFA384X_RID_CREATEIBSS, 1);
  1020. if (ret) {
  1021. printk("%s: Create IBSS setting to 1 failed\n",
  1022. dev->name);
  1023. }
  1024. }
  1025. if (local->name_set)
  1026. (void) hostap_set_string(dev, HFA384X_RID_CNFOWNNAME,
  1027. local->name);
  1028. if (hostap_set_encryption(local)) {
  1029. printk(KERN_INFO "%s: could not configure encryption\n",
  1030. dev->name);
  1031. }
  1032. (void) hostap_set_antsel(local);
  1033. if (hostap_set_roaming(local)) {
  1034. printk(KERN_INFO "%s: could not set host roaming\n",
  1035. dev->name);
  1036. }
  1037. if (local->sta_fw_ver >= PRISM2_FW_VER(1,6,3) &&
  1038. hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY, local->enh_sec))
  1039. printk(KERN_INFO "%s: cnfEnhSecurity setting to 0x%x failed\n",
  1040. dev->name, local->enh_sec);
  1041. /* 32-bit tallies were added in STA f/w 0.8.0, but they were apparently
  1042. * not working correctly (last seven counters report bogus values).
  1043. * This has been fixed in 0.8.2, so enable 32-bit tallies only
  1044. * beginning with that firmware version. Another bug fix for 32-bit
  1045. * tallies in 1.4.0; should 16-bit tallies be used for some other
  1046. * versions, too? */
  1047. if (local->sta_fw_ver >= PRISM2_FW_VER(0,8,2)) {
  1048. if (hostap_set_word(dev, HFA384X_RID_CNFTHIRTY2TALLY, 1)) {
  1049. printk(KERN_INFO "%s: cnfThirty2Tally setting "
  1050. "failed\n", dev->name);
  1051. local->tallies32 = 0;
  1052. } else
  1053. local->tallies32 = 1;
  1054. } else
  1055. local->tallies32 = 0;
  1056. hostap_set_auth_algs(local);
  1057. if (hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
  1058. local->fragm_threshold)) {
  1059. printk(KERN_INFO "%s: setting FragmentationThreshold to %d "
  1060. "failed\n", dev->name, local->fragm_threshold);
  1061. }
  1062. if (hostap_set_word(dev, HFA384X_RID_RTSTHRESHOLD,
  1063. local->rts_threshold)) {
  1064. printk(KERN_INFO "%s: setting RTSThreshold to %d failed\n",
  1065. dev->name, local->rts_threshold);
  1066. }
  1067. if (local->manual_retry_count >= 0 &&
  1068. hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
  1069. local->manual_retry_count)) {
  1070. printk(KERN_INFO "%s: setting cnfAltRetryCount to %d failed\n",
  1071. dev->name, local->manual_retry_count);
  1072. }
  1073. if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1) &&
  1074. hfa384x_get_rid(dev, HFA384X_RID_CNFDBMADJUST, &tmp, 2, 1) == 2) {
  1075. local->rssi_to_dBm = le16_to_cpu(tmp);
  1076. }
  1077. if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->wpa &&
  1078. hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1)) {
  1079. printk(KERN_INFO "%s: setting ssnHandlingMode to 1 failed\n",
  1080. dev->name);
  1081. }
  1082. if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->generic_elem &&
  1083. hfa384x_set_rid(dev, HFA384X_RID_GENERICELEMENT,
  1084. local->generic_elem, local->generic_elem_len)) {
  1085. printk(KERN_INFO "%s: setting genericElement failed\n",
  1086. dev->name);
  1087. }
  1088. fail:
  1089. return ret;
  1090. }
  1091. static int prism2_hw_init(struct net_device *dev, int initial)
  1092. {
  1093. struct hostap_interface *iface;
  1094. local_info_t *local;
  1095. int ret, first = 1;
  1096. unsigned long start, delay;
  1097. PDEBUG(DEBUG_FLOW, "prism2_hw_init()\n");
  1098. iface = netdev_priv(dev);
  1099. local = iface->local;
  1100. clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits);
  1101. init:
  1102. /* initialize HFA 384x */
  1103. ret = hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_INIT, 0);
  1104. if (ret) {
  1105. printk(KERN_INFO "%s: first command failed - assuming card "
  1106. "does not have primary firmware\n", dev_info);
  1107. }
  1108. if (first && (HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
  1109. /* EvStat has Cmd bit set in some cases, so retry once if no
  1110. * wait was needed */
  1111. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  1112. printk(KERN_DEBUG "%s: init command completed too quickly - "
  1113. "retrying\n", dev->name);
  1114. first = 0;
  1115. goto init;
  1116. }
  1117. start = jiffies;
  1118. delay = jiffies + HFA384X_INIT_TIMEOUT;
  1119. while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
  1120. time_before(jiffies, delay))
  1121. yield();
  1122. if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
  1123. printk(KERN_DEBUG "%s: assuming no Primary image in "
  1124. "flash - card initialization not completed\n",
  1125. dev_info);
  1126. local->no_pri = 1;
  1127. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1128. if (local->sram_type == -1)
  1129. local->sram_type = prism2_get_ram_size(local);
  1130. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1131. return 1;
  1132. }
  1133. local->no_pri = 0;
  1134. printk(KERN_DEBUG "prism2_hw_init: initialized in %lu ms\n",
  1135. (jiffies - start) * 1000 / HZ);
  1136. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  1137. return 0;
  1138. }
  1139. static int prism2_hw_init2(struct net_device *dev, int initial)
  1140. {
  1141. struct hostap_interface *iface;
  1142. local_info_t *local;
  1143. int i;
  1144. iface = netdev_priv(dev);
  1145. local = iface->local;
  1146. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1147. kfree(local->pda);
  1148. if (local->no_pri)
  1149. local->pda = NULL;
  1150. else
  1151. local->pda = prism2_read_pda(dev);
  1152. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1153. hfa384x_disable_interrupts(dev);
  1154. #ifndef final_version
  1155. HFA384X_OUTW(HFA384X_MAGIC, HFA384X_SWSUPPORT0_OFF);
  1156. if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
  1157. printk("SWSUPPORT0 write/read failed: %04X != %04X\n",
  1158. HFA384X_INW(HFA384X_SWSUPPORT0_OFF), HFA384X_MAGIC);
  1159. goto failed;
  1160. }
  1161. #endif
  1162. if (initial || local->pri_only) {
  1163. hfa384x_events_only_cmd(dev);
  1164. /* get card version information */
  1165. if (prism2_get_version_info(dev, HFA384X_RID_NICID, "NIC") ||
  1166. prism2_get_version_info(dev, HFA384X_RID_PRIID, "PRI")) {
  1167. hfa384x_disable_interrupts(dev);
  1168. goto failed;
  1169. }
  1170. if (prism2_get_version_info(dev, HFA384X_RID_STAID, "STA")) {
  1171. printk(KERN_DEBUG "%s: Failed to read STA f/w version "
  1172. "- only Primary f/w present\n", dev->name);
  1173. local->pri_only = 1;
  1174. return 0;
  1175. }
  1176. local->pri_only = 0;
  1177. hfa384x_disable_interrupts(dev);
  1178. }
  1179. /* FIX: could convert allocate_fid to use sleeping CmdCompl wait and
  1180. * enable interrupts before this. This would also require some sort of
  1181. * sleeping AllocEv waiting */
  1182. /* allocate TX FIDs */
  1183. local->txfid_len = PRISM2_TXFID_LEN;
  1184. for (i = 0; i < PRISM2_TXFID_COUNT; i++) {
  1185. local->txfid[i] = hfa384x_allocate_fid(dev, local->txfid_len);
  1186. if (local->txfid[i] == 0xffff && local->txfid_len > 1600) {
  1187. local->txfid[i] = hfa384x_allocate_fid(dev, 1600);
  1188. if (local->txfid[i] != 0xffff) {
  1189. printk(KERN_DEBUG "%s: Using shorter TX FID "
  1190. "(1600 bytes)\n", dev->name);
  1191. local->txfid_len = 1600;
  1192. }
  1193. }
  1194. if (local->txfid[i] == 0xffff)
  1195. goto failed;
  1196. local->intransmitfid[i] = PRISM2_TXFID_EMPTY;
  1197. }
  1198. hfa384x_events_only_cmd(dev);
  1199. if (initial) {
  1200. struct list_head *ptr;
  1201. prism2_check_sta_fw_version(local);
  1202. if (hfa384x_get_rid(dev, HFA384X_RID_CNFOWNMACADDR,
  1203. &dev->dev_addr, 6, 1) < 0) {
  1204. printk("%s: could not get own MAC address\n",
  1205. dev->name);
  1206. }
  1207. list_for_each(ptr, &local->hostap_interfaces) {
  1208. iface = list_entry(ptr, struct hostap_interface, list);
  1209. memcpy(iface->dev->dev_addr, dev->dev_addr, ETH_ALEN);
  1210. }
  1211. } else if (local->fw_ap)
  1212. prism2_check_sta_fw_version(local);
  1213. prism2_setup_rids(dev);
  1214. /* MAC is now configured, but port 0 is not yet enabled */
  1215. return 0;
  1216. failed:
  1217. if (!local->no_pri)
  1218. printk(KERN_WARNING "%s: Initialization failed\n", dev_info);
  1219. return 1;
  1220. }
  1221. static int prism2_hw_enable(struct net_device *dev, int initial)
  1222. {
  1223. struct hostap_interface *iface;
  1224. local_info_t *local;
  1225. int was_resetting;
  1226. iface = netdev_priv(dev);
  1227. local = iface->local;
  1228. was_resetting = local->hw_resetting;
  1229. if (hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL, NULL)) {
  1230. printk("%s: MAC port 0 enabling failed\n", dev->name);
  1231. return 1;
  1232. }
  1233. local->hw_ready = 1;
  1234. local->hw_reset_tries = 0;
  1235. local->hw_resetting = 0;
  1236. hfa384x_enable_interrupts(dev);
  1237. /* at least D-Link DWL-650 seems to require additional port reset
  1238. * before it starts acting as an AP, so reset port automatically
  1239. * here just in case */
  1240. if (initial && prism2_reset_port(dev)) {
  1241. printk("%s: MAC port 0 reseting failed\n", dev->name);
  1242. return 1;
  1243. }
  1244. if (was_resetting && netif_queue_stopped(dev)) {
  1245. /* If hw_reset() was called during pending transmit, netif
  1246. * queue was stopped. Wake it up now since the wlan card has
  1247. * been resetted. */
  1248. netif_wake_queue(dev);
  1249. }
  1250. return 0;
  1251. }
  1252. static int prism2_hw_config(struct net_device *dev, int initial)
  1253. {
  1254. struct hostap_interface *iface;
  1255. local_info_t *local;
  1256. iface = netdev_priv(dev);
  1257. local = iface->local;
  1258. if (local->hw_downloading)
  1259. return 1;
  1260. if (prism2_hw_init(dev, initial)) {
  1261. return local->no_pri ? 0 : 1;
  1262. }
  1263. if (prism2_hw_init2(dev, initial))
  1264. return 1;
  1265. /* Enable firmware if secondary image is loaded and at least one of the
  1266. * netdevices is up. */
  1267. if (!local->pri_only &&
  1268. (initial == 0 || (initial == 2 && local->num_dev_open > 0))) {
  1269. if (!local->dev_enabled)
  1270. prism2_callback(local, PRISM2_CALLBACK_ENABLE);
  1271. local->dev_enabled = 1;
  1272. return prism2_hw_enable(dev, initial);
  1273. }
  1274. return 0;
  1275. }
  1276. static void prism2_hw_shutdown(struct net_device *dev, int no_disable)
  1277. {
  1278. struct hostap_interface *iface;
  1279. local_info_t *local;
  1280. iface = netdev_priv(dev);
  1281. local = iface->local;
  1282. /* Allow only command completion events during disable */
  1283. hfa384x_events_only_cmd(dev);
  1284. local->hw_ready = 0;
  1285. if (local->dev_enabled)
  1286. prism2_callback(local, PRISM2_CALLBACK_DISABLE);
  1287. local->dev_enabled = 0;
  1288. if (local->func->card_present && !local->func->card_present(local)) {
  1289. printk(KERN_DEBUG "%s: card already removed or not configured "
  1290. "during shutdown\n", dev->name);
  1291. return;
  1292. }
  1293. if ((no_disable & HOSTAP_HW_NO_DISABLE) == 0 &&
  1294. hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL, NULL))
  1295. printk(KERN_WARNING "%s: Shutdown failed\n", dev_info);
  1296. hfa384x_disable_interrupts(dev);
  1297. if (no_disable & HOSTAP_HW_ENABLE_CMDCOMPL)
  1298. hfa384x_events_only_cmd(dev);
  1299. else
  1300. prism2_clear_cmd_queue(local);
  1301. }
  1302. static void prism2_hw_reset(struct net_device *dev)
  1303. {
  1304. struct hostap_interface *iface;
  1305. local_info_t *local;
  1306. #if 0
  1307. static long last_reset = 0;
  1308. /* do not reset card more than once per second to avoid ending up in a
  1309. * busy loop reseting the card */
  1310. if (time_before_eq(jiffies, last_reset + HZ))
  1311. return;
  1312. last_reset = jiffies;
  1313. #endif
  1314. iface = netdev_priv(dev);
  1315. local = iface->local;
  1316. if (in_interrupt()) {
  1317. printk(KERN_DEBUG "%s: driver bug - prism2_hw_reset() called "
  1318. "in interrupt context\n", dev->name);
  1319. return;
  1320. }
  1321. if (local->hw_downloading)
  1322. return;
  1323. if (local->hw_resetting) {
  1324. printk(KERN_WARNING "%s: %s: already resetting card - "
  1325. "ignoring reset request\n", dev_info, dev->name);
  1326. return;
  1327. }
  1328. local->hw_reset_tries++;
  1329. if (local->hw_reset_tries > 10) {
  1330. printk(KERN_WARNING "%s: too many reset tries, skipping\n",
  1331. dev->name);
  1332. return;
  1333. }
  1334. printk(KERN_WARNING "%s: %s: resetting card\n", dev_info, dev->name);
  1335. hfa384x_disable_interrupts(dev);
  1336. local->hw_resetting = 1;
  1337. if (local->func->cor_sreset) {
  1338. /* Host system seems to hang in some cases with high traffic
  1339. * load or shared interrupts during COR sreset. Disable shared
  1340. * interrupts during reset to avoid these crashes. COS sreset
  1341. * takes quite a long time, so it is unfortunate that this
  1342. * seems to be needed. Anyway, I do not know of any better way
  1343. * of avoiding the crash. */
  1344. disable_irq(dev->irq);
  1345. local->func->cor_sreset(local);
  1346. enable_irq(dev->irq);
  1347. }
  1348. prism2_hw_shutdown(dev, 1);
  1349. prism2_hw_config(dev, 0);
  1350. local->hw_resetting = 0;
  1351. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1352. if (local->dl_pri) {
  1353. printk(KERN_DEBUG "%s: persistent download of primary "
  1354. "firmware\n", dev->name);
  1355. if (prism2_download_genesis(local, local->dl_pri) < 0)
  1356. printk(KERN_WARNING "%s: download (PRI) failed\n",
  1357. dev->name);
  1358. }
  1359. if (local->dl_sec) {
  1360. printk(KERN_DEBUG "%s: persistent download of secondary "
  1361. "firmware\n", dev->name);
  1362. if (prism2_download_volatile(local, local->dl_sec) < 0)
  1363. printk(KERN_WARNING "%s: download (SEC) failed\n",
  1364. dev->name);
  1365. }
  1366. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1367. /* TODO: restore beacon TIM bits for STAs that have buffered frames */
  1368. }
  1369. static void prism2_schedule_reset(local_info_t *local)
  1370. {
  1371. schedule_work(&local->reset_queue);
  1372. }
  1373. /* Called only as scheduled task after noticing card timeout in interrupt
  1374. * context */
  1375. static void handle_reset_queue(void *data)
  1376. {
  1377. local_info_t *local = (local_info_t *) data;
  1378. printk(KERN_DEBUG "%s: scheduled card reset\n", local->dev->name);
  1379. prism2_hw_reset(local->dev);
  1380. if (netif_queue_stopped(local->dev)) {
  1381. int i;
  1382. for (i = 0; i < PRISM2_TXFID_COUNT; i++)
  1383. if (local->intransmitfid[i] == PRISM2_TXFID_EMPTY) {
  1384. PDEBUG(DEBUG_EXTRA, "prism2_tx_timeout: "
  1385. "wake up queue\n");
  1386. netif_wake_queue(local->dev);
  1387. break;
  1388. }
  1389. }
  1390. }
  1391. static int prism2_get_txfid_idx(local_info_t *local)
  1392. {
  1393. int idx, end;
  1394. unsigned long flags;
  1395. spin_lock_irqsave(&local->txfidlock, flags);
  1396. end = idx = local->next_txfid;
  1397. do {
  1398. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
  1399. local->intransmitfid[idx] = PRISM2_TXFID_RESERVED;
  1400. spin_unlock_irqrestore(&local->txfidlock, flags);
  1401. return idx;
  1402. }
  1403. idx++;
  1404. if (idx >= PRISM2_TXFID_COUNT)
  1405. idx = 0;
  1406. } while (idx != end);
  1407. spin_unlock_irqrestore(&local->txfidlock, flags);
  1408. PDEBUG(DEBUG_EXTRA2, "prism2_get_txfid_idx: no room in txfid buf: "
  1409. "packet dropped\n");
  1410. local->stats.tx_dropped++;
  1411. return -1;
  1412. }
  1413. /* Called only from hardware IRQ */
  1414. static void prism2_transmit_cb(struct net_device *dev, long context,
  1415. u16 resp0, u16 res)
  1416. {
  1417. struct hostap_interface *iface;
  1418. local_info_t *local;
  1419. int idx = (int) context;
  1420. iface = netdev_priv(dev);
  1421. local = iface->local;
  1422. if (res) {
  1423. printk(KERN_DEBUG "%s: prism2_transmit_cb - res=0x%02x\n",
  1424. dev->name, res);
  1425. return;
  1426. }
  1427. if (idx < 0 || idx >= PRISM2_TXFID_COUNT) {
  1428. printk(KERN_DEBUG "%s: prism2_transmit_cb called with invalid "
  1429. "idx=%d\n", dev->name, idx);
  1430. return;
  1431. }
  1432. if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  1433. printk(KERN_DEBUG "%s: driver bug: prism2_transmit_cb called "
  1434. "with no pending transmit\n", dev->name);
  1435. }
  1436. if (netif_queue_stopped(dev)) {
  1437. /* ready for next TX, so wake up queue that was stopped in
  1438. * prism2_transmit() */
  1439. netif_wake_queue(dev);
  1440. }
  1441. spin_lock(&local->txfidlock);
  1442. /* With reclaim, Resp0 contains new txfid for transmit; the old txfid
  1443. * will be automatically allocated for the next TX frame */
  1444. local->intransmitfid[idx] = resp0;
  1445. PDEBUG(DEBUG_FID, "%s: prism2_transmit_cb: txfid[%d]=0x%04x, "
  1446. "resp0=0x%04x, transmit_txfid=0x%04x\n",
  1447. dev->name, idx, local->txfid[idx],
  1448. resp0, local->intransmitfid[local->next_txfid]);
  1449. idx++;
  1450. if (idx >= PRISM2_TXFID_COUNT)
  1451. idx = 0;
  1452. local->next_txfid = idx;
  1453. /* check if all TX buffers are occupied */
  1454. do {
  1455. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
  1456. spin_unlock(&local->txfidlock);
  1457. return;
  1458. }
  1459. idx++;
  1460. if (idx >= PRISM2_TXFID_COUNT)
  1461. idx = 0;
  1462. } while (idx != local->next_txfid);
  1463. spin_unlock(&local->txfidlock);
  1464. /* no empty TX buffers, stop queue */
  1465. netif_stop_queue(dev);
  1466. }
  1467. /* Called only from software IRQ if PCI bus master is not used (with bus master
  1468. * this can be called both from software and hardware IRQ) */
  1469. static int prism2_transmit(struct net_device *dev, int idx)
  1470. {
  1471. struct hostap_interface *iface;
  1472. local_info_t *local;
  1473. int res;
  1474. iface = netdev_priv(dev);
  1475. local = iface->local;
  1476. /* The driver tries to stop netif queue so that there would not be
  1477. * more than one attempt to transmit frames going on; check that this
  1478. * is really the case */
  1479. if (test_and_set_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  1480. printk(KERN_DEBUG "%s: driver bug - prism2_transmit() called "
  1481. "when previous TX was pending\n", dev->name);
  1482. return -1;
  1483. }
  1484. /* stop the queue for the time that transmit is pending */
  1485. netif_stop_queue(dev);
  1486. /* transmit packet */
  1487. res = hfa384x_cmd_callback(
  1488. dev,
  1489. HFA384X_CMDCODE_TRANSMIT | HFA384X_CMD_TX_RECLAIM,
  1490. local->txfid[idx],
  1491. prism2_transmit_cb, (long) idx);
  1492. if (res) {
  1493. struct net_device_stats *stats;
  1494. printk(KERN_DEBUG "%s: prism2_transmit: CMDCODE_TRANSMIT "
  1495. "failed (res=%d)\n", dev->name, res);
  1496. stats = hostap_get_stats(dev);
  1497. stats->tx_dropped++;
  1498. netif_wake_queue(dev);
  1499. return -1;
  1500. }
  1501. dev->trans_start = jiffies;
  1502. /* Since we did not wait for command completion, the card continues
  1503. * to process on the background and we will finish handling when
  1504. * command completion event is handled (prism2_cmd_ev() function) */
  1505. return 0;
  1506. }
  1507. /* Send IEEE 802.11 frame (convert the header into Prism2 TX descriptor and
  1508. * send the payload with this descriptor) */
  1509. /* Called only from software IRQ */
  1510. static int prism2_tx_80211(struct sk_buff *skb, struct net_device *dev)
  1511. {
  1512. struct hostap_interface *iface;
  1513. local_info_t *local;
  1514. struct hfa384x_tx_frame txdesc;
  1515. struct hostap_skb_tx_data *meta;
  1516. int hdr_len, data_len, idx, res, ret = -1;
  1517. u16 tx_control, fc;
  1518. iface = netdev_priv(dev);
  1519. local = iface->local;
  1520. meta = (struct hostap_skb_tx_data *) skb->cb;
  1521. prism2_callback(local, PRISM2_CALLBACK_TX_START);
  1522. if ((local->func->card_present && !local->func->card_present(local)) ||
  1523. !local->hw_ready || local->hw_downloading || local->pri_only) {
  1524. if (net_ratelimit()) {
  1525. printk(KERN_DEBUG "%s: prism2_tx_80211: hw not ready -"
  1526. " skipping\n", dev->name);
  1527. }
  1528. goto fail;
  1529. }
  1530. memset(&txdesc, 0, sizeof(txdesc));
  1531. /* skb->data starts with txdesc->frame_control */
  1532. hdr_len = 24;
  1533. memcpy(&txdesc.frame_control, skb->data, hdr_len);
  1534. fc = le16_to_cpu(txdesc.frame_control);
  1535. if (HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
  1536. (fc & WLAN_FC_FROMDS) && (fc & WLAN_FC_TODS) && 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 inline 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. HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT ? "Mgmt" : "",
  1991. HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_CTRL ? "Ctrl" : "",
  1992. HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA ? "Data" : "",
  1993. HOSTAP_FC_GET_STYPE(fc),
  1994. fc & WLAN_FC_TODS ? " ToDS" : "",
  1995. fc & WLAN_FC_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 inline 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, struct pt_regs *regs)
  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. static struct net_device *
  2583. prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx,
  2584. struct device *sdev)
  2585. {
  2586. struct net_device *dev;
  2587. struct hostap_interface *iface;
  2588. struct local_info *local;
  2589. int len, i, ret;
  2590. if (funcs == NULL)
  2591. return NULL;
  2592. len = strlen(dev_template);
  2593. if (len >= IFNAMSIZ || strstr(dev_template, "%d") == NULL) {
  2594. printk(KERN_WARNING "hostap: Invalid dev_template='%s'\n",
  2595. dev_template);
  2596. return NULL;
  2597. }
  2598. len = sizeof(struct hostap_interface) +
  2599. 3 + sizeof(struct local_info) +
  2600. 3 + sizeof(struct ap_data);
  2601. dev = alloc_etherdev(len);
  2602. if (dev == NULL)
  2603. return NULL;
  2604. iface = netdev_priv(dev);
  2605. local = (struct local_info *) ((((long) (iface + 1)) + 3) & ~3);
  2606. local->ap = (struct ap_data *) ((((long) (local + 1)) + 3) & ~3);
  2607. local->dev = iface->dev = dev;
  2608. iface->local = local;
  2609. iface->type = HOSTAP_INTERFACE_MASTER;
  2610. INIT_LIST_HEAD(&local->hostap_interfaces);
  2611. local->hw_module = THIS_MODULE;
  2612. #ifdef PRISM2_IO_DEBUG
  2613. local->io_debug_enabled = 1;
  2614. #endif /* PRISM2_IO_DEBUG */
  2615. local->func = funcs;
  2616. local->func->cmd = hfa384x_cmd;
  2617. local->func->read_regs = hfa384x_read_regs;
  2618. local->func->get_rid = hfa384x_get_rid;
  2619. local->func->set_rid = hfa384x_set_rid;
  2620. local->func->hw_enable = prism2_hw_enable;
  2621. local->func->hw_config = prism2_hw_config;
  2622. local->func->hw_reset = prism2_hw_reset;
  2623. local->func->hw_shutdown = prism2_hw_shutdown;
  2624. local->func->reset_port = prism2_reset_port;
  2625. local->func->schedule_reset = prism2_schedule_reset;
  2626. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2627. local->func->read_aux = prism2_download_aux_dump;
  2628. local->func->download = prism2_download;
  2629. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2630. local->func->tx = prism2_tx_80211;
  2631. local->func->set_tim = prism2_set_tim;
  2632. local->func->need_tx_headroom = 0; /* no need to add txdesc in
  2633. * skb->data (FIX: maybe for DMA bus
  2634. * mastering? */
  2635. local->mtu = mtu;
  2636. rwlock_init(&local->iface_lock);
  2637. spin_lock_init(&local->txfidlock);
  2638. spin_lock_init(&local->cmdlock);
  2639. spin_lock_init(&local->baplock);
  2640. spin_lock_init(&local->lock);
  2641. init_MUTEX(&local->rid_bap_sem);
  2642. if (card_idx < 0 || card_idx >= MAX_PARM_DEVICES)
  2643. card_idx = 0;
  2644. local->card_idx = card_idx;
  2645. len = strlen(essid);
  2646. memcpy(local->essid, essid,
  2647. len > MAX_SSID_LEN ? MAX_SSID_LEN : len);
  2648. local->essid[MAX_SSID_LEN] = '\0';
  2649. i = GET_INT_PARM(iw_mode, card_idx);
  2650. if ((i >= IW_MODE_ADHOC && i <= IW_MODE_REPEAT) ||
  2651. i == IW_MODE_MONITOR) {
  2652. local->iw_mode = i;
  2653. } else {
  2654. printk(KERN_WARNING "prism2: Unknown iw_mode %d; using "
  2655. "IW_MODE_MASTER\n", i);
  2656. local->iw_mode = IW_MODE_MASTER;
  2657. }
  2658. local->channel = GET_INT_PARM(channel, card_idx);
  2659. local->beacon_int = GET_INT_PARM(beacon_int, card_idx);
  2660. local->dtim_period = GET_INT_PARM(dtim_period, card_idx);
  2661. local->wds_max_connections = 16;
  2662. local->tx_control = HFA384X_TX_CTRL_FLAGS;
  2663. local->manual_retry_count = -1;
  2664. local->rts_threshold = 2347;
  2665. local->fragm_threshold = 2346;
  2666. local->rssi_to_dBm = 100; /* default; to be overriden by
  2667. * cnfDbmAdjust, if available */
  2668. local->auth_algs = PRISM2_AUTH_OPEN | PRISM2_AUTH_SHARED_KEY;
  2669. local->sram_type = -1;
  2670. local->scan_channel_mask = 0xffff;
  2671. /* Initialize task queue structures */
  2672. INIT_WORK(&local->reset_queue, handle_reset_queue, local);
  2673. INIT_WORK(&local->set_multicast_list_queue,
  2674. hostap_set_multicast_list_queue, local->dev);
  2675. INIT_WORK(&local->set_tim_queue, handle_set_tim_queue, local);
  2676. INIT_LIST_HEAD(&local->set_tim_list);
  2677. spin_lock_init(&local->set_tim_lock);
  2678. INIT_WORK(&local->comms_qual_update, handle_comms_qual_update, local);
  2679. /* Initialize tasklets for handling hardware IRQ related operations
  2680. * outside hw IRQ handler */
  2681. #define HOSTAP_TASKLET_INIT(q, f, d) \
  2682. do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \
  2683. while (0)
  2684. HOSTAP_TASKLET_INIT(&local->bap_tasklet, hostap_bap_tasklet,
  2685. (unsigned long) local);
  2686. HOSTAP_TASKLET_INIT(&local->info_tasklet, hostap_info_tasklet,
  2687. (unsigned long) local);
  2688. hostap_info_init(local);
  2689. HOSTAP_TASKLET_INIT(&local->rx_tasklet,
  2690. hostap_rx_tasklet, (unsigned long) local);
  2691. skb_queue_head_init(&local->rx_list);
  2692. HOSTAP_TASKLET_INIT(&local->sta_tx_exc_tasklet,
  2693. hostap_sta_tx_exc_tasklet, (unsigned long) local);
  2694. skb_queue_head_init(&local->sta_tx_exc_list);
  2695. INIT_LIST_HEAD(&local->cmd_queue);
  2696. init_waitqueue_head(&local->hostscan_wq);
  2697. INIT_LIST_HEAD(&local->crypt_deinit_list);
  2698. init_timer(&local->crypt_deinit_timer);
  2699. local->crypt_deinit_timer.data = (unsigned long) local;
  2700. local->crypt_deinit_timer.function = prism2_crypt_deinit_handler;
  2701. init_timer(&local->passive_scan_timer);
  2702. local->passive_scan_timer.data = (unsigned long) local;
  2703. local->passive_scan_timer.function = hostap_passive_scan;
  2704. init_timer(&local->tick_timer);
  2705. local->tick_timer.data = (unsigned long) local;
  2706. local->tick_timer.function = hostap_tick_timer;
  2707. local->tick_timer.expires = jiffies + 2 * HZ;
  2708. add_timer(&local->tick_timer);
  2709. INIT_LIST_HEAD(&local->bss_list);
  2710. hostap_setup_dev(dev, local, 1);
  2711. local->saved_eth_header_parse = dev->hard_header_parse;
  2712. dev->hard_start_xmit = hostap_master_start_xmit;
  2713. dev->type = ARPHRD_IEEE80211;
  2714. dev->hard_header_parse = hostap_80211_header_parse;
  2715. rtnl_lock();
  2716. ret = dev_alloc_name(dev, "wifi%d");
  2717. SET_NETDEV_DEV(dev, sdev);
  2718. if (ret >= 0)
  2719. ret = register_netdevice(dev);
  2720. rtnl_unlock();
  2721. if (ret < 0) {
  2722. printk(KERN_WARNING "%s: register netdevice failed!\n",
  2723. dev_info);
  2724. goto fail;
  2725. }
  2726. printk(KERN_INFO "%s: Registered netdevice %s\n", dev_info, dev->name);
  2727. #ifndef PRISM2_NO_PROCFS_DEBUG
  2728. create_proc_read_entry("registers", 0, local->proc,
  2729. prism2_registers_proc_read, local);
  2730. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2731. hostap_init_data(local);
  2732. return dev;
  2733. fail:
  2734. free_netdev(dev);
  2735. return NULL;
  2736. }
  2737. static int hostap_hw_ready(struct net_device *dev)
  2738. {
  2739. struct hostap_interface *iface;
  2740. struct local_info *local;
  2741. iface = netdev_priv(dev);
  2742. local = iface->local;
  2743. local->ddev = hostap_add_interface(local, HOSTAP_INTERFACE_MAIN, 0,
  2744. "", dev_template);
  2745. if (local->ddev) {
  2746. if (local->iw_mode == IW_MODE_INFRA ||
  2747. local->iw_mode == IW_MODE_ADHOC) {
  2748. netif_carrier_off(local->dev);
  2749. netif_carrier_off(local->ddev);
  2750. }
  2751. hostap_init_proc(local);
  2752. hostap_init_ap_proc(local);
  2753. return 0;
  2754. }
  2755. return -1;
  2756. }
  2757. static void prism2_free_local_data(struct net_device *dev)
  2758. {
  2759. struct hostap_tx_callback_info *tx_cb, *tx_cb_prev;
  2760. int i;
  2761. struct hostap_interface *iface;
  2762. struct local_info *local;
  2763. struct list_head *ptr, *n;
  2764. if (dev == NULL)
  2765. return;
  2766. iface = netdev_priv(dev);
  2767. local = iface->local;
  2768. flush_scheduled_work();
  2769. if (timer_pending(&local->crypt_deinit_timer))
  2770. del_timer(&local->crypt_deinit_timer);
  2771. prism2_crypt_deinit_entries(local, 1);
  2772. if (timer_pending(&local->passive_scan_timer))
  2773. del_timer(&local->passive_scan_timer);
  2774. if (timer_pending(&local->tick_timer))
  2775. del_timer(&local->tick_timer);
  2776. prism2_clear_cmd_queue(local);
  2777. skb_queue_purge(&local->info_list);
  2778. skb_queue_purge(&local->rx_list);
  2779. skb_queue_purge(&local->sta_tx_exc_list);
  2780. if (local->dev_enabled)
  2781. prism2_callback(local, PRISM2_CALLBACK_DISABLE);
  2782. for (i = 0; i < WEP_KEYS; i++) {
  2783. struct ieee80211_crypt_data *crypt = local->crypt[i];
  2784. if (crypt) {
  2785. if (crypt->ops)
  2786. crypt->ops->deinit(crypt->priv);
  2787. kfree(crypt);
  2788. local->crypt[i] = NULL;
  2789. }
  2790. }
  2791. if (local->ap != NULL)
  2792. hostap_free_data(local->ap);
  2793. #ifndef PRISM2_NO_PROCFS_DEBUG
  2794. if (local->proc != NULL)
  2795. remove_proc_entry("registers", local->proc);
  2796. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2797. hostap_remove_proc(local);
  2798. tx_cb = local->tx_callback;
  2799. while (tx_cb != NULL) {
  2800. tx_cb_prev = tx_cb;
  2801. tx_cb = tx_cb->next;
  2802. kfree(tx_cb_prev);
  2803. }
  2804. hostap_set_hostapd(local, 0, 0);
  2805. hostap_set_hostapd_sta(local, 0, 0);
  2806. for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
  2807. if (local->frag_cache[i].skb != NULL)
  2808. dev_kfree_skb(local->frag_cache[i].skb);
  2809. }
  2810. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2811. prism2_download_free_data(local->dl_pri);
  2812. prism2_download_free_data(local->dl_sec);
  2813. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2814. list_for_each_safe(ptr, n, &local->hostap_interfaces) {
  2815. iface = list_entry(ptr, struct hostap_interface, list);
  2816. if (iface->type == HOSTAP_INTERFACE_MASTER) {
  2817. /* special handling for this interface below */
  2818. continue;
  2819. }
  2820. hostap_remove_interface(iface->dev, 0, 1);
  2821. }
  2822. prism2_clear_set_tim_queue(local);
  2823. list_for_each_safe(ptr, n, &local->bss_list) {
  2824. struct hostap_bss_info *bss =
  2825. list_entry(ptr, struct hostap_bss_info, list);
  2826. kfree(bss);
  2827. }
  2828. kfree(local->pda);
  2829. kfree(local->last_scan_results);
  2830. kfree(local->generic_elem);
  2831. unregister_netdev(local->dev);
  2832. free_netdev(local->dev);
  2833. }
  2834. #ifndef PRISM2_PLX
  2835. static void prism2_suspend(struct net_device *dev)
  2836. {
  2837. struct hostap_interface *iface;
  2838. struct local_info *local;
  2839. union iwreq_data wrqu;
  2840. iface = dev->priv;
  2841. local = iface->local;
  2842. /* Send disconnect event, e.g., to trigger reassociation after resume
  2843. * if wpa_supplicant is used. */
  2844. memset(&wrqu, 0, sizeof(wrqu));
  2845. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  2846. wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
  2847. /* Disable hardware and firmware */
  2848. prism2_hw_shutdown(dev, 0);
  2849. }
  2850. #endif /* PRISM2_PLX */
  2851. /* These might at some point be compiled separately and used as separate
  2852. * kernel modules or linked into one */
  2853. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2854. #include "hostap_download.c"
  2855. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2856. #ifdef PRISM2_CALLBACK
  2857. /* External hostap_callback.c file can be used to, e.g., blink activity led.
  2858. * This can use platform specific code and must define prism2_callback()
  2859. * function (if PRISM2_CALLBACK is not defined, these function calls are not
  2860. * used. */
  2861. #include "hostap_callback.c"
  2862. #endif /* PRISM2_CALLBACK */