hostap_hw.c 94 KB

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