main.c 129 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989
  1. /*
  2. Broadcom B43 wireless driver
  3. Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
  4. Copyright (c) 2005 Stefano Brivio <stefano.brivio@polimi.it>
  5. Copyright (c) 2005-2009 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/firmware.h>
  29. #include <linux/wireless.h>
  30. #include <linux/workqueue.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/io.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_common.h"
  39. #include "phy_g.h"
  40. #include "phy_n.h"
  41. #include "dma.h"
  42. #include "pio.h"
  43. #include "sysfs.h"
  44. #include "xmit.h"
  45. #include "lo.h"
  46. #include "pcmcia.h"
  47. MODULE_DESCRIPTION("Broadcom B43 wireless driver");
  48. MODULE_AUTHOR("Martin Langer");
  49. MODULE_AUTHOR("Stefano Brivio");
  50. MODULE_AUTHOR("Michael Buesch");
  51. MODULE_LICENSE("GPL");
  52. MODULE_FIRMWARE(B43_SUPPORTED_FIRMWARE_ID);
  53. static int modparam_bad_frames_preempt;
  54. module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
  55. MODULE_PARM_DESC(bad_frames_preempt,
  56. "enable(1) / disable(0) Bad Frames Preemption");
  57. static char modparam_fwpostfix[16];
  58. module_param_string(fwpostfix, modparam_fwpostfix, 16, 0444);
  59. MODULE_PARM_DESC(fwpostfix, "Postfix for the .fw files to load.");
  60. static int modparam_hwpctl;
  61. module_param_named(hwpctl, modparam_hwpctl, int, 0444);
  62. MODULE_PARM_DESC(hwpctl, "Enable hardware-side power control (default off)");
  63. static int modparam_nohwcrypt;
  64. module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
  65. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  66. int b43_modparam_qos = 1;
  67. module_param_named(qos, b43_modparam_qos, int, 0444);
  68. MODULE_PARM_DESC(qos, "Enable QOS support (default on)");
  69. static int modparam_btcoex = 1;
  70. module_param_named(btcoex, modparam_btcoex, int, 0444);
  71. MODULE_PARM_DESC(btcoex, "Enable Bluetooth coexistance (default on)");
  72. int b43_modparam_verbose = B43_VERBOSITY_DEFAULT;
  73. module_param_named(verbose, b43_modparam_verbose, int, 0644);
  74. MODULE_PARM_DESC(verbose, "Log message verbosity: 0=error, 1=warn, 2=info(default), 3=debug");
  75. static const struct ssb_device_id b43_ssb_tbl[] = {
  76. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 5),
  77. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 6),
  78. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 7),
  79. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 9),
  80. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 10),
  81. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 11),
  82. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 13),
  83. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 15),
  84. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 16),
  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. .bitrate = B43_RATE_TO_BASE100KBPS(_rateid), \
  95. .hw_value = (_rateid), \
  96. .flags = (_flags), \
  97. }
  98. /*
  99. * NOTE: When changing this, sync with xmit.c's
  100. * b43_plcp_get_bitrate_idx_* functions!
  101. */
  102. static struct ieee80211_rate __b43_ratetable[] = {
  103. RATETAB_ENT(B43_CCK_RATE_1MB, 0),
  104. RATETAB_ENT(B43_CCK_RATE_2MB, IEEE80211_RATE_SHORT_PREAMBLE),
  105. RATETAB_ENT(B43_CCK_RATE_5MB, IEEE80211_RATE_SHORT_PREAMBLE),
  106. RATETAB_ENT(B43_CCK_RATE_11MB, IEEE80211_RATE_SHORT_PREAMBLE),
  107. RATETAB_ENT(B43_OFDM_RATE_6MB, 0),
  108. RATETAB_ENT(B43_OFDM_RATE_9MB, 0),
  109. RATETAB_ENT(B43_OFDM_RATE_12MB, 0),
  110. RATETAB_ENT(B43_OFDM_RATE_18MB, 0),
  111. RATETAB_ENT(B43_OFDM_RATE_24MB, 0),
  112. RATETAB_ENT(B43_OFDM_RATE_36MB, 0),
  113. RATETAB_ENT(B43_OFDM_RATE_48MB, 0),
  114. RATETAB_ENT(B43_OFDM_RATE_54MB, 0),
  115. };
  116. #define b43_a_ratetable (__b43_ratetable + 4)
  117. #define b43_a_ratetable_size 8
  118. #define b43_b_ratetable (__b43_ratetable + 0)
  119. #define b43_b_ratetable_size 4
  120. #define b43_g_ratetable (__b43_ratetable + 0)
  121. #define b43_g_ratetable_size 12
  122. #define CHAN4G(_channel, _freq, _flags) { \
  123. .band = IEEE80211_BAND_2GHZ, \
  124. .center_freq = (_freq), \
  125. .hw_value = (_channel), \
  126. .flags = (_flags), \
  127. .max_antenna_gain = 0, \
  128. .max_power = 30, \
  129. }
  130. static struct ieee80211_channel b43_2ghz_chantable[] = {
  131. CHAN4G(1, 2412, 0),
  132. CHAN4G(2, 2417, 0),
  133. CHAN4G(3, 2422, 0),
  134. CHAN4G(4, 2427, 0),
  135. CHAN4G(5, 2432, 0),
  136. CHAN4G(6, 2437, 0),
  137. CHAN4G(7, 2442, 0),
  138. CHAN4G(8, 2447, 0),
  139. CHAN4G(9, 2452, 0),
  140. CHAN4G(10, 2457, 0),
  141. CHAN4G(11, 2462, 0),
  142. CHAN4G(12, 2467, 0),
  143. CHAN4G(13, 2472, 0),
  144. CHAN4G(14, 2484, 0),
  145. };
  146. #undef CHAN4G
  147. #define CHAN5G(_channel, _flags) { \
  148. .band = IEEE80211_BAND_5GHZ, \
  149. .center_freq = 5000 + (5 * (_channel)), \
  150. .hw_value = (_channel), \
  151. .flags = (_flags), \
  152. .max_antenna_gain = 0, \
  153. .max_power = 30, \
  154. }
  155. static struct ieee80211_channel b43_5ghz_nphy_chantable[] = {
  156. CHAN5G(32, 0), CHAN5G(34, 0),
  157. CHAN5G(36, 0), CHAN5G(38, 0),
  158. CHAN5G(40, 0), CHAN5G(42, 0),
  159. CHAN5G(44, 0), CHAN5G(46, 0),
  160. CHAN5G(48, 0), CHAN5G(50, 0),
  161. CHAN5G(52, 0), CHAN5G(54, 0),
  162. CHAN5G(56, 0), CHAN5G(58, 0),
  163. CHAN5G(60, 0), CHAN5G(62, 0),
  164. CHAN5G(64, 0), CHAN5G(66, 0),
  165. CHAN5G(68, 0), CHAN5G(70, 0),
  166. CHAN5G(72, 0), CHAN5G(74, 0),
  167. CHAN5G(76, 0), CHAN5G(78, 0),
  168. CHAN5G(80, 0), CHAN5G(82, 0),
  169. CHAN5G(84, 0), CHAN5G(86, 0),
  170. CHAN5G(88, 0), CHAN5G(90, 0),
  171. CHAN5G(92, 0), CHAN5G(94, 0),
  172. CHAN5G(96, 0), CHAN5G(98, 0),
  173. CHAN5G(100, 0), CHAN5G(102, 0),
  174. CHAN5G(104, 0), CHAN5G(106, 0),
  175. CHAN5G(108, 0), CHAN5G(110, 0),
  176. CHAN5G(112, 0), CHAN5G(114, 0),
  177. CHAN5G(116, 0), CHAN5G(118, 0),
  178. CHAN5G(120, 0), CHAN5G(122, 0),
  179. CHAN5G(124, 0), CHAN5G(126, 0),
  180. CHAN5G(128, 0), CHAN5G(130, 0),
  181. CHAN5G(132, 0), CHAN5G(134, 0),
  182. CHAN5G(136, 0), CHAN5G(138, 0),
  183. CHAN5G(140, 0), CHAN5G(142, 0),
  184. CHAN5G(144, 0), CHAN5G(145, 0),
  185. CHAN5G(146, 0), CHAN5G(147, 0),
  186. CHAN5G(148, 0), CHAN5G(149, 0),
  187. CHAN5G(150, 0), CHAN5G(151, 0),
  188. CHAN5G(152, 0), CHAN5G(153, 0),
  189. CHAN5G(154, 0), CHAN5G(155, 0),
  190. CHAN5G(156, 0), CHAN5G(157, 0),
  191. CHAN5G(158, 0), CHAN5G(159, 0),
  192. CHAN5G(160, 0), CHAN5G(161, 0),
  193. CHAN5G(162, 0), CHAN5G(163, 0),
  194. CHAN5G(164, 0), CHAN5G(165, 0),
  195. CHAN5G(166, 0), CHAN5G(168, 0),
  196. CHAN5G(170, 0), CHAN5G(172, 0),
  197. CHAN5G(174, 0), CHAN5G(176, 0),
  198. CHAN5G(178, 0), CHAN5G(180, 0),
  199. CHAN5G(182, 0), CHAN5G(184, 0),
  200. CHAN5G(186, 0), CHAN5G(188, 0),
  201. CHAN5G(190, 0), CHAN5G(192, 0),
  202. CHAN5G(194, 0), CHAN5G(196, 0),
  203. CHAN5G(198, 0), CHAN5G(200, 0),
  204. CHAN5G(202, 0), CHAN5G(204, 0),
  205. CHAN5G(206, 0), CHAN5G(208, 0),
  206. CHAN5G(210, 0), CHAN5G(212, 0),
  207. CHAN5G(214, 0), CHAN5G(216, 0),
  208. CHAN5G(218, 0), CHAN5G(220, 0),
  209. CHAN5G(222, 0), CHAN5G(224, 0),
  210. CHAN5G(226, 0), CHAN5G(228, 0),
  211. };
  212. static struct ieee80211_channel b43_5ghz_aphy_chantable[] = {
  213. CHAN5G(34, 0), CHAN5G(36, 0),
  214. CHAN5G(38, 0), CHAN5G(40, 0),
  215. CHAN5G(42, 0), CHAN5G(44, 0),
  216. CHAN5G(46, 0), CHAN5G(48, 0),
  217. CHAN5G(52, 0), CHAN5G(56, 0),
  218. CHAN5G(60, 0), CHAN5G(64, 0),
  219. CHAN5G(100, 0), CHAN5G(104, 0),
  220. CHAN5G(108, 0), CHAN5G(112, 0),
  221. CHAN5G(116, 0), CHAN5G(120, 0),
  222. CHAN5G(124, 0), CHAN5G(128, 0),
  223. CHAN5G(132, 0), CHAN5G(136, 0),
  224. CHAN5G(140, 0), CHAN5G(149, 0),
  225. CHAN5G(153, 0), CHAN5G(157, 0),
  226. CHAN5G(161, 0), CHAN5G(165, 0),
  227. CHAN5G(184, 0), CHAN5G(188, 0),
  228. CHAN5G(192, 0), CHAN5G(196, 0),
  229. CHAN5G(200, 0), CHAN5G(204, 0),
  230. CHAN5G(208, 0), CHAN5G(212, 0),
  231. CHAN5G(216, 0),
  232. };
  233. #undef CHAN5G
  234. static struct ieee80211_supported_band b43_band_5GHz_nphy = {
  235. .band = IEEE80211_BAND_5GHZ,
  236. .channels = b43_5ghz_nphy_chantable,
  237. .n_channels = ARRAY_SIZE(b43_5ghz_nphy_chantable),
  238. .bitrates = b43_a_ratetable,
  239. .n_bitrates = b43_a_ratetable_size,
  240. };
  241. static struct ieee80211_supported_band b43_band_5GHz_aphy = {
  242. .band = IEEE80211_BAND_5GHZ,
  243. .channels = b43_5ghz_aphy_chantable,
  244. .n_channels = ARRAY_SIZE(b43_5ghz_aphy_chantable),
  245. .bitrates = b43_a_ratetable,
  246. .n_bitrates = b43_a_ratetable_size,
  247. };
  248. static struct ieee80211_supported_band b43_band_2GHz = {
  249. .band = IEEE80211_BAND_2GHZ,
  250. .channels = b43_2ghz_chantable,
  251. .n_channels = ARRAY_SIZE(b43_2ghz_chantable),
  252. .bitrates = b43_g_ratetable,
  253. .n_bitrates = b43_g_ratetable_size,
  254. };
  255. static void b43_wireless_core_exit(struct b43_wldev *dev);
  256. static int b43_wireless_core_init(struct b43_wldev *dev);
  257. static void b43_wireless_core_stop(struct b43_wldev *dev);
  258. static int b43_wireless_core_start(struct b43_wldev *dev);
  259. static int b43_ratelimit(struct b43_wl *wl)
  260. {
  261. if (!wl || !wl->current_dev)
  262. return 1;
  263. if (b43_status(wl->current_dev) < B43_STAT_STARTED)
  264. return 1;
  265. /* We are up and running.
  266. * Ratelimit the messages to avoid DoS over the net. */
  267. return net_ratelimit();
  268. }
  269. void b43info(struct b43_wl *wl, const char *fmt, ...)
  270. {
  271. va_list args;
  272. if (b43_modparam_verbose < B43_VERBOSITY_INFO)
  273. return;
  274. if (!b43_ratelimit(wl))
  275. return;
  276. va_start(args, fmt);
  277. printk(KERN_INFO "b43-%s: ",
  278. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  279. vprintk(fmt, args);
  280. va_end(args);
  281. }
  282. void b43err(struct b43_wl *wl, const char *fmt, ...)
  283. {
  284. va_list args;
  285. if (b43_modparam_verbose < B43_VERBOSITY_ERROR)
  286. return;
  287. if (!b43_ratelimit(wl))
  288. return;
  289. va_start(args, fmt);
  290. printk(KERN_ERR "b43-%s ERROR: ",
  291. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  292. vprintk(fmt, args);
  293. va_end(args);
  294. }
  295. void b43warn(struct b43_wl *wl, const char *fmt, ...)
  296. {
  297. va_list args;
  298. if (b43_modparam_verbose < B43_VERBOSITY_WARN)
  299. return;
  300. if (!b43_ratelimit(wl))
  301. return;
  302. va_start(args, fmt);
  303. printk(KERN_WARNING "b43-%s warning: ",
  304. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  305. vprintk(fmt, args);
  306. va_end(args);
  307. }
  308. void b43dbg(struct b43_wl *wl, const char *fmt, ...)
  309. {
  310. va_list args;
  311. if (b43_modparam_verbose < B43_VERBOSITY_DEBUG)
  312. return;
  313. va_start(args, fmt);
  314. printk(KERN_DEBUG "b43-%s debug: ",
  315. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  316. vprintk(fmt, args);
  317. va_end(args);
  318. }
  319. static void b43_ram_write(struct b43_wldev *dev, u16 offset, u32 val)
  320. {
  321. u32 macctl;
  322. B43_WARN_ON(offset % 4 != 0);
  323. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  324. if (macctl & B43_MACCTL_BE)
  325. val = swab32(val);
  326. b43_write32(dev, B43_MMIO_RAM_CONTROL, offset);
  327. mmiowb();
  328. b43_write32(dev, B43_MMIO_RAM_DATA, val);
  329. }
  330. static inline void b43_shm_control_word(struct b43_wldev *dev,
  331. u16 routing, u16 offset)
  332. {
  333. u32 control;
  334. /* "offset" is the WORD offset. */
  335. control = routing;
  336. control <<= 16;
  337. control |= offset;
  338. b43_write32(dev, B43_MMIO_SHM_CONTROL, control);
  339. }
  340. u32 __b43_shm_read32(struct b43_wldev *dev, u16 routing, u16 offset)
  341. {
  342. u32 ret;
  343. if (routing == B43_SHM_SHARED) {
  344. B43_WARN_ON(offset & 0x0001);
  345. if (offset & 0x0003) {
  346. /* Unaligned access */
  347. b43_shm_control_word(dev, routing, offset >> 2);
  348. ret = b43_read16(dev, B43_MMIO_SHM_DATA_UNALIGNED);
  349. ret <<= 16;
  350. b43_shm_control_word(dev, routing, (offset >> 2) + 1);
  351. ret |= b43_read16(dev, B43_MMIO_SHM_DATA);
  352. goto out;
  353. }
  354. offset >>= 2;
  355. }
  356. b43_shm_control_word(dev, routing, offset);
  357. ret = b43_read32(dev, B43_MMIO_SHM_DATA);
  358. out:
  359. return ret;
  360. }
  361. u32 b43_shm_read32(struct b43_wldev *dev, u16 routing, u16 offset)
  362. {
  363. struct b43_wl *wl = dev->wl;
  364. unsigned long flags;
  365. u32 ret;
  366. spin_lock_irqsave(&wl->shm_lock, flags);
  367. ret = __b43_shm_read32(dev, routing, offset);
  368. spin_unlock_irqrestore(&wl->shm_lock, flags);
  369. return ret;
  370. }
  371. u16 __b43_shm_read16(struct b43_wldev *dev, u16 routing, u16 offset)
  372. {
  373. u16 ret;
  374. if (routing == B43_SHM_SHARED) {
  375. B43_WARN_ON(offset & 0x0001);
  376. if (offset & 0x0003) {
  377. /* Unaligned access */
  378. b43_shm_control_word(dev, routing, offset >> 2);
  379. ret = b43_read16(dev, B43_MMIO_SHM_DATA_UNALIGNED);
  380. goto out;
  381. }
  382. offset >>= 2;
  383. }
  384. b43_shm_control_word(dev, routing, offset);
  385. ret = b43_read16(dev, B43_MMIO_SHM_DATA);
  386. out:
  387. return ret;
  388. }
  389. u16 b43_shm_read16(struct b43_wldev *dev, u16 routing, u16 offset)
  390. {
  391. struct b43_wl *wl = dev->wl;
  392. unsigned long flags;
  393. u16 ret;
  394. spin_lock_irqsave(&wl->shm_lock, flags);
  395. ret = __b43_shm_read16(dev, routing, offset);
  396. spin_unlock_irqrestore(&wl->shm_lock, flags);
  397. return ret;
  398. }
  399. void __b43_shm_write32(struct b43_wldev *dev, u16 routing, u16 offset, u32 value)
  400. {
  401. if (routing == B43_SHM_SHARED) {
  402. B43_WARN_ON(offset & 0x0001);
  403. if (offset & 0x0003) {
  404. /* Unaligned access */
  405. b43_shm_control_word(dev, routing, offset >> 2);
  406. b43_write16(dev, B43_MMIO_SHM_DATA_UNALIGNED,
  407. (value >> 16) & 0xffff);
  408. b43_shm_control_word(dev, routing, (offset >> 2) + 1);
  409. b43_write16(dev, B43_MMIO_SHM_DATA, value & 0xffff);
  410. return;
  411. }
  412. offset >>= 2;
  413. }
  414. b43_shm_control_word(dev, routing, offset);
  415. b43_write32(dev, B43_MMIO_SHM_DATA, value);
  416. }
  417. void b43_shm_write32(struct b43_wldev *dev, u16 routing, u16 offset, u32 value)
  418. {
  419. struct b43_wl *wl = dev->wl;
  420. unsigned long flags;
  421. spin_lock_irqsave(&wl->shm_lock, flags);
  422. __b43_shm_write32(dev, routing, offset, value);
  423. spin_unlock_irqrestore(&wl->shm_lock, flags);
  424. }
  425. void __b43_shm_write16(struct b43_wldev *dev, u16 routing, u16 offset, u16 value)
  426. {
  427. if (routing == B43_SHM_SHARED) {
  428. B43_WARN_ON(offset & 0x0001);
  429. if (offset & 0x0003) {
  430. /* Unaligned access */
  431. b43_shm_control_word(dev, routing, offset >> 2);
  432. b43_write16(dev, B43_MMIO_SHM_DATA_UNALIGNED, value);
  433. return;
  434. }
  435. offset >>= 2;
  436. }
  437. b43_shm_control_word(dev, routing, offset);
  438. b43_write16(dev, B43_MMIO_SHM_DATA, value);
  439. }
  440. void b43_shm_write16(struct b43_wldev *dev, u16 routing, u16 offset, u16 value)
  441. {
  442. struct b43_wl *wl = dev->wl;
  443. unsigned long flags;
  444. spin_lock_irqsave(&wl->shm_lock, flags);
  445. __b43_shm_write16(dev, routing, offset, value);
  446. spin_unlock_irqrestore(&wl->shm_lock, flags);
  447. }
  448. /* Read HostFlags */
  449. u64 b43_hf_read(struct b43_wldev *dev)
  450. {
  451. u64 ret;
  452. ret = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFHI);
  453. ret <<= 16;
  454. ret |= b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFMI);
  455. ret <<= 16;
  456. ret |= b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFLO);
  457. return ret;
  458. }
  459. /* Write HostFlags */
  460. void b43_hf_write(struct b43_wldev *dev, u64 value)
  461. {
  462. u16 lo, mi, hi;
  463. lo = (value & 0x00000000FFFFULL);
  464. mi = (value & 0x0000FFFF0000ULL) >> 16;
  465. hi = (value & 0xFFFF00000000ULL) >> 32;
  466. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFLO, lo);
  467. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFMI, mi);
  468. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFHI, hi);
  469. }
  470. void b43_tsf_read(struct b43_wldev *dev, u64 *tsf)
  471. {
  472. u32 low, high;
  473. B43_WARN_ON(dev->dev->id.revision < 3);
  474. /* The hardware guarantees us an atomic read, if we
  475. * read the low register first. */
  476. low = b43_read32(dev, B43_MMIO_REV3PLUS_TSF_LOW);
  477. high = b43_read32(dev, B43_MMIO_REV3PLUS_TSF_HIGH);
  478. *tsf = high;
  479. *tsf <<= 32;
  480. *tsf |= low;
  481. }
  482. static void b43_time_lock(struct b43_wldev *dev)
  483. {
  484. u32 macctl;
  485. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  486. macctl |= B43_MACCTL_TBTTHOLD;
  487. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  488. /* Commit the write */
  489. b43_read32(dev, B43_MMIO_MACCTL);
  490. }
  491. static void b43_time_unlock(struct b43_wldev *dev)
  492. {
  493. u32 macctl;
  494. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  495. macctl &= ~B43_MACCTL_TBTTHOLD;
  496. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  497. /* Commit the write */
  498. b43_read32(dev, B43_MMIO_MACCTL);
  499. }
  500. static void b43_tsf_write_locked(struct b43_wldev *dev, u64 tsf)
  501. {
  502. u32 low, high;
  503. B43_WARN_ON(dev->dev->id.revision < 3);
  504. low = tsf;
  505. high = (tsf >> 32);
  506. /* The hardware guarantees us an atomic write, if we
  507. * write the low register first. */
  508. b43_write32(dev, B43_MMIO_REV3PLUS_TSF_LOW, low);
  509. mmiowb();
  510. b43_write32(dev, B43_MMIO_REV3PLUS_TSF_HIGH, high);
  511. mmiowb();
  512. }
  513. void b43_tsf_write(struct b43_wldev *dev, u64 tsf)
  514. {
  515. b43_time_lock(dev);
  516. b43_tsf_write_locked(dev, tsf);
  517. b43_time_unlock(dev);
  518. }
  519. static
  520. void b43_macfilter_set(struct b43_wldev *dev, u16 offset, const u8 *mac)
  521. {
  522. static const u8 zero_addr[ETH_ALEN] = { 0 };
  523. u16 data;
  524. if (!mac)
  525. mac = zero_addr;
  526. offset |= 0x0020;
  527. b43_write16(dev, B43_MMIO_MACFILTER_CONTROL, offset);
  528. data = mac[0];
  529. data |= mac[1] << 8;
  530. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  531. data = mac[2];
  532. data |= mac[3] << 8;
  533. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  534. data = mac[4];
  535. data |= mac[5] << 8;
  536. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  537. }
  538. static void b43_write_mac_bssid_templates(struct b43_wldev *dev)
  539. {
  540. const u8 *mac;
  541. const u8 *bssid;
  542. u8 mac_bssid[ETH_ALEN * 2];
  543. int i;
  544. u32 tmp;
  545. bssid = dev->wl->bssid;
  546. mac = dev->wl->mac_addr;
  547. b43_macfilter_set(dev, B43_MACFILTER_BSSID, bssid);
  548. memcpy(mac_bssid, mac, ETH_ALEN);
  549. memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
  550. /* Write our MAC address and BSSID to template ram */
  551. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32)) {
  552. tmp = (u32) (mac_bssid[i + 0]);
  553. tmp |= (u32) (mac_bssid[i + 1]) << 8;
  554. tmp |= (u32) (mac_bssid[i + 2]) << 16;
  555. tmp |= (u32) (mac_bssid[i + 3]) << 24;
  556. b43_ram_write(dev, 0x20 + i, tmp);
  557. }
  558. }
  559. static void b43_upload_card_macaddress(struct b43_wldev *dev)
  560. {
  561. b43_write_mac_bssid_templates(dev);
  562. b43_macfilter_set(dev, B43_MACFILTER_SELF, dev->wl->mac_addr);
  563. }
  564. static void b43_set_slot_time(struct b43_wldev *dev, u16 slot_time)
  565. {
  566. /* slot_time is in usec. */
  567. if (dev->phy.type != B43_PHYTYPE_G)
  568. return;
  569. b43_write16(dev, 0x684, 510 + slot_time);
  570. b43_shm_write16(dev, B43_SHM_SHARED, 0x0010, slot_time);
  571. }
  572. static void b43_short_slot_timing_enable(struct b43_wldev *dev)
  573. {
  574. b43_set_slot_time(dev, 9);
  575. }
  576. static void b43_short_slot_timing_disable(struct b43_wldev *dev)
  577. {
  578. b43_set_slot_time(dev, 20);
  579. }
  580. /* Synchronize IRQ top- and bottom-half.
  581. * IRQs must be masked before calling this.
  582. * This must not be called with the irq_lock held.
  583. */
  584. static void b43_synchronize_irq(struct b43_wldev *dev)
  585. {
  586. synchronize_irq(dev->dev->irq);
  587. tasklet_kill(&dev->isr_tasklet);
  588. }
  589. /* DummyTransmission function, as documented on
  590. * http://bcm-specs.sipsolutions.net/DummyTransmission
  591. */
  592. void b43_dummy_transmission(struct b43_wldev *dev)
  593. {
  594. struct b43_wl *wl = dev->wl;
  595. struct b43_phy *phy = &dev->phy;
  596. unsigned int i, max_loop;
  597. u16 value;
  598. u32 buffer[5] = {
  599. 0x00000000,
  600. 0x00D40000,
  601. 0x00000000,
  602. 0x01000000,
  603. 0x00000000,
  604. };
  605. switch (phy->type) {
  606. case B43_PHYTYPE_A:
  607. max_loop = 0x1E;
  608. buffer[0] = 0x000201CC;
  609. break;
  610. case B43_PHYTYPE_B:
  611. case B43_PHYTYPE_G:
  612. max_loop = 0xFA;
  613. buffer[0] = 0x000B846E;
  614. break;
  615. default:
  616. B43_WARN_ON(1);
  617. return;
  618. }
  619. spin_lock_irq(&wl->irq_lock);
  620. write_lock(&wl->tx_lock);
  621. for (i = 0; i < 5; i++)
  622. b43_ram_write(dev, i * 4, buffer[i]);
  623. /* Commit writes */
  624. b43_read32(dev, B43_MMIO_MACCTL);
  625. b43_write16(dev, 0x0568, 0x0000);
  626. b43_write16(dev, 0x07C0, 0x0000);
  627. value = ((phy->type == B43_PHYTYPE_A) ? 1 : 0);
  628. b43_write16(dev, 0x050C, value);
  629. b43_write16(dev, 0x0508, 0x0000);
  630. b43_write16(dev, 0x050A, 0x0000);
  631. b43_write16(dev, 0x054C, 0x0000);
  632. b43_write16(dev, 0x056A, 0x0014);
  633. b43_write16(dev, 0x0568, 0x0826);
  634. b43_write16(dev, 0x0500, 0x0000);
  635. b43_write16(dev, 0x0502, 0x0030);
  636. if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
  637. b43_radio_write16(dev, 0x0051, 0x0017);
  638. for (i = 0x00; i < max_loop; i++) {
  639. value = b43_read16(dev, 0x050E);
  640. if (value & 0x0080)
  641. break;
  642. udelay(10);
  643. }
  644. for (i = 0x00; i < 0x0A; i++) {
  645. value = b43_read16(dev, 0x050E);
  646. if (value & 0x0400)
  647. break;
  648. udelay(10);
  649. }
  650. for (i = 0x00; i < 0x19; i++) {
  651. value = b43_read16(dev, 0x0690);
  652. if (!(value & 0x0100))
  653. break;
  654. udelay(10);
  655. }
  656. if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
  657. b43_radio_write16(dev, 0x0051, 0x0037);
  658. write_unlock(&wl->tx_lock);
  659. spin_unlock_irq(&wl->irq_lock);
  660. }
  661. static void key_write(struct b43_wldev *dev,
  662. u8 index, u8 algorithm, const u8 *key)
  663. {
  664. unsigned int i;
  665. u32 offset;
  666. u16 value;
  667. u16 kidx;
  668. /* Key index/algo block */
  669. kidx = b43_kidx_to_fw(dev, index);
  670. value = ((kidx << 4) | algorithm);
  671. b43_shm_write16(dev, B43_SHM_SHARED,
  672. B43_SHM_SH_KEYIDXBLOCK + (kidx * 2), value);
  673. /* Write the key to the Key Table Pointer offset */
  674. offset = dev->ktp + (index * B43_SEC_KEYSIZE);
  675. for (i = 0; i < B43_SEC_KEYSIZE; i += 2) {
  676. value = key[i];
  677. value |= (u16) (key[i + 1]) << 8;
  678. b43_shm_write16(dev, B43_SHM_SHARED, offset + i, value);
  679. }
  680. }
  681. static void keymac_write(struct b43_wldev *dev, u8 index, const u8 *addr)
  682. {
  683. u32 addrtmp[2] = { 0, 0, };
  684. u8 per_sta_keys_start = 8;
  685. if (b43_new_kidx_api(dev))
  686. per_sta_keys_start = 4;
  687. B43_WARN_ON(index < per_sta_keys_start);
  688. /* We have two default TX keys and possibly two default RX keys.
  689. * Physical mac 0 is mapped to physical key 4 or 8, depending
  690. * on the firmware version.
  691. * So we must adjust the index here.
  692. */
  693. index -= per_sta_keys_start;
  694. if (addr) {
  695. addrtmp[0] = addr[0];
  696. addrtmp[0] |= ((u32) (addr[1]) << 8);
  697. addrtmp[0] |= ((u32) (addr[2]) << 16);
  698. addrtmp[0] |= ((u32) (addr[3]) << 24);
  699. addrtmp[1] = addr[4];
  700. addrtmp[1] |= ((u32) (addr[5]) << 8);
  701. }
  702. if (dev->dev->id.revision >= 5) {
  703. /* Receive match transmitter address mechanism */
  704. b43_shm_write32(dev, B43_SHM_RCMTA,
  705. (index * 2) + 0, addrtmp[0]);
  706. b43_shm_write16(dev, B43_SHM_RCMTA,
  707. (index * 2) + 1, addrtmp[1]);
  708. } else {
  709. /* RXE (Receive Engine) and
  710. * PSM (Programmable State Machine) mechanism
  711. */
  712. if (index < 8) {
  713. /* TODO write to RCM 16, 19, 22 and 25 */
  714. } else {
  715. b43_shm_write32(dev, B43_SHM_SHARED,
  716. B43_SHM_SH_PSM + (index * 6) + 0,
  717. addrtmp[0]);
  718. b43_shm_write16(dev, B43_SHM_SHARED,
  719. B43_SHM_SH_PSM + (index * 6) + 4,
  720. addrtmp[1]);
  721. }
  722. }
  723. }
  724. static void do_key_write(struct b43_wldev *dev,
  725. u8 index, u8 algorithm,
  726. const u8 *key, size_t key_len, const u8 *mac_addr)
  727. {
  728. u8 buf[B43_SEC_KEYSIZE] = { 0, };
  729. u8 per_sta_keys_start = 8;
  730. if (b43_new_kidx_api(dev))
  731. per_sta_keys_start = 4;
  732. B43_WARN_ON(index >= dev->max_nr_keys);
  733. B43_WARN_ON(key_len > B43_SEC_KEYSIZE);
  734. if (index >= per_sta_keys_start)
  735. keymac_write(dev, index, NULL); /* First zero out mac. */
  736. if (key)
  737. memcpy(buf, key, key_len);
  738. key_write(dev, index, algorithm, buf);
  739. if (index >= per_sta_keys_start)
  740. keymac_write(dev, index, mac_addr);
  741. dev->key[index].algorithm = algorithm;
  742. }
  743. static int b43_key_write(struct b43_wldev *dev,
  744. int index, u8 algorithm,
  745. const u8 *key, size_t key_len,
  746. const u8 *mac_addr,
  747. struct ieee80211_key_conf *keyconf)
  748. {
  749. int i;
  750. int sta_keys_start;
  751. if (key_len > B43_SEC_KEYSIZE)
  752. return -EINVAL;
  753. for (i = 0; i < dev->max_nr_keys; i++) {
  754. /* Check that we don't already have this key. */
  755. B43_WARN_ON(dev->key[i].keyconf == keyconf);
  756. }
  757. if (index < 0) {
  758. /* Pairwise key. Get an empty slot for the key. */
  759. if (b43_new_kidx_api(dev))
  760. sta_keys_start = 4;
  761. else
  762. sta_keys_start = 8;
  763. for (i = sta_keys_start; i < dev->max_nr_keys; i++) {
  764. if (!dev->key[i].keyconf) {
  765. /* found empty */
  766. index = i;
  767. break;
  768. }
  769. }
  770. if (index < 0) {
  771. b43warn(dev->wl, "Out of hardware key memory\n");
  772. return -ENOSPC;
  773. }
  774. } else
  775. B43_WARN_ON(index > 3);
  776. do_key_write(dev, index, algorithm, key, key_len, mac_addr);
  777. if ((index <= 3) && !b43_new_kidx_api(dev)) {
  778. /* Default RX key */
  779. B43_WARN_ON(mac_addr);
  780. do_key_write(dev, index + 4, algorithm, key, key_len, NULL);
  781. }
  782. keyconf->hw_key_idx = index;
  783. dev->key[index].keyconf = keyconf;
  784. return 0;
  785. }
  786. static int b43_key_clear(struct b43_wldev *dev, int index)
  787. {
  788. if (B43_WARN_ON((index < 0) || (index >= dev->max_nr_keys)))
  789. return -EINVAL;
  790. do_key_write(dev, index, B43_SEC_ALGO_NONE,
  791. NULL, B43_SEC_KEYSIZE, NULL);
  792. if ((index <= 3) && !b43_new_kidx_api(dev)) {
  793. do_key_write(dev, index + 4, B43_SEC_ALGO_NONE,
  794. NULL, B43_SEC_KEYSIZE, NULL);
  795. }
  796. dev->key[index].keyconf = NULL;
  797. return 0;
  798. }
  799. static void b43_clear_keys(struct b43_wldev *dev)
  800. {
  801. int i;
  802. for (i = 0; i < dev->max_nr_keys; i++)
  803. b43_key_clear(dev, i);
  804. }
  805. static void b43_dump_keymemory(struct b43_wldev *dev)
  806. {
  807. unsigned int i, index, offset;
  808. DECLARE_MAC_BUF(macbuf);
  809. u8 mac[ETH_ALEN];
  810. u16 algo;
  811. u32 rcmta0;
  812. u16 rcmta1;
  813. u64 hf;
  814. struct b43_key *key;
  815. if (!b43_debug(dev, B43_DBG_KEYS))
  816. return;
  817. hf = b43_hf_read(dev);
  818. b43dbg(dev->wl, "Hardware key memory dump: USEDEFKEYS=%u\n",
  819. !!(hf & B43_HF_USEDEFKEYS));
  820. for (index = 0; index < dev->max_nr_keys; index++) {
  821. key = &(dev->key[index]);
  822. printk(KERN_DEBUG "Key slot %02u: %s",
  823. index, (key->keyconf == NULL) ? " " : "*");
  824. offset = dev->ktp + (index * B43_SEC_KEYSIZE);
  825. for (i = 0; i < B43_SEC_KEYSIZE; i += 2) {
  826. u16 tmp = b43_shm_read16(dev, B43_SHM_SHARED, offset + i);
  827. printk("%02X%02X", (tmp & 0xFF), ((tmp >> 8) & 0xFF));
  828. }
  829. algo = b43_shm_read16(dev, B43_SHM_SHARED,
  830. B43_SHM_SH_KEYIDXBLOCK + (index * 2));
  831. printk(" Algo: %04X/%02X", algo, key->algorithm);
  832. if (index >= 4) {
  833. rcmta0 = b43_shm_read32(dev, B43_SHM_RCMTA,
  834. ((index - 4) * 2) + 0);
  835. rcmta1 = b43_shm_read16(dev, B43_SHM_RCMTA,
  836. ((index - 4) * 2) + 1);
  837. *((__le32 *)(&mac[0])) = cpu_to_le32(rcmta0);
  838. *((__le16 *)(&mac[4])) = cpu_to_le16(rcmta1);
  839. printk(" MAC: %s",
  840. print_mac(macbuf, mac));
  841. } else
  842. printk(" DEFAULT KEY");
  843. printk("\n");
  844. }
  845. }
  846. void b43_power_saving_ctl_bits(struct b43_wldev *dev, unsigned int ps_flags)
  847. {
  848. u32 macctl;
  849. u16 ucstat;
  850. bool hwps;
  851. bool awake;
  852. int i;
  853. B43_WARN_ON((ps_flags & B43_PS_ENABLED) &&
  854. (ps_flags & B43_PS_DISABLED));
  855. B43_WARN_ON((ps_flags & B43_PS_AWAKE) && (ps_flags & B43_PS_ASLEEP));
  856. if (ps_flags & B43_PS_ENABLED) {
  857. hwps = 1;
  858. } else if (ps_flags & B43_PS_DISABLED) {
  859. hwps = 0;
  860. } else {
  861. //TODO: If powersave is not off and FIXME is not set and we are not in adhoc
  862. // and thus is not an AP and we are associated, set bit 25
  863. }
  864. if (ps_flags & B43_PS_AWAKE) {
  865. awake = 1;
  866. } else if (ps_flags & B43_PS_ASLEEP) {
  867. awake = 0;
  868. } else {
  869. //TODO: If the device is awake or this is an AP, or we are scanning, or FIXME,
  870. // or we are associated, or FIXME, or the latest PS-Poll packet sent was
  871. // successful, set bit26
  872. }
  873. /* FIXME: For now we force awake-on and hwps-off */
  874. hwps = 0;
  875. awake = 1;
  876. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  877. if (hwps)
  878. macctl |= B43_MACCTL_HWPS;
  879. else
  880. macctl &= ~B43_MACCTL_HWPS;
  881. if (awake)
  882. macctl |= B43_MACCTL_AWAKE;
  883. else
  884. macctl &= ~B43_MACCTL_AWAKE;
  885. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  886. /* Commit write */
  887. b43_read32(dev, B43_MMIO_MACCTL);
  888. if (awake && dev->dev->id.revision >= 5) {
  889. /* Wait for the microcode to wake up. */
  890. for (i = 0; i < 100; i++) {
  891. ucstat = b43_shm_read16(dev, B43_SHM_SHARED,
  892. B43_SHM_SH_UCODESTAT);
  893. if (ucstat != B43_SHM_SH_UCODESTAT_SLEEP)
  894. break;
  895. udelay(10);
  896. }
  897. }
  898. }
  899. void b43_wireless_core_reset(struct b43_wldev *dev, u32 flags)
  900. {
  901. u32 tmslow;
  902. u32 macctl;
  903. flags |= B43_TMSLOW_PHYCLKEN;
  904. flags |= B43_TMSLOW_PHYRESET;
  905. ssb_device_enable(dev->dev, flags);
  906. msleep(2); /* Wait for the PLL to turn on. */
  907. /* Now take the PHY out of Reset again */
  908. tmslow = ssb_read32(dev->dev, SSB_TMSLOW);
  909. tmslow |= SSB_TMSLOW_FGC;
  910. tmslow &= ~B43_TMSLOW_PHYRESET;
  911. ssb_write32(dev->dev, SSB_TMSLOW, tmslow);
  912. ssb_read32(dev->dev, SSB_TMSLOW); /* flush */
  913. msleep(1);
  914. tmslow &= ~SSB_TMSLOW_FGC;
  915. ssb_write32(dev->dev, SSB_TMSLOW, tmslow);
  916. ssb_read32(dev->dev, SSB_TMSLOW); /* flush */
  917. msleep(1);
  918. /* Turn Analog ON, but only if we already know the PHY-type.
  919. * This protects against very early setup where we don't know the
  920. * PHY-type, yet. wireless_core_reset will be called once again later,
  921. * when we know the PHY-type. */
  922. if (dev->phy.ops)
  923. dev->phy.ops->switch_analog(dev, 1);
  924. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  925. macctl &= ~B43_MACCTL_GMODE;
  926. if (flags & B43_TMSLOW_GMODE)
  927. macctl |= B43_MACCTL_GMODE;
  928. macctl |= B43_MACCTL_IHR_ENABLED;
  929. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  930. }
  931. static void handle_irq_transmit_status(struct b43_wldev *dev)
  932. {
  933. u32 v0, v1;
  934. u16 tmp;
  935. struct b43_txstatus stat;
  936. while (1) {
  937. v0 = b43_read32(dev, B43_MMIO_XMITSTAT_0);
  938. if (!(v0 & 0x00000001))
  939. break;
  940. v1 = b43_read32(dev, B43_MMIO_XMITSTAT_1);
  941. stat.cookie = (v0 >> 16);
  942. stat.seq = (v1 & 0x0000FFFF);
  943. stat.phy_stat = ((v1 & 0x00FF0000) >> 16);
  944. tmp = (v0 & 0x0000FFFF);
  945. stat.frame_count = ((tmp & 0xF000) >> 12);
  946. stat.rts_count = ((tmp & 0x0F00) >> 8);
  947. stat.supp_reason = ((tmp & 0x001C) >> 2);
  948. stat.pm_indicated = !!(tmp & 0x0080);
  949. stat.intermediate = !!(tmp & 0x0040);
  950. stat.for_ampdu = !!(tmp & 0x0020);
  951. stat.acked = !!(tmp & 0x0002);
  952. b43_handle_txstatus(dev, &stat);
  953. }
  954. }
  955. static void drain_txstatus_queue(struct b43_wldev *dev)
  956. {
  957. u32 dummy;
  958. if (dev->dev->id.revision < 5)
  959. return;
  960. /* Read all entries from the microcode TXstatus FIFO
  961. * and throw them away.
  962. */
  963. while (1) {
  964. dummy = b43_read32(dev, B43_MMIO_XMITSTAT_0);
  965. if (!(dummy & 0x00000001))
  966. break;
  967. dummy = b43_read32(dev, B43_MMIO_XMITSTAT_1);
  968. }
  969. }
  970. static u32 b43_jssi_read(struct b43_wldev *dev)
  971. {
  972. u32 val = 0;
  973. val = b43_shm_read16(dev, B43_SHM_SHARED, 0x08A);
  974. val <<= 16;
  975. val |= b43_shm_read16(dev, B43_SHM_SHARED, 0x088);
  976. return val;
  977. }
  978. static void b43_jssi_write(struct b43_wldev *dev, u32 jssi)
  979. {
  980. b43_shm_write16(dev, B43_SHM_SHARED, 0x088, (jssi & 0x0000FFFF));
  981. b43_shm_write16(dev, B43_SHM_SHARED, 0x08A, (jssi & 0xFFFF0000) >> 16);
  982. }
  983. static void b43_generate_noise_sample(struct b43_wldev *dev)
  984. {
  985. b43_jssi_write(dev, 0x7F7F7F7F);
  986. b43_write32(dev, B43_MMIO_MACCMD,
  987. b43_read32(dev, B43_MMIO_MACCMD) | B43_MACCMD_BGNOISE);
  988. }
  989. static void b43_calculate_link_quality(struct b43_wldev *dev)
  990. {
  991. /* Top half of Link Quality calculation. */
  992. if (dev->phy.type != B43_PHYTYPE_G)
  993. return;
  994. if (dev->noisecalc.calculation_running)
  995. return;
  996. dev->noisecalc.calculation_running = 1;
  997. dev->noisecalc.nr_samples = 0;
  998. b43_generate_noise_sample(dev);
  999. }
  1000. static void handle_irq_noise(struct b43_wldev *dev)
  1001. {
  1002. struct b43_phy_g *phy = dev->phy.g;
  1003. u16 tmp;
  1004. u8 noise[4];
  1005. u8 i, j;
  1006. s32 average;
  1007. /* Bottom half of Link Quality calculation. */
  1008. if (dev->phy.type != B43_PHYTYPE_G)
  1009. return;
  1010. /* Possible race condition: It might be possible that the user
  1011. * changed to a different channel in the meantime since we
  1012. * started the calculation. We ignore that fact, since it's
  1013. * not really that much of a problem. The background noise is
  1014. * an estimation only anyway. Slightly wrong results will get damped
  1015. * by the averaging of the 8 sample rounds. Additionally the
  1016. * value is shortlived. So it will be replaced by the next noise
  1017. * calculation round soon. */
  1018. B43_WARN_ON(!dev->noisecalc.calculation_running);
  1019. *((__le32 *)noise) = cpu_to_le32(b43_jssi_read(dev));
  1020. if (noise[0] == 0x7F || noise[1] == 0x7F ||
  1021. noise[2] == 0x7F || noise[3] == 0x7F)
  1022. goto generate_new;
  1023. /* Get the noise samples. */
  1024. B43_WARN_ON(dev->noisecalc.nr_samples >= 8);
  1025. i = dev->noisecalc.nr_samples;
  1026. noise[0] = clamp_val(noise[0], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1027. noise[1] = clamp_val(noise[1], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1028. noise[2] = clamp_val(noise[2], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1029. noise[3] = clamp_val(noise[3], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1030. dev->noisecalc.samples[i][0] = phy->nrssi_lt[noise[0]];
  1031. dev->noisecalc.samples[i][1] = phy->nrssi_lt[noise[1]];
  1032. dev->noisecalc.samples[i][2] = phy->nrssi_lt[noise[2]];
  1033. dev->noisecalc.samples[i][3] = phy->nrssi_lt[noise[3]];
  1034. dev->noisecalc.nr_samples++;
  1035. if (dev->noisecalc.nr_samples == 8) {
  1036. /* Calculate the Link Quality by the noise samples. */
  1037. average = 0;
  1038. for (i = 0; i < 8; i++) {
  1039. for (j = 0; j < 4; j++)
  1040. average += dev->noisecalc.samples[i][j];
  1041. }
  1042. average /= (8 * 4);
  1043. average *= 125;
  1044. average += 64;
  1045. average /= 128;
  1046. tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x40C);
  1047. tmp = (tmp / 128) & 0x1F;
  1048. if (tmp >= 8)
  1049. average += 2;
  1050. else
  1051. average -= 25;
  1052. if (tmp == 8)
  1053. average -= 72;
  1054. else
  1055. average -= 48;
  1056. dev->stats.link_noise = average;
  1057. dev->noisecalc.calculation_running = 0;
  1058. return;
  1059. }
  1060. generate_new:
  1061. b43_generate_noise_sample(dev);
  1062. }
  1063. static void handle_irq_tbtt_indication(struct b43_wldev *dev)
  1064. {
  1065. if (b43_is_mode(dev->wl, NL80211_IFTYPE_AP)) {
  1066. ///TODO: PS TBTT
  1067. } else {
  1068. if (1 /*FIXME: the last PSpoll frame was sent successfully */ )
  1069. b43_power_saving_ctl_bits(dev, 0);
  1070. }
  1071. if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC))
  1072. dev->dfq_valid = 1;
  1073. }
  1074. static void handle_irq_atim_end(struct b43_wldev *dev)
  1075. {
  1076. if (dev->dfq_valid) {
  1077. b43_write32(dev, B43_MMIO_MACCMD,
  1078. b43_read32(dev, B43_MMIO_MACCMD)
  1079. | B43_MACCMD_DFQ_VALID);
  1080. dev->dfq_valid = 0;
  1081. }
  1082. }
  1083. static void handle_irq_pmq(struct b43_wldev *dev)
  1084. {
  1085. u32 tmp;
  1086. //TODO: AP mode.
  1087. while (1) {
  1088. tmp = b43_read32(dev, B43_MMIO_PS_STATUS);
  1089. if (!(tmp & 0x00000008))
  1090. break;
  1091. }
  1092. /* 16bit write is odd, but correct. */
  1093. b43_write16(dev, B43_MMIO_PS_STATUS, 0x0002);
  1094. }
  1095. static void b43_write_template_common(struct b43_wldev *dev,
  1096. const u8 *data, u16 size,
  1097. u16 ram_offset,
  1098. u16 shm_size_offset, u8 rate)
  1099. {
  1100. u32 i, tmp;
  1101. struct b43_plcp_hdr4 plcp;
  1102. plcp.data = 0;
  1103. b43_generate_plcp_hdr(&plcp, size + FCS_LEN, rate);
  1104. b43_ram_write(dev, ram_offset, le32_to_cpu(plcp.data));
  1105. ram_offset += sizeof(u32);
  1106. /* The PLCP is 6 bytes long, but we only wrote 4 bytes, yet.
  1107. * So leave the first two bytes of the next write blank.
  1108. */
  1109. tmp = (u32) (data[0]) << 16;
  1110. tmp |= (u32) (data[1]) << 24;
  1111. b43_ram_write(dev, ram_offset, tmp);
  1112. ram_offset += sizeof(u32);
  1113. for (i = 2; i < size; i += sizeof(u32)) {
  1114. tmp = (u32) (data[i + 0]);
  1115. if (i + 1 < size)
  1116. tmp |= (u32) (data[i + 1]) << 8;
  1117. if (i + 2 < size)
  1118. tmp |= (u32) (data[i + 2]) << 16;
  1119. if (i + 3 < size)
  1120. tmp |= (u32) (data[i + 3]) << 24;
  1121. b43_ram_write(dev, ram_offset + i - 2, tmp);
  1122. }
  1123. b43_shm_write16(dev, B43_SHM_SHARED, shm_size_offset,
  1124. size + sizeof(struct b43_plcp_hdr6));
  1125. }
  1126. /* Check if the use of the antenna that ieee80211 told us to
  1127. * use is possible. This will fall back to DEFAULT.
  1128. * "antenna_nr" is the antenna identifier we got from ieee80211. */
  1129. u8 b43_ieee80211_antenna_sanitize(struct b43_wldev *dev,
  1130. u8 antenna_nr)
  1131. {
  1132. u8 antenna_mask;
  1133. if (antenna_nr == 0) {
  1134. /* Zero means "use default antenna". That's always OK. */
  1135. return 0;
  1136. }
  1137. /* Get the mask of available antennas. */
  1138. if (dev->phy.gmode)
  1139. antenna_mask = dev->dev->bus->sprom.ant_available_bg;
  1140. else
  1141. antenna_mask = dev->dev->bus->sprom.ant_available_a;
  1142. if (!(antenna_mask & (1 << (antenna_nr - 1)))) {
  1143. /* This antenna is not available. Fall back to default. */
  1144. return 0;
  1145. }
  1146. return antenna_nr;
  1147. }
  1148. /* Convert a b43 antenna number value to the PHY TX control value. */
  1149. static u16 b43_antenna_to_phyctl(int antenna)
  1150. {
  1151. switch (antenna) {
  1152. case B43_ANTENNA0:
  1153. return B43_TXH_PHY_ANT0;
  1154. case B43_ANTENNA1:
  1155. return B43_TXH_PHY_ANT1;
  1156. case B43_ANTENNA2:
  1157. return B43_TXH_PHY_ANT2;
  1158. case B43_ANTENNA3:
  1159. return B43_TXH_PHY_ANT3;
  1160. case B43_ANTENNA_AUTO:
  1161. return B43_TXH_PHY_ANT01AUTO;
  1162. }
  1163. B43_WARN_ON(1);
  1164. return 0;
  1165. }
  1166. static void b43_write_beacon_template(struct b43_wldev *dev,
  1167. u16 ram_offset,
  1168. u16 shm_size_offset)
  1169. {
  1170. unsigned int i, len, variable_len;
  1171. const struct ieee80211_mgmt *bcn;
  1172. const u8 *ie;
  1173. bool tim_found = 0;
  1174. unsigned int rate;
  1175. u16 ctl;
  1176. int antenna;
  1177. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(dev->wl->current_beacon);
  1178. bcn = (const struct ieee80211_mgmt *)(dev->wl->current_beacon->data);
  1179. len = min((size_t) dev->wl->current_beacon->len,
  1180. 0x200 - sizeof(struct b43_plcp_hdr6));
  1181. rate = ieee80211_get_tx_rate(dev->wl->hw, info)->hw_value;
  1182. b43_write_template_common(dev, (const u8 *)bcn,
  1183. len, ram_offset, shm_size_offset, rate);
  1184. /* Write the PHY TX control parameters. */
  1185. antenna = B43_ANTENNA_DEFAULT;
  1186. antenna = b43_antenna_to_phyctl(antenna);
  1187. ctl = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL);
  1188. /* We can't send beacons with short preamble. Would get PHY errors. */
  1189. ctl &= ~B43_TXH_PHY_SHORTPRMBL;
  1190. ctl &= ~B43_TXH_PHY_ANT;
  1191. ctl &= ~B43_TXH_PHY_ENC;
  1192. ctl |= antenna;
  1193. if (b43_is_cck_rate(rate))
  1194. ctl |= B43_TXH_PHY_ENC_CCK;
  1195. else
  1196. ctl |= B43_TXH_PHY_ENC_OFDM;
  1197. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL, ctl);
  1198. /* Find the position of the TIM and the DTIM_period value
  1199. * and write them to SHM. */
  1200. ie = bcn->u.beacon.variable;
  1201. variable_len = len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
  1202. for (i = 0; i < variable_len - 2; ) {
  1203. uint8_t ie_id, ie_len;
  1204. ie_id = ie[i];
  1205. ie_len = ie[i + 1];
  1206. if (ie_id == 5) {
  1207. u16 tim_position;
  1208. u16 dtim_period;
  1209. /* This is the TIM Information Element */
  1210. /* Check whether the ie_len is in the beacon data range. */
  1211. if (variable_len < ie_len + 2 + i)
  1212. break;
  1213. /* A valid TIM is at least 4 bytes long. */
  1214. if (ie_len < 4)
  1215. break;
  1216. tim_found = 1;
  1217. tim_position = sizeof(struct b43_plcp_hdr6);
  1218. tim_position += offsetof(struct ieee80211_mgmt, u.beacon.variable);
  1219. tim_position += i;
  1220. dtim_period = ie[i + 3];
  1221. b43_shm_write16(dev, B43_SHM_SHARED,
  1222. B43_SHM_SH_TIMBPOS, tim_position);
  1223. b43_shm_write16(dev, B43_SHM_SHARED,
  1224. B43_SHM_SH_DTIMPER, dtim_period);
  1225. break;
  1226. }
  1227. i += ie_len + 2;
  1228. }
  1229. if (!tim_found) {
  1230. /*
  1231. * If ucode wants to modify TIM do it behind the beacon, this
  1232. * will happen, for example, when doing mesh networking.
  1233. */
  1234. b43_shm_write16(dev, B43_SHM_SHARED,
  1235. B43_SHM_SH_TIMBPOS,
  1236. len + sizeof(struct b43_plcp_hdr6));
  1237. b43_shm_write16(dev, B43_SHM_SHARED,
  1238. B43_SHM_SH_DTIMPER, 0);
  1239. }
  1240. b43dbg(dev->wl, "Updated beacon template at 0x%x\n", ram_offset);
  1241. }
  1242. static void b43_write_probe_resp_plcp(struct b43_wldev *dev,
  1243. u16 shm_offset, u16 size,
  1244. struct ieee80211_rate *rate)
  1245. {
  1246. struct b43_plcp_hdr4 plcp;
  1247. u32 tmp;
  1248. __le16 dur;
  1249. plcp.data = 0;
  1250. b43_generate_plcp_hdr(&plcp, size + FCS_LEN, rate->hw_value);
  1251. dur = ieee80211_generic_frame_duration(dev->wl->hw,
  1252. dev->wl->vif, size,
  1253. rate);
  1254. /* Write PLCP in two parts and timing for packet transfer */
  1255. tmp = le32_to_cpu(plcp.data);
  1256. b43_shm_write16(dev, B43_SHM_SHARED, shm_offset, tmp & 0xFFFF);
  1257. b43_shm_write16(dev, B43_SHM_SHARED, shm_offset + 2, tmp >> 16);
  1258. b43_shm_write16(dev, B43_SHM_SHARED, shm_offset + 6, le16_to_cpu(dur));
  1259. }
  1260. /* Instead of using custom probe response template, this function
  1261. * just patches custom beacon template by:
  1262. * 1) Changing packet type
  1263. * 2) Patching duration field
  1264. * 3) Stripping TIM
  1265. */
  1266. static const u8 *b43_generate_probe_resp(struct b43_wldev *dev,
  1267. u16 *dest_size,
  1268. struct ieee80211_rate *rate)
  1269. {
  1270. const u8 *src_data;
  1271. u8 *dest_data;
  1272. u16 src_size, elem_size, src_pos, dest_pos;
  1273. __le16 dur;
  1274. struct ieee80211_hdr *hdr;
  1275. size_t ie_start;
  1276. src_size = dev->wl->current_beacon->len;
  1277. src_data = (const u8 *)dev->wl->current_beacon->data;
  1278. /* Get the start offset of the variable IEs in the packet. */
  1279. ie_start = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
  1280. B43_WARN_ON(ie_start != offsetof(struct ieee80211_mgmt, u.beacon.variable));
  1281. if (B43_WARN_ON(src_size < ie_start))
  1282. return NULL;
  1283. dest_data = kmalloc(src_size, GFP_ATOMIC);
  1284. if (unlikely(!dest_data))
  1285. return NULL;
  1286. /* Copy the static data and all Information Elements, except the TIM. */
  1287. memcpy(dest_data, src_data, ie_start);
  1288. src_pos = ie_start;
  1289. dest_pos = ie_start;
  1290. for ( ; src_pos < src_size - 2; src_pos += elem_size) {
  1291. elem_size = src_data[src_pos + 1] + 2;
  1292. if (src_data[src_pos] == 5) {
  1293. /* This is the TIM. */
  1294. continue;
  1295. }
  1296. memcpy(dest_data + dest_pos, src_data + src_pos,
  1297. elem_size);
  1298. dest_pos += elem_size;
  1299. }
  1300. *dest_size = dest_pos;
  1301. hdr = (struct ieee80211_hdr *)dest_data;
  1302. /* Set the frame control. */
  1303. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1304. IEEE80211_STYPE_PROBE_RESP);
  1305. dur = ieee80211_generic_frame_duration(dev->wl->hw,
  1306. dev->wl->vif, *dest_size,
  1307. rate);
  1308. hdr->duration_id = dur;
  1309. return dest_data;
  1310. }
  1311. static void b43_write_probe_resp_template(struct b43_wldev *dev,
  1312. u16 ram_offset,
  1313. u16 shm_size_offset,
  1314. struct ieee80211_rate *rate)
  1315. {
  1316. const u8 *probe_resp_data;
  1317. u16 size;
  1318. size = dev->wl->current_beacon->len;
  1319. probe_resp_data = b43_generate_probe_resp(dev, &size, rate);
  1320. if (unlikely(!probe_resp_data))
  1321. return;
  1322. /* Looks like PLCP headers plus packet timings are stored for
  1323. * all possible basic rates
  1324. */
  1325. b43_write_probe_resp_plcp(dev, 0x31A, size, &b43_b_ratetable[0]);
  1326. b43_write_probe_resp_plcp(dev, 0x32C, size, &b43_b_ratetable[1]);
  1327. b43_write_probe_resp_plcp(dev, 0x33E, size, &b43_b_ratetable[2]);
  1328. b43_write_probe_resp_plcp(dev, 0x350, size, &b43_b_ratetable[3]);
  1329. size = min((size_t) size, 0x200 - sizeof(struct b43_plcp_hdr6));
  1330. b43_write_template_common(dev, probe_resp_data,
  1331. size, ram_offset, shm_size_offset,
  1332. rate->hw_value);
  1333. kfree(probe_resp_data);
  1334. }
  1335. static void b43_upload_beacon0(struct b43_wldev *dev)
  1336. {
  1337. struct b43_wl *wl = dev->wl;
  1338. if (wl->beacon0_uploaded)
  1339. return;
  1340. b43_write_beacon_template(dev, 0x68, 0x18);
  1341. /* FIXME: Probe resp upload doesn't really belong here,
  1342. * but we don't use that feature anyway. */
  1343. b43_write_probe_resp_template(dev, 0x268, 0x4A,
  1344. &__b43_ratetable[3]);
  1345. wl->beacon0_uploaded = 1;
  1346. }
  1347. static void b43_upload_beacon1(struct b43_wldev *dev)
  1348. {
  1349. struct b43_wl *wl = dev->wl;
  1350. if (wl->beacon1_uploaded)
  1351. return;
  1352. b43_write_beacon_template(dev, 0x468, 0x1A);
  1353. wl->beacon1_uploaded = 1;
  1354. }
  1355. static void handle_irq_beacon(struct b43_wldev *dev)
  1356. {
  1357. struct b43_wl *wl = dev->wl;
  1358. u32 cmd, beacon0_valid, beacon1_valid;
  1359. if (!b43_is_mode(wl, NL80211_IFTYPE_AP) &&
  1360. !b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT))
  1361. return;
  1362. /* This is the bottom half of the asynchronous beacon update. */
  1363. /* Ignore interrupt in the future. */
  1364. dev->irq_mask &= ~B43_IRQ_BEACON;
  1365. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1366. beacon0_valid = (cmd & B43_MACCMD_BEACON0_VALID);
  1367. beacon1_valid = (cmd & B43_MACCMD_BEACON1_VALID);
  1368. /* Schedule interrupt manually, if busy. */
  1369. if (beacon0_valid && beacon1_valid) {
  1370. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, B43_IRQ_BEACON);
  1371. dev->irq_mask |= B43_IRQ_BEACON;
  1372. return;
  1373. }
  1374. if (unlikely(wl->beacon_templates_virgin)) {
  1375. /* We never uploaded a beacon before.
  1376. * Upload both templates now, but only mark one valid. */
  1377. wl->beacon_templates_virgin = 0;
  1378. b43_upload_beacon0(dev);
  1379. b43_upload_beacon1(dev);
  1380. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1381. cmd |= B43_MACCMD_BEACON0_VALID;
  1382. b43_write32(dev, B43_MMIO_MACCMD, cmd);
  1383. } else {
  1384. if (!beacon0_valid) {
  1385. b43_upload_beacon0(dev);
  1386. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1387. cmd |= B43_MACCMD_BEACON0_VALID;
  1388. b43_write32(dev, B43_MMIO_MACCMD, cmd);
  1389. } else if (!beacon1_valid) {
  1390. b43_upload_beacon1(dev);
  1391. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1392. cmd |= B43_MACCMD_BEACON1_VALID;
  1393. b43_write32(dev, B43_MMIO_MACCMD, cmd);
  1394. }
  1395. }
  1396. }
  1397. static void b43_beacon_update_trigger_work(struct work_struct *work)
  1398. {
  1399. struct b43_wl *wl = container_of(work, struct b43_wl,
  1400. beacon_update_trigger);
  1401. struct b43_wldev *dev;
  1402. mutex_lock(&wl->mutex);
  1403. dev = wl->current_dev;
  1404. if (likely(dev && (b43_status(dev) >= B43_STAT_INITIALIZED))) {
  1405. spin_lock_irq(&wl->irq_lock);
  1406. /* update beacon right away or defer to irq */
  1407. handle_irq_beacon(dev);
  1408. /* The handler might have updated the IRQ mask. */
  1409. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
  1410. mmiowb();
  1411. spin_unlock_irq(&wl->irq_lock);
  1412. }
  1413. mutex_unlock(&wl->mutex);
  1414. }
  1415. /* Asynchronously update the packet templates in template RAM.
  1416. * Locking: Requires wl->irq_lock to be locked. */
  1417. static void b43_update_templates(struct b43_wl *wl)
  1418. {
  1419. struct sk_buff *beacon;
  1420. /* This is the top half of the ansynchronous beacon update.
  1421. * The bottom half is the beacon IRQ.
  1422. * Beacon update must be asynchronous to avoid sending an
  1423. * invalid beacon. This can happen for example, if the firmware
  1424. * transmits a beacon while we are updating it. */
  1425. /* We could modify the existing beacon and set the aid bit in
  1426. * the TIM field, but that would probably require resizing and
  1427. * moving of data within the beacon template.
  1428. * Simply request a new beacon and let mac80211 do the hard work. */
  1429. beacon = ieee80211_beacon_get(wl->hw, wl->vif);
  1430. if (unlikely(!beacon))
  1431. return;
  1432. if (wl->current_beacon)
  1433. dev_kfree_skb_any(wl->current_beacon);
  1434. wl->current_beacon = beacon;
  1435. wl->beacon0_uploaded = 0;
  1436. wl->beacon1_uploaded = 0;
  1437. queue_work(wl->hw->workqueue, &wl->beacon_update_trigger);
  1438. }
  1439. static void b43_set_beacon_int(struct b43_wldev *dev, u16 beacon_int)
  1440. {
  1441. b43_time_lock(dev);
  1442. if (dev->dev->id.revision >= 3) {
  1443. b43_write32(dev, B43_MMIO_TSF_CFP_REP, (beacon_int << 16));
  1444. b43_write32(dev, B43_MMIO_TSF_CFP_START, (beacon_int << 10));
  1445. } else {
  1446. b43_write16(dev, 0x606, (beacon_int >> 6));
  1447. b43_write16(dev, 0x610, beacon_int);
  1448. }
  1449. b43_time_unlock(dev);
  1450. b43dbg(dev->wl, "Set beacon interval to %u\n", beacon_int);
  1451. }
  1452. static void b43_handle_firmware_panic(struct b43_wldev *dev)
  1453. {
  1454. u16 reason;
  1455. /* Read the register that contains the reason code for the panic. */
  1456. reason = b43_shm_read16(dev, B43_SHM_SCRATCH, B43_FWPANIC_REASON_REG);
  1457. b43err(dev->wl, "Whoopsy, firmware panic! Reason: %u\n", reason);
  1458. switch (reason) {
  1459. default:
  1460. b43dbg(dev->wl, "The panic reason is unknown.\n");
  1461. /* fallthrough */
  1462. case B43_FWPANIC_DIE:
  1463. /* Do not restart the controller or firmware.
  1464. * The device is nonfunctional from now on.
  1465. * Restarting would result in this panic to trigger again,
  1466. * so we avoid that recursion. */
  1467. break;
  1468. case B43_FWPANIC_RESTART:
  1469. b43_controller_restart(dev, "Microcode panic");
  1470. break;
  1471. }
  1472. }
  1473. static void handle_irq_ucode_debug(struct b43_wldev *dev)
  1474. {
  1475. unsigned int i, cnt;
  1476. u16 reason, marker_id, marker_line;
  1477. __le16 *buf;
  1478. /* The proprietary firmware doesn't have this IRQ. */
  1479. if (!dev->fw.opensource)
  1480. return;
  1481. /* Read the register that contains the reason code for this IRQ. */
  1482. reason = b43_shm_read16(dev, B43_SHM_SCRATCH, B43_DEBUGIRQ_REASON_REG);
  1483. switch (reason) {
  1484. case B43_DEBUGIRQ_PANIC:
  1485. b43_handle_firmware_panic(dev);
  1486. break;
  1487. case B43_DEBUGIRQ_DUMP_SHM:
  1488. if (!B43_DEBUG)
  1489. break; /* Only with driver debugging enabled. */
  1490. buf = kmalloc(4096, GFP_ATOMIC);
  1491. if (!buf) {
  1492. b43dbg(dev->wl, "SHM-dump: Failed to allocate memory\n");
  1493. goto out;
  1494. }
  1495. for (i = 0; i < 4096; i += 2) {
  1496. u16 tmp = b43_shm_read16(dev, B43_SHM_SHARED, i);
  1497. buf[i / 2] = cpu_to_le16(tmp);
  1498. }
  1499. b43info(dev->wl, "Shared memory dump:\n");
  1500. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET,
  1501. 16, 2, buf, 4096, 1);
  1502. kfree(buf);
  1503. break;
  1504. case B43_DEBUGIRQ_DUMP_REGS:
  1505. if (!B43_DEBUG)
  1506. break; /* Only with driver debugging enabled. */
  1507. b43info(dev->wl, "Microcode register dump:\n");
  1508. for (i = 0, cnt = 0; i < 64; i++) {
  1509. u16 tmp = b43_shm_read16(dev, B43_SHM_SCRATCH, i);
  1510. if (cnt == 0)
  1511. printk(KERN_INFO);
  1512. printk("r%02u: 0x%04X ", i, tmp);
  1513. cnt++;
  1514. if (cnt == 6) {
  1515. printk("\n");
  1516. cnt = 0;
  1517. }
  1518. }
  1519. printk("\n");
  1520. break;
  1521. case B43_DEBUGIRQ_MARKER:
  1522. if (!B43_DEBUG)
  1523. break; /* Only with driver debugging enabled. */
  1524. marker_id = b43_shm_read16(dev, B43_SHM_SCRATCH,
  1525. B43_MARKER_ID_REG);
  1526. marker_line = b43_shm_read16(dev, B43_SHM_SCRATCH,
  1527. B43_MARKER_LINE_REG);
  1528. b43info(dev->wl, "The firmware just executed the MARKER(%u) "
  1529. "at line number %u\n",
  1530. marker_id, marker_line);
  1531. break;
  1532. default:
  1533. b43dbg(dev->wl, "Debug-IRQ triggered for unknown reason: %u\n",
  1534. reason);
  1535. }
  1536. out:
  1537. /* Acknowledge the debug-IRQ, so the firmware can continue. */
  1538. b43_shm_write16(dev, B43_SHM_SCRATCH,
  1539. B43_DEBUGIRQ_REASON_REG, B43_DEBUGIRQ_ACK);
  1540. }
  1541. /* Interrupt handler bottom-half */
  1542. static void b43_interrupt_tasklet(struct b43_wldev *dev)
  1543. {
  1544. u32 reason;
  1545. u32 dma_reason[ARRAY_SIZE(dev->dma_reason)];
  1546. u32 merged_dma_reason = 0;
  1547. int i;
  1548. unsigned long flags;
  1549. spin_lock_irqsave(&dev->wl->irq_lock, flags);
  1550. B43_WARN_ON(b43_status(dev) != B43_STAT_STARTED);
  1551. reason = dev->irq_reason;
  1552. for (i = 0; i < ARRAY_SIZE(dma_reason); i++) {
  1553. dma_reason[i] = dev->dma_reason[i];
  1554. merged_dma_reason |= dma_reason[i];
  1555. }
  1556. if (unlikely(reason & B43_IRQ_MAC_TXERR))
  1557. b43err(dev->wl, "MAC transmission error\n");
  1558. if (unlikely(reason & B43_IRQ_PHY_TXERR)) {
  1559. b43err(dev->wl, "PHY transmission error\n");
  1560. rmb();
  1561. if (unlikely(atomic_dec_and_test(&dev->phy.txerr_cnt))) {
  1562. atomic_set(&dev->phy.txerr_cnt,
  1563. B43_PHY_TX_BADNESS_LIMIT);
  1564. b43err(dev->wl, "Too many PHY TX errors, "
  1565. "restarting the controller\n");
  1566. b43_controller_restart(dev, "PHY TX errors");
  1567. }
  1568. }
  1569. if (unlikely(merged_dma_reason & (B43_DMAIRQ_FATALMASK |
  1570. B43_DMAIRQ_NONFATALMASK))) {
  1571. if (merged_dma_reason & B43_DMAIRQ_FATALMASK) {
  1572. b43err(dev->wl, "Fatal DMA error: "
  1573. "0x%08X, 0x%08X, 0x%08X, "
  1574. "0x%08X, 0x%08X, 0x%08X\n",
  1575. dma_reason[0], dma_reason[1],
  1576. dma_reason[2], dma_reason[3],
  1577. dma_reason[4], dma_reason[5]);
  1578. b43_controller_restart(dev, "DMA error");
  1579. mmiowb();
  1580. spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
  1581. return;
  1582. }
  1583. if (merged_dma_reason & B43_DMAIRQ_NONFATALMASK) {
  1584. b43err(dev->wl, "DMA error: "
  1585. "0x%08X, 0x%08X, 0x%08X, "
  1586. "0x%08X, 0x%08X, 0x%08X\n",
  1587. dma_reason[0], dma_reason[1],
  1588. dma_reason[2], dma_reason[3],
  1589. dma_reason[4], dma_reason[5]);
  1590. }
  1591. }
  1592. if (unlikely(reason & B43_IRQ_UCODE_DEBUG))
  1593. handle_irq_ucode_debug(dev);
  1594. if (reason & B43_IRQ_TBTT_INDI)
  1595. handle_irq_tbtt_indication(dev);
  1596. if (reason & B43_IRQ_ATIM_END)
  1597. handle_irq_atim_end(dev);
  1598. if (reason & B43_IRQ_BEACON)
  1599. handle_irq_beacon(dev);
  1600. if (reason & B43_IRQ_PMQ)
  1601. handle_irq_pmq(dev);
  1602. if (reason & B43_IRQ_TXFIFO_FLUSH_OK)
  1603. ;/* TODO */
  1604. if (reason & B43_IRQ_NOISESAMPLE_OK)
  1605. handle_irq_noise(dev);
  1606. /* Check the DMA reason registers for received data. */
  1607. if (dma_reason[0] & B43_DMAIRQ_RX_DONE) {
  1608. if (b43_using_pio_transfers(dev))
  1609. b43_pio_rx(dev->pio.rx_queue);
  1610. else
  1611. b43_dma_rx(dev->dma.rx_ring);
  1612. }
  1613. B43_WARN_ON(dma_reason[1] & B43_DMAIRQ_RX_DONE);
  1614. B43_WARN_ON(dma_reason[2] & B43_DMAIRQ_RX_DONE);
  1615. B43_WARN_ON(dma_reason[3] & B43_DMAIRQ_RX_DONE);
  1616. B43_WARN_ON(dma_reason[4] & B43_DMAIRQ_RX_DONE);
  1617. B43_WARN_ON(dma_reason[5] & B43_DMAIRQ_RX_DONE);
  1618. if (reason & B43_IRQ_TX_OK)
  1619. handle_irq_transmit_status(dev);
  1620. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
  1621. mmiowb();
  1622. spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
  1623. }
  1624. static void b43_interrupt_ack(struct b43_wldev *dev, u32 reason)
  1625. {
  1626. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, reason);
  1627. b43_write32(dev, B43_MMIO_DMA0_REASON, dev->dma_reason[0]);
  1628. b43_write32(dev, B43_MMIO_DMA1_REASON, dev->dma_reason[1]);
  1629. b43_write32(dev, B43_MMIO_DMA2_REASON, dev->dma_reason[2]);
  1630. b43_write32(dev, B43_MMIO_DMA3_REASON, dev->dma_reason[3]);
  1631. b43_write32(dev, B43_MMIO_DMA4_REASON, dev->dma_reason[4]);
  1632. /* Unused ring
  1633. b43_write32(dev, B43_MMIO_DMA5_REASON, dev->dma_reason[5]);
  1634. */
  1635. }
  1636. /* Interrupt handler top-half */
  1637. static irqreturn_t b43_interrupt_handler(int irq, void *dev_id)
  1638. {
  1639. irqreturn_t ret = IRQ_NONE;
  1640. struct b43_wldev *dev = dev_id;
  1641. u32 reason;
  1642. B43_WARN_ON(!dev);
  1643. spin_lock(&dev->wl->irq_lock);
  1644. if (unlikely(b43_status(dev) < B43_STAT_STARTED)) {
  1645. /* This can only happen on shared IRQ lines. */
  1646. goto out;
  1647. }
  1648. reason = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  1649. if (reason == 0xffffffff) /* shared IRQ */
  1650. goto out;
  1651. ret = IRQ_HANDLED;
  1652. reason &= dev->irq_mask;
  1653. if (!reason)
  1654. goto out;
  1655. dev->dma_reason[0] = b43_read32(dev, B43_MMIO_DMA0_REASON)
  1656. & 0x0001DC00;
  1657. dev->dma_reason[1] = b43_read32(dev, B43_MMIO_DMA1_REASON)
  1658. & 0x0000DC00;
  1659. dev->dma_reason[2] = b43_read32(dev, B43_MMIO_DMA2_REASON)
  1660. & 0x0000DC00;
  1661. dev->dma_reason[3] = b43_read32(dev, B43_MMIO_DMA3_REASON)
  1662. & 0x0001DC00;
  1663. dev->dma_reason[4] = b43_read32(dev, B43_MMIO_DMA4_REASON)
  1664. & 0x0000DC00;
  1665. /* Unused ring
  1666. dev->dma_reason[5] = b43_read32(dev, B43_MMIO_DMA5_REASON)
  1667. & 0x0000DC00;
  1668. */
  1669. b43_interrupt_ack(dev, reason);
  1670. /* disable all IRQs. They are enabled again in the bottom half. */
  1671. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, 0);
  1672. /* save the reason code and call our bottom half. */
  1673. dev->irq_reason = reason;
  1674. tasklet_schedule(&dev->isr_tasklet);
  1675. out:
  1676. mmiowb();
  1677. spin_unlock(&dev->wl->irq_lock);
  1678. return ret;
  1679. }
  1680. void b43_do_release_fw(struct b43_firmware_file *fw)
  1681. {
  1682. release_firmware(fw->data);
  1683. fw->data = NULL;
  1684. fw->filename = NULL;
  1685. }
  1686. static void b43_release_firmware(struct b43_wldev *dev)
  1687. {
  1688. b43_do_release_fw(&dev->fw.ucode);
  1689. b43_do_release_fw(&dev->fw.pcm);
  1690. b43_do_release_fw(&dev->fw.initvals);
  1691. b43_do_release_fw(&dev->fw.initvals_band);
  1692. }
  1693. static void b43_print_fw_helptext(struct b43_wl *wl, bool error)
  1694. {
  1695. const char text[] =
  1696. "You must go to " \
  1697. "http://wireless.kernel.org/en/users/Drivers/b43#devicefirmware " \
  1698. "and download the correct firmware for this driver version. " \
  1699. "Please carefully read all instructions on this website.\n";
  1700. if (error)
  1701. b43err(wl, text);
  1702. else
  1703. b43warn(wl, text);
  1704. }
  1705. int b43_do_request_fw(struct b43_request_fw_context *ctx,
  1706. const char *name,
  1707. struct b43_firmware_file *fw)
  1708. {
  1709. const struct firmware *blob;
  1710. struct b43_fw_header *hdr;
  1711. u32 size;
  1712. int err;
  1713. if (!name) {
  1714. /* Don't fetch anything. Free possibly cached firmware. */
  1715. /* FIXME: We should probably keep it anyway, to save some headache
  1716. * on suspend/resume with multiband devices. */
  1717. b43_do_release_fw(fw);
  1718. return 0;
  1719. }
  1720. if (fw->filename) {
  1721. if ((fw->type == ctx->req_type) &&
  1722. (strcmp(fw->filename, name) == 0))
  1723. return 0; /* Already have this fw. */
  1724. /* Free the cached firmware first. */
  1725. /* FIXME: We should probably do this later after we successfully
  1726. * got the new fw. This could reduce headache with multiband devices.
  1727. * We could also redesign this to cache the firmware for all possible
  1728. * bands all the time. */
  1729. b43_do_release_fw(fw);
  1730. }
  1731. switch (ctx->req_type) {
  1732. case B43_FWTYPE_PROPRIETARY:
  1733. snprintf(ctx->fwname, sizeof(ctx->fwname),
  1734. "b43%s/%s.fw",
  1735. modparam_fwpostfix, name);
  1736. break;
  1737. case B43_FWTYPE_OPENSOURCE:
  1738. snprintf(ctx->fwname, sizeof(ctx->fwname),
  1739. "b43-open%s/%s.fw",
  1740. modparam_fwpostfix, name);
  1741. break;
  1742. default:
  1743. B43_WARN_ON(1);
  1744. return -ENOSYS;
  1745. }
  1746. err = request_firmware(&blob, ctx->fwname, ctx->dev->dev->dev);
  1747. if (err == -ENOENT) {
  1748. snprintf(ctx->errors[ctx->req_type],
  1749. sizeof(ctx->errors[ctx->req_type]),
  1750. "Firmware file \"%s\" not found\n", ctx->fwname);
  1751. return err;
  1752. } else if (err) {
  1753. snprintf(ctx->errors[ctx->req_type],
  1754. sizeof(ctx->errors[ctx->req_type]),
  1755. "Firmware file \"%s\" request failed (err=%d)\n",
  1756. ctx->fwname, err);
  1757. return err;
  1758. }
  1759. if (blob->size < sizeof(struct b43_fw_header))
  1760. goto err_format;
  1761. hdr = (struct b43_fw_header *)(blob->data);
  1762. switch (hdr->type) {
  1763. case B43_FW_TYPE_UCODE:
  1764. case B43_FW_TYPE_PCM:
  1765. size = be32_to_cpu(hdr->size);
  1766. if (size != blob->size - sizeof(struct b43_fw_header))
  1767. goto err_format;
  1768. /* fallthrough */
  1769. case B43_FW_TYPE_IV:
  1770. if (hdr->ver != 1)
  1771. goto err_format;
  1772. break;
  1773. default:
  1774. goto err_format;
  1775. }
  1776. fw->data = blob;
  1777. fw->filename = name;
  1778. fw->type = ctx->req_type;
  1779. return 0;
  1780. err_format:
  1781. snprintf(ctx->errors[ctx->req_type],
  1782. sizeof(ctx->errors[ctx->req_type]),
  1783. "Firmware file \"%s\" format error.\n", ctx->fwname);
  1784. release_firmware(blob);
  1785. return -EPROTO;
  1786. }
  1787. static int b43_try_request_fw(struct b43_request_fw_context *ctx)
  1788. {
  1789. struct b43_wldev *dev = ctx->dev;
  1790. struct b43_firmware *fw = &ctx->dev->fw;
  1791. const u8 rev = ctx->dev->dev->id.revision;
  1792. const char *filename;
  1793. u32 tmshigh;
  1794. int err;
  1795. /* Get microcode */
  1796. tmshigh = ssb_read32(dev->dev, SSB_TMSHIGH);
  1797. if ((rev >= 5) && (rev <= 10))
  1798. filename = "ucode5";
  1799. else if ((rev >= 11) && (rev <= 12))
  1800. filename = "ucode11";
  1801. else if (rev >= 13)
  1802. filename = "ucode13";
  1803. else
  1804. goto err_no_ucode;
  1805. err = b43_do_request_fw(ctx, filename, &fw->ucode);
  1806. if (err)
  1807. goto err_load;
  1808. /* Get PCM code */
  1809. if ((rev >= 5) && (rev <= 10))
  1810. filename = "pcm5";
  1811. else if (rev >= 11)
  1812. filename = NULL;
  1813. else
  1814. goto err_no_pcm;
  1815. fw->pcm_request_failed = 0;
  1816. err = b43_do_request_fw(ctx, filename, &fw->pcm);
  1817. if (err == -ENOENT) {
  1818. /* We did not find a PCM file? Not fatal, but
  1819. * core rev <= 10 must do without hwcrypto then. */
  1820. fw->pcm_request_failed = 1;
  1821. } else if (err)
  1822. goto err_load;
  1823. /* Get initvals */
  1824. switch (dev->phy.type) {
  1825. case B43_PHYTYPE_A:
  1826. if ((rev >= 5) && (rev <= 10)) {
  1827. if (tmshigh & B43_TMSHIGH_HAVE_2GHZ_PHY)
  1828. filename = "a0g1initvals5";
  1829. else
  1830. filename = "a0g0initvals5";
  1831. } else
  1832. goto err_no_initvals;
  1833. break;
  1834. case B43_PHYTYPE_G:
  1835. if ((rev >= 5) && (rev <= 10))
  1836. filename = "b0g0initvals5";
  1837. else if (rev >= 13)
  1838. filename = "b0g0initvals13";
  1839. else
  1840. goto err_no_initvals;
  1841. break;
  1842. case B43_PHYTYPE_N:
  1843. if ((rev >= 11) && (rev <= 12))
  1844. filename = "n0initvals11";
  1845. else
  1846. goto err_no_initvals;
  1847. break;
  1848. default:
  1849. goto err_no_initvals;
  1850. }
  1851. err = b43_do_request_fw(ctx, filename, &fw->initvals);
  1852. if (err)
  1853. goto err_load;
  1854. /* Get bandswitch initvals */
  1855. switch (dev->phy.type) {
  1856. case B43_PHYTYPE_A:
  1857. if ((rev >= 5) && (rev <= 10)) {
  1858. if (tmshigh & B43_TMSHIGH_HAVE_2GHZ_PHY)
  1859. filename = "a0g1bsinitvals5";
  1860. else
  1861. filename = "a0g0bsinitvals5";
  1862. } else if (rev >= 11)
  1863. filename = NULL;
  1864. else
  1865. goto err_no_initvals;
  1866. break;
  1867. case B43_PHYTYPE_G:
  1868. if ((rev >= 5) && (rev <= 10))
  1869. filename = "b0g0bsinitvals5";
  1870. else if (rev >= 11)
  1871. filename = NULL;
  1872. else
  1873. goto err_no_initvals;
  1874. break;
  1875. case B43_PHYTYPE_N:
  1876. if ((rev >= 11) && (rev <= 12))
  1877. filename = "n0bsinitvals11";
  1878. else
  1879. goto err_no_initvals;
  1880. break;
  1881. default:
  1882. goto err_no_initvals;
  1883. }
  1884. err = b43_do_request_fw(ctx, filename, &fw->initvals_band);
  1885. if (err)
  1886. goto err_load;
  1887. return 0;
  1888. err_no_ucode:
  1889. err = ctx->fatal_failure = -EOPNOTSUPP;
  1890. b43err(dev->wl, "The driver does not know which firmware (ucode) "
  1891. "is required for your device (wl-core rev %u)\n", rev);
  1892. goto error;
  1893. err_no_pcm:
  1894. err = ctx->fatal_failure = -EOPNOTSUPP;
  1895. b43err(dev->wl, "The driver does not know which firmware (PCM) "
  1896. "is required for your device (wl-core rev %u)\n", rev);
  1897. goto error;
  1898. err_no_initvals:
  1899. err = ctx->fatal_failure = -EOPNOTSUPP;
  1900. b43err(dev->wl, "The driver does not know which firmware (initvals) "
  1901. "is required for your device (wl-core rev %u)\n", rev);
  1902. goto error;
  1903. err_load:
  1904. /* We failed to load this firmware image. The error message
  1905. * already is in ctx->errors. Return and let our caller decide
  1906. * what to do. */
  1907. goto error;
  1908. error:
  1909. b43_release_firmware(dev);
  1910. return err;
  1911. }
  1912. static int b43_request_firmware(struct b43_wldev *dev)
  1913. {
  1914. struct b43_request_fw_context *ctx;
  1915. unsigned int i;
  1916. int err;
  1917. const char *errmsg;
  1918. ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
  1919. if (!ctx)
  1920. return -ENOMEM;
  1921. ctx->dev = dev;
  1922. ctx->req_type = B43_FWTYPE_PROPRIETARY;
  1923. err = b43_try_request_fw(ctx);
  1924. if (!err)
  1925. goto out; /* Successfully loaded it. */
  1926. err = ctx->fatal_failure;
  1927. if (err)
  1928. goto out;
  1929. ctx->req_type = B43_FWTYPE_OPENSOURCE;
  1930. err = b43_try_request_fw(ctx);
  1931. if (!err)
  1932. goto out; /* Successfully loaded it. */
  1933. err = ctx->fatal_failure;
  1934. if (err)
  1935. goto out;
  1936. /* Could not find a usable firmware. Print the errors. */
  1937. for (i = 0; i < B43_NR_FWTYPES; i++) {
  1938. errmsg = ctx->errors[i];
  1939. if (strlen(errmsg))
  1940. b43err(dev->wl, errmsg);
  1941. }
  1942. b43_print_fw_helptext(dev->wl, 1);
  1943. err = -ENOENT;
  1944. out:
  1945. kfree(ctx);
  1946. return err;
  1947. }
  1948. static int b43_upload_microcode(struct b43_wldev *dev)
  1949. {
  1950. const size_t hdr_len = sizeof(struct b43_fw_header);
  1951. const __be32 *data;
  1952. unsigned int i, len;
  1953. u16 fwrev, fwpatch, fwdate, fwtime;
  1954. u32 tmp, macctl;
  1955. int err = 0;
  1956. /* Jump the microcode PSM to offset 0 */
  1957. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  1958. B43_WARN_ON(macctl & B43_MACCTL_PSM_RUN);
  1959. macctl |= B43_MACCTL_PSM_JMP0;
  1960. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  1961. /* Zero out all microcode PSM registers and shared memory. */
  1962. for (i = 0; i < 64; i++)
  1963. b43_shm_write16(dev, B43_SHM_SCRATCH, i, 0);
  1964. for (i = 0; i < 4096; i += 2)
  1965. b43_shm_write16(dev, B43_SHM_SHARED, i, 0);
  1966. /* Upload Microcode. */
  1967. data = (__be32 *) (dev->fw.ucode.data->data + hdr_len);
  1968. len = (dev->fw.ucode.data->size - hdr_len) / sizeof(__be32);
  1969. b43_shm_control_word(dev, B43_SHM_UCODE | B43_SHM_AUTOINC_W, 0x0000);
  1970. for (i = 0; i < len; i++) {
  1971. b43_write32(dev, B43_MMIO_SHM_DATA, be32_to_cpu(data[i]));
  1972. udelay(10);
  1973. }
  1974. if (dev->fw.pcm.data) {
  1975. /* Upload PCM data. */
  1976. data = (__be32 *) (dev->fw.pcm.data->data + hdr_len);
  1977. len = (dev->fw.pcm.data->size - hdr_len) / sizeof(__be32);
  1978. b43_shm_control_word(dev, B43_SHM_HW, 0x01EA);
  1979. b43_write32(dev, B43_MMIO_SHM_DATA, 0x00004000);
  1980. /* No need for autoinc bit in SHM_HW */
  1981. b43_shm_control_word(dev, B43_SHM_HW, 0x01EB);
  1982. for (i = 0; i < len; i++) {
  1983. b43_write32(dev, B43_MMIO_SHM_DATA, be32_to_cpu(data[i]));
  1984. udelay(10);
  1985. }
  1986. }
  1987. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, B43_IRQ_ALL);
  1988. /* Start the microcode PSM */
  1989. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  1990. macctl &= ~B43_MACCTL_PSM_JMP0;
  1991. macctl |= B43_MACCTL_PSM_RUN;
  1992. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  1993. /* Wait for the microcode to load and respond */
  1994. i = 0;
  1995. while (1) {
  1996. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  1997. if (tmp == B43_IRQ_MAC_SUSPENDED)
  1998. break;
  1999. i++;
  2000. if (i >= 20) {
  2001. b43err(dev->wl, "Microcode not responding\n");
  2002. b43_print_fw_helptext(dev->wl, 1);
  2003. err = -ENODEV;
  2004. goto error;
  2005. }
  2006. msleep_interruptible(50);
  2007. if (signal_pending(current)) {
  2008. err = -EINTR;
  2009. goto error;
  2010. }
  2011. }
  2012. b43_read32(dev, B43_MMIO_GEN_IRQ_REASON); /* dummy read */
  2013. /* Get and check the revisions. */
  2014. fwrev = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEREV);
  2015. fwpatch = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEPATCH);
  2016. fwdate = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEDATE);
  2017. fwtime = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODETIME);
  2018. if (fwrev <= 0x128) {
  2019. b43err(dev->wl, "YOUR FIRMWARE IS TOO OLD. Firmware from "
  2020. "binary drivers older than version 4.x is unsupported. "
  2021. "You must upgrade your firmware files.\n");
  2022. b43_print_fw_helptext(dev->wl, 1);
  2023. err = -EOPNOTSUPP;
  2024. goto error;
  2025. }
  2026. dev->fw.rev = fwrev;
  2027. dev->fw.patch = fwpatch;
  2028. dev->fw.opensource = (fwdate == 0xFFFF);
  2029. if (dev->fw.opensource) {
  2030. /* Patchlevel info is encoded in the "time" field. */
  2031. dev->fw.patch = fwtime;
  2032. b43info(dev->wl, "Loading OpenSource firmware version %u.%u%s\n",
  2033. dev->fw.rev, dev->fw.patch,
  2034. dev->fw.pcm_request_failed ? " (Hardware crypto not supported)" : "");
  2035. } else {
  2036. b43info(dev->wl, "Loading firmware version %u.%u "
  2037. "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n",
  2038. fwrev, fwpatch,
  2039. (fwdate >> 12) & 0xF, (fwdate >> 8) & 0xF, fwdate & 0xFF,
  2040. (fwtime >> 11) & 0x1F, (fwtime >> 5) & 0x3F, fwtime & 0x1F);
  2041. if (dev->fw.pcm_request_failed) {
  2042. b43warn(dev->wl, "No \"pcm5.fw\" firmware file found. "
  2043. "Hardware accelerated cryptography is disabled.\n");
  2044. b43_print_fw_helptext(dev->wl, 0);
  2045. }
  2046. }
  2047. if (b43_is_old_txhdr_format(dev)) {
  2048. /* We're over the deadline, but we keep support for old fw
  2049. * until it turns out to be in major conflict with something new. */
  2050. b43warn(dev->wl, "You are using an old firmware image. "
  2051. "Support for old firmware will be removed soon "
  2052. "(official deadline was July 2008).\n");
  2053. b43_print_fw_helptext(dev->wl, 0);
  2054. }
  2055. return 0;
  2056. error:
  2057. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  2058. macctl &= ~B43_MACCTL_PSM_RUN;
  2059. macctl |= B43_MACCTL_PSM_JMP0;
  2060. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  2061. return err;
  2062. }
  2063. static int b43_write_initvals(struct b43_wldev *dev,
  2064. const struct b43_iv *ivals,
  2065. size_t count,
  2066. size_t array_size)
  2067. {
  2068. const struct b43_iv *iv;
  2069. u16 offset;
  2070. size_t i;
  2071. bool bit32;
  2072. BUILD_BUG_ON(sizeof(struct b43_iv) != 6);
  2073. iv = ivals;
  2074. for (i = 0; i < count; i++) {
  2075. if (array_size < sizeof(iv->offset_size))
  2076. goto err_format;
  2077. array_size -= sizeof(iv->offset_size);
  2078. offset = be16_to_cpu(iv->offset_size);
  2079. bit32 = !!(offset & B43_IV_32BIT);
  2080. offset &= B43_IV_OFFSET_MASK;
  2081. if (offset >= 0x1000)
  2082. goto err_format;
  2083. if (bit32) {
  2084. u32 value;
  2085. if (array_size < sizeof(iv->data.d32))
  2086. goto err_format;
  2087. array_size -= sizeof(iv->data.d32);
  2088. value = get_unaligned_be32(&iv->data.d32);
  2089. b43_write32(dev, offset, value);
  2090. iv = (const struct b43_iv *)((const uint8_t *)iv +
  2091. sizeof(__be16) +
  2092. sizeof(__be32));
  2093. } else {
  2094. u16 value;
  2095. if (array_size < sizeof(iv->data.d16))
  2096. goto err_format;
  2097. array_size -= sizeof(iv->data.d16);
  2098. value = be16_to_cpu(iv->data.d16);
  2099. b43_write16(dev, offset, value);
  2100. iv = (const struct b43_iv *)((const uint8_t *)iv +
  2101. sizeof(__be16) +
  2102. sizeof(__be16));
  2103. }
  2104. }
  2105. if (array_size)
  2106. goto err_format;
  2107. return 0;
  2108. err_format:
  2109. b43err(dev->wl, "Initial Values Firmware file-format error.\n");
  2110. b43_print_fw_helptext(dev->wl, 1);
  2111. return -EPROTO;
  2112. }
  2113. static int b43_upload_initvals(struct b43_wldev *dev)
  2114. {
  2115. const size_t hdr_len = sizeof(struct b43_fw_header);
  2116. const struct b43_fw_header *hdr;
  2117. struct b43_firmware *fw = &dev->fw;
  2118. const struct b43_iv *ivals;
  2119. size_t count;
  2120. int err;
  2121. hdr = (const struct b43_fw_header *)(fw->initvals.data->data);
  2122. ivals = (const struct b43_iv *)(fw->initvals.data->data + hdr_len);
  2123. count = be32_to_cpu(hdr->size);
  2124. err = b43_write_initvals(dev, ivals, count,
  2125. fw->initvals.data->size - hdr_len);
  2126. if (err)
  2127. goto out;
  2128. if (fw->initvals_band.data) {
  2129. hdr = (const struct b43_fw_header *)(fw->initvals_band.data->data);
  2130. ivals = (const struct b43_iv *)(fw->initvals_band.data->data + hdr_len);
  2131. count = be32_to_cpu(hdr->size);
  2132. err = b43_write_initvals(dev, ivals, count,
  2133. fw->initvals_band.data->size - hdr_len);
  2134. if (err)
  2135. goto out;
  2136. }
  2137. out:
  2138. return err;
  2139. }
  2140. /* Initialize the GPIOs
  2141. * http://bcm-specs.sipsolutions.net/GPIO
  2142. */
  2143. static int b43_gpio_init(struct b43_wldev *dev)
  2144. {
  2145. struct ssb_bus *bus = dev->dev->bus;
  2146. struct ssb_device *gpiodev, *pcidev = NULL;
  2147. u32 mask, set;
  2148. b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL)
  2149. & ~B43_MACCTL_GPOUTSMSK);
  2150. b43_write16(dev, B43_MMIO_GPIO_MASK, b43_read16(dev, B43_MMIO_GPIO_MASK)
  2151. | 0x000F);
  2152. mask = 0x0000001F;
  2153. set = 0x0000000F;
  2154. if (dev->dev->bus->chip_id == 0x4301) {
  2155. mask |= 0x0060;
  2156. set |= 0x0060;
  2157. }
  2158. if (0 /* FIXME: conditional unknown */ ) {
  2159. b43_write16(dev, B43_MMIO_GPIO_MASK,
  2160. b43_read16(dev, B43_MMIO_GPIO_MASK)
  2161. | 0x0100);
  2162. mask |= 0x0180;
  2163. set |= 0x0180;
  2164. }
  2165. if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_PACTRL) {
  2166. b43_write16(dev, B43_MMIO_GPIO_MASK,
  2167. b43_read16(dev, B43_MMIO_GPIO_MASK)
  2168. | 0x0200);
  2169. mask |= 0x0200;
  2170. set |= 0x0200;
  2171. }
  2172. if (dev->dev->id.revision >= 2)
  2173. mask |= 0x0010; /* FIXME: This is redundant. */
  2174. #ifdef CONFIG_SSB_DRIVER_PCICORE
  2175. pcidev = bus->pcicore.dev;
  2176. #endif
  2177. gpiodev = bus->chipco.dev ? : pcidev;
  2178. if (!gpiodev)
  2179. return 0;
  2180. ssb_write32(gpiodev, B43_GPIO_CONTROL,
  2181. (ssb_read32(gpiodev, B43_GPIO_CONTROL)
  2182. & mask) | set);
  2183. return 0;
  2184. }
  2185. /* Turn off all GPIO stuff. Call this on module unload, for example. */
  2186. static void b43_gpio_cleanup(struct b43_wldev *dev)
  2187. {
  2188. struct ssb_bus *bus = dev->dev->bus;
  2189. struct ssb_device *gpiodev, *pcidev = NULL;
  2190. #ifdef CONFIG_SSB_DRIVER_PCICORE
  2191. pcidev = bus->pcicore.dev;
  2192. #endif
  2193. gpiodev = bus->chipco.dev ? : pcidev;
  2194. if (!gpiodev)
  2195. return;
  2196. ssb_write32(gpiodev, B43_GPIO_CONTROL, 0);
  2197. }
  2198. /* http://bcm-specs.sipsolutions.net/EnableMac */
  2199. void b43_mac_enable(struct b43_wldev *dev)
  2200. {
  2201. if (b43_debug(dev, B43_DBG_FIRMWARE)) {
  2202. u16 fwstate;
  2203. fwstate = b43_shm_read16(dev, B43_SHM_SHARED,
  2204. B43_SHM_SH_UCODESTAT);
  2205. if ((fwstate != B43_SHM_SH_UCODESTAT_SUSP) &&
  2206. (fwstate != B43_SHM_SH_UCODESTAT_SLEEP)) {
  2207. b43err(dev->wl, "b43_mac_enable(): The firmware "
  2208. "should be suspended, but current state is %u\n",
  2209. fwstate);
  2210. }
  2211. }
  2212. dev->mac_suspended--;
  2213. B43_WARN_ON(dev->mac_suspended < 0);
  2214. if (dev->mac_suspended == 0) {
  2215. b43_write32(dev, B43_MMIO_MACCTL,
  2216. b43_read32(dev, B43_MMIO_MACCTL)
  2217. | B43_MACCTL_ENABLED);
  2218. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON,
  2219. B43_IRQ_MAC_SUSPENDED);
  2220. /* Commit writes */
  2221. b43_read32(dev, B43_MMIO_MACCTL);
  2222. b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2223. b43_power_saving_ctl_bits(dev, 0);
  2224. }
  2225. }
  2226. /* http://bcm-specs.sipsolutions.net/SuspendMAC */
  2227. void b43_mac_suspend(struct b43_wldev *dev)
  2228. {
  2229. int i;
  2230. u32 tmp;
  2231. might_sleep();
  2232. B43_WARN_ON(dev->mac_suspended < 0);
  2233. if (dev->mac_suspended == 0) {
  2234. b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
  2235. b43_write32(dev, B43_MMIO_MACCTL,
  2236. b43_read32(dev, B43_MMIO_MACCTL)
  2237. & ~B43_MACCTL_ENABLED);
  2238. /* force pci to flush the write */
  2239. b43_read32(dev, B43_MMIO_MACCTL);
  2240. for (i = 35; i; i--) {
  2241. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2242. if (tmp & B43_IRQ_MAC_SUSPENDED)
  2243. goto out;
  2244. udelay(10);
  2245. }
  2246. /* Hm, it seems this will take some time. Use msleep(). */
  2247. for (i = 40; i; i--) {
  2248. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2249. if (tmp & B43_IRQ_MAC_SUSPENDED)
  2250. goto out;
  2251. msleep(1);
  2252. }
  2253. b43err(dev->wl, "MAC suspend failed\n");
  2254. }
  2255. out:
  2256. dev->mac_suspended++;
  2257. }
  2258. static void b43_adjust_opmode(struct b43_wldev *dev)
  2259. {
  2260. struct b43_wl *wl = dev->wl;
  2261. u32 ctl;
  2262. u16 cfp_pretbtt;
  2263. ctl = b43_read32(dev, B43_MMIO_MACCTL);
  2264. /* Reset status to STA infrastructure mode. */
  2265. ctl &= ~B43_MACCTL_AP;
  2266. ctl &= ~B43_MACCTL_KEEP_CTL;
  2267. ctl &= ~B43_MACCTL_KEEP_BADPLCP;
  2268. ctl &= ~B43_MACCTL_KEEP_BAD;
  2269. ctl &= ~B43_MACCTL_PROMISC;
  2270. ctl &= ~B43_MACCTL_BEACPROMISC;
  2271. ctl |= B43_MACCTL_INFRA;
  2272. if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
  2273. b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT))
  2274. ctl |= B43_MACCTL_AP;
  2275. else if (b43_is_mode(wl, NL80211_IFTYPE_ADHOC))
  2276. ctl &= ~B43_MACCTL_INFRA;
  2277. if (wl->filter_flags & FIF_CONTROL)
  2278. ctl |= B43_MACCTL_KEEP_CTL;
  2279. if (wl->filter_flags & FIF_FCSFAIL)
  2280. ctl |= B43_MACCTL_KEEP_BAD;
  2281. if (wl->filter_flags & FIF_PLCPFAIL)
  2282. ctl |= B43_MACCTL_KEEP_BADPLCP;
  2283. if (wl->filter_flags & FIF_PROMISC_IN_BSS)
  2284. ctl |= B43_MACCTL_PROMISC;
  2285. if (wl->filter_flags & FIF_BCN_PRBRESP_PROMISC)
  2286. ctl |= B43_MACCTL_BEACPROMISC;
  2287. /* Workaround: On old hardware the HW-MAC-address-filter
  2288. * doesn't work properly, so always run promisc in filter
  2289. * it in software. */
  2290. if (dev->dev->id.revision <= 4)
  2291. ctl |= B43_MACCTL_PROMISC;
  2292. b43_write32(dev, B43_MMIO_MACCTL, ctl);
  2293. cfp_pretbtt = 2;
  2294. if ((ctl & B43_MACCTL_INFRA) && !(ctl & B43_MACCTL_AP)) {
  2295. if (dev->dev->bus->chip_id == 0x4306 &&
  2296. dev->dev->bus->chip_rev == 3)
  2297. cfp_pretbtt = 100;
  2298. else
  2299. cfp_pretbtt = 50;
  2300. }
  2301. b43_write16(dev, 0x612, cfp_pretbtt);
  2302. }
  2303. static void b43_rate_memory_write(struct b43_wldev *dev, u16 rate, int is_ofdm)
  2304. {
  2305. u16 offset;
  2306. if (is_ofdm) {
  2307. offset = 0x480;
  2308. offset += (b43_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
  2309. } else {
  2310. offset = 0x4C0;
  2311. offset += (b43_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
  2312. }
  2313. b43_shm_write16(dev, B43_SHM_SHARED, offset + 0x20,
  2314. b43_shm_read16(dev, B43_SHM_SHARED, offset));
  2315. }
  2316. static void b43_rate_memory_init(struct b43_wldev *dev)
  2317. {
  2318. switch (dev->phy.type) {
  2319. case B43_PHYTYPE_A:
  2320. case B43_PHYTYPE_G:
  2321. case B43_PHYTYPE_N:
  2322. b43_rate_memory_write(dev, B43_OFDM_RATE_6MB, 1);
  2323. b43_rate_memory_write(dev, B43_OFDM_RATE_12MB, 1);
  2324. b43_rate_memory_write(dev, B43_OFDM_RATE_18MB, 1);
  2325. b43_rate_memory_write(dev, B43_OFDM_RATE_24MB, 1);
  2326. b43_rate_memory_write(dev, B43_OFDM_RATE_36MB, 1);
  2327. b43_rate_memory_write(dev, B43_OFDM_RATE_48MB, 1);
  2328. b43_rate_memory_write(dev, B43_OFDM_RATE_54MB, 1);
  2329. if (dev->phy.type == B43_PHYTYPE_A)
  2330. break;
  2331. /* fallthrough */
  2332. case B43_PHYTYPE_B:
  2333. b43_rate_memory_write(dev, B43_CCK_RATE_1MB, 0);
  2334. b43_rate_memory_write(dev, B43_CCK_RATE_2MB, 0);
  2335. b43_rate_memory_write(dev, B43_CCK_RATE_5MB, 0);
  2336. b43_rate_memory_write(dev, B43_CCK_RATE_11MB, 0);
  2337. break;
  2338. default:
  2339. B43_WARN_ON(1);
  2340. }
  2341. }
  2342. /* Set the default values for the PHY TX Control Words. */
  2343. static void b43_set_phytxctl_defaults(struct b43_wldev *dev)
  2344. {
  2345. u16 ctl = 0;
  2346. ctl |= B43_TXH_PHY_ENC_CCK;
  2347. ctl |= B43_TXH_PHY_ANT01AUTO;
  2348. ctl |= B43_TXH_PHY_TXPWR;
  2349. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL, ctl);
  2350. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL, ctl);
  2351. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL, ctl);
  2352. }
  2353. /* Set the TX-Antenna for management frames sent by firmware. */
  2354. static void b43_mgmtframe_txantenna(struct b43_wldev *dev, int antenna)
  2355. {
  2356. u16 ant;
  2357. u16 tmp;
  2358. ant = b43_antenna_to_phyctl(antenna);
  2359. /* For ACK/CTS */
  2360. tmp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL);
  2361. tmp = (tmp & ~B43_TXH_PHY_ANT) | ant;
  2362. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL, tmp);
  2363. /* For Probe Resposes */
  2364. tmp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL);
  2365. tmp = (tmp & ~B43_TXH_PHY_ANT) | ant;
  2366. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL, tmp);
  2367. }
  2368. /* This is the opposite of b43_chip_init() */
  2369. static void b43_chip_exit(struct b43_wldev *dev)
  2370. {
  2371. b43_phy_exit(dev);
  2372. b43_gpio_cleanup(dev);
  2373. /* firmware is released later */
  2374. }
  2375. /* Initialize the chip
  2376. * http://bcm-specs.sipsolutions.net/ChipInit
  2377. */
  2378. static int b43_chip_init(struct b43_wldev *dev)
  2379. {
  2380. struct b43_phy *phy = &dev->phy;
  2381. int err;
  2382. u32 value32, macctl;
  2383. u16 value16;
  2384. /* Initialize the MAC control */
  2385. macctl = B43_MACCTL_IHR_ENABLED | B43_MACCTL_SHM_ENABLED;
  2386. if (dev->phy.gmode)
  2387. macctl |= B43_MACCTL_GMODE;
  2388. macctl |= B43_MACCTL_INFRA;
  2389. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  2390. err = b43_request_firmware(dev);
  2391. if (err)
  2392. goto out;
  2393. err = b43_upload_microcode(dev);
  2394. if (err)
  2395. goto out; /* firmware is released later */
  2396. err = b43_gpio_init(dev);
  2397. if (err)
  2398. goto out; /* firmware is released later */
  2399. err = b43_upload_initvals(dev);
  2400. if (err)
  2401. goto err_gpio_clean;
  2402. /* Turn the Analog on and initialize the PHY. */
  2403. phy->ops->switch_analog(dev, 1);
  2404. err = b43_phy_init(dev);
  2405. if (err)
  2406. goto err_gpio_clean;
  2407. /* Disable Interference Mitigation. */
  2408. if (phy->ops->interf_mitigation)
  2409. phy->ops->interf_mitigation(dev, B43_INTERFMODE_NONE);
  2410. /* Select the antennae */
  2411. if (phy->ops->set_rx_antenna)
  2412. phy->ops->set_rx_antenna(dev, B43_ANTENNA_DEFAULT);
  2413. b43_mgmtframe_txantenna(dev, B43_ANTENNA_DEFAULT);
  2414. if (phy->type == B43_PHYTYPE_B) {
  2415. value16 = b43_read16(dev, 0x005E);
  2416. value16 |= 0x0004;
  2417. b43_write16(dev, 0x005E, value16);
  2418. }
  2419. b43_write32(dev, 0x0100, 0x01000000);
  2420. if (dev->dev->id.revision < 5)
  2421. b43_write32(dev, 0x010C, 0x01000000);
  2422. b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL)
  2423. & ~B43_MACCTL_INFRA);
  2424. b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL)
  2425. | B43_MACCTL_INFRA);
  2426. /* Probe Response Timeout value */
  2427. /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
  2428. b43_shm_write16(dev, B43_SHM_SHARED, 0x0074, 0x0000);
  2429. /* Initially set the wireless operation mode. */
  2430. b43_adjust_opmode(dev);
  2431. if (dev->dev->id.revision < 3) {
  2432. b43_write16(dev, 0x060E, 0x0000);
  2433. b43_write16(dev, 0x0610, 0x8000);
  2434. b43_write16(dev, 0x0604, 0x0000);
  2435. b43_write16(dev, 0x0606, 0x0200);
  2436. } else {
  2437. b43_write32(dev, 0x0188, 0x80000000);
  2438. b43_write32(dev, 0x018C, 0x02000000);
  2439. }
  2440. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, 0x00004000);
  2441. b43_write32(dev, B43_MMIO_DMA0_IRQ_MASK, 0x0001DC00);
  2442. b43_write32(dev, B43_MMIO_DMA1_IRQ_MASK, 0x0000DC00);
  2443. b43_write32(dev, B43_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
  2444. b43_write32(dev, B43_MMIO_DMA3_IRQ_MASK, 0x0001DC00);
  2445. b43_write32(dev, B43_MMIO_DMA4_IRQ_MASK, 0x0000DC00);
  2446. b43_write32(dev, B43_MMIO_DMA5_IRQ_MASK, 0x0000DC00);
  2447. value32 = ssb_read32(dev->dev, SSB_TMSLOW);
  2448. value32 |= 0x00100000;
  2449. ssb_write32(dev->dev, SSB_TMSLOW, value32);
  2450. b43_write16(dev, B43_MMIO_POWERUP_DELAY,
  2451. dev->dev->bus->chipco.fast_pwrup_delay);
  2452. err = 0;
  2453. b43dbg(dev->wl, "Chip initialized\n");
  2454. out:
  2455. return err;
  2456. err_gpio_clean:
  2457. b43_gpio_cleanup(dev);
  2458. return err;
  2459. }
  2460. static void b43_periodic_every60sec(struct b43_wldev *dev)
  2461. {
  2462. const struct b43_phy_operations *ops = dev->phy.ops;
  2463. if (ops->pwork_60sec)
  2464. ops->pwork_60sec(dev);
  2465. /* Force check the TX power emission now. */
  2466. b43_phy_txpower_check(dev, B43_TXPWR_IGNORE_TIME);
  2467. }
  2468. static void b43_periodic_every30sec(struct b43_wldev *dev)
  2469. {
  2470. /* Update device statistics. */
  2471. b43_calculate_link_quality(dev);
  2472. }
  2473. static void b43_periodic_every15sec(struct b43_wldev *dev)
  2474. {
  2475. struct b43_phy *phy = &dev->phy;
  2476. u16 wdr;
  2477. if (dev->fw.opensource) {
  2478. /* Check if the firmware is still alive.
  2479. * It will reset the watchdog counter to 0 in its idle loop. */
  2480. wdr = b43_shm_read16(dev, B43_SHM_SCRATCH, B43_WATCHDOG_REG);
  2481. if (unlikely(wdr)) {
  2482. b43err(dev->wl, "Firmware watchdog: The firmware died!\n");
  2483. b43_controller_restart(dev, "Firmware watchdog");
  2484. return;
  2485. } else {
  2486. b43_shm_write16(dev, B43_SHM_SCRATCH,
  2487. B43_WATCHDOG_REG, 1);
  2488. }
  2489. }
  2490. if (phy->ops->pwork_15sec)
  2491. phy->ops->pwork_15sec(dev);
  2492. atomic_set(&phy->txerr_cnt, B43_PHY_TX_BADNESS_LIMIT);
  2493. wmb();
  2494. }
  2495. static void do_periodic_work(struct b43_wldev *dev)
  2496. {
  2497. unsigned int state;
  2498. state = dev->periodic_state;
  2499. if (state % 4 == 0)
  2500. b43_periodic_every60sec(dev);
  2501. if (state % 2 == 0)
  2502. b43_periodic_every30sec(dev);
  2503. b43_periodic_every15sec(dev);
  2504. }
  2505. /* Periodic work locking policy:
  2506. * The whole periodic work handler is protected by
  2507. * wl->mutex. If another lock is needed somewhere in the
  2508. * pwork callchain, it's aquired in-place, where it's needed.
  2509. */
  2510. static void b43_periodic_work_handler(struct work_struct *work)
  2511. {
  2512. struct b43_wldev *dev = container_of(work, struct b43_wldev,
  2513. periodic_work.work);
  2514. struct b43_wl *wl = dev->wl;
  2515. unsigned long delay;
  2516. mutex_lock(&wl->mutex);
  2517. if (unlikely(b43_status(dev) != B43_STAT_STARTED))
  2518. goto out;
  2519. if (b43_debug(dev, B43_DBG_PWORK_STOP))
  2520. goto out_requeue;
  2521. do_periodic_work(dev);
  2522. dev->periodic_state++;
  2523. out_requeue:
  2524. if (b43_debug(dev, B43_DBG_PWORK_FAST))
  2525. delay = msecs_to_jiffies(50);
  2526. else
  2527. delay = round_jiffies_relative(HZ * 15);
  2528. queue_delayed_work(wl->hw->workqueue, &dev->periodic_work, delay);
  2529. out:
  2530. mutex_unlock(&wl->mutex);
  2531. }
  2532. static void b43_periodic_tasks_setup(struct b43_wldev *dev)
  2533. {
  2534. struct delayed_work *work = &dev->periodic_work;
  2535. dev->periodic_state = 0;
  2536. INIT_DELAYED_WORK(work, b43_periodic_work_handler);
  2537. queue_delayed_work(dev->wl->hw->workqueue, work, 0);
  2538. }
  2539. /* Check if communication with the device works correctly. */
  2540. static int b43_validate_chipaccess(struct b43_wldev *dev)
  2541. {
  2542. u32 v, backup;
  2543. backup = b43_shm_read32(dev, B43_SHM_SHARED, 0);
  2544. /* Check for read/write and endianness problems. */
  2545. b43_shm_write32(dev, B43_SHM_SHARED, 0, 0x55AAAA55);
  2546. if (b43_shm_read32(dev, B43_SHM_SHARED, 0) != 0x55AAAA55)
  2547. goto error;
  2548. b43_shm_write32(dev, B43_SHM_SHARED, 0, 0xAA5555AA);
  2549. if (b43_shm_read32(dev, B43_SHM_SHARED, 0) != 0xAA5555AA)
  2550. goto error;
  2551. b43_shm_write32(dev, B43_SHM_SHARED, 0, backup);
  2552. if ((dev->dev->id.revision >= 3) && (dev->dev->id.revision <= 10)) {
  2553. /* The 32bit register shadows the two 16bit registers
  2554. * with update sideeffects. Validate this. */
  2555. b43_write16(dev, B43_MMIO_TSF_CFP_START, 0xAAAA);
  2556. b43_write32(dev, B43_MMIO_TSF_CFP_START, 0xCCCCBBBB);
  2557. if (b43_read16(dev, B43_MMIO_TSF_CFP_START_LOW) != 0xBBBB)
  2558. goto error;
  2559. if (b43_read16(dev, B43_MMIO_TSF_CFP_START_HIGH) != 0xCCCC)
  2560. goto error;
  2561. }
  2562. b43_write32(dev, B43_MMIO_TSF_CFP_START, 0);
  2563. v = b43_read32(dev, B43_MMIO_MACCTL);
  2564. v |= B43_MACCTL_GMODE;
  2565. if (v != (B43_MACCTL_GMODE | B43_MACCTL_IHR_ENABLED))
  2566. goto error;
  2567. return 0;
  2568. error:
  2569. b43err(dev->wl, "Failed to validate the chipaccess\n");
  2570. return -ENODEV;
  2571. }
  2572. static void b43_security_init(struct b43_wldev *dev)
  2573. {
  2574. dev->max_nr_keys = (dev->dev->id.revision >= 5) ? 58 : 20;
  2575. B43_WARN_ON(dev->max_nr_keys > ARRAY_SIZE(dev->key));
  2576. dev->ktp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_KTP);
  2577. /* KTP is a word address, but we address SHM bytewise.
  2578. * So multiply by two.
  2579. */
  2580. dev->ktp *= 2;
  2581. if (dev->dev->id.revision >= 5) {
  2582. /* Number of RCMTA address slots */
  2583. b43_write16(dev, B43_MMIO_RCMTA_COUNT, dev->max_nr_keys - 8);
  2584. }
  2585. b43_clear_keys(dev);
  2586. }
  2587. #ifdef CONFIG_B43_HWRNG
  2588. static int b43_rng_read(struct hwrng *rng, u32 *data)
  2589. {
  2590. struct b43_wl *wl = (struct b43_wl *)rng->priv;
  2591. unsigned long flags;
  2592. /* Don't take wl->mutex here, as it could deadlock with
  2593. * hwrng internal locking. It's not needed to take
  2594. * wl->mutex here, anyway. */
  2595. spin_lock_irqsave(&wl->irq_lock, flags);
  2596. *data = b43_read16(wl->current_dev, B43_MMIO_RNG);
  2597. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2598. return (sizeof(u16));
  2599. }
  2600. #endif /* CONFIG_B43_HWRNG */
  2601. static void b43_rng_exit(struct b43_wl *wl)
  2602. {
  2603. #ifdef CONFIG_B43_HWRNG
  2604. if (wl->rng_initialized)
  2605. hwrng_unregister(&wl->rng);
  2606. #endif /* CONFIG_B43_HWRNG */
  2607. }
  2608. static int b43_rng_init(struct b43_wl *wl)
  2609. {
  2610. int err = 0;
  2611. #ifdef CONFIG_B43_HWRNG
  2612. snprintf(wl->rng_name, ARRAY_SIZE(wl->rng_name),
  2613. "%s_%s", KBUILD_MODNAME, wiphy_name(wl->hw->wiphy));
  2614. wl->rng.name = wl->rng_name;
  2615. wl->rng.data_read = b43_rng_read;
  2616. wl->rng.priv = (unsigned long)wl;
  2617. wl->rng_initialized = 1;
  2618. err = hwrng_register(&wl->rng);
  2619. if (err) {
  2620. wl->rng_initialized = 0;
  2621. b43err(wl, "Failed to register the random "
  2622. "number generator (%d)\n", err);
  2623. }
  2624. #endif /* CONFIG_B43_HWRNG */
  2625. return err;
  2626. }
  2627. static int b43_op_tx(struct ieee80211_hw *hw,
  2628. struct sk_buff *skb)
  2629. {
  2630. struct b43_wl *wl = hw_to_b43_wl(hw);
  2631. struct b43_wldev *dev = wl->current_dev;
  2632. unsigned long flags;
  2633. int err;
  2634. if (unlikely(skb->len < 2 + 2 + 6)) {
  2635. /* Too short, this can't be a valid frame. */
  2636. goto drop_packet;
  2637. }
  2638. B43_WARN_ON(skb_shinfo(skb)->nr_frags);
  2639. if (unlikely(!dev))
  2640. goto drop_packet;
  2641. /* Transmissions on seperate queues can run concurrently. */
  2642. read_lock_irqsave(&wl->tx_lock, flags);
  2643. err = -ENODEV;
  2644. if (likely(b43_status(dev) >= B43_STAT_STARTED)) {
  2645. if (b43_using_pio_transfers(dev))
  2646. err = b43_pio_tx(dev, skb);
  2647. else
  2648. err = b43_dma_tx(dev, skb);
  2649. }
  2650. read_unlock_irqrestore(&wl->tx_lock, flags);
  2651. if (unlikely(err))
  2652. goto drop_packet;
  2653. return NETDEV_TX_OK;
  2654. drop_packet:
  2655. /* We can not transmit this packet. Drop it. */
  2656. dev_kfree_skb_any(skb);
  2657. return NETDEV_TX_OK;
  2658. }
  2659. /* Locking: wl->irq_lock */
  2660. static void b43_qos_params_upload(struct b43_wldev *dev,
  2661. const struct ieee80211_tx_queue_params *p,
  2662. u16 shm_offset)
  2663. {
  2664. u16 params[B43_NR_QOSPARAMS];
  2665. int bslots, tmp;
  2666. unsigned int i;
  2667. bslots = b43_read16(dev, B43_MMIO_RNG) & p->cw_min;
  2668. memset(&params, 0, sizeof(params));
  2669. params[B43_QOSPARAM_TXOP] = p->txop * 32;
  2670. params[B43_QOSPARAM_CWMIN] = p->cw_min;
  2671. params[B43_QOSPARAM_CWMAX] = p->cw_max;
  2672. params[B43_QOSPARAM_CWCUR] = p->cw_min;
  2673. params[B43_QOSPARAM_AIFS] = p->aifs;
  2674. params[B43_QOSPARAM_BSLOTS] = bslots;
  2675. params[B43_QOSPARAM_REGGAP] = bslots + p->aifs;
  2676. for (i = 0; i < ARRAY_SIZE(params); i++) {
  2677. if (i == B43_QOSPARAM_STATUS) {
  2678. tmp = b43_shm_read16(dev, B43_SHM_SHARED,
  2679. shm_offset + (i * 2));
  2680. /* Mark the parameters as updated. */
  2681. tmp |= 0x100;
  2682. b43_shm_write16(dev, B43_SHM_SHARED,
  2683. shm_offset + (i * 2),
  2684. tmp);
  2685. } else {
  2686. b43_shm_write16(dev, B43_SHM_SHARED,
  2687. shm_offset + (i * 2),
  2688. params[i]);
  2689. }
  2690. }
  2691. }
  2692. /* Mapping of mac80211 queue numbers to b43 QoS SHM offsets. */
  2693. static const u16 b43_qos_shm_offsets[] = {
  2694. /* [mac80211-queue-nr] = SHM_OFFSET, */
  2695. [0] = B43_QOS_VOICE,
  2696. [1] = B43_QOS_VIDEO,
  2697. [2] = B43_QOS_BESTEFFORT,
  2698. [3] = B43_QOS_BACKGROUND,
  2699. };
  2700. /* Update all QOS parameters in hardware. */
  2701. static void b43_qos_upload_all(struct b43_wldev *dev)
  2702. {
  2703. struct b43_wl *wl = dev->wl;
  2704. struct b43_qos_params *params;
  2705. unsigned int i;
  2706. BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
  2707. ARRAY_SIZE(wl->qos_params));
  2708. b43_mac_suspend(dev);
  2709. for (i = 0; i < ARRAY_SIZE(wl->qos_params); i++) {
  2710. params = &(wl->qos_params[i]);
  2711. b43_qos_params_upload(dev, &(params->p),
  2712. b43_qos_shm_offsets[i]);
  2713. }
  2714. b43_mac_enable(dev);
  2715. }
  2716. static void b43_qos_clear(struct b43_wl *wl)
  2717. {
  2718. struct b43_qos_params *params;
  2719. unsigned int i;
  2720. /* Initialize QoS parameters to sane defaults. */
  2721. BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
  2722. ARRAY_SIZE(wl->qos_params));
  2723. for (i = 0; i < ARRAY_SIZE(wl->qos_params); i++) {
  2724. params = &(wl->qos_params[i]);
  2725. switch (b43_qos_shm_offsets[i]) {
  2726. case B43_QOS_VOICE:
  2727. params->p.txop = 0;
  2728. params->p.aifs = 2;
  2729. params->p.cw_min = 0x0001;
  2730. params->p.cw_max = 0x0001;
  2731. break;
  2732. case B43_QOS_VIDEO:
  2733. params->p.txop = 0;
  2734. params->p.aifs = 2;
  2735. params->p.cw_min = 0x0001;
  2736. params->p.cw_max = 0x0001;
  2737. break;
  2738. case B43_QOS_BESTEFFORT:
  2739. params->p.txop = 0;
  2740. params->p.aifs = 3;
  2741. params->p.cw_min = 0x0001;
  2742. params->p.cw_max = 0x03FF;
  2743. break;
  2744. case B43_QOS_BACKGROUND:
  2745. params->p.txop = 0;
  2746. params->p.aifs = 7;
  2747. params->p.cw_min = 0x0001;
  2748. params->p.cw_max = 0x03FF;
  2749. break;
  2750. default:
  2751. B43_WARN_ON(1);
  2752. }
  2753. }
  2754. }
  2755. /* Initialize the core's QOS capabilities */
  2756. static void b43_qos_init(struct b43_wldev *dev)
  2757. {
  2758. /* Upload the current QOS parameters. */
  2759. b43_qos_upload_all(dev);
  2760. /* Enable QOS support. */
  2761. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF);
  2762. b43_write16(dev, B43_MMIO_IFSCTL,
  2763. b43_read16(dev, B43_MMIO_IFSCTL)
  2764. | B43_MMIO_IFSCTL_USE_EDCF);
  2765. }
  2766. static int b43_op_conf_tx(struct ieee80211_hw *hw, u16 _queue,
  2767. const struct ieee80211_tx_queue_params *params)
  2768. {
  2769. struct b43_wl *wl = hw_to_b43_wl(hw);
  2770. struct b43_wldev *dev;
  2771. unsigned int queue = (unsigned int)_queue;
  2772. int err = -ENODEV;
  2773. if (queue >= ARRAY_SIZE(wl->qos_params)) {
  2774. /* Queue not available or don't support setting
  2775. * params on this queue. Return success to not
  2776. * confuse mac80211. */
  2777. return 0;
  2778. }
  2779. BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
  2780. ARRAY_SIZE(wl->qos_params));
  2781. mutex_lock(&wl->mutex);
  2782. dev = wl->current_dev;
  2783. if (unlikely(!dev || (b43_status(dev) < B43_STAT_INITIALIZED)))
  2784. goto out_unlock;
  2785. memcpy(&(wl->qos_params[queue].p), params, sizeof(*params));
  2786. b43_mac_suspend(dev);
  2787. b43_qos_params_upload(dev, &(wl->qos_params[queue].p),
  2788. b43_qos_shm_offsets[queue]);
  2789. b43_mac_enable(dev);
  2790. err = 0;
  2791. out_unlock:
  2792. mutex_unlock(&wl->mutex);
  2793. return err;
  2794. }
  2795. static int b43_op_get_tx_stats(struct ieee80211_hw *hw,
  2796. struct ieee80211_tx_queue_stats *stats)
  2797. {
  2798. struct b43_wl *wl = hw_to_b43_wl(hw);
  2799. struct b43_wldev *dev = wl->current_dev;
  2800. unsigned long flags;
  2801. int err = -ENODEV;
  2802. if (!dev)
  2803. goto out;
  2804. spin_lock_irqsave(&wl->irq_lock, flags);
  2805. if (likely(b43_status(dev) >= B43_STAT_STARTED)) {
  2806. if (b43_using_pio_transfers(dev))
  2807. b43_pio_get_tx_stats(dev, stats);
  2808. else
  2809. b43_dma_get_tx_stats(dev, stats);
  2810. err = 0;
  2811. }
  2812. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2813. out:
  2814. return err;
  2815. }
  2816. static int b43_op_get_stats(struct ieee80211_hw *hw,
  2817. struct ieee80211_low_level_stats *stats)
  2818. {
  2819. struct b43_wl *wl = hw_to_b43_wl(hw);
  2820. unsigned long flags;
  2821. spin_lock_irqsave(&wl->irq_lock, flags);
  2822. memcpy(stats, &wl->ieee_stats, sizeof(*stats));
  2823. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2824. return 0;
  2825. }
  2826. static u64 b43_op_get_tsf(struct ieee80211_hw *hw)
  2827. {
  2828. struct b43_wl *wl = hw_to_b43_wl(hw);
  2829. struct b43_wldev *dev;
  2830. u64 tsf;
  2831. mutex_lock(&wl->mutex);
  2832. spin_lock_irq(&wl->irq_lock);
  2833. dev = wl->current_dev;
  2834. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED))
  2835. b43_tsf_read(dev, &tsf);
  2836. else
  2837. tsf = 0;
  2838. spin_unlock_irq(&wl->irq_lock);
  2839. mutex_unlock(&wl->mutex);
  2840. return tsf;
  2841. }
  2842. static void b43_op_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  2843. {
  2844. struct b43_wl *wl = hw_to_b43_wl(hw);
  2845. struct b43_wldev *dev;
  2846. mutex_lock(&wl->mutex);
  2847. spin_lock_irq(&wl->irq_lock);
  2848. dev = wl->current_dev;
  2849. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED))
  2850. b43_tsf_write(dev, tsf);
  2851. spin_unlock_irq(&wl->irq_lock);
  2852. mutex_unlock(&wl->mutex);
  2853. }
  2854. static void b43_put_phy_into_reset(struct b43_wldev *dev)
  2855. {
  2856. struct ssb_device *sdev = dev->dev;
  2857. u32 tmslow;
  2858. tmslow = ssb_read32(sdev, SSB_TMSLOW);
  2859. tmslow &= ~B43_TMSLOW_GMODE;
  2860. tmslow |= B43_TMSLOW_PHYRESET;
  2861. tmslow |= SSB_TMSLOW_FGC;
  2862. ssb_write32(sdev, SSB_TMSLOW, tmslow);
  2863. msleep(1);
  2864. tmslow = ssb_read32(sdev, SSB_TMSLOW);
  2865. tmslow &= ~SSB_TMSLOW_FGC;
  2866. tmslow |= B43_TMSLOW_PHYRESET;
  2867. ssb_write32(sdev, SSB_TMSLOW, tmslow);
  2868. msleep(1);
  2869. }
  2870. static const char *band_to_string(enum ieee80211_band band)
  2871. {
  2872. switch (band) {
  2873. case IEEE80211_BAND_5GHZ:
  2874. return "5";
  2875. case IEEE80211_BAND_2GHZ:
  2876. return "2.4";
  2877. default:
  2878. break;
  2879. }
  2880. B43_WARN_ON(1);
  2881. return "";
  2882. }
  2883. /* Expects wl->mutex locked */
  2884. static int b43_switch_band(struct b43_wl *wl, struct ieee80211_channel *chan)
  2885. {
  2886. struct b43_wldev *up_dev = NULL;
  2887. struct b43_wldev *down_dev;
  2888. struct b43_wldev *d;
  2889. int err;
  2890. bool uninitialized_var(gmode);
  2891. int prev_status;
  2892. /* Find a device and PHY which supports the band. */
  2893. list_for_each_entry(d, &wl->devlist, list) {
  2894. switch (chan->band) {
  2895. case IEEE80211_BAND_5GHZ:
  2896. if (d->phy.supports_5ghz) {
  2897. up_dev = d;
  2898. gmode = 0;
  2899. }
  2900. break;
  2901. case IEEE80211_BAND_2GHZ:
  2902. if (d->phy.supports_2ghz) {
  2903. up_dev = d;
  2904. gmode = 1;
  2905. }
  2906. break;
  2907. default:
  2908. B43_WARN_ON(1);
  2909. return -EINVAL;
  2910. }
  2911. if (up_dev)
  2912. break;
  2913. }
  2914. if (!up_dev) {
  2915. b43err(wl, "Could not find a device for %s-GHz band operation\n",
  2916. band_to_string(chan->band));
  2917. return -ENODEV;
  2918. }
  2919. if ((up_dev == wl->current_dev) &&
  2920. (!!wl->current_dev->phy.gmode == !!gmode)) {
  2921. /* This device is already running. */
  2922. return 0;
  2923. }
  2924. b43dbg(wl, "Switching to %s-GHz band\n",
  2925. band_to_string(chan->band));
  2926. down_dev = wl->current_dev;
  2927. prev_status = b43_status(down_dev);
  2928. /* Shutdown the currently running core. */
  2929. if (prev_status >= B43_STAT_STARTED)
  2930. b43_wireless_core_stop(down_dev);
  2931. if (prev_status >= B43_STAT_INITIALIZED)
  2932. b43_wireless_core_exit(down_dev);
  2933. if (down_dev != up_dev) {
  2934. /* We switch to a different core, so we put PHY into
  2935. * RESET on the old core. */
  2936. b43_put_phy_into_reset(down_dev);
  2937. }
  2938. /* Now start the new core. */
  2939. up_dev->phy.gmode = gmode;
  2940. if (prev_status >= B43_STAT_INITIALIZED) {
  2941. err = b43_wireless_core_init(up_dev);
  2942. if (err) {
  2943. b43err(wl, "Fatal: Could not initialize device for "
  2944. "selected %s-GHz band\n",
  2945. band_to_string(chan->band));
  2946. goto init_failure;
  2947. }
  2948. }
  2949. if (prev_status >= B43_STAT_STARTED) {
  2950. err = b43_wireless_core_start(up_dev);
  2951. if (err) {
  2952. b43err(wl, "Fatal: Coult not start device for "
  2953. "selected %s-GHz band\n",
  2954. band_to_string(chan->band));
  2955. b43_wireless_core_exit(up_dev);
  2956. goto init_failure;
  2957. }
  2958. }
  2959. B43_WARN_ON(b43_status(up_dev) != prev_status);
  2960. wl->current_dev = up_dev;
  2961. return 0;
  2962. init_failure:
  2963. /* Whoops, failed to init the new core. No core is operating now. */
  2964. wl->current_dev = NULL;
  2965. return err;
  2966. }
  2967. /* Write the short and long frame retry limit values. */
  2968. static void b43_set_retry_limits(struct b43_wldev *dev,
  2969. unsigned int short_retry,
  2970. unsigned int long_retry)
  2971. {
  2972. /* The retry limit is a 4-bit counter. Enforce this to avoid overflowing
  2973. * the chip-internal counter. */
  2974. short_retry = min(short_retry, (unsigned int)0xF);
  2975. long_retry = min(long_retry, (unsigned int)0xF);
  2976. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_SRLIMIT,
  2977. short_retry);
  2978. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_LRLIMIT,
  2979. long_retry);
  2980. }
  2981. static int b43_op_config(struct ieee80211_hw *hw, u32 changed)
  2982. {
  2983. struct b43_wl *wl = hw_to_b43_wl(hw);
  2984. struct b43_wldev *dev;
  2985. struct b43_phy *phy;
  2986. struct ieee80211_conf *conf = &hw->conf;
  2987. unsigned long flags;
  2988. int antenna;
  2989. int err = 0;
  2990. mutex_lock(&wl->mutex);
  2991. /* Switch the band (if necessary). This might change the active core. */
  2992. err = b43_switch_band(wl, conf->channel);
  2993. if (err)
  2994. goto out_unlock_mutex;
  2995. dev = wl->current_dev;
  2996. phy = &dev->phy;
  2997. b43_mac_suspend(dev);
  2998. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  2999. b43_set_retry_limits(dev, conf->short_frame_max_tx_count,
  3000. conf->long_frame_max_tx_count);
  3001. changed &= ~IEEE80211_CONF_CHANGE_RETRY_LIMITS;
  3002. if (!changed)
  3003. goto out_mac_enable;
  3004. /* Switch to the requested channel.
  3005. * The firmware takes care of races with the TX handler. */
  3006. if (conf->channel->hw_value != phy->channel)
  3007. b43_switch_channel(dev, conf->channel->hw_value);
  3008. dev->wl->radiotap_enabled = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
  3009. /* Adjust the desired TX power level. */
  3010. if (conf->power_level != 0) {
  3011. spin_lock_irqsave(&wl->irq_lock, flags);
  3012. if (conf->power_level != phy->desired_txpower) {
  3013. phy->desired_txpower = conf->power_level;
  3014. b43_phy_txpower_check(dev, B43_TXPWR_IGNORE_TIME |
  3015. B43_TXPWR_IGNORE_TSSI);
  3016. }
  3017. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3018. }
  3019. /* Antennas for RX and management frame TX. */
  3020. antenna = B43_ANTENNA_DEFAULT;
  3021. b43_mgmtframe_txantenna(dev, antenna);
  3022. antenna = B43_ANTENNA_DEFAULT;
  3023. if (phy->ops->set_rx_antenna)
  3024. phy->ops->set_rx_antenna(dev, antenna);
  3025. /* Update templates for AP/mesh mode. */
  3026. if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
  3027. b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT))
  3028. b43_set_beacon_int(dev, conf->beacon_int);
  3029. if (!!conf->radio_enabled != phy->radio_on) {
  3030. if (conf->radio_enabled) {
  3031. b43_software_rfkill(dev, RFKILL_STATE_UNBLOCKED);
  3032. b43info(dev->wl, "Radio turned on by software\n");
  3033. if (!dev->radio_hw_enable) {
  3034. b43info(dev->wl, "The hardware RF-kill button "
  3035. "still turns the radio physically off. "
  3036. "Press the button to turn it on.\n");
  3037. }
  3038. } else {
  3039. b43_software_rfkill(dev, RFKILL_STATE_SOFT_BLOCKED);
  3040. b43info(dev->wl, "Radio turned off by software\n");
  3041. }
  3042. }
  3043. out_mac_enable:
  3044. b43_mac_enable(dev);
  3045. out_unlock_mutex:
  3046. mutex_unlock(&wl->mutex);
  3047. return err;
  3048. }
  3049. static void b43_update_basic_rates(struct b43_wldev *dev, u32 brates)
  3050. {
  3051. struct ieee80211_supported_band *sband =
  3052. dev->wl->hw->wiphy->bands[b43_current_band(dev->wl)];
  3053. struct ieee80211_rate *rate;
  3054. int i;
  3055. u16 basic, direct, offset, basic_offset, rateptr;
  3056. for (i = 0; i < sband->n_bitrates; i++) {
  3057. rate = &sband->bitrates[i];
  3058. if (b43_is_cck_rate(rate->hw_value)) {
  3059. direct = B43_SHM_SH_CCKDIRECT;
  3060. basic = B43_SHM_SH_CCKBASIC;
  3061. offset = b43_plcp_get_ratecode_cck(rate->hw_value);
  3062. offset &= 0xF;
  3063. } else {
  3064. direct = B43_SHM_SH_OFDMDIRECT;
  3065. basic = B43_SHM_SH_OFDMBASIC;
  3066. offset = b43_plcp_get_ratecode_ofdm(rate->hw_value);
  3067. offset &= 0xF;
  3068. }
  3069. rate = ieee80211_get_response_rate(sband, brates, rate->bitrate);
  3070. if (b43_is_cck_rate(rate->hw_value)) {
  3071. basic_offset = b43_plcp_get_ratecode_cck(rate->hw_value);
  3072. basic_offset &= 0xF;
  3073. } else {
  3074. basic_offset = b43_plcp_get_ratecode_ofdm(rate->hw_value);
  3075. basic_offset &= 0xF;
  3076. }
  3077. /*
  3078. * Get the pointer that we need to point to
  3079. * from the direct map
  3080. */
  3081. rateptr = b43_shm_read16(dev, B43_SHM_SHARED,
  3082. direct + 2 * basic_offset);
  3083. /* and write it to the basic map */
  3084. b43_shm_write16(dev, B43_SHM_SHARED, basic + 2 * offset,
  3085. rateptr);
  3086. }
  3087. }
  3088. static void b43_op_bss_info_changed(struct ieee80211_hw *hw,
  3089. struct ieee80211_vif *vif,
  3090. struct ieee80211_bss_conf *conf,
  3091. u32 changed)
  3092. {
  3093. struct b43_wl *wl = hw_to_b43_wl(hw);
  3094. struct b43_wldev *dev;
  3095. mutex_lock(&wl->mutex);
  3096. dev = wl->current_dev;
  3097. if (!dev || b43_status(dev) < B43_STAT_STARTED)
  3098. goto out_unlock_mutex;
  3099. b43_mac_suspend(dev);
  3100. if (changed & BSS_CHANGED_BASIC_RATES)
  3101. b43_update_basic_rates(dev, conf->basic_rates);
  3102. if (changed & BSS_CHANGED_ERP_SLOT) {
  3103. if (conf->use_short_slot)
  3104. b43_short_slot_timing_enable(dev);
  3105. else
  3106. b43_short_slot_timing_disable(dev);
  3107. }
  3108. b43_mac_enable(dev);
  3109. out_unlock_mutex:
  3110. mutex_unlock(&wl->mutex);
  3111. return;
  3112. }
  3113. static int b43_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  3114. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  3115. struct ieee80211_key_conf *key)
  3116. {
  3117. struct b43_wl *wl = hw_to_b43_wl(hw);
  3118. struct b43_wldev *dev;
  3119. u8 algorithm;
  3120. u8 index;
  3121. int err;
  3122. static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  3123. if (modparam_nohwcrypt)
  3124. return -ENOSPC; /* User disabled HW-crypto */
  3125. mutex_lock(&wl->mutex);
  3126. spin_lock_irq(&wl->irq_lock);
  3127. write_lock(&wl->tx_lock);
  3128. /* Why do we need all this locking here?
  3129. * mutex -> Every config operation must take it.
  3130. * irq_lock -> We modify the dev->key array, which is accessed
  3131. * in the IRQ handlers.
  3132. * tx_lock -> We modify the dev->key array, which is accessed
  3133. * in the TX handler.
  3134. */
  3135. dev = wl->current_dev;
  3136. err = -ENODEV;
  3137. if (!dev || b43_status(dev) < B43_STAT_INITIALIZED)
  3138. goto out_unlock;
  3139. if (dev->fw.pcm_request_failed) {
  3140. /* We don't have firmware for the crypto engine.
  3141. * Must use software-crypto. */
  3142. err = -EOPNOTSUPP;
  3143. goto out_unlock;
  3144. }
  3145. err = -EINVAL;
  3146. switch (key->alg) {
  3147. case ALG_WEP:
  3148. if (key->keylen == LEN_WEP40)
  3149. algorithm = B43_SEC_ALGO_WEP40;
  3150. else
  3151. algorithm = B43_SEC_ALGO_WEP104;
  3152. break;
  3153. case ALG_TKIP:
  3154. algorithm = B43_SEC_ALGO_TKIP;
  3155. break;
  3156. case ALG_CCMP:
  3157. algorithm = B43_SEC_ALGO_AES;
  3158. break;
  3159. default:
  3160. B43_WARN_ON(1);
  3161. goto out_unlock;
  3162. }
  3163. index = (u8) (key->keyidx);
  3164. if (index > 3)
  3165. goto out_unlock;
  3166. switch (cmd) {
  3167. case SET_KEY:
  3168. if (algorithm == B43_SEC_ALGO_TKIP) {
  3169. /* FIXME: No TKIP hardware encryption for now. */
  3170. err = -EOPNOTSUPP;
  3171. goto out_unlock;
  3172. }
  3173. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
  3174. if (WARN_ON(!sta)) {
  3175. err = -EOPNOTSUPP;
  3176. goto out_unlock;
  3177. }
  3178. /* Pairwise key with an assigned MAC address. */
  3179. err = b43_key_write(dev, -1, algorithm,
  3180. key->key, key->keylen,
  3181. sta->addr, key);
  3182. } else {
  3183. /* Group key */
  3184. err = b43_key_write(dev, index, algorithm,
  3185. key->key, key->keylen, NULL, key);
  3186. }
  3187. if (err)
  3188. goto out_unlock;
  3189. if (algorithm == B43_SEC_ALGO_WEP40 ||
  3190. algorithm == B43_SEC_ALGO_WEP104) {
  3191. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_USEDEFKEYS);
  3192. } else {
  3193. b43_hf_write(dev,
  3194. b43_hf_read(dev) & ~B43_HF_USEDEFKEYS);
  3195. }
  3196. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  3197. break;
  3198. case DISABLE_KEY: {
  3199. err = b43_key_clear(dev, key->hw_key_idx);
  3200. if (err)
  3201. goto out_unlock;
  3202. break;
  3203. }
  3204. default:
  3205. B43_WARN_ON(1);
  3206. }
  3207. out_unlock:
  3208. if (!err) {
  3209. b43dbg(wl, "%s hardware based encryption for keyidx: %d, "
  3210. "mac: %pM\n",
  3211. cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
  3212. sta ? sta->addr : bcast_addr);
  3213. b43_dump_keymemory(dev);
  3214. }
  3215. write_unlock(&wl->tx_lock);
  3216. spin_unlock_irq(&wl->irq_lock);
  3217. mutex_unlock(&wl->mutex);
  3218. return err;
  3219. }
  3220. static void b43_op_configure_filter(struct ieee80211_hw *hw,
  3221. unsigned int changed, unsigned int *fflags,
  3222. int mc_count, struct dev_addr_list *mc_list)
  3223. {
  3224. struct b43_wl *wl = hw_to_b43_wl(hw);
  3225. struct b43_wldev *dev = wl->current_dev;
  3226. unsigned long flags;
  3227. if (!dev) {
  3228. *fflags = 0;
  3229. return;
  3230. }
  3231. spin_lock_irqsave(&wl->irq_lock, flags);
  3232. *fflags &= FIF_PROMISC_IN_BSS |
  3233. FIF_ALLMULTI |
  3234. FIF_FCSFAIL |
  3235. FIF_PLCPFAIL |
  3236. FIF_CONTROL |
  3237. FIF_OTHER_BSS |
  3238. FIF_BCN_PRBRESP_PROMISC;
  3239. changed &= FIF_PROMISC_IN_BSS |
  3240. FIF_ALLMULTI |
  3241. FIF_FCSFAIL |
  3242. FIF_PLCPFAIL |
  3243. FIF_CONTROL |
  3244. FIF_OTHER_BSS |
  3245. FIF_BCN_PRBRESP_PROMISC;
  3246. wl->filter_flags = *fflags;
  3247. if (changed && b43_status(dev) >= B43_STAT_INITIALIZED)
  3248. b43_adjust_opmode(dev);
  3249. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3250. }
  3251. static int b43_op_config_interface(struct ieee80211_hw *hw,
  3252. struct ieee80211_vif *vif,
  3253. struct ieee80211_if_conf *conf)
  3254. {
  3255. struct b43_wl *wl = hw_to_b43_wl(hw);
  3256. struct b43_wldev *dev = wl->current_dev;
  3257. unsigned long flags;
  3258. if (!dev)
  3259. return -ENODEV;
  3260. mutex_lock(&wl->mutex);
  3261. spin_lock_irqsave(&wl->irq_lock, flags);
  3262. B43_WARN_ON(wl->vif != vif);
  3263. if (conf->bssid)
  3264. memcpy(wl->bssid, conf->bssid, ETH_ALEN);
  3265. else
  3266. memset(wl->bssid, 0, ETH_ALEN);
  3267. if (b43_status(dev) >= B43_STAT_INITIALIZED) {
  3268. if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
  3269. b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT)) {
  3270. B43_WARN_ON(vif->type != wl->if_type);
  3271. if (conf->changed & IEEE80211_IFCC_BEACON)
  3272. b43_update_templates(wl);
  3273. } else if (b43_is_mode(wl, NL80211_IFTYPE_ADHOC)) {
  3274. if (conf->changed & IEEE80211_IFCC_BEACON)
  3275. b43_update_templates(wl);
  3276. }
  3277. b43_write_mac_bssid_templates(dev);
  3278. }
  3279. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3280. mutex_unlock(&wl->mutex);
  3281. return 0;
  3282. }
  3283. /* Locking: wl->mutex */
  3284. static void b43_wireless_core_stop(struct b43_wldev *dev)
  3285. {
  3286. struct b43_wl *wl = dev->wl;
  3287. unsigned long flags;
  3288. if (b43_status(dev) < B43_STAT_STARTED)
  3289. return;
  3290. /* Disable and sync interrupts. We must do this before than
  3291. * setting the status to INITIALIZED, as the interrupt handler
  3292. * won't care about IRQs then. */
  3293. spin_lock_irqsave(&wl->irq_lock, flags);
  3294. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, 0);
  3295. b43_read32(dev, B43_MMIO_GEN_IRQ_MASK); /* flush */
  3296. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3297. b43_synchronize_irq(dev);
  3298. write_lock_irqsave(&wl->tx_lock, flags);
  3299. b43_set_status(dev, B43_STAT_INITIALIZED);
  3300. write_unlock_irqrestore(&wl->tx_lock, flags);
  3301. b43_pio_stop(dev);
  3302. mutex_unlock(&wl->mutex);
  3303. /* Must unlock as it would otherwise deadlock. No races here.
  3304. * Cancel the possibly running self-rearming periodic work. */
  3305. cancel_delayed_work_sync(&dev->periodic_work);
  3306. mutex_lock(&wl->mutex);
  3307. b43_mac_suspend(dev);
  3308. free_irq(dev->dev->irq, dev);
  3309. b43dbg(wl, "Wireless interface stopped\n");
  3310. }
  3311. /* Locking: wl->mutex */
  3312. static int b43_wireless_core_start(struct b43_wldev *dev)
  3313. {
  3314. int err;
  3315. B43_WARN_ON(b43_status(dev) != B43_STAT_INITIALIZED);
  3316. drain_txstatus_queue(dev);
  3317. err = request_irq(dev->dev->irq, b43_interrupt_handler,
  3318. IRQF_SHARED, KBUILD_MODNAME, dev);
  3319. if (err) {
  3320. b43err(dev->wl, "Cannot request IRQ-%d\n", dev->dev->irq);
  3321. goto out;
  3322. }
  3323. /* We are ready to run. */
  3324. b43_set_status(dev, B43_STAT_STARTED);
  3325. /* Start data flow (TX/RX). */
  3326. b43_mac_enable(dev);
  3327. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
  3328. /* Start maintainance work */
  3329. b43_periodic_tasks_setup(dev);
  3330. b43dbg(dev->wl, "Wireless interface started\n");
  3331. out:
  3332. return err;
  3333. }
  3334. /* Get PHY and RADIO versioning numbers */
  3335. static int b43_phy_versioning(struct b43_wldev *dev)
  3336. {
  3337. struct b43_phy *phy = &dev->phy;
  3338. u32 tmp;
  3339. u8 analog_type;
  3340. u8 phy_type;
  3341. u8 phy_rev;
  3342. u16 radio_manuf;
  3343. u16 radio_ver;
  3344. u16 radio_rev;
  3345. int unsupported = 0;
  3346. /* Get PHY versioning */
  3347. tmp = b43_read16(dev, B43_MMIO_PHY_VER);
  3348. analog_type = (tmp & B43_PHYVER_ANALOG) >> B43_PHYVER_ANALOG_SHIFT;
  3349. phy_type = (tmp & B43_PHYVER_TYPE) >> B43_PHYVER_TYPE_SHIFT;
  3350. phy_rev = (tmp & B43_PHYVER_VERSION);
  3351. switch (phy_type) {
  3352. case B43_PHYTYPE_A:
  3353. if (phy_rev >= 4)
  3354. unsupported = 1;
  3355. break;
  3356. case B43_PHYTYPE_B:
  3357. if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6
  3358. && phy_rev != 7)
  3359. unsupported = 1;
  3360. break;
  3361. case B43_PHYTYPE_G:
  3362. if (phy_rev > 9)
  3363. unsupported = 1;
  3364. break;
  3365. #ifdef CONFIG_B43_NPHY
  3366. case B43_PHYTYPE_N:
  3367. if (phy_rev > 4)
  3368. unsupported = 1;
  3369. break;
  3370. #endif
  3371. #ifdef CONFIG_B43_PHY_LP
  3372. case B43_PHYTYPE_LP:
  3373. if (phy_rev > 1)
  3374. unsupported = 1;
  3375. break;
  3376. #endif
  3377. default:
  3378. unsupported = 1;
  3379. };
  3380. if (unsupported) {
  3381. b43err(dev->wl, "FOUND UNSUPPORTED PHY "
  3382. "(Analog %u, Type %u, Revision %u)\n",
  3383. analog_type, phy_type, phy_rev);
  3384. return -EOPNOTSUPP;
  3385. }
  3386. b43dbg(dev->wl, "Found PHY: Analog %u, Type %u, Revision %u\n",
  3387. analog_type, phy_type, phy_rev);
  3388. /* Get RADIO versioning */
  3389. if (dev->dev->bus->chip_id == 0x4317) {
  3390. if (dev->dev->bus->chip_rev == 0)
  3391. tmp = 0x3205017F;
  3392. else if (dev->dev->bus->chip_rev == 1)
  3393. tmp = 0x4205017F;
  3394. else
  3395. tmp = 0x5205017F;
  3396. } else {
  3397. b43_write16(dev, B43_MMIO_RADIO_CONTROL, B43_RADIOCTL_ID);
  3398. tmp = b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
  3399. b43_write16(dev, B43_MMIO_RADIO_CONTROL, B43_RADIOCTL_ID);
  3400. tmp |= (u32)b43_read16(dev, B43_MMIO_RADIO_DATA_HIGH) << 16;
  3401. }
  3402. radio_manuf = (tmp & 0x00000FFF);
  3403. radio_ver = (tmp & 0x0FFFF000) >> 12;
  3404. radio_rev = (tmp & 0xF0000000) >> 28;
  3405. if (radio_manuf != 0x17F /* Broadcom */)
  3406. unsupported = 1;
  3407. switch (phy_type) {
  3408. case B43_PHYTYPE_A:
  3409. if (radio_ver != 0x2060)
  3410. unsupported = 1;
  3411. if (radio_rev != 1)
  3412. unsupported = 1;
  3413. if (radio_manuf != 0x17F)
  3414. unsupported = 1;
  3415. break;
  3416. case B43_PHYTYPE_B:
  3417. if ((radio_ver & 0xFFF0) != 0x2050)
  3418. unsupported = 1;
  3419. break;
  3420. case B43_PHYTYPE_G:
  3421. if (radio_ver != 0x2050)
  3422. unsupported = 1;
  3423. break;
  3424. case B43_PHYTYPE_N:
  3425. if (radio_ver != 0x2055 && radio_ver != 0x2056)
  3426. unsupported = 1;
  3427. break;
  3428. case B43_PHYTYPE_LP:
  3429. if (radio_ver != 0x2062)
  3430. unsupported = 1;
  3431. break;
  3432. default:
  3433. B43_WARN_ON(1);
  3434. }
  3435. if (unsupported) {
  3436. b43err(dev->wl, "FOUND UNSUPPORTED RADIO "
  3437. "(Manuf 0x%X, Version 0x%X, Revision %u)\n",
  3438. radio_manuf, radio_ver, radio_rev);
  3439. return -EOPNOTSUPP;
  3440. }
  3441. b43dbg(dev->wl, "Found Radio: Manuf 0x%X, Version 0x%X, Revision %u\n",
  3442. radio_manuf, radio_ver, radio_rev);
  3443. phy->radio_manuf = radio_manuf;
  3444. phy->radio_ver = radio_ver;
  3445. phy->radio_rev = radio_rev;
  3446. phy->analog = analog_type;
  3447. phy->type = phy_type;
  3448. phy->rev = phy_rev;
  3449. return 0;
  3450. }
  3451. static void setup_struct_phy_for_init(struct b43_wldev *dev,
  3452. struct b43_phy *phy)
  3453. {
  3454. phy->hardware_power_control = !!modparam_hwpctl;
  3455. phy->next_txpwr_check_time = jiffies;
  3456. /* PHY TX errors counter. */
  3457. atomic_set(&phy->txerr_cnt, B43_PHY_TX_BADNESS_LIMIT);
  3458. #if B43_DEBUG
  3459. phy->phy_locked = 0;
  3460. phy->radio_locked = 0;
  3461. #endif
  3462. }
  3463. static void setup_struct_wldev_for_init(struct b43_wldev *dev)
  3464. {
  3465. dev->dfq_valid = 0;
  3466. /* Assume the radio is enabled. If it's not enabled, the state will
  3467. * immediately get fixed on the first periodic work run. */
  3468. dev->radio_hw_enable = 1;
  3469. /* Stats */
  3470. memset(&dev->stats, 0, sizeof(dev->stats));
  3471. setup_struct_phy_for_init(dev, &dev->phy);
  3472. /* IRQ related flags */
  3473. dev->irq_reason = 0;
  3474. memset(dev->dma_reason, 0, sizeof(dev->dma_reason));
  3475. dev->irq_mask = B43_IRQ_MASKTEMPLATE;
  3476. if (b43_modparam_verbose < B43_VERBOSITY_DEBUG)
  3477. dev->irq_mask &= ~B43_IRQ_PHY_TXERR;
  3478. dev->mac_suspended = 1;
  3479. /* Noise calculation context */
  3480. memset(&dev->noisecalc, 0, sizeof(dev->noisecalc));
  3481. }
  3482. static void b43_bluetooth_coext_enable(struct b43_wldev *dev)
  3483. {
  3484. struct ssb_sprom *sprom = &dev->dev->bus->sprom;
  3485. u64 hf;
  3486. if (!modparam_btcoex)
  3487. return;
  3488. if (!(sprom->boardflags_lo & B43_BFL_BTCOEXIST))
  3489. return;
  3490. if (dev->phy.type != B43_PHYTYPE_B && !dev->phy.gmode)
  3491. return;
  3492. hf = b43_hf_read(dev);
  3493. if (sprom->boardflags_lo & B43_BFL_BTCMOD)
  3494. hf |= B43_HF_BTCOEXALT;
  3495. else
  3496. hf |= B43_HF_BTCOEX;
  3497. b43_hf_write(dev, hf);
  3498. }
  3499. static void b43_bluetooth_coext_disable(struct b43_wldev *dev)
  3500. {
  3501. if (!modparam_btcoex)
  3502. return;
  3503. //TODO
  3504. }
  3505. static void b43_imcfglo_timeouts_workaround(struct b43_wldev *dev)
  3506. {
  3507. #ifdef CONFIG_SSB_DRIVER_PCICORE
  3508. struct ssb_bus *bus = dev->dev->bus;
  3509. u32 tmp;
  3510. if (bus->pcicore.dev &&
  3511. bus->pcicore.dev->id.coreid == SSB_DEV_PCI &&
  3512. bus->pcicore.dev->id.revision <= 5) {
  3513. /* IMCFGLO timeouts workaround. */
  3514. tmp = ssb_read32(dev->dev, SSB_IMCFGLO);
  3515. tmp &= ~SSB_IMCFGLO_REQTO;
  3516. tmp &= ~SSB_IMCFGLO_SERTO;
  3517. switch (bus->bustype) {
  3518. case SSB_BUSTYPE_PCI:
  3519. case SSB_BUSTYPE_PCMCIA:
  3520. tmp |= 0x32;
  3521. break;
  3522. case SSB_BUSTYPE_SSB:
  3523. tmp |= 0x53;
  3524. break;
  3525. }
  3526. ssb_write32(dev->dev, SSB_IMCFGLO, tmp);
  3527. }
  3528. #endif /* CONFIG_SSB_DRIVER_PCICORE */
  3529. }
  3530. static void b43_set_synth_pu_delay(struct b43_wldev *dev, bool idle)
  3531. {
  3532. u16 pu_delay;
  3533. /* The time value is in microseconds. */
  3534. if (dev->phy.type == B43_PHYTYPE_A)
  3535. pu_delay = 3700;
  3536. else
  3537. pu_delay = 1050;
  3538. if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC) || idle)
  3539. pu_delay = 500;
  3540. if ((dev->phy.radio_ver == 0x2050) && (dev->phy.radio_rev == 8))
  3541. pu_delay = max(pu_delay, (u16)2400);
  3542. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_SPUWKUP, pu_delay);
  3543. }
  3544. /* Set the TSF CFP pre-TargetBeaconTransmissionTime. */
  3545. static void b43_set_pretbtt(struct b43_wldev *dev)
  3546. {
  3547. u16 pretbtt;
  3548. /* The time value is in microseconds. */
  3549. if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC)) {
  3550. pretbtt = 2;
  3551. } else {
  3552. if (dev->phy.type == B43_PHYTYPE_A)
  3553. pretbtt = 120;
  3554. else
  3555. pretbtt = 250;
  3556. }
  3557. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRETBTT, pretbtt);
  3558. b43_write16(dev, B43_MMIO_TSF_CFP_PRETBTT, pretbtt);
  3559. }
  3560. /* Shutdown a wireless core */
  3561. /* Locking: wl->mutex */
  3562. static void b43_wireless_core_exit(struct b43_wldev *dev)
  3563. {
  3564. u32 macctl;
  3565. B43_WARN_ON(b43_status(dev) > B43_STAT_INITIALIZED);
  3566. if (b43_status(dev) != B43_STAT_INITIALIZED)
  3567. return;
  3568. b43_set_status(dev, B43_STAT_UNINIT);
  3569. /* Stop the microcode PSM. */
  3570. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  3571. macctl &= ~B43_MACCTL_PSM_RUN;
  3572. macctl |= B43_MACCTL_PSM_JMP0;
  3573. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  3574. if (!dev->suspend_in_progress) {
  3575. b43_leds_exit(dev);
  3576. b43_rng_exit(dev->wl);
  3577. }
  3578. b43_dma_free(dev);
  3579. b43_pio_free(dev);
  3580. b43_chip_exit(dev);
  3581. dev->phy.ops->switch_analog(dev, 0);
  3582. if (dev->wl->current_beacon) {
  3583. dev_kfree_skb_any(dev->wl->current_beacon);
  3584. dev->wl->current_beacon = NULL;
  3585. }
  3586. ssb_device_disable(dev->dev, 0);
  3587. ssb_bus_may_powerdown(dev->dev->bus);
  3588. }
  3589. /* Initialize a wireless core */
  3590. static int b43_wireless_core_init(struct b43_wldev *dev)
  3591. {
  3592. struct b43_wl *wl = dev->wl;
  3593. struct ssb_bus *bus = dev->dev->bus;
  3594. struct ssb_sprom *sprom = &bus->sprom;
  3595. struct b43_phy *phy = &dev->phy;
  3596. int err;
  3597. u64 hf;
  3598. u32 tmp;
  3599. B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
  3600. err = ssb_bus_powerup(bus, 0);
  3601. if (err)
  3602. goto out;
  3603. if (!ssb_device_is_enabled(dev->dev)) {
  3604. tmp = phy->gmode ? B43_TMSLOW_GMODE : 0;
  3605. b43_wireless_core_reset(dev, tmp);
  3606. }
  3607. /* Reset all data structures. */
  3608. setup_struct_wldev_for_init(dev);
  3609. phy->ops->prepare_structs(dev);
  3610. /* Enable IRQ routing to this device. */
  3611. ssb_pcicore_dev_irqvecs_enable(&bus->pcicore, dev->dev);
  3612. b43_imcfglo_timeouts_workaround(dev);
  3613. b43_bluetooth_coext_disable(dev);
  3614. if (phy->ops->prepare_hardware) {
  3615. err = phy->ops->prepare_hardware(dev);
  3616. if (err)
  3617. goto err_busdown;
  3618. }
  3619. err = b43_chip_init(dev);
  3620. if (err)
  3621. goto err_busdown;
  3622. b43_shm_write16(dev, B43_SHM_SHARED,
  3623. B43_SHM_SH_WLCOREREV, dev->dev->id.revision);
  3624. hf = b43_hf_read(dev);
  3625. if (phy->type == B43_PHYTYPE_G) {
  3626. hf |= B43_HF_SYMW;
  3627. if (phy->rev == 1)
  3628. hf |= B43_HF_GDCW;
  3629. if (sprom->boardflags_lo & B43_BFL_PACTRL)
  3630. hf |= B43_HF_OFDMPABOOST;
  3631. }
  3632. if (phy->radio_ver == 0x2050) {
  3633. if (phy->radio_rev == 6)
  3634. hf |= B43_HF_4318TSSI;
  3635. if (phy->radio_rev < 6)
  3636. hf |= B43_HF_VCORECALC;
  3637. }
  3638. if (sprom->boardflags_lo & B43_BFL_XTAL_NOSLOW)
  3639. hf |= B43_HF_DSCRQ; /* Disable slowclock requests from ucode. */
  3640. #ifdef CONFIG_SSB_DRIVER_PCICORE
  3641. if ((bus->bustype == SSB_BUSTYPE_PCI) &&
  3642. (bus->pcicore.dev->id.revision <= 10))
  3643. hf |= B43_HF_PCISCW; /* PCI slow clock workaround. */
  3644. #endif
  3645. hf &= ~B43_HF_SKCFPUP;
  3646. b43_hf_write(dev, hf);
  3647. b43_set_retry_limits(dev, B43_DEFAULT_SHORT_RETRY_LIMIT,
  3648. B43_DEFAULT_LONG_RETRY_LIMIT);
  3649. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_SFFBLIM, 3);
  3650. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_LFFBLIM, 2);
  3651. /* Disable sending probe responses from firmware.
  3652. * Setting the MaxTime to one usec will always trigger
  3653. * a timeout, so we never send any probe resp.
  3654. * A timeout of zero is infinite. */
  3655. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRMAXTIME, 1);
  3656. b43_rate_memory_init(dev);
  3657. b43_set_phytxctl_defaults(dev);
  3658. /* Minimum Contention Window */
  3659. if (phy->type == B43_PHYTYPE_B) {
  3660. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MINCONT, 0x1F);
  3661. } else {
  3662. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MINCONT, 0xF);
  3663. }
  3664. /* Maximum Contention Window */
  3665. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MAXCONT, 0x3FF);
  3666. if ((dev->dev->bus->bustype == SSB_BUSTYPE_PCMCIA) || B43_FORCE_PIO) {
  3667. dev->__using_pio_transfers = 1;
  3668. err = b43_pio_init(dev);
  3669. } else {
  3670. dev->__using_pio_transfers = 0;
  3671. err = b43_dma_init(dev);
  3672. }
  3673. if (err)
  3674. goto err_chip_exit;
  3675. b43_qos_init(dev);
  3676. b43_set_synth_pu_delay(dev, 1);
  3677. b43_bluetooth_coext_enable(dev);
  3678. ssb_bus_powerup(bus, !(sprom->boardflags_lo & B43_BFL_XTAL_NOSLOW));
  3679. b43_upload_card_macaddress(dev);
  3680. b43_security_init(dev);
  3681. if (!dev->suspend_in_progress)
  3682. b43_rng_init(wl);
  3683. b43_set_status(dev, B43_STAT_INITIALIZED);
  3684. if (!dev->suspend_in_progress)
  3685. b43_leds_init(dev);
  3686. out:
  3687. return err;
  3688. err_chip_exit:
  3689. b43_chip_exit(dev);
  3690. err_busdown:
  3691. ssb_bus_may_powerdown(bus);
  3692. B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
  3693. return err;
  3694. }
  3695. static int b43_op_add_interface(struct ieee80211_hw *hw,
  3696. struct ieee80211_if_init_conf *conf)
  3697. {
  3698. struct b43_wl *wl = hw_to_b43_wl(hw);
  3699. struct b43_wldev *dev;
  3700. unsigned long flags;
  3701. int err = -EOPNOTSUPP;
  3702. /* TODO: allow WDS/AP devices to coexist */
  3703. if (conf->type != NL80211_IFTYPE_AP &&
  3704. conf->type != NL80211_IFTYPE_MESH_POINT &&
  3705. conf->type != NL80211_IFTYPE_STATION &&
  3706. conf->type != NL80211_IFTYPE_WDS &&
  3707. conf->type != NL80211_IFTYPE_ADHOC)
  3708. return -EOPNOTSUPP;
  3709. mutex_lock(&wl->mutex);
  3710. if (wl->operating)
  3711. goto out_mutex_unlock;
  3712. b43dbg(wl, "Adding Interface type %d\n", conf->type);
  3713. dev = wl->current_dev;
  3714. wl->operating = 1;
  3715. wl->vif = conf->vif;
  3716. wl->if_type = conf->type;
  3717. memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN);
  3718. spin_lock_irqsave(&wl->irq_lock, flags);
  3719. b43_adjust_opmode(dev);
  3720. b43_set_pretbtt(dev);
  3721. b43_set_synth_pu_delay(dev, 0);
  3722. b43_upload_card_macaddress(dev);
  3723. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3724. err = 0;
  3725. out_mutex_unlock:
  3726. mutex_unlock(&wl->mutex);
  3727. return err;
  3728. }
  3729. static void b43_op_remove_interface(struct ieee80211_hw *hw,
  3730. struct ieee80211_if_init_conf *conf)
  3731. {
  3732. struct b43_wl *wl = hw_to_b43_wl(hw);
  3733. struct b43_wldev *dev = wl->current_dev;
  3734. unsigned long flags;
  3735. b43dbg(wl, "Removing Interface type %d\n", conf->type);
  3736. mutex_lock(&wl->mutex);
  3737. B43_WARN_ON(!wl->operating);
  3738. B43_WARN_ON(wl->vif != conf->vif);
  3739. wl->vif = NULL;
  3740. wl->operating = 0;
  3741. spin_lock_irqsave(&wl->irq_lock, flags);
  3742. b43_adjust_opmode(dev);
  3743. memset(wl->mac_addr, 0, ETH_ALEN);
  3744. b43_upload_card_macaddress(dev);
  3745. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3746. mutex_unlock(&wl->mutex);
  3747. }
  3748. static int b43_op_start(struct ieee80211_hw *hw)
  3749. {
  3750. struct b43_wl *wl = hw_to_b43_wl(hw);
  3751. struct b43_wldev *dev = wl->current_dev;
  3752. int did_init = 0;
  3753. int err = 0;
  3754. bool do_rfkill_exit = 0;
  3755. /* Kill all old instance specific information to make sure
  3756. * the card won't use it in the short timeframe between start
  3757. * and mac80211 reconfiguring it. */
  3758. memset(wl->bssid, 0, ETH_ALEN);
  3759. memset(wl->mac_addr, 0, ETH_ALEN);
  3760. wl->filter_flags = 0;
  3761. wl->radiotap_enabled = 0;
  3762. b43_qos_clear(wl);
  3763. wl->beacon0_uploaded = 0;
  3764. wl->beacon1_uploaded = 0;
  3765. wl->beacon_templates_virgin = 1;
  3766. /* First register RFkill.
  3767. * LEDs that are registered later depend on it. */
  3768. b43_rfkill_init(dev);
  3769. mutex_lock(&wl->mutex);
  3770. if (b43_status(dev) < B43_STAT_INITIALIZED) {
  3771. err = b43_wireless_core_init(dev);
  3772. if (err) {
  3773. do_rfkill_exit = 1;
  3774. goto out_mutex_unlock;
  3775. }
  3776. did_init = 1;
  3777. }
  3778. if (b43_status(dev) < B43_STAT_STARTED) {
  3779. err = b43_wireless_core_start(dev);
  3780. if (err) {
  3781. if (did_init)
  3782. b43_wireless_core_exit(dev);
  3783. do_rfkill_exit = 1;
  3784. goto out_mutex_unlock;
  3785. }
  3786. }
  3787. out_mutex_unlock:
  3788. mutex_unlock(&wl->mutex);
  3789. if (do_rfkill_exit)
  3790. b43_rfkill_exit(dev);
  3791. return err;
  3792. }
  3793. static void b43_op_stop(struct ieee80211_hw *hw)
  3794. {
  3795. struct b43_wl *wl = hw_to_b43_wl(hw);
  3796. struct b43_wldev *dev = wl->current_dev;
  3797. b43_rfkill_exit(dev);
  3798. cancel_work_sync(&(wl->beacon_update_trigger));
  3799. mutex_lock(&wl->mutex);
  3800. if (b43_status(dev) >= B43_STAT_STARTED)
  3801. b43_wireless_core_stop(dev);
  3802. b43_wireless_core_exit(dev);
  3803. mutex_unlock(&wl->mutex);
  3804. cancel_work_sync(&(wl->txpower_adjust_work));
  3805. }
  3806. static int b43_op_beacon_set_tim(struct ieee80211_hw *hw,
  3807. struct ieee80211_sta *sta, bool set)
  3808. {
  3809. struct b43_wl *wl = hw_to_b43_wl(hw);
  3810. unsigned long flags;
  3811. spin_lock_irqsave(&wl->irq_lock, flags);
  3812. b43_update_templates(wl);
  3813. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3814. return 0;
  3815. }
  3816. static void b43_op_sta_notify(struct ieee80211_hw *hw,
  3817. struct ieee80211_vif *vif,
  3818. enum sta_notify_cmd notify_cmd,
  3819. struct ieee80211_sta *sta)
  3820. {
  3821. struct b43_wl *wl = hw_to_b43_wl(hw);
  3822. B43_WARN_ON(!vif || wl->vif != vif);
  3823. }
  3824. static void b43_op_sw_scan_start_notifier(struct ieee80211_hw *hw)
  3825. {
  3826. struct b43_wl *wl = hw_to_b43_wl(hw);
  3827. struct b43_wldev *dev;
  3828. mutex_lock(&wl->mutex);
  3829. dev = wl->current_dev;
  3830. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED)) {
  3831. /* Disable CFP update during scan on other channels. */
  3832. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_SKCFPUP);
  3833. }
  3834. mutex_unlock(&wl->mutex);
  3835. }
  3836. static void b43_op_sw_scan_complete_notifier(struct ieee80211_hw *hw)
  3837. {
  3838. struct b43_wl *wl = hw_to_b43_wl(hw);
  3839. struct b43_wldev *dev;
  3840. mutex_lock(&wl->mutex);
  3841. dev = wl->current_dev;
  3842. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED)) {
  3843. /* Re-enable CFP update. */
  3844. b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_SKCFPUP);
  3845. }
  3846. mutex_unlock(&wl->mutex);
  3847. }
  3848. static const struct ieee80211_ops b43_hw_ops = {
  3849. .tx = b43_op_tx,
  3850. .conf_tx = b43_op_conf_tx,
  3851. .add_interface = b43_op_add_interface,
  3852. .remove_interface = b43_op_remove_interface,
  3853. .config = b43_op_config,
  3854. .bss_info_changed = b43_op_bss_info_changed,
  3855. .config_interface = b43_op_config_interface,
  3856. .configure_filter = b43_op_configure_filter,
  3857. .set_key = b43_op_set_key,
  3858. .get_stats = b43_op_get_stats,
  3859. .get_tx_stats = b43_op_get_tx_stats,
  3860. .get_tsf = b43_op_get_tsf,
  3861. .set_tsf = b43_op_set_tsf,
  3862. .start = b43_op_start,
  3863. .stop = b43_op_stop,
  3864. .set_tim = b43_op_beacon_set_tim,
  3865. .sta_notify = b43_op_sta_notify,
  3866. .sw_scan_start = b43_op_sw_scan_start_notifier,
  3867. .sw_scan_complete = b43_op_sw_scan_complete_notifier,
  3868. };
  3869. /* Hard-reset the chip. Do not call this directly.
  3870. * Use b43_controller_restart()
  3871. */
  3872. static void b43_chip_reset(struct work_struct *work)
  3873. {
  3874. struct b43_wldev *dev =
  3875. container_of(work, struct b43_wldev, restart_work);
  3876. struct b43_wl *wl = dev->wl;
  3877. int err = 0;
  3878. int prev_status;
  3879. mutex_lock(&wl->mutex);
  3880. prev_status = b43_status(dev);
  3881. /* Bring the device down... */
  3882. if (prev_status >= B43_STAT_STARTED)
  3883. b43_wireless_core_stop(dev);
  3884. if (prev_status >= B43_STAT_INITIALIZED)
  3885. b43_wireless_core_exit(dev);
  3886. /* ...and up again. */
  3887. if (prev_status >= B43_STAT_INITIALIZED) {
  3888. err = b43_wireless_core_init(dev);
  3889. if (err)
  3890. goto out;
  3891. }
  3892. if (prev_status >= B43_STAT_STARTED) {
  3893. err = b43_wireless_core_start(dev);
  3894. if (err) {
  3895. b43_wireless_core_exit(dev);
  3896. goto out;
  3897. }
  3898. }
  3899. out:
  3900. if (err)
  3901. wl->current_dev = NULL; /* Failed to init the dev. */
  3902. mutex_unlock(&wl->mutex);
  3903. if (err)
  3904. b43err(wl, "Controller restart FAILED\n");
  3905. else
  3906. b43info(wl, "Controller restarted\n");
  3907. }
  3908. static int b43_setup_bands(struct b43_wldev *dev,
  3909. bool have_2ghz_phy, bool have_5ghz_phy)
  3910. {
  3911. struct ieee80211_hw *hw = dev->wl->hw;
  3912. if (have_2ghz_phy)
  3913. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &b43_band_2GHz;
  3914. if (dev->phy.type == B43_PHYTYPE_N) {
  3915. if (have_5ghz_phy)
  3916. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &b43_band_5GHz_nphy;
  3917. } else {
  3918. if (have_5ghz_phy)
  3919. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &b43_band_5GHz_aphy;
  3920. }
  3921. dev->phy.supports_2ghz = have_2ghz_phy;
  3922. dev->phy.supports_5ghz = have_5ghz_phy;
  3923. return 0;
  3924. }
  3925. static void b43_wireless_core_detach(struct b43_wldev *dev)
  3926. {
  3927. /* We release firmware that late to not be required to re-request
  3928. * is all the time when we reinit the core. */
  3929. b43_release_firmware(dev);
  3930. b43_phy_free(dev);
  3931. }
  3932. static int b43_wireless_core_attach(struct b43_wldev *dev)
  3933. {
  3934. struct b43_wl *wl = dev->wl;
  3935. struct ssb_bus *bus = dev->dev->bus;
  3936. struct pci_dev *pdev = bus->host_pci;
  3937. int err;
  3938. bool have_2ghz_phy = 0, have_5ghz_phy = 0;
  3939. u32 tmp;
  3940. /* Do NOT do any device initialization here.
  3941. * Do it in wireless_core_init() instead.
  3942. * This function is for gathering basic information about the HW, only.
  3943. * Also some structs may be set up here. But most likely you want to have
  3944. * that in core_init(), too.
  3945. */
  3946. err = ssb_bus_powerup(bus, 0);
  3947. if (err) {
  3948. b43err(wl, "Bus powerup failed\n");
  3949. goto out;
  3950. }
  3951. /* Get the PHY type. */
  3952. if (dev->dev->id.revision >= 5) {
  3953. u32 tmshigh;
  3954. tmshigh = ssb_read32(dev->dev, SSB_TMSHIGH);
  3955. have_2ghz_phy = !!(tmshigh & B43_TMSHIGH_HAVE_2GHZ_PHY);
  3956. have_5ghz_phy = !!(tmshigh & B43_TMSHIGH_HAVE_5GHZ_PHY);
  3957. } else
  3958. B43_WARN_ON(1);
  3959. dev->phy.gmode = have_2ghz_phy;
  3960. tmp = dev->phy.gmode ? B43_TMSLOW_GMODE : 0;
  3961. b43_wireless_core_reset(dev, tmp);
  3962. err = b43_phy_versioning(dev);
  3963. if (err)
  3964. goto err_powerdown;
  3965. /* Check if this device supports multiband. */
  3966. if (!pdev ||
  3967. (pdev->device != 0x4312 &&
  3968. pdev->device != 0x4319 && pdev->device != 0x4324)) {
  3969. /* No multiband support. */
  3970. have_2ghz_phy = 0;
  3971. have_5ghz_phy = 0;
  3972. switch (dev->phy.type) {
  3973. case B43_PHYTYPE_A:
  3974. have_5ghz_phy = 1;
  3975. break;
  3976. case B43_PHYTYPE_G:
  3977. case B43_PHYTYPE_N:
  3978. case B43_PHYTYPE_LP:
  3979. have_2ghz_phy = 1;
  3980. break;
  3981. default:
  3982. B43_WARN_ON(1);
  3983. }
  3984. }
  3985. if (dev->phy.type == B43_PHYTYPE_A) {
  3986. /* FIXME */
  3987. b43err(wl, "IEEE 802.11a devices are unsupported\n");
  3988. err = -EOPNOTSUPP;
  3989. goto err_powerdown;
  3990. }
  3991. if (1 /* disable A-PHY */) {
  3992. /* FIXME: For now we disable the A-PHY on multi-PHY devices. */
  3993. if (dev->phy.type != B43_PHYTYPE_N) {
  3994. have_2ghz_phy = 1;
  3995. have_5ghz_phy = 0;
  3996. }
  3997. }
  3998. err = b43_phy_allocate(dev);
  3999. if (err)
  4000. goto err_powerdown;
  4001. dev->phy.gmode = have_2ghz_phy;
  4002. tmp = dev->phy.gmode ? B43_TMSLOW_GMODE : 0;
  4003. b43_wireless_core_reset(dev, tmp);
  4004. err = b43_validate_chipaccess(dev);
  4005. if (err)
  4006. goto err_phy_free;
  4007. err = b43_setup_bands(dev, have_2ghz_phy, have_5ghz_phy);
  4008. if (err)
  4009. goto err_phy_free;
  4010. /* Now set some default "current_dev" */
  4011. if (!wl->current_dev)
  4012. wl->current_dev = dev;
  4013. INIT_WORK(&dev->restart_work, b43_chip_reset);
  4014. dev->phy.ops->switch_analog(dev, 0);
  4015. ssb_device_disable(dev->dev, 0);
  4016. ssb_bus_may_powerdown(bus);
  4017. out:
  4018. return err;
  4019. err_phy_free:
  4020. b43_phy_free(dev);
  4021. err_powerdown:
  4022. ssb_bus_may_powerdown(bus);
  4023. return err;
  4024. }
  4025. static void b43_one_core_detach(struct ssb_device *dev)
  4026. {
  4027. struct b43_wldev *wldev;
  4028. struct b43_wl *wl;
  4029. /* Do not cancel ieee80211-workqueue based work here.
  4030. * See comment in b43_remove(). */
  4031. wldev = ssb_get_drvdata(dev);
  4032. wl = wldev->wl;
  4033. b43_debugfs_remove_device(wldev);
  4034. b43_wireless_core_detach(wldev);
  4035. list_del(&wldev->list);
  4036. wl->nr_devs--;
  4037. ssb_set_drvdata(dev, NULL);
  4038. kfree(wldev);
  4039. }
  4040. static int b43_one_core_attach(struct ssb_device *dev, struct b43_wl *wl)
  4041. {
  4042. struct b43_wldev *wldev;
  4043. struct pci_dev *pdev;
  4044. int err = -ENOMEM;
  4045. if (!list_empty(&wl->devlist)) {
  4046. /* We are not the first core on this chip. */
  4047. pdev = dev->bus->host_pci;
  4048. /* Only special chips support more than one wireless
  4049. * core, although some of the other chips have more than
  4050. * one wireless core as well. Check for this and
  4051. * bail out early.
  4052. */
  4053. if (!pdev ||
  4054. ((pdev->device != 0x4321) &&
  4055. (pdev->device != 0x4313) && (pdev->device != 0x431A))) {
  4056. b43dbg(wl, "Ignoring unconnected 802.11 core\n");
  4057. return -ENODEV;
  4058. }
  4059. }
  4060. wldev = kzalloc(sizeof(*wldev), GFP_KERNEL);
  4061. if (!wldev)
  4062. goto out;
  4063. wldev->dev = dev;
  4064. wldev->wl = wl;
  4065. b43_set_status(wldev, B43_STAT_UNINIT);
  4066. wldev->bad_frames_preempt = modparam_bad_frames_preempt;
  4067. tasklet_init(&wldev->isr_tasklet,
  4068. (void (*)(unsigned long))b43_interrupt_tasklet,
  4069. (unsigned long)wldev);
  4070. INIT_LIST_HEAD(&wldev->list);
  4071. err = b43_wireless_core_attach(wldev);
  4072. if (err)
  4073. goto err_kfree_wldev;
  4074. list_add(&wldev->list, &wl->devlist);
  4075. wl->nr_devs++;
  4076. ssb_set_drvdata(dev, wldev);
  4077. b43_debugfs_add_device(wldev);
  4078. out:
  4079. return err;
  4080. err_kfree_wldev:
  4081. kfree(wldev);
  4082. return err;
  4083. }
  4084. #define IS_PDEV(pdev, _vendor, _device, _subvendor, _subdevice) ( \
  4085. (pdev->vendor == PCI_VENDOR_ID_##_vendor) && \
  4086. (pdev->device == _device) && \
  4087. (pdev->subsystem_vendor == PCI_VENDOR_ID_##_subvendor) && \
  4088. (pdev->subsystem_device == _subdevice) )
  4089. static void b43_sprom_fixup(struct ssb_bus *bus)
  4090. {
  4091. struct pci_dev *pdev;
  4092. /* boardflags workarounds */
  4093. if (bus->boardinfo.vendor == SSB_BOARDVENDOR_DELL &&
  4094. bus->chip_id == 0x4301 && bus->boardinfo.rev == 0x74)
  4095. bus->sprom.boardflags_lo |= B43_BFL_BTCOEXIST;
  4096. if (bus->boardinfo.vendor == PCI_VENDOR_ID_APPLE &&
  4097. bus->boardinfo.type == 0x4E && bus->boardinfo.rev > 0x40)
  4098. bus->sprom.boardflags_lo |= B43_BFL_PACTRL;
  4099. if (bus->bustype == SSB_BUSTYPE_PCI) {
  4100. pdev = bus->host_pci;
  4101. if (IS_PDEV(pdev, BROADCOM, 0x4318, ASUSTEK, 0x100F) ||
  4102. IS_PDEV(pdev, BROADCOM, 0x4320, DELL, 0x0003) ||
  4103. IS_PDEV(pdev, BROADCOM, 0x4320, HP, 0x12f8) ||
  4104. IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0015) ||
  4105. IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0014) ||
  4106. IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0013) ||
  4107. IS_PDEV(pdev, BROADCOM, 0x4320, MOTOROLA, 0x7010))
  4108. bus->sprom.boardflags_lo &= ~B43_BFL_BTCOEXIST;
  4109. }
  4110. }
  4111. static void b43_wireless_exit(struct ssb_device *dev, struct b43_wl *wl)
  4112. {
  4113. struct ieee80211_hw *hw = wl->hw;
  4114. ssb_set_devtypedata(dev, NULL);
  4115. ieee80211_free_hw(hw);
  4116. }
  4117. static int b43_wireless_init(struct ssb_device *dev)
  4118. {
  4119. struct ssb_sprom *sprom = &dev->bus->sprom;
  4120. struct ieee80211_hw *hw;
  4121. struct b43_wl *wl;
  4122. int err = -ENOMEM;
  4123. b43_sprom_fixup(dev->bus);
  4124. hw = ieee80211_alloc_hw(sizeof(*wl), &b43_hw_ops);
  4125. if (!hw) {
  4126. b43err(NULL, "Could not allocate ieee80211 device\n");
  4127. goto out;
  4128. }
  4129. /* fill hw info */
  4130. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  4131. IEEE80211_HW_SIGNAL_DBM |
  4132. IEEE80211_HW_NOISE_DBM;
  4133. hw->wiphy->interface_modes =
  4134. BIT(NL80211_IFTYPE_AP) |
  4135. BIT(NL80211_IFTYPE_MESH_POINT) |
  4136. BIT(NL80211_IFTYPE_STATION) |
  4137. BIT(NL80211_IFTYPE_WDS) |
  4138. BIT(NL80211_IFTYPE_ADHOC);
  4139. hw->queues = b43_modparam_qos ? 4 : 1;
  4140. hw->max_rates = 2;
  4141. SET_IEEE80211_DEV(hw, dev->dev);
  4142. if (is_valid_ether_addr(sprom->et1mac))
  4143. SET_IEEE80211_PERM_ADDR(hw, sprom->et1mac);
  4144. else
  4145. SET_IEEE80211_PERM_ADDR(hw, sprom->il0mac);
  4146. /* Get and initialize struct b43_wl */
  4147. wl = hw_to_b43_wl(hw);
  4148. memset(wl, 0, sizeof(*wl));
  4149. wl->hw = hw;
  4150. spin_lock_init(&wl->irq_lock);
  4151. rwlock_init(&wl->tx_lock);
  4152. spin_lock_init(&wl->leds_lock);
  4153. spin_lock_init(&wl->shm_lock);
  4154. mutex_init(&wl->mutex);
  4155. INIT_LIST_HEAD(&wl->devlist);
  4156. INIT_WORK(&wl->beacon_update_trigger, b43_beacon_update_trigger_work);
  4157. INIT_WORK(&wl->txpower_adjust_work, b43_phy_txpower_adjust_work);
  4158. ssb_set_devtypedata(dev, wl);
  4159. b43info(wl, "Broadcom %04X WLAN found (core revision %u)\n",
  4160. dev->bus->chip_id, dev->id.revision);
  4161. err = 0;
  4162. out:
  4163. return err;
  4164. }
  4165. static int b43_probe(struct ssb_device *dev, const struct ssb_device_id *id)
  4166. {
  4167. struct b43_wl *wl;
  4168. int err;
  4169. int first = 0;
  4170. wl = ssb_get_devtypedata(dev);
  4171. if (!wl) {
  4172. /* Probing the first core. Must setup common struct b43_wl */
  4173. first = 1;
  4174. err = b43_wireless_init(dev);
  4175. if (err)
  4176. goto out;
  4177. wl = ssb_get_devtypedata(dev);
  4178. B43_WARN_ON(!wl);
  4179. }
  4180. err = b43_one_core_attach(dev, wl);
  4181. if (err)
  4182. goto err_wireless_exit;
  4183. if (first) {
  4184. err = ieee80211_register_hw(wl->hw);
  4185. if (err)
  4186. goto err_one_core_detach;
  4187. }
  4188. out:
  4189. return err;
  4190. err_one_core_detach:
  4191. b43_one_core_detach(dev);
  4192. err_wireless_exit:
  4193. if (first)
  4194. b43_wireless_exit(dev, wl);
  4195. return err;
  4196. }
  4197. static void b43_remove(struct ssb_device *dev)
  4198. {
  4199. struct b43_wl *wl = ssb_get_devtypedata(dev);
  4200. struct b43_wldev *wldev = ssb_get_drvdata(dev);
  4201. /* We must cancel any work here before unregistering from ieee80211,
  4202. * as the ieee80211 unreg will destroy the workqueue. */
  4203. cancel_work_sync(&wldev->restart_work);
  4204. B43_WARN_ON(!wl);
  4205. if (wl->current_dev == wldev)
  4206. ieee80211_unregister_hw(wl->hw);
  4207. b43_one_core_detach(dev);
  4208. if (list_empty(&wl->devlist)) {
  4209. /* Last core on the chip unregistered.
  4210. * We can destroy common struct b43_wl.
  4211. */
  4212. b43_wireless_exit(dev, wl);
  4213. }
  4214. }
  4215. /* Perform a hardware reset. This can be called from any context. */
  4216. void b43_controller_restart(struct b43_wldev *dev, const char *reason)
  4217. {
  4218. /* Must avoid requeueing, if we are in shutdown. */
  4219. if (b43_status(dev) < B43_STAT_INITIALIZED)
  4220. return;
  4221. b43info(dev->wl, "Controller RESET (%s) ...\n", reason);
  4222. queue_work(dev->wl->hw->workqueue, &dev->restart_work);
  4223. }
  4224. #ifdef CONFIG_PM
  4225. static int b43_suspend(struct ssb_device *dev, pm_message_t state)
  4226. {
  4227. struct b43_wldev *wldev = ssb_get_drvdata(dev);
  4228. struct b43_wl *wl = wldev->wl;
  4229. b43dbg(wl, "Suspending...\n");
  4230. mutex_lock(&wl->mutex);
  4231. wldev->suspend_in_progress = true;
  4232. wldev->suspend_init_status = b43_status(wldev);
  4233. if (wldev->suspend_init_status >= B43_STAT_STARTED)
  4234. b43_wireless_core_stop(wldev);
  4235. if (wldev->suspend_init_status >= B43_STAT_INITIALIZED)
  4236. b43_wireless_core_exit(wldev);
  4237. mutex_unlock(&wl->mutex);
  4238. b43dbg(wl, "Device suspended.\n");
  4239. return 0;
  4240. }
  4241. static int b43_resume(struct ssb_device *dev)
  4242. {
  4243. struct b43_wldev *wldev = ssb_get_drvdata(dev);
  4244. struct b43_wl *wl = wldev->wl;
  4245. int err = 0;
  4246. b43dbg(wl, "Resuming...\n");
  4247. mutex_lock(&wl->mutex);
  4248. if (wldev->suspend_init_status >= B43_STAT_INITIALIZED) {
  4249. err = b43_wireless_core_init(wldev);
  4250. if (err) {
  4251. b43err(wl, "Resume failed at core init\n");
  4252. goto out;
  4253. }
  4254. }
  4255. if (wldev->suspend_init_status >= B43_STAT_STARTED) {
  4256. err = b43_wireless_core_start(wldev);
  4257. if (err) {
  4258. b43_leds_exit(wldev);
  4259. b43_rng_exit(wldev->wl);
  4260. b43_wireless_core_exit(wldev);
  4261. b43err(wl, "Resume failed at core start\n");
  4262. goto out;
  4263. }
  4264. }
  4265. b43dbg(wl, "Device resumed.\n");
  4266. out:
  4267. wldev->suspend_in_progress = false;
  4268. mutex_unlock(&wl->mutex);
  4269. return err;
  4270. }
  4271. #else /* CONFIG_PM */
  4272. # define b43_suspend NULL
  4273. # define b43_resume NULL
  4274. #endif /* CONFIG_PM */
  4275. static struct ssb_driver b43_ssb_driver = {
  4276. .name = KBUILD_MODNAME,
  4277. .id_table = b43_ssb_tbl,
  4278. .probe = b43_probe,
  4279. .remove = b43_remove,
  4280. .suspend = b43_suspend,
  4281. .resume = b43_resume,
  4282. };
  4283. static void b43_print_driverinfo(void)
  4284. {
  4285. const char *feat_pci = "", *feat_pcmcia = "", *feat_nphy = "",
  4286. *feat_leds = "", *feat_rfkill = "";
  4287. #ifdef CONFIG_B43_PCI_AUTOSELECT
  4288. feat_pci = "P";
  4289. #endif
  4290. #ifdef CONFIG_B43_PCMCIA
  4291. feat_pcmcia = "M";
  4292. #endif
  4293. #ifdef CONFIG_B43_NPHY
  4294. feat_nphy = "N";
  4295. #endif
  4296. #ifdef CONFIG_B43_LEDS
  4297. feat_leds = "L";
  4298. #endif
  4299. #ifdef CONFIG_B43_RFKILL
  4300. feat_rfkill = "R";
  4301. #endif
  4302. printk(KERN_INFO "Broadcom 43xx driver loaded "
  4303. "[ Features: %s%s%s%s%s, Firmware-ID: "
  4304. B43_SUPPORTED_FIRMWARE_ID " ]\n",
  4305. feat_pci, feat_pcmcia, feat_nphy,
  4306. feat_leds, feat_rfkill);
  4307. }
  4308. static int __init b43_init(void)
  4309. {
  4310. int err;
  4311. b43_debugfs_init();
  4312. err = b43_pcmcia_init();
  4313. if (err)
  4314. goto err_dfs_exit;
  4315. err = ssb_driver_register(&b43_ssb_driver);
  4316. if (err)
  4317. goto err_pcmcia_exit;
  4318. b43_print_driverinfo();
  4319. return err;
  4320. err_pcmcia_exit:
  4321. b43_pcmcia_exit();
  4322. err_dfs_exit:
  4323. b43_debugfs_exit();
  4324. return err;
  4325. }
  4326. static void __exit b43_exit(void)
  4327. {
  4328. ssb_driver_unregister(&b43_ssb_driver);
  4329. b43_pcmcia_exit();
  4330. b43_debugfs_exit();
  4331. }
  4332. module_init(b43_init)
  4333. module_exit(b43_exit)