main.c 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068
  1. /*
  2. Broadcom B43 wireless driver
  3. Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
  4. Copyright (c) 2005 Stefano Brivio <st3@riseup.net>
  5. Copyright (c) 2005, 2006 Michael Buesch <mb@bu3sch.de>
  6. Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
  7. Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  8. Some parts of the code in this file are derived from the ipw2200
  9. driver Copyright(c) 2003 - 2004 Intel Corporation.
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; see the file COPYING. If not, write to
  20. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  21. Boston, MA 02110-1301, USA.
  22. */
  23. #include <linux/delay.h>
  24. #include <linux/init.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/if_arp.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/version.h>
  29. #include <linux/firmware.h>
  30. #include <linux/wireless.h>
  31. #include <linux/workqueue.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/dma-mapping.h>
  34. #include <asm/unaligned.h>
  35. #include "b43.h"
  36. #include "main.h"
  37. #include "debugfs.h"
  38. #include "phy.h"
  39. #include "dma.h"
  40. #include "pio.h"
  41. #include "sysfs.h"
  42. #include "xmit.h"
  43. #include "lo.h"
  44. #include "pcmcia.h"
  45. MODULE_DESCRIPTION("Broadcom B43 wireless driver");
  46. MODULE_AUTHOR("Martin Langer");
  47. MODULE_AUTHOR("Stefano Brivio");
  48. MODULE_AUTHOR("Michael Buesch");
  49. MODULE_LICENSE("GPL");
  50. extern char *nvram_get(char *name);
  51. #if defined(CONFIG_B43_DMA) && defined(CONFIG_B43_PIO)
  52. static int modparam_pio;
  53. module_param_named(pio, modparam_pio, int, 0444);
  54. MODULE_PARM_DESC(pio, "enable(1) / disable(0) PIO mode");
  55. #elif defined(CONFIG_B43_DMA)
  56. # define modparam_pio 0
  57. #elif defined(CONFIG_B43_PIO)
  58. # define modparam_pio 1
  59. #endif
  60. static int modparam_bad_frames_preempt;
  61. module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
  62. MODULE_PARM_DESC(bad_frames_preempt,
  63. "enable(1) / disable(0) Bad Frames Preemption");
  64. static int modparam_short_retry = B43_DEFAULT_SHORT_RETRY_LIMIT;
  65. module_param_named(short_retry, modparam_short_retry, int, 0444);
  66. MODULE_PARM_DESC(short_retry, "Short-Retry-Limit (0 - 15)");
  67. static int modparam_long_retry = B43_DEFAULT_LONG_RETRY_LIMIT;
  68. module_param_named(long_retry, modparam_long_retry, int, 0444);
  69. MODULE_PARM_DESC(long_retry, "Long-Retry-Limit (0 - 15)");
  70. static char modparam_fwpostfix[16];
  71. module_param_string(fwpostfix, modparam_fwpostfix, 16, 0444);
  72. MODULE_PARM_DESC(fwpostfix, "Postfix for the .fw files to load.");
  73. static int modparam_hwpctl;
  74. module_param_named(hwpctl, modparam_hwpctl, int, 0444);
  75. MODULE_PARM_DESC(hwpctl, "Enable hardware-side power control (default off)");
  76. static int modparam_nohwcrypt;
  77. module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
  78. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  79. static const struct ssb_device_id b43_ssb_tbl[] = {
  80. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 5),
  81. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 6),
  82. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 7),
  83. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 9),
  84. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 10),
  85. SSB_DEVTABLE_END
  86. };
  87. MODULE_DEVICE_TABLE(ssb, b43_ssb_tbl);
  88. /* Channel and ratetables are shared for all devices.
  89. * They can't be const, because ieee80211 puts some precalculated
  90. * data in there. This data is the same for all devices, so we don't
  91. * get concurrency issues */
  92. #define RATETAB_ENT(_rateid, _flags) \
  93. { \
  94. .rate = B43_RATE_TO_BASE100KBPS(_rateid), \
  95. .val = (_rateid), \
  96. .val2 = (_rateid), \
  97. .flags = (_flags), \
  98. }
  99. static struct ieee80211_rate __b43_ratetable[] = {
  100. RATETAB_ENT(B43_CCK_RATE_1MB, IEEE80211_RATE_CCK),
  101. RATETAB_ENT(B43_CCK_RATE_2MB, IEEE80211_RATE_CCK_2),
  102. RATETAB_ENT(B43_CCK_RATE_5MB, IEEE80211_RATE_CCK_2),
  103. RATETAB_ENT(B43_CCK_RATE_11MB, IEEE80211_RATE_CCK_2),
  104. RATETAB_ENT(B43_OFDM_RATE_6MB, IEEE80211_RATE_OFDM),
  105. RATETAB_ENT(B43_OFDM_RATE_9MB, IEEE80211_RATE_OFDM),
  106. RATETAB_ENT(B43_OFDM_RATE_12MB, IEEE80211_RATE_OFDM),
  107. RATETAB_ENT(B43_OFDM_RATE_18MB, IEEE80211_RATE_OFDM),
  108. RATETAB_ENT(B43_OFDM_RATE_24MB, IEEE80211_RATE_OFDM),
  109. RATETAB_ENT(B43_OFDM_RATE_36MB, IEEE80211_RATE_OFDM),
  110. RATETAB_ENT(B43_OFDM_RATE_48MB, IEEE80211_RATE_OFDM),
  111. RATETAB_ENT(B43_OFDM_RATE_54MB, IEEE80211_RATE_OFDM),
  112. };
  113. #define b43_a_ratetable (__b43_ratetable + 4)
  114. #define b43_a_ratetable_size 8
  115. #define b43_b_ratetable (__b43_ratetable + 0)
  116. #define b43_b_ratetable_size 4
  117. #define b43_g_ratetable (__b43_ratetable + 0)
  118. #define b43_g_ratetable_size 12
  119. #define CHANTAB_ENT(_chanid, _freq) \
  120. { \
  121. .chan = (_chanid), \
  122. .freq = (_freq), \
  123. .val = (_chanid), \
  124. .flag = IEEE80211_CHAN_W_SCAN | \
  125. IEEE80211_CHAN_W_ACTIVE_SCAN | \
  126. IEEE80211_CHAN_W_IBSS, \
  127. .power_level = 0xFF, \
  128. .antenna_max = 0xFF, \
  129. }
  130. static struct ieee80211_channel b43_bg_chantable[] = {
  131. CHANTAB_ENT(1, 2412),
  132. CHANTAB_ENT(2, 2417),
  133. CHANTAB_ENT(3, 2422),
  134. CHANTAB_ENT(4, 2427),
  135. CHANTAB_ENT(5, 2432),
  136. CHANTAB_ENT(6, 2437),
  137. CHANTAB_ENT(7, 2442),
  138. CHANTAB_ENT(8, 2447),
  139. CHANTAB_ENT(9, 2452),
  140. CHANTAB_ENT(10, 2457),
  141. CHANTAB_ENT(11, 2462),
  142. CHANTAB_ENT(12, 2467),
  143. CHANTAB_ENT(13, 2472),
  144. CHANTAB_ENT(14, 2484),
  145. };
  146. #define b43_bg_chantable_size ARRAY_SIZE(b43_bg_chantable)
  147. static struct ieee80211_channel b43_a_chantable[] = {
  148. CHANTAB_ENT(36, 5180),
  149. CHANTAB_ENT(40, 5200),
  150. CHANTAB_ENT(44, 5220),
  151. CHANTAB_ENT(48, 5240),
  152. CHANTAB_ENT(52, 5260),
  153. CHANTAB_ENT(56, 5280),
  154. CHANTAB_ENT(60, 5300),
  155. CHANTAB_ENT(64, 5320),
  156. CHANTAB_ENT(149, 5745),
  157. CHANTAB_ENT(153, 5765),
  158. CHANTAB_ENT(157, 5785),
  159. CHANTAB_ENT(161, 5805),
  160. CHANTAB_ENT(165, 5825),
  161. };
  162. #define b43_a_chantable_size ARRAY_SIZE(b43_a_chantable)
  163. static void b43_wireless_core_exit(struct b43_wldev *dev);
  164. static int b43_wireless_core_init(struct b43_wldev *dev);
  165. static void b43_wireless_core_stop(struct b43_wldev *dev);
  166. static int b43_wireless_core_start(struct b43_wldev *dev);
  167. static int b43_ratelimit(struct b43_wl *wl)
  168. {
  169. if (!wl || !wl->current_dev)
  170. return 1;
  171. if (b43_status(wl->current_dev) < B43_STAT_STARTED)
  172. return 1;
  173. /* We are up and running.
  174. * Ratelimit the messages to avoid DoS over the net. */
  175. return net_ratelimit();
  176. }
  177. void b43info(struct b43_wl *wl, const char *fmt, ...)
  178. {
  179. va_list args;
  180. if (!b43_ratelimit(wl))
  181. return;
  182. va_start(args, fmt);
  183. printk(KERN_INFO "b43-%s: ",
  184. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  185. vprintk(fmt, args);
  186. va_end(args);
  187. }
  188. void b43err(struct b43_wl *wl, const char *fmt, ...)
  189. {
  190. va_list args;
  191. if (!b43_ratelimit(wl))
  192. return;
  193. va_start(args, fmt);
  194. printk(KERN_ERR "b43-%s ERROR: ",
  195. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  196. vprintk(fmt, args);
  197. va_end(args);
  198. }
  199. void b43warn(struct b43_wl *wl, const char *fmt, ...)
  200. {
  201. va_list args;
  202. if (!b43_ratelimit(wl))
  203. return;
  204. va_start(args, fmt);
  205. printk(KERN_WARNING "b43-%s warning: ",
  206. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  207. vprintk(fmt, args);
  208. va_end(args);
  209. }
  210. #if B43_DEBUG
  211. void b43dbg(struct b43_wl *wl, const char *fmt, ...)
  212. {
  213. va_list args;
  214. va_start(args, fmt);
  215. printk(KERN_DEBUG "b43-%s debug: ",
  216. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  217. vprintk(fmt, args);
  218. va_end(args);
  219. }
  220. #endif /* DEBUG */
  221. static void b43_ram_write(struct b43_wldev *dev, u16 offset, u32 val)
  222. {
  223. u32 macctl;
  224. B43_WARN_ON(offset % 4 != 0);
  225. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  226. if (macctl & B43_MACCTL_BE)
  227. val = swab32(val);
  228. b43_write32(dev, B43_MMIO_RAM_CONTROL, offset);
  229. mmiowb();
  230. b43_write32(dev, B43_MMIO_RAM_DATA, val);
  231. }
  232. static inline
  233. void b43_shm_control_word(struct b43_wldev *dev, u16 routing, u16 offset)
  234. {
  235. u32 control;
  236. /* "offset" is the WORD offset. */
  237. control = routing;
  238. control <<= 16;
  239. control |= offset;
  240. b43_write32(dev, B43_MMIO_SHM_CONTROL, control);
  241. }
  242. u32 b43_shm_read32(struct b43_wldev *dev, u16 routing, u16 offset)
  243. {
  244. u32 ret;
  245. if (routing == B43_SHM_SHARED) {
  246. B43_WARN_ON(offset & 0x0001);
  247. if (offset & 0x0003) {
  248. /* Unaligned access */
  249. b43_shm_control_word(dev, routing, offset >> 2);
  250. ret = b43_read16(dev, B43_MMIO_SHM_DATA_UNALIGNED);
  251. ret <<= 16;
  252. b43_shm_control_word(dev, routing, (offset >> 2) + 1);
  253. ret |= b43_read16(dev, B43_MMIO_SHM_DATA);
  254. return ret;
  255. }
  256. offset >>= 2;
  257. }
  258. b43_shm_control_word(dev, routing, offset);
  259. ret = b43_read32(dev, B43_MMIO_SHM_DATA);
  260. return ret;
  261. }
  262. u16 b43_shm_read16(struct b43_wldev * dev, u16 routing, u16 offset)
  263. {
  264. u16 ret;
  265. if (routing == B43_SHM_SHARED) {
  266. B43_WARN_ON(offset & 0x0001);
  267. if (offset & 0x0003) {
  268. /* Unaligned access */
  269. b43_shm_control_word(dev, routing, offset >> 2);
  270. ret = b43_read16(dev, B43_MMIO_SHM_DATA_UNALIGNED);
  271. return ret;
  272. }
  273. offset >>= 2;
  274. }
  275. b43_shm_control_word(dev, routing, offset);
  276. ret = b43_read16(dev, B43_MMIO_SHM_DATA);
  277. return ret;
  278. }
  279. void b43_shm_write32(struct b43_wldev *dev, u16 routing, u16 offset, u32 value)
  280. {
  281. if (routing == B43_SHM_SHARED) {
  282. B43_WARN_ON(offset & 0x0001);
  283. if (offset & 0x0003) {
  284. /* Unaligned access */
  285. b43_shm_control_word(dev, routing, offset >> 2);
  286. mmiowb();
  287. b43_write16(dev, B43_MMIO_SHM_DATA_UNALIGNED,
  288. (value >> 16) & 0xffff);
  289. mmiowb();
  290. b43_shm_control_word(dev, routing, (offset >> 2) + 1);
  291. mmiowb();
  292. b43_write16(dev, B43_MMIO_SHM_DATA, value & 0xffff);
  293. return;
  294. }
  295. offset >>= 2;
  296. }
  297. b43_shm_control_word(dev, routing, offset);
  298. mmiowb();
  299. b43_write32(dev, B43_MMIO_SHM_DATA, value);
  300. }
  301. void b43_shm_write16(struct b43_wldev *dev, u16 routing, u16 offset, u16 value)
  302. {
  303. if (routing == B43_SHM_SHARED) {
  304. B43_WARN_ON(offset & 0x0001);
  305. if (offset & 0x0003) {
  306. /* Unaligned access */
  307. b43_shm_control_word(dev, routing, offset >> 2);
  308. mmiowb();
  309. b43_write16(dev, B43_MMIO_SHM_DATA_UNALIGNED, value);
  310. return;
  311. }
  312. offset >>= 2;
  313. }
  314. b43_shm_control_word(dev, routing, offset);
  315. mmiowb();
  316. b43_write16(dev, B43_MMIO_SHM_DATA, value);
  317. }
  318. /* Read HostFlags */
  319. u32 b43_hf_read(struct b43_wldev * dev)
  320. {
  321. u32 ret;
  322. ret = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFHI);
  323. ret <<= 16;
  324. ret |= b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFLO);
  325. return ret;
  326. }
  327. /* Write HostFlags */
  328. void b43_hf_write(struct b43_wldev *dev, u32 value)
  329. {
  330. b43_shm_write16(dev, B43_SHM_SHARED,
  331. B43_SHM_SH_HOSTFLO, (value & 0x0000FFFF));
  332. b43_shm_write16(dev, B43_SHM_SHARED,
  333. B43_SHM_SH_HOSTFHI, ((value & 0xFFFF0000) >> 16));
  334. }
  335. void b43_tsf_read(struct b43_wldev *dev, u64 * tsf)
  336. {
  337. /* We need to be careful. As we read the TSF from multiple
  338. * registers, we should take care of register overflows.
  339. * In theory, the whole tsf read process should be atomic.
  340. * We try to be atomic here, by restaring the read process,
  341. * if any of the high registers changed (overflew).
  342. */
  343. if (dev->dev->id.revision >= 3) {
  344. u32 low, high, high2;
  345. do {
  346. high = b43_read32(dev, B43_MMIO_REV3PLUS_TSF_HIGH);
  347. low = b43_read32(dev, B43_MMIO_REV3PLUS_TSF_LOW);
  348. high2 = b43_read32(dev, B43_MMIO_REV3PLUS_TSF_HIGH);
  349. } while (unlikely(high != high2));
  350. *tsf = high;
  351. *tsf <<= 32;
  352. *tsf |= low;
  353. } else {
  354. u64 tmp;
  355. u16 v0, v1, v2, v3;
  356. u16 test1, test2, test3;
  357. do {
  358. v3 = b43_read16(dev, B43_MMIO_TSF_3);
  359. v2 = b43_read16(dev, B43_MMIO_TSF_2);
  360. v1 = b43_read16(dev, B43_MMIO_TSF_1);
  361. v0 = b43_read16(dev, B43_MMIO_TSF_0);
  362. test3 = b43_read16(dev, B43_MMIO_TSF_3);
  363. test2 = b43_read16(dev, B43_MMIO_TSF_2);
  364. test1 = b43_read16(dev, B43_MMIO_TSF_1);
  365. } while (v3 != test3 || v2 != test2 || v1 != test1);
  366. *tsf = v3;
  367. *tsf <<= 48;
  368. tmp = v2;
  369. tmp <<= 32;
  370. *tsf |= tmp;
  371. tmp = v1;
  372. tmp <<= 16;
  373. *tsf |= tmp;
  374. *tsf |= v0;
  375. }
  376. }
  377. static void b43_time_lock(struct b43_wldev *dev)
  378. {
  379. u32 macctl;
  380. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  381. macctl |= B43_MACCTL_TBTTHOLD;
  382. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  383. /* Commit the write */
  384. b43_read32(dev, B43_MMIO_MACCTL);
  385. }
  386. static void b43_time_unlock(struct b43_wldev *dev)
  387. {
  388. u32 macctl;
  389. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  390. macctl &= ~B43_MACCTL_TBTTHOLD;
  391. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  392. /* Commit the write */
  393. b43_read32(dev, B43_MMIO_MACCTL);
  394. }
  395. static void b43_tsf_write_locked(struct b43_wldev *dev, u64 tsf)
  396. {
  397. /* Be careful with the in-progress timer.
  398. * First zero out the low register, so we have a full
  399. * register-overflow duration to complete the operation.
  400. */
  401. if (dev->dev->id.revision >= 3) {
  402. u32 lo = (tsf & 0x00000000FFFFFFFFULL);
  403. u32 hi = (tsf & 0xFFFFFFFF00000000ULL) >> 32;
  404. b43_write32(dev, B43_MMIO_REV3PLUS_TSF_LOW, 0);
  405. mmiowb();
  406. b43_write32(dev, B43_MMIO_REV3PLUS_TSF_HIGH, hi);
  407. mmiowb();
  408. b43_write32(dev, B43_MMIO_REV3PLUS_TSF_LOW, lo);
  409. } else {
  410. u16 v0 = (tsf & 0x000000000000FFFFULL);
  411. u16 v1 = (tsf & 0x00000000FFFF0000ULL) >> 16;
  412. u16 v2 = (tsf & 0x0000FFFF00000000ULL) >> 32;
  413. u16 v3 = (tsf & 0xFFFF000000000000ULL) >> 48;
  414. b43_write16(dev, B43_MMIO_TSF_0, 0);
  415. mmiowb();
  416. b43_write16(dev, B43_MMIO_TSF_3, v3);
  417. mmiowb();
  418. b43_write16(dev, B43_MMIO_TSF_2, v2);
  419. mmiowb();
  420. b43_write16(dev, B43_MMIO_TSF_1, v1);
  421. mmiowb();
  422. b43_write16(dev, B43_MMIO_TSF_0, v0);
  423. }
  424. }
  425. void b43_tsf_write(struct b43_wldev *dev, u64 tsf)
  426. {
  427. b43_time_lock(dev);
  428. b43_tsf_write_locked(dev, tsf);
  429. b43_time_unlock(dev);
  430. }
  431. static
  432. void b43_macfilter_set(struct b43_wldev *dev, u16 offset, const u8 * mac)
  433. {
  434. static const u8 zero_addr[ETH_ALEN] = { 0 };
  435. u16 data;
  436. if (!mac)
  437. mac = zero_addr;
  438. offset |= 0x0020;
  439. b43_write16(dev, B43_MMIO_MACFILTER_CONTROL, offset);
  440. data = mac[0];
  441. data |= mac[1] << 8;
  442. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  443. data = mac[2];
  444. data |= mac[3] << 8;
  445. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  446. data = mac[4];
  447. data |= mac[5] << 8;
  448. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  449. }
  450. static void b43_write_mac_bssid_templates(struct b43_wldev *dev)
  451. {
  452. const u8 *mac;
  453. const u8 *bssid;
  454. u8 mac_bssid[ETH_ALEN * 2];
  455. int i;
  456. u32 tmp;
  457. bssid = dev->wl->bssid;
  458. mac = dev->wl->mac_addr;
  459. b43_macfilter_set(dev, B43_MACFILTER_BSSID, bssid);
  460. memcpy(mac_bssid, mac, ETH_ALEN);
  461. memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
  462. /* Write our MAC address and BSSID to template ram */
  463. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32)) {
  464. tmp = (u32) (mac_bssid[i + 0]);
  465. tmp |= (u32) (mac_bssid[i + 1]) << 8;
  466. tmp |= (u32) (mac_bssid[i + 2]) << 16;
  467. tmp |= (u32) (mac_bssid[i + 3]) << 24;
  468. b43_ram_write(dev, 0x20 + i, tmp);
  469. }
  470. }
  471. static void b43_upload_card_macaddress(struct b43_wldev *dev)
  472. {
  473. b43_write_mac_bssid_templates(dev);
  474. b43_macfilter_set(dev, B43_MACFILTER_SELF, dev->wl->mac_addr);
  475. }
  476. static void b43_set_slot_time(struct b43_wldev *dev, u16 slot_time)
  477. {
  478. /* slot_time is in usec. */
  479. if (dev->phy.type != B43_PHYTYPE_G)
  480. return;
  481. b43_write16(dev, 0x684, 510 + slot_time);
  482. b43_shm_write16(dev, B43_SHM_SHARED, 0x0010, slot_time);
  483. }
  484. static void b43_short_slot_timing_enable(struct b43_wldev *dev)
  485. {
  486. b43_set_slot_time(dev, 9);
  487. dev->short_slot = 1;
  488. }
  489. static void b43_short_slot_timing_disable(struct b43_wldev *dev)
  490. {
  491. b43_set_slot_time(dev, 20);
  492. dev->short_slot = 0;
  493. }
  494. /* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
  495. * Returns the _previously_ enabled IRQ mask.
  496. */
  497. static inline u32 b43_interrupt_enable(struct b43_wldev *dev, u32 mask)
  498. {
  499. u32 old_mask;
  500. old_mask = b43_read32(dev, B43_MMIO_GEN_IRQ_MASK);
  501. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, old_mask | mask);
  502. return old_mask;
  503. }
  504. /* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
  505. * Returns the _previously_ enabled IRQ mask.
  506. */
  507. static inline u32 b43_interrupt_disable(struct b43_wldev *dev, u32 mask)
  508. {
  509. u32 old_mask;
  510. old_mask = b43_read32(dev, B43_MMIO_GEN_IRQ_MASK);
  511. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
  512. return old_mask;
  513. }
  514. /* Synchronize IRQ top- and bottom-half.
  515. * IRQs must be masked before calling this.
  516. * This must not be called with the irq_lock held.
  517. */
  518. static void b43_synchronize_irq(struct b43_wldev *dev)
  519. {
  520. synchronize_irq(dev->dev->irq);
  521. tasklet_kill(&dev->isr_tasklet);
  522. }
  523. /* DummyTransmission function, as documented on
  524. * http://bcm-specs.sipsolutions.net/DummyTransmission
  525. */
  526. void b43_dummy_transmission(struct b43_wldev *dev)
  527. {
  528. struct b43_phy *phy = &dev->phy;
  529. unsigned int i, max_loop;
  530. u16 value;
  531. u32 buffer[5] = {
  532. 0x00000000,
  533. 0x00D40000,
  534. 0x00000000,
  535. 0x01000000,
  536. 0x00000000,
  537. };
  538. switch (phy->type) {
  539. case B43_PHYTYPE_A:
  540. max_loop = 0x1E;
  541. buffer[0] = 0x000201CC;
  542. break;
  543. case B43_PHYTYPE_B:
  544. case B43_PHYTYPE_G:
  545. max_loop = 0xFA;
  546. buffer[0] = 0x000B846E;
  547. break;
  548. default:
  549. B43_WARN_ON(1);
  550. return;
  551. }
  552. for (i = 0; i < 5; i++)
  553. b43_ram_write(dev, i * 4, buffer[i]);
  554. /* Commit writes */
  555. b43_read32(dev, B43_MMIO_MACCTL);
  556. b43_write16(dev, 0x0568, 0x0000);
  557. b43_write16(dev, 0x07C0, 0x0000);
  558. value = ((phy->type == B43_PHYTYPE_A) ? 1 : 0);
  559. b43_write16(dev, 0x050C, value);
  560. b43_write16(dev, 0x0508, 0x0000);
  561. b43_write16(dev, 0x050A, 0x0000);
  562. b43_write16(dev, 0x054C, 0x0000);
  563. b43_write16(dev, 0x056A, 0x0014);
  564. b43_write16(dev, 0x0568, 0x0826);
  565. b43_write16(dev, 0x0500, 0x0000);
  566. b43_write16(dev, 0x0502, 0x0030);
  567. if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
  568. b43_radio_write16(dev, 0x0051, 0x0017);
  569. for (i = 0x00; i < max_loop; i++) {
  570. value = b43_read16(dev, 0x050E);
  571. if (value & 0x0080)
  572. break;
  573. udelay(10);
  574. }
  575. for (i = 0x00; i < 0x0A; i++) {
  576. value = b43_read16(dev, 0x050E);
  577. if (value & 0x0400)
  578. break;
  579. udelay(10);
  580. }
  581. for (i = 0x00; i < 0x0A; i++) {
  582. value = b43_read16(dev, 0x0690);
  583. if (!(value & 0x0100))
  584. break;
  585. udelay(10);
  586. }
  587. if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
  588. b43_radio_write16(dev, 0x0051, 0x0037);
  589. }
  590. static void key_write(struct b43_wldev *dev,
  591. u8 index, u8 algorithm, const u8 * key)
  592. {
  593. unsigned int i;
  594. u32 offset;
  595. u16 value;
  596. u16 kidx;
  597. /* Key index/algo block */
  598. kidx = b43_kidx_to_fw(dev, index);
  599. value = ((kidx << 4) | algorithm);
  600. b43_shm_write16(dev, B43_SHM_SHARED,
  601. B43_SHM_SH_KEYIDXBLOCK + (kidx * 2), value);
  602. /* Write the key to the Key Table Pointer offset */
  603. offset = dev->ktp + (index * B43_SEC_KEYSIZE);
  604. for (i = 0; i < B43_SEC_KEYSIZE; i += 2) {
  605. value = key[i];
  606. value |= (u16) (key[i + 1]) << 8;
  607. b43_shm_write16(dev, B43_SHM_SHARED, offset + i, value);
  608. }
  609. }
  610. static void keymac_write(struct b43_wldev *dev, u8 index, const u8 * addr)
  611. {
  612. u32 addrtmp[2] = { 0, 0, };
  613. u8 per_sta_keys_start = 8;
  614. if (b43_new_kidx_api(dev))
  615. per_sta_keys_start = 4;
  616. B43_WARN_ON(index < per_sta_keys_start);
  617. /* We have two default TX keys and possibly two default RX keys.
  618. * Physical mac 0 is mapped to physical key 4 or 8, depending
  619. * on the firmware version.
  620. * So we must adjust the index here.
  621. */
  622. index -= per_sta_keys_start;
  623. if (addr) {
  624. addrtmp[0] = addr[0];
  625. addrtmp[0] |= ((u32) (addr[1]) << 8);
  626. addrtmp[0] |= ((u32) (addr[2]) << 16);
  627. addrtmp[0] |= ((u32) (addr[3]) << 24);
  628. addrtmp[1] = addr[4];
  629. addrtmp[1] |= ((u32) (addr[5]) << 8);
  630. }
  631. if (dev->dev->id.revision >= 5) {
  632. /* Receive match transmitter address mechanism */
  633. b43_shm_write32(dev, B43_SHM_RCMTA,
  634. (index * 2) + 0, addrtmp[0]);
  635. b43_shm_write16(dev, B43_SHM_RCMTA,
  636. (index * 2) + 1, addrtmp[1]);
  637. } else {
  638. /* RXE (Receive Engine) and
  639. * PSM (Programmable State Machine) mechanism
  640. */
  641. if (index < 8) {
  642. /* TODO write to RCM 16, 19, 22 and 25 */
  643. } else {
  644. b43_shm_write32(dev, B43_SHM_SHARED,
  645. B43_SHM_SH_PSM + (index * 6) + 0,
  646. addrtmp[0]);
  647. b43_shm_write16(dev, B43_SHM_SHARED,
  648. B43_SHM_SH_PSM + (index * 6) + 4,
  649. addrtmp[1]);
  650. }
  651. }
  652. }
  653. static void do_key_write(struct b43_wldev *dev,
  654. u8 index, u8 algorithm,
  655. const u8 * key, size_t key_len, const u8 * mac_addr)
  656. {
  657. u8 buf[B43_SEC_KEYSIZE] = { 0, };
  658. u8 per_sta_keys_start = 8;
  659. if (b43_new_kidx_api(dev))
  660. per_sta_keys_start = 4;
  661. B43_WARN_ON(index >= dev->max_nr_keys);
  662. B43_WARN_ON(key_len > B43_SEC_KEYSIZE);
  663. if (index >= per_sta_keys_start)
  664. keymac_write(dev, index, NULL); /* First zero out mac. */
  665. if (key)
  666. memcpy(buf, key, key_len);
  667. key_write(dev, index, algorithm, buf);
  668. if (index >= per_sta_keys_start)
  669. keymac_write(dev, index, mac_addr);
  670. dev->key[index].algorithm = algorithm;
  671. }
  672. static int b43_key_write(struct b43_wldev *dev,
  673. int index, u8 algorithm,
  674. const u8 * key, size_t key_len,
  675. const u8 * mac_addr,
  676. struct ieee80211_key_conf *keyconf)
  677. {
  678. int i;
  679. int sta_keys_start;
  680. if (key_len > B43_SEC_KEYSIZE)
  681. return -EINVAL;
  682. for (i = 0; i < dev->max_nr_keys; i++) {
  683. /* Check that we don't already have this key. */
  684. B43_WARN_ON(dev->key[i].keyconf == keyconf);
  685. }
  686. if (index < 0) {
  687. /* Either pairwise key or address is 00:00:00:00:00:00
  688. * for transmit-only keys. Search the index. */
  689. if (b43_new_kidx_api(dev))
  690. sta_keys_start = 4;
  691. else
  692. sta_keys_start = 8;
  693. for (i = sta_keys_start; i < dev->max_nr_keys; i++) {
  694. if (!dev->key[i].keyconf) {
  695. /* found empty */
  696. index = i;
  697. break;
  698. }
  699. }
  700. if (index < 0) {
  701. b43err(dev->wl, "Out of hardware key memory\n");
  702. return -ENOSPC;
  703. }
  704. } else
  705. B43_WARN_ON(index > 3);
  706. do_key_write(dev, index, algorithm, key, key_len, mac_addr);
  707. if ((index <= 3) && !b43_new_kidx_api(dev)) {
  708. /* Default RX key */
  709. B43_WARN_ON(mac_addr);
  710. do_key_write(dev, index + 4, algorithm, key, key_len, NULL);
  711. }
  712. keyconf->hw_key_idx = index;
  713. dev->key[index].keyconf = keyconf;
  714. return 0;
  715. }
  716. static int b43_key_clear(struct b43_wldev *dev, int index)
  717. {
  718. if (B43_WARN_ON((index < 0) || (index >= dev->max_nr_keys)))
  719. return -EINVAL;
  720. do_key_write(dev, index, B43_SEC_ALGO_NONE,
  721. NULL, B43_SEC_KEYSIZE, NULL);
  722. if ((index <= 3) && !b43_new_kidx_api(dev)) {
  723. do_key_write(dev, index + 4, B43_SEC_ALGO_NONE,
  724. NULL, B43_SEC_KEYSIZE, NULL);
  725. }
  726. dev->key[index].keyconf = NULL;
  727. return 0;
  728. }
  729. static void b43_clear_keys(struct b43_wldev *dev)
  730. {
  731. int i;
  732. for (i = 0; i < dev->max_nr_keys; i++)
  733. b43_key_clear(dev, i);
  734. }
  735. void b43_power_saving_ctl_bits(struct b43_wldev *dev, unsigned int ps_flags)
  736. {
  737. u32 macctl;
  738. u16 ucstat;
  739. bool hwps;
  740. bool awake;
  741. int i;
  742. B43_WARN_ON((ps_flags & B43_PS_ENABLED) &&
  743. (ps_flags & B43_PS_DISABLED));
  744. B43_WARN_ON((ps_flags & B43_PS_AWAKE) && (ps_flags & B43_PS_ASLEEP));
  745. if (ps_flags & B43_PS_ENABLED) {
  746. hwps = 1;
  747. } else if (ps_flags & B43_PS_DISABLED) {
  748. hwps = 0;
  749. } else {
  750. //TODO: If powersave is not off and FIXME is not set and we are not in adhoc
  751. // and thus is not an AP and we are associated, set bit 25
  752. }
  753. if (ps_flags & B43_PS_AWAKE) {
  754. awake = 1;
  755. } else if (ps_flags & B43_PS_ASLEEP) {
  756. awake = 0;
  757. } else {
  758. //TODO: If the device is awake or this is an AP, or we are scanning, or FIXME,
  759. // or we are associated, or FIXME, or the latest PS-Poll packet sent was
  760. // successful, set bit26
  761. }
  762. /* FIXME: For now we force awake-on and hwps-off */
  763. hwps = 0;
  764. awake = 1;
  765. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  766. if (hwps)
  767. macctl |= B43_MACCTL_HWPS;
  768. else
  769. macctl &= ~B43_MACCTL_HWPS;
  770. if (awake)
  771. macctl |= B43_MACCTL_AWAKE;
  772. else
  773. macctl &= ~B43_MACCTL_AWAKE;
  774. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  775. /* Commit write */
  776. b43_read32(dev, B43_MMIO_MACCTL);
  777. if (awake && dev->dev->id.revision >= 5) {
  778. /* Wait for the microcode to wake up. */
  779. for (i = 0; i < 100; i++) {
  780. ucstat = b43_shm_read16(dev, B43_SHM_SHARED,
  781. B43_SHM_SH_UCODESTAT);
  782. if (ucstat != B43_SHM_SH_UCODESTAT_SLEEP)
  783. break;
  784. udelay(10);
  785. }
  786. }
  787. }
  788. /* Turn the Analog ON/OFF */
  789. static void b43_switch_analog(struct b43_wldev *dev, int on)
  790. {
  791. b43_write16(dev, B43_MMIO_PHY0, on ? 0 : 0xF4);
  792. }
  793. void b43_wireless_core_reset(struct b43_wldev *dev, u32 flags)
  794. {
  795. u32 tmslow;
  796. u32 macctl;
  797. flags |= B43_TMSLOW_PHYCLKEN;
  798. flags |= B43_TMSLOW_PHYRESET;
  799. ssb_device_enable(dev->dev, flags);
  800. msleep(2); /* Wait for the PLL to turn on. */
  801. /* Now take the PHY out of Reset again */
  802. tmslow = ssb_read32(dev->dev, SSB_TMSLOW);
  803. tmslow |= SSB_TMSLOW_FGC;
  804. tmslow &= ~B43_TMSLOW_PHYRESET;
  805. ssb_write32(dev->dev, SSB_TMSLOW, tmslow);
  806. ssb_read32(dev->dev, SSB_TMSLOW); /* flush */
  807. msleep(1);
  808. tmslow &= ~SSB_TMSLOW_FGC;
  809. ssb_write32(dev->dev, SSB_TMSLOW, tmslow);
  810. ssb_read32(dev->dev, SSB_TMSLOW); /* flush */
  811. msleep(1);
  812. /* Turn Analog ON */
  813. b43_switch_analog(dev, 1);
  814. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  815. macctl &= ~B43_MACCTL_GMODE;
  816. if (flags & B43_TMSLOW_GMODE)
  817. macctl |= B43_MACCTL_GMODE;
  818. macctl |= B43_MACCTL_IHR_ENABLED;
  819. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  820. }
  821. static void handle_irq_transmit_status(struct b43_wldev *dev)
  822. {
  823. u32 v0, v1;
  824. u16 tmp;
  825. struct b43_txstatus stat;
  826. while (1) {
  827. v0 = b43_read32(dev, B43_MMIO_XMITSTAT_0);
  828. if (!(v0 & 0x00000001))
  829. break;
  830. v1 = b43_read32(dev, B43_MMIO_XMITSTAT_1);
  831. stat.cookie = (v0 >> 16);
  832. stat.seq = (v1 & 0x0000FFFF);
  833. stat.phy_stat = ((v1 & 0x00FF0000) >> 16);
  834. tmp = (v0 & 0x0000FFFF);
  835. stat.frame_count = ((tmp & 0xF000) >> 12);
  836. stat.rts_count = ((tmp & 0x0F00) >> 8);
  837. stat.supp_reason = ((tmp & 0x001C) >> 2);
  838. stat.pm_indicated = !!(tmp & 0x0080);
  839. stat.intermediate = !!(tmp & 0x0040);
  840. stat.for_ampdu = !!(tmp & 0x0020);
  841. stat.acked = !!(tmp & 0x0002);
  842. b43_handle_txstatus(dev, &stat);
  843. }
  844. }
  845. static void drain_txstatus_queue(struct b43_wldev *dev)
  846. {
  847. u32 dummy;
  848. if (dev->dev->id.revision < 5)
  849. return;
  850. /* Read all entries from the microcode TXstatus FIFO
  851. * and throw them away.
  852. */
  853. while (1) {
  854. dummy = b43_read32(dev, B43_MMIO_XMITSTAT_0);
  855. if (!(dummy & 0x00000001))
  856. break;
  857. dummy = b43_read32(dev, B43_MMIO_XMITSTAT_1);
  858. }
  859. }
  860. static u32 b43_jssi_read(struct b43_wldev *dev)
  861. {
  862. u32 val = 0;
  863. val = b43_shm_read16(dev, B43_SHM_SHARED, 0x08A);
  864. val <<= 16;
  865. val |= b43_shm_read16(dev, B43_SHM_SHARED, 0x088);
  866. return val;
  867. }
  868. static void b43_jssi_write(struct b43_wldev *dev, u32 jssi)
  869. {
  870. b43_shm_write16(dev, B43_SHM_SHARED, 0x088, (jssi & 0x0000FFFF));
  871. b43_shm_write16(dev, B43_SHM_SHARED, 0x08A, (jssi & 0xFFFF0000) >> 16);
  872. }
  873. static void b43_generate_noise_sample(struct b43_wldev *dev)
  874. {
  875. b43_jssi_write(dev, 0x7F7F7F7F);
  876. b43_write32(dev, B43_MMIO_STATUS2_BITFIELD,
  877. b43_read32(dev, B43_MMIO_STATUS2_BITFIELD)
  878. | (1 << 4));
  879. B43_WARN_ON(dev->noisecalc.channel_at_start != dev->phy.channel);
  880. }
  881. static void b43_calculate_link_quality(struct b43_wldev *dev)
  882. {
  883. /* Top half of Link Quality calculation. */
  884. if (dev->noisecalc.calculation_running)
  885. return;
  886. dev->noisecalc.channel_at_start = dev->phy.channel;
  887. dev->noisecalc.calculation_running = 1;
  888. dev->noisecalc.nr_samples = 0;
  889. b43_generate_noise_sample(dev);
  890. }
  891. static void handle_irq_noise(struct b43_wldev *dev)
  892. {
  893. struct b43_phy *phy = &dev->phy;
  894. u16 tmp;
  895. u8 noise[4];
  896. u8 i, j;
  897. s32 average;
  898. /* Bottom half of Link Quality calculation. */
  899. B43_WARN_ON(!dev->noisecalc.calculation_running);
  900. if (dev->noisecalc.channel_at_start != phy->channel)
  901. goto drop_calculation;
  902. *((__le32 *)noise) = cpu_to_le32(b43_jssi_read(dev));
  903. if (noise[0] == 0x7F || noise[1] == 0x7F ||
  904. noise[2] == 0x7F || noise[3] == 0x7F)
  905. goto generate_new;
  906. /* Get the noise samples. */
  907. B43_WARN_ON(dev->noisecalc.nr_samples >= 8);
  908. i = dev->noisecalc.nr_samples;
  909. noise[0] = limit_value(noise[0], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  910. noise[1] = limit_value(noise[1], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  911. noise[2] = limit_value(noise[2], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  912. noise[3] = limit_value(noise[3], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  913. dev->noisecalc.samples[i][0] = phy->nrssi_lt[noise[0]];
  914. dev->noisecalc.samples[i][1] = phy->nrssi_lt[noise[1]];
  915. dev->noisecalc.samples[i][2] = phy->nrssi_lt[noise[2]];
  916. dev->noisecalc.samples[i][3] = phy->nrssi_lt[noise[3]];
  917. dev->noisecalc.nr_samples++;
  918. if (dev->noisecalc.nr_samples == 8) {
  919. /* Calculate the Link Quality by the noise samples. */
  920. average = 0;
  921. for (i = 0; i < 8; i++) {
  922. for (j = 0; j < 4; j++)
  923. average += dev->noisecalc.samples[i][j];
  924. }
  925. average /= (8 * 4);
  926. average *= 125;
  927. average += 64;
  928. average /= 128;
  929. tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x40C);
  930. tmp = (tmp / 128) & 0x1F;
  931. if (tmp >= 8)
  932. average += 2;
  933. else
  934. average -= 25;
  935. if (tmp == 8)
  936. average -= 72;
  937. else
  938. average -= 48;
  939. dev->stats.link_noise = average;
  940. drop_calculation:
  941. dev->noisecalc.calculation_running = 0;
  942. return;
  943. }
  944. generate_new:
  945. b43_generate_noise_sample(dev);
  946. }
  947. static void handle_irq_tbtt_indication(struct b43_wldev *dev)
  948. {
  949. if (b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP)) {
  950. ///TODO: PS TBTT
  951. } else {
  952. if (1 /*FIXME: the last PSpoll frame was sent successfully */ )
  953. b43_power_saving_ctl_bits(dev, 0);
  954. }
  955. dev->reg124_set_0x4 = 0;
  956. if (b43_is_mode(dev->wl, IEEE80211_IF_TYPE_IBSS))
  957. dev->reg124_set_0x4 = 1;
  958. }
  959. static void handle_irq_atim_end(struct b43_wldev *dev)
  960. {
  961. if (!dev->reg124_set_0x4 /*FIXME rename this variable */ )
  962. return;
  963. b43_write32(dev, B43_MMIO_STATUS2_BITFIELD,
  964. b43_read32(dev, B43_MMIO_STATUS2_BITFIELD)
  965. | 0x4);
  966. }
  967. static void handle_irq_pmq(struct b43_wldev *dev)
  968. {
  969. u32 tmp;
  970. //TODO: AP mode.
  971. while (1) {
  972. tmp = b43_read32(dev, B43_MMIO_PS_STATUS);
  973. if (!(tmp & 0x00000008))
  974. break;
  975. }
  976. /* 16bit write is odd, but correct. */
  977. b43_write16(dev, B43_MMIO_PS_STATUS, 0x0002);
  978. }
  979. static void b43_write_template_common(struct b43_wldev *dev,
  980. const u8 * data, u16 size,
  981. u16 ram_offset,
  982. u16 shm_size_offset, u8 rate)
  983. {
  984. u32 i, tmp;
  985. struct b43_plcp_hdr4 plcp;
  986. plcp.data = 0;
  987. b43_generate_plcp_hdr(&plcp, size + FCS_LEN, rate);
  988. b43_ram_write(dev, ram_offset, le32_to_cpu(plcp.data));
  989. ram_offset += sizeof(u32);
  990. /* The PLCP is 6 bytes long, but we only wrote 4 bytes, yet.
  991. * So leave the first two bytes of the next write blank.
  992. */
  993. tmp = (u32) (data[0]) << 16;
  994. tmp |= (u32) (data[1]) << 24;
  995. b43_ram_write(dev, ram_offset, tmp);
  996. ram_offset += sizeof(u32);
  997. for (i = 2; i < size; i += sizeof(u32)) {
  998. tmp = (u32) (data[i + 0]);
  999. if (i + 1 < size)
  1000. tmp |= (u32) (data[i + 1]) << 8;
  1001. if (i + 2 < size)
  1002. tmp |= (u32) (data[i + 2]) << 16;
  1003. if (i + 3 < size)
  1004. tmp |= (u32) (data[i + 3]) << 24;
  1005. b43_ram_write(dev, ram_offset + i - 2, tmp);
  1006. }
  1007. b43_shm_write16(dev, B43_SHM_SHARED, shm_size_offset,
  1008. size + sizeof(struct b43_plcp_hdr6));
  1009. }
  1010. static void b43_write_beacon_template(struct b43_wldev *dev,
  1011. u16 ram_offset,
  1012. u16 shm_size_offset, u8 rate)
  1013. {
  1014. int len;
  1015. const u8 *data;
  1016. B43_WARN_ON(!dev->cached_beacon);
  1017. len = min((size_t) dev->cached_beacon->len,
  1018. 0x200 - sizeof(struct b43_plcp_hdr6));
  1019. data = (const u8 *)(dev->cached_beacon->data);
  1020. b43_write_template_common(dev, data,
  1021. len, ram_offset, shm_size_offset, rate);
  1022. }
  1023. static void b43_write_probe_resp_plcp(struct b43_wldev *dev,
  1024. u16 shm_offset, u16 size, u8 rate)
  1025. {
  1026. struct b43_plcp_hdr4 plcp;
  1027. u32 tmp;
  1028. __le16 dur;
  1029. plcp.data = 0;
  1030. b43_generate_plcp_hdr(&plcp, size + FCS_LEN, rate);
  1031. dur = ieee80211_generic_frame_duration(dev->wl->hw,
  1032. dev->wl->if_id, size,
  1033. B43_RATE_TO_BASE100KBPS(rate));
  1034. /* Write PLCP in two parts and timing for packet transfer */
  1035. tmp = le32_to_cpu(plcp.data);
  1036. b43_shm_write16(dev, B43_SHM_SHARED, shm_offset, tmp & 0xFFFF);
  1037. b43_shm_write16(dev, B43_SHM_SHARED, shm_offset + 2, tmp >> 16);
  1038. b43_shm_write16(dev, B43_SHM_SHARED, shm_offset + 6, le16_to_cpu(dur));
  1039. }
  1040. /* Instead of using custom probe response template, this function
  1041. * just patches custom beacon template by:
  1042. * 1) Changing packet type
  1043. * 2) Patching duration field
  1044. * 3) Stripping TIM
  1045. */
  1046. static u8 *b43_generate_probe_resp(struct b43_wldev *dev,
  1047. u16 * dest_size, u8 rate)
  1048. {
  1049. const u8 *src_data;
  1050. u8 *dest_data;
  1051. u16 src_size, elem_size, src_pos, dest_pos;
  1052. __le16 dur;
  1053. struct ieee80211_hdr *hdr;
  1054. B43_WARN_ON(!dev->cached_beacon);
  1055. src_size = dev->cached_beacon->len;
  1056. src_data = (const u8 *)dev->cached_beacon->data;
  1057. if (unlikely(src_size < 0x24)) {
  1058. b43dbg(dev->wl, "b43_generate_probe_resp: " "invalid beacon\n");
  1059. return NULL;
  1060. }
  1061. dest_data = kmalloc(src_size, GFP_ATOMIC);
  1062. if (unlikely(!dest_data))
  1063. return NULL;
  1064. /* 0x24 is offset of first variable-len Information-Element
  1065. * in beacon frame.
  1066. */
  1067. memcpy(dest_data, src_data, 0x24);
  1068. src_pos = dest_pos = 0x24;
  1069. for (; src_pos < src_size - 2; src_pos += elem_size) {
  1070. elem_size = src_data[src_pos + 1] + 2;
  1071. if (src_data[src_pos] != 0x05) { /* TIM */
  1072. memcpy(dest_data + dest_pos, src_data + src_pos,
  1073. elem_size);
  1074. dest_pos += elem_size;
  1075. }
  1076. }
  1077. *dest_size = dest_pos;
  1078. hdr = (struct ieee80211_hdr *)dest_data;
  1079. /* Set the frame control. */
  1080. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1081. IEEE80211_STYPE_PROBE_RESP);
  1082. dur = ieee80211_generic_frame_duration(dev->wl->hw,
  1083. dev->wl->if_id, *dest_size,
  1084. B43_RATE_TO_BASE100KBPS(rate));
  1085. hdr->duration_id = dur;
  1086. return dest_data;
  1087. }
  1088. static void b43_write_probe_resp_template(struct b43_wldev *dev,
  1089. u16 ram_offset,
  1090. u16 shm_size_offset, u8 rate)
  1091. {
  1092. u8 *probe_resp_data;
  1093. u16 size;
  1094. B43_WARN_ON(!dev->cached_beacon);
  1095. size = dev->cached_beacon->len;
  1096. probe_resp_data = b43_generate_probe_resp(dev, &size, rate);
  1097. if (unlikely(!probe_resp_data))
  1098. return;
  1099. /* Looks like PLCP headers plus packet timings are stored for
  1100. * all possible basic rates
  1101. */
  1102. b43_write_probe_resp_plcp(dev, 0x31A, size, B43_CCK_RATE_1MB);
  1103. b43_write_probe_resp_plcp(dev, 0x32C, size, B43_CCK_RATE_2MB);
  1104. b43_write_probe_resp_plcp(dev, 0x33E, size, B43_CCK_RATE_5MB);
  1105. b43_write_probe_resp_plcp(dev, 0x350, size, B43_CCK_RATE_11MB);
  1106. size = min((size_t) size, 0x200 - sizeof(struct b43_plcp_hdr6));
  1107. b43_write_template_common(dev, probe_resp_data,
  1108. size, ram_offset, shm_size_offset, rate);
  1109. kfree(probe_resp_data);
  1110. }
  1111. static int b43_refresh_cached_beacon(struct b43_wldev *dev,
  1112. struct sk_buff *beacon)
  1113. {
  1114. if (dev->cached_beacon)
  1115. kfree_skb(dev->cached_beacon);
  1116. dev->cached_beacon = beacon;
  1117. return 0;
  1118. }
  1119. static void b43_update_templates(struct b43_wldev *dev)
  1120. {
  1121. u32 status;
  1122. B43_WARN_ON(!dev->cached_beacon);
  1123. b43_write_beacon_template(dev, 0x68, 0x18, B43_CCK_RATE_1MB);
  1124. b43_write_beacon_template(dev, 0x468, 0x1A, B43_CCK_RATE_1MB);
  1125. b43_write_probe_resp_template(dev, 0x268, 0x4A, B43_CCK_RATE_11MB);
  1126. status = b43_read32(dev, B43_MMIO_STATUS2_BITFIELD);
  1127. status |= 0x03;
  1128. b43_write32(dev, B43_MMIO_STATUS2_BITFIELD, status);
  1129. }
  1130. static void b43_refresh_templates(struct b43_wldev *dev, struct sk_buff *beacon)
  1131. {
  1132. int err;
  1133. err = b43_refresh_cached_beacon(dev, beacon);
  1134. if (unlikely(err))
  1135. return;
  1136. b43_update_templates(dev);
  1137. }
  1138. static void b43_set_ssid(struct b43_wldev *dev, const u8 * ssid, u8 ssid_len)
  1139. {
  1140. u32 tmp;
  1141. u16 i, len;
  1142. len = min((u16) ssid_len, (u16) 0x100);
  1143. for (i = 0; i < len; i += sizeof(u32)) {
  1144. tmp = (u32) (ssid[i + 0]);
  1145. if (i + 1 < len)
  1146. tmp |= (u32) (ssid[i + 1]) << 8;
  1147. if (i + 2 < len)
  1148. tmp |= (u32) (ssid[i + 2]) << 16;
  1149. if (i + 3 < len)
  1150. tmp |= (u32) (ssid[i + 3]) << 24;
  1151. b43_shm_write32(dev, B43_SHM_SHARED, 0x380 + i, tmp);
  1152. }
  1153. b43_shm_write16(dev, B43_SHM_SHARED, 0x48, len);
  1154. }
  1155. static void b43_set_beacon_int(struct b43_wldev *dev, u16 beacon_int)
  1156. {
  1157. b43_time_lock(dev);
  1158. if (dev->dev->id.revision >= 3) {
  1159. b43_write32(dev, 0x188, (beacon_int << 16));
  1160. } else {
  1161. b43_write16(dev, 0x606, (beacon_int >> 6));
  1162. b43_write16(dev, 0x610, beacon_int);
  1163. }
  1164. b43_time_unlock(dev);
  1165. }
  1166. static void handle_irq_beacon(struct b43_wldev *dev)
  1167. {
  1168. u32 status;
  1169. if (!b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
  1170. return;
  1171. dev->irq_savedstate &= ~B43_IRQ_BEACON;
  1172. status = b43_read32(dev, B43_MMIO_STATUS2_BITFIELD);
  1173. if (!dev->cached_beacon || ((status & 0x1) && (status & 0x2))) {
  1174. /* ACK beacon IRQ. */
  1175. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, B43_IRQ_BEACON);
  1176. dev->irq_savedstate |= B43_IRQ_BEACON;
  1177. if (dev->cached_beacon)
  1178. kfree_skb(dev->cached_beacon);
  1179. dev->cached_beacon = NULL;
  1180. return;
  1181. }
  1182. if (!(status & 0x1)) {
  1183. b43_write_beacon_template(dev, 0x68, 0x18, B43_CCK_RATE_1MB);
  1184. status |= 0x1;
  1185. b43_write32(dev, B43_MMIO_STATUS2_BITFIELD, status);
  1186. }
  1187. if (!(status & 0x2)) {
  1188. b43_write_beacon_template(dev, 0x468, 0x1A, B43_CCK_RATE_1MB);
  1189. status |= 0x2;
  1190. b43_write32(dev, B43_MMIO_STATUS2_BITFIELD, status);
  1191. }
  1192. }
  1193. static void handle_irq_ucode_debug(struct b43_wldev *dev)
  1194. {
  1195. //TODO
  1196. }
  1197. /* Interrupt handler bottom-half */
  1198. static void b43_interrupt_tasklet(struct b43_wldev *dev)
  1199. {
  1200. u32 reason;
  1201. u32 dma_reason[ARRAY_SIZE(dev->dma_reason)];
  1202. u32 merged_dma_reason = 0;
  1203. int i;
  1204. unsigned long flags;
  1205. spin_lock_irqsave(&dev->wl->irq_lock, flags);
  1206. B43_WARN_ON(b43_status(dev) != B43_STAT_STARTED);
  1207. reason = dev->irq_reason;
  1208. for (i = 0; i < ARRAY_SIZE(dma_reason); i++) {
  1209. dma_reason[i] = dev->dma_reason[i];
  1210. merged_dma_reason |= dma_reason[i];
  1211. }
  1212. if (unlikely(reason & B43_IRQ_MAC_TXERR))
  1213. b43err(dev->wl, "MAC transmission error\n");
  1214. if (unlikely(reason & B43_IRQ_PHY_TXERR))
  1215. b43err(dev->wl, "PHY transmission error\n");
  1216. if (unlikely(merged_dma_reason & (B43_DMAIRQ_FATALMASK |
  1217. B43_DMAIRQ_NONFATALMASK))) {
  1218. if (merged_dma_reason & B43_DMAIRQ_FATALMASK) {
  1219. b43err(dev->wl, "Fatal DMA error: "
  1220. "0x%08X, 0x%08X, 0x%08X, "
  1221. "0x%08X, 0x%08X, 0x%08X\n",
  1222. dma_reason[0], dma_reason[1],
  1223. dma_reason[2], dma_reason[3],
  1224. dma_reason[4], dma_reason[5]);
  1225. b43_controller_restart(dev, "DMA error");
  1226. mmiowb();
  1227. spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
  1228. return;
  1229. }
  1230. if (merged_dma_reason & B43_DMAIRQ_NONFATALMASK) {
  1231. b43err(dev->wl, "DMA error: "
  1232. "0x%08X, 0x%08X, 0x%08X, "
  1233. "0x%08X, 0x%08X, 0x%08X\n",
  1234. dma_reason[0], dma_reason[1],
  1235. dma_reason[2], dma_reason[3],
  1236. dma_reason[4], dma_reason[5]);
  1237. }
  1238. }
  1239. if (unlikely(reason & B43_IRQ_UCODE_DEBUG))
  1240. handle_irq_ucode_debug(dev);
  1241. if (reason & B43_IRQ_TBTT_INDI)
  1242. handle_irq_tbtt_indication(dev);
  1243. if (reason & B43_IRQ_ATIM_END)
  1244. handle_irq_atim_end(dev);
  1245. if (reason & B43_IRQ_BEACON)
  1246. handle_irq_beacon(dev);
  1247. if (reason & B43_IRQ_PMQ)
  1248. handle_irq_pmq(dev);
  1249. if (reason & B43_IRQ_TXFIFO_FLUSH_OK)
  1250. ;/* TODO */
  1251. if (reason & B43_IRQ_NOISESAMPLE_OK)
  1252. handle_irq_noise(dev);
  1253. /* Check the DMA reason registers for received data. */
  1254. if (dma_reason[0] & B43_DMAIRQ_RX_DONE) {
  1255. if (b43_using_pio(dev))
  1256. b43_pio_rx(dev->pio.queue0);
  1257. else
  1258. b43_dma_rx(dev->dma.rx_ring0);
  1259. }
  1260. B43_WARN_ON(dma_reason[1] & B43_DMAIRQ_RX_DONE);
  1261. B43_WARN_ON(dma_reason[2] & B43_DMAIRQ_RX_DONE);
  1262. if (dma_reason[3] & B43_DMAIRQ_RX_DONE) {
  1263. if (b43_using_pio(dev))
  1264. b43_pio_rx(dev->pio.queue3);
  1265. else
  1266. b43_dma_rx(dev->dma.rx_ring3);
  1267. }
  1268. B43_WARN_ON(dma_reason[4] & B43_DMAIRQ_RX_DONE);
  1269. B43_WARN_ON(dma_reason[5] & B43_DMAIRQ_RX_DONE);
  1270. if (reason & B43_IRQ_TX_OK)
  1271. handle_irq_transmit_status(dev);
  1272. b43_interrupt_enable(dev, dev->irq_savedstate);
  1273. mmiowb();
  1274. spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
  1275. }
  1276. static void pio_irq_workaround(struct b43_wldev *dev, u16 base, int queueidx)
  1277. {
  1278. u16 rxctl;
  1279. rxctl = b43_read16(dev, base + B43_PIO_RXCTL);
  1280. if (rxctl & B43_PIO_RXCTL_DATAAVAILABLE)
  1281. dev->dma_reason[queueidx] |= B43_DMAIRQ_RX_DONE;
  1282. else
  1283. dev->dma_reason[queueidx] &= ~B43_DMAIRQ_RX_DONE;
  1284. }
  1285. static void b43_interrupt_ack(struct b43_wldev *dev, u32 reason)
  1286. {
  1287. if (b43_using_pio(dev) &&
  1288. (dev->dev->id.revision < 3) &&
  1289. (!(reason & B43_IRQ_PIO_WORKAROUND))) {
  1290. /* Apply a PIO specific workaround to the dma_reasons */
  1291. pio_irq_workaround(dev, B43_MMIO_PIO1_BASE, 0);
  1292. pio_irq_workaround(dev, B43_MMIO_PIO2_BASE, 1);
  1293. pio_irq_workaround(dev, B43_MMIO_PIO3_BASE, 2);
  1294. pio_irq_workaround(dev, B43_MMIO_PIO4_BASE, 3);
  1295. }
  1296. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, reason);
  1297. b43_write32(dev, B43_MMIO_DMA0_REASON, dev->dma_reason[0]);
  1298. b43_write32(dev, B43_MMIO_DMA1_REASON, dev->dma_reason[1]);
  1299. b43_write32(dev, B43_MMIO_DMA2_REASON, dev->dma_reason[2]);
  1300. b43_write32(dev, B43_MMIO_DMA3_REASON, dev->dma_reason[3]);
  1301. b43_write32(dev, B43_MMIO_DMA4_REASON, dev->dma_reason[4]);
  1302. b43_write32(dev, B43_MMIO_DMA5_REASON, dev->dma_reason[5]);
  1303. }
  1304. /* Interrupt handler top-half */
  1305. static irqreturn_t b43_interrupt_handler(int irq, void *dev_id)
  1306. {
  1307. irqreturn_t ret = IRQ_NONE;
  1308. struct b43_wldev *dev = dev_id;
  1309. u32 reason;
  1310. if (!dev)
  1311. return IRQ_NONE;
  1312. spin_lock(&dev->wl->irq_lock);
  1313. if (b43_status(dev) < B43_STAT_STARTED)
  1314. goto out;
  1315. reason = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  1316. if (reason == 0xffffffff) /* shared IRQ */
  1317. goto out;
  1318. ret = IRQ_HANDLED;
  1319. reason &= b43_read32(dev, B43_MMIO_GEN_IRQ_MASK);
  1320. if (!reason)
  1321. goto out;
  1322. dev->dma_reason[0] = b43_read32(dev, B43_MMIO_DMA0_REASON)
  1323. & 0x0001DC00;
  1324. dev->dma_reason[1] = b43_read32(dev, B43_MMIO_DMA1_REASON)
  1325. & 0x0000DC00;
  1326. dev->dma_reason[2] = b43_read32(dev, B43_MMIO_DMA2_REASON)
  1327. & 0x0000DC00;
  1328. dev->dma_reason[3] = b43_read32(dev, B43_MMIO_DMA3_REASON)
  1329. & 0x0001DC00;
  1330. dev->dma_reason[4] = b43_read32(dev, B43_MMIO_DMA4_REASON)
  1331. & 0x0000DC00;
  1332. dev->dma_reason[5] = b43_read32(dev, B43_MMIO_DMA5_REASON)
  1333. & 0x0000DC00;
  1334. b43_interrupt_ack(dev, reason);
  1335. /* disable all IRQs. They are enabled again in the bottom half. */
  1336. dev->irq_savedstate = b43_interrupt_disable(dev, B43_IRQ_ALL);
  1337. /* save the reason code and call our bottom half. */
  1338. dev->irq_reason = reason;
  1339. tasklet_schedule(&dev->isr_tasklet);
  1340. out:
  1341. mmiowb();
  1342. spin_unlock(&dev->wl->irq_lock);
  1343. return ret;
  1344. }
  1345. static void b43_release_firmware(struct b43_wldev *dev)
  1346. {
  1347. release_firmware(dev->fw.ucode);
  1348. dev->fw.ucode = NULL;
  1349. release_firmware(dev->fw.pcm);
  1350. dev->fw.pcm = NULL;
  1351. release_firmware(dev->fw.initvals);
  1352. dev->fw.initvals = NULL;
  1353. release_firmware(dev->fw.initvals_band);
  1354. dev->fw.initvals_band = NULL;
  1355. }
  1356. static void b43_print_fw_helptext(struct b43_wl *wl)
  1357. {
  1358. b43err(wl, "You must go to "
  1359. "http://linuxwireless.org/en/users/Drivers/b43#devicefirmware "
  1360. "and download the correct firmware (version 4).\n");
  1361. }
  1362. static int do_request_fw(struct b43_wldev *dev,
  1363. const char *name,
  1364. const struct firmware **fw)
  1365. {
  1366. char path[sizeof(modparam_fwpostfix) + 32];
  1367. struct b43_fw_header *hdr;
  1368. u32 size;
  1369. int err;
  1370. if (!name)
  1371. return 0;
  1372. snprintf(path, ARRAY_SIZE(path),
  1373. "b43%s/%s.fw",
  1374. modparam_fwpostfix, name);
  1375. err = request_firmware(fw, path, dev->dev->dev);
  1376. if (err) {
  1377. b43err(dev->wl, "Firmware file \"%s\" not found "
  1378. "or load failed.\n", path);
  1379. return err;
  1380. }
  1381. if ((*fw)->size < sizeof(struct b43_fw_header))
  1382. goto err_format;
  1383. hdr = (struct b43_fw_header *)((*fw)->data);
  1384. switch (hdr->type) {
  1385. case B43_FW_TYPE_UCODE:
  1386. case B43_FW_TYPE_PCM:
  1387. size = be32_to_cpu(hdr->size);
  1388. if (size != (*fw)->size - sizeof(struct b43_fw_header))
  1389. goto err_format;
  1390. /* fallthrough */
  1391. case B43_FW_TYPE_IV:
  1392. if (hdr->ver != 1)
  1393. goto err_format;
  1394. break;
  1395. default:
  1396. goto err_format;
  1397. }
  1398. return err;
  1399. err_format:
  1400. b43err(dev->wl, "Firmware file \"%s\" format error.\n", path);
  1401. return -EPROTO;
  1402. }
  1403. static int b43_request_firmware(struct b43_wldev *dev)
  1404. {
  1405. struct b43_firmware *fw = &dev->fw;
  1406. const u8 rev = dev->dev->id.revision;
  1407. const char *filename;
  1408. u32 tmshigh;
  1409. int err;
  1410. tmshigh = ssb_read32(dev->dev, SSB_TMSHIGH);
  1411. if (!fw->ucode) {
  1412. if ((rev >= 5) && (rev <= 10))
  1413. filename = "ucode5";
  1414. else if ((rev >= 11) && (rev <= 12))
  1415. filename = "ucode11";
  1416. else if (rev >= 13)
  1417. filename = "ucode13";
  1418. else
  1419. goto err_no_ucode;
  1420. err = do_request_fw(dev, filename, &fw->ucode);
  1421. if (err)
  1422. goto err_load;
  1423. }
  1424. if (!fw->pcm) {
  1425. if ((rev >= 5) && (rev <= 10))
  1426. filename = "pcm5";
  1427. else if (rev >= 11)
  1428. filename = NULL;
  1429. else
  1430. goto err_no_pcm;
  1431. err = do_request_fw(dev, filename, &fw->pcm);
  1432. if (err)
  1433. goto err_load;
  1434. }
  1435. if (!fw->initvals) {
  1436. switch (dev->phy.type) {
  1437. case B43_PHYTYPE_A:
  1438. if ((rev >= 5) && (rev <= 10)) {
  1439. if (tmshigh & B43_TMSHIGH_GPHY)
  1440. filename = "a0g1initvals5";
  1441. else
  1442. filename = "a0g0initvals5";
  1443. } else
  1444. goto err_no_initvals;
  1445. break;
  1446. case B43_PHYTYPE_G:
  1447. if ((rev >= 5) && (rev <= 10))
  1448. filename = "b0g0initvals5";
  1449. else if (rev >= 13)
  1450. filename = "lp0initvals13";
  1451. else
  1452. goto err_no_initvals;
  1453. break;
  1454. default:
  1455. goto err_no_initvals;
  1456. }
  1457. err = do_request_fw(dev, filename, &fw->initvals);
  1458. if (err)
  1459. goto err_load;
  1460. }
  1461. if (!fw->initvals_band) {
  1462. switch (dev->phy.type) {
  1463. case B43_PHYTYPE_A:
  1464. if ((rev >= 5) && (rev <= 10)) {
  1465. if (tmshigh & B43_TMSHIGH_GPHY)
  1466. filename = "a0g1bsinitvals5";
  1467. else
  1468. filename = "a0g0bsinitvals5";
  1469. } else if (rev >= 11)
  1470. filename = NULL;
  1471. else
  1472. goto err_no_initvals;
  1473. break;
  1474. case B43_PHYTYPE_G:
  1475. if ((rev >= 5) && (rev <= 10))
  1476. filename = "b0g0bsinitvals5";
  1477. else if (rev >= 11)
  1478. filename = NULL;
  1479. else
  1480. goto err_no_initvals;
  1481. break;
  1482. default:
  1483. goto err_no_initvals;
  1484. }
  1485. err = do_request_fw(dev, filename, &fw->initvals_band);
  1486. if (err)
  1487. goto err_load;
  1488. }
  1489. return 0;
  1490. err_load:
  1491. b43_print_fw_helptext(dev->wl);
  1492. goto error;
  1493. err_no_ucode:
  1494. err = -ENODEV;
  1495. b43err(dev->wl, "No microcode available for core rev %u\n", rev);
  1496. goto error;
  1497. err_no_pcm:
  1498. err = -ENODEV;
  1499. b43err(dev->wl, "No PCM available for core rev %u\n", rev);
  1500. goto error;
  1501. err_no_initvals:
  1502. err = -ENODEV;
  1503. b43err(dev->wl, "No Initial Values firmware file for PHY %u, "
  1504. "core rev %u\n", dev->phy.type, rev);
  1505. goto error;
  1506. error:
  1507. b43_release_firmware(dev);
  1508. return err;
  1509. }
  1510. static int b43_upload_microcode(struct b43_wldev *dev)
  1511. {
  1512. const size_t hdr_len = sizeof(struct b43_fw_header);
  1513. const __be32 *data;
  1514. unsigned int i, len;
  1515. u16 fwrev, fwpatch, fwdate, fwtime;
  1516. u32 tmp;
  1517. int err = 0;
  1518. /* Upload Microcode. */
  1519. data = (__be32 *) (dev->fw.ucode->data + hdr_len);
  1520. len = (dev->fw.ucode->size - hdr_len) / sizeof(__be32);
  1521. b43_shm_control_word(dev, B43_SHM_UCODE | B43_SHM_AUTOINC_W, 0x0000);
  1522. for (i = 0; i < len; i++) {
  1523. b43_write32(dev, B43_MMIO_SHM_DATA, be32_to_cpu(data[i]));
  1524. udelay(10);
  1525. }
  1526. if (dev->fw.pcm) {
  1527. /* Upload PCM data. */
  1528. data = (__be32 *) (dev->fw.pcm->data + hdr_len);
  1529. len = (dev->fw.pcm->size - hdr_len) / sizeof(__be32);
  1530. b43_shm_control_word(dev, B43_SHM_HW, 0x01EA);
  1531. b43_write32(dev, B43_MMIO_SHM_DATA, 0x00004000);
  1532. /* No need for autoinc bit in SHM_HW */
  1533. b43_shm_control_word(dev, B43_SHM_HW, 0x01EB);
  1534. for (i = 0; i < len; i++) {
  1535. b43_write32(dev, B43_MMIO_SHM_DATA, be32_to_cpu(data[i]));
  1536. udelay(10);
  1537. }
  1538. }
  1539. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, B43_IRQ_ALL);
  1540. b43_write32(dev, B43_MMIO_MACCTL,
  1541. B43_MACCTL_PSM_RUN |
  1542. B43_MACCTL_IHR_ENABLED | B43_MACCTL_INFRA);
  1543. /* Wait for the microcode to load and respond */
  1544. i = 0;
  1545. while (1) {
  1546. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  1547. if (tmp == B43_IRQ_MAC_SUSPENDED)
  1548. break;
  1549. i++;
  1550. if (i >= 50) {
  1551. b43err(dev->wl, "Microcode not responding\n");
  1552. b43_print_fw_helptext(dev->wl);
  1553. err = -ENODEV;
  1554. goto out;
  1555. }
  1556. udelay(10);
  1557. }
  1558. b43_read32(dev, B43_MMIO_GEN_IRQ_REASON); /* dummy read */
  1559. /* Get and check the revisions. */
  1560. fwrev = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEREV);
  1561. fwpatch = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEPATCH);
  1562. fwdate = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEDATE);
  1563. fwtime = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODETIME);
  1564. if (fwrev <= 0x128) {
  1565. b43err(dev->wl, "YOUR FIRMWARE IS TOO OLD. Firmware from "
  1566. "binary drivers older than version 4.x is unsupported. "
  1567. "You must upgrade your firmware files.\n");
  1568. b43_print_fw_helptext(dev->wl);
  1569. b43_write32(dev, B43_MMIO_MACCTL, 0);
  1570. err = -EOPNOTSUPP;
  1571. goto out;
  1572. }
  1573. b43dbg(dev->wl, "Loading firmware version %u.%u "
  1574. "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n",
  1575. fwrev, fwpatch,
  1576. (fwdate >> 12) & 0xF, (fwdate >> 8) & 0xF, fwdate & 0xFF,
  1577. (fwtime >> 11) & 0x1F, (fwtime >> 5) & 0x3F, fwtime & 0x1F);
  1578. dev->fw.rev = fwrev;
  1579. dev->fw.patch = fwpatch;
  1580. out:
  1581. return err;
  1582. }
  1583. static int b43_write_initvals(struct b43_wldev *dev,
  1584. const struct b43_iv *ivals,
  1585. size_t count,
  1586. size_t array_size)
  1587. {
  1588. const struct b43_iv *iv;
  1589. u16 offset;
  1590. size_t i;
  1591. bool bit32;
  1592. BUILD_BUG_ON(sizeof(struct b43_iv) != 6);
  1593. iv = ivals;
  1594. for (i = 0; i < count; i++) {
  1595. if (array_size < sizeof(iv->offset_size))
  1596. goto err_format;
  1597. array_size -= sizeof(iv->offset_size);
  1598. offset = be16_to_cpu(iv->offset_size);
  1599. bit32 = !!(offset & B43_IV_32BIT);
  1600. offset &= B43_IV_OFFSET_MASK;
  1601. if (offset >= 0x1000)
  1602. goto err_format;
  1603. if (bit32) {
  1604. u32 value;
  1605. if (array_size < sizeof(iv->data.d32))
  1606. goto err_format;
  1607. array_size -= sizeof(iv->data.d32);
  1608. value = be32_to_cpu(get_unaligned(&iv->data.d32));
  1609. b43_write32(dev, offset, value);
  1610. iv = (const struct b43_iv *)((const uint8_t *)iv +
  1611. sizeof(__be16) +
  1612. sizeof(__be32));
  1613. } else {
  1614. u16 value;
  1615. if (array_size < sizeof(iv->data.d16))
  1616. goto err_format;
  1617. array_size -= sizeof(iv->data.d16);
  1618. value = be16_to_cpu(iv->data.d16);
  1619. b43_write16(dev, offset, value);
  1620. iv = (const struct b43_iv *)((const uint8_t *)iv +
  1621. sizeof(__be16) +
  1622. sizeof(__be16));
  1623. }
  1624. }
  1625. if (array_size)
  1626. goto err_format;
  1627. return 0;
  1628. err_format:
  1629. b43err(dev->wl, "Initial Values Firmware file-format error.\n");
  1630. b43_print_fw_helptext(dev->wl);
  1631. return -EPROTO;
  1632. }
  1633. static int b43_upload_initvals(struct b43_wldev *dev)
  1634. {
  1635. const size_t hdr_len = sizeof(struct b43_fw_header);
  1636. const struct b43_fw_header *hdr;
  1637. struct b43_firmware *fw = &dev->fw;
  1638. const struct b43_iv *ivals;
  1639. size_t count;
  1640. int err;
  1641. hdr = (const struct b43_fw_header *)(fw->initvals->data);
  1642. ivals = (const struct b43_iv *)(fw->initvals->data + hdr_len);
  1643. count = be32_to_cpu(hdr->size);
  1644. err = b43_write_initvals(dev, ivals, count,
  1645. fw->initvals->size - hdr_len);
  1646. if (err)
  1647. goto out;
  1648. if (fw->initvals_band) {
  1649. hdr = (const struct b43_fw_header *)(fw->initvals_band->data);
  1650. ivals = (const struct b43_iv *)(fw->initvals_band->data + hdr_len);
  1651. count = be32_to_cpu(hdr->size);
  1652. err = b43_write_initvals(dev, ivals, count,
  1653. fw->initvals_band->size - hdr_len);
  1654. if (err)
  1655. goto out;
  1656. }
  1657. out:
  1658. return err;
  1659. }
  1660. /* Initialize the GPIOs
  1661. * http://bcm-specs.sipsolutions.net/GPIO
  1662. */
  1663. static int b43_gpio_init(struct b43_wldev *dev)
  1664. {
  1665. struct ssb_bus *bus = dev->dev->bus;
  1666. struct ssb_device *gpiodev, *pcidev = NULL;
  1667. u32 mask, set;
  1668. b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL)
  1669. & ~B43_MACCTL_GPOUTSMSK);
  1670. b43_write16(dev, B43_MMIO_GPIO_MASK, b43_read16(dev, B43_MMIO_GPIO_MASK)
  1671. | 0x000F);
  1672. mask = 0x0000001F;
  1673. set = 0x0000000F;
  1674. if (dev->dev->bus->chip_id == 0x4301) {
  1675. mask |= 0x0060;
  1676. set |= 0x0060;
  1677. }
  1678. if (0 /* FIXME: conditional unknown */ ) {
  1679. b43_write16(dev, B43_MMIO_GPIO_MASK,
  1680. b43_read16(dev, B43_MMIO_GPIO_MASK)
  1681. | 0x0100);
  1682. mask |= 0x0180;
  1683. set |= 0x0180;
  1684. }
  1685. if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_PACTRL) {
  1686. b43_write16(dev, B43_MMIO_GPIO_MASK,
  1687. b43_read16(dev, B43_MMIO_GPIO_MASK)
  1688. | 0x0200);
  1689. mask |= 0x0200;
  1690. set |= 0x0200;
  1691. }
  1692. if (dev->dev->id.revision >= 2)
  1693. mask |= 0x0010; /* FIXME: This is redundant. */
  1694. #ifdef CONFIG_SSB_DRIVER_PCICORE
  1695. pcidev = bus->pcicore.dev;
  1696. #endif
  1697. gpiodev = bus->chipco.dev ? : pcidev;
  1698. if (!gpiodev)
  1699. return 0;
  1700. ssb_write32(gpiodev, B43_GPIO_CONTROL,
  1701. (ssb_read32(gpiodev, B43_GPIO_CONTROL)
  1702. & mask) | set);
  1703. return 0;
  1704. }
  1705. /* Turn off all GPIO stuff. Call this on module unload, for example. */
  1706. static void b43_gpio_cleanup(struct b43_wldev *dev)
  1707. {
  1708. struct ssb_bus *bus = dev->dev->bus;
  1709. struct ssb_device *gpiodev, *pcidev = NULL;
  1710. #ifdef CONFIG_SSB_DRIVER_PCICORE
  1711. pcidev = bus->pcicore.dev;
  1712. #endif
  1713. gpiodev = bus->chipco.dev ? : pcidev;
  1714. if (!gpiodev)
  1715. return;
  1716. ssb_write32(gpiodev, B43_GPIO_CONTROL, 0);
  1717. }
  1718. /* http://bcm-specs.sipsolutions.net/EnableMac */
  1719. void b43_mac_enable(struct b43_wldev *dev)
  1720. {
  1721. dev->mac_suspended--;
  1722. B43_WARN_ON(dev->mac_suspended < 0);
  1723. B43_WARN_ON(irqs_disabled());
  1724. if (dev->mac_suspended == 0) {
  1725. b43_write32(dev, B43_MMIO_MACCTL,
  1726. b43_read32(dev, B43_MMIO_MACCTL)
  1727. | B43_MACCTL_ENABLED);
  1728. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON,
  1729. B43_IRQ_MAC_SUSPENDED);
  1730. /* Commit writes */
  1731. b43_read32(dev, B43_MMIO_MACCTL);
  1732. b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  1733. b43_power_saving_ctl_bits(dev, 0);
  1734. /* Re-enable IRQs. */
  1735. spin_lock_irq(&dev->wl->irq_lock);
  1736. b43_interrupt_enable(dev, dev->irq_savedstate);
  1737. spin_unlock_irq(&dev->wl->irq_lock);
  1738. }
  1739. }
  1740. /* http://bcm-specs.sipsolutions.net/SuspendMAC */
  1741. void b43_mac_suspend(struct b43_wldev *dev)
  1742. {
  1743. int i;
  1744. u32 tmp;
  1745. might_sleep();
  1746. B43_WARN_ON(irqs_disabled());
  1747. B43_WARN_ON(dev->mac_suspended < 0);
  1748. if (dev->mac_suspended == 0) {
  1749. /* Mask IRQs before suspending MAC. Otherwise
  1750. * the MAC stays busy and won't suspend. */
  1751. spin_lock_irq(&dev->wl->irq_lock);
  1752. tmp = b43_interrupt_disable(dev, B43_IRQ_ALL);
  1753. spin_unlock_irq(&dev->wl->irq_lock);
  1754. b43_synchronize_irq(dev);
  1755. dev->irq_savedstate = tmp;
  1756. b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
  1757. b43_write32(dev, B43_MMIO_MACCTL,
  1758. b43_read32(dev, B43_MMIO_MACCTL)
  1759. & ~B43_MACCTL_ENABLED);
  1760. /* force pci to flush the write */
  1761. b43_read32(dev, B43_MMIO_MACCTL);
  1762. for (i = 40; i; i--) {
  1763. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  1764. if (tmp & B43_IRQ_MAC_SUSPENDED)
  1765. goto out;
  1766. msleep(1);
  1767. }
  1768. b43err(dev->wl, "MAC suspend failed\n");
  1769. }
  1770. out:
  1771. dev->mac_suspended++;
  1772. }
  1773. static void b43_adjust_opmode(struct b43_wldev *dev)
  1774. {
  1775. struct b43_wl *wl = dev->wl;
  1776. u32 ctl;
  1777. u16 cfp_pretbtt;
  1778. ctl = b43_read32(dev, B43_MMIO_MACCTL);
  1779. /* Reset status to STA infrastructure mode. */
  1780. ctl &= ~B43_MACCTL_AP;
  1781. ctl &= ~B43_MACCTL_KEEP_CTL;
  1782. ctl &= ~B43_MACCTL_KEEP_BADPLCP;
  1783. ctl &= ~B43_MACCTL_KEEP_BAD;
  1784. ctl &= ~B43_MACCTL_PROMISC;
  1785. ctl &= ~B43_MACCTL_BEACPROMISC;
  1786. ctl |= B43_MACCTL_INFRA;
  1787. if (b43_is_mode(wl, IEEE80211_IF_TYPE_AP))
  1788. ctl |= B43_MACCTL_AP;
  1789. else if (b43_is_mode(wl, IEEE80211_IF_TYPE_IBSS))
  1790. ctl &= ~B43_MACCTL_INFRA;
  1791. if (wl->filter_flags & FIF_CONTROL)
  1792. ctl |= B43_MACCTL_KEEP_CTL;
  1793. if (wl->filter_flags & FIF_FCSFAIL)
  1794. ctl |= B43_MACCTL_KEEP_BAD;
  1795. if (wl->filter_flags & FIF_PLCPFAIL)
  1796. ctl |= B43_MACCTL_KEEP_BADPLCP;
  1797. if (wl->filter_flags & FIF_PROMISC_IN_BSS)
  1798. ctl |= B43_MACCTL_PROMISC;
  1799. if (wl->filter_flags & FIF_BCN_PRBRESP_PROMISC)
  1800. ctl |= B43_MACCTL_BEACPROMISC;
  1801. /* Workaround: On old hardware the HW-MAC-address-filter
  1802. * doesn't work properly, so always run promisc in filter
  1803. * it in software. */
  1804. if (dev->dev->id.revision <= 4)
  1805. ctl |= B43_MACCTL_PROMISC;
  1806. b43_write32(dev, B43_MMIO_MACCTL, ctl);
  1807. cfp_pretbtt = 2;
  1808. if ((ctl & B43_MACCTL_INFRA) && !(ctl & B43_MACCTL_AP)) {
  1809. if (dev->dev->bus->chip_id == 0x4306 &&
  1810. dev->dev->bus->chip_rev == 3)
  1811. cfp_pretbtt = 100;
  1812. else
  1813. cfp_pretbtt = 50;
  1814. }
  1815. b43_write16(dev, 0x612, cfp_pretbtt);
  1816. }
  1817. static void b43_rate_memory_write(struct b43_wldev *dev, u16 rate, int is_ofdm)
  1818. {
  1819. u16 offset;
  1820. if (is_ofdm) {
  1821. offset = 0x480;
  1822. offset += (b43_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
  1823. } else {
  1824. offset = 0x4C0;
  1825. offset += (b43_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
  1826. }
  1827. b43_shm_write16(dev, B43_SHM_SHARED, offset + 0x20,
  1828. b43_shm_read16(dev, B43_SHM_SHARED, offset));
  1829. }
  1830. static void b43_rate_memory_init(struct b43_wldev *dev)
  1831. {
  1832. switch (dev->phy.type) {
  1833. case B43_PHYTYPE_A:
  1834. case B43_PHYTYPE_G:
  1835. b43_rate_memory_write(dev, B43_OFDM_RATE_6MB, 1);
  1836. b43_rate_memory_write(dev, B43_OFDM_RATE_12MB, 1);
  1837. b43_rate_memory_write(dev, B43_OFDM_RATE_18MB, 1);
  1838. b43_rate_memory_write(dev, B43_OFDM_RATE_24MB, 1);
  1839. b43_rate_memory_write(dev, B43_OFDM_RATE_36MB, 1);
  1840. b43_rate_memory_write(dev, B43_OFDM_RATE_48MB, 1);
  1841. b43_rate_memory_write(dev, B43_OFDM_RATE_54MB, 1);
  1842. if (dev->phy.type == B43_PHYTYPE_A)
  1843. break;
  1844. /* fallthrough */
  1845. case B43_PHYTYPE_B:
  1846. b43_rate_memory_write(dev, B43_CCK_RATE_1MB, 0);
  1847. b43_rate_memory_write(dev, B43_CCK_RATE_2MB, 0);
  1848. b43_rate_memory_write(dev, B43_CCK_RATE_5MB, 0);
  1849. b43_rate_memory_write(dev, B43_CCK_RATE_11MB, 0);
  1850. break;
  1851. default:
  1852. B43_WARN_ON(1);
  1853. }
  1854. }
  1855. /* Set the TX-Antenna for management frames sent by firmware. */
  1856. static void b43_mgmtframe_txantenna(struct b43_wldev *dev, int antenna)
  1857. {
  1858. u16 ant = 0;
  1859. u16 tmp;
  1860. switch (antenna) {
  1861. case B43_ANTENNA0:
  1862. ant |= B43_TX4_PHY_ANT0;
  1863. break;
  1864. case B43_ANTENNA1:
  1865. ant |= B43_TX4_PHY_ANT1;
  1866. break;
  1867. case B43_ANTENNA_AUTO:
  1868. ant |= B43_TX4_PHY_ANTLAST;
  1869. break;
  1870. default:
  1871. B43_WARN_ON(1);
  1872. }
  1873. /* FIXME We also need to set the other flags of the PHY control field somewhere. */
  1874. /* For Beacons */
  1875. tmp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL);
  1876. tmp = (tmp & ~B43_TX4_PHY_ANT) | ant;
  1877. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL, tmp);
  1878. /* For ACK/CTS */
  1879. tmp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL);
  1880. tmp = (tmp & ~B43_TX4_PHY_ANT) | ant;
  1881. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL, tmp);
  1882. /* For Probe Resposes */
  1883. tmp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL);
  1884. tmp = (tmp & ~B43_TX4_PHY_ANT) | ant;
  1885. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL, tmp);
  1886. }
  1887. /* This is the opposite of b43_chip_init() */
  1888. static void b43_chip_exit(struct b43_wldev *dev)
  1889. {
  1890. b43_radio_turn_off(dev, 1);
  1891. b43_gpio_cleanup(dev);
  1892. /* firmware is released later */
  1893. }
  1894. /* Initialize the chip
  1895. * http://bcm-specs.sipsolutions.net/ChipInit
  1896. */
  1897. static int b43_chip_init(struct b43_wldev *dev)
  1898. {
  1899. struct b43_phy *phy = &dev->phy;
  1900. int err, tmp;
  1901. u32 value32;
  1902. u16 value16;
  1903. b43_write32(dev, B43_MMIO_MACCTL,
  1904. B43_MACCTL_PSM_JMP0 | B43_MACCTL_IHR_ENABLED);
  1905. err = b43_request_firmware(dev);
  1906. if (err)
  1907. goto out;
  1908. err = b43_upload_microcode(dev);
  1909. if (err)
  1910. goto out; /* firmware is released later */
  1911. err = b43_gpio_init(dev);
  1912. if (err)
  1913. goto out; /* firmware is released later */
  1914. err = b43_upload_initvals(dev);
  1915. if (err)
  1916. goto err_gpio_clean;
  1917. b43_radio_turn_on(dev);
  1918. b43_write16(dev, 0x03E6, 0x0000);
  1919. err = b43_phy_init(dev);
  1920. if (err)
  1921. goto err_radio_off;
  1922. /* Select initial Interference Mitigation. */
  1923. tmp = phy->interfmode;
  1924. phy->interfmode = B43_INTERFMODE_NONE;
  1925. b43_radio_set_interference_mitigation(dev, tmp);
  1926. b43_set_rx_antenna(dev, B43_ANTENNA_DEFAULT);
  1927. b43_mgmtframe_txantenna(dev, B43_ANTENNA_DEFAULT);
  1928. if (phy->type == B43_PHYTYPE_B) {
  1929. value16 = b43_read16(dev, 0x005E);
  1930. value16 |= 0x0004;
  1931. b43_write16(dev, 0x005E, value16);
  1932. }
  1933. b43_write32(dev, 0x0100, 0x01000000);
  1934. if (dev->dev->id.revision < 5)
  1935. b43_write32(dev, 0x010C, 0x01000000);
  1936. b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL)
  1937. & ~B43_MACCTL_INFRA);
  1938. b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL)
  1939. | B43_MACCTL_INFRA);
  1940. if (b43_using_pio(dev)) {
  1941. b43_write32(dev, 0x0210, 0x00000100);
  1942. b43_write32(dev, 0x0230, 0x00000100);
  1943. b43_write32(dev, 0x0250, 0x00000100);
  1944. b43_write32(dev, 0x0270, 0x00000100);
  1945. b43_shm_write16(dev, B43_SHM_SHARED, 0x0034, 0x0000);
  1946. }
  1947. /* Probe Response Timeout value */
  1948. /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
  1949. b43_shm_write16(dev, B43_SHM_SHARED, 0x0074, 0x0000);
  1950. /* Initially set the wireless operation mode. */
  1951. b43_adjust_opmode(dev);
  1952. if (dev->dev->id.revision < 3) {
  1953. b43_write16(dev, 0x060E, 0x0000);
  1954. b43_write16(dev, 0x0610, 0x8000);
  1955. b43_write16(dev, 0x0604, 0x0000);
  1956. b43_write16(dev, 0x0606, 0x0200);
  1957. } else {
  1958. b43_write32(dev, 0x0188, 0x80000000);
  1959. b43_write32(dev, 0x018C, 0x02000000);
  1960. }
  1961. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, 0x00004000);
  1962. b43_write32(dev, B43_MMIO_DMA0_IRQ_MASK, 0x0001DC00);
  1963. b43_write32(dev, B43_MMIO_DMA1_IRQ_MASK, 0x0000DC00);
  1964. b43_write32(dev, B43_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
  1965. b43_write32(dev, B43_MMIO_DMA3_IRQ_MASK, 0x0001DC00);
  1966. b43_write32(dev, B43_MMIO_DMA4_IRQ_MASK, 0x0000DC00);
  1967. b43_write32(dev, B43_MMIO_DMA5_IRQ_MASK, 0x0000DC00);
  1968. value32 = ssb_read32(dev->dev, SSB_TMSLOW);
  1969. value32 |= 0x00100000;
  1970. ssb_write32(dev->dev, SSB_TMSLOW, value32);
  1971. b43_write16(dev, B43_MMIO_POWERUP_DELAY,
  1972. dev->dev->bus->chipco.fast_pwrup_delay);
  1973. err = 0;
  1974. b43dbg(dev->wl, "Chip initialized\n");
  1975. out:
  1976. return err;
  1977. err_radio_off:
  1978. b43_radio_turn_off(dev, 1);
  1979. err_gpio_clean:
  1980. b43_gpio_cleanup(dev);
  1981. return err;
  1982. }
  1983. static void b43_periodic_every120sec(struct b43_wldev *dev)
  1984. {
  1985. struct b43_phy *phy = &dev->phy;
  1986. if (phy->type != B43_PHYTYPE_G || phy->rev < 2)
  1987. return;
  1988. b43_mac_suspend(dev);
  1989. b43_lo_g_measure(dev);
  1990. b43_mac_enable(dev);
  1991. if (b43_has_hardware_pctl(phy))
  1992. b43_lo_g_ctl_mark_all_unused(dev);
  1993. }
  1994. static void b43_periodic_every60sec(struct b43_wldev *dev)
  1995. {
  1996. struct b43_phy *phy = &dev->phy;
  1997. if (!b43_has_hardware_pctl(phy))
  1998. b43_lo_g_ctl_mark_all_unused(dev);
  1999. if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_RSSI) {
  2000. b43_mac_suspend(dev);
  2001. b43_calc_nrssi_slope(dev);
  2002. if ((phy->radio_ver == 0x2050) && (phy->radio_rev == 8)) {
  2003. u8 old_chan = phy->channel;
  2004. /* VCO Calibration */
  2005. if (old_chan >= 8)
  2006. b43_radio_selectchannel(dev, 1, 0);
  2007. else
  2008. b43_radio_selectchannel(dev, 13, 0);
  2009. b43_radio_selectchannel(dev, old_chan, 0);
  2010. }
  2011. b43_mac_enable(dev);
  2012. }
  2013. }
  2014. static void b43_periodic_every30sec(struct b43_wldev *dev)
  2015. {
  2016. /* Update device statistics. */
  2017. b43_calculate_link_quality(dev);
  2018. }
  2019. static void b43_periodic_every15sec(struct b43_wldev *dev)
  2020. {
  2021. struct b43_phy *phy = &dev->phy;
  2022. if (phy->type == B43_PHYTYPE_G) {
  2023. //TODO: update_aci_moving_average
  2024. if (phy->aci_enable && phy->aci_wlan_automatic) {
  2025. b43_mac_suspend(dev);
  2026. if (!phy->aci_enable && 1 /*TODO: not scanning? */ ) {
  2027. if (0 /*TODO: bunch of conditions */ ) {
  2028. b43_radio_set_interference_mitigation
  2029. (dev, B43_INTERFMODE_MANUALWLAN);
  2030. }
  2031. } else if (1 /*TODO*/) {
  2032. /*
  2033. if ((aci_average > 1000) && !(b43_radio_aci_scan(dev))) {
  2034. b43_radio_set_interference_mitigation(dev,
  2035. B43_INTERFMODE_NONE);
  2036. }
  2037. */
  2038. }
  2039. b43_mac_enable(dev);
  2040. } else if (phy->interfmode == B43_INTERFMODE_NONWLAN &&
  2041. phy->rev == 1) {
  2042. //TODO: implement rev1 workaround
  2043. }
  2044. }
  2045. b43_phy_xmitpower(dev); //FIXME: unless scanning?
  2046. //TODO for APHY (temperature?)
  2047. }
  2048. static void do_periodic_work(struct b43_wldev *dev)
  2049. {
  2050. unsigned int state;
  2051. state = dev->periodic_state;
  2052. if (state % 8 == 0)
  2053. b43_periodic_every120sec(dev);
  2054. if (state % 4 == 0)
  2055. b43_periodic_every60sec(dev);
  2056. if (state % 2 == 0)
  2057. b43_periodic_every30sec(dev);
  2058. b43_periodic_every15sec(dev);
  2059. }
  2060. /* Periodic work locking policy:
  2061. * The whole periodic work handler is protected by
  2062. * wl->mutex. If another lock is needed somewhere in the
  2063. * pwork callchain, it's aquired in-place, where it's needed.
  2064. */
  2065. static void b43_periodic_work_handler(struct work_struct *work)
  2066. {
  2067. struct b43_wldev *dev = container_of(work, struct b43_wldev,
  2068. periodic_work.work);
  2069. struct b43_wl *wl = dev->wl;
  2070. unsigned long delay;
  2071. mutex_lock(&wl->mutex);
  2072. if (unlikely(b43_status(dev) != B43_STAT_STARTED))
  2073. goto out;
  2074. if (b43_debug(dev, B43_DBG_PWORK_STOP))
  2075. goto out_requeue;
  2076. do_periodic_work(dev);
  2077. dev->periodic_state++;
  2078. out_requeue:
  2079. if (b43_debug(dev, B43_DBG_PWORK_FAST))
  2080. delay = msecs_to_jiffies(50);
  2081. else
  2082. delay = round_jiffies_relative(HZ * 15);
  2083. queue_delayed_work(wl->hw->workqueue, &dev->periodic_work, delay);
  2084. out:
  2085. mutex_unlock(&wl->mutex);
  2086. }
  2087. static void b43_periodic_tasks_setup(struct b43_wldev *dev)
  2088. {
  2089. struct delayed_work *work = &dev->periodic_work;
  2090. dev->periodic_state = 0;
  2091. INIT_DELAYED_WORK(work, b43_periodic_work_handler);
  2092. queue_delayed_work(dev->wl->hw->workqueue, work, 0);
  2093. }
  2094. /* Validate access to the chip (SHM) */
  2095. static int b43_validate_chipaccess(struct b43_wldev *dev)
  2096. {
  2097. u32 value;
  2098. u32 shm_backup;
  2099. shm_backup = b43_shm_read32(dev, B43_SHM_SHARED, 0);
  2100. b43_shm_write32(dev, B43_SHM_SHARED, 0, 0xAA5555AA);
  2101. if (b43_shm_read32(dev, B43_SHM_SHARED, 0) != 0xAA5555AA)
  2102. goto error;
  2103. b43_shm_write32(dev, B43_SHM_SHARED, 0, 0x55AAAA55);
  2104. if (b43_shm_read32(dev, B43_SHM_SHARED, 0) != 0x55AAAA55)
  2105. goto error;
  2106. b43_shm_write32(dev, B43_SHM_SHARED, 0, shm_backup);
  2107. value = b43_read32(dev, B43_MMIO_MACCTL);
  2108. if ((value | B43_MACCTL_GMODE) !=
  2109. (B43_MACCTL_GMODE | B43_MACCTL_IHR_ENABLED))
  2110. goto error;
  2111. value = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2112. if (value)
  2113. goto error;
  2114. return 0;
  2115. error:
  2116. b43err(dev->wl, "Failed to validate the chipaccess\n");
  2117. return -ENODEV;
  2118. }
  2119. static void b43_security_init(struct b43_wldev *dev)
  2120. {
  2121. dev->max_nr_keys = (dev->dev->id.revision >= 5) ? 58 : 20;
  2122. B43_WARN_ON(dev->max_nr_keys > ARRAY_SIZE(dev->key));
  2123. dev->ktp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_KTP);
  2124. /* KTP is a word address, but we address SHM bytewise.
  2125. * So multiply by two.
  2126. */
  2127. dev->ktp *= 2;
  2128. if (dev->dev->id.revision >= 5) {
  2129. /* Number of RCMTA address slots */
  2130. b43_write16(dev, B43_MMIO_RCMTA_COUNT, dev->max_nr_keys - 8);
  2131. }
  2132. b43_clear_keys(dev);
  2133. }
  2134. static int b43_rng_read(struct hwrng *rng, u32 * data)
  2135. {
  2136. struct b43_wl *wl = (struct b43_wl *)rng->priv;
  2137. unsigned long flags;
  2138. /* Don't take wl->mutex here, as it could deadlock with
  2139. * hwrng internal locking. It's not needed to take
  2140. * wl->mutex here, anyway. */
  2141. spin_lock_irqsave(&wl->irq_lock, flags);
  2142. *data = b43_read16(wl->current_dev, B43_MMIO_RNG);
  2143. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2144. return (sizeof(u16));
  2145. }
  2146. static void b43_rng_exit(struct b43_wl *wl)
  2147. {
  2148. if (wl->rng_initialized)
  2149. hwrng_unregister(&wl->rng);
  2150. }
  2151. static int b43_rng_init(struct b43_wl *wl)
  2152. {
  2153. int err;
  2154. snprintf(wl->rng_name, ARRAY_SIZE(wl->rng_name),
  2155. "%s_%s", KBUILD_MODNAME, wiphy_name(wl->hw->wiphy));
  2156. wl->rng.name = wl->rng_name;
  2157. wl->rng.data_read = b43_rng_read;
  2158. wl->rng.priv = (unsigned long)wl;
  2159. wl->rng_initialized = 1;
  2160. err = hwrng_register(&wl->rng);
  2161. if (err) {
  2162. wl->rng_initialized = 0;
  2163. b43err(wl, "Failed to register the random "
  2164. "number generator (%d)\n", err);
  2165. }
  2166. return err;
  2167. }
  2168. static int b43_tx(struct ieee80211_hw *hw,
  2169. struct sk_buff *skb, struct ieee80211_tx_control *ctl)
  2170. {
  2171. struct b43_wl *wl = hw_to_b43_wl(hw);
  2172. struct b43_wldev *dev = wl->current_dev;
  2173. int err = -ENODEV;
  2174. unsigned long flags;
  2175. if (unlikely(!dev))
  2176. goto out;
  2177. if (unlikely(b43_status(dev) < B43_STAT_STARTED))
  2178. goto out;
  2179. /* DMA-TX is done without a global lock. */
  2180. if (b43_using_pio(dev)) {
  2181. spin_lock_irqsave(&wl->irq_lock, flags);
  2182. err = b43_pio_tx(dev, skb, ctl);
  2183. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2184. } else
  2185. err = b43_dma_tx(dev, skb, ctl);
  2186. out:
  2187. if (unlikely(err))
  2188. return NETDEV_TX_BUSY;
  2189. return NETDEV_TX_OK;
  2190. }
  2191. static int b43_conf_tx(struct ieee80211_hw *hw,
  2192. int queue,
  2193. const struct ieee80211_tx_queue_params *params)
  2194. {
  2195. return 0;
  2196. }
  2197. static int b43_get_tx_stats(struct ieee80211_hw *hw,
  2198. struct ieee80211_tx_queue_stats *stats)
  2199. {
  2200. struct b43_wl *wl = hw_to_b43_wl(hw);
  2201. struct b43_wldev *dev = wl->current_dev;
  2202. unsigned long flags;
  2203. int err = -ENODEV;
  2204. if (!dev)
  2205. goto out;
  2206. spin_lock_irqsave(&wl->irq_lock, flags);
  2207. if (likely(b43_status(dev) >= B43_STAT_STARTED)) {
  2208. if (b43_using_pio(dev))
  2209. b43_pio_get_tx_stats(dev, stats);
  2210. else
  2211. b43_dma_get_tx_stats(dev, stats);
  2212. err = 0;
  2213. }
  2214. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2215. out:
  2216. return err;
  2217. }
  2218. static int b43_get_stats(struct ieee80211_hw *hw,
  2219. struct ieee80211_low_level_stats *stats)
  2220. {
  2221. struct b43_wl *wl = hw_to_b43_wl(hw);
  2222. unsigned long flags;
  2223. spin_lock_irqsave(&wl->irq_lock, flags);
  2224. memcpy(stats, &wl->ieee_stats, sizeof(*stats));
  2225. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2226. return 0;
  2227. }
  2228. static const char *phymode_to_string(unsigned int phymode)
  2229. {
  2230. switch (phymode) {
  2231. case B43_PHYMODE_A:
  2232. return "A";
  2233. case B43_PHYMODE_B:
  2234. return "B";
  2235. case B43_PHYMODE_G:
  2236. return "G";
  2237. default:
  2238. B43_WARN_ON(1);
  2239. }
  2240. return "";
  2241. }
  2242. static int find_wldev_for_phymode(struct b43_wl *wl,
  2243. unsigned int phymode,
  2244. struct b43_wldev **dev, bool * gmode)
  2245. {
  2246. struct b43_wldev *d;
  2247. list_for_each_entry(d, &wl->devlist, list) {
  2248. if (d->phy.possible_phymodes & phymode) {
  2249. /* Ok, this device supports the PHY-mode.
  2250. * Now figure out how the gmode bit has to be
  2251. * set to support it. */
  2252. if (phymode == B43_PHYMODE_A)
  2253. *gmode = 0;
  2254. else
  2255. *gmode = 1;
  2256. *dev = d;
  2257. return 0;
  2258. }
  2259. }
  2260. return -ESRCH;
  2261. }
  2262. static void b43_put_phy_into_reset(struct b43_wldev *dev)
  2263. {
  2264. struct ssb_device *sdev = dev->dev;
  2265. u32 tmslow;
  2266. tmslow = ssb_read32(sdev, SSB_TMSLOW);
  2267. tmslow &= ~B43_TMSLOW_GMODE;
  2268. tmslow |= B43_TMSLOW_PHYRESET;
  2269. tmslow |= SSB_TMSLOW_FGC;
  2270. ssb_write32(sdev, SSB_TMSLOW, tmslow);
  2271. msleep(1);
  2272. tmslow = ssb_read32(sdev, SSB_TMSLOW);
  2273. tmslow &= ~SSB_TMSLOW_FGC;
  2274. tmslow |= B43_TMSLOW_PHYRESET;
  2275. ssb_write32(sdev, SSB_TMSLOW, tmslow);
  2276. msleep(1);
  2277. }
  2278. /* Expects wl->mutex locked */
  2279. static int b43_switch_phymode(struct b43_wl *wl, unsigned int new_mode)
  2280. {
  2281. struct b43_wldev *up_dev;
  2282. struct b43_wldev *down_dev;
  2283. int err;
  2284. bool gmode = 0;
  2285. int prev_status;
  2286. err = find_wldev_for_phymode(wl, new_mode, &up_dev, &gmode);
  2287. if (err) {
  2288. b43err(wl, "Could not find a device for %s-PHY mode\n",
  2289. phymode_to_string(new_mode));
  2290. return err;
  2291. }
  2292. if ((up_dev == wl->current_dev) &&
  2293. (!!wl->current_dev->phy.gmode == !!gmode)) {
  2294. /* This device is already running. */
  2295. return 0;
  2296. }
  2297. b43dbg(wl, "Reconfiguring PHYmode to %s-PHY\n",
  2298. phymode_to_string(new_mode));
  2299. down_dev = wl->current_dev;
  2300. prev_status = b43_status(down_dev);
  2301. /* Shutdown the currently running core. */
  2302. if (prev_status >= B43_STAT_STARTED)
  2303. b43_wireless_core_stop(down_dev);
  2304. if (prev_status >= B43_STAT_INITIALIZED)
  2305. b43_wireless_core_exit(down_dev);
  2306. if (down_dev != up_dev) {
  2307. /* We switch to a different core, so we put PHY into
  2308. * RESET on the old core. */
  2309. b43_put_phy_into_reset(down_dev);
  2310. }
  2311. /* Now start the new core. */
  2312. up_dev->phy.gmode = gmode;
  2313. if (prev_status >= B43_STAT_INITIALIZED) {
  2314. err = b43_wireless_core_init(up_dev);
  2315. if (err) {
  2316. b43err(wl, "Fatal: Could not initialize device for "
  2317. "newly selected %s-PHY mode\n",
  2318. phymode_to_string(new_mode));
  2319. goto init_failure;
  2320. }
  2321. }
  2322. if (prev_status >= B43_STAT_STARTED) {
  2323. err = b43_wireless_core_start(up_dev);
  2324. if (err) {
  2325. b43err(wl, "Fatal: Coult not start device for "
  2326. "newly selected %s-PHY mode\n",
  2327. phymode_to_string(new_mode));
  2328. b43_wireless_core_exit(up_dev);
  2329. goto init_failure;
  2330. }
  2331. }
  2332. B43_WARN_ON(b43_status(up_dev) != prev_status);
  2333. wl->current_dev = up_dev;
  2334. return 0;
  2335. init_failure:
  2336. /* Whoops, failed to init the new core. No core is operating now. */
  2337. wl->current_dev = NULL;
  2338. return err;
  2339. }
  2340. static int b43_antenna_from_ieee80211(u8 antenna)
  2341. {
  2342. switch (antenna) {
  2343. case 0: /* default/diversity */
  2344. return B43_ANTENNA_DEFAULT;
  2345. case 1: /* Antenna 0 */
  2346. return B43_ANTENNA0;
  2347. case 2: /* Antenna 1 */
  2348. return B43_ANTENNA1;
  2349. default:
  2350. return B43_ANTENNA_DEFAULT;
  2351. }
  2352. }
  2353. static int b43_dev_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
  2354. {
  2355. struct b43_wl *wl = hw_to_b43_wl(hw);
  2356. struct b43_wldev *dev;
  2357. struct b43_phy *phy;
  2358. unsigned long flags;
  2359. unsigned int new_phymode = 0xFFFF;
  2360. int antenna_tx;
  2361. int antenna_rx;
  2362. int err = 0;
  2363. u32 savedirqs;
  2364. antenna_tx = b43_antenna_from_ieee80211(conf->antenna_sel_tx);
  2365. antenna_rx = b43_antenna_from_ieee80211(conf->antenna_sel_rx);
  2366. mutex_lock(&wl->mutex);
  2367. /* Switch the PHY mode (if necessary). */
  2368. switch (conf->phymode) {
  2369. case MODE_IEEE80211A:
  2370. new_phymode = B43_PHYMODE_A;
  2371. break;
  2372. case MODE_IEEE80211B:
  2373. new_phymode = B43_PHYMODE_B;
  2374. break;
  2375. case MODE_IEEE80211G:
  2376. new_phymode = B43_PHYMODE_G;
  2377. break;
  2378. default:
  2379. B43_WARN_ON(1);
  2380. }
  2381. err = b43_switch_phymode(wl, new_phymode);
  2382. if (err)
  2383. goto out_unlock_mutex;
  2384. dev = wl->current_dev;
  2385. phy = &dev->phy;
  2386. /* Disable IRQs while reconfiguring the device.
  2387. * This makes it possible to drop the spinlock throughout
  2388. * the reconfiguration process. */
  2389. spin_lock_irqsave(&wl->irq_lock, flags);
  2390. if (b43_status(dev) < B43_STAT_STARTED) {
  2391. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2392. goto out_unlock_mutex;
  2393. }
  2394. savedirqs = b43_interrupt_disable(dev, B43_IRQ_ALL);
  2395. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2396. b43_synchronize_irq(dev);
  2397. /* Switch to the requested channel.
  2398. * The firmware takes care of races with the TX handler. */
  2399. if (conf->channel_val != phy->channel)
  2400. b43_radio_selectchannel(dev, conf->channel_val, 0);
  2401. /* Enable/Disable ShortSlot timing. */
  2402. if ((!!(conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME)) !=
  2403. dev->short_slot) {
  2404. B43_WARN_ON(phy->type != B43_PHYTYPE_G);
  2405. if (conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME)
  2406. b43_short_slot_timing_enable(dev);
  2407. else
  2408. b43_short_slot_timing_disable(dev);
  2409. }
  2410. /* Adjust the desired TX power level. */
  2411. if (conf->power_level != 0) {
  2412. if (conf->power_level != phy->power_level) {
  2413. phy->power_level = conf->power_level;
  2414. b43_phy_xmitpower(dev);
  2415. }
  2416. }
  2417. /* Antennas for RX and management frame TX. */
  2418. b43_mgmtframe_txantenna(dev, antenna_tx);
  2419. b43_set_rx_antenna(dev, antenna_rx);
  2420. /* Update templates for AP mode. */
  2421. if (b43_is_mode(wl, IEEE80211_IF_TYPE_AP))
  2422. b43_set_beacon_int(dev, conf->beacon_int);
  2423. if (!!conf->radio_enabled != phy->radio_on) {
  2424. if (conf->radio_enabled) {
  2425. b43_radio_turn_on(dev);
  2426. b43info(dev->wl, "Radio turned on by software\n");
  2427. if (!dev->radio_hw_enable) {
  2428. b43info(dev->wl, "The hardware RF-kill button "
  2429. "still turns the radio physically off. "
  2430. "Press the button to turn it on.\n");
  2431. }
  2432. } else {
  2433. b43_radio_turn_off(dev, 0);
  2434. b43info(dev->wl, "Radio turned off by software\n");
  2435. }
  2436. }
  2437. spin_lock_irqsave(&wl->irq_lock, flags);
  2438. b43_interrupt_enable(dev, savedirqs);
  2439. mmiowb();
  2440. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2441. out_unlock_mutex:
  2442. mutex_unlock(&wl->mutex);
  2443. return err;
  2444. }
  2445. static int b43_dev_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2446. const u8 *local_addr, const u8 *addr,
  2447. struct ieee80211_key_conf *key)
  2448. {
  2449. struct b43_wl *wl = hw_to_b43_wl(hw);
  2450. struct b43_wldev *dev;
  2451. unsigned long flags;
  2452. u8 algorithm;
  2453. u8 index;
  2454. int err;
  2455. DECLARE_MAC_BUF(mac);
  2456. if (modparam_nohwcrypt)
  2457. return -ENOSPC; /* User disabled HW-crypto */
  2458. mutex_lock(&wl->mutex);
  2459. spin_lock_irqsave(&wl->irq_lock, flags);
  2460. dev = wl->current_dev;
  2461. err = -ENODEV;
  2462. if (!dev || b43_status(dev) < B43_STAT_INITIALIZED)
  2463. goto out_unlock;
  2464. err = -EINVAL;
  2465. switch (key->alg) {
  2466. case ALG_WEP:
  2467. if (key->keylen == 5)
  2468. algorithm = B43_SEC_ALGO_WEP40;
  2469. else
  2470. algorithm = B43_SEC_ALGO_WEP104;
  2471. break;
  2472. case ALG_TKIP:
  2473. algorithm = B43_SEC_ALGO_TKIP;
  2474. break;
  2475. case ALG_CCMP:
  2476. algorithm = B43_SEC_ALGO_AES;
  2477. break;
  2478. default:
  2479. B43_WARN_ON(1);
  2480. goto out_unlock;
  2481. }
  2482. index = (u8) (key->keyidx);
  2483. if (index > 3)
  2484. goto out_unlock;
  2485. switch (cmd) {
  2486. case SET_KEY:
  2487. if (algorithm == B43_SEC_ALGO_TKIP) {
  2488. /* FIXME: No TKIP hardware encryption for now. */
  2489. err = -EOPNOTSUPP;
  2490. goto out_unlock;
  2491. }
  2492. if (is_broadcast_ether_addr(addr)) {
  2493. /* addr is FF:FF:FF:FF:FF:FF for default keys */
  2494. err = b43_key_write(dev, index, algorithm,
  2495. key->key, key->keylen, NULL, key);
  2496. } else {
  2497. /*
  2498. * either pairwise key or address is 00:00:00:00:00:00
  2499. * for transmit-only keys
  2500. */
  2501. err = b43_key_write(dev, -1, algorithm,
  2502. key->key, key->keylen, addr, key);
  2503. }
  2504. if (err)
  2505. goto out_unlock;
  2506. if (algorithm == B43_SEC_ALGO_WEP40 ||
  2507. algorithm == B43_SEC_ALGO_WEP104) {
  2508. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_USEDEFKEYS);
  2509. } else {
  2510. b43_hf_write(dev,
  2511. b43_hf_read(dev) & ~B43_HF_USEDEFKEYS);
  2512. }
  2513. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2514. break;
  2515. case DISABLE_KEY: {
  2516. err = b43_key_clear(dev, key->hw_key_idx);
  2517. if (err)
  2518. goto out_unlock;
  2519. break;
  2520. }
  2521. default:
  2522. B43_WARN_ON(1);
  2523. }
  2524. out_unlock:
  2525. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2526. mutex_unlock(&wl->mutex);
  2527. out:
  2528. if (!err) {
  2529. b43dbg(wl, "%s hardware based encryption for keyidx: %d, "
  2530. "mac: %s\n",
  2531. cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
  2532. print_mac(mac, addr));
  2533. }
  2534. return err;
  2535. }
  2536. static void b43_configure_filter(struct ieee80211_hw *hw,
  2537. unsigned int changed, unsigned int *fflags,
  2538. int mc_count, struct dev_addr_list *mc_list)
  2539. {
  2540. struct b43_wl *wl = hw_to_b43_wl(hw);
  2541. struct b43_wldev *dev = wl->current_dev;
  2542. unsigned long flags;
  2543. if (!dev) {
  2544. *fflags = 0;
  2545. return;
  2546. }
  2547. spin_lock_irqsave(&wl->irq_lock, flags);
  2548. *fflags &= FIF_PROMISC_IN_BSS |
  2549. FIF_ALLMULTI |
  2550. FIF_FCSFAIL |
  2551. FIF_PLCPFAIL |
  2552. FIF_CONTROL |
  2553. FIF_OTHER_BSS |
  2554. FIF_BCN_PRBRESP_PROMISC;
  2555. changed &= FIF_PROMISC_IN_BSS |
  2556. FIF_ALLMULTI |
  2557. FIF_FCSFAIL |
  2558. FIF_PLCPFAIL |
  2559. FIF_CONTROL |
  2560. FIF_OTHER_BSS |
  2561. FIF_BCN_PRBRESP_PROMISC;
  2562. wl->filter_flags = *fflags;
  2563. if (changed && b43_status(dev) >= B43_STAT_INITIALIZED)
  2564. b43_adjust_opmode(dev);
  2565. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2566. }
  2567. static int b43_config_interface(struct ieee80211_hw *hw,
  2568. int if_id, struct ieee80211_if_conf *conf)
  2569. {
  2570. struct b43_wl *wl = hw_to_b43_wl(hw);
  2571. struct b43_wldev *dev = wl->current_dev;
  2572. unsigned long flags;
  2573. if (!dev)
  2574. return -ENODEV;
  2575. mutex_lock(&wl->mutex);
  2576. spin_lock_irqsave(&wl->irq_lock, flags);
  2577. B43_WARN_ON(wl->if_id != if_id);
  2578. if (conf->bssid)
  2579. memcpy(wl->bssid, conf->bssid, ETH_ALEN);
  2580. else
  2581. memset(wl->bssid, 0, ETH_ALEN);
  2582. if (b43_status(dev) >= B43_STAT_INITIALIZED) {
  2583. if (b43_is_mode(wl, IEEE80211_IF_TYPE_AP)) {
  2584. B43_WARN_ON(conf->type != IEEE80211_IF_TYPE_AP);
  2585. b43_set_ssid(dev, conf->ssid, conf->ssid_len);
  2586. if (conf->beacon)
  2587. b43_refresh_templates(dev, conf->beacon);
  2588. }
  2589. b43_write_mac_bssid_templates(dev);
  2590. }
  2591. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2592. mutex_unlock(&wl->mutex);
  2593. return 0;
  2594. }
  2595. /* Locking: wl->mutex */
  2596. static void b43_wireless_core_stop(struct b43_wldev *dev)
  2597. {
  2598. struct b43_wl *wl = dev->wl;
  2599. unsigned long flags;
  2600. if (b43_status(dev) < B43_STAT_STARTED)
  2601. return;
  2602. /* Disable and sync interrupts. We must do this before than
  2603. * setting the status to INITIALIZED, as the interrupt handler
  2604. * won't care about IRQs then. */
  2605. spin_lock_irqsave(&wl->irq_lock, flags);
  2606. dev->irq_savedstate = b43_interrupt_disable(dev, B43_IRQ_ALL);
  2607. b43_read32(dev, B43_MMIO_GEN_IRQ_MASK); /* flush */
  2608. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2609. b43_synchronize_irq(dev);
  2610. b43_set_status(dev, B43_STAT_INITIALIZED);
  2611. mutex_unlock(&wl->mutex);
  2612. /* Must unlock as it would otherwise deadlock. No races here.
  2613. * Cancel the possibly running self-rearming periodic work. */
  2614. cancel_delayed_work_sync(&dev->periodic_work);
  2615. mutex_lock(&wl->mutex);
  2616. ieee80211_stop_queues(wl->hw); //FIXME this could cause a deadlock, as mac80211 seems buggy.
  2617. b43_mac_suspend(dev);
  2618. free_irq(dev->dev->irq, dev);
  2619. b43dbg(wl, "Wireless interface stopped\n");
  2620. }
  2621. /* Locking: wl->mutex */
  2622. static int b43_wireless_core_start(struct b43_wldev *dev)
  2623. {
  2624. int err;
  2625. B43_WARN_ON(b43_status(dev) != B43_STAT_INITIALIZED);
  2626. drain_txstatus_queue(dev);
  2627. err = request_irq(dev->dev->irq, b43_interrupt_handler,
  2628. IRQF_SHARED, KBUILD_MODNAME, dev);
  2629. if (err) {
  2630. b43err(dev->wl, "Cannot request IRQ-%d\n", dev->dev->irq);
  2631. goto out;
  2632. }
  2633. /* We are ready to run. */
  2634. b43_set_status(dev, B43_STAT_STARTED);
  2635. /* Start data flow (TX/RX). */
  2636. b43_mac_enable(dev);
  2637. b43_interrupt_enable(dev, dev->irq_savedstate);
  2638. ieee80211_start_queues(dev->wl->hw);
  2639. /* Start maintainance work */
  2640. b43_periodic_tasks_setup(dev);
  2641. b43dbg(dev->wl, "Wireless interface started\n");
  2642. out:
  2643. return err;
  2644. }
  2645. /* Get PHY and RADIO versioning numbers */
  2646. static int b43_phy_versioning(struct b43_wldev *dev)
  2647. {
  2648. struct b43_phy *phy = &dev->phy;
  2649. u32 tmp;
  2650. u8 analog_type;
  2651. u8 phy_type;
  2652. u8 phy_rev;
  2653. u16 radio_manuf;
  2654. u16 radio_ver;
  2655. u16 radio_rev;
  2656. int unsupported = 0;
  2657. /* Get PHY versioning */
  2658. tmp = b43_read16(dev, B43_MMIO_PHY_VER);
  2659. analog_type = (tmp & B43_PHYVER_ANALOG) >> B43_PHYVER_ANALOG_SHIFT;
  2660. phy_type = (tmp & B43_PHYVER_TYPE) >> B43_PHYVER_TYPE_SHIFT;
  2661. phy_rev = (tmp & B43_PHYVER_VERSION);
  2662. switch (phy_type) {
  2663. case B43_PHYTYPE_A:
  2664. if (phy_rev >= 4)
  2665. unsupported = 1;
  2666. break;
  2667. case B43_PHYTYPE_B:
  2668. if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6
  2669. && phy_rev != 7)
  2670. unsupported = 1;
  2671. break;
  2672. case B43_PHYTYPE_G:
  2673. if (phy_rev > 8)
  2674. unsupported = 1;
  2675. break;
  2676. default:
  2677. unsupported = 1;
  2678. };
  2679. if (unsupported) {
  2680. b43err(dev->wl, "FOUND UNSUPPORTED PHY "
  2681. "(Analog %u, Type %u, Revision %u)\n",
  2682. analog_type, phy_type, phy_rev);
  2683. return -EOPNOTSUPP;
  2684. }
  2685. b43dbg(dev->wl, "Found PHY: Analog %u, Type %u, Revision %u\n",
  2686. analog_type, phy_type, phy_rev);
  2687. /* Get RADIO versioning */
  2688. if (dev->dev->bus->chip_id == 0x4317) {
  2689. if (dev->dev->bus->chip_rev == 0)
  2690. tmp = 0x3205017F;
  2691. else if (dev->dev->bus->chip_rev == 1)
  2692. tmp = 0x4205017F;
  2693. else
  2694. tmp = 0x5205017F;
  2695. } else {
  2696. b43_write16(dev, B43_MMIO_RADIO_CONTROL, B43_RADIOCTL_ID);
  2697. tmp = b43_read16(dev, B43_MMIO_RADIO_DATA_HIGH);
  2698. tmp <<= 16;
  2699. b43_write16(dev, B43_MMIO_RADIO_CONTROL, B43_RADIOCTL_ID);
  2700. tmp |= b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
  2701. }
  2702. radio_manuf = (tmp & 0x00000FFF);
  2703. radio_ver = (tmp & 0x0FFFF000) >> 12;
  2704. radio_rev = (tmp & 0xF0000000) >> 28;
  2705. switch (phy_type) {
  2706. case B43_PHYTYPE_A:
  2707. if (radio_ver != 0x2060)
  2708. unsupported = 1;
  2709. if (radio_rev != 1)
  2710. unsupported = 1;
  2711. if (radio_manuf != 0x17F)
  2712. unsupported = 1;
  2713. break;
  2714. case B43_PHYTYPE_B:
  2715. if ((radio_ver & 0xFFF0) != 0x2050)
  2716. unsupported = 1;
  2717. break;
  2718. case B43_PHYTYPE_G:
  2719. if (radio_ver != 0x2050)
  2720. unsupported = 1;
  2721. break;
  2722. default:
  2723. B43_WARN_ON(1);
  2724. }
  2725. if (unsupported) {
  2726. b43err(dev->wl, "FOUND UNSUPPORTED RADIO "
  2727. "(Manuf 0x%X, Version 0x%X, Revision %u)\n",
  2728. radio_manuf, radio_ver, radio_rev);
  2729. return -EOPNOTSUPP;
  2730. }
  2731. b43dbg(dev->wl, "Found Radio: Manuf 0x%X, Version 0x%X, Revision %u\n",
  2732. radio_manuf, radio_ver, radio_rev);
  2733. phy->radio_manuf = radio_manuf;
  2734. phy->radio_ver = radio_ver;
  2735. phy->radio_rev = radio_rev;
  2736. phy->analog = analog_type;
  2737. phy->type = phy_type;
  2738. phy->rev = phy_rev;
  2739. return 0;
  2740. }
  2741. static void setup_struct_phy_for_init(struct b43_wldev *dev,
  2742. struct b43_phy *phy)
  2743. {
  2744. struct b43_txpower_lo_control *lo;
  2745. int i;
  2746. memset(phy->minlowsig, 0xFF, sizeof(phy->minlowsig));
  2747. memset(phy->minlowsigpos, 0, sizeof(phy->minlowsigpos));
  2748. /* Flags */
  2749. phy->locked = 0;
  2750. phy->aci_enable = 0;
  2751. phy->aci_wlan_automatic = 0;
  2752. phy->aci_hw_rssi = 0;
  2753. phy->radio_off_context.valid = 0;
  2754. lo = phy->lo_control;
  2755. if (lo) {
  2756. memset(lo, 0, sizeof(*(phy->lo_control)));
  2757. lo->rebuild = 1;
  2758. lo->tx_bias = 0xFF;
  2759. }
  2760. phy->max_lb_gain = 0;
  2761. phy->trsw_rx_gain = 0;
  2762. phy->txpwr_offset = 0;
  2763. /* NRSSI */
  2764. phy->nrssislope = 0;
  2765. for (i = 0; i < ARRAY_SIZE(phy->nrssi); i++)
  2766. phy->nrssi[i] = -1000;
  2767. for (i = 0; i < ARRAY_SIZE(phy->nrssi_lt); i++)
  2768. phy->nrssi_lt[i] = i;
  2769. phy->lofcal = 0xFFFF;
  2770. phy->initval = 0xFFFF;
  2771. spin_lock_init(&phy->lock);
  2772. phy->interfmode = B43_INTERFMODE_NONE;
  2773. phy->channel = 0xFF;
  2774. phy->hardware_power_control = !!modparam_hwpctl;
  2775. }
  2776. static void setup_struct_wldev_for_init(struct b43_wldev *dev)
  2777. {
  2778. /* Flags */
  2779. dev->reg124_set_0x4 = 0;
  2780. /* Assume the radio is enabled. If it's not enabled, the state will
  2781. * immediately get fixed on the first periodic work run. */
  2782. dev->radio_hw_enable = 1;
  2783. /* Stats */
  2784. memset(&dev->stats, 0, sizeof(dev->stats));
  2785. setup_struct_phy_for_init(dev, &dev->phy);
  2786. /* IRQ related flags */
  2787. dev->irq_reason = 0;
  2788. memset(dev->dma_reason, 0, sizeof(dev->dma_reason));
  2789. dev->irq_savedstate = B43_IRQ_MASKTEMPLATE;
  2790. dev->mac_suspended = 1;
  2791. /* Noise calculation context */
  2792. memset(&dev->noisecalc, 0, sizeof(dev->noisecalc));
  2793. }
  2794. static void b43_bluetooth_coext_enable(struct b43_wldev *dev)
  2795. {
  2796. struct ssb_sprom *sprom = &dev->dev->bus->sprom;
  2797. u32 hf;
  2798. if (!(sprom->r1.boardflags_lo & B43_BFL_BTCOEXIST))
  2799. return;
  2800. if (dev->phy.type != B43_PHYTYPE_B && !dev->phy.gmode)
  2801. return;
  2802. hf = b43_hf_read(dev);
  2803. if (sprom->r1.boardflags_lo & B43_BFL_BTCMOD)
  2804. hf |= B43_HF_BTCOEXALT;
  2805. else
  2806. hf |= B43_HF_BTCOEX;
  2807. b43_hf_write(dev, hf);
  2808. //TODO
  2809. }
  2810. static void b43_bluetooth_coext_disable(struct b43_wldev *dev)
  2811. { //TODO
  2812. }
  2813. static void b43_imcfglo_timeouts_workaround(struct b43_wldev *dev)
  2814. {
  2815. #ifdef CONFIG_SSB_DRIVER_PCICORE
  2816. struct ssb_bus *bus = dev->dev->bus;
  2817. u32 tmp;
  2818. if (bus->pcicore.dev &&
  2819. bus->pcicore.dev->id.coreid == SSB_DEV_PCI &&
  2820. bus->pcicore.dev->id.revision <= 5) {
  2821. /* IMCFGLO timeouts workaround. */
  2822. tmp = ssb_read32(dev->dev, SSB_IMCFGLO);
  2823. tmp &= ~SSB_IMCFGLO_REQTO;
  2824. tmp &= ~SSB_IMCFGLO_SERTO;
  2825. switch (bus->bustype) {
  2826. case SSB_BUSTYPE_PCI:
  2827. case SSB_BUSTYPE_PCMCIA:
  2828. tmp |= 0x32;
  2829. break;
  2830. case SSB_BUSTYPE_SSB:
  2831. tmp |= 0x53;
  2832. break;
  2833. }
  2834. ssb_write32(dev->dev, SSB_IMCFGLO, tmp);
  2835. }
  2836. #endif /* CONFIG_SSB_DRIVER_PCICORE */
  2837. }
  2838. /* Shutdown a wireless core */
  2839. /* Locking: wl->mutex */
  2840. static void b43_wireless_core_exit(struct b43_wldev *dev)
  2841. {
  2842. struct b43_phy *phy = &dev->phy;
  2843. B43_WARN_ON(b43_status(dev) > B43_STAT_INITIALIZED);
  2844. if (b43_status(dev) != B43_STAT_INITIALIZED)
  2845. return;
  2846. b43_set_status(dev, B43_STAT_UNINIT);
  2847. b43_leds_exit(dev);
  2848. b43_rng_exit(dev->wl);
  2849. b43_pio_free(dev);
  2850. b43_dma_free(dev);
  2851. b43_chip_exit(dev);
  2852. b43_radio_turn_off(dev, 1);
  2853. b43_switch_analog(dev, 0);
  2854. if (phy->dyn_tssi_tbl)
  2855. kfree(phy->tssi2dbm);
  2856. kfree(phy->lo_control);
  2857. phy->lo_control = NULL;
  2858. ssb_device_disable(dev->dev, 0);
  2859. ssb_bus_may_powerdown(dev->dev->bus);
  2860. }
  2861. /* Initialize a wireless core */
  2862. static int b43_wireless_core_init(struct b43_wldev *dev)
  2863. {
  2864. struct b43_wl *wl = dev->wl;
  2865. struct ssb_bus *bus = dev->dev->bus;
  2866. struct ssb_sprom *sprom = &bus->sprom;
  2867. struct b43_phy *phy = &dev->phy;
  2868. int err;
  2869. u32 hf, tmp;
  2870. B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
  2871. err = ssb_bus_powerup(bus, 0);
  2872. if (err)
  2873. goto out;
  2874. if (!ssb_device_is_enabled(dev->dev)) {
  2875. tmp = phy->gmode ? B43_TMSLOW_GMODE : 0;
  2876. b43_wireless_core_reset(dev, tmp);
  2877. }
  2878. if ((phy->type == B43_PHYTYPE_B) || (phy->type == B43_PHYTYPE_G)) {
  2879. phy->lo_control =
  2880. kzalloc(sizeof(*(phy->lo_control)), GFP_KERNEL);
  2881. if (!phy->lo_control) {
  2882. err = -ENOMEM;
  2883. goto err_busdown;
  2884. }
  2885. }
  2886. setup_struct_wldev_for_init(dev);
  2887. err = b43_phy_init_tssi2dbm_table(dev);
  2888. if (err)
  2889. goto err_kfree_lo_control;
  2890. /* Enable IRQ routing to this device. */
  2891. ssb_pcicore_dev_irqvecs_enable(&bus->pcicore, dev->dev);
  2892. b43_imcfglo_timeouts_workaround(dev);
  2893. b43_bluetooth_coext_disable(dev);
  2894. b43_phy_early_init(dev);
  2895. err = b43_chip_init(dev);
  2896. if (err)
  2897. goto err_kfree_tssitbl;
  2898. b43_shm_write16(dev, B43_SHM_SHARED,
  2899. B43_SHM_SH_WLCOREREV, dev->dev->id.revision);
  2900. hf = b43_hf_read(dev);
  2901. if (phy->type == B43_PHYTYPE_G) {
  2902. hf |= B43_HF_SYMW;
  2903. if (phy->rev == 1)
  2904. hf |= B43_HF_GDCW;
  2905. if (sprom->r1.boardflags_lo & B43_BFL_PACTRL)
  2906. hf |= B43_HF_OFDMPABOOST;
  2907. } else if (phy->type == B43_PHYTYPE_B) {
  2908. hf |= B43_HF_SYMW;
  2909. if (phy->rev >= 2 && phy->radio_ver == 0x2050)
  2910. hf &= ~B43_HF_GDCW;
  2911. }
  2912. b43_hf_write(dev, hf);
  2913. /* Short/Long Retry Limit.
  2914. * The retry-limit is a 4-bit counter. Enforce this to avoid overflowing
  2915. * the chip-internal counter.
  2916. */
  2917. tmp = limit_value(modparam_short_retry, 0, 0xF);
  2918. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_SRLIMIT, tmp);
  2919. tmp = limit_value(modparam_long_retry, 0, 0xF);
  2920. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_LRLIMIT, tmp);
  2921. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_SFFBLIM, 3);
  2922. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_LFFBLIM, 2);
  2923. /* Disable sending probe responses from firmware.
  2924. * Setting the MaxTime to one usec will always trigger
  2925. * a timeout, so we never send any probe resp.
  2926. * A timeout of zero is infinite. */
  2927. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRMAXTIME, 1);
  2928. b43_rate_memory_init(dev);
  2929. /* Minimum Contention Window */
  2930. if (phy->type == B43_PHYTYPE_B) {
  2931. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MINCONT, 0x1F);
  2932. } else {
  2933. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MINCONT, 0xF);
  2934. }
  2935. /* Maximum Contention Window */
  2936. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MAXCONT, 0x3FF);
  2937. do {
  2938. if (b43_using_pio(dev)) {
  2939. err = b43_pio_init(dev);
  2940. } else {
  2941. err = b43_dma_init(dev);
  2942. if (!err)
  2943. b43_qos_init(dev);
  2944. }
  2945. } while (err == -EAGAIN);
  2946. if (err)
  2947. goto err_chip_exit;
  2948. //FIXME
  2949. #if 1
  2950. b43_write16(dev, 0x0612, 0x0050);
  2951. b43_shm_write16(dev, B43_SHM_SHARED, 0x0416, 0x0050);
  2952. b43_shm_write16(dev, B43_SHM_SHARED, 0x0414, 0x01F4);
  2953. #endif
  2954. b43_bluetooth_coext_enable(dev);
  2955. ssb_bus_powerup(bus, 1); /* Enable dynamic PCTL */
  2956. memset(wl->bssid, 0, ETH_ALEN);
  2957. memset(wl->mac_addr, 0, ETH_ALEN);
  2958. b43_upload_card_macaddress(dev);
  2959. b43_security_init(dev);
  2960. b43_rng_init(wl);
  2961. b43_set_status(dev, B43_STAT_INITIALIZED);
  2962. b43_leds_init(dev);
  2963. out:
  2964. return err;
  2965. err_chip_exit:
  2966. b43_chip_exit(dev);
  2967. err_kfree_tssitbl:
  2968. if (phy->dyn_tssi_tbl)
  2969. kfree(phy->tssi2dbm);
  2970. err_kfree_lo_control:
  2971. kfree(phy->lo_control);
  2972. phy->lo_control = NULL;
  2973. err_busdown:
  2974. ssb_bus_may_powerdown(bus);
  2975. B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
  2976. return err;
  2977. }
  2978. static int b43_add_interface(struct ieee80211_hw *hw,
  2979. struct ieee80211_if_init_conf *conf)
  2980. {
  2981. struct b43_wl *wl = hw_to_b43_wl(hw);
  2982. struct b43_wldev *dev;
  2983. unsigned long flags;
  2984. int err = -EOPNOTSUPP;
  2985. /* TODO: allow WDS/AP devices to coexist */
  2986. if (conf->type != IEEE80211_IF_TYPE_AP &&
  2987. conf->type != IEEE80211_IF_TYPE_STA &&
  2988. conf->type != IEEE80211_IF_TYPE_WDS &&
  2989. conf->type != IEEE80211_IF_TYPE_IBSS)
  2990. return -EOPNOTSUPP;
  2991. mutex_lock(&wl->mutex);
  2992. if (wl->operating)
  2993. goto out_mutex_unlock;
  2994. b43dbg(wl, "Adding Interface type %d\n", conf->type);
  2995. dev = wl->current_dev;
  2996. wl->operating = 1;
  2997. wl->if_id = conf->if_id;
  2998. wl->if_type = conf->type;
  2999. memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN);
  3000. spin_lock_irqsave(&wl->irq_lock, flags);
  3001. b43_adjust_opmode(dev);
  3002. b43_upload_card_macaddress(dev);
  3003. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3004. err = 0;
  3005. out_mutex_unlock:
  3006. mutex_unlock(&wl->mutex);
  3007. return err;
  3008. }
  3009. static void b43_remove_interface(struct ieee80211_hw *hw,
  3010. struct ieee80211_if_init_conf *conf)
  3011. {
  3012. struct b43_wl *wl = hw_to_b43_wl(hw);
  3013. struct b43_wldev *dev = wl->current_dev;
  3014. unsigned long flags;
  3015. b43dbg(wl, "Removing Interface type %d\n", conf->type);
  3016. mutex_lock(&wl->mutex);
  3017. B43_WARN_ON(!wl->operating);
  3018. B43_WARN_ON(wl->if_id != conf->if_id);
  3019. wl->operating = 0;
  3020. spin_lock_irqsave(&wl->irq_lock, flags);
  3021. b43_adjust_opmode(dev);
  3022. memset(wl->mac_addr, 0, ETH_ALEN);
  3023. b43_upload_card_macaddress(dev);
  3024. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3025. mutex_unlock(&wl->mutex);
  3026. }
  3027. static int b43_start(struct ieee80211_hw *hw)
  3028. {
  3029. struct b43_wl *wl = hw_to_b43_wl(hw);
  3030. struct b43_wldev *dev = wl->current_dev;
  3031. int did_init = 0;
  3032. int err = 0;
  3033. /* First register RFkill.
  3034. * LEDs that are registered later depend on it. */
  3035. b43_rfkill_init(dev);
  3036. mutex_lock(&wl->mutex);
  3037. if (b43_status(dev) < B43_STAT_INITIALIZED) {
  3038. err = b43_wireless_core_init(dev);
  3039. if (err)
  3040. goto out_mutex_unlock;
  3041. did_init = 1;
  3042. }
  3043. if (b43_status(dev) < B43_STAT_STARTED) {
  3044. err = b43_wireless_core_start(dev);
  3045. if (err) {
  3046. if (did_init)
  3047. b43_wireless_core_exit(dev);
  3048. goto out_mutex_unlock;
  3049. }
  3050. }
  3051. out_mutex_unlock:
  3052. mutex_unlock(&wl->mutex);
  3053. return err;
  3054. }
  3055. static void b43_stop(struct ieee80211_hw *hw)
  3056. {
  3057. struct b43_wl *wl = hw_to_b43_wl(hw);
  3058. struct b43_wldev *dev = wl->current_dev;
  3059. b43_rfkill_exit(dev);
  3060. mutex_lock(&wl->mutex);
  3061. if (b43_status(dev) >= B43_STAT_STARTED)
  3062. b43_wireless_core_stop(dev);
  3063. b43_wireless_core_exit(dev);
  3064. mutex_unlock(&wl->mutex);
  3065. }
  3066. static const struct ieee80211_ops b43_hw_ops = {
  3067. .tx = b43_tx,
  3068. .conf_tx = b43_conf_tx,
  3069. .add_interface = b43_add_interface,
  3070. .remove_interface = b43_remove_interface,
  3071. .config = b43_dev_config,
  3072. .config_interface = b43_config_interface,
  3073. .configure_filter = b43_configure_filter,
  3074. .set_key = b43_dev_set_key,
  3075. .get_stats = b43_get_stats,
  3076. .get_tx_stats = b43_get_tx_stats,
  3077. .start = b43_start,
  3078. .stop = b43_stop,
  3079. };
  3080. /* Hard-reset the chip. Do not call this directly.
  3081. * Use b43_controller_restart()
  3082. */
  3083. static void b43_chip_reset(struct work_struct *work)
  3084. {
  3085. struct b43_wldev *dev =
  3086. container_of(work, struct b43_wldev, restart_work);
  3087. struct b43_wl *wl = dev->wl;
  3088. int err = 0;
  3089. int prev_status;
  3090. mutex_lock(&wl->mutex);
  3091. prev_status = b43_status(dev);
  3092. /* Bring the device down... */
  3093. if (prev_status >= B43_STAT_STARTED)
  3094. b43_wireless_core_stop(dev);
  3095. if (prev_status >= B43_STAT_INITIALIZED)
  3096. b43_wireless_core_exit(dev);
  3097. /* ...and up again. */
  3098. if (prev_status >= B43_STAT_INITIALIZED) {
  3099. err = b43_wireless_core_init(dev);
  3100. if (err)
  3101. goto out;
  3102. }
  3103. if (prev_status >= B43_STAT_STARTED) {
  3104. err = b43_wireless_core_start(dev);
  3105. if (err) {
  3106. b43_wireless_core_exit(dev);
  3107. goto out;
  3108. }
  3109. }
  3110. out:
  3111. mutex_unlock(&wl->mutex);
  3112. if (err)
  3113. b43err(wl, "Controller restart FAILED\n");
  3114. else
  3115. b43info(wl, "Controller restarted\n");
  3116. }
  3117. static int b43_setup_modes(struct b43_wldev *dev,
  3118. int have_aphy, int have_bphy, int have_gphy)
  3119. {
  3120. struct ieee80211_hw *hw = dev->wl->hw;
  3121. struct ieee80211_hw_mode *mode;
  3122. struct b43_phy *phy = &dev->phy;
  3123. int cnt = 0;
  3124. int err;
  3125. /*FIXME: Don't tell ieee80211 about an A-PHY, because we currently don't support A-PHY. */
  3126. have_aphy = 0;
  3127. phy->possible_phymodes = 0;
  3128. for (; 1; cnt++) {
  3129. if (have_aphy) {
  3130. B43_WARN_ON(cnt >= B43_MAX_PHYHWMODES);
  3131. mode = &phy->hwmodes[cnt];
  3132. mode->mode = MODE_IEEE80211A;
  3133. mode->num_channels = b43_a_chantable_size;
  3134. mode->channels = b43_a_chantable;
  3135. mode->num_rates = b43_a_ratetable_size;
  3136. mode->rates = b43_a_ratetable;
  3137. err = ieee80211_register_hwmode(hw, mode);
  3138. if (err)
  3139. return err;
  3140. phy->possible_phymodes |= B43_PHYMODE_A;
  3141. have_aphy = 0;
  3142. continue;
  3143. }
  3144. if (have_bphy) {
  3145. B43_WARN_ON(cnt >= B43_MAX_PHYHWMODES);
  3146. mode = &phy->hwmodes[cnt];
  3147. mode->mode = MODE_IEEE80211B;
  3148. mode->num_channels = b43_bg_chantable_size;
  3149. mode->channels = b43_bg_chantable;
  3150. mode->num_rates = b43_b_ratetable_size;
  3151. mode->rates = b43_b_ratetable;
  3152. err = ieee80211_register_hwmode(hw, mode);
  3153. if (err)
  3154. return err;
  3155. phy->possible_phymodes |= B43_PHYMODE_B;
  3156. have_bphy = 0;
  3157. continue;
  3158. }
  3159. if (have_gphy) {
  3160. B43_WARN_ON(cnt >= B43_MAX_PHYHWMODES);
  3161. mode = &phy->hwmodes[cnt];
  3162. mode->mode = MODE_IEEE80211G;
  3163. mode->num_channels = b43_bg_chantable_size;
  3164. mode->channels = b43_bg_chantable;
  3165. mode->num_rates = b43_g_ratetable_size;
  3166. mode->rates = b43_g_ratetable;
  3167. err = ieee80211_register_hwmode(hw, mode);
  3168. if (err)
  3169. return err;
  3170. phy->possible_phymodes |= B43_PHYMODE_G;
  3171. have_gphy = 0;
  3172. continue;
  3173. }
  3174. break;
  3175. }
  3176. return 0;
  3177. }
  3178. static void b43_wireless_core_detach(struct b43_wldev *dev)
  3179. {
  3180. /* We release firmware that late to not be required to re-request
  3181. * is all the time when we reinit the core. */
  3182. b43_release_firmware(dev);
  3183. }
  3184. static int b43_wireless_core_attach(struct b43_wldev *dev)
  3185. {
  3186. struct b43_wl *wl = dev->wl;
  3187. struct ssb_bus *bus = dev->dev->bus;
  3188. struct pci_dev *pdev = bus->host_pci;
  3189. int err;
  3190. int have_aphy = 0, have_bphy = 0, have_gphy = 0;
  3191. u32 tmp;
  3192. /* Do NOT do any device initialization here.
  3193. * Do it in wireless_core_init() instead.
  3194. * This function is for gathering basic information about the HW, only.
  3195. * Also some structs may be set up here. But most likely you want to have
  3196. * that in core_init(), too.
  3197. */
  3198. err = ssb_bus_powerup(bus, 0);
  3199. if (err) {
  3200. b43err(wl, "Bus powerup failed\n");
  3201. goto out;
  3202. }
  3203. /* Get the PHY type. */
  3204. if (dev->dev->id.revision >= 5) {
  3205. u32 tmshigh;
  3206. tmshigh = ssb_read32(dev->dev, SSB_TMSHIGH);
  3207. have_aphy = !!(tmshigh & B43_TMSHIGH_APHY);
  3208. have_gphy = !!(tmshigh & B43_TMSHIGH_GPHY);
  3209. if (!have_aphy && !have_gphy)
  3210. have_bphy = 1;
  3211. } else if (dev->dev->id.revision == 4) {
  3212. have_gphy = 1;
  3213. have_aphy = 1;
  3214. } else
  3215. have_bphy = 1;
  3216. dev->phy.gmode = (have_gphy || have_bphy);
  3217. tmp = dev->phy.gmode ? B43_TMSLOW_GMODE : 0;
  3218. b43_wireless_core_reset(dev, tmp);
  3219. err = b43_phy_versioning(dev);
  3220. if (err)
  3221. goto err_powerdown;
  3222. /* Check if this device supports multiband. */
  3223. if (!pdev ||
  3224. (pdev->device != 0x4312 &&
  3225. pdev->device != 0x4319 && pdev->device != 0x4324)) {
  3226. /* No multiband support. */
  3227. have_aphy = 0;
  3228. have_bphy = 0;
  3229. have_gphy = 0;
  3230. switch (dev->phy.type) {
  3231. case B43_PHYTYPE_A:
  3232. have_aphy = 1;
  3233. break;
  3234. case B43_PHYTYPE_B:
  3235. have_bphy = 1;
  3236. break;
  3237. case B43_PHYTYPE_G:
  3238. have_gphy = 1;
  3239. break;
  3240. default:
  3241. B43_WARN_ON(1);
  3242. }
  3243. }
  3244. dev->phy.gmode = (have_gphy || have_bphy);
  3245. tmp = dev->phy.gmode ? B43_TMSLOW_GMODE : 0;
  3246. b43_wireless_core_reset(dev, tmp);
  3247. err = b43_validate_chipaccess(dev);
  3248. if (err)
  3249. goto err_powerdown;
  3250. err = b43_setup_modes(dev, have_aphy, have_bphy, have_gphy);
  3251. if (err)
  3252. goto err_powerdown;
  3253. /* Now set some default "current_dev" */
  3254. if (!wl->current_dev)
  3255. wl->current_dev = dev;
  3256. INIT_WORK(&dev->restart_work, b43_chip_reset);
  3257. b43_radio_turn_off(dev, 1);
  3258. b43_switch_analog(dev, 0);
  3259. ssb_device_disable(dev->dev, 0);
  3260. ssb_bus_may_powerdown(bus);
  3261. out:
  3262. return err;
  3263. err_powerdown:
  3264. ssb_bus_may_powerdown(bus);
  3265. return err;
  3266. }
  3267. static void b43_one_core_detach(struct ssb_device *dev)
  3268. {
  3269. struct b43_wldev *wldev;
  3270. struct b43_wl *wl;
  3271. wldev = ssb_get_drvdata(dev);
  3272. wl = wldev->wl;
  3273. cancel_work_sync(&wldev->restart_work);
  3274. b43_debugfs_remove_device(wldev);
  3275. b43_wireless_core_detach(wldev);
  3276. list_del(&wldev->list);
  3277. wl->nr_devs--;
  3278. ssb_set_drvdata(dev, NULL);
  3279. kfree(wldev);
  3280. }
  3281. static int b43_one_core_attach(struct ssb_device *dev, struct b43_wl *wl)
  3282. {
  3283. struct b43_wldev *wldev;
  3284. struct pci_dev *pdev;
  3285. int err = -ENOMEM;
  3286. if (!list_empty(&wl->devlist)) {
  3287. /* We are not the first core on this chip. */
  3288. pdev = dev->bus->host_pci;
  3289. /* Only special chips support more than one wireless
  3290. * core, although some of the other chips have more than
  3291. * one wireless core as well. Check for this and
  3292. * bail out early.
  3293. */
  3294. if (!pdev ||
  3295. ((pdev->device != 0x4321) &&
  3296. (pdev->device != 0x4313) && (pdev->device != 0x431A))) {
  3297. b43dbg(wl, "Ignoring unconnected 802.11 core\n");
  3298. return -ENODEV;
  3299. }
  3300. }
  3301. wldev = kzalloc(sizeof(*wldev), GFP_KERNEL);
  3302. if (!wldev)
  3303. goto out;
  3304. wldev->dev = dev;
  3305. wldev->wl = wl;
  3306. b43_set_status(wldev, B43_STAT_UNINIT);
  3307. wldev->bad_frames_preempt = modparam_bad_frames_preempt;
  3308. tasklet_init(&wldev->isr_tasklet,
  3309. (void (*)(unsigned long))b43_interrupt_tasklet,
  3310. (unsigned long)wldev);
  3311. if (modparam_pio)
  3312. wldev->__using_pio = 1;
  3313. INIT_LIST_HEAD(&wldev->list);
  3314. err = b43_wireless_core_attach(wldev);
  3315. if (err)
  3316. goto err_kfree_wldev;
  3317. list_add(&wldev->list, &wl->devlist);
  3318. wl->nr_devs++;
  3319. ssb_set_drvdata(dev, wldev);
  3320. b43_debugfs_add_device(wldev);
  3321. out:
  3322. return err;
  3323. err_kfree_wldev:
  3324. kfree(wldev);
  3325. return err;
  3326. }
  3327. static void b43_sprom_fixup(struct ssb_bus *bus)
  3328. {
  3329. /* boardflags workarounds */
  3330. if (bus->boardinfo.vendor == SSB_BOARDVENDOR_DELL &&
  3331. bus->chip_id == 0x4301 && bus->boardinfo.rev == 0x74)
  3332. bus->sprom.r1.boardflags_lo |= B43_BFL_BTCOEXIST;
  3333. if (bus->boardinfo.vendor == PCI_VENDOR_ID_APPLE &&
  3334. bus->boardinfo.type == 0x4E && bus->boardinfo.rev > 0x40)
  3335. bus->sprom.r1.boardflags_lo |= B43_BFL_PACTRL;
  3336. /* Handle case when gain is not set in sprom */
  3337. if (bus->sprom.r1.antenna_gain_a == 0xFF)
  3338. bus->sprom.r1.antenna_gain_a = 2;
  3339. if (bus->sprom.r1.antenna_gain_bg == 0xFF)
  3340. bus->sprom.r1.antenna_gain_bg = 2;
  3341. /* Convert Antennagain values to Q5.2 */
  3342. bus->sprom.r1.antenna_gain_a <<= 2;
  3343. bus->sprom.r1.antenna_gain_bg <<= 2;
  3344. }
  3345. static void b43_wireless_exit(struct ssb_device *dev, struct b43_wl *wl)
  3346. {
  3347. struct ieee80211_hw *hw = wl->hw;
  3348. ssb_set_devtypedata(dev, NULL);
  3349. ieee80211_free_hw(hw);
  3350. }
  3351. static int b43_wireless_init(struct ssb_device *dev)
  3352. {
  3353. struct ssb_sprom *sprom = &dev->bus->sprom;
  3354. struct ieee80211_hw *hw;
  3355. struct b43_wl *wl;
  3356. int err = -ENOMEM;
  3357. b43_sprom_fixup(dev->bus);
  3358. hw = ieee80211_alloc_hw(sizeof(*wl), &b43_hw_ops);
  3359. if (!hw) {
  3360. b43err(NULL, "Could not allocate ieee80211 device\n");
  3361. goto out;
  3362. }
  3363. /* fill hw info */
  3364. hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
  3365. hw->max_signal = 100;
  3366. hw->max_rssi = -110;
  3367. hw->max_noise = -110;
  3368. hw->queues = 1; /* FIXME: hardware has more queues */
  3369. SET_IEEE80211_DEV(hw, dev->dev);
  3370. if (is_valid_ether_addr(sprom->r1.et1mac))
  3371. SET_IEEE80211_PERM_ADDR(hw, sprom->r1.et1mac);
  3372. else
  3373. SET_IEEE80211_PERM_ADDR(hw, sprom->r1.il0mac);
  3374. /* Get and initialize struct b43_wl */
  3375. wl = hw_to_b43_wl(hw);
  3376. memset(wl, 0, sizeof(*wl));
  3377. wl->hw = hw;
  3378. spin_lock_init(&wl->irq_lock);
  3379. spin_lock_init(&wl->leds_lock);
  3380. mutex_init(&wl->mutex);
  3381. INIT_LIST_HEAD(&wl->devlist);
  3382. ssb_set_devtypedata(dev, wl);
  3383. b43info(wl, "Broadcom %04X WLAN found\n", dev->bus->chip_id);
  3384. err = 0;
  3385. out:
  3386. return err;
  3387. }
  3388. static int b43_probe(struct ssb_device *dev, const struct ssb_device_id *id)
  3389. {
  3390. struct b43_wl *wl;
  3391. int err;
  3392. int first = 0;
  3393. wl = ssb_get_devtypedata(dev);
  3394. if (!wl) {
  3395. /* Probing the first core. Must setup common struct b43_wl */
  3396. first = 1;
  3397. err = b43_wireless_init(dev);
  3398. if (err)
  3399. goto out;
  3400. wl = ssb_get_devtypedata(dev);
  3401. B43_WARN_ON(!wl);
  3402. }
  3403. err = b43_one_core_attach(dev, wl);
  3404. if (err)
  3405. goto err_wireless_exit;
  3406. if (first) {
  3407. err = ieee80211_register_hw(wl->hw);
  3408. if (err)
  3409. goto err_one_core_detach;
  3410. }
  3411. out:
  3412. return err;
  3413. err_one_core_detach:
  3414. b43_one_core_detach(dev);
  3415. err_wireless_exit:
  3416. if (first)
  3417. b43_wireless_exit(dev, wl);
  3418. return err;
  3419. }
  3420. static void b43_remove(struct ssb_device *dev)
  3421. {
  3422. struct b43_wl *wl = ssb_get_devtypedata(dev);
  3423. struct b43_wldev *wldev = ssb_get_drvdata(dev);
  3424. B43_WARN_ON(!wl);
  3425. if (wl->current_dev == wldev)
  3426. ieee80211_unregister_hw(wl->hw);
  3427. b43_one_core_detach(dev);
  3428. if (list_empty(&wl->devlist)) {
  3429. /* Last core on the chip unregistered.
  3430. * We can destroy common struct b43_wl.
  3431. */
  3432. b43_wireless_exit(dev, wl);
  3433. }
  3434. }
  3435. /* Perform a hardware reset. This can be called from any context. */
  3436. void b43_controller_restart(struct b43_wldev *dev, const char *reason)
  3437. {
  3438. /* Must avoid requeueing, if we are in shutdown. */
  3439. if (b43_status(dev) < B43_STAT_INITIALIZED)
  3440. return;
  3441. b43info(dev->wl, "Controller RESET (%s) ...\n", reason);
  3442. queue_work(dev->wl->hw->workqueue, &dev->restart_work);
  3443. }
  3444. #ifdef CONFIG_PM
  3445. static int b43_suspend(struct ssb_device *dev, pm_message_t state)
  3446. {
  3447. struct b43_wldev *wldev = ssb_get_drvdata(dev);
  3448. struct b43_wl *wl = wldev->wl;
  3449. b43dbg(wl, "Suspending...\n");
  3450. mutex_lock(&wl->mutex);
  3451. wldev->suspend_init_status = b43_status(wldev);
  3452. if (wldev->suspend_init_status >= B43_STAT_STARTED)
  3453. b43_wireless_core_stop(wldev);
  3454. if (wldev->suspend_init_status >= B43_STAT_INITIALIZED)
  3455. b43_wireless_core_exit(wldev);
  3456. mutex_unlock(&wl->mutex);
  3457. b43dbg(wl, "Device suspended.\n");
  3458. return 0;
  3459. }
  3460. static int b43_resume(struct ssb_device *dev)
  3461. {
  3462. struct b43_wldev *wldev = ssb_get_drvdata(dev);
  3463. struct b43_wl *wl = wldev->wl;
  3464. int err = 0;
  3465. b43dbg(wl, "Resuming...\n");
  3466. mutex_lock(&wl->mutex);
  3467. if (wldev->suspend_init_status >= B43_STAT_INITIALIZED) {
  3468. err = b43_wireless_core_init(wldev);
  3469. if (err) {
  3470. b43err(wl, "Resume failed at core init\n");
  3471. goto out;
  3472. }
  3473. }
  3474. if (wldev->suspend_init_status >= B43_STAT_STARTED) {
  3475. err = b43_wireless_core_start(wldev);
  3476. if (err) {
  3477. b43_wireless_core_exit(wldev);
  3478. b43err(wl, "Resume failed at core start\n");
  3479. goto out;
  3480. }
  3481. }
  3482. mutex_unlock(&wl->mutex);
  3483. b43dbg(wl, "Device resumed.\n");
  3484. out:
  3485. return err;
  3486. }
  3487. #else /* CONFIG_PM */
  3488. # define b43_suspend NULL
  3489. # define b43_resume NULL
  3490. #endif /* CONFIG_PM */
  3491. static struct ssb_driver b43_ssb_driver = {
  3492. .name = KBUILD_MODNAME,
  3493. .id_table = b43_ssb_tbl,
  3494. .probe = b43_probe,
  3495. .remove = b43_remove,
  3496. .suspend = b43_suspend,
  3497. .resume = b43_resume,
  3498. };
  3499. static int __init b43_init(void)
  3500. {
  3501. int err;
  3502. b43_debugfs_init();
  3503. err = b43_pcmcia_init();
  3504. if (err)
  3505. goto err_dfs_exit;
  3506. err = ssb_driver_register(&b43_ssb_driver);
  3507. if (err)
  3508. goto err_pcmcia_exit;
  3509. return err;
  3510. err_pcmcia_exit:
  3511. b43_pcmcia_exit();
  3512. err_dfs_exit:
  3513. b43_debugfs_exit();
  3514. return err;
  3515. }
  3516. static void __exit b43_exit(void)
  3517. {
  3518. ssb_driver_unregister(&b43_ssb_driver);
  3519. b43_pcmcia_exit();
  3520. b43_debugfs_exit();
  3521. }
  3522. module_init(b43_init)
  3523. module_exit(b43_exit)