hostap_hw.c 100 KB

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