iwl3945-base.c 123 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/pci-aspm.h>
  35. #include <linux/slab.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/delay.h>
  38. #include <linux/sched.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/wireless.h>
  42. #include <linux/firmware.h>
  43. #include <linux/etherdevice.h>
  44. #include <linux/if_arp.h>
  45. #include <net/ieee80211_radiotap.h>
  46. #include <net/mac80211.h>
  47. #include <asm/div64.h>
  48. #define DRV_NAME "iwl3945"
  49. #include "iwl-fh.h"
  50. #include "iwl-3945-fh.h"
  51. #include "iwl-commands.h"
  52. #include "iwl-sta.h"
  53. #include "iwl-3945.h"
  54. #include "iwl-core.h"
  55. #include "iwl-helpers.h"
  56. #include "iwl-dev.h"
  57. #include "iwl-spectrum.h"
  58. /*
  59. * module name, copyright, version, etc.
  60. */
  61. #define DRV_DESCRIPTION \
  62. "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
  63. #ifdef CONFIG_IWLWIFI_DEBUG
  64. #define VD "d"
  65. #else
  66. #define VD
  67. #endif
  68. /*
  69. * add "s" to indicate spectrum measurement included.
  70. * we add it here to be consistent with previous releases in which
  71. * this was configurable.
  72. */
  73. #define DRV_VERSION IWLWIFI_VERSION VD "s"
  74. #define DRV_COPYRIGHT "Copyright(c) 2003-2010 Intel Corporation"
  75. #define DRV_AUTHOR "<ilw@linux.intel.com>"
  76. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  77. MODULE_VERSION(DRV_VERSION);
  78. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  79. MODULE_LICENSE("GPL");
  80. /* module parameters */
  81. struct iwl_mod_params iwl3945_mod_params = {
  82. .sw_crypto = 1,
  83. .restart_fw = 1,
  84. /* the rest are 0 by default */
  85. };
  86. /**
  87. * iwl3945_get_antenna_flags - Get antenna flags for RXON command
  88. * @priv: eeprom and antenna fields are used to determine antenna flags
  89. *
  90. * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
  91. * iwl3945_mod_params.antenna specifies the antenna diversity mode:
  92. *
  93. * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
  94. * IWL_ANTENNA_MAIN - Force MAIN antenna
  95. * IWL_ANTENNA_AUX - Force AUX antenna
  96. */
  97. __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
  98. {
  99. struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  100. switch (iwl3945_mod_params.antenna) {
  101. case IWL_ANTENNA_DIVERSITY:
  102. return 0;
  103. case IWL_ANTENNA_MAIN:
  104. if (eeprom->antenna_switch_type)
  105. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
  106. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
  107. case IWL_ANTENNA_AUX:
  108. if (eeprom->antenna_switch_type)
  109. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
  110. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
  111. }
  112. /* bad antenna selector value */
  113. IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
  114. iwl3945_mod_params.antenna);
  115. return 0; /* "diversity" is default if error */
  116. }
  117. static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
  118. struct ieee80211_key_conf *keyconf,
  119. u8 sta_id)
  120. {
  121. unsigned long flags;
  122. __le16 key_flags = 0;
  123. int ret;
  124. key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
  125. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  126. if (sta_id == priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id)
  127. key_flags |= STA_KEY_MULTICAST_MSK;
  128. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  129. keyconf->hw_key_idx = keyconf->keyidx;
  130. key_flags &= ~STA_KEY_FLG_INVALID;
  131. spin_lock_irqsave(&priv->sta_lock, flags);
  132. priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  133. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  134. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
  135. keyconf->keylen);
  136. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
  137. keyconf->keylen);
  138. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  139. == STA_KEY_FLG_NO_ENC)
  140. priv->stations[sta_id].sta.key.key_offset =
  141. iwl_get_free_ucode_key_index(priv);
  142. /* else, we are overriding an existing key => no need to allocated room
  143. * in uCode. */
  144. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  145. "no space for a new key");
  146. priv->stations[sta_id].sta.key.key_flags = key_flags;
  147. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  148. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  149. IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
  150. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  151. spin_unlock_irqrestore(&priv->sta_lock, flags);
  152. return ret;
  153. }
  154. static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv,
  155. struct ieee80211_key_conf *keyconf,
  156. u8 sta_id)
  157. {
  158. return -EOPNOTSUPP;
  159. }
  160. static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv,
  161. struct ieee80211_key_conf *keyconf,
  162. u8 sta_id)
  163. {
  164. return -EOPNOTSUPP;
  165. }
  166. static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
  167. {
  168. unsigned long flags;
  169. struct iwl_addsta_cmd sta_cmd;
  170. spin_lock_irqsave(&priv->sta_lock, flags);
  171. memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key));
  172. memset(&priv->stations[sta_id].sta.key, 0,
  173. sizeof(struct iwl4965_keyinfo));
  174. priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
  175. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  176. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  177. memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
  178. spin_unlock_irqrestore(&priv->sta_lock, flags);
  179. IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
  180. return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  181. }
  182. static int iwl3945_set_dynamic_key(struct iwl_priv *priv,
  183. struct ieee80211_key_conf *keyconf, u8 sta_id)
  184. {
  185. int ret = 0;
  186. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  187. switch (keyconf->cipher) {
  188. case WLAN_CIPHER_SUITE_CCMP:
  189. ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
  190. break;
  191. case WLAN_CIPHER_SUITE_TKIP:
  192. ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
  193. break;
  194. case WLAN_CIPHER_SUITE_WEP40:
  195. case WLAN_CIPHER_SUITE_WEP104:
  196. ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
  197. break;
  198. default:
  199. IWL_ERR(priv, "Unknown alg: %s alg=%x\n", __func__,
  200. keyconf->cipher);
  201. ret = -EINVAL;
  202. }
  203. IWL_DEBUG_WEP(priv, "Set dynamic key: alg=%x len=%d idx=%d sta=%d ret=%d\n",
  204. keyconf->cipher, keyconf->keylen, keyconf->keyidx,
  205. sta_id, ret);
  206. return ret;
  207. }
  208. static int iwl3945_remove_static_key(struct iwl_priv *priv)
  209. {
  210. int ret = -EOPNOTSUPP;
  211. return ret;
  212. }
  213. static int iwl3945_set_static_key(struct iwl_priv *priv,
  214. struct ieee80211_key_conf *key)
  215. {
  216. if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  217. key->cipher == WLAN_CIPHER_SUITE_WEP104)
  218. return -EOPNOTSUPP;
  219. IWL_ERR(priv, "Static key invalid: cipher %x\n", key->cipher);
  220. return -EINVAL;
  221. }
  222. static void iwl3945_clear_free_frames(struct iwl_priv *priv)
  223. {
  224. struct list_head *element;
  225. IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
  226. priv->frames_count);
  227. while (!list_empty(&priv->free_frames)) {
  228. element = priv->free_frames.next;
  229. list_del(element);
  230. kfree(list_entry(element, struct iwl3945_frame, list));
  231. priv->frames_count--;
  232. }
  233. if (priv->frames_count) {
  234. IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
  235. priv->frames_count);
  236. priv->frames_count = 0;
  237. }
  238. }
  239. static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
  240. {
  241. struct iwl3945_frame *frame;
  242. struct list_head *element;
  243. if (list_empty(&priv->free_frames)) {
  244. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  245. if (!frame) {
  246. IWL_ERR(priv, "Could not allocate frame!\n");
  247. return NULL;
  248. }
  249. priv->frames_count++;
  250. return frame;
  251. }
  252. element = priv->free_frames.next;
  253. list_del(element);
  254. return list_entry(element, struct iwl3945_frame, list);
  255. }
  256. static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
  257. {
  258. memset(frame, 0, sizeof(*frame));
  259. list_add(&frame->list, &priv->free_frames);
  260. }
  261. unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
  262. struct ieee80211_hdr *hdr,
  263. int left)
  264. {
  265. if (!iwl_is_associated(priv, IWL_RXON_CTX_BSS) || !priv->ibss_beacon)
  266. return 0;
  267. if (priv->ibss_beacon->len > left)
  268. return 0;
  269. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  270. return priv->ibss_beacon->len;
  271. }
  272. static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
  273. {
  274. struct iwl3945_frame *frame;
  275. unsigned int frame_size;
  276. int rc;
  277. u8 rate;
  278. frame = iwl3945_get_free_frame(priv);
  279. if (!frame) {
  280. IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
  281. "command.\n");
  282. return -ENOMEM;
  283. }
  284. rate = iwl_rate_get_lowest_plcp(priv,
  285. &priv->contexts[IWL_RXON_CTX_BSS]);
  286. frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
  287. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  288. &frame->u.cmd[0]);
  289. iwl3945_free_frame(priv, frame);
  290. return rc;
  291. }
  292. static void iwl3945_unset_hw_params(struct iwl_priv *priv)
  293. {
  294. if (priv->_3945.shared_virt)
  295. dma_free_coherent(&priv->pci_dev->dev,
  296. sizeof(struct iwl3945_shared),
  297. priv->_3945.shared_virt,
  298. priv->_3945.shared_phys);
  299. }
  300. static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
  301. struct ieee80211_tx_info *info,
  302. struct iwl_device_cmd *cmd,
  303. struct sk_buff *skb_frag,
  304. int sta_id)
  305. {
  306. struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
  307. struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
  308. tx_cmd->sec_ctl = 0;
  309. switch (keyinfo->cipher) {
  310. case WLAN_CIPHER_SUITE_CCMP:
  311. tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
  312. memcpy(tx_cmd->key, keyinfo->key, keyinfo->keylen);
  313. IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
  314. break;
  315. case WLAN_CIPHER_SUITE_TKIP:
  316. break;
  317. case WLAN_CIPHER_SUITE_WEP104:
  318. tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
  319. /* fall through */
  320. case WLAN_CIPHER_SUITE_WEP40:
  321. tx_cmd->sec_ctl |= TX_CMD_SEC_WEP |
  322. (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
  323. memcpy(&tx_cmd->key[3], keyinfo->key, keyinfo->keylen);
  324. IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
  325. "with key %d\n", info->control.hw_key->hw_key_idx);
  326. break;
  327. default:
  328. IWL_ERR(priv, "Unknown encode cipher %x\n", keyinfo->cipher);
  329. break;
  330. }
  331. }
  332. /*
  333. * handle build REPLY_TX command notification.
  334. */
  335. static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
  336. struct iwl_device_cmd *cmd,
  337. struct ieee80211_tx_info *info,
  338. struct ieee80211_hdr *hdr, u8 std_id)
  339. {
  340. struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
  341. __le32 tx_flags = tx_cmd->tx_flags;
  342. __le16 fc = hdr->frame_control;
  343. tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  344. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  345. tx_flags |= TX_CMD_FLG_ACK_MSK;
  346. if (ieee80211_is_mgmt(fc))
  347. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  348. if (ieee80211_is_probe_resp(fc) &&
  349. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  350. tx_flags |= TX_CMD_FLG_TSF_MSK;
  351. } else {
  352. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  353. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  354. }
  355. tx_cmd->sta_id = std_id;
  356. if (ieee80211_has_morefrags(fc))
  357. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  358. if (ieee80211_is_data_qos(fc)) {
  359. u8 *qc = ieee80211_get_qos_ctl(hdr);
  360. tx_cmd->tid_tspec = qc[0] & 0xf;
  361. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  362. } else {
  363. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  364. }
  365. priv->cfg->ops->utils->tx_cmd_protection(priv, info, fc, &tx_flags);
  366. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  367. if (ieee80211_is_mgmt(fc)) {
  368. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  369. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
  370. else
  371. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
  372. } else {
  373. tx_cmd->timeout.pm_frame_timeout = 0;
  374. }
  375. tx_cmd->driver_txop = 0;
  376. tx_cmd->tx_flags = tx_flags;
  377. tx_cmd->next_frame_len = 0;
  378. }
  379. /*
  380. * start REPLY_TX command process
  381. */
  382. static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
  383. {
  384. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  385. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  386. struct iwl3945_tx_cmd *tx_cmd;
  387. struct iwl_tx_queue *txq = NULL;
  388. struct iwl_queue *q = NULL;
  389. struct iwl_device_cmd *out_cmd;
  390. struct iwl_cmd_meta *out_meta;
  391. dma_addr_t phys_addr;
  392. dma_addr_t txcmd_phys;
  393. int txq_id = skb_get_queue_mapping(skb);
  394. u16 len, idx, len_org, hdr_len; /* TODO: len_org is not used */
  395. u8 id;
  396. u8 unicast;
  397. u8 sta_id;
  398. u8 tid = 0;
  399. __le16 fc;
  400. u8 wait_write_ptr = 0;
  401. unsigned long flags;
  402. spin_lock_irqsave(&priv->lock, flags);
  403. if (iwl_is_rfkill(priv)) {
  404. IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
  405. goto drop_unlock;
  406. }
  407. if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
  408. IWL_ERR(priv, "ERROR: No TX rate available.\n");
  409. goto drop_unlock;
  410. }
  411. unicast = !is_multicast_ether_addr(hdr->addr1);
  412. id = 0;
  413. fc = hdr->frame_control;
  414. #ifdef CONFIG_IWLWIFI_DEBUG
  415. if (ieee80211_is_auth(fc))
  416. IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
  417. else if (ieee80211_is_assoc_req(fc))
  418. IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
  419. else if (ieee80211_is_reassoc_req(fc))
  420. IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
  421. #endif
  422. spin_unlock_irqrestore(&priv->lock, flags);
  423. hdr_len = ieee80211_hdrlen(fc);
  424. /* Find index into station table for destination station */
  425. sta_id = iwl_sta_id_or_broadcast(
  426. priv, &priv->contexts[IWL_RXON_CTX_BSS],
  427. info->control.sta);
  428. if (sta_id == IWL_INVALID_STATION) {
  429. IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
  430. hdr->addr1);
  431. goto drop;
  432. }
  433. IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
  434. if (ieee80211_is_data_qos(fc)) {
  435. u8 *qc = ieee80211_get_qos_ctl(hdr);
  436. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  437. if (unlikely(tid >= MAX_TID_COUNT))
  438. goto drop;
  439. }
  440. /* Descriptor for chosen Tx queue */
  441. txq = &priv->txq[txq_id];
  442. q = &txq->q;
  443. if ((iwl_queue_space(q) < q->high_mark))
  444. goto drop;
  445. spin_lock_irqsave(&priv->lock, flags);
  446. idx = get_cmd_index(q, q->write_ptr, 0);
  447. /* Set up driver data for this TFD */
  448. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
  449. txq->txb[q->write_ptr].skb = skb;
  450. txq->txb[q->write_ptr].ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  451. /* Init first empty entry in queue's array of Tx/cmd buffers */
  452. out_cmd = txq->cmd[idx];
  453. out_meta = &txq->meta[idx];
  454. tx_cmd = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
  455. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  456. memset(tx_cmd, 0, sizeof(*tx_cmd));
  457. /*
  458. * Set up the Tx-command (not MAC!) header.
  459. * Store the chosen Tx queue and TFD index within the sequence field;
  460. * after Tx, uCode's Tx response will return this value so driver can
  461. * locate the frame within the tx queue and do post-tx processing.
  462. */
  463. out_cmd->hdr.cmd = REPLY_TX;
  464. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  465. INDEX_TO_SEQ(q->write_ptr)));
  466. /* Copy MAC header from skb into command buffer */
  467. memcpy(tx_cmd->hdr, hdr, hdr_len);
  468. if (info->control.hw_key)
  469. iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
  470. /* TODO need this for burst mode later on */
  471. iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
  472. /* set is_hcca to 0; it probably will never be implemented */
  473. iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
  474. /* Total # bytes to be transmitted */
  475. len = (u16)skb->len;
  476. tx_cmd->len = cpu_to_le16(len);
  477. iwl_dbg_log_tx_data_frame(priv, len, hdr);
  478. iwl_update_stats(priv, true, fc, len);
  479. tx_cmd->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
  480. tx_cmd->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
  481. if (!ieee80211_has_morefrags(hdr->frame_control)) {
  482. txq->need_update = 1;
  483. } else {
  484. wait_write_ptr = 1;
  485. txq->need_update = 0;
  486. }
  487. IWL_DEBUG_TX(priv, "sequence nr = 0X%x\n",
  488. le16_to_cpu(out_cmd->hdr.sequence));
  489. IWL_DEBUG_TX(priv, "tx_flags = 0X%x\n", le32_to_cpu(tx_cmd->tx_flags));
  490. iwl_print_hex_dump(priv, IWL_DL_TX, tx_cmd, sizeof(*tx_cmd));
  491. iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd->hdr,
  492. ieee80211_hdrlen(fc));
  493. /*
  494. * Use the first empty entry in this queue's command buffer array
  495. * to contain the Tx command and MAC header concatenated together
  496. * (payload data will be in another buffer).
  497. * Size of this varies, due to varying MAC header length.
  498. * If end is not dword aligned, we'll have 2 extra bytes at the end
  499. * of the MAC header (device reads on dword boundaries).
  500. * We'll tell device about this padding later.
  501. */
  502. len = sizeof(struct iwl3945_tx_cmd) +
  503. sizeof(struct iwl_cmd_header) + hdr_len;
  504. len_org = len;
  505. len = (len + 3) & ~3;
  506. if (len_org != len)
  507. len_org = 1;
  508. else
  509. len_org = 0;
  510. /* Physical address of this Tx command's header (not MAC header!),
  511. * within command buffer array. */
  512. txcmd_phys = pci_map_single(priv->pci_dev, &out_cmd->hdr,
  513. len, PCI_DMA_TODEVICE);
  514. /* we do not map meta data ... so we can safely access address to
  515. * provide to unmap command*/
  516. dma_unmap_addr_set(out_meta, mapping, txcmd_phys);
  517. dma_unmap_len_set(out_meta, len, len);
  518. /* Add buffer containing Tx command and MAC(!) header to TFD's
  519. * first entry */
  520. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  521. txcmd_phys, len, 1, 0);
  522. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  523. * if any (802.11 null frames have no payload). */
  524. len = skb->len - hdr_len;
  525. if (len) {
  526. phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
  527. len, PCI_DMA_TODEVICE);
  528. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  529. phys_addr, len,
  530. 0, U32_PAD(len));
  531. }
  532. /* Tell device the write index *just past* this latest filled TFD */
  533. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  534. iwl_txq_update_write_ptr(priv, txq);
  535. spin_unlock_irqrestore(&priv->lock, flags);
  536. if ((iwl_queue_space(q) < q->high_mark)
  537. && priv->mac80211_registered) {
  538. if (wait_write_ptr) {
  539. spin_lock_irqsave(&priv->lock, flags);
  540. txq->need_update = 1;
  541. iwl_txq_update_write_ptr(priv, txq);
  542. spin_unlock_irqrestore(&priv->lock, flags);
  543. }
  544. iwl_stop_queue(priv, skb_get_queue_mapping(skb));
  545. }
  546. return 0;
  547. drop_unlock:
  548. spin_unlock_irqrestore(&priv->lock, flags);
  549. drop:
  550. return -1;
  551. }
  552. static int iwl3945_get_measurement(struct iwl_priv *priv,
  553. struct ieee80211_measurement_params *params,
  554. u8 type)
  555. {
  556. struct iwl_spectrum_cmd spectrum;
  557. struct iwl_rx_packet *pkt;
  558. struct iwl_host_cmd cmd = {
  559. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  560. .data = (void *)&spectrum,
  561. .flags = CMD_WANT_SKB,
  562. };
  563. u32 add_time = le64_to_cpu(params->start_time);
  564. int rc;
  565. int spectrum_resp_status;
  566. int duration = le16_to_cpu(params->duration);
  567. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  568. if (iwl_is_associated(priv, IWL_RXON_CTX_BSS))
  569. add_time = iwl_usecs_to_beacons(priv,
  570. le64_to_cpu(params->start_time) - priv->_3945.last_tsf,
  571. le16_to_cpu(ctx->timing.beacon_interval));
  572. memset(&spectrum, 0, sizeof(spectrum));
  573. spectrum.channel_count = cpu_to_le16(1);
  574. spectrum.flags =
  575. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  576. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  577. cmd.len = sizeof(spectrum);
  578. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  579. if (iwl_is_associated(priv, IWL_RXON_CTX_BSS))
  580. spectrum.start_time =
  581. iwl_add_beacon_time(priv,
  582. priv->_3945.last_beacon_time, add_time,
  583. le16_to_cpu(ctx->timing.beacon_interval));
  584. else
  585. spectrum.start_time = 0;
  586. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  587. spectrum.channels[0].channel = params->channel;
  588. spectrum.channels[0].type = type;
  589. if (ctx->active.flags & RXON_FLG_BAND_24G_MSK)
  590. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  591. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  592. rc = iwl_send_cmd_sync(priv, &cmd);
  593. if (rc)
  594. return rc;
  595. pkt = (struct iwl_rx_packet *)cmd.reply_page;
  596. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  597. IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
  598. rc = -EIO;
  599. }
  600. spectrum_resp_status = le16_to_cpu(pkt->u.spectrum.status);
  601. switch (spectrum_resp_status) {
  602. case 0: /* Command will be handled */
  603. if (pkt->u.spectrum.id != 0xff) {
  604. IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
  605. pkt->u.spectrum.id);
  606. priv->measurement_status &= ~MEASUREMENT_READY;
  607. }
  608. priv->measurement_status |= MEASUREMENT_ACTIVE;
  609. rc = 0;
  610. break;
  611. case 1: /* Command will not be handled */
  612. rc = -EAGAIN;
  613. break;
  614. }
  615. iwl_free_pages(priv, cmd.reply_page);
  616. return rc;
  617. }
  618. static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
  619. struct iwl_rx_mem_buffer *rxb)
  620. {
  621. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  622. struct iwl_alive_resp *palive;
  623. struct delayed_work *pwork;
  624. palive = &pkt->u.alive_frame;
  625. IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
  626. "0x%01X 0x%01X\n",
  627. palive->is_valid, palive->ver_type,
  628. palive->ver_subtype);
  629. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  630. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  631. memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
  632. sizeof(struct iwl_alive_resp));
  633. pwork = &priv->init_alive_start;
  634. } else {
  635. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  636. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  637. sizeof(struct iwl_alive_resp));
  638. pwork = &priv->alive_start;
  639. iwl3945_disable_events(priv);
  640. }
  641. /* We delay the ALIVE response by 5ms to
  642. * give the HW RF Kill time to activate... */
  643. if (palive->is_valid == UCODE_VALID_OK)
  644. queue_delayed_work(priv->workqueue, pwork,
  645. msecs_to_jiffies(5));
  646. else
  647. IWL_WARN(priv, "uCode did not respond OK.\n");
  648. }
  649. static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
  650. struct iwl_rx_mem_buffer *rxb)
  651. {
  652. #ifdef CONFIG_IWLWIFI_DEBUG
  653. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  654. #endif
  655. IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
  656. }
  657. static void iwl3945_bg_beacon_update(struct work_struct *work)
  658. {
  659. struct iwl_priv *priv =
  660. container_of(work, struct iwl_priv, beacon_update);
  661. struct sk_buff *beacon;
  662. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  663. beacon = ieee80211_beacon_get(priv->hw,
  664. priv->contexts[IWL_RXON_CTX_BSS].vif);
  665. if (!beacon) {
  666. IWL_ERR(priv, "update beacon failed\n");
  667. return;
  668. }
  669. mutex_lock(&priv->mutex);
  670. /* new beacon skb is allocated every time; dispose previous.*/
  671. if (priv->ibss_beacon)
  672. dev_kfree_skb(priv->ibss_beacon);
  673. priv->ibss_beacon = beacon;
  674. mutex_unlock(&priv->mutex);
  675. iwl3945_send_beacon_cmd(priv);
  676. }
  677. static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
  678. struct iwl_rx_mem_buffer *rxb)
  679. {
  680. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  681. struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
  682. #ifdef CONFIG_IWLWIFI_DEBUG
  683. u8 rate = beacon->beacon_notify_hdr.rate;
  684. IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
  685. "tsf %d %d rate %d\n",
  686. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  687. beacon->beacon_notify_hdr.failure_frame,
  688. le32_to_cpu(beacon->ibss_mgr_status),
  689. le32_to_cpu(beacon->high_tsf),
  690. le32_to_cpu(beacon->low_tsf), rate);
  691. #endif
  692. priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  693. if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
  694. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  695. queue_work(priv->workqueue, &priv->beacon_update);
  696. }
  697. /* Handle notification from uCode that card's power state is changing
  698. * due to software, hardware, or critical temperature RFKILL */
  699. static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
  700. struct iwl_rx_mem_buffer *rxb)
  701. {
  702. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  703. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  704. unsigned long status = priv->status;
  705. IWL_WARN(priv, "Card state received: HW:%s SW:%s\n",
  706. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  707. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  708. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  709. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  710. if (flags & HW_CARD_DISABLED)
  711. set_bit(STATUS_RF_KILL_HW, &priv->status);
  712. else
  713. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  714. iwl_scan_cancel(priv);
  715. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  716. test_bit(STATUS_RF_KILL_HW, &priv->status)))
  717. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  718. test_bit(STATUS_RF_KILL_HW, &priv->status));
  719. else
  720. wake_up_interruptible(&priv->wait_command_queue);
  721. }
  722. /**
  723. * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
  724. *
  725. * Setup the RX handlers for each of the reply types sent from the uCode
  726. * to the host.
  727. *
  728. * This function chains into the hardware specific files for them to setup
  729. * any hardware specific handlers as well.
  730. */
  731. static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
  732. {
  733. priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
  734. priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
  735. priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
  736. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
  737. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  738. iwl_rx_spectrum_measure_notif;
  739. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
  740. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  741. iwl_rx_pm_debug_statistics_notif;
  742. priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
  743. /*
  744. * The same handler is used for both the REPLY to a discrete
  745. * statistics request from the host as well as for the periodic
  746. * statistics notifications (after received beacons) from the uCode.
  747. */
  748. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_reply_statistics;
  749. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
  750. iwl_setup_rx_scan_handlers(priv);
  751. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
  752. /* Set up hardware specific Rx handlers */
  753. iwl3945_hw_rx_handler_setup(priv);
  754. }
  755. /************************** RX-FUNCTIONS ****************************/
  756. /*
  757. * Rx theory of operation
  758. *
  759. * The host allocates 32 DMA target addresses and passes the host address
  760. * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
  761. * 0 to 31
  762. *
  763. * Rx Queue Indexes
  764. * The host/firmware share two index registers for managing the Rx buffers.
  765. *
  766. * The READ index maps to the first position that the firmware may be writing
  767. * to -- the driver can read up to (but not including) this position and get
  768. * good data.
  769. * The READ index is managed by the firmware once the card is enabled.
  770. *
  771. * The WRITE index maps to the last position the driver has read from -- the
  772. * position preceding WRITE is the last slot the firmware can place a packet.
  773. *
  774. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  775. * WRITE = READ.
  776. *
  777. * During initialization, the host sets up the READ queue position to the first
  778. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  779. *
  780. * When the firmware places a packet in a buffer, it will advance the READ index
  781. * and fire the RX interrupt. The driver can then query the READ index and
  782. * process as many packets as possible, moving the WRITE index forward as it
  783. * resets the Rx queue buffers with new memory.
  784. *
  785. * The management in the driver is as follows:
  786. * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
  787. * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  788. * to replenish the iwl->rxq->rx_free.
  789. * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
  790. * iwl->rxq is replenished and the READ INDEX is updated (updating the
  791. * 'processed' and 'read' driver indexes as well)
  792. * + A received packet is processed and handed to the kernel network stack,
  793. * detached from the iwl->rxq. The driver 'processed' index is updated.
  794. * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
  795. * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
  796. * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
  797. * were enough free buffers and RX_STALLED is set it is cleared.
  798. *
  799. *
  800. * Driver sequence:
  801. *
  802. * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
  803. * iwl3945_rx_queue_restock
  804. * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
  805. * queue, updates firmware pointers, and updates
  806. * the WRITE index. If insufficient rx_free buffers
  807. * are available, schedules iwl3945_rx_replenish
  808. *
  809. * -- enable interrupts --
  810. * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
  811. * READ INDEX, detaching the SKB from the pool.
  812. * Moves the packet buffer from queue to rx_used.
  813. * Calls iwl3945_rx_queue_restock to refill any empty
  814. * slots.
  815. * ...
  816. *
  817. */
  818. /**
  819. * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  820. */
  821. static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
  822. dma_addr_t dma_addr)
  823. {
  824. return cpu_to_le32((u32)dma_addr);
  825. }
  826. /**
  827. * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
  828. *
  829. * If there are slots in the RX queue that need to be restocked,
  830. * and we have free pre-allocated buffers, fill the ranks as much
  831. * as we can, pulling from rx_free.
  832. *
  833. * This moves the 'write' index forward to catch up with 'processed', and
  834. * also updates the memory address in the firmware to reference the new
  835. * target buffer.
  836. */
  837. static void iwl3945_rx_queue_restock(struct iwl_priv *priv)
  838. {
  839. struct iwl_rx_queue *rxq = &priv->rxq;
  840. struct list_head *element;
  841. struct iwl_rx_mem_buffer *rxb;
  842. unsigned long flags;
  843. int write;
  844. spin_lock_irqsave(&rxq->lock, flags);
  845. write = rxq->write & ~0x7;
  846. while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  847. /* Get next free Rx buffer, remove from free list */
  848. element = rxq->rx_free.next;
  849. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  850. list_del(element);
  851. /* Point to Rx buffer via next RBD in circular buffer */
  852. rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->page_dma);
  853. rxq->queue[rxq->write] = rxb;
  854. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  855. rxq->free_count--;
  856. }
  857. spin_unlock_irqrestore(&rxq->lock, flags);
  858. /* If the pre-allocated buffer pool is dropping low, schedule to
  859. * refill it */
  860. if (rxq->free_count <= RX_LOW_WATERMARK)
  861. queue_work(priv->workqueue, &priv->rx_replenish);
  862. /* If we've added more space for the firmware to place data, tell it.
  863. * Increment device's write pointer in multiples of 8. */
  864. if ((rxq->write_actual != (rxq->write & ~0x7))
  865. || (abs(rxq->write - rxq->read) > 7)) {
  866. spin_lock_irqsave(&rxq->lock, flags);
  867. rxq->need_update = 1;
  868. spin_unlock_irqrestore(&rxq->lock, flags);
  869. iwl_rx_queue_update_write_ptr(priv, rxq);
  870. }
  871. }
  872. /**
  873. * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
  874. *
  875. * When moving to rx_free an SKB is allocated for the slot.
  876. *
  877. * Also restock the Rx queue via iwl3945_rx_queue_restock.
  878. * This is called as a scheduled work item (except for during initialization)
  879. */
  880. static void iwl3945_rx_allocate(struct iwl_priv *priv, gfp_t priority)
  881. {
  882. struct iwl_rx_queue *rxq = &priv->rxq;
  883. struct list_head *element;
  884. struct iwl_rx_mem_buffer *rxb;
  885. struct page *page;
  886. unsigned long flags;
  887. gfp_t gfp_mask = priority;
  888. while (1) {
  889. spin_lock_irqsave(&rxq->lock, flags);
  890. if (list_empty(&rxq->rx_used)) {
  891. spin_unlock_irqrestore(&rxq->lock, flags);
  892. return;
  893. }
  894. spin_unlock_irqrestore(&rxq->lock, flags);
  895. if (rxq->free_count > RX_LOW_WATERMARK)
  896. gfp_mask |= __GFP_NOWARN;
  897. if (priv->hw_params.rx_page_order > 0)
  898. gfp_mask |= __GFP_COMP;
  899. /* Alloc a new receive buffer */
  900. page = alloc_pages(gfp_mask, priv->hw_params.rx_page_order);
  901. if (!page) {
  902. if (net_ratelimit())
  903. IWL_DEBUG_INFO(priv, "Failed to allocate SKB buffer.\n");
  904. if ((rxq->free_count <= RX_LOW_WATERMARK) &&
  905. net_ratelimit())
  906. IWL_CRIT(priv, "Failed to allocate SKB buffer with %s. Only %u free buffers remaining.\n",
  907. priority == GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
  908. rxq->free_count);
  909. /* We don't reschedule replenish work here -- we will
  910. * call the restock method and if it still needs
  911. * more buffers it will schedule replenish */
  912. break;
  913. }
  914. spin_lock_irqsave(&rxq->lock, flags);
  915. if (list_empty(&rxq->rx_used)) {
  916. spin_unlock_irqrestore(&rxq->lock, flags);
  917. __free_pages(page, priv->hw_params.rx_page_order);
  918. return;
  919. }
  920. element = rxq->rx_used.next;
  921. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  922. list_del(element);
  923. spin_unlock_irqrestore(&rxq->lock, flags);
  924. rxb->page = page;
  925. /* Get physical address of RB/SKB */
  926. rxb->page_dma = pci_map_page(priv->pci_dev, page, 0,
  927. PAGE_SIZE << priv->hw_params.rx_page_order,
  928. PCI_DMA_FROMDEVICE);
  929. spin_lock_irqsave(&rxq->lock, flags);
  930. list_add_tail(&rxb->list, &rxq->rx_free);
  931. rxq->free_count++;
  932. priv->alloc_rxb_page++;
  933. spin_unlock_irqrestore(&rxq->lock, flags);
  934. }
  935. }
  936. void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  937. {
  938. unsigned long flags;
  939. int i;
  940. spin_lock_irqsave(&rxq->lock, flags);
  941. INIT_LIST_HEAD(&rxq->rx_free);
  942. INIT_LIST_HEAD(&rxq->rx_used);
  943. /* Fill the rx_used queue with _all_ of the Rx buffers */
  944. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  945. /* In the reset function, these buffers may have been allocated
  946. * to an SKB, so we need to unmap and free potential storage */
  947. if (rxq->pool[i].page != NULL) {
  948. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  949. PAGE_SIZE << priv->hw_params.rx_page_order,
  950. PCI_DMA_FROMDEVICE);
  951. __iwl_free_pages(priv, rxq->pool[i].page);
  952. rxq->pool[i].page = NULL;
  953. }
  954. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  955. }
  956. /* Set us so that we have processed and used all buffers, but have
  957. * not restocked the Rx queue with fresh buffers */
  958. rxq->read = rxq->write = 0;
  959. rxq->write_actual = 0;
  960. rxq->free_count = 0;
  961. spin_unlock_irqrestore(&rxq->lock, flags);
  962. }
  963. void iwl3945_rx_replenish(void *data)
  964. {
  965. struct iwl_priv *priv = data;
  966. unsigned long flags;
  967. iwl3945_rx_allocate(priv, GFP_KERNEL);
  968. spin_lock_irqsave(&priv->lock, flags);
  969. iwl3945_rx_queue_restock(priv);
  970. spin_unlock_irqrestore(&priv->lock, flags);
  971. }
  972. static void iwl3945_rx_replenish_now(struct iwl_priv *priv)
  973. {
  974. iwl3945_rx_allocate(priv, GFP_ATOMIC);
  975. iwl3945_rx_queue_restock(priv);
  976. }
  977. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  978. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  979. * This free routine walks the list of POOL entries and if SKB is set to
  980. * non NULL it is unmapped and freed
  981. */
  982. static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  983. {
  984. int i;
  985. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  986. if (rxq->pool[i].page != NULL) {
  987. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  988. PAGE_SIZE << priv->hw_params.rx_page_order,
  989. PCI_DMA_FROMDEVICE);
  990. __iwl_free_pages(priv, rxq->pool[i].page);
  991. rxq->pool[i].page = NULL;
  992. }
  993. }
  994. dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  995. rxq->bd_dma);
  996. dma_free_coherent(&priv->pci_dev->dev, sizeof(struct iwl_rb_status),
  997. rxq->rb_stts, rxq->rb_stts_dma);
  998. rxq->bd = NULL;
  999. rxq->rb_stts = NULL;
  1000. }
  1001. /* Convert linear signal-to-noise ratio into dB */
  1002. static u8 ratio2dB[100] = {
  1003. /* 0 1 2 3 4 5 6 7 8 9 */
  1004. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  1005. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  1006. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  1007. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  1008. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  1009. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  1010. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  1011. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  1012. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  1013. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  1014. };
  1015. /* Calculates a relative dB value from a ratio of linear
  1016. * (i.e. not dB) signal levels.
  1017. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  1018. int iwl3945_calc_db_from_ratio(int sig_ratio)
  1019. {
  1020. /* 1000:1 or higher just report as 60 dB */
  1021. if (sig_ratio >= 1000)
  1022. return 60;
  1023. /* 100:1 or higher, divide by 10 and use table,
  1024. * add 20 dB to make up for divide by 10 */
  1025. if (sig_ratio >= 100)
  1026. return 20 + (int)ratio2dB[sig_ratio/10];
  1027. /* We shouldn't see this */
  1028. if (sig_ratio < 1)
  1029. return 0;
  1030. /* Use table for ratios 1:1 - 99:1 */
  1031. return (int)ratio2dB[sig_ratio];
  1032. }
  1033. /**
  1034. * iwl3945_rx_handle - Main entry function for receiving responses from uCode
  1035. *
  1036. * Uses the priv->rx_handlers callback function array to invoke
  1037. * the appropriate handlers, including command responses,
  1038. * frame-received notifications, and other notifications.
  1039. */
  1040. static void iwl3945_rx_handle(struct iwl_priv *priv)
  1041. {
  1042. struct iwl_rx_mem_buffer *rxb;
  1043. struct iwl_rx_packet *pkt;
  1044. struct iwl_rx_queue *rxq = &priv->rxq;
  1045. u32 r, i;
  1046. int reclaim;
  1047. unsigned long flags;
  1048. u8 fill_rx = 0;
  1049. u32 count = 8;
  1050. int total_empty = 0;
  1051. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  1052. * buffer that the driver may process (last buffer filled by ucode). */
  1053. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  1054. i = rxq->read;
  1055. /* calculate total frames need to be restock after handling RX */
  1056. total_empty = r - rxq->write_actual;
  1057. if (total_empty < 0)
  1058. total_empty += RX_QUEUE_SIZE;
  1059. if (total_empty > (RX_QUEUE_SIZE / 2))
  1060. fill_rx = 1;
  1061. /* Rx interrupt, but nothing sent from uCode */
  1062. if (i == r)
  1063. IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
  1064. while (i != r) {
  1065. int len;
  1066. rxb = rxq->queue[i];
  1067. /* If an RXB doesn't have a Rx queue slot associated with it,
  1068. * then a bug has been introduced in the queue refilling
  1069. * routines -- catch it here */
  1070. BUG_ON(rxb == NULL);
  1071. rxq->queue[i] = NULL;
  1072. pci_unmap_page(priv->pci_dev, rxb->page_dma,
  1073. PAGE_SIZE << priv->hw_params.rx_page_order,
  1074. PCI_DMA_FROMDEVICE);
  1075. pkt = rxb_addr(rxb);
  1076. len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  1077. len += sizeof(u32); /* account for status word */
  1078. trace_iwlwifi_dev_rx(priv, pkt, len);
  1079. /* Reclaim a command buffer only if this packet is a response
  1080. * to a (driver-originated) command.
  1081. * If the packet (e.g. Rx frame) originated from uCode,
  1082. * there is no command buffer to reclaim.
  1083. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  1084. * but apparently a few don't get set; catch them here. */
  1085. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  1086. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  1087. (pkt->hdr.cmd != REPLY_TX);
  1088. /* Based on type of command response or notification,
  1089. * handle those that need handling via function in
  1090. * rx_handlers table. See iwl3945_setup_rx_handlers() */
  1091. if (priv->rx_handlers[pkt->hdr.cmd]) {
  1092. IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r, i,
  1093. get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  1094. priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
  1095. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  1096. } else {
  1097. /* No handling needed */
  1098. IWL_DEBUG_RX(priv,
  1099. "r %d i %d No handler needed for %s, 0x%02x\n",
  1100. r, i, get_cmd_string(pkt->hdr.cmd),
  1101. pkt->hdr.cmd);
  1102. }
  1103. /*
  1104. * XXX: After here, we should always check rxb->page
  1105. * against NULL before touching it or its virtual
  1106. * memory (pkt). Because some rx_handler might have
  1107. * already taken or freed the pages.
  1108. */
  1109. if (reclaim) {
  1110. /* Invoke any callbacks, transfer the buffer to caller,
  1111. * and fire off the (possibly) blocking iwl_send_cmd()
  1112. * as we reclaim the driver command queue */
  1113. if (rxb->page)
  1114. iwl_tx_cmd_complete(priv, rxb);
  1115. else
  1116. IWL_WARN(priv, "Claim null rxb?\n");
  1117. }
  1118. /* Reuse the page if possible. For notification packets and
  1119. * SKBs that fail to Rx correctly, add them back into the
  1120. * rx_free list for reuse later. */
  1121. spin_lock_irqsave(&rxq->lock, flags);
  1122. if (rxb->page != NULL) {
  1123. rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
  1124. 0, PAGE_SIZE << priv->hw_params.rx_page_order,
  1125. PCI_DMA_FROMDEVICE);
  1126. list_add_tail(&rxb->list, &rxq->rx_free);
  1127. rxq->free_count++;
  1128. } else
  1129. list_add_tail(&rxb->list, &rxq->rx_used);
  1130. spin_unlock_irqrestore(&rxq->lock, flags);
  1131. i = (i + 1) & RX_QUEUE_MASK;
  1132. /* If there are a lot of unused frames,
  1133. * restock the Rx queue so ucode won't assert. */
  1134. if (fill_rx) {
  1135. count++;
  1136. if (count >= 8) {
  1137. rxq->read = i;
  1138. iwl3945_rx_replenish_now(priv);
  1139. count = 0;
  1140. }
  1141. }
  1142. }
  1143. /* Backtrack one entry */
  1144. rxq->read = i;
  1145. if (fill_rx)
  1146. iwl3945_rx_replenish_now(priv);
  1147. else
  1148. iwl3945_rx_queue_restock(priv);
  1149. }
  1150. /* call this function to flush any scheduled tasklet */
  1151. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  1152. {
  1153. /* wait to make sure we flush pending tasklet*/
  1154. synchronize_irq(priv->pci_dev->irq);
  1155. tasklet_kill(&priv->irq_tasklet);
  1156. }
  1157. static const char *desc_lookup(int i)
  1158. {
  1159. switch (i) {
  1160. case 1:
  1161. return "FAIL";
  1162. case 2:
  1163. return "BAD_PARAM";
  1164. case 3:
  1165. return "BAD_CHECKSUM";
  1166. case 4:
  1167. return "NMI_INTERRUPT";
  1168. case 5:
  1169. return "SYSASSERT";
  1170. case 6:
  1171. return "FATAL_ERROR";
  1172. }
  1173. return "UNKNOWN";
  1174. }
  1175. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1176. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1177. void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
  1178. {
  1179. u32 i;
  1180. u32 desc, time, count, base, data1;
  1181. u32 blink1, blink2, ilink1, ilink2;
  1182. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  1183. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  1184. IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
  1185. return;
  1186. }
  1187. count = iwl_read_targ_mem(priv, base);
  1188. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1189. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1190. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1191. priv->status, count);
  1192. }
  1193. IWL_ERR(priv, "Desc Time asrtPC blink2 "
  1194. "ilink1 nmiPC Line\n");
  1195. for (i = ERROR_START_OFFSET;
  1196. i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
  1197. i += ERROR_ELEM_SIZE) {
  1198. desc = iwl_read_targ_mem(priv, base + i);
  1199. time =
  1200. iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
  1201. blink1 =
  1202. iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
  1203. blink2 =
  1204. iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
  1205. ilink1 =
  1206. iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
  1207. ilink2 =
  1208. iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
  1209. data1 =
  1210. iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
  1211. IWL_ERR(priv,
  1212. "%-13s (0x%X) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
  1213. desc_lookup(desc), desc, time, blink1, blink2,
  1214. ilink1, ilink2, data1);
  1215. trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, 0,
  1216. 0, blink1, blink2, ilink1, ilink2);
  1217. }
  1218. }
  1219. #define EVENT_START_OFFSET (6 * sizeof(u32))
  1220. /**
  1221. * iwl3945_print_event_log - Dump error event log to syslog
  1222. *
  1223. */
  1224. static int iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1225. u32 num_events, u32 mode,
  1226. int pos, char **buf, size_t bufsz)
  1227. {
  1228. u32 i;
  1229. u32 base; /* SRAM byte address of event log header */
  1230. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1231. u32 ptr; /* SRAM byte address of log data */
  1232. u32 ev, time, data; /* event log data */
  1233. unsigned long reg_flags;
  1234. if (num_events == 0)
  1235. return pos;
  1236. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1237. if (mode == 0)
  1238. event_size = 2 * sizeof(u32);
  1239. else
  1240. event_size = 3 * sizeof(u32);
  1241. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1242. /* Make sure device is powered up for SRAM reads */
  1243. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  1244. iwl_grab_nic_access(priv);
  1245. /* Set starting address; reads will auto-increment */
  1246. _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
  1247. rmb();
  1248. /* "time" is actually "data" for mode 0 (no timestamp).
  1249. * place event id # at far right for easier visual parsing. */
  1250. for (i = 0; i < num_events; i++) {
  1251. ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1252. time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1253. if (mode == 0) {
  1254. /* data, ev */
  1255. if (bufsz) {
  1256. pos += scnprintf(*buf + pos, bufsz - pos,
  1257. "0x%08x:%04u\n",
  1258. time, ev);
  1259. } else {
  1260. IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
  1261. trace_iwlwifi_dev_ucode_event(priv, 0,
  1262. time, ev);
  1263. }
  1264. } else {
  1265. data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1266. if (bufsz) {
  1267. pos += scnprintf(*buf + pos, bufsz - pos,
  1268. "%010u:0x%08x:%04u\n",
  1269. time, data, ev);
  1270. } else {
  1271. IWL_ERR(priv, "%010u\t0x%08x\t%04u\n",
  1272. time, data, ev);
  1273. trace_iwlwifi_dev_ucode_event(priv, time,
  1274. data, ev);
  1275. }
  1276. }
  1277. }
  1278. /* Allow device to power down */
  1279. iwl_release_nic_access(priv);
  1280. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  1281. return pos;
  1282. }
  1283. /**
  1284. * iwl3945_print_last_event_logs - Dump the newest # of event log to syslog
  1285. */
  1286. static int iwl3945_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1287. u32 num_wraps, u32 next_entry,
  1288. u32 size, u32 mode,
  1289. int pos, char **buf, size_t bufsz)
  1290. {
  1291. /*
  1292. * display the newest DEFAULT_LOG_ENTRIES entries
  1293. * i.e the entries just before the next ont that uCode would fill.
  1294. */
  1295. if (num_wraps) {
  1296. if (next_entry < size) {
  1297. pos = iwl3945_print_event_log(priv,
  1298. capacity - (size - next_entry),
  1299. size - next_entry, mode,
  1300. pos, buf, bufsz);
  1301. pos = iwl3945_print_event_log(priv, 0,
  1302. next_entry, mode,
  1303. pos, buf, bufsz);
  1304. } else
  1305. pos = iwl3945_print_event_log(priv, next_entry - size,
  1306. size, mode,
  1307. pos, buf, bufsz);
  1308. } else {
  1309. if (next_entry < size)
  1310. pos = iwl3945_print_event_log(priv, 0,
  1311. next_entry, mode,
  1312. pos, buf, bufsz);
  1313. else
  1314. pos = iwl3945_print_event_log(priv, next_entry - size,
  1315. size, mode,
  1316. pos, buf, bufsz);
  1317. }
  1318. return pos;
  1319. }
  1320. #define DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES (20)
  1321. int iwl3945_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1322. char **buf, bool display)
  1323. {
  1324. u32 base; /* SRAM byte address of event log header */
  1325. u32 capacity; /* event log capacity in # entries */
  1326. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1327. u32 num_wraps; /* # times uCode wrapped to top of log */
  1328. u32 next_entry; /* index of next entry to be written by uCode */
  1329. u32 size; /* # entries that we'll print */
  1330. int pos = 0;
  1331. size_t bufsz = 0;
  1332. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1333. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  1334. IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
  1335. return -EINVAL;
  1336. }
  1337. /* event log header */
  1338. capacity = iwl_read_targ_mem(priv, base);
  1339. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1340. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1341. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1342. if (capacity > priv->cfg->max_event_log_size) {
  1343. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
  1344. capacity, priv->cfg->max_event_log_size);
  1345. capacity = priv->cfg->max_event_log_size;
  1346. }
  1347. if (next_entry > priv->cfg->max_event_log_size) {
  1348. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  1349. next_entry, priv->cfg->max_event_log_size);
  1350. next_entry = priv->cfg->max_event_log_size;
  1351. }
  1352. size = num_wraps ? capacity : next_entry;
  1353. /* bail out if nothing in log */
  1354. if (size == 0) {
  1355. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1356. return pos;
  1357. }
  1358. #ifdef CONFIG_IWLWIFI_DEBUG
  1359. if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
  1360. size = (size > DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES)
  1361. ? DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES : size;
  1362. #else
  1363. size = (size > DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES)
  1364. ? DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES : size;
  1365. #endif
  1366. IWL_ERR(priv, "Start IWL Event Log Dump: display last %d count\n",
  1367. size);
  1368. #ifdef CONFIG_IWLWIFI_DEBUG
  1369. if (display) {
  1370. if (full_log)
  1371. bufsz = capacity * 48;
  1372. else
  1373. bufsz = size * 48;
  1374. *buf = kmalloc(bufsz, GFP_KERNEL);
  1375. if (!*buf)
  1376. return -ENOMEM;
  1377. }
  1378. if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
  1379. /* if uCode has wrapped back to top of log,
  1380. * start at the oldest entry,
  1381. * i.e the next one that uCode would fill.
  1382. */
  1383. if (num_wraps)
  1384. pos = iwl3945_print_event_log(priv, next_entry,
  1385. capacity - next_entry, mode,
  1386. pos, buf, bufsz);
  1387. /* (then/else) start at top of log */
  1388. pos = iwl3945_print_event_log(priv, 0, next_entry, mode,
  1389. pos, buf, bufsz);
  1390. } else
  1391. pos = iwl3945_print_last_event_logs(priv, capacity, num_wraps,
  1392. next_entry, size, mode,
  1393. pos, buf, bufsz);
  1394. #else
  1395. pos = iwl3945_print_last_event_logs(priv, capacity, num_wraps,
  1396. next_entry, size, mode,
  1397. pos, buf, bufsz);
  1398. #endif
  1399. return pos;
  1400. }
  1401. static void iwl3945_irq_tasklet(struct iwl_priv *priv)
  1402. {
  1403. u32 inta, handled = 0;
  1404. u32 inta_fh;
  1405. unsigned long flags;
  1406. #ifdef CONFIG_IWLWIFI_DEBUG
  1407. u32 inta_mask;
  1408. #endif
  1409. spin_lock_irqsave(&priv->lock, flags);
  1410. /* Ack/clear/reset pending uCode interrupts.
  1411. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  1412. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  1413. inta = iwl_read32(priv, CSR_INT);
  1414. iwl_write32(priv, CSR_INT, inta);
  1415. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  1416. * Any new interrupts that happen after this, either while we're
  1417. * in this tasklet, or later, will show up in next ISR/tasklet. */
  1418. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1419. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  1420. #ifdef CONFIG_IWLWIFI_DEBUG
  1421. if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
  1422. /* just for debug */
  1423. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1424. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1425. inta, inta_mask, inta_fh);
  1426. }
  1427. #endif
  1428. spin_unlock_irqrestore(&priv->lock, flags);
  1429. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  1430. * atomic, make sure that inta covers all the interrupts that
  1431. * we've discovered, even if FH interrupt came in just after
  1432. * reading CSR_INT. */
  1433. if (inta_fh & CSR39_FH_INT_RX_MASK)
  1434. inta |= CSR_INT_BIT_FH_RX;
  1435. if (inta_fh & CSR39_FH_INT_TX_MASK)
  1436. inta |= CSR_INT_BIT_FH_TX;
  1437. /* Now service all interrupt bits discovered above. */
  1438. if (inta & CSR_INT_BIT_HW_ERR) {
  1439. IWL_ERR(priv, "Hardware error detected. Restarting.\n");
  1440. /* Tell the device to stop sending interrupts */
  1441. iwl_disable_interrupts(priv);
  1442. priv->isr_stats.hw++;
  1443. iwl_irq_handle_error(priv);
  1444. handled |= CSR_INT_BIT_HW_ERR;
  1445. return;
  1446. }
  1447. #ifdef CONFIG_IWLWIFI_DEBUG
  1448. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  1449. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  1450. if (inta & CSR_INT_BIT_SCD) {
  1451. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  1452. "the frame/frames.\n");
  1453. priv->isr_stats.sch++;
  1454. }
  1455. /* Alive notification via Rx interrupt will do the real work */
  1456. if (inta & CSR_INT_BIT_ALIVE) {
  1457. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  1458. priv->isr_stats.alive++;
  1459. }
  1460. }
  1461. #endif
  1462. /* Safely ignore these bits for debug checks below */
  1463. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  1464. /* Error detected by uCode */
  1465. if (inta & CSR_INT_BIT_SW_ERR) {
  1466. IWL_ERR(priv, "Microcode SW error detected. "
  1467. "Restarting 0x%X.\n", inta);
  1468. priv->isr_stats.sw++;
  1469. priv->isr_stats.sw_err = inta;
  1470. iwl_irq_handle_error(priv);
  1471. handled |= CSR_INT_BIT_SW_ERR;
  1472. }
  1473. /* uCode wakes up after power-down sleep */
  1474. if (inta & CSR_INT_BIT_WAKEUP) {
  1475. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  1476. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  1477. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  1478. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  1479. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  1480. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  1481. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  1482. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  1483. priv->isr_stats.wakeup++;
  1484. handled |= CSR_INT_BIT_WAKEUP;
  1485. }
  1486. /* All uCode command responses, including Tx command responses,
  1487. * Rx "responses" (frame-received notification), and other
  1488. * notifications from uCode come through here*/
  1489. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  1490. iwl3945_rx_handle(priv);
  1491. priv->isr_stats.rx++;
  1492. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  1493. }
  1494. if (inta & CSR_INT_BIT_FH_TX) {
  1495. IWL_DEBUG_ISR(priv, "Tx interrupt\n");
  1496. priv->isr_stats.tx++;
  1497. iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
  1498. iwl_write_direct32(priv, FH39_TCSR_CREDIT
  1499. (FH39_SRVC_CHNL), 0x0);
  1500. handled |= CSR_INT_BIT_FH_TX;
  1501. }
  1502. if (inta & ~handled) {
  1503. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1504. priv->isr_stats.unhandled++;
  1505. }
  1506. if (inta & ~priv->inta_mask) {
  1507. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  1508. inta & ~priv->inta_mask);
  1509. IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
  1510. }
  1511. /* Re-enable all interrupts */
  1512. /* only Re-enable if disabled by irq */
  1513. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1514. iwl_enable_interrupts(priv);
  1515. #ifdef CONFIG_IWLWIFI_DEBUG
  1516. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  1517. inta = iwl_read32(priv, CSR_INT);
  1518. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1519. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1520. IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  1521. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  1522. }
  1523. #endif
  1524. }
  1525. static int iwl3945_get_single_channel_for_scan(struct iwl_priv *priv,
  1526. struct ieee80211_vif *vif,
  1527. enum ieee80211_band band,
  1528. struct iwl3945_scan_channel *scan_ch)
  1529. {
  1530. const struct ieee80211_supported_band *sband;
  1531. u16 passive_dwell = 0;
  1532. u16 active_dwell = 0;
  1533. int added = 0;
  1534. u8 channel = 0;
  1535. sband = iwl_get_hw_mode(priv, band);
  1536. if (!sband) {
  1537. IWL_ERR(priv, "invalid band\n");
  1538. return added;
  1539. }
  1540. active_dwell = iwl_get_active_dwell_time(priv, band, 0);
  1541. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  1542. if (passive_dwell <= active_dwell)
  1543. passive_dwell = active_dwell + 1;
  1544. channel = iwl_get_single_channel_number(priv, band);
  1545. if (channel) {
  1546. scan_ch->channel = channel;
  1547. scan_ch->type = 0; /* passive */
  1548. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  1549. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  1550. /* Set txpower levels to defaults */
  1551. scan_ch->tpc.dsp_atten = 110;
  1552. if (band == IEEE80211_BAND_5GHZ)
  1553. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  1554. else
  1555. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  1556. added++;
  1557. } else
  1558. IWL_ERR(priv, "no valid channel found\n");
  1559. return added;
  1560. }
  1561. static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
  1562. enum ieee80211_band band,
  1563. u8 is_active, u8 n_probes,
  1564. struct iwl3945_scan_channel *scan_ch,
  1565. struct ieee80211_vif *vif)
  1566. {
  1567. struct ieee80211_channel *chan;
  1568. const struct ieee80211_supported_band *sband;
  1569. const struct iwl_channel_info *ch_info;
  1570. u16 passive_dwell = 0;
  1571. u16 active_dwell = 0;
  1572. int added, i;
  1573. sband = iwl_get_hw_mode(priv, band);
  1574. if (!sband)
  1575. return 0;
  1576. active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
  1577. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  1578. if (passive_dwell <= active_dwell)
  1579. passive_dwell = active_dwell + 1;
  1580. for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
  1581. chan = priv->scan_request->channels[i];
  1582. if (chan->band != band)
  1583. continue;
  1584. scan_ch->channel = chan->hw_value;
  1585. ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
  1586. if (!is_channel_valid(ch_info)) {
  1587. IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
  1588. scan_ch->channel);
  1589. continue;
  1590. }
  1591. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  1592. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  1593. /* If passive , set up for auto-switch
  1594. * and use long active_dwell time.
  1595. */
  1596. if (!is_active || is_channel_passive(ch_info) ||
  1597. (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
  1598. scan_ch->type = 0; /* passive */
  1599. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  1600. scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
  1601. } else {
  1602. scan_ch->type = 1; /* active */
  1603. }
  1604. /* Set direct probe bits. These may be used both for active
  1605. * scan channels (probes gets sent right away),
  1606. * or for passive channels (probes get se sent only after
  1607. * hearing clear Rx packet).*/
  1608. if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
  1609. if (n_probes)
  1610. scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
  1611. } else {
  1612. /* uCode v1 does not allow setting direct probe bits on
  1613. * passive channel. */
  1614. if ((scan_ch->type & 1) && n_probes)
  1615. scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
  1616. }
  1617. /* Set txpower levels to defaults */
  1618. scan_ch->tpc.dsp_atten = 110;
  1619. /* scan_pwr_info->tpc.dsp_atten; */
  1620. /*scan_pwr_info->tpc.tx_gain; */
  1621. if (band == IEEE80211_BAND_5GHZ)
  1622. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  1623. else {
  1624. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  1625. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  1626. * power level:
  1627. * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
  1628. */
  1629. }
  1630. IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
  1631. scan_ch->channel,
  1632. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  1633. (scan_ch->type & 1) ?
  1634. active_dwell : passive_dwell);
  1635. scan_ch++;
  1636. added++;
  1637. }
  1638. IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
  1639. return added;
  1640. }
  1641. static void iwl3945_init_hw_rates(struct iwl_priv *priv,
  1642. struct ieee80211_rate *rates)
  1643. {
  1644. int i;
  1645. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  1646. rates[i].bitrate = iwl3945_rates[i].ieee * 5;
  1647. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  1648. rates[i].hw_value_short = i;
  1649. rates[i].flags = 0;
  1650. if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  1651. /*
  1652. * If CCK != 1M then set short preamble rate flag.
  1653. */
  1654. rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
  1655. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  1656. }
  1657. }
  1658. }
  1659. /******************************************************************************
  1660. *
  1661. * uCode download functions
  1662. *
  1663. ******************************************************************************/
  1664. static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
  1665. {
  1666. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  1667. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  1668. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1669. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  1670. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1671. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1672. }
  1673. /**
  1674. * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
  1675. * looking at all data.
  1676. */
  1677. static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
  1678. {
  1679. u32 val;
  1680. u32 save_len = len;
  1681. int rc = 0;
  1682. u32 errcnt;
  1683. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  1684. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  1685. IWL39_RTC_INST_LOWER_BOUND);
  1686. errcnt = 0;
  1687. for (; len > 0; len -= sizeof(u32), image++) {
  1688. /* read data comes through single port, auto-incr addr */
  1689. /* NOTE: Use the debugless read so we don't flood kernel log
  1690. * if IWL_DL_IO is set */
  1691. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1692. if (val != le32_to_cpu(*image)) {
  1693. IWL_ERR(priv, "uCode INST section is invalid at "
  1694. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  1695. save_len - len, val, le32_to_cpu(*image));
  1696. rc = -EIO;
  1697. errcnt++;
  1698. if (errcnt >= 20)
  1699. break;
  1700. }
  1701. }
  1702. if (!errcnt)
  1703. IWL_DEBUG_INFO(priv,
  1704. "ucode image in INSTRUCTION memory is good\n");
  1705. return rc;
  1706. }
  1707. /**
  1708. * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
  1709. * using sample data 100 bytes apart. If these sample points are good,
  1710. * it's a pretty good bet that everything between them is good, too.
  1711. */
  1712. static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  1713. {
  1714. u32 val;
  1715. int rc = 0;
  1716. u32 errcnt = 0;
  1717. u32 i;
  1718. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  1719. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  1720. /* read data comes through single port, auto-incr addr */
  1721. /* NOTE: Use the debugless read so we don't flood kernel log
  1722. * if IWL_DL_IO is set */
  1723. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  1724. i + IWL39_RTC_INST_LOWER_BOUND);
  1725. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1726. if (val != le32_to_cpu(*image)) {
  1727. #if 0 /* Enable this if you want to see details */
  1728. IWL_ERR(priv, "uCode INST section is invalid at "
  1729. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  1730. i, val, *image);
  1731. #endif
  1732. rc = -EIO;
  1733. errcnt++;
  1734. if (errcnt >= 3)
  1735. break;
  1736. }
  1737. }
  1738. return rc;
  1739. }
  1740. /**
  1741. * iwl3945_verify_ucode - determine which instruction image is in SRAM,
  1742. * and verify its contents
  1743. */
  1744. static int iwl3945_verify_ucode(struct iwl_priv *priv)
  1745. {
  1746. __le32 *image;
  1747. u32 len;
  1748. int rc = 0;
  1749. /* Try bootstrap */
  1750. image = (__le32 *)priv->ucode_boot.v_addr;
  1751. len = priv->ucode_boot.len;
  1752. rc = iwl3945_verify_inst_sparse(priv, image, len);
  1753. if (rc == 0) {
  1754. IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
  1755. return 0;
  1756. }
  1757. /* Try initialize */
  1758. image = (__le32 *)priv->ucode_init.v_addr;
  1759. len = priv->ucode_init.len;
  1760. rc = iwl3945_verify_inst_sparse(priv, image, len);
  1761. if (rc == 0) {
  1762. IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
  1763. return 0;
  1764. }
  1765. /* Try runtime/protocol */
  1766. image = (__le32 *)priv->ucode_code.v_addr;
  1767. len = priv->ucode_code.len;
  1768. rc = iwl3945_verify_inst_sparse(priv, image, len);
  1769. if (rc == 0) {
  1770. IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
  1771. return 0;
  1772. }
  1773. IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  1774. /* Since nothing seems to match, show first several data entries in
  1775. * instruction SRAM, so maybe visual inspection will give a clue.
  1776. * Selection of bootstrap image (vs. other images) is arbitrary. */
  1777. image = (__le32 *)priv->ucode_boot.v_addr;
  1778. len = priv->ucode_boot.len;
  1779. rc = iwl3945_verify_inst_full(priv, image, len);
  1780. return rc;
  1781. }
  1782. static void iwl3945_nic_start(struct iwl_priv *priv)
  1783. {
  1784. /* Remove all resets to allow NIC to operate */
  1785. iwl_write32(priv, CSR_RESET, 0);
  1786. }
  1787. #define IWL3945_UCODE_GET(item) \
  1788. static u32 iwl3945_ucode_get_##item(const struct iwl_ucode_header *ucode)\
  1789. { \
  1790. return le32_to_cpu(ucode->u.v1.item); \
  1791. }
  1792. static u32 iwl3945_ucode_get_header_size(u32 api_ver)
  1793. {
  1794. return 24;
  1795. }
  1796. static u8 *iwl3945_ucode_get_data(const struct iwl_ucode_header *ucode)
  1797. {
  1798. return (u8 *) ucode->u.v1.data;
  1799. }
  1800. IWL3945_UCODE_GET(inst_size);
  1801. IWL3945_UCODE_GET(data_size);
  1802. IWL3945_UCODE_GET(init_size);
  1803. IWL3945_UCODE_GET(init_data_size);
  1804. IWL3945_UCODE_GET(boot_size);
  1805. /**
  1806. * iwl3945_read_ucode - Read uCode images from disk file.
  1807. *
  1808. * Copy into buffers for card to fetch via bus-mastering
  1809. */
  1810. static int iwl3945_read_ucode(struct iwl_priv *priv)
  1811. {
  1812. const struct iwl_ucode_header *ucode;
  1813. int ret = -EINVAL, index;
  1814. const struct firmware *ucode_raw;
  1815. /* firmware file name contains uCode/driver compatibility version */
  1816. const char *name_pre = priv->cfg->fw_name_pre;
  1817. const unsigned int api_max = priv->cfg->ucode_api_max;
  1818. const unsigned int api_min = priv->cfg->ucode_api_min;
  1819. char buf[25];
  1820. u8 *src;
  1821. size_t len;
  1822. u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
  1823. /* Ask kernel firmware_class module to get the boot firmware off disk.
  1824. * request_firmware() is synchronous, file is in memory on return. */
  1825. for (index = api_max; index >= api_min; index--) {
  1826. sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
  1827. ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
  1828. if (ret < 0) {
  1829. IWL_ERR(priv, "%s firmware file req failed: %d\n",
  1830. buf, ret);
  1831. if (ret == -ENOENT)
  1832. continue;
  1833. else
  1834. goto error;
  1835. } else {
  1836. if (index < api_max)
  1837. IWL_ERR(priv, "Loaded firmware %s, "
  1838. "which is deprecated. "
  1839. " Please use API v%u instead.\n",
  1840. buf, api_max);
  1841. IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
  1842. "(%zd bytes) from disk\n",
  1843. buf, ucode_raw->size);
  1844. break;
  1845. }
  1846. }
  1847. if (ret < 0)
  1848. goto error;
  1849. /* Make sure that we got at least our header! */
  1850. if (ucode_raw->size < iwl3945_ucode_get_header_size(1)) {
  1851. IWL_ERR(priv, "File size way too small!\n");
  1852. ret = -EINVAL;
  1853. goto err_release;
  1854. }
  1855. /* Data from ucode file: header followed by uCode images */
  1856. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  1857. priv->ucode_ver = le32_to_cpu(ucode->ver);
  1858. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1859. inst_size = iwl3945_ucode_get_inst_size(ucode);
  1860. data_size = iwl3945_ucode_get_data_size(ucode);
  1861. init_size = iwl3945_ucode_get_init_size(ucode);
  1862. init_data_size = iwl3945_ucode_get_init_data_size(ucode);
  1863. boot_size = iwl3945_ucode_get_boot_size(ucode);
  1864. src = iwl3945_ucode_get_data(ucode);
  1865. /* api_ver should match the api version forming part of the
  1866. * firmware filename ... but we don't check for that and only rely
  1867. * on the API version read from firmware header from here on forward */
  1868. if (api_ver < api_min || api_ver > api_max) {
  1869. IWL_ERR(priv, "Driver unable to support your firmware API. "
  1870. "Driver supports v%u, firmware is v%u.\n",
  1871. api_max, api_ver);
  1872. priv->ucode_ver = 0;
  1873. ret = -EINVAL;
  1874. goto err_release;
  1875. }
  1876. if (api_ver != api_max)
  1877. IWL_ERR(priv, "Firmware has old API version. Expected %u, "
  1878. "got %u. New firmware can be obtained "
  1879. "from http://www.intellinuxwireless.org.\n",
  1880. api_max, api_ver);
  1881. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
  1882. IWL_UCODE_MAJOR(priv->ucode_ver),
  1883. IWL_UCODE_MINOR(priv->ucode_ver),
  1884. IWL_UCODE_API(priv->ucode_ver),
  1885. IWL_UCODE_SERIAL(priv->ucode_ver));
  1886. snprintf(priv->hw->wiphy->fw_version,
  1887. sizeof(priv->hw->wiphy->fw_version),
  1888. "%u.%u.%u.%u",
  1889. IWL_UCODE_MAJOR(priv->ucode_ver),
  1890. IWL_UCODE_MINOR(priv->ucode_ver),
  1891. IWL_UCODE_API(priv->ucode_ver),
  1892. IWL_UCODE_SERIAL(priv->ucode_ver));
  1893. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  1894. priv->ucode_ver);
  1895. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
  1896. inst_size);
  1897. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
  1898. data_size);
  1899. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
  1900. init_size);
  1901. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
  1902. init_data_size);
  1903. IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
  1904. boot_size);
  1905. /* Verify size of file vs. image size info in file's header */
  1906. if (ucode_raw->size != iwl3945_ucode_get_header_size(api_ver) +
  1907. inst_size + data_size + init_size +
  1908. init_data_size + boot_size) {
  1909. IWL_DEBUG_INFO(priv,
  1910. "uCode file size %zd does not match expected size\n",
  1911. ucode_raw->size);
  1912. ret = -EINVAL;
  1913. goto err_release;
  1914. }
  1915. /* Verify that uCode images will fit in card's SRAM */
  1916. if (inst_size > IWL39_MAX_INST_SIZE) {
  1917. IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
  1918. inst_size);
  1919. ret = -EINVAL;
  1920. goto err_release;
  1921. }
  1922. if (data_size > IWL39_MAX_DATA_SIZE) {
  1923. IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
  1924. data_size);
  1925. ret = -EINVAL;
  1926. goto err_release;
  1927. }
  1928. if (init_size > IWL39_MAX_INST_SIZE) {
  1929. IWL_DEBUG_INFO(priv,
  1930. "uCode init instr len %d too large to fit in\n",
  1931. init_size);
  1932. ret = -EINVAL;
  1933. goto err_release;
  1934. }
  1935. if (init_data_size > IWL39_MAX_DATA_SIZE) {
  1936. IWL_DEBUG_INFO(priv,
  1937. "uCode init data len %d too large to fit in\n",
  1938. init_data_size);
  1939. ret = -EINVAL;
  1940. goto err_release;
  1941. }
  1942. if (boot_size > IWL39_MAX_BSM_SIZE) {
  1943. IWL_DEBUG_INFO(priv,
  1944. "uCode boot instr len %d too large to fit in\n",
  1945. boot_size);
  1946. ret = -EINVAL;
  1947. goto err_release;
  1948. }
  1949. /* Allocate ucode buffers for card's bus-master loading ... */
  1950. /* Runtime instructions and 2 copies of data:
  1951. * 1) unmodified from disk
  1952. * 2) backup cache for save/restore during power-downs */
  1953. priv->ucode_code.len = inst_size;
  1954. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  1955. priv->ucode_data.len = data_size;
  1956. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  1957. priv->ucode_data_backup.len = data_size;
  1958. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1959. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  1960. !priv->ucode_data_backup.v_addr)
  1961. goto err_pci_alloc;
  1962. /* Initialization instructions and data */
  1963. if (init_size && init_data_size) {
  1964. priv->ucode_init.len = init_size;
  1965. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  1966. priv->ucode_init_data.len = init_data_size;
  1967. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1968. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  1969. goto err_pci_alloc;
  1970. }
  1971. /* Bootstrap (instructions only, no data) */
  1972. if (boot_size) {
  1973. priv->ucode_boot.len = boot_size;
  1974. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1975. if (!priv->ucode_boot.v_addr)
  1976. goto err_pci_alloc;
  1977. }
  1978. /* Copy images into buffers for card's bus-master reads ... */
  1979. /* Runtime instructions (first block of data in file) */
  1980. len = inst_size;
  1981. IWL_DEBUG_INFO(priv,
  1982. "Copying (but not loading) uCode instr len %zd\n", len);
  1983. memcpy(priv->ucode_code.v_addr, src, len);
  1984. src += len;
  1985. IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  1986. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  1987. /* Runtime data (2nd block)
  1988. * NOTE: Copy into backup buffer will be done in iwl3945_up() */
  1989. len = data_size;
  1990. IWL_DEBUG_INFO(priv,
  1991. "Copying (but not loading) uCode data len %zd\n", len);
  1992. memcpy(priv->ucode_data.v_addr, src, len);
  1993. memcpy(priv->ucode_data_backup.v_addr, src, len);
  1994. src += len;
  1995. /* Initialization instructions (3rd block) */
  1996. if (init_size) {
  1997. len = init_size;
  1998. IWL_DEBUG_INFO(priv,
  1999. "Copying (but not loading) init instr len %zd\n", len);
  2000. memcpy(priv->ucode_init.v_addr, src, len);
  2001. src += len;
  2002. }
  2003. /* Initialization data (4th block) */
  2004. if (init_data_size) {
  2005. len = init_data_size;
  2006. IWL_DEBUG_INFO(priv,
  2007. "Copying (but not loading) init data len %zd\n", len);
  2008. memcpy(priv->ucode_init_data.v_addr, src, len);
  2009. src += len;
  2010. }
  2011. /* Bootstrap instructions (5th block) */
  2012. len = boot_size;
  2013. IWL_DEBUG_INFO(priv,
  2014. "Copying (but not loading) boot instr len %zd\n", len);
  2015. memcpy(priv->ucode_boot.v_addr, src, len);
  2016. /* We have our copies now, allow OS release its copies */
  2017. release_firmware(ucode_raw);
  2018. return 0;
  2019. err_pci_alloc:
  2020. IWL_ERR(priv, "failed to allocate pci memory\n");
  2021. ret = -ENOMEM;
  2022. iwl3945_dealloc_ucode_pci(priv);
  2023. err_release:
  2024. release_firmware(ucode_raw);
  2025. error:
  2026. return ret;
  2027. }
  2028. /**
  2029. * iwl3945_set_ucode_ptrs - Set uCode address location
  2030. *
  2031. * Tell initialization uCode where to find runtime uCode.
  2032. *
  2033. * BSM registers initially contain pointers to initialization uCode.
  2034. * We need to replace them to load runtime uCode inst and data,
  2035. * and to save runtime data when powering down.
  2036. */
  2037. static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
  2038. {
  2039. dma_addr_t pinst;
  2040. dma_addr_t pdata;
  2041. /* bits 31:0 for 3945 */
  2042. pinst = priv->ucode_code.p_addr;
  2043. pdata = priv->ucode_data_backup.p_addr;
  2044. /* Tell bootstrap uCode where to find image to load */
  2045. iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  2046. iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  2047. iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
  2048. priv->ucode_data.len);
  2049. /* Inst byte count must be last to set up, bit 31 signals uCode
  2050. * that all new ptr/size info is in place */
  2051. iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
  2052. priv->ucode_code.len | BSM_DRAM_INST_LOAD);
  2053. IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
  2054. return 0;
  2055. }
  2056. /**
  2057. * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
  2058. *
  2059. * Called after REPLY_ALIVE notification received from "initialize" uCode.
  2060. *
  2061. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  2062. */
  2063. static void iwl3945_init_alive_start(struct iwl_priv *priv)
  2064. {
  2065. /* Check alive response for "valid" sign from uCode */
  2066. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  2067. /* We had an error bringing up the hardware, so take it
  2068. * all the way back down so we can try again */
  2069. IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
  2070. goto restart;
  2071. }
  2072. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  2073. * This is a paranoid check, because we would not have gotten the
  2074. * "initialize" alive if code weren't properly loaded. */
  2075. if (iwl3945_verify_ucode(priv)) {
  2076. /* Runtime instruction load was bad;
  2077. * take it all the way back down so we can try again */
  2078. IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
  2079. goto restart;
  2080. }
  2081. /* Send pointers to protocol/runtime uCode image ... init code will
  2082. * load and launch runtime uCode, which will send us another "Alive"
  2083. * notification. */
  2084. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  2085. if (iwl3945_set_ucode_ptrs(priv)) {
  2086. /* Runtime instruction load won't happen;
  2087. * take it all the way back down so we can try again */
  2088. IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
  2089. goto restart;
  2090. }
  2091. return;
  2092. restart:
  2093. queue_work(priv->workqueue, &priv->restart);
  2094. }
  2095. /**
  2096. * iwl3945_alive_start - called after REPLY_ALIVE notification received
  2097. * from protocol/runtime uCode (initialization uCode's
  2098. * Alive gets handled by iwl3945_init_alive_start()).
  2099. */
  2100. static void iwl3945_alive_start(struct iwl_priv *priv)
  2101. {
  2102. int thermal_spin = 0;
  2103. u32 rfkill;
  2104. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2105. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  2106. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  2107. /* We had an error bringing up the hardware, so take it
  2108. * all the way back down so we can try again */
  2109. IWL_DEBUG_INFO(priv, "Alive failed.\n");
  2110. goto restart;
  2111. }
  2112. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  2113. * This is a paranoid check, because we would not have gotten the
  2114. * "runtime" alive if code weren't properly loaded. */
  2115. if (iwl3945_verify_ucode(priv)) {
  2116. /* Runtime instruction load was bad;
  2117. * take it all the way back down so we can try again */
  2118. IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
  2119. goto restart;
  2120. }
  2121. rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
  2122. IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
  2123. if (rfkill & 0x1) {
  2124. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2125. /* if RFKILL is not on, then wait for thermal
  2126. * sensor in adapter to kick in */
  2127. while (iwl3945_hw_get_temperature(priv) == 0) {
  2128. thermal_spin++;
  2129. udelay(10);
  2130. }
  2131. if (thermal_spin)
  2132. IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
  2133. thermal_spin * 10);
  2134. } else
  2135. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2136. /* After the ALIVE response, we can send commands to 3945 uCode */
  2137. set_bit(STATUS_ALIVE, &priv->status);
  2138. if (priv->cfg->ops->lib->recover_from_tx_stall) {
  2139. /* Enable timer to monitor the driver queues */
  2140. mod_timer(&priv->monitor_recover,
  2141. jiffies +
  2142. msecs_to_jiffies(priv->cfg->monitor_recover_period));
  2143. }
  2144. if (iwl_is_rfkill(priv))
  2145. return;
  2146. ieee80211_wake_queues(priv->hw);
  2147. priv->active_rate = IWL_RATES_MASK;
  2148. iwl_power_update_mode(priv, true);
  2149. if (iwl_is_associated(priv, IWL_RXON_CTX_BSS)) {
  2150. struct iwl3945_rxon_cmd *active_rxon =
  2151. (struct iwl3945_rxon_cmd *)(&ctx->active);
  2152. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2153. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2154. } else {
  2155. /* Initialize our rx_config data */
  2156. iwl_connection_init_rx_config(priv, ctx);
  2157. }
  2158. /* Configure Bluetooth device coexistence support */
  2159. priv->cfg->ops->hcmd->send_bt_config(priv);
  2160. /* Configure the adapter for unassociated operation */
  2161. iwlcore_commit_rxon(priv, ctx);
  2162. iwl3945_reg_txpower_periodic(priv);
  2163. iwl_leds_init(priv);
  2164. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  2165. set_bit(STATUS_READY, &priv->status);
  2166. wake_up_interruptible(&priv->wait_command_queue);
  2167. return;
  2168. restart:
  2169. queue_work(priv->workqueue, &priv->restart);
  2170. }
  2171. static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
  2172. static void __iwl3945_down(struct iwl_priv *priv)
  2173. {
  2174. unsigned long flags;
  2175. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  2176. struct ieee80211_conf *conf = NULL;
  2177. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  2178. conf = ieee80211_get_hw_conf(priv->hw);
  2179. if (!exit_pending)
  2180. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2181. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  2182. * to prevent rearm timer */
  2183. if (priv->cfg->ops->lib->recover_from_tx_stall)
  2184. del_timer_sync(&priv->monitor_recover);
  2185. /* Station information will now be cleared in device */
  2186. iwl_clear_ucode_stations(priv, NULL);
  2187. iwl_dealloc_bcast_stations(priv);
  2188. iwl_clear_driver_stations(priv);
  2189. /* Unblock any waiting calls */
  2190. wake_up_interruptible_all(&priv->wait_command_queue);
  2191. /* Wipe out the EXIT_PENDING status bit if we are not actually
  2192. * exiting the module */
  2193. if (!exit_pending)
  2194. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2195. /* stop and reset the on-board processor */
  2196. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2197. /* tell the device to stop sending interrupts */
  2198. spin_lock_irqsave(&priv->lock, flags);
  2199. iwl_disable_interrupts(priv);
  2200. spin_unlock_irqrestore(&priv->lock, flags);
  2201. iwl_synchronize_irq(priv);
  2202. if (priv->mac80211_registered)
  2203. ieee80211_stop_queues(priv->hw);
  2204. /* If we have not previously called iwl3945_init() then
  2205. * clear all bits but the RF Kill bits and return */
  2206. if (!iwl_is_init(priv)) {
  2207. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2208. STATUS_RF_KILL_HW |
  2209. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2210. STATUS_GEO_CONFIGURED |
  2211. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2212. STATUS_EXIT_PENDING;
  2213. goto exit;
  2214. }
  2215. /* ...otherwise clear out all the status bits but the RF Kill
  2216. * bit and continue taking the NIC down. */
  2217. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2218. STATUS_RF_KILL_HW |
  2219. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2220. STATUS_GEO_CONFIGURED |
  2221. test_bit(STATUS_FW_ERROR, &priv->status) <<
  2222. STATUS_FW_ERROR |
  2223. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2224. STATUS_EXIT_PENDING;
  2225. iwl3945_hw_txq_ctx_stop(priv);
  2226. iwl3945_hw_rxq_stop(priv);
  2227. /* Power-down device's busmaster DMA clocks */
  2228. iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  2229. udelay(5);
  2230. /* Stop the device, and put it in low power state */
  2231. priv->cfg->ops->lib->apm_ops.stop(priv);
  2232. exit:
  2233. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  2234. if (priv->ibss_beacon)
  2235. dev_kfree_skb(priv->ibss_beacon);
  2236. priv->ibss_beacon = NULL;
  2237. /* clear out any free frames */
  2238. iwl3945_clear_free_frames(priv);
  2239. }
  2240. static void iwl3945_down(struct iwl_priv *priv)
  2241. {
  2242. mutex_lock(&priv->mutex);
  2243. __iwl3945_down(priv);
  2244. mutex_unlock(&priv->mutex);
  2245. iwl3945_cancel_deferred_work(priv);
  2246. }
  2247. #define MAX_HW_RESTARTS 5
  2248. static int __iwl3945_up(struct iwl_priv *priv)
  2249. {
  2250. int rc, i;
  2251. rc = iwl_alloc_bcast_station(priv, &priv->contexts[IWL_RXON_CTX_BSS],
  2252. false);
  2253. if (rc)
  2254. return rc;
  2255. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2256. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  2257. return -EIO;
  2258. }
  2259. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  2260. IWL_ERR(priv, "ucode not available for device bring up\n");
  2261. return -EIO;
  2262. }
  2263. /* If platform's RF_KILL switch is NOT set to KILL */
  2264. if (iwl_read32(priv, CSR_GP_CNTRL) &
  2265. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2266. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2267. else {
  2268. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2269. IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
  2270. return -ENODEV;
  2271. }
  2272. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2273. rc = iwl3945_hw_nic_init(priv);
  2274. if (rc) {
  2275. IWL_ERR(priv, "Unable to int nic\n");
  2276. return rc;
  2277. }
  2278. /* make sure rfkill handshake bits are cleared */
  2279. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2280. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2281. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2282. /* clear (again), then enable host interrupts */
  2283. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2284. iwl_enable_interrupts(priv);
  2285. /* really make sure rfkill handshake bits are cleared */
  2286. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2287. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2288. /* Copy original ucode data image from disk into backup cache.
  2289. * This will be used to initialize the on-board processor's
  2290. * data SRAM for a clean start when the runtime program first loads. */
  2291. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  2292. priv->ucode_data.len);
  2293. /* We return success when we resume from suspend and rf_kill is on. */
  2294. if (test_bit(STATUS_RF_KILL_HW, &priv->status))
  2295. return 0;
  2296. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  2297. /* load bootstrap state machine,
  2298. * load bootstrap program into processor's memory,
  2299. * prepare to load the "initialize" uCode */
  2300. rc = priv->cfg->ops->lib->load_ucode(priv);
  2301. if (rc) {
  2302. IWL_ERR(priv,
  2303. "Unable to set up bootstrap uCode: %d\n", rc);
  2304. continue;
  2305. }
  2306. /* start card; "initialize" will load runtime ucode */
  2307. iwl3945_nic_start(priv);
  2308. IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
  2309. return 0;
  2310. }
  2311. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2312. __iwl3945_down(priv);
  2313. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2314. /* tried to restart and config the device for as long as our
  2315. * patience could withstand */
  2316. IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
  2317. return -EIO;
  2318. }
  2319. /*****************************************************************************
  2320. *
  2321. * Workqueue callbacks
  2322. *
  2323. *****************************************************************************/
  2324. static void iwl3945_bg_init_alive_start(struct work_struct *data)
  2325. {
  2326. struct iwl_priv *priv =
  2327. container_of(data, struct iwl_priv, init_alive_start.work);
  2328. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2329. return;
  2330. mutex_lock(&priv->mutex);
  2331. iwl3945_init_alive_start(priv);
  2332. mutex_unlock(&priv->mutex);
  2333. }
  2334. static void iwl3945_bg_alive_start(struct work_struct *data)
  2335. {
  2336. struct iwl_priv *priv =
  2337. container_of(data, struct iwl_priv, alive_start.work);
  2338. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2339. return;
  2340. mutex_lock(&priv->mutex);
  2341. iwl3945_alive_start(priv);
  2342. mutex_unlock(&priv->mutex);
  2343. }
  2344. /*
  2345. * 3945 cannot interrupt driver when hardware rf kill switch toggles;
  2346. * driver must poll CSR_GP_CNTRL_REG register for change. This register
  2347. * *is* readable even when device has been SW_RESET into low power mode
  2348. * (e.g. during RF KILL).
  2349. */
  2350. static void iwl3945_rfkill_poll(struct work_struct *data)
  2351. {
  2352. struct iwl_priv *priv =
  2353. container_of(data, struct iwl_priv, _3945.rfkill_poll.work);
  2354. bool old_rfkill = test_bit(STATUS_RF_KILL_HW, &priv->status);
  2355. bool new_rfkill = !(iwl_read32(priv, CSR_GP_CNTRL)
  2356. & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW);
  2357. if (new_rfkill != old_rfkill) {
  2358. if (new_rfkill)
  2359. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2360. else
  2361. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2362. wiphy_rfkill_set_hw_state(priv->hw->wiphy, new_rfkill);
  2363. IWL_DEBUG_RF_KILL(priv, "RF_KILL bit toggled to %s.\n",
  2364. new_rfkill ? "disable radio" : "enable radio");
  2365. }
  2366. /* Keep this running, even if radio now enabled. This will be
  2367. * cancelled in mac_start() if system decides to start again */
  2368. queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll,
  2369. round_jiffies_relative(2 * HZ));
  2370. }
  2371. void iwl3945_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
  2372. {
  2373. struct iwl_host_cmd cmd = {
  2374. .id = REPLY_SCAN_CMD,
  2375. .len = sizeof(struct iwl3945_scan_cmd),
  2376. .flags = CMD_SIZE_HUGE,
  2377. };
  2378. struct iwl3945_scan_cmd *scan;
  2379. struct ieee80211_conf *conf = NULL;
  2380. u8 n_probes = 0;
  2381. enum ieee80211_band band;
  2382. bool is_active = false;
  2383. conf = ieee80211_get_hw_conf(priv->hw);
  2384. cancel_delayed_work(&priv->scan_check);
  2385. if (!iwl_is_ready(priv)) {
  2386. IWL_WARN(priv, "request scan called when driver not ready.\n");
  2387. goto done;
  2388. }
  2389. /* Make sure the scan wasn't canceled before this queued work
  2390. * was given the chance to run... */
  2391. if (!test_bit(STATUS_SCANNING, &priv->status))
  2392. goto done;
  2393. /* This should never be called or scheduled if there is currently
  2394. * a scan active in the hardware. */
  2395. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  2396. IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
  2397. "Ignoring second request.\n");
  2398. goto done;
  2399. }
  2400. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2401. IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
  2402. goto done;
  2403. }
  2404. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2405. IWL_DEBUG_HC(priv,
  2406. "Scan request while abort pending. Queuing.\n");
  2407. goto done;
  2408. }
  2409. if (iwl_is_rfkill(priv)) {
  2410. IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
  2411. goto done;
  2412. }
  2413. if (!test_bit(STATUS_READY, &priv->status)) {
  2414. IWL_DEBUG_HC(priv,
  2415. "Scan request while uninitialized. Queuing.\n");
  2416. goto done;
  2417. }
  2418. if (!priv->scan_cmd) {
  2419. priv->scan_cmd = kmalloc(sizeof(struct iwl3945_scan_cmd) +
  2420. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  2421. if (!priv->scan_cmd) {
  2422. IWL_DEBUG_SCAN(priv, "Fail to allocate scan memory\n");
  2423. goto done;
  2424. }
  2425. }
  2426. scan = priv->scan_cmd;
  2427. memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
  2428. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  2429. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  2430. if (iwl_is_associated(priv, IWL_RXON_CTX_BSS)) {
  2431. u16 interval = 0;
  2432. u32 extra;
  2433. u32 suspend_time = 100;
  2434. u32 scan_suspend_time = 100;
  2435. unsigned long flags;
  2436. IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
  2437. spin_lock_irqsave(&priv->lock, flags);
  2438. if (priv->is_internal_short_scan)
  2439. interval = 0;
  2440. else
  2441. interval = vif->bss_conf.beacon_int;
  2442. spin_unlock_irqrestore(&priv->lock, flags);
  2443. scan->suspend_time = 0;
  2444. scan->max_out_time = cpu_to_le32(200 * 1024);
  2445. if (!interval)
  2446. interval = suspend_time;
  2447. /*
  2448. * suspend time format:
  2449. * 0-19: beacon interval in usec (time before exec.)
  2450. * 20-23: 0
  2451. * 24-31: number of beacons (suspend between channels)
  2452. */
  2453. extra = (suspend_time / interval) << 24;
  2454. scan_suspend_time = 0xFF0FFFFF &
  2455. (extra | ((suspend_time % interval) * 1024));
  2456. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  2457. IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
  2458. scan_suspend_time, interval);
  2459. }
  2460. if (priv->is_internal_short_scan) {
  2461. IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
  2462. } else if (priv->scan_request->n_ssids) {
  2463. int i, p = 0;
  2464. IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
  2465. for (i = 0; i < priv->scan_request->n_ssids; i++) {
  2466. /* always does wildcard anyway */
  2467. if (!priv->scan_request->ssids[i].ssid_len)
  2468. continue;
  2469. scan->direct_scan[p].id = WLAN_EID_SSID;
  2470. scan->direct_scan[p].len =
  2471. priv->scan_request->ssids[i].ssid_len;
  2472. memcpy(scan->direct_scan[p].ssid,
  2473. priv->scan_request->ssids[i].ssid,
  2474. priv->scan_request->ssids[i].ssid_len);
  2475. n_probes++;
  2476. p++;
  2477. }
  2478. is_active = true;
  2479. } else
  2480. IWL_DEBUG_SCAN(priv, "Kicking off passive scan.\n");
  2481. /* We don't build a direct scan probe request; the uCode will do
  2482. * that based on the direct_mask added to each channel entry */
  2483. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  2484. scan->tx_cmd.sta_id = priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id;
  2485. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2486. /* flags + rate selection */
  2487. switch (priv->scan_band) {
  2488. case IEEE80211_BAND_2GHZ:
  2489. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  2490. scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
  2491. scan->good_CRC_th = 0;
  2492. band = IEEE80211_BAND_2GHZ;
  2493. break;
  2494. case IEEE80211_BAND_5GHZ:
  2495. scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
  2496. /*
  2497. * If active scaning is requested but a certain channel
  2498. * is marked passive, we can do active scanning if we
  2499. * detect transmissions.
  2500. */
  2501. scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
  2502. IWL_GOOD_CRC_TH_DISABLED;
  2503. band = IEEE80211_BAND_5GHZ;
  2504. break;
  2505. default:
  2506. IWL_WARN(priv, "Invalid scan band\n");
  2507. goto done;
  2508. }
  2509. if (!priv->is_internal_short_scan) {
  2510. scan->tx_cmd.len = cpu_to_le16(
  2511. iwl_fill_probe_req(priv,
  2512. (struct ieee80211_mgmt *)scan->data,
  2513. vif->addr,
  2514. priv->scan_request->ie,
  2515. priv->scan_request->ie_len,
  2516. IWL_MAX_SCAN_SIZE - sizeof(*scan)));
  2517. } else {
  2518. /* use bcast addr, will not be transmitted but must be valid */
  2519. scan->tx_cmd.len = cpu_to_le16(
  2520. iwl_fill_probe_req(priv,
  2521. (struct ieee80211_mgmt *)scan->data,
  2522. iwl_bcast_addr, NULL, 0,
  2523. IWL_MAX_SCAN_SIZE - sizeof(*scan)));
  2524. }
  2525. /* select Rx antennas */
  2526. scan->flags |= iwl3945_get_antenna_flags(priv);
  2527. if (priv->is_internal_short_scan) {
  2528. scan->channel_count =
  2529. iwl3945_get_single_channel_for_scan(priv, vif, band,
  2530. (void *)&scan->data[le16_to_cpu(
  2531. scan->tx_cmd.len)]);
  2532. } else {
  2533. scan->channel_count =
  2534. iwl3945_get_channels_for_scan(priv, band, is_active, n_probes,
  2535. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)], vif);
  2536. }
  2537. if (scan->channel_count == 0) {
  2538. IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
  2539. goto done;
  2540. }
  2541. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  2542. scan->channel_count * sizeof(struct iwl3945_scan_channel);
  2543. cmd.data = scan;
  2544. scan->len = cpu_to_le16(cmd.len);
  2545. set_bit(STATUS_SCAN_HW, &priv->status);
  2546. if (iwl_send_cmd_sync(priv, &cmd))
  2547. goto done;
  2548. queue_delayed_work(priv->workqueue, &priv->scan_check,
  2549. IWL_SCAN_CHECK_WATCHDOG);
  2550. return;
  2551. done:
  2552. /* can not perform scan make sure we clear scanning
  2553. * bits from status so next scan request can be performed.
  2554. * if we dont clear scanning status bit here all next scan
  2555. * will fail
  2556. */
  2557. clear_bit(STATUS_SCAN_HW, &priv->status);
  2558. clear_bit(STATUS_SCANNING, &priv->status);
  2559. /* inform mac80211 scan aborted */
  2560. queue_work(priv->workqueue, &priv->scan_completed);
  2561. }
  2562. static void iwl3945_bg_restart(struct work_struct *data)
  2563. {
  2564. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  2565. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2566. return;
  2567. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  2568. struct iwl_rxon_context *ctx;
  2569. mutex_lock(&priv->mutex);
  2570. for_each_context(priv, ctx)
  2571. ctx->vif = NULL;
  2572. priv->is_open = 0;
  2573. mutex_unlock(&priv->mutex);
  2574. iwl3945_down(priv);
  2575. ieee80211_restart_hw(priv->hw);
  2576. } else {
  2577. iwl3945_down(priv);
  2578. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2579. return;
  2580. mutex_lock(&priv->mutex);
  2581. __iwl3945_up(priv);
  2582. mutex_unlock(&priv->mutex);
  2583. }
  2584. }
  2585. static void iwl3945_bg_rx_replenish(struct work_struct *data)
  2586. {
  2587. struct iwl_priv *priv =
  2588. container_of(data, struct iwl_priv, rx_replenish);
  2589. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2590. return;
  2591. mutex_lock(&priv->mutex);
  2592. iwl3945_rx_replenish(priv);
  2593. mutex_unlock(&priv->mutex);
  2594. }
  2595. void iwl3945_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
  2596. {
  2597. int rc = 0;
  2598. struct ieee80211_conf *conf = NULL;
  2599. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2600. if (!vif || !priv->is_open)
  2601. return;
  2602. if (vif->type == NL80211_IFTYPE_AP) {
  2603. IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
  2604. return;
  2605. }
  2606. IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
  2607. vif->bss_conf.aid, ctx->active.bssid_addr);
  2608. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2609. return;
  2610. iwl_scan_cancel_timeout(priv, 200);
  2611. conf = ieee80211_get_hw_conf(priv->hw);
  2612. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2613. iwlcore_commit_rxon(priv, ctx);
  2614. rc = iwl_send_rxon_timing(priv, ctx);
  2615. if (rc)
  2616. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  2617. "Attempting to continue.\n");
  2618. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2619. ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  2620. IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
  2621. vif->bss_conf.aid, vif->bss_conf.beacon_int);
  2622. if (vif->bss_conf.use_short_preamble)
  2623. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2624. else
  2625. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2626. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
  2627. if (vif->bss_conf.use_short_slot)
  2628. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  2629. else
  2630. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2631. }
  2632. iwlcore_commit_rxon(priv, ctx);
  2633. switch (vif->type) {
  2634. case NL80211_IFTYPE_STATION:
  2635. iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
  2636. break;
  2637. case NL80211_IFTYPE_ADHOC:
  2638. iwl3945_send_beacon_cmd(priv);
  2639. break;
  2640. default:
  2641. IWL_ERR(priv, "%s Should not be called in %d mode\n",
  2642. __func__, vif->type);
  2643. break;
  2644. }
  2645. }
  2646. /*****************************************************************************
  2647. *
  2648. * mac80211 entry point functions
  2649. *
  2650. *****************************************************************************/
  2651. #define UCODE_READY_TIMEOUT (2 * HZ)
  2652. static int iwl3945_mac_start(struct ieee80211_hw *hw)
  2653. {
  2654. struct iwl_priv *priv = hw->priv;
  2655. int ret;
  2656. IWL_DEBUG_MAC80211(priv, "enter\n");
  2657. /* we should be verifying the device is ready to be opened */
  2658. mutex_lock(&priv->mutex);
  2659. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  2660. * ucode filename and max sizes are card-specific. */
  2661. if (!priv->ucode_code.len) {
  2662. ret = iwl3945_read_ucode(priv);
  2663. if (ret) {
  2664. IWL_ERR(priv, "Could not read microcode: %d\n", ret);
  2665. mutex_unlock(&priv->mutex);
  2666. goto out_release_irq;
  2667. }
  2668. }
  2669. ret = __iwl3945_up(priv);
  2670. mutex_unlock(&priv->mutex);
  2671. if (ret)
  2672. goto out_release_irq;
  2673. IWL_DEBUG_INFO(priv, "Start UP work.\n");
  2674. /* Wait for START_ALIVE from ucode. Otherwise callbacks from
  2675. * mac80211 will not be run successfully. */
  2676. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  2677. test_bit(STATUS_READY, &priv->status),
  2678. UCODE_READY_TIMEOUT);
  2679. if (!ret) {
  2680. if (!test_bit(STATUS_READY, &priv->status)) {
  2681. IWL_ERR(priv,
  2682. "Wait for START_ALIVE timeout after %dms.\n",
  2683. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  2684. ret = -ETIMEDOUT;
  2685. goto out_release_irq;
  2686. }
  2687. }
  2688. /* ucode is running and will send rfkill notifications,
  2689. * no need to poll the killswitch state anymore */
  2690. cancel_delayed_work(&priv->_3945.rfkill_poll);
  2691. iwl_led_start(priv);
  2692. priv->is_open = 1;
  2693. IWL_DEBUG_MAC80211(priv, "leave\n");
  2694. return 0;
  2695. out_release_irq:
  2696. priv->is_open = 0;
  2697. IWL_DEBUG_MAC80211(priv, "leave - failed\n");
  2698. return ret;
  2699. }
  2700. static void iwl3945_mac_stop(struct ieee80211_hw *hw)
  2701. {
  2702. struct iwl_priv *priv = hw->priv;
  2703. IWL_DEBUG_MAC80211(priv, "enter\n");
  2704. if (!priv->is_open) {
  2705. IWL_DEBUG_MAC80211(priv, "leave - skip\n");
  2706. return;
  2707. }
  2708. priv->is_open = 0;
  2709. if (iwl_is_ready_rf(priv)) {
  2710. /* stop mac, cancel any scan request and clear
  2711. * RXON_FILTER_ASSOC_MSK BIT
  2712. */
  2713. mutex_lock(&priv->mutex);
  2714. iwl_scan_cancel_timeout(priv, 100);
  2715. mutex_unlock(&priv->mutex);
  2716. }
  2717. iwl3945_down(priv);
  2718. flush_workqueue(priv->workqueue);
  2719. /* start polling the killswitch state again */
  2720. queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll,
  2721. round_jiffies_relative(2 * HZ));
  2722. IWL_DEBUG_MAC80211(priv, "leave\n");
  2723. }
  2724. static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2725. {
  2726. struct iwl_priv *priv = hw->priv;
  2727. IWL_DEBUG_MAC80211(priv, "enter\n");
  2728. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  2729. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  2730. if (iwl3945_tx_skb(priv, skb))
  2731. dev_kfree_skb_any(skb);
  2732. IWL_DEBUG_MAC80211(priv, "leave\n");
  2733. return NETDEV_TX_OK;
  2734. }
  2735. void iwl3945_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
  2736. {
  2737. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2738. int rc = 0;
  2739. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2740. return;
  2741. /* The following should be done only at AP bring up */
  2742. if (!(iwl_is_associated(priv, IWL_RXON_CTX_BSS))) {
  2743. /* RXON - unassoc (to set timing command) */
  2744. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2745. iwlcore_commit_rxon(priv, ctx);
  2746. /* RXON Timing */
  2747. rc = iwl_send_rxon_timing(priv, ctx);
  2748. if (rc)
  2749. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  2750. "Attempting to continue.\n");
  2751. ctx->staging.assoc_id = 0;
  2752. if (vif->bss_conf.use_short_preamble)
  2753. ctx->staging.flags |=
  2754. RXON_FLG_SHORT_PREAMBLE_MSK;
  2755. else
  2756. ctx->staging.flags &=
  2757. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2758. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
  2759. if (vif->bss_conf.use_short_slot)
  2760. ctx->staging.flags |=
  2761. RXON_FLG_SHORT_SLOT_MSK;
  2762. else
  2763. ctx->staging.flags &=
  2764. ~RXON_FLG_SHORT_SLOT_MSK;
  2765. }
  2766. /* restore RXON assoc */
  2767. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2768. iwlcore_commit_rxon(priv, ctx);
  2769. }
  2770. iwl3945_send_beacon_cmd(priv);
  2771. /* FIXME - we need to add code here to detect a totally new
  2772. * configuration, reset the AP, unassoc, rxon timing, assoc,
  2773. * clear sta table, add BCAST sta... */
  2774. }
  2775. static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2776. struct ieee80211_vif *vif,
  2777. struct ieee80211_sta *sta,
  2778. struct ieee80211_key_conf *key)
  2779. {
  2780. struct iwl_priv *priv = hw->priv;
  2781. int ret = 0;
  2782. u8 sta_id = IWL_INVALID_STATION;
  2783. u8 static_key;
  2784. IWL_DEBUG_MAC80211(priv, "enter\n");
  2785. if (iwl3945_mod_params.sw_crypto) {
  2786. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  2787. return -EOPNOTSUPP;
  2788. }
  2789. static_key = !iwl_is_associated(priv, IWL_RXON_CTX_BSS);
  2790. if (!static_key) {
  2791. sta_id = iwl_sta_id_or_broadcast(
  2792. priv, &priv->contexts[IWL_RXON_CTX_BSS], sta);
  2793. if (sta_id == IWL_INVALID_STATION)
  2794. return -EINVAL;
  2795. }
  2796. mutex_lock(&priv->mutex);
  2797. iwl_scan_cancel_timeout(priv, 100);
  2798. switch (cmd) {
  2799. case SET_KEY:
  2800. if (static_key)
  2801. ret = iwl3945_set_static_key(priv, key);
  2802. else
  2803. ret = iwl3945_set_dynamic_key(priv, key, sta_id);
  2804. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  2805. break;
  2806. case DISABLE_KEY:
  2807. if (static_key)
  2808. ret = iwl3945_remove_static_key(priv);
  2809. else
  2810. ret = iwl3945_clear_sta_key_info(priv, sta_id);
  2811. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  2812. break;
  2813. default:
  2814. ret = -EINVAL;
  2815. }
  2816. mutex_unlock(&priv->mutex);
  2817. IWL_DEBUG_MAC80211(priv, "leave\n");
  2818. return ret;
  2819. }
  2820. static int iwl3945_mac_sta_add(struct ieee80211_hw *hw,
  2821. struct ieee80211_vif *vif,
  2822. struct ieee80211_sta *sta)
  2823. {
  2824. struct iwl_priv *priv = hw->priv;
  2825. struct iwl3945_sta_priv *sta_priv = (void *)sta->drv_priv;
  2826. int ret;
  2827. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  2828. u8 sta_id;
  2829. IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
  2830. sta->addr);
  2831. mutex_lock(&priv->mutex);
  2832. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  2833. sta->addr);
  2834. sta_priv->common.sta_id = IWL_INVALID_STATION;
  2835. ret = iwl_add_station_common(priv, &priv->contexts[IWL_RXON_CTX_BSS],
  2836. sta->addr, is_ap, sta, &sta_id);
  2837. if (ret) {
  2838. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  2839. sta->addr, ret);
  2840. /* Should we return success if return code is EEXIST ? */
  2841. mutex_unlock(&priv->mutex);
  2842. return ret;
  2843. }
  2844. sta_priv->common.sta_id = sta_id;
  2845. /* Initialize rate scaling */
  2846. IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
  2847. sta->addr);
  2848. iwl3945_rs_rate_init(priv, sta, sta_id);
  2849. mutex_unlock(&priv->mutex);
  2850. return 0;
  2851. }
  2852. static void iwl3945_configure_filter(struct ieee80211_hw *hw,
  2853. unsigned int changed_flags,
  2854. unsigned int *total_flags,
  2855. u64 multicast)
  2856. {
  2857. struct iwl_priv *priv = hw->priv;
  2858. __le32 filter_or = 0, filter_nand = 0;
  2859. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2860. #define CHK(test, flag) do { \
  2861. if (*total_flags & (test)) \
  2862. filter_or |= (flag); \
  2863. else \
  2864. filter_nand |= (flag); \
  2865. } while (0)
  2866. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  2867. changed_flags, *total_flags);
  2868. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  2869. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK);
  2870. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  2871. #undef CHK
  2872. mutex_lock(&priv->mutex);
  2873. ctx->staging.filter_flags &= ~filter_nand;
  2874. ctx->staging.filter_flags |= filter_or;
  2875. /*
  2876. * Committing directly here breaks for some reason,
  2877. * but we'll eventually commit the filter flags
  2878. * change anyway.
  2879. */
  2880. mutex_unlock(&priv->mutex);
  2881. /*
  2882. * Receiving all multicast frames is always enabled by the
  2883. * default flags setup in iwl_connection_init_rx_config()
  2884. * since we currently do not support programming multicast
  2885. * filters into the device.
  2886. */
  2887. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  2888. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  2889. }
  2890. /*****************************************************************************
  2891. *
  2892. * sysfs attributes
  2893. *
  2894. *****************************************************************************/
  2895. #ifdef CONFIG_IWLWIFI_DEBUG
  2896. /*
  2897. * The following adds a new attribute to the sysfs representation
  2898. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  2899. * used for controlling the debug level.
  2900. *
  2901. * See the level definitions in iwl for details.
  2902. *
  2903. * The debug_level being managed using sysfs below is a per device debug
  2904. * level that is used instead of the global debug level if it (the per
  2905. * device debug level) is set.
  2906. */
  2907. static ssize_t show_debug_level(struct device *d,
  2908. struct device_attribute *attr, char *buf)
  2909. {
  2910. struct iwl_priv *priv = dev_get_drvdata(d);
  2911. return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
  2912. }
  2913. static ssize_t store_debug_level(struct device *d,
  2914. struct device_attribute *attr,
  2915. const char *buf, size_t count)
  2916. {
  2917. struct iwl_priv *priv = dev_get_drvdata(d);
  2918. unsigned long val;
  2919. int ret;
  2920. ret = strict_strtoul(buf, 0, &val);
  2921. if (ret)
  2922. IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
  2923. else {
  2924. priv->debug_level = val;
  2925. if (iwl_alloc_traffic_mem(priv))
  2926. IWL_ERR(priv,
  2927. "Not enough memory to generate traffic log\n");
  2928. }
  2929. return strnlen(buf, count);
  2930. }
  2931. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  2932. show_debug_level, store_debug_level);
  2933. #endif /* CONFIG_IWLWIFI_DEBUG */
  2934. static ssize_t show_temperature(struct device *d,
  2935. struct device_attribute *attr, char *buf)
  2936. {
  2937. struct iwl_priv *priv = dev_get_drvdata(d);
  2938. if (!iwl_is_alive(priv))
  2939. return -EAGAIN;
  2940. return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
  2941. }
  2942. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  2943. static ssize_t show_tx_power(struct device *d,
  2944. struct device_attribute *attr, char *buf)
  2945. {
  2946. struct iwl_priv *priv = dev_get_drvdata(d);
  2947. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  2948. }
  2949. static ssize_t store_tx_power(struct device *d,
  2950. struct device_attribute *attr,
  2951. const char *buf, size_t count)
  2952. {
  2953. struct iwl_priv *priv = dev_get_drvdata(d);
  2954. char *p = (char *)buf;
  2955. u32 val;
  2956. val = simple_strtoul(p, &p, 10);
  2957. if (p == buf)
  2958. IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
  2959. else
  2960. iwl3945_hw_reg_set_txpower(priv, val);
  2961. return count;
  2962. }
  2963. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  2964. static ssize_t show_flags(struct device *d,
  2965. struct device_attribute *attr, char *buf)
  2966. {
  2967. struct iwl_priv *priv = dev_get_drvdata(d);
  2968. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2969. return sprintf(buf, "0x%04X\n", ctx->active.flags);
  2970. }
  2971. static ssize_t store_flags(struct device *d,
  2972. struct device_attribute *attr,
  2973. const char *buf, size_t count)
  2974. {
  2975. struct iwl_priv *priv = dev_get_drvdata(d);
  2976. u32 flags = simple_strtoul(buf, NULL, 0);
  2977. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2978. mutex_lock(&priv->mutex);
  2979. if (le32_to_cpu(ctx->staging.flags) != flags) {
  2980. /* Cancel any currently running scans... */
  2981. if (iwl_scan_cancel_timeout(priv, 100))
  2982. IWL_WARN(priv, "Could not cancel scan.\n");
  2983. else {
  2984. IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
  2985. flags);
  2986. ctx->staging.flags = cpu_to_le32(flags);
  2987. iwlcore_commit_rxon(priv, ctx);
  2988. }
  2989. }
  2990. mutex_unlock(&priv->mutex);
  2991. return count;
  2992. }
  2993. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  2994. static ssize_t show_filter_flags(struct device *d,
  2995. struct device_attribute *attr, char *buf)
  2996. {
  2997. struct iwl_priv *priv = dev_get_drvdata(d);
  2998. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2999. return sprintf(buf, "0x%04X\n",
  3000. le32_to_cpu(ctx->active.filter_flags));
  3001. }
  3002. static ssize_t store_filter_flags(struct device *d,
  3003. struct device_attribute *attr,
  3004. const char *buf, size_t count)
  3005. {
  3006. struct iwl_priv *priv = dev_get_drvdata(d);
  3007. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  3008. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  3009. mutex_lock(&priv->mutex);
  3010. if (le32_to_cpu(ctx->staging.filter_flags) != filter_flags) {
  3011. /* Cancel any currently running scans... */
  3012. if (iwl_scan_cancel_timeout(priv, 100))
  3013. IWL_WARN(priv, "Could not cancel scan.\n");
  3014. else {
  3015. IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
  3016. "0x%04X\n", filter_flags);
  3017. ctx->staging.filter_flags =
  3018. cpu_to_le32(filter_flags);
  3019. iwlcore_commit_rxon(priv, ctx);
  3020. }
  3021. }
  3022. mutex_unlock(&priv->mutex);
  3023. return count;
  3024. }
  3025. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  3026. store_filter_flags);
  3027. static ssize_t show_measurement(struct device *d,
  3028. struct device_attribute *attr, char *buf)
  3029. {
  3030. struct iwl_priv *priv = dev_get_drvdata(d);
  3031. struct iwl_spectrum_notification measure_report;
  3032. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  3033. u8 *data = (u8 *)&measure_report;
  3034. unsigned long flags;
  3035. spin_lock_irqsave(&priv->lock, flags);
  3036. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  3037. spin_unlock_irqrestore(&priv->lock, flags);
  3038. return 0;
  3039. }
  3040. memcpy(&measure_report, &priv->measure_report, size);
  3041. priv->measurement_status = 0;
  3042. spin_unlock_irqrestore(&priv->lock, flags);
  3043. while (size && (PAGE_SIZE - len)) {
  3044. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  3045. PAGE_SIZE - len, 1);
  3046. len = strlen(buf);
  3047. if (PAGE_SIZE - len)
  3048. buf[len++] = '\n';
  3049. ofs += 16;
  3050. size -= min(size, 16U);
  3051. }
  3052. return len;
  3053. }
  3054. static ssize_t store_measurement(struct device *d,
  3055. struct device_attribute *attr,
  3056. const char *buf, size_t count)
  3057. {
  3058. struct iwl_priv *priv = dev_get_drvdata(d);
  3059. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  3060. struct ieee80211_measurement_params params = {
  3061. .channel = le16_to_cpu(ctx->active.channel),
  3062. .start_time = cpu_to_le64(priv->_3945.last_tsf),
  3063. .duration = cpu_to_le16(1),
  3064. };
  3065. u8 type = IWL_MEASURE_BASIC;
  3066. u8 buffer[32];
  3067. u8 channel;
  3068. if (count) {
  3069. char *p = buffer;
  3070. strncpy(buffer, buf, min(sizeof(buffer), count));
  3071. channel = simple_strtoul(p, NULL, 0);
  3072. if (channel)
  3073. params.channel = channel;
  3074. p = buffer;
  3075. while (*p && *p != ' ')
  3076. p++;
  3077. if (*p)
  3078. type = simple_strtoul(p + 1, NULL, 0);
  3079. }
  3080. IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
  3081. "channel %d (for '%s')\n", type, params.channel, buf);
  3082. iwl3945_get_measurement(priv, &params, type);
  3083. return count;
  3084. }
  3085. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  3086. show_measurement, store_measurement);
  3087. static ssize_t store_retry_rate(struct device *d,
  3088. struct device_attribute *attr,
  3089. const char *buf, size_t count)
  3090. {
  3091. struct iwl_priv *priv = dev_get_drvdata(d);
  3092. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  3093. if (priv->retry_rate <= 0)
  3094. priv->retry_rate = 1;
  3095. return count;
  3096. }
  3097. static ssize_t show_retry_rate(struct device *d,
  3098. struct device_attribute *attr, char *buf)
  3099. {
  3100. struct iwl_priv *priv = dev_get_drvdata(d);
  3101. return sprintf(buf, "%d", priv->retry_rate);
  3102. }
  3103. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  3104. store_retry_rate);
  3105. static ssize_t show_channels(struct device *d,
  3106. struct device_attribute *attr, char *buf)
  3107. {
  3108. /* all this shit doesn't belong into sysfs anyway */
  3109. return 0;
  3110. }
  3111. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  3112. static ssize_t show_antenna(struct device *d,
  3113. struct device_attribute *attr, char *buf)
  3114. {
  3115. struct iwl_priv *priv = dev_get_drvdata(d);
  3116. if (!iwl_is_alive(priv))
  3117. return -EAGAIN;
  3118. return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
  3119. }
  3120. static ssize_t store_antenna(struct device *d,
  3121. struct device_attribute *attr,
  3122. const char *buf, size_t count)
  3123. {
  3124. struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
  3125. int ant;
  3126. if (count == 0)
  3127. return 0;
  3128. if (sscanf(buf, "%1i", &ant) != 1) {
  3129. IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
  3130. return count;
  3131. }
  3132. if ((ant >= 0) && (ant <= 2)) {
  3133. IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
  3134. iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
  3135. } else
  3136. IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
  3137. return count;
  3138. }
  3139. static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
  3140. static ssize_t show_status(struct device *d,
  3141. struct device_attribute *attr, char *buf)
  3142. {
  3143. struct iwl_priv *priv = dev_get_drvdata(d);
  3144. if (!iwl_is_alive(priv))
  3145. return -EAGAIN;
  3146. return sprintf(buf, "0x%08x\n", (int)priv->status);
  3147. }
  3148. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  3149. static ssize_t dump_error_log(struct device *d,
  3150. struct device_attribute *attr,
  3151. const char *buf, size_t count)
  3152. {
  3153. struct iwl_priv *priv = dev_get_drvdata(d);
  3154. char *p = (char *)buf;
  3155. if (p[0] == '1')
  3156. iwl3945_dump_nic_error_log(priv);
  3157. return strnlen(buf, count);
  3158. }
  3159. static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
  3160. /*****************************************************************************
  3161. *
  3162. * driver setup and tear down
  3163. *
  3164. *****************************************************************************/
  3165. static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
  3166. {
  3167. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  3168. init_waitqueue_head(&priv->wait_command_queue);
  3169. INIT_WORK(&priv->restart, iwl3945_bg_restart);
  3170. INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
  3171. INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
  3172. INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
  3173. INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
  3174. INIT_DELAYED_WORK(&priv->_3945.rfkill_poll, iwl3945_rfkill_poll);
  3175. iwl_setup_scan_deferred_work(priv);
  3176. iwl3945_hw_setup_deferred_work(priv);
  3177. if (priv->cfg->ops->lib->recover_from_tx_stall) {
  3178. init_timer(&priv->monitor_recover);
  3179. priv->monitor_recover.data = (unsigned long)priv;
  3180. priv->monitor_recover.function =
  3181. priv->cfg->ops->lib->recover_from_tx_stall;
  3182. }
  3183. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  3184. iwl3945_irq_tasklet, (unsigned long)priv);
  3185. }
  3186. static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
  3187. {
  3188. iwl3945_hw_cancel_deferred_work(priv);
  3189. cancel_delayed_work_sync(&priv->init_alive_start);
  3190. cancel_delayed_work(&priv->scan_check);
  3191. cancel_delayed_work(&priv->alive_start);
  3192. cancel_work_sync(&priv->start_internal_scan);
  3193. cancel_work_sync(&priv->beacon_update);
  3194. }
  3195. static struct attribute *iwl3945_sysfs_entries[] = {
  3196. &dev_attr_antenna.attr,
  3197. &dev_attr_channels.attr,
  3198. &dev_attr_dump_errors.attr,
  3199. &dev_attr_flags.attr,
  3200. &dev_attr_filter_flags.attr,
  3201. &dev_attr_measurement.attr,
  3202. &dev_attr_retry_rate.attr,
  3203. &dev_attr_status.attr,
  3204. &dev_attr_temperature.attr,
  3205. &dev_attr_tx_power.attr,
  3206. #ifdef CONFIG_IWLWIFI_DEBUG
  3207. &dev_attr_debug_level.attr,
  3208. #endif
  3209. NULL
  3210. };
  3211. static struct attribute_group iwl3945_attribute_group = {
  3212. .name = NULL, /* put in device directory */
  3213. .attrs = iwl3945_sysfs_entries,
  3214. };
  3215. static struct ieee80211_ops iwl3945_hw_ops = {
  3216. .tx = iwl3945_mac_tx,
  3217. .start = iwl3945_mac_start,
  3218. .stop = iwl3945_mac_stop,
  3219. .add_interface = iwl_mac_add_interface,
  3220. .remove_interface = iwl_mac_remove_interface,
  3221. .config = iwl_mac_config,
  3222. .configure_filter = iwl3945_configure_filter,
  3223. .set_key = iwl3945_mac_set_key,
  3224. .conf_tx = iwl_mac_conf_tx,
  3225. .reset_tsf = iwl_mac_reset_tsf,
  3226. .bss_info_changed = iwl_bss_info_changed,
  3227. .hw_scan = iwl_mac_hw_scan,
  3228. .sta_add = iwl3945_mac_sta_add,
  3229. .sta_remove = iwl_mac_sta_remove,
  3230. .tx_last_beacon = iwl_mac_tx_last_beacon,
  3231. };
  3232. static int iwl3945_init_drv(struct iwl_priv *priv)
  3233. {
  3234. int ret;
  3235. struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  3236. priv->retry_rate = 1;
  3237. priv->ibss_beacon = NULL;
  3238. spin_lock_init(&priv->sta_lock);
  3239. spin_lock_init(&priv->hcmd_lock);
  3240. INIT_LIST_HEAD(&priv->free_frames);
  3241. mutex_init(&priv->mutex);
  3242. mutex_init(&priv->sync_cmd_mutex);
  3243. priv->ieee_channels = NULL;
  3244. priv->ieee_rates = NULL;
  3245. priv->band = IEEE80211_BAND_2GHZ;
  3246. priv->iw_mode = NL80211_IFTYPE_STATION;
  3247. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  3248. priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
  3249. if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
  3250. IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
  3251. eeprom->version);
  3252. ret = -EINVAL;
  3253. goto err;
  3254. }
  3255. ret = iwl_init_channel_map(priv);
  3256. if (ret) {
  3257. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  3258. goto err;
  3259. }
  3260. /* Set up txpower settings in driver for all channels */
  3261. if (iwl3945_txpower_set_from_eeprom(priv)) {
  3262. ret = -EIO;
  3263. goto err_free_channel_map;
  3264. }
  3265. ret = iwlcore_init_geos(priv);
  3266. if (ret) {
  3267. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  3268. goto err_free_channel_map;
  3269. }
  3270. iwl3945_init_hw_rates(priv, priv->ieee_rates);
  3271. return 0;
  3272. err_free_channel_map:
  3273. iwl_free_channel_map(priv);
  3274. err:
  3275. return ret;
  3276. }
  3277. #define IWL3945_MAX_PROBE_REQUEST 200
  3278. static int iwl3945_setup_mac(struct iwl_priv *priv)
  3279. {
  3280. int ret;
  3281. struct ieee80211_hw *hw = priv->hw;
  3282. hw->rate_control_algorithm = "iwl-3945-rs";
  3283. hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
  3284. hw->vif_data_size = sizeof(struct iwl_vif_priv);
  3285. /* Tell mac80211 our characteristics */
  3286. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  3287. IEEE80211_HW_SPECTRUM_MGMT;
  3288. if (!priv->cfg->broken_powersave)
  3289. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  3290. IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
  3291. hw->wiphy->interface_modes =
  3292. priv->contexts[IWL_RXON_CTX_BSS].interface_modes;
  3293. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  3294. WIPHY_FLAG_DISABLE_BEACON_HINTS;
  3295. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX_3945;
  3296. /* we create the 802.11 header and a zero-length SSID element */
  3297. hw->wiphy->max_scan_ie_len = IWL3945_MAX_PROBE_REQUEST - 24 - 2;
  3298. /* Default value; 4 EDCA QOS priorities */
  3299. hw->queues = 4;
  3300. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  3301. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  3302. &priv->bands[IEEE80211_BAND_2GHZ];
  3303. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  3304. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  3305. &priv->bands[IEEE80211_BAND_5GHZ];
  3306. ret = ieee80211_register_hw(priv->hw);
  3307. if (ret) {
  3308. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  3309. return ret;
  3310. }
  3311. priv->mac80211_registered = 1;
  3312. return 0;
  3313. }
  3314. static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3315. {
  3316. int err = 0, i;
  3317. struct iwl_priv *priv;
  3318. struct ieee80211_hw *hw;
  3319. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  3320. struct iwl3945_eeprom *eeprom;
  3321. unsigned long flags;
  3322. /***********************
  3323. * 1. Allocating HW data
  3324. * ********************/
  3325. /* mac80211 allocates memory for this device instance, including
  3326. * space for this driver's private structure */
  3327. hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
  3328. if (hw == NULL) {
  3329. pr_err("Can not allocate network device\n");
  3330. err = -ENOMEM;
  3331. goto out;
  3332. }
  3333. priv = hw->priv;
  3334. SET_IEEE80211_DEV(hw, &pdev->dev);
  3335. priv->cmd_queue = IWL39_CMD_QUEUE_NUM;
  3336. /* 3945 has only one valid context */
  3337. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  3338. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  3339. priv->contexts[i].ctxid = i;
  3340. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  3341. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  3342. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  3343. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  3344. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  3345. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  3346. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  3347. BIT(NL80211_IFTYPE_STATION) |
  3348. BIT(NL80211_IFTYPE_ADHOC);
  3349. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  3350. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  3351. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  3352. /*
  3353. * Disabling hardware scan means that mac80211 will perform scans
  3354. * "the hard way", rather than using device's scan.
  3355. */
  3356. if (iwl3945_mod_params.disable_hw_scan) {
  3357. IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
  3358. iwl3945_hw_ops.hw_scan = NULL;
  3359. }
  3360. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  3361. priv->cfg = cfg;
  3362. priv->pci_dev = pdev;
  3363. priv->inta_mask = CSR_INI_SET_MASK;
  3364. if (iwl_alloc_traffic_mem(priv))
  3365. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  3366. /***************************
  3367. * 2. Initializing PCI bus
  3368. * *************************/
  3369. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  3370. PCIE_LINK_STATE_CLKPM);
  3371. if (pci_enable_device(pdev)) {
  3372. err = -ENODEV;
  3373. goto out_ieee80211_free_hw;
  3374. }
  3375. pci_set_master(pdev);
  3376. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  3377. if (!err)
  3378. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  3379. if (err) {
  3380. IWL_WARN(priv, "No suitable DMA available.\n");
  3381. goto out_pci_disable_device;
  3382. }
  3383. pci_set_drvdata(pdev, priv);
  3384. err = pci_request_regions(pdev, DRV_NAME);
  3385. if (err)
  3386. goto out_pci_disable_device;
  3387. /***********************
  3388. * 3. Read REV Register
  3389. * ********************/
  3390. priv->hw_base = pci_iomap(pdev, 0, 0);
  3391. if (!priv->hw_base) {
  3392. err = -ENODEV;
  3393. goto out_pci_release_regions;
  3394. }
  3395. IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
  3396. (unsigned long long) pci_resource_len(pdev, 0));
  3397. IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
  3398. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  3399. * PCI Tx retries from interfering with C3 CPU state */
  3400. pci_write_config_byte(pdev, 0x41, 0x00);
  3401. /* these spin locks will be used in apm_ops.init and EEPROM access
  3402. * we should init now
  3403. */
  3404. spin_lock_init(&priv->reg_lock);
  3405. spin_lock_init(&priv->lock);
  3406. /*
  3407. * stop and reset the on-board processor just in case it is in a
  3408. * strange state ... like being left stranded by a primary kernel
  3409. * and this is now the kdump kernel trying to start up
  3410. */
  3411. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  3412. /***********************
  3413. * 4. Read EEPROM
  3414. * ********************/
  3415. /* Read the EEPROM */
  3416. err = iwl_eeprom_init(priv);
  3417. if (err) {
  3418. IWL_ERR(priv, "Unable to init EEPROM\n");
  3419. goto out_iounmap;
  3420. }
  3421. /* MAC Address location in EEPROM same for 3945/4965 */
  3422. eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  3423. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", eeprom->mac_address);
  3424. SET_IEEE80211_PERM_ADDR(priv->hw, eeprom->mac_address);
  3425. /***********************
  3426. * 5. Setup HW Constants
  3427. * ********************/
  3428. /* Device-specific setup */
  3429. if (iwl3945_hw_set_hw_params(priv)) {
  3430. IWL_ERR(priv, "failed to set hw settings\n");
  3431. goto out_eeprom_free;
  3432. }
  3433. /***********************
  3434. * 6. Setup priv
  3435. * ********************/
  3436. err = iwl3945_init_drv(priv);
  3437. if (err) {
  3438. IWL_ERR(priv, "initializing driver failed\n");
  3439. goto out_unset_hw_params;
  3440. }
  3441. IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
  3442. priv->cfg->name);
  3443. /***********************
  3444. * 7. Setup Services
  3445. * ********************/
  3446. spin_lock_irqsave(&priv->lock, flags);
  3447. iwl_disable_interrupts(priv);
  3448. spin_unlock_irqrestore(&priv->lock, flags);
  3449. pci_enable_msi(priv->pci_dev);
  3450. err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
  3451. IRQF_SHARED, DRV_NAME, priv);
  3452. if (err) {
  3453. IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
  3454. goto out_disable_msi;
  3455. }
  3456. err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  3457. if (err) {
  3458. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  3459. goto out_release_irq;
  3460. }
  3461. iwl_set_rxon_channel(priv,
  3462. &priv->bands[IEEE80211_BAND_2GHZ].channels[5],
  3463. &priv->contexts[IWL_RXON_CTX_BSS]);
  3464. iwl3945_setup_deferred_work(priv);
  3465. iwl3945_setup_rx_handlers(priv);
  3466. iwl_power_initialize(priv);
  3467. /*********************************
  3468. * 8. Setup and Register mac80211
  3469. * *******************************/
  3470. iwl_enable_interrupts(priv);
  3471. err = iwl3945_setup_mac(priv);
  3472. if (err)
  3473. goto out_remove_sysfs;
  3474. err = iwl_dbgfs_register(priv, DRV_NAME);
  3475. if (err)
  3476. IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
  3477. /* Start monitoring the killswitch */
  3478. queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll,
  3479. 2 * HZ);
  3480. return 0;
  3481. out_remove_sysfs:
  3482. destroy_workqueue(priv->workqueue);
  3483. priv->workqueue = NULL;
  3484. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  3485. out_release_irq:
  3486. free_irq(priv->pci_dev->irq, priv);
  3487. out_disable_msi:
  3488. pci_disable_msi(priv->pci_dev);
  3489. iwlcore_free_geos(priv);
  3490. iwl_free_channel_map(priv);
  3491. out_unset_hw_params:
  3492. iwl3945_unset_hw_params(priv);
  3493. out_eeprom_free:
  3494. iwl_eeprom_free(priv);
  3495. out_iounmap:
  3496. pci_iounmap(pdev, priv->hw_base);
  3497. out_pci_release_regions:
  3498. pci_release_regions(pdev);
  3499. out_pci_disable_device:
  3500. pci_set_drvdata(pdev, NULL);
  3501. pci_disable_device(pdev);
  3502. out_ieee80211_free_hw:
  3503. iwl_free_traffic_mem(priv);
  3504. ieee80211_free_hw(priv->hw);
  3505. out:
  3506. return err;
  3507. }
  3508. static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
  3509. {
  3510. struct iwl_priv *priv = pci_get_drvdata(pdev);
  3511. unsigned long flags;
  3512. if (!priv)
  3513. return;
  3514. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  3515. iwl_dbgfs_unregister(priv);
  3516. set_bit(STATUS_EXIT_PENDING, &priv->status);
  3517. if (priv->mac80211_registered) {
  3518. ieee80211_unregister_hw(priv->hw);
  3519. priv->mac80211_registered = 0;
  3520. } else {
  3521. iwl3945_down(priv);
  3522. }
  3523. /*
  3524. * Make sure device is reset to low power before unloading driver.
  3525. * This may be redundant with iwl_down(), but there are paths to
  3526. * run iwl_down() without calling apm_ops.stop(), and there are
  3527. * paths to avoid running iwl_down() at all before leaving driver.
  3528. * This (inexpensive) call *makes sure* device is reset.
  3529. */
  3530. priv->cfg->ops->lib->apm_ops.stop(priv);
  3531. /* make sure we flush any pending irq or
  3532. * tasklet for the driver
  3533. */
  3534. spin_lock_irqsave(&priv->lock, flags);
  3535. iwl_disable_interrupts(priv);
  3536. spin_unlock_irqrestore(&priv->lock, flags);
  3537. iwl_synchronize_irq(priv);
  3538. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  3539. cancel_delayed_work_sync(&priv->_3945.rfkill_poll);
  3540. iwl3945_dealloc_ucode_pci(priv);
  3541. if (priv->rxq.bd)
  3542. iwl3945_rx_queue_free(priv, &priv->rxq);
  3543. iwl3945_hw_txq_ctx_free(priv);
  3544. iwl3945_unset_hw_params(priv);
  3545. /*netif_stop_queue(dev); */
  3546. flush_workqueue(priv->workqueue);
  3547. /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
  3548. * priv->workqueue... so we can't take down the workqueue
  3549. * until now... */
  3550. destroy_workqueue(priv->workqueue);
  3551. priv->workqueue = NULL;
  3552. iwl_free_traffic_mem(priv);
  3553. free_irq(pdev->irq, priv);
  3554. pci_disable_msi(pdev);
  3555. pci_iounmap(pdev, priv->hw_base);
  3556. pci_release_regions(pdev);
  3557. pci_disable_device(pdev);
  3558. pci_set_drvdata(pdev, NULL);
  3559. iwl_free_channel_map(priv);
  3560. iwlcore_free_geos(priv);
  3561. kfree(priv->scan_cmd);
  3562. if (priv->ibss_beacon)
  3563. dev_kfree_skb(priv->ibss_beacon);
  3564. ieee80211_free_hw(priv->hw);
  3565. }
  3566. /*****************************************************************************
  3567. *
  3568. * driver and module entry point
  3569. *
  3570. *****************************************************************************/
  3571. static struct pci_driver iwl3945_driver = {
  3572. .name = DRV_NAME,
  3573. .id_table = iwl3945_hw_card_ids,
  3574. .probe = iwl3945_pci_probe,
  3575. .remove = __devexit_p(iwl3945_pci_remove),
  3576. #ifdef CONFIG_PM
  3577. .suspend = iwl_pci_suspend,
  3578. .resume = iwl_pci_resume,
  3579. #endif
  3580. };
  3581. static int __init iwl3945_init(void)
  3582. {
  3583. int ret;
  3584. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  3585. pr_info(DRV_COPYRIGHT "\n");
  3586. ret = iwl3945_rate_control_register();
  3587. if (ret) {
  3588. pr_err("Unable to register rate control algorithm: %d\n", ret);
  3589. return ret;
  3590. }
  3591. ret = pci_register_driver(&iwl3945_driver);
  3592. if (ret) {
  3593. pr_err("Unable to initialize PCI module\n");
  3594. goto error_register;
  3595. }
  3596. return ret;
  3597. error_register:
  3598. iwl3945_rate_control_unregister();
  3599. return ret;
  3600. }
  3601. static void __exit iwl3945_exit(void)
  3602. {
  3603. pci_unregister_driver(&iwl3945_driver);
  3604. iwl3945_rate_control_unregister();
  3605. }
  3606. MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
  3607. module_param_named(antenna, iwl3945_mod_params.antenna, int, S_IRUGO);
  3608. MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
  3609. module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, S_IRUGO);
  3610. MODULE_PARM_DESC(swcrypto,
  3611. "using software crypto (default 1 [software])\n");
  3612. #ifdef CONFIG_IWLWIFI_DEBUG
  3613. module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
  3614. MODULE_PARM_DESC(debug, "debug output mask");
  3615. #endif
  3616. module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan,
  3617. int, S_IRUGO);
  3618. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  3619. module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, S_IRUGO);
  3620. MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
  3621. module_exit(iwl3945_exit);
  3622. module_init(iwl3945_init);