bcm43xx_main.c 124 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596
  1. /*
  2. Broadcom BCM43xx wireless driver
  3. Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
  4. Stefano Brivio <st3@riseup.net>
  5. Michael Buesch <mbuesch@freenet.de>
  6. Danny van Dyk <kugelfang@gentoo.org>
  7. Andreas Jaggi <andreas.jaggi@waterwave.ch>
  8. Some parts of the code in this file are derived from the ipw2200
  9. driver Copyright(c) 2003 - 2004 Intel Corporation.
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; see the file COPYING. If not, write to
  20. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  21. Boston, MA 02110-1301, USA.
  22. */
  23. #include <linux/delay.h>
  24. #include <linux/init.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/if_arp.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/version.h>
  29. #include <linux/firmware.h>
  30. #include <linux/wireless.h>
  31. #include <linux/workqueue.h>
  32. #include <linux/skbuff.h>
  33. #include <net/iw_handler.h>
  34. #include "bcm43xx.h"
  35. #include "bcm43xx_main.h"
  36. #include "bcm43xx_debugfs.h"
  37. #include "bcm43xx_radio.h"
  38. #include "bcm43xx_phy.h"
  39. #include "bcm43xx_dma.h"
  40. #include "bcm43xx_pio.h"
  41. #include "bcm43xx_power.h"
  42. #include "bcm43xx_wx.h"
  43. MODULE_DESCRIPTION("Broadcom BCM43xx wireless driver");
  44. MODULE_AUTHOR("Martin Langer");
  45. MODULE_AUTHOR("Stefano Brivio");
  46. MODULE_AUTHOR("Michael Buesch");
  47. MODULE_LICENSE("GPL");
  48. #ifdef CONFIG_BCM947XX
  49. extern char *nvram_get(char *name);
  50. #endif
  51. /* Module parameters */
  52. static int modparam_pio;
  53. module_param_named(pio, modparam_pio, int, 0444);
  54. MODULE_PARM_DESC(pio, "enable(1) / disable(0) PIO mode");
  55. static int modparam_bad_frames_preempt;
  56. module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
  57. MODULE_PARM_DESC(bad_frames_preempt, "enable(1) / disable(0) Bad Frames Preemption");
  58. static int modparam_short_retry = BCM43xx_DEFAULT_SHORT_RETRY_LIMIT;
  59. module_param_named(short_retry, modparam_short_retry, int, 0444);
  60. MODULE_PARM_DESC(short_retry, "Short-Retry-Limit (0 - 15)");
  61. static int modparam_long_retry = BCM43xx_DEFAULT_LONG_RETRY_LIMIT;
  62. module_param_named(long_retry, modparam_long_retry, int, 0444);
  63. MODULE_PARM_DESC(long_retry, "Long-Retry-Limit (0 - 15)");
  64. static int modparam_locale = -1;
  65. module_param_named(locale, modparam_locale, int, 0444);
  66. MODULE_PARM_DESC(country, "Select LocaleCode 0-11 (For travelers)");
  67. static int modparam_outdoor;
  68. module_param_named(outdoor, modparam_outdoor, int, 0444);
  69. MODULE_PARM_DESC(outdoor, "Set to 1, if you are using the device outdoor, 0 otherwise.");
  70. static int modparam_noleds;
  71. module_param_named(noleds, modparam_noleds, int, 0444);
  72. MODULE_PARM_DESC(noleds, "Turn off all LED activity");
  73. #ifdef CONFIG_BCM43XX_DEBUG
  74. static char modparam_fwpostfix[64];
  75. module_param_string(fwpostfix, modparam_fwpostfix, 64, 0444);
  76. MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for debugging.");
  77. #else
  78. # define modparam_fwpostfix ""
  79. #endif /* CONFIG_BCM43XX_DEBUG*/
  80. /* If you want to debug with just a single device, enable this,
  81. * where the string is the pci device ID (as given by the kernel's
  82. * pci_name function) of the device to be used.
  83. */
  84. //#define DEBUG_SINGLE_DEVICE_ONLY "0001:11:00.0"
  85. /* If you want to enable printing of each MMIO access, enable this. */
  86. //#define DEBUG_ENABLE_MMIO_PRINT
  87. /* If you want to enable printing of MMIO access within
  88. * ucode/pcm upload, initvals write, enable this.
  89. */
  90. //#define DEBUG_ENABLE_UCODE_MMIO_PRINT
  91. /* If you want to enable printing of PCI Config Space access, enable this */
  92. //#define DEBUG_ENABLE_PCILOG
  93. static struct pci_device_id bcm43xx_pci_tbl[] = {
  94. /* Detailed list maintained at:
  95. * http://openfacts.berlios.de/index-en.phtml?title=Bcm43xxDevices
  96. */
  97. #ifdef CONFIG_BCM947XX
  98. /* SB bus on BCM947xx */
  99. { PCI_VENDOR_ID_BROADCOM, 0x0800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  100. #endif
  101. /* Broadcom 4303 802.11b */
  102. { PCI_VENDOR_ID_BROADCOM, 0x4301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  103. /* Broadcom 4307 802.11b */
  104. { PCI_VENDOR_ID_BROADCOM, 0x4307, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  105. /* Broadcom 4318 802.11b/g */
  106. { PCI_VENDOR_ID_BROADCOM, 0x4318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  107. /* Broadcom 4306 802.11b/g */
  108. { PCI_VENDOR_ID_BROADCOM, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  109. /* Broadcom 4306 802.11a */
  110. // { PCI_VENDOR_ID_BROADCOM, 0x4321, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  111. /* Broadcom 4309 802.11a/b/g */
  112. { PCI_VENDOR_ID_BROADCOM, 0x4324, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  113. /* Broadcom 43XG 802.11b/g */
  114. { PCI_VENDOR_ID_BROADCOM, 0x4325, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  115. /* required last entry */
  116. { 0, },
  117. };
  118. MODULE_DEVICE_TABLE(pci, bcm43xx_pci_tbl);
  119. static void bcm43xx_ram_write(struct bcm43xx_private *bcm, u16 offset, u32 val)
  120. {
  121. u32 status;
  122. status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  123. if (!(status & BCM43xx_SBF_XFER_REG_BYTESWAP))
  124. val = swab32(val);
  125. bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_CONTROL, offset);
  126. bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_DATA, val);
  127. }
  128. static inline
  129. void bcm43xx_shm_control_word(struct bcm43xx_private *bcm,
  130. u16 routing, u16 offset)
  131. {
  132. u32 control;
  133. /* "offset" is the WORD offset. */
  134. control = routing;
  135. control <<= 16;
  136. control |= offset;
  137. bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_CONTROL, control);
  138. }
  139. u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
  140. u16 routing, u16 offset)
  141. {
  142. u32 ret;
  143. if (routing == BCM43xx_SHM_SHARED) {
  144. if (offset & 0x0003) {
  145. /* Unaligned access */
  146. bcm43xx_shm_control_word(bcm, routing, offset >> 2);
  147. ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
  148. ret <<= 16;
  149. bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
  150. ret |= bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
  151. return ret;
  152. }
  153. offset >>= 2;
  154. }
  155. bcm43xx_shm_control_word(bcm, routing, offset);
  156. ret = bcm43xx_read32(bcm, BCM43xx_MMIO_SHM_DATA);
  157. return ret;
  158. }
  159. u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
  160. u16 routing, u16 offset)
  161. {
  162. u16 ret;
  163. if (routing == BCM43xx_SHM_SHARED) {
  164. if (offset & 0x0003) {
  165. /* Unaligned access */
  166. bcm43xx_shm_control_word(bcm, routing, offset >> 2);
  167. ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
  168. return ret;
  169. }
  170. offset >>= 2;
  171. }
  172. bcm43xx_shm_control_word(bcm, routing, offset);
  173. ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
  174. return ret;
  175. }
  176. void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
  177. u16 routing, u16 offset,
  178. u32 value)
  179. {
  180. if (routing == BCM43xx_SHM_SHARED) {
  181. if (offset & 0x0003) {
  182. /* Unaligned access */
  183. bcm43xx_shm_control_word(bcm, routing, offset >> 2);
  184. bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
  185. (value >> 16) & 0xffff);
  186. bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
  187. bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA,
  188. value & 0xffff);
  189. return;
  190. }
  191. offset >>= 2;
  192. }
  193. bcm43xx_shm_control_word(bcm, routing, offset);
  194. bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, value);
  195. }
  196. void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
  197. u16 routing, u16 offset,
  198. u16 value)
  199. {
  200. if (routing == BCM43xx_SHM_SHARED) {
  201. if (offset & 0x0003) {
  202. /* Unaligned access */
  203. bcm43xx_shm_control_word(bcm, routing, offset >> 2);
  204. bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
  205. value);
  206. return;
  207. }
  208. offset >>= 2;
  209. }
  210. bcm43xx_shm_control_word(bcm, routing, offset);
  211. bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA, value);
  212. }
  213. void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf)
  214. {
  215. /* We need to be careful. As we read the TSF from multiple
  216. * registers, we should take care of register overflows.
  217. * In theory, the whole tsf read process should be atomic.
  218. * We try to be atomic here, by restaring the read process,
  219. * if any of the high registers changed (overflew).
  220. */
  221. if (bcm->current_core->rev >= 3) {
  222. u32 low, high, high2;
  223. do {
  224. high = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
  225. low = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW);
  226. high2 = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
  227. } while (unlikely(high != high2));
  228. *tsf = high;
  229. *tsf <<= 32;
  230. *tsf |= low;
  231. } else {
  232. u64 tmp;
  233. u16 v0, v1, v2, v3;
  234. u16 test1, test2, test3;
  235. do {
  236. v3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
  237. v2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
  238. v1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
  239. v0 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_0);
  240. test3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
  241. test2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
  242. test1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
  243. } while (v3 != test3 || v2 != test2 || v1 != test1);
  244. *tsf = v3;
  245. *tsf <<= 48;
  246. tmp = v2;
  247. tmp <<= 32;
  248. *tsf |= tmp;
  249. tmp = v1;
  250. tmp <<= 16;
  251. *tsf |= tmp;
  252. *tsf |= v0;
  253. }
  254. }
  255. void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf)
  256. {
  257. u32 status;
  258. status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  259. status |= BCM43xx_SBF_TIME_UPDATE;
  260. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
  261. /* Be careful with the in-progress timer.
  262. * First zero out the low register, so we have a full
  263. * register-overflow duration to complete the operation.
  264. */
  265. if (bcm->current_core->rev >= 3) {
  266. u32 lo = (tsf & 0x00000000FFFFFFFFULL);
  267. u32 hi = (tsf & 0xFFFFFFFF00000000ULL) >> 32;
  268. barrier();
  269. bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, 0);
  270. bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH, hi);
  271. bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, lo);
  272. } else {
  273. u16 v0 = (tsf & 0x000000000000FFFFULL);
  274. u16 v1 = (tsf & 0x00000000FFFF0000ULL) >> 16;
  275. u16 v2 = (tsf & 0x0000FFFF00000000ULL) >> 32;
  276. u16 v3 = (tsf & 0xFFFF000000000000ULL) >> 48;
  277. barrier();
  278. bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, 0);
  279. bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_3, v3);
  280. bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_2, v2);
  281. bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_1, v1);
  282. bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, v0);
  283. }
  284. status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  285. status &= ~BCM43xx_SBF_TIME_UPDATE;
  286. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
  287. }
  288. static inline
  289. u8 bcm43xx_plcp_get_bitrate(struct bcm43xx_plcp_hdr4 *plcp,
  290. const int ofdm_modulation)
  291. {
  292. u8 rate;
  293. if (ofdm_modulation) {
  294. switch (plcp->raw[0] & 0xF) {
  295. case 0xB:
  296. rate = IEEE80211_OFDM_RATE_6MB;
  297. break;
  298. case 0xF:
  299. rate = IEEE80211_OFDM_RATE_9MB;
  300. break;
  301. case 0xA:
  302. rate = IEEE80211_OFDM_RATE_12MB;
  303. break;
  304. case 0xE:
  305. rate = IEEE80211_OFDM_RATE_18MB;
  306. break;
  307. case 0x9:
  308. rate = IEEE80211_OFDM_RATE_24MB;
  309. break;
  310. case 0xD:
  311. rate = IEEE80211_OFDM_RATE_36MB;
  312. break;
  313. case 0x8:
  314. rate = IEEE80211_OFDM_RATE_48MB;
  315. break;
  316. case 0xC:
  317. rate = IEEE80211_OFDM_RATE_54MB;
  318. break;
  319. default:
  320. rate = 0;
  321. assert(0);
  322. }
  323. } else {
  324. switch (plcp->raw[0]) {
  325. case 0x0A:
  326. rate = IEEE80211_CCK_RATE_1MB;
  327. break;
  328. case 0x14:
  329. rate = IEEE80211_CCK_RATE_2MB;
  330. break;
  331. case 0x37:
  332. rate = IEEE80211_CCK_RATE_5MB;
  333. break;
  334. case 0x6E:
  335. rate = IEEE80211_CCK_RATE_11MB;
  336. break;
  337. default:
  338. rate = 0;
  339. assert(0);
  340. }
  341. }
  342. return rate;
  343. }
  344. static inline
  345. u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate)
  346. {
  347. switch (bitrate) {
  348. case IEEE80211_CCK_RATE_1MB:
  349. return 0x0A;
  350. case IEEE80211_CCK_RATE_2MB:
  351. return 0x14;
  352. case IEEE80211_CCK_RATE_5MB:
  353. return 0x37;
  354. case IEEE80211_CCK_RATE_11MB:
  355. return 0x6E;
  356. }
  357. assert(0);
  358. return 0;
  359. }
  360. static inline
  361. u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate)
  362. {
  363. switch (bitrate) {
  364. case IEEE80211_OFDM_RATE_6MB:
  365. return 0xB;
  366. case IEEE80211_OFDM_RATE_9MB:
  367. return 0xF;
  368. case IEEE80211_OFDM_RATE_12MB:
  369. return 0xA;
  370. case IEEE80211_OFDM_RATE_18MB:
  371. return 0xE;
  372. case IEEE80211_OFDM_RATE_24MB:
  373. return 0x9;
  374. case IEEE80211_OFDM_RATE_36MB:
  375. return 0xD;
  376. case IEEE80211_OFDM_RATE_48MB:
  377. return 0x8;
  378. case IEEE80211_OFDM_RATE_54MB:
  379. return 0xC;
  380. }
  381. assert(0);
  382. return 0;
  383. }
  384. static void bcm43xx_generate_plcp_hdr(struct bcm43xx_plcp_hdr4 *plcp,
  385. u16 octets, const u8 bitrate,
  386. const int ofdm_modulation)
  387. {
  388. __le32 *data = &(plcp->data);
  389. __u8 *raw = plcp->raw;
  390. /* Account for hardware-appended FCS. */
  391. octets += IEEE80211_FCS_LEN;
  392. if (ofdm_modulation) {
  393. *data = bcm43xx_plcp_get_ratecode_ofdm(bitrate);
  394. assert(!(octets & 0xF000));
  395. *data |= (octets << 5);
  396. *data = cpu_to_le32(*data);
  397. } else {
  398. u32 plen;
  399. plen = octets * 16 / bitrate;
  400. if ((octets * 16 % bitrate) > 0) {
  401. plen++;
  402. if ((bitrate == IEEE80211_CCK_RATE_11MB)
  403. && ((octets * 8 % 11) < 4)) {
  404. raw[1] = 0x84;
  405. } else
  406. raw[1] = 0x04;
  407. } else
  408. raw[1] = 0x04;
  409. *data |= cpu_to_le32(plen << 16);
  410. raw[0] = bcm43xx_plcp_get_ratecode_cck(bitrate);
  411. }
  412. //bcm43xx_printk_bitdump(raw, 4, 0, "PLCP");
  413. }
  414. void fastcall
  415. bcm43xx_generate_txhdr(struct bcm43xx_private *bcm,
  416. struct bcm43xx_txhdr *txhdr,
  417. const unsigned char *fragment_data,
  418. unsigned int fragment_len,
  419. const int is_first_fragment,
  420. const u16 cookie)
  421. {
  422. const struct bcm43xx_phyinfo *phy = bcm->current_core->phy;
  423. const struct ieee80211_hdr_1addr *wireless_header = (const struct ieee80211_hdr_1addr *)fragment_data;
  424. const struct ieee80211_security *secinfo = &bcm->ieee->sec;
  425. u8 bitrate;
  426. int ofdm_modulation;
  427. u8 fallback_bitrate;
  428. int fallback_ofdm_modulation;
  429. u16 tmp;
  430. u16 encrypt_frame;
  431. /* Now construct the TX header. */
  432. memset(txhdr, 0, sizeof(*txhdr));
  433. //TODO: Some RTS/CTS stuff has to be done.
  434. //TODO: Encryption stuff.
  435. //TODO: others?
  436. bitrate = bcm->softmac->txrates.default_rate;
  437. ofdm_modulation = !(ieee80211_is_cck_rate(bitrate));
  438. fallback_bitrate = bcm->softmac->txrates.default_fallback;
  439. fallback_ofdm_modulation = !(ieee80211_is_cck_rate(fallback_bitrate));
  440. /* Set Frame Control from 80211 header. */
  441. txhdr->frame_control = wireless_header->frame_ctl;
  442. /* Copy address1 from 80211 header. */
  443. memcpy(txhdr->mac1, wireless_header->addr1, 6);
  444. /* Set the fallback duration ID. */
  445. //FIXME: We use the original durid for now.
  446. txhdr->fallback_dur_id = wireless_header->duration_id;
  447. /* Set the cookie (used as driver internal ID for the frame) */
  448. txhdr->cookie = cpu_to_le16(cookie);
  449. encrypt_frame = le16_to_cpup(&wireless_header->frame_ctl) & IEEE80211_FCTL_PROTECTED;
  450. if (encrypt_frame && !bcm->ieee->host_encrypt) {
  451. const struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)wireless_header;
  452. if (fragment_len <= sizeof(struct ieee80211_hdr_3addr)+4) {
  453. dprintkl(KERN_ERR PFX "invalid packet with PROTECTED"
  454. "flag set discarded");
  455. return;
  456. }
  457. memcpy(txhdr->wep_iv, hdr->payload, 4);
  458. /* Hardware appends ICV. */
  459. fragment_len += 4;
  460. }
  461. /* Generate the PLCP header and the fallback PLCP header. */
  462. bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->plcp),
  463. fragment_len,
  464. bitrate, ofdm_modulation);
  465. bcm43xx_generate_plcp_hdr(&txhdr->fallback_plcp, fragment_len,
  466. fallback_bitrate, fallback_ofdm_modulation);
  467. /* Set the CONTROL field */
  468. tmp = 0;
  469. if (ofdm_modulation)
  470. tmp |= BCM43xx_TXHDRCTL_OFDM;
  471. if (bcm->short_preamble) //FIXME: could be the other way around, please test
  472. tmp |= BCM43xx_TXHDRCTL_SHORT_PREAMBLE;
  473. tmp |= (phy->antenna_diversity << BCM43xx_TXHDRCTL_ANTENNADIV_SHIFT)
  474. & BCM43xx_TXHDRCTL_ANTENNADIV_MASK;
  475. txhdr->control = cpu_to_le16(tmp);
  476. /* Set the FLAGS field */
  477. tmp = 0;
  478. if (!is_multicast_ether_addr(wireless_header->addr1) &&
  479. !is_broadcast_ether_addr(wireless_header->addr1))
  480. tmp |= BCM43xx_TXHDRFLAG_EXPECTACK;
  481. if (1 /* FIXME: PS poll?? */)
  482. tmp |= 0x10; // FIXME: unknown meaning.
  483. if (fallback_ofdm_modulation)
  484. tmp |= BCM43xx_TXHDRFLAG_FALLBACKOFDM;
  485. if (is_first_fragment)
  486. tmp |= BCM43xx_TXHDRFLAG_FIRSTFRAGMENT;
  487. txhdr->flags = cpu_to_le16(tmp);
  488. /* Set WSEC/RATE field */
  489. if (encrypt_frame && !bcm->ieee->host_encrypt) {
  490. tmp = (bcm->key[secinfo->active_key].algorithm << BCM43xx_TXHDR_WSEC_ALGO_SHIFT)
  491. & BCM43xx_TXHDR_WSEC_ALGO_MASK;
  492. tmp |= (secinfo->active_key << BCM43xx_TXHDR_WSEC_KEYINDEX_SHIFT)
  493. & BCM43xx_TXHDR_WSEC_KEYINDEX_MASK;
  494. txhdr->wsec_rate = cpu_to_le16(tmp);
  495. }
  496. //bcm43xx_printk_bitdump((const unsigned char *)txhdr, sizeof(*txhdr), 1, "TX header");
  497. }
  498. static
  499. void bcm43xx_macfilter_set(struct bcm43xx_private *bcm,
  500. u16 offset,
  501. const u8 *mac)
  502. {
  503. u16 data;
  504. offset |= 0x0020;
  505. bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_CONTROL, offset);
  506. data = mac[0];
  507. data |= mac[1] << 8;
  508. bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
  509. data = mac[2];
  510. data |= mac[3] << 8;
  511. bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
  512. data = mac[4];
  513. data |= mac[5] << 8;
  514. bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
  515. }
  516. static inline
  517. void bcm43xx_macfilter_clear(struct bcm43xx_private *bcm,
  518. u16 offset)
  519. {
  520. const u8 zero_addr[ETH_ALEN] = { 0 };
  521. bcm43xx_macfilter_set(bcm, offset, zero_addr);
  522. }
  523. static void bcm43xx_write_mac_bssid_templates(struct bcm43xx_private *bcm)
  524. {
  525. const u8 *mac = (const u8 *)(bcm->net_dev->dev_addr);
  526. const u8 *bssid = (const u8 *)(bcm->ieee->bssid);
  527. u8 mac_bssid[ETH_ALEN * 2];
  528. int i;
  529. memcpy(mac_bssid, mac, ETH_ALEN);
  530. memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
  531. /* Write our MAC address and BSSID to template ram */
  532. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
  533. bcm43xx_ram_write(bcm, 0x20 + i, *((u32 *)(mac_bssid + i)));
  534. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
  535. bcm43xx_ram_write(bcm, 0x78 + i, *((u32 *)(mac_bssid + i)));
  536. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
  537. bcm43xx_ram_write(bcm, 0x478 + i, *((u32 *)(mac_bssid + i)));
  538. }
  539. static inline
  540. void bcm43xx_set_slot_time(struct bcm43xx_private *bcm, u16 slot_time)
  541. {
  542. /* slot_time is in usec. */
  543. if (bcm->current_core->phy->type != BCM43xx_PHYTYPE_G)
  544. return;
  545. bcm43xx_write16(bcm, 0x684, 510 + slot_time);
  546. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0010, slot_time);
  547. }
  548. static inline
  549. void bcm43xx_short_slot_timing_enable(struct bcm43xx_private *bcm)
  550. {
  551. bcm43xx_set_slot_time(bcm, 9);
  552. }
  553. static inline
  554. void bcm43xx_short_slot_timing_disable(struct bcm43xx_private *bcm)
  555. {
  556. bcm43xx_set_slot_time(bcm, 20);
  557. }
  558. //FIXME: rename this func?
  559. static void bcm43xx_disassociate(struct bcm43xx_private *bcm)
  560. {
  561. bcm43xx_mac_suspend(bcm);
  562. bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
  563. bcm43xx_ram_write(bcm, 0x0026, 0x0000);
  564. bcm43xx_ram_write(bcm, 0x0028, 0x0000);
  565. bcm43xx_ram_write(bcm, 0x007E, 0x0000);
  566. bcm43xx_ram_write(bcm, 0x0080, 0x0000);
  567. bcm43xx_ram_write(bcm, 0x047E, 0x0000);
  568. bcm43xx_ram_write(bcm, 0x0480, 0x0000);
  569. if (bcm->current_core->rev < 3) {
  570. bcm43xx_write16(bcm, 0x0610, 0x8000);
  571. bcm43xx_write16(bcm, 0x060E, 0x0000);
  572. } else
  573. bcm43xx_write32(bcm, 0x0188, 0x80000000);
  574. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
  575. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_G &&
  576. ieee80211_is_ofdm_rate(bcm->softmac->txrates.default_rate))
  577. bcm43xx_short_slot_timing_enable(bcm);
  578. bcm43xx_mac_enable(bcm);
  579. }
  580. //FIXME: rename this func?
  581. static void bcm43xx_associate(struct bcm43xx_private *bcm,
  582. const u8 *mac)
  583. {
  584. memcpy(bcm->ieee->bssid, mac, ETH_ALEN);
  585. bcm43xx_mac_suspend(bcm);
  586. bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_ASSOC, mac);
  587. bcm43xx_write_mac_bssid_templates(bcm);
  588. bcm43xx_mac_enable(bcm);
  589. }
  590. /* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
  591. * Returns the _previously_ enabled IRQ mask.
  592. */
  593. static inline u32 bcm43xx_interrupt_enable(struct bcm43xx_private *bcm, u32 mask)
  594. {
  595. u32 old_mask;
  596. old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
  597. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask | mask);
  598. return old_mask;
  599. }
  600. /* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
  601. * Returns the _previously_ enabled IRQ mask.
  602. */
  603. static inline u32 bcm43xx_interrupt_disable(struct bcm43xx_private *bcm, u32 mask)
  604. {
  605. u32 old_mask;
  606. old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
  607. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
  608. return old_mask;
  609. }
  610. /* Make sure we don't receive more data from the device. */
  611. static int bcm43xx_disable_interrupts_sync(struct bcm43xx_private *bcm, u32 *oldstate)
  612. {
  613. u32 old;
  614. unsigned long flags;
  615. spin_lock_irqsave(&bcm->lock, flags);
  616. if (bcm43xx_is_initializing(bcm) || bcm->shutting_down) {
  617. spin_unlock_irqrestore(&bcm->lock, flags);
  618. return -EBUSY;
  619. }
  620. old = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  621. tasklet_disable(&bcm->isr_tasklet);
  622. spin_unlock_irqrestore(&bcm->lock, flags);
  623. if (oldstate)
  624. *oldstate = old;
  625. return 0;
  626. }
  627. static int bcm43xx_read_radioinfo(struct bcm43xx_private *bcm)
  628. {
  629. u32 radio_id;
  630. u16 manufact;
  631. u16 version;
  632. u8 revision;
  633. s8 i;
  634. if (bcm->chip_id == 0x4317) {
  635. if (bcm->chip_rev == 0x00)
  636. radio_id = 0x3205017F;
  637. else if (bcm->chip_rev == 0x01)
  638. radio_id = 0x4205017F;
  639. else
  640. radio_id = 0x5205017F;
  641. } else {
  642. bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
  643. radio_id = bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_HIGH);
  644. radio_id <<= 16;
  645. bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
  646. radio_id |= bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
  647. }
  648. manufact = (radio_id & 0x00000FFF);
  649. version = (radio_id & 0x0FFFF000) >> 12;
  650. revision = (radio_id & 0xF0000000) >> 28;
  651. dprintk(KERN_INFO PFX "Detected Radio: ID: %x (Manuf: %x Ver: %x Rev: %x)\n",
  652. radio_id, manufact, version, revision);
  653. switch (bcm->current_core->phy->type) {
  654. case BCM43xx_PHYTYPE_A:
  655. if ((version != 0x2060) || (revision != 1) || (manufact != 0x17f))
  656. goto err_unsupported_radio;
  657. break;
  658. case BCM43xx_PHYTYPE_B:
  659. if ((version & 0xFFF0) != 0x2050)
  660. goto err_unsupported_radio;
  661. break;
  662. case BCM43xx_PHYTYPE_G:
  663. if (version != 0x2050)
  664. goto err_unsupported_radio;
  665. break;
  666. }
  667. bcm->current_core->radio->manufact = manufact;
  668. bcm->current_core->radio->version = version;
  669. bcm->current_core->radio->revision = revision;
  670. /* Set default attenuation values. */
  671. bcm->current_core->radio->txpower[0] = 2;
  672. bcm->current_core->radio->txpower[1] = 2;
  673. if (revision == 1)
  674. bcm->current_core->radio->txpower[2] = 3;
  675. else
  676. bcm->current_core->radio->txpower[2] = 0;
  677. /* Initialize the in-memory nrssi Lookup Table. */
  678. for (i = 0; i < 64; i++)
  679. bcm->current_core->radio->nrssi_lt[i] = i;
  680. return 0;
  681. err_unsupported_radio:
  682. printk(KERN_ERR PFX "Unsupported Radio connected to the PHY!\n");
  683. return -ENODEV;
  684. }
  685. static const char * bcm43xx_locale_iso(u8 locale)
  686. {
  687. /* ISO 3166-1 country codes.
  688. * Note that there aren't ISO 3166-1 codes for
  689. * all or locales. (Not all locales are countries)
  690. */
  691. switch (locale) {
  692. case BCM43xx_LOCALE_WORLD:
  693. case BCM43xx_LOCALE_ALL:
  694. return "XX";
  695. case BCM43xx_LOCALE_THAILAND:
  696. return "TH";
  697. case BCM43xx_LOCALE_ISRAEL:
  698. return "IL";
  699. case BCM43xx_LOCALE_JORDAN:
  700. return "JO";
  701. case BCM43xx_LOCALE_CHINA:
  702. return "CN";
  703. case BCM43xx_LOCALE_JAPAN:
  704. case BCM43xx_LOCALE_JAPAN_HIGH:
  705. return "JP";
  706. case BCM43xx_LOCALE_USA_CANADA_ANZ:
  707. case BCM43xx_LOCALE_USA_LOW:
  708. return "US";
  709. case BCM43xx_LOCALE_EUROPE:
  710. return "EU";
  711. case BCM43xx_LOCALE_NONE:
  712. return " ";
  713. }
  714. assert(0);
  715. return " ";
  716. }
  717. static const char * bcm43xx_locale_string(u8 locale)
  718. {
  719. switch (locale) {
  720. case BCM43xx_LOCALE_WORLD:
  721. return "World";
  722. case BCM43xx_LOCALE_THAILAND:
  723. return "Thailand";
  724. case BCM43xx_LOCALE_ISRAEL:
  725. return "Israel";
  726. case BCM43xx_LOCALE_JORDAN:
  727. return "Jordan";
  728. case BCM43xx_LOCALE_CHINA:
  729. return "China";
  730. case BCM43xx_LOCALE_JAPAN:
  731. return "Japan";
  732. case BCM43xx_LOCALE_USA_CANADA_ANZ:
  733. return "USA/Canada/ANZ";
  734. case BCM43xx_LOCALE_EUROPE:
  735. return "Europe";
  736. case BCM43xx_LOCALE_USA_LOW:
  737. return "USAlow";
  738. case BCM43xx_LOCALE_JAPAN_HIGH:
  739. return "JapanHigh";
  740. case BCM43xx_LOCALE_ALL:
  741. return "All";
  742. case BCM43xx_LOCALE_NONE:
  743. return "None";
  744. }
  745. assert(0);
  746. return "";
  747. }
  748. static inline u8 bcm43xx_crc8(u8 crc, u8 data)
  749. {
  750. static const u8 t[] = {
  751. 0x00, 0xF7, 0xB9, 0x4E, 0x25, 0xD2, 0x9C, 0x6B,
  752. 0x4A, 0xBD, 0xF3, 0x04, 0x6F, 0x98, 0xD6, 0x21,
  753. 0x94, 0x63, 0x2D, 0xDA, 0xB1, 0x46, 0x08, 0xFF,
  754. 0xDE, 0x29, 0x67, 0x90, 0xFB, 0x0C, 0x42, 0xB5,
  755. 0x7F, 0x88, 0xC6, 0x31, 0x5A, 0xAD, 0xE3, 0x14,
  756. 0x35, 0xC2, 0x8C, 0x7B, 0x10, 0xE7, 0xA9, 0x5E,
  757. 0xEB, 0x1C, 0x52, 0xA5, 0xCE, 0x39, 0x77, 0x80,
  758. 0xA1, 0x56, 0x18, 0xEF, 0x84, 0x73, 0x3D, 0xCA,
  759. 0xFE, 0x09, 0x47, 0xB0, 0xDB, 0x2C, 0x62, 0x95,
  760. 0xB4, 0x43, 0x0D, 0xFA, 0x91, 0x66, 0x28, 0xDF,
  761. 0x6A, 0x9D, 0xD3, 0x24, 0x4F, 0xB8, 0xF6, 0x01,
  762. 0x20, 0xD7, 0x99, 0x6E, 0x05, 0xF2, 0xBC, 0x4B,
  763. 0x81, 0x76, 0x38, 0xCF, 0xA4, 0x53, 0x1D, 0xEA,
  764. 0xCB, 0x3C, 0x72, 0x85, 0xEE, 0x19, 0x57, 0xA0,
  765. 0x15, 0xE2, 0xAC, 0x5B, 0x30, 0xC7, 0x89, 0x7E,
  766. 0x5F, 0xA8, 0xE6, 0x11, 0x7A, 0x8D, 0xC3, 0x34,
  767. 0xAB, 0x5C, 0x12, 0xE5, 0x8E, 0x79, 0x37, 0xC0,
  768. 0xE1, 0x16, 0x58, 0xAF, 0xC4, 0x33, 0x7D, 0x8A,
  769. 0x3F, 0xC8, 0x86, 0x71, 0x1A, 0xED, 0xA3, 0x54,
  770. 0x75, 0x82, 0xCC, 0x3B, 0x50, 0xA7, 0xE9, 0x1E,
  771. 0xD4, 0x23, 0x6D, 0x9A, 0xF1, 0x06, 0x48, 0xBF,
  772. 0x9E, 0x69, 0x27, 0xD0, 0xBB, 0x4C, 0x02, 0xF5,
  773. 0x40, 0xB7, 0xF9, 0x0E, 0x65, 0x92, 0xDC, 0x2B,
  774. 0x0A, 0xFD, 0xB3, 0x44, 0x2F, 0xD8, 0x96, 0x61,
  775. 0x55, 0xA2, 0xEC, 0x1B, 0x70, 0x87, 0xC9, 0x3E,
  776. 0x1F, 0xE8, 0xA6, 0x51, 0x3A, 0xCD, 0x83, 0x74,
  777. 0xC1, 0x36, 0x78, 0x8F, 0xE4, 0x13, 0x5D, 0xAA,
  778. 0x8B, 0x7C, 0x32, 0xC5, 0xAE, 0x59, 0x17, 0xE0,
  779. 0x2A, 0xDD, 0x93, 0x64, 0x0F, 0xF8, 0xB6, 0x41,
  780. 0x60, 0x97, 0xD9, 0x2E, 0x45, 0xB2, 0xFC, 0x0B,
  781. 0xBE, 0x49, 0x07, 0xF0, 0x9B, 0x6C, 0x22, 0xD5,
  782. 0xF4, 0x03, 0x4D, 0xBA, 0xD1, 0x26, 0x68, 0x9F,
  783. };
  784. return t[crc ^ data];
  785. }
  786. u8 bcm43xx_sprom_crc(const u16 *sprom)
  787. {
  788. int word;
  789. u8 crc = 0xFF;
  790. for (word = 0; word < BCM43xx_SPROM_SIZE - 1; word++) {
  791. crc = bcm43xx_crc8(crc, sprom[word] & 0x00FF);
  792. crc = bcm43xx_crc8(crc, (sprom[word] & 0xFF00) >> 8);
  793. }
  794. crc = bcm43xx_crc8(crc, sprom[BCM43xx_SPROM_VERSION] & 0x00FF);
  795. crc ^= 0xFF;
  796. return crc;
  797. }
  798. static int bcm43xx_read_sprom(struct bcm43xx_private *bcm)
  799. {
  800. int i;
  801. u16 value;
  802. u16 *sprom;
  803. u8 crc, expected_crc;
  804. #ifdef CONFIG_BCM947XX
  805. char *c;
  806. #endif
  807. sprom = kzalloc(BCM43xx_SPROM_SIZE * sizeof(u16),
  808. GFP_KERNEL);
  809. if (!sprom) {
  810. printk(KERN_ERR PFX "read_sprom OOM\n");
  811. return -ENOMEM;
  812. }
  813. #ifdef CONFIG_BCM947XX
  814. sprom[BCM43xx_SPROM_BOARDFLAGS2] = atoi(nvram_get("boardflags2"));
  815. sprom[BCM43xx_SPROM_BOARDFLAGS] = atoi(nvram_get("boardflags"));
  816. if ((c = nvram_get("il0macaddr")) != NULL)
  817. e_aton(c, (char *) &(sprom[BCM43xx_SPROM_IL0MACADDR]));
  818. if ((c = nvram_get("et1macaddr")) != NULL)
  819. e_aton(c, (char *) &(sprom[BCM43xx_SPROM_ET1MACADDR]));
  820. sprom[BCM43xx_SPROM_PA0B0] = atoi(nvram_get("pa0b0"));
  821. sprom[BCM43xx_SPROM_PA0B1] = atoi(nvram_get("pa0b1"));
  822. sprom[BCM43xx_SPROM_PA0B2] = atoi(nvram_get("pa0b2"));
  823. sprom[BCM43xx_SPROM_PA1B0] = atoi(nvram_get("pa1b0"));
  824. sprom[BCM43xx_SPROM_PA1B1] = atoi(nvram_get("pa1b1"));
  825. sprom[BCM43xx_SPROM_PA1B2] = atoi(nvram_get("pa1b2"));
  826. sprom[BCM43xx_SPROM_BOARDREV] = atoi(nvram_get("boardrev"));
  827. #else
  828. for (i = 0; i < BCM43xx_SPROM_SIZE; i++)
  829. sprom[i] = bcm43xx_read16(bcm, BCM43xx_SPROM_BASE + (i * 2));
  830. /* CRC-8 check. */
  831. crc = bcm43xx_sprom_crc(sprom);
  832. expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
  833. if (crc != expected_crc) {
  834. printk(KERN_WARNING PFX "WARNING: Invalid SPROM checksum "
  835. "(0x%02X, expected: 0x%02X)\n",
  836. crc, expected_crc);
  837. }
  838. #endif
  839. /* boardflags2 */
  840. value = sprom[BCM43xx_SPROM_BOARDFLAGS2];
  841. bcm->sprom.boardflags2 = value;
  842. /* il0macaddr */
  843. value = sprom[BCM43xx_SPROM_IL0MACADDR + 0];
  844. *(((u16 *)bcm->sprom.il0macaddr) + 0) = cpu_to_be16(value);
  845. value = sprom[BCM43xx_SPROM_IL0MACADDR + 1];
  846. *(((u16 *)bcm->sprom.il0macaddr) + 1) = cpu_to_be16(value);
  847. value = sprom[BCM43xx_SPROM_IL0MACADDR + 2];
  848. *(((u16 *)bcm->sprom.il0macaddr) + 2) = cpu_to_be16(value);
  849. /* et0macaddr */
  850. value = sprom[BCM43xx_SPROM_ET0MACADDR + 0];
  851. *(((u16 *)bcm->sprom.et0macaddr) + 0) = cpu_to_be16(value);
  852. value = sprom[BCM43xx_SPROM_ET0MACADDR + 1];
  853. *(((u16 *)bcm->sprom.et0macaddr) + 1) = cpu_to_be16(value);
  854. value = sprom[BCM43xx_SPROM_ET0MACADDR + 2];
  855. *(((u16 *)bcm->sprom.et0macaddr) + 2) = cpu_to_be16(value);
  856. /* et1macaddr */
  857. value = sprom[BCM43xx_SPROM_ET1MACADDR + 0];
  858. *(((u16 *)bcm->sprom.et1macaddr) + 0) = cpu_to_be16(value);
  859. value = sprom[BCM43xx_SPROM_ET1MACADDR + 1];
  860. *(((u16 *)bcm->sprom.et1macaddr) + 1) = cpu_to_be16(value);
  861. value = sprom[BCM43xx_SPROM_ET1MACADDR + 2];
  862. *(((u16 *)bcm->sprom.et1macaddr) + 2) = cpu_to_be16(value);
  863. /* ethernet phy settings */
  864. value = sprom[BCM43xx_SPROM_ETHPHY];
  865. bcm->sprom.et0phyaddr = (value & 0x001F);
  866. bcm->sprom.et1phyaddr = (value & 0x03E0) >> 5;
  867. bcm->sprom.et0mdcport = (value & (1 << 14)) >> 14;
  868. bcm->sprom.et1mdcport = (value & (1 << 15)) >> 15;
  869. /* boardrev, antennas, locale */
  870. value = sprom[BCM43xx_SPROM_BOARDREV];
  871. bcm->sprom.boardrev = (value & 0x00FF);
  872. bcm->sprom.locale = (value & 0x0F00) >> 8;
  873. bcm->sprom.antennas_aphy = (value & 0x3000) >> 12;
  874. bcm->sprom.antennas_bgphy = (value & 0xC000) >> 14;
  875. if (modparam_locale != -1) {
  876. if (modparam_locale >= 0 && modparam_locale <= 11) {
  877. bcm->sprom.locale = modparam_locale;
  878. printk(KERN_WARNING PFX "Operating with modified "
  879. "LocaleCode %u (%s)\n",
  880. bcm->sprom.locale,
  881. bcm43xx_locale_string(bcm->sprom.locale));
  882. } else {
  883. printk(KERN_WARNING PFX "Module parameter \"locale\" "
  884. "invalid value. (0 - 11)\n");
  885. }
  886. }
  887. /* pa0b* */
  888. value = sprom[BCM43xx_SPROM_PA0B0];
  889. bcm->sprom.pa0b0 = value;
  890. value = sprom[BCM43xx_SPROM_PA0B1];
  891. bcm->sprom.pa0b1 = value;
  892. value = sprom[BCM43xx_SPROM_PA0B2];
  893. bcm->sprom.pa0b2 = value;
  894. /* wl0gpio* */
  895. value = sprom[BCM43xx_SPROM_WL0GPIO0];
  896. if (value == 0x0000)
  897. value = 0xFFFF;
  898. bcm->sprom.wl0gpio0 = value & 0x00FF;
  899. bcm->sprom.wl0gpio1 = (value & 0xFF00) >> 8;
  900. value = sprom[BCM43xx_SPROM_WL0GPIO2];
  901. if (value == 0x0000)
  902. value = 0xFFFF;
  903. bcm->sprom.wl0gpio2 = value & 0x00FF;
  904. bcm->sprom.wl0gpio3 = (value & 0xFF00) >> 8;
  905. /* maxpower */
  906. value = sprom[BCM43xx_SPROM_MAXPWR];
  907. bcm->sprom.maxpower_aphy = (value & 0xFF00) >> 8;
  908. bcm->sprom.maxpower_bgphy = value & 0x00FF;
  909. /* pa1b* */
  910. value = sprom[BCM43xx_SPROM_PA1B0];
  911. bcm->sprom.pa1b0 = value;
  912. value = sprom[BCM43xx_SPROM_PA1B1];
  913. bcm->sprom.pa1b1 = value;
  914. value = sprom[BCM43xx_SPROM_PA1B2];
  915. bcm->sprom.pa1b2 = value;
  916. /* idle tssi target */
  917. value = sprom[BCM43xx_SPROM_IDL_TSSI_TGT];
  918. bcm->sprom.idle_tssi_tgt_aphy = value & 0x00FF;
  919. bcm->sprom.idle_tssi_tgt_bgphy = (value & 0xFF00) >> 8;
  920. /* boardflags */
  921. value = sprom[BCM43xx_SPROM_BOARDFLAGS];
  922. if (value == 0xFFFF)
  923. value = 0x0000;
  924. bcm->sprom.boardflags = value;
  925. /* antenna gain */
  926. value = sprom[BCM43xx_SPROM_ANTENNA_GAIN];
  927. if (value == 0x0000 || value == 0xFFFF)
  928. value = 0x0202;
  929. /* convert values to Q5.2 */
  930. bcm->sprom.antennagain_aphy = ((value & 0xFF00) >> 8) * 4;
  931. bcm->sprom.antennagain_bgphy = (value & 0x00FF) * 4;
  932. kfree(sprom);
  933. return 0;
  934. }
  935. static int bcm43xx_channel_is_allowed(struct bcm43xx_private *bcm, u8 channel,
  936. u8 *max_power, u8 *flags)
  937. {
  938. /* THIS FUNCTION DOES _NOT_ ENFORCE REGULATORY DOMAIN COMPLIANCE.
  939. * It is only a helper function to make life easier to
  940. * select legal channels and transmission powers.
  941. */
  942. u8 phytype = bcm->current_core->phy->type;
  943. int allowed = 0;
  944. *max_power = 0;
  945. *flags = 0;
  946. //FIXME: Set max_power and maybe flags
  947. /*FIXME: Allowed channels are sometimes different for outdoor
  948. * or indoor use. See modparam_outdoor.
  949. */
  950. /* From b specs Max Power BPHY:
  951. * USA: 1000mW
  952. * Europe: 100mW
  953. * Japan: 10mW/MHz
  954. */
  955. switch (bcm->sprom.locale) {
  956. case BCM43xx_LOCALE_WORLD:
  957. if (phytype == BCM43xx_PHYTYPE_A) {
  958. allowed = 1;//FIXME
  959. } else if (phytype == BCM43xx_PHYTYPE_B) {
  960. if (channel >= 1 && channel <= 13)
  961. allowed = 1;
  962. } else {
  963. if (channel >= 1 && channel <= 13)
  964. allowed = 1;
  965. }
  966. break;
  967. case BCM43xx_LOCALE_THAILAND:
  968. if (phytype == BCM43xx_PHYTYPE_A) {
  969. allowed = 1;//FIXME
  970. } else if (phytype == BCM43xx_PHYTYPE_B) {
  971. if (channel >= 1 && channel <= 14)
  972. allowed = 1;
  973. } else {
  974. if (channel >= 1 && channel <= 14)
  975. allowed = 1;
  976. }
  977. break;
  978. case BCM43xx_LOCALE_ISRAEL:
  979. if (phytype == BCM43xx_PHYTYPE_A) {
  980. allowed = 1;//FIXME
  981. } else if (phytype == BCM43xx_PHYTYPE_B) {
  982. if (channel >= 5 && channel <= 7)
  983. allowed = 1;
  984. } else {
  985. if (channel >= 5 && channel <= 7)
  986. allowed = 1;
  987. }
  988. break;
  989. case BCM43xx_LOCALE_JORDAN:
  990. if (phytype == BCM43xx_PHYTYPE_A) {
  991. allowed = 1;//FIXME
  992. } else if (phytype == BCM43xx_PHYTYPE_B) {
  993. if (channel >= 10 && channel <= 13)
  994. allowed = 1;
  995. } else {
  996. if (channel >= 10 && channel <= 13)
  997. allowed = 1;
  998. }
  999. break;
  1000. case BCM43xx_LOCALE_CHINA:
  1001. if (phytype == BCM43xx_PHYTYPE_A) {
  1002. allowed = 1;//FIXME
  1003. } else if (phytype == BCM43xx_PHYTYPE_B) {
  1004. if (channel >= 1 && channel <= 13)
  1005. allowed = 1;
  1006. } else {
  1007. if (channel >= 1 && channel <= 13)
  1008. allowed = 1;
  1009. }
  1010. break;
  1011. case BCM43xx_LOCALE_JAPAN:
  1012. if (phytype == BCM43xx_PHYTYPE_A) {
  1013. allowed = 1;//FIXME
  1014. } else if (phytype == BCM43xx_PHYTYPE_B) {
  1015. //FIXME: This seems to be wrong.
  1016. if (channel >= 1 && channel <= 14)
  1017. allowed = 1;
  1018. } else {
  1019. //FIXME: This seems to be wrong.
  1020. if (channel >= 1 && channel <= 14)
  1021. allowed = 1;
  1022. }
  1023. break;
  1024. case BCM43xx_LOCALE_USA_CANADA_ANZ:
  1025. if (phytype == BCM43xx_PHYTYPE_A) {
  1026. allowed = 1;//FIXME
  1027. } else if (phytype == BCM43xx_PHYTYPE_B) {
  1028. if (channel >= 1 && channel <= 13)
  1029. allowed = 1;
  1030. } else {
  1031. if (channel >= 1 && channel <= 11)
  1032. allowed = 1;
  1033. }
  1034. break;
  1035. case BCM43xx_LOCALE_EUROPE:
  1036. if (phytype == BCM43xx_PHYTYPE_A) {
  1037. allowed = 1;//FIXME
  1038. } else if (phytype == BCM43xx_PHYTYPE_B) {
  1039. if (channel >= 1 && channel <= 13)
  1040. allowed = 1;
  1041. } else {
  1042. if (channel >= 1 && channel <= 13)
  1043. allowed = 1;
  1044. }
  1045. break;
  1046. case BCM43xx_LOCALE_USA_LOW:
  1047. if (phytype == BCM43xx_PHYTYPE_A) {
  1048. allowed = 1;//FIXME
  1049. } else if (phytype == BCM43xx_PHYTYPE_B) {
  1050. if (channel >= 1 && channel <= 13)
  1051. allowed = 1;
  1052. } else {
  1053. if (channel >= 1 && channel <= 11)
  1054. allowed = 1;
  1055. }
  1056. break;
  1057. case BCM43xx_LOCALE_JAPAN_HIGH:
  1058. if (phytype == BCM43xx_PHYTYPE_A) {
  1059. allowed = 1;//FIXME
  1060. } else if (phytype == BCM43xx_PHYTYPE_B) {
  1061. //FIXME?
  1062. if (channel >= 1 && channel <= 14)
  1063. allowed = 1;
  1064. } else {
  1065. if (channel >= 1 && channel <= 14)
  1066. allowed = 1;
  1067. }
  1068. break;
  1069. case BCM43xx_LOCALE_ALL:
  1070. allowed = 1;
  1071. break;
  1072. case BCM43xx_LOCALE_NONE:
  1073. break;
  1074. default:
  1075. assert(0);
  1076. }
  1077. return allowed;
  1078. }
  1079. static void bcm43xx_geo_init(struct bcm43xx_private *bcm)
  1080. {
  1081. struct ieee80211_geo geo;
  1082. struct ieee80211_channel *chan;
  1083. int have_a = 0, have_bg = 0;
  1084. int i, num80211;
  1085. u8 channel, flags, max_power;
  1086. struct bcm43xx_phyinfo *phy;
  1087. const char *iso_country;
  1088. memset(&geo, 0, sizeof(geo));
  1089. num80211 = bcm43xx_num_80211_cores(bcm);
  1090. for (i = 0; i < num80211; i++) {
  1091. phy = bcm->phy + i;
  1092. switch (phy->type) {
  1093. case BCM43xx_PHYTYPE_B:
  1094. case BCM43xx_PHYTYPE_G:
  1095. have_bg = 1;
  1096. break;
  1097. case BCM43xx_PHYTYPE_A:
  1098. have_a = 1;
  1099. break;
  1100. default:
  1101. assert(0);
  1102. }
  1103. }
  1104. iso_country = bcm43xx_locale_iso(bcm->sprom.locale);
  1105. if (have_a) {
  1106. for (i = 0, channel = 0; channel < 201; channel++) {
  1107. if (!bcm43xx_channel_is_allowed(bcm, channel,
  1108. &max_power, &flags))
  1109. continue;
  1110. chan = &geo.a[i++];
  1111. chan->freq = bcm43xx_channel_to_freq(bcm, channel);
  1112. chan->channel = channel;
  1113. chan->flags = flags;
  1114. chan->max_power = max_power;
  1115. }
  1116. geo.a_channels = i;
  1117. }
  1118. if (have_bg) {
  1119. for (i = 0, channel = 1; channel < 15; channel++) {
  1120. if (!bcm43xx_channel_is_allowed(bcm, channel,
  1121. &max_power, &flags))
  1122. continue;
  1123. chan = &geo.bg[i++];
  1124. chan->freq = bcm43xx_channel_to_freq(bcm, channel);
  1125. chan->channel = channel;
  1126. chan->flags = flags;
  1127. chan->max_power = max_power;
  1128. }
  1129. geo.bg_channels = i;
  1130. }
  1131. memcpy(geo.name, iso_country, 2);
  1132. if (0 /*TODO: Outdoor use only */)
  1133. geo.name[2] = 'O';
  1134. else if (0 /*TODO: Indoor use only */)
  1135. geo.name[2] = 'I';
  1136. else
  1137. geo.name[2] = ' ';
  1138. geo.name[3] = '\0';
  1139. ieee80211_set_geo(bcm->ieee, &geo);
  1140. }
  1141. /* DummyTransmission function, as documented on
  1142. * http://bcm-specs.sipsolutions.net/DummyTransmission
  1143. */
  1144. void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm)
  1145. {
  1146. unsigned int i, max_loop;
  1147. u16 value = 0;
  1148. u32 buffer[5] = {
  1149. 0x00000000,
  1150. 0x0000D400,
  1151. 0x00000000,
  1152. 0x00000001,
  1153. 0x00000000,
  1154. };
  1155. switch (bcm->current_core->phy->type) {
  1156. case BCM43xx_PHYTYPE_A:
  1157. max_loop = 0x1E;
  1158. buffer[0] = 0xCC010200;
  1159. break;
  1160. case BCM43xx_PHYTYPE_B:
  1161. case BCM43xx_PHYTYPE_G:
  1162. max_loop = 0xFA;
  1163. buffer[0] = 0x6E840B00;
  1164. break;
  1165. default:
  1166. assert(0);
  1167. return;
  1168. }
  1169. for (i = 0; i < 5; i++)
  1170. bcm43xx_ram_write(bcm, i * 4, buffer[i]);
  1171. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
  1172. bcm43xx_write16(bcm, 0x0568, 0x0000);
  1173. bcm43xx_write16(bcm, 0x07C0, 0x0000);
  1174. bcm43xx_write16(bcm, 0x050C, ((bcm->current_core->phy->type == BCM43xx_PHYTYPE_A) ? 1 : 0));
  1175. bcm43xx_write16(bcm, 0x0508, 0x0000);
  1176. bcm43xx_write16(bcm, 0x050A, 0x0000);
  1177. bcm43xx_write16(bcm, 0x054C, 0x0000);
  1178. bcm43xx_write16(bcm, 0x056A, 0x0014);
  1179. bcm43xx_write16(bcm, 0x0568, 0x0826);
  1180. bcm43xx_write16(bcm, 0x0500, 0x0000);
  1181. bcm43xx_write16(bcm, 0x0502, 0x0030);
  1182. for (i = 0x00; i < max_loop; i++) {
  1183. value = bcm43xx_read16(bcm, 0x050E);
  1184. if ((value & 0x0080) != 0)
  1185. break;
  1186. udelay(10);
  1187. }
  1188. for (i = 0x00; i < 0x0A; i++) {
  1189. value = bcm43xx_read16(bcm, 0x050E);
  1190. if ((value & 0x0400) != 0)
  1191. break;
  1192. udelay(10);
  1193. }
  1194. for (i = 0x00; i < 0x0A; i++) {
  1195. value = bcm43xx_read16(bcm, 0x0690);
  1196. if ((value & 0x0100) == 0)
  1197. break;
  1198. udelay(10);
  1199. }
  1200. }
  1201. static void key_write(struct bcm43xx_private *bcm,
  1202. u8 index, u8 algorithm, const u16 *key)
  1203. {
  1204. unsigned int i, basic_wep = 0;
  1205. u32 offset;
  1206. u16 value;
  1207. /* Write associated key information */
  1208. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x100 + (index * 2),
  1209. ((index << 4) | (algorithm & 0x0F)));
  1210. /* The first 4 WEP keys need extra love */
  1211. if (((algorithm == BCM43xx_SEC_ALGO_WEP) ||
  1212. (algorithm == BCM43xx_SEC_ALGO_WEP104)) && (index < 4))
  1213. basic_wep = 1;
  1214. /* Write key payload, 8 little endian words */
  1215. offset = bcm->security_offset + (index * BCM43xx_SEC_KEYSIZE);
  1216. for (i = 0; i < (BCM43xx_SEC_KEYSIZE / sizeof(u16)); i++) {
  1217. value = cpu_to_le16(key[i]);
  1218. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
  1219. offset + (i * 2), value);
  1220. if (!basic_wep)
  1221. continue;
  1222. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
  1223. offset + (i * 2) + 4 * BCM43xx_SEC_KEYSIZE,
  1224. value);
  1225. }
  1226. }
  1227. static void keymac_write(struct bcm43xx_private *bcm,
  1228. u8 index, const u32 *addr)
  1229. {
  1230. /* for keys 0-3 there is no associated mac address */
  1231. if (index < 4)
  1232. return;
  1233. index -= 4;
  1234. if (bcm->current_core->rev >= 5) {
  1235. bcm43xx_shm_write32(bcm,
  1236. BCM43xx_SHM_HWMAC,
  1237. index * 2,
  1238. cpu_to_be32(*addr));
  1239. bcm43xx_shm_write16(bcm,
  1240. BCM43xx_SHM_HWMAC,
  1241. (index * 2) + 1,
  1242. cpu_to_be16(*((u16 *)(addr + 1))));
  1243. } else {
  1244. if (index < 8) {
  1245. TODO(); /* Put them in the macaddress filter */
  1246. } else {
  1247. TODO();
  1248. /* Put them BCM43xx_SHM_SHARED, stating index 0x0120.
  1249. Keep in mind to update the count of keymacs in 0x003E as well! */
  1250. }
  1251. }
  1252. }
  1253. static int bcm43xx_key_write(struct bcm43xx_private *bcm,
  1254. u8 index, u8 algorithm,
  1255. const u8 *_key, int key_len,
  1256. const u8 *mac_addr)
  1257. {
  1258. u8 key[BCM43xx_SEC_KEYSIZE] = { 0 };
  1259. if (index >= ARRAY_SIZE(bcm->key))
  1260. return -EINVAL;
  1261. if (key_len > ARRAY_SIZE(key))
  1262. return -EINVAL;
  1263. if (algorithm < 1 || algorithm > 5)
  1264. return -EINVAL;
  1265. memcpy(key, _key, key_len);
  1266. key_write(bcm, index, algorithm, (const u16 *)key);
  1267. keymac_write(bcm, index, (const u32 *)mac_addr);
  1268. bcm->key[index].algorithm = algorithm;
  1269. return 0;
  1270. }
  1271. static void bcm43xx_clear_keys(struct bcm43xx_private *bcm)
  1272. {
  1273. static const u32 zero_mac[2] = { 0 };
  1274. unsigned int i,j, nr_keys = 54;
  1275. u16 offset;
  1276. if (bcm->current_core->rev < 5)
  1277. nr_keys = 16;
  1278. assert(nr_keys <= ARRAY_SIZE(bcm->key));
  1279. for (i = 0; i < nr_keys; i++) {
  1280. bcm->key[i].enabled = 0;
  1281. /* returns for i < 4 immediately */
  1282. keymac_write(bcm, i, zero_mac);
  1283. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
  1284. 0x100 + (i * 2), 0x0000);
  1285. for (j = 0; j < 8; j++) {
  1286. offset = bcm->security_offset + (j * 4) + (i * BCM43xx_SEC_KEYSIZE);
  1287. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
  1288. offset, 0x0000);
  1289. }
  1290. }
  1291. dprintk(KERN_INFO PFX "Keys cleared\n");
  1292. }
  1293. /* Puts the index of the current core into user supplied core variable.
  1294. * This function reads the value from the device.
  1295. * Almost always you don't want to call this, but use bcm->current_core
  1296. */
  1297. static inline
  1298. int _get_current_core(struct bcm43xx_private *bcm, int *core)
  1299. {
  1300. int err;
  1301. err = bcm43xx_pci_read_config32(bcm, BCM43xx_REG_ACTIVE_CORE, core);
  1302. if (unlikely(err)) {
  1303. dprintk(KERN_ERR PFX "BCM43xx_REG_ACTIVE_CORE read failed!\n");
  1304. return -ENODEV;
  1305. }
  1306. *core = (*core - 0x18000000) / 0x1000;
  1307. return 0;
  1308. }
  1309. /* Lowlevel core-switch function. This is only to be used in
  1310. * bcm43xx_switch_core() and bcm43xx_probe_cores()
  1311. */
  1312. static int _switch_core(struct bcm43xx_private *bcm, int core)
  1313. {
  1314. int err;
  1315. int attempts = 0;
  1316. int current_core = -1;
  1317. assert(core >= 0);
  1318. err = _get_current_core(bcm, &current_core);
  1319. if (unlikely(err))
  1320. goto out;
  1321. /* Write the computed value to the register. This doesn't always
  1322. succeed so we retry BCM43xx_SWITCH_CORE_MAX_RETRIES times */
  1323. while (current_core != core) {
  1324. if (unlikely(attempts++ > BCM43xx_SWITCH_CORE_MAX_RETRIES)) {
  1325. err = -ENODEV;
  1326. printk(KERN_ERR PFX
  1327. "unable to switch to core %u, retried %i times\n",
  1328. core, attempts);
  1329. goto out;
  1330. }
  1331. err = bcm43xx_pci_write_config32(bcm, BCM43xx_REG_ACTIVE_CORE,
  1332. (core * 0x1000) + 0x18000000);
  1333. if (unlikely(err)) {
  1334. dprintk(KERN_ERR PFX "BCM43xx_REG_ACTIVE_CORE write failed!\n");
  1335. continue;
  1336. }
  1337. _get_current_core(bcm, &current_core);
  1338. #ifdef CONFIG_BCM947XX
  1339. if (bcm->pci_dev->bus->number == 0)
  1340. bcm->current_core_offset = 0x1000 * core;
  1341. else
  1342. bcm->current_core_offset = 0;
  1343. #endif
  1344. }
  1345. assert(err == 0);
  1346. out:
  1347. return err;
  1348. }
  1349. int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core)
  1350. {
  1351. int err;
  1352. if (!new_core)
  1353. return 0;
  1354. if (!(new_core->flags & BCM43xx_COREFLAG_AVAILABLE))
  1355. return -ENODEV;
  1356. if (bcm->current_core == new_core)
  1357. return 0;
  1358. err = _switch_core(bcm, new_core->index);
  1359. if (!err)
  1360. bcm->current_core = new_core;
  1361. return err;
  1362. }
  1363. static inline int bcm43xx_core_enabled(struct bcm43xx_private *bcm)
  1364. {
  1365. u32 value;
  1366. value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1367. value &= BCM43xx_SBTMSTATELOW_CLOCK | BCM43xx_SBTMSTATELOW_RESET
  1368. | BCM43xx_SBTMSTATELOW_REJECT;
  1369. return (value == BCM43xx_SBTMSTATELOW_CLOCK);
  1370. }
  1371. /* disable current core */
  1372. static int bcm43xx_core_disable(struct bcm43xx_private *bcm, u32 core_flags)
  1373. {
  1374. u32 sbtmstatelow;
  1375. u32 sbtmstatehigh;
  1376. int i;
  1377. /* fetch sbtmstatelow from core information registers */
  1378. sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1379. /* core is already in reset */
  1380. if (sbtmstatelow & BCM43xx_SBTMSTATELOW_RESET)
  1381. goto out;
  1382. if (sbtmstatelow & BCM43xx_SBTMSTATELOW_CLOCK) {
  1383. sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
  1384. BCM43xx_SBTMSTATELOW_REJECT;
  1385. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1386. for (i = 0; i < 1000; i++) {
  1387. sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1388. if (sbtmstatelow & BCM43xx_SBTMSTATELOW_REJECT) {
  1389. i = -1;
  1390. break;
  1391. }
  1392. udelay(10);
  1393. }
  1394. if (i != -1) {
  1395. printk(KERN_ERR PFX "Error: core_disable() REJECT timeout!\n");
  1396. return -EBUSY;
  1397. }
  1398. for (i = 0; i < 1000; i++) {
  1399. sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
  1400. if (!(sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_BUSY)) {
  1401. i = -1;
  1402. break;
  1403. }
  1404. udelay(10);
  1405. }
  1406. if (i != -1) {
  1407. printk(KERN_ERR PFX "Error: core_disable() BUSY timeout!\n");
  1408. return -EBUSY;
  1409. }
  1410. sbtmstatelow = BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
  1411. BCM43xx_SBTMSTATELOW_REJECT |
  1412. BCM43xx_SBTMSTATELOW_RESET |
  1413. BCM43xx_SBTMSTATELOW_CLOCK |
  1414. core_flags;
  1415. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1416. udelay(10);
  1417. }
  1418. sbtmstatelow = BCM43xx_SBTMSTATELOW_RESET |
  1419. BCM43xx_SBTMSTATELOW_REJECT |
  1420. core_flags;
  1421. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1422. out:
  1423. bcm->current_core->flags &= ~ BCM43xx_COREFLAG_ENABLED;
  1424. return 0;
  1425. }
  1426. /* enable (reset) current core */
  1427. static int bcm43xx_core_enable(struct bcm43xx_private *bcm, u32 core_flags)
  1428. {
  1429. u32 sbtmstatelow;
  1430. u32 sbtmstatehigh;
  1431. u32 sbimstate;
  1432. int err;
  1433. err = bcm43xx_core_disable(bcm, core_flags);
  1434. if (err)
  1435. goto out;
  1436. sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
  1437. BCM43xx_SBTMSTATELOW_RESET |
  1438. BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
  1439. core_flags;
  1440. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1441. udelay(1);
  1442. sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
  1443. if (sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_SERROR) {
  1444. sbtmstatehigh = 0x00000000;
  1445. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATEHIGH, sbtmstatehigh);
  1446. }
  1447. sbimstate = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMSTATE);
  1448. if (sbimstate & (BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT)) {
  1449. sbimstate &= ~(BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT);
  1450. bcm43xx_write32(bcm, BCM43xx_CIR_SBIMSTATE, sbimstate);
  1451. }
  1452. sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
  1453. BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
  1454. core_flags;
  1455. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1456. udelay(1);
  1457. sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK | core_flags;
  1458. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1459. udelay(1);
  1460. bcm->current_core->flags |= BCM43xx_COREFLAG_ENABLED;
  1461. assert(err == 0);
  1462. out:
  1463. return err;
  1464. }
  1465. /* http://bcm-specs.sipsolutions.net/80211CoreReset */
  1466. void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy)
  1467. {
  1468. u32 flags = 0x00040000;
  1469. if ((bcm43xx_core_enabled(bcm)) && (!bcm->pio_mode)) {
  1470. //FIXME: Do we _really_ want #ifndef CONFIG_BCM947XX here?
  1471. #ifndef CONFIG_BCM947XX
  1472. /* reset all used DMA controllers. */
  1473. bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
  1474. bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA2_BASE);
  1475. bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA3_BASE);
  1476. bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
  1477. bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
  1478. if (bcm->current_core->rev < 5)
  1479. bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
  1480. #endif
  1481. }
  1482. if (bcm->shutting_down) {
  1483. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  1484. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
  1485. & ~(BCM43xx_SBF_MAC_ENABLED | 0x00000002));
  1486. } else {
  1487. if (connect_phy)
  1488. flags |= 0x20000000;
  1489. bcm43xx_phy_connect(bcm, connect_phy);
  1490. bcm43xx_core_enable(bcm, flags);
  1491. bcm43xx_write16(bcm, 0x03E6, 0x0000);
  1492. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  1493. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
  1494. | BCM43xx_SBF_400);
  1495. }
  1496. }
  1497. static void bcm43xx_wireless_core_disable(struct bcm43xx_private *bcm)
  1498. {
  1499. bcm43xx_radio_turn_off(bcm);
  1500. bcm43xx_write16(bcm, 0x03E6, 0x00F4);
  1501. bcm43xx_core_disable(bcm, 0);
  1502. }
  1503. /* Mark the current 80211 core inactive.
  1504. * "active_80211_core" is the other 80211 core, which is used.
  1505. */
  1506. static int bcm43xx_wireless_core_mark_inactive(struct bcm43xx_private *bcm,
  1507. struct bcm43xx_coreinfo *active_80211_core)
  1508. {
  1509. u32 sbtmstatelow;
  1510. struct bcm43xx_coreinfo *old_core;
  1511. int err = 0;
  1512. bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  1513. bcm43xx_radio_turn_off(bcm);
  1514. sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1515. sbtmstatelow &= ~0x200a0000;
  1516. sbtmstatelow |= 0xa0000;
  1517. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1518. udelay(1);
  1519. sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1520. sbtmstatelow &= ~0xa0000;
  1521. sbtmstatelow |= 0x80000;
  1522. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1523. udelay(1);
  1524. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_G) {
  1525. old_core = bcm->current_core;
  1526. err = bcm43xx_switch_core(bcm, active_80211_core);
  1527. if (err)
  1528. goto out;
  1529. sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1530. sbtmstatelow &= ~0x20000000;
  1531. sbtmstatelow |= 0x20000000;
  1532. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1533. err = bcm43xx_switch_core(bcm, old_core);
  1534. }
  1535. out:
  1536. return err;
  1537. }
  1538. static inline void handle_irq_transmit_status(struct bcm43xx_private *bcm)
  1539. {
  1540. u32 v0, v1;
  1541. u16 tmp;
  1542. struct bcm43xx_xmitstatus stat;
  1543. assert(bcm->current_core->id == BCM43xx_COREID_80211);
  1544. assert(bcm->current_core->rev >= 5);
  1545. while (1) {
  1546. v0 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_0);
  1547. if (!v0)
  1548. break;
  1549. v1 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_1);
  1550. stat.cookie = (v0 >> 16) & 0x0000FFFF;
  1551. tmp = (u16)((v0 & 0xFFF0) | ((v0 & 0xF) >> 1));
  1552. stat.flags = tmp & 0xFF;
  1553. stat.cnt1 = (tmp & 0x0F00) >> 8;
  1554. stat.cnt2 = (tmp & 0xF000) >> 12;
  1555. stat.seq = (u16)(v1 & 0xFFFF);
  1556. stat.unknown = (u16)((v1 >> 16) & 0xFF);
  1557. bcm43xx_debugfs_log_txstat(bcm, &stat);
  1558. if (stat.flags & BCM43xx_TXSTAT_FLAG_IGNORE)
  1559. continue;
  1560. if (!(stat.flags & BCM43xx_TXSTAT_FLAG_ACK)) {
  1561. //TODO: packet was not acked (was lost)
  1562. }
  1563. //TODO: There are more (unknown) flags to test. see bcm43xx_main.h
  1564. if (bcm->pio_mode)
  1565. bcm43xx_pio_handle_xmitstatus(bcm, &stat);
  1566. else
  1567. bcm43xx_dma_handle_xmitstatus(bcm, &stat);
  1568. }
  1569. }
  1570. static inline void bcm43xx_generate_noise_sample(struct bcm43xx_private *bcm)
  1571. {
  1572. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x408, 0x7F7F);
  1573. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x40A, 0x7F7F);
  1574. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
  1575. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD) | (1 << 4));
  1576. assert(bcm->noisecalc.core_at_start == bcm->current_core);
  1577. assert(bcm->noisecalc.channel_at_start == bcm->current_core->radio->channel);
  1578. }
  1579. static void bcm43xx_calculate_link_quality(struct bcm43xx_private *bcm)
  1580. {
  1581. /* Top half of Link Quality calculation. */
  1582. if (bcm->noisecalc.calculation_running)
  1583. return;
  1584. bcm->noisecalc.core_at_start = bcm->current_core;
  1585. bcm->noisecalc.channel_at_start = bcm->current_core->radio->channel;
  1586. bcm->noisecalc.calculation_running = 1;
  1587. bcm->noisecalc.nr_samples = 0;
  1588. bcm43xx_generate_noise_sample(bcm);
  1589. }
  1590. static inline void handle_irq_noise(struct bcm43xx_private *bcm)
  1591. {
  1592. struct bcm43xx_radioinfo *radio = bcm->current_core->radio;
  1593. u16 tmp;
  1594. u8 noise[4];
  1595. u8 i, j;
  1596. s32 average;
  1597. /* Bottom half of Link Quality calculation. */
  1598. assert(bcm->noisecalc.calculation_running);
  1599. if (bcm->noisecalc.core_at_start != bcm->current_core ||
  1600. bcm->noisecalc.channel_at_start != radio->channel)
  1601. goto drop_calculation;
  1602. tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x408);
  1603. noise[0] = (tmp & 0x00FF);
  1604. noise[1] = (tmp & 0xFF00) >> 8;
  1605. tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40A);
  1606. noise[2] = (tmp & 0x00FF);
  1607. noise[3] = (tmp & 0xFF00) >> 8;
  1608. if (noise[0] == 0x7F || noise[1] == 0x7F ||
  1609. noise[2] == 0x7F || noise[3] == 0x7F)
  1610. goto generate_new;
  1611. /* Get the noise samples. */
  1612. assert(bcm->noisecalc.nr_samples <= 8);
  1613. i = bcm->noisecalc.nr_samples;
  1614. noise[0] = limit_value(noise[0], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
  1615. noise[1] = limit_value(noise[1], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
  1616. noise[2] = limit_value(noise[2], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
  1617. noise[3] = limit_value(noise[3], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
  1618. bcm->noisecalc.samples[i][0] = radio->nrssi_lt[noise[0]];
  1619. bcm->noisecalc.samples[i][1] = radio->nrssi_lt[noise[1]];
  1620. bcm->noisecalc.samples[i][2] = radio->nrssi_lt[noise[2]];
  1621. bcm->noisecalc.samples[i][3] = radio->nrssi_lt[noise[3]];
  1622. bcm->noisecalc.nr_samples++;
  1623. if (bcm->noisecalc.nr_samples == 8) {
  1624. /* Calculate the Link Quality by the noise samples. */
  1625. average = 0;
  1626. for (i = 0; i < 8; i++) {
  1627. for (j = 0; j < 4; j++)
  1628. average += bcm->noisecalc.samples[i][j];
  1629. }
  1630. average /= (8 * 4);
  1631. average *= 125;
  1632. average += 64;
  1633. average /= 128;
  1634. tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40C);
  1635. tmp = (tmp / 128) & 0x1F;
  1636. if (tmp >= 8)
  1637. average += 2;
  1638. else
  1639. average -= 25;
  1640. if (tmp == 8)
  1641. average -= 72;
  1642. else
  1643. average -= 48;
  1644. if (average > -65)
  1645. bcm->stats.link_quality = 0;
  1646. else if (average > -75)
  1647. bcm->stats.link_quality = 1;
  1648. else if (average > -85)
  1649. bcm->stats.link_quality = 2;
  1650. else
  1651. bcm->stats.link_quality = 3;
  1652. // dprintk(KERN_INFO PFX "Link Quality: %u (avg was %d)\n", bcm->stats.link_quality, average);
  1653. drop_calculation:
  1654. bcm->noisecalc.calculation_running = 0;
  1655. return;
  1656. }
  1657. generate_new:
  1658. bcm43xx_generate_noise_sample(bcm);
  1659. }
  1660. static inline
  1661. void handle_irq_ps(struct bcm43xx_private *bcm)
  1662. {
  1663. if (bcm->ieee->iw_mode == IW_MODE_MASTER) {
  1664. ///TODO: PS TBTT
  1665. } else {
  1666. if (1/*FIXME: the last PSpoll frame was sent successfully */)
  1667. bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
  1668. }
  1669. if (bcm->ieee->iw_mode == IW_MODE_ADHOC)
  1670. bcm->reg124_set_0x4 = 1;
  1671. //FIXME else set to false?
  1672. }
  1673. static inline
  1674. void handle_irq_reg124(struct bcm43xx_private *bcm)
  1675. {
  1676. if (!bcm->reg124_set_0x4)
  1677. return;
  1678. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
  1679. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD)
  1680. | 0x4);
  1681. //FIXME: reset reg124_set_0x4 to false?
  1682. }
  1683. static inline
  1684. void handle_irq_pmq(struct bcm43xx_private *bcm)
  1685. {
  1686. u32 tmp;
  1687. //TODO: AP mode.
  1688. while (1) {
  1689. tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_PS_STATUS);
  1690. if (!(tmp & 0x00000008))
  1691. break;
  1692. }
  1693. /* 16bit write is odd, but correct. */
  1694. bcm43xx_write16(bcm, BCM43xx_MMIO_PS_STATUS, 0x0002);
  1695. }
  1696. static void bcm43xx_generate_beacon_template(struct bcm43xx_private *bcm,
  1697. u16 ram_offset, u16 shm_size_offset)
  1698. {
  1699. u32 value;
  1700. u16 size = 0;
  1701. /* Timestamp. */
  1702. //FIXME: assumption: The chip sets the timestamp
  1703. value = 0;
  1704. bcm43xx_ram_write(bcm, ram_offset++, value);
  1705. bcm43xx_ram_write(bcm, ram_offset++, value);
  1706. size += 8;
  1707. /* Beacon Interval / Capability Information */
  1708. value = 0x0000;//FIXME: Which interval?
  1709. value |= (1 << 0) << 16; /* ESS */
  1710. value |= (1 << 2) << 16; /* CF Pollable */ //FIXME?
  1711. value |= (1 << 3) << 16; /* CF Poll Request */ //FIXME?
  1712. if (!bcm->ieee->open_wep)
  1713. value |= (1 << 4) << 16; /* Privacy */
  1714. bcm43xx_ram_write(bcm, ram_offset++, value);
  1715. size += 4;
  1716. /* SSID */
  1717. //TODO
  1718. /* FH Parameter Set */
  1719. //TODO
  1720. /* DS Parameter Set */
  1721. //TODO
  1722. /* CF Parameter Set */
  1723. //TODO
  1724. /* TIM */
  1725. //TODO
  1726. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, shm_size_offset, size);
  1727. }
  1728. static inline
  1729. void handle_irq_beacon(struct bcm43xx_private *bcm)
  1730. {
  1731. u32 status;
  1732. bcm->irq_savedstate &= ~BCM43xx_IRQ_BEACON;
  1733. status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD);
  1734. if ((status & 0x1) && (status & 0x2)) {
  1735. /* ACK beacon IRQ. */
  1736. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON,
  1737. BCM43xx_IRQ_BEACON);
  1738. bcm->irq_savedstate |= BCM43xx_IRQ_BEACON;
  1739. return;
  1740. }
  1741. if (!(status & 0x1)) {
  1742. bcm43xx_generate_beacon_template(bcm, 0x68, 0x18);
  1743. status |= 0x1;
  1744. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
  1745. }
  1746. if (!(status & 0x2)) {
  1747. bcm43xx_generate_beacon_template(bcm, 0x468, 0x1A);
  1748. status |= 0x2;
  1749. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
  1750. }
  1751. }
  1752. /* Debug helper for irq bottom-half to print all reason registers. */
  1753. #define bcmirq_print_reasons(description) \
  1754. do { \
  1755. dprintkl(KERN_ERR PFX description "\n" \
  1756. KERN_ERR PFX " Generic Reason: 0x%08x\n" \
  1757. KERN_ERR PFX " DMA reasons: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n" \
  1758. KERN_ERR PFX " DMA TX status: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", \
  1759. reason, \
  1760. dma_reason[0], dma_reason[1], \
  1761. dma_reason[2], dma_reason[3], \
  1762. bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_BASE + BCM43xx_DMA_TX_STATUS), \
  1763. bcm43xx_read32(bcm, BCM43xx_MMIO_DMA2_BASE + BCM43xx_DMA_TX_STATUS), \
  1764. bcm43xx_read32(bcm, BCM43xx_MMIO_DMA3_BASE + BCM43xx_DMA_TX_STATUS), \
  1765. bcm43xx_read32(bcm, BCM43xx_MMIO_DMA4_BASE + BCM43xx_DMA_TX_STATUS)); \
  1766. } while (0)
  1767. /* Interrupt handler bottom-half */
  1768. static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
  1769. {
  1770. u32 reason;
  1771. u32 dma_reason[4];
  1772. int activity = 0;
  1773. unsigned long flags;
  1774. #ifdef CONFIG_BCM43XX_DEBUG
  1775. u32 _handled = 0x00000000;
  1776. # define bcmirq_handled(irq) do { _handled |= (irq); } while (0)
  1777. #else
  1778. # define bcmirq_handled(irq) do { /* nothing */ } while (0)
  1779. #endif /* CONFIG_BCM43XX_DEBUG*/
  1780. spin_lock_irqsave(&bcm->lock, flags);
  1781. reason = bcm->irq_reason;
  1782. dma_reason[0] = bcm->dma_reason[0];
  1783. dma_reason[1] = bcm->dma_reason[1];
  1784. dma_reason[2] = bcm->dma_reason[2];
  1785. dma_reason[3] = bcm->dma_reason[3];
  1786. if (unlikely(reason & BCM43xx_IRQ_XMIT_ERROR)) {
  1787. /* TX error. We get this when Template Ram is written in wrong endianess
  1788. * in dummy_tx(). We also get this if something is wrong with the TX header
  1789. * on DMA or PIO queues.
  1790. * Maybe we get this in other error conditions, too.
  1791. */
  1792. bcmirq_print_reasons("XMIT ERROR");
  1793. bcmirq_handled(BCM43xx_IRQ_XMIT_ERROR);
  1794. }
  1795. if (reason & BCM43xx_IRQ_PS) {
  1796. handle_irq_ps(bcm);
  1797. bcmirq_handled(BCM43xx_IRQ_PS);
  1798. }
  1799. if (reason & BCM43xx_IRQ_REG124) {
  1800. handle_irq_reg124(bcm);
  1801. bcmirq_handled(BCM43xx_IRQ_REG124);
  1802. }
  1803. if (reason & BCM43xx_IRQ_BEACON) {
  1804. if (bcm->ieee->iw_mode == IW_MODE_MASTER)
  1805. handle_irq_beacon(bcm);
  1806. bcmirq_handled(BCM43xx_IRQ_BEACON);
  1807. }
  1808. if (reason & BCM43xx_IRQ_PMQ) {
  1809. handle_irq_pmq(bcm);
  1810. bcmirq_handled(BCM43xx_IRQ_PMQ);
  1811. }
  1812. if (reason & BCM43xx_IRQ_SCAN) {
  1813. /*TODO*/
  1814. //bcmirq_handled(BCM43xx_IRQ_SCAN);
  1815. }
  1816. if (reason & BCM43xx_IRQ_NOISE) {
  1817. handle_irq_noise(bcm);
  1818. bcmirq_handled(BCM43xx_IRQ_NOISE);
  1819. }
  1820. /* Check the DMA reason registers for received data. */
  1821. assert(!(dma_reason[1] & BCM43xx_DMAIRQ_RX_DONE));
  1822. assert(!(dma_reason[2] & BCM43xx_DMAIRQ_RX_DONE));
  1823. if (dma_reason[0] & BCM43xx_DMAIRQ_RX_DONE) {
  1824. if (bcm->pio_mode)
  1825. bcm43xx_pio_rx(bcm->current_core->pio->queue0);
  1826. else
  1827. bcm43xx_dma_rx(bcm->current_core->dma->rx_ring0);
  1828. activity = 1;
  1829. }
  1830. if (dma_reason[3] & BCM43xx_DMAIRQ_RX_DONE) {
  1831. if (likely(bcm->current_core->rev < 5)) {
  1832. if (bcm->pio_mode)
  1833. bcm43xx_pio_rx(bcm->current_core->pio->queue3);
  1834. else
  1835. bcm43xx_dma_rx(bcm->current_core->dma->rx_ring1);
  1836. activity = 1;
  1837. } else
  1838. assert(0);
  1839. }
  1840. bcmirq_handled(BCM43xx_IRQ_RX);
  1841. if (reason & BCM43xx_IRQ_XMIT_STATUS) {
  1842. if (bcm->current_core->rev >= 5) {
  1843. handle_irq_transmit_status(bcm);
  1844. activity = 1;
  1845. }
  1846. //TODO: In AP mode, this also causes sending of powersave responses.
  1847. bcmirq_handled(BCM43xx_IRQ_XMIT_STATUS);
  1848. }
  1849. /* We get spurious IRQs, althought they are masked.
  1850. * Assume they are void and ignore them.
  1851. */
  1852. bcmirq_handled(~(bcm->irq_savedstate));
  1853. /* IRQ_PIO_WORKAROUND is handled in the top-half. */
  1854. bcmirq_handled(BCM43xx_IRQ_PIO_WORKAROUND);
  1855. #ifdef CONFIG_BCM43XX_DEBUG
  1856. if (unlikely(reason & ~_handled)) {
  1857. printkl(KERN_WARNING PFX
  1858. "Unhandled IRQ! Reason: 0x%08x, Unhandled: 0x%08x, "
  1859. "DMA: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
  1860. reason, (reason & ~_handled),
  1861. dma_reason[0], dma_reason[1],
  1862. dma_reason[2], dma_reason[3]);
  1863. }
  1864. #endif
  1865. #undef bcmirq_handled
  1866. if (!modparam_noleds)
  1867. bcm43xx_leds_update(bcm, activity);
  1868. bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
  1869. spin_unlock_irqrestore(&bcm->lock, flags);
  1870. }
  1871. #undef bcmirq_print_reasons
  1872. static inline
  1873. void bcm43xx_interrupt_ack(struct bcm43xx_private *bcm,
  1874. u32 reason, u32 mask)
  1875. {
  1876. bcm->dma_reason[0] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_REASON)
  1877. & 0x0001dc00;
  1878. bcm->dma_reason[1] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA2_REASON)
  1879. & 0x0000dc00;
  1880. bcm->dma_reason[2] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA3_REASON)
  1881. & 0x0000dc00;
  1882. bcm->dma_reason[3] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA4_REASON)
  1883. & 0x0001dc00;
  1884. if ((bcm->pio_mode) &&
  1885. (bcm->current_core->rev < 3) &&
  1886. (!(reason & BCM43xx_IRQ_PIO_WORKAROUND))) {
  1887. /* Apply a PIO specific workaround to the dma_reasons */
  1888. #define apply_pio_workaround(BASE, QNUM) \
  1889. do { \
  1890. if (bcm43xx_read16(bcm, BASE + BCM43xx_PIO_RXCTL) & BCM43xx_PIO_RXCTL_DATAAVAILABLE) \
  1891. bcm->dma_reason[QNUM] |= 0x00010000; \
  1892. else \
  1893. bcm->dma_reason[QNUM] &= ~0x00010000; \
  1894. } while (0)
  1895. apply_pio_workaround(BCM43xx_MMIO_PIO1_BASE, 0);
  1896. apply_pio_workaround(BCM43xx_MMIO_PIO2_BASE, 1);
  1897. apply_pio_workaround(BCM43xx_MMIO_PIO3_BASE, 2);
  1898. apply_pio_workaround(BCM43xx_MMIO_PIO4_BASE, 3);
  1899. #undef apply_pio_workaround
  1900. }
  1901. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON,
  1902. reason & mask);
  1903. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_REASON,
  1904. bcm->dma_reason[0]);
  1905. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_REASON,
  1906. bcm->dma_reason[1]);
  1907. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_REASON,
  1908. bcm->dma_reason[2]);
  1909. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_REASON,
  1910. bcm->dma_reason[3]);
  1911. }
  1912. /* Interrupt handler top-half */
  1913. static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_regs *regs)
  1914. {
  1915. struct bcm43xx_private *bcm = dev_id;
  1916. u32 reason, mask;
  1917. if (!bcm)
  1918. return IRQ_NONE;
  1919. spin_lock(&bcm->lock);
  1920. reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
  1921. if (reason == 0xffffffff) {
  1922. /* irq not for us (shared irq) */
  1923. spin_unlock(&bcm->lock);
  1924. return IRQ_NONE;
  1925. }
  1926. mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
  1927. if (!(reason & mask)) {
  1928. spin_unlock(&bcm->lock);
  1929. return IRQ_HANDLED;
  1930. }
  1931. bcm43xx_interrupt_ack(bcm, reason, mask);
  1932. /* disable all IRQs. They are enabled again in the bottom half. */
  1933. bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  1934. /* save the reason code and call our bottom half. */
  1935. bcm->irq_reason = reason;
  1936. tasklet_schedule(&bcm->isr_tasklet);
  1937. spin_unlock(&bcm->lock);
  1938. return IRQ_HANDLED;
  1939. }
  1940. static void bcm43xx_release_firmware(struct bcm43xx_private *bcm)
  1941. {
  1942. if (bcm->firmware_norelease)
  1943. return; /* Suspending or controller reset. */
  1944. release_firmware(bcm->ucode);
  1945. bcm->ucode = NULL;
  1946. release_firmware(bcm->pcm);
  1947. bcm->pcm = NULL;
  1948. release_firmware(bcm->initvals0);
  1949. bcm->initvals0 = NULL;
  1950. release_firmware(bcm->initvals1);
  1951. bcm->initvals1 = NULL;
  1952. }
  1953. static int bcm43xx_request_firmware(struct bcm43xx_private *bcm)
  1954. {
  1955. struct bcm43xx_phyinfo *phy = bcm->current_core->phy;
  1956. u8 rev = bcm->current_core->rev;
  1957. int err = 0;
  1958. int nr;
  1959. char buf[22 + sizeof(modparam_fwpostfix) - 1] = { 0 };
  1960. if (!bcm->ucode) {
  1961. snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_microcode%d%s.fw",
  1962. (rev >= 5 ? 5 : rev),
  1963. modparam_fwpostfix);
  1964. err = request_firmware(&bcm->ucode, buf, &bcm->pci_dev->dev);
  1965. if (err) {
  1966. printk(KERN_ERR PFX
  1967. "Error: Microcode \"%s\" not available or load failed.\n",
  1968. buf);
  1969. goto error;
  1970. }
  1971. }
  1972. if (!bcm->pcm) {
  1973. snprintf(buf, ARRAY_SIZE(buf),
  1974. "bcm43xx_pcm%d%s.fw",
  1975. (rev < 5 ? 4 : 5),
  1976. modparam_fwpostfix);
  1977. err = request_firmware(&bcm->pcm, buf, &bcm->pci_dev->dev);
  1978. if (err) {
  1979. printk(KERN_ERR PFX
  1980. "Error: PCM \"%s\" not available or load failed.\n",
  1981. buf);
  1982. goto error;
  1983. }
  1984. }
  1985. if (!bcm->initvals0) {
  1986. if (rev == 2 || rev == 4) {
  1987. switch (phy->type) {
  1988. case BCM43xx_PHYTYPE_A:
  1989. nr = 3;
  1990. break;
  1991. case BCM43xx_PHYTYPE_B:
  1992. case BCM43xx_PHYTYPE_G:
  1993. nr = 1;
  1994. break;
  1995. default:
  1996. goto err_noinitval;
  1997. }
  1998. } else if (rev >= 5) {
  1999. switch (phy->type) {
  2000. case BCM43xx_PHYTYPE_A:
  2001. nr = 7;
  2002. break;
  2003. case BCM43xx_PHYTYPE_B:
  2004. case BCM43xx_PHYTYPE_G:
  2005. nr = 5;
  2006. break;
  2007. default:
  2008. goto err_noinitval;
  2009. }
  2010. } else
  2011. goto err_noinitval;
  2012. snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
  2013. nr, modparam_fwpostfix);
  2014. err = request_firmware(&bcm->initvals0, buf, &bcm->pci_dev->dev);
  2015. if (err) {
  2016. printk(KERN_ERR PFX
  2017. "Error: InitVals \"%s\" not available or load failed.\n",
  2018. buf);
  2019. goto error;
  2020. }
  2021. if (bcm->initvals0->size % sizeof(struct bcm43xx_initval)) {
  2022. printk(KERN_ERR PFX "InitVals fileformat error.\n");
  2023. goto error;
  2024. }
  2025. }
  2026. if (!bcm->initvals1) {
  2027. if (rev >= 5) {
  2028. u32 sbtmstatehigh;
  2029. switch (phy->type) {
  2030. case BCM43xx_PHYTYPE_A:
  2031. sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
  2032. if (sbtmstatehigh & 0x00010000)
  2033. nr = 9;
  2034. else
  2035. nr = 10;
  2036. break;
  2037. case BCM43xx_PHYTYPE_B:
  2038. case BCM43xx_PHYTYPE_G:
  2039. nr = 6;
  2040. break;
  2041. default:
  2042. goto err_noinitval;
  2043. }
  2044. snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
  2045. nr, modparam_fwpostfix);
  2046. err = request_firmware(&bcm->initvals1, buf, &bcm->pci_dev->dev);
  2047. if (err) {
  2048. printk(KERN_ERR PFX
  2049. "Error: InitVals \"%s\" not available or load failed.\n",
  2050. buf);
  2051. goto error;
  2052. }
  2053. if (bcm->initvals1->size % sizeof(struct bcm43xx_initval)) {
  2054. printk(KERN_ERR PFX "InitVals fileformat error.\n");
  2055. goto error;
  2056. }
  2057. }
  2058. }
  2059. out:
  2060. return err;
  2061. error:
  2062. bcm43xx_release_firmware(bcm);
  2063. goto out;
  2064. err_noinitval:
  2065. printk(KERN_ERR PFX "Error: No InitVals available!\n");
  2066. err = -ENOENT;
  2067. goto error;
  2068. }
  2069. static void bcm43xx_upload_microcode(struct bcm43xx_private *bcm)
  2070. {
  2071. const u32 *data;
  2072. unsigned int i, len;
  2073. #ifdef DEBUG_ENABLE_UCODE_MMIO_PRINT
  2074. bcm43xx_mmioprint_enable(bcm);
  2075. #else
  2076. bcm43xx_mmioprint_disable(bcm);
  2077. #endif
  2078. /* Upload Microcode. */
  2079. data = (u32 *)(bcm->ucode->data);
  2080. len = bcm->ucode->size / sizeof(u32);
  2081. bcm43xx_shm_control_word(bcm, BCM43xx_SHM_UCODE, 0x0000);
  2082. for (i = 0; i < len; i++) {
  2083. bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
  2084. be32_to_cpu(data[i]));
  2085. udelay(10);
  2086. }
  2087. /* Upload PCM data. */
  2088. data = (u32 *)(bcm->pcm->data);
  2089. len = bcm->pcm->size / sizeof(u32);
  2090. bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01ea);
  2091. bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, 0x00004000);
  2092. bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01eb);
  2093. for (i = 0; i < len; i++) {
  2094. bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
  2095. be32_to_cpu(data[i]));
  2096. udelay(10);
  2097. }
  2098. #ifdef DEBUG_ENABLE_UCODE_MMIO_PRINT
  2099. bcm43xx_mmioprint_disable(bcm);
  2100. #else
  2101. bcm43xx_mmioprint_enable(bcm);
  2102. #endif
  2103. }
  2104. static void bcm43xx_write_initvals(struct bcm43xx_private *bcm,
  2105. const struct bcm43xx_initval *data,
  2106. const unsigned int len)
  2107. {
  2108. u16 offset, size;
  2109. u32 value;
  2110. unsigned int i;
  2111. for (i = 0; i < len; i++) {
  2112. offset = be16_to_cpu(data[i].offset);
  2113. size = be16_to_cpu(data[i].size);
  2114. value = be32_to_cpu(data[i].value);
  2115. if (size == 2)
  2116. bcm43xx_write16(bcm, offset, value);
  2117. else if (size == 4)
  2118. bcm43xx_write32(bcm, offset, value);
  2119. else
  2120. printk(KERN_ERR PFX "InitVals fileformat error.\n");
  2121. }
  2122. }
  2123. static void bcm43xx_upload_initvals(struct bcm43xx_private *bcm)
  2124. {
  2125. #ifdef DEBUG_ENABLE_UCODE_MMIO_PRINT
  2126. bcm43xx_mmioprint_enable(bcm);
  2127. #else
  2128. bcm43xx_mmioprint_disable(bcm);
  2129. #endif
  2130. bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals0->data,
  2131. bcm->initvals0->size / sizeof(struct bcm43xx_initval));
  2132. if (bcm->initvals1) {
  2133. bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals1->data,
  2134. bcm->initvals1->size / sizeof(struct bcm43xx_initval));
  2135. }
  2136. #ifdef DEBUG_ENABLE_UCODE_MMIO_PRINT
  2137. bcm43xx_mmioprint_disable(bcm);
  2138. #else
  2139. bcm43xx_mmioprint_enable(bcm);
  2140. #endif
  2141. }
  2142. static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm)
  2143. {
  2144. int res;
  2145. unsigned int i;
  2146. u32 data;
  2147. bcm->irq = bcm->pci_dev->irq;
  2148. #ifdef CONFIG_BCM947XX
  2149. if (bcm->pci_dev->bus->number == 0) {
  2150. struct pci_dev *d = NULL;
  2151. /* FIXME: we will probably need more device IDs here... */
  2152. d = pci_find_device(PCI_VENDOR_ID_BROADCOM, 0x4324, NULL);
  2153. if (d != NULL) {
  2154. bcm->irq = d->irq;
  2155. }
  2156. }
  2157. #endif
  2158. res = request_irq(bcm->irq, bcm43xx_interrupt_handler,
  2159. SA_SHIRQ, DRV_NAME, bcm);
  2160. if (res) {
  2161. printk(KERN_ERR PFX "Cannot register IRQ%d\n", bcm->irq);
  2162. return -EFAULT;
  2163. }
  2164. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0xffffffff);
  2165. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, 0x00020402);
  2166. i = 0;
  2167. while (1) {
  2168. data = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
  2169. if (data == BCM43xx_IRQ_READY)
  2170. break;
  2171. i++;
  2172. if (i >= BCM43xx_IRQWAIT_MAX_RETRIES) {
  2173. printk(KERN_ERR PFX "Card IRQ register not responding. "
  2174. "Giving up.\n");
  2175. free_irq(bcm->irq, bcm);
  2176. return -ENODEV;
  2177. }
  2178. udelay(10);
  2179. }
  2180. // dummy read
  2181. bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
  2182. return 0;
  2183. }
  2184. /* Switch to the core used to write the GPIO register.
  2185. * This is either the ChipCommon, or the PCI core.
  2186. */
  2187. static inline int switch_to_gpio_core(struct bcm43xx_private *bcm)
  2188. {
  2189. int err;
  2190. /* Where to find the GPIO register depends on the chipset.
  2191. * If it has a ChipCommon, its register at offset 0x6c is the GPIO
  2192. * control register. Otherwise the register at offset 0x6c in the
  2193. * PCI core is the GPIO control register.
  2194. */
  2195. err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
  2196. if (err == -ENODEV) {
  2197. err = bcm43xx_switch_core(bcm, &bcm->core_pci);
  2198. if (err == -ENODEV) {
  2199. printk(KERN_ERR PFX "gpio error: "
  2200. "Neither ChipCommon nor PCI core available!\n");
  2201. return -ENODEV;
  2202. } else if (err != 0)
  2203. return -ENODEV;
  2204. } else if (err != 0)
  2205. return -ENODEV;
  2206. return 0;
  2207. }
  2208. /* Initialize the GPIOs
  2209. * http://bcm-specs.sipsolutions.net/GPIO
  2210. */
  2211. static int bcm43xx_gpio_init(struct bcm43xx_private *bcm)
  2212. {
  2213. struct bcm43xx_coreinfo *old_core;
  2214. int err;
  2215. u32 mask, value;
  2216. value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2217. value &= ~0xc000;
  2218. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value);
  2219. mask = 0x0000001F;
  2220. value = 0x0000000F;
  2221. bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL,
  2222. bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL) & 0xFFF0);
  2223. bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
  2224. bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK) | 0x000F);
  2225. old_core = bcm->current_core;
  2226. err = switch_to_gpio_core(bcm);
  2227. if (err)
  2228. return err;
  2229. if (bcm->current_core->rev >= 2){
  2230. mask |= 0x10;
  2231. value |= 0x10;
  2232. }
  2233. if (bcm->chip_id == 0x4301) {
  2234. mask |= 0x60;
  2235. value |= 0x60;
  2236. }
  2237. if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
  2238. mask |= 0x200;
  2239. value |= 0x200;
  2240. }
  2241. bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL,
  2242. (bcm43xx_read32(bcm, BCM43xx_GPIO_CONTROL) & mask) | value);
  2243. err = bcm43xx_switch_core(bcm, old_core);
  2244. assert(err == 0);
  2245. return 0;
  2246. }
  2247. /* Turn off all GPIO stuff. Call this on module unload, for example. */
  2248. static int bcm43xx_gpio_cleanup(struct bcm43xx_private *bcm)
  2249. {
  2250. struct bcm43xx_coreinfo *old_core;
  2251. int err;
  2252. old_core = bcm->current_core;
  2253. err = switch_to_gpio_core(bcm);
  2254. if (err)
  2255. return err;
  2256. bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL, 0x00000000);
  2257. err = bcm43xx_switch_core(bcm, old_core);
  2258. assert(err == 0);
  2259. return 0;
  2260. }
  2261. /* http://bcm-specs.sipsolutions.net/EnableMac */
  2262. void bcm43xx_mac_enable(struct bcm43xx_private *bcm)
  2263. {
  2264. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  2265. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
  2266. | BCM43xx_SBF_MAC_ENABLED);
  2267. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, BCM43xx_IRQ_READY);
  2268. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
  2269. bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
  2270. bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
  2271. }
  2272. /* http://bcm-specs.sipsolutions.net/SuspendMAC */
  2273. void bcm43xx_mac_suspend(struct bcm43xx_private *bcm)
  2274. {
  2275. int i;
  2276. u32 tmp;
  2277. bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
  2278. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  2279. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
  2280. & ~BCM43xx_SBF_MAC_ENABLED);
  2281. bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
  2282. for (i = 1000; i > 0; i--) {
  2283. tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
  2284. if (tmp & BCM43xx_IRQ_READY) {
  2285. i = -1;
  2286. break;
  2287. }
  2288. udelay(10);
  2289. }
  2290. if (!i)
  2291. printkl(KERN_ERR PFX "Failed to suspend mac!\n");
  2292. }
  2293. void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
  2294. int iw_mode)
  2295. {
  2296. unsigned long flags;
  2297. u32 status;
  2298. spin_lock_irqsave(&bcm->ieee->lock, flags);
  2299. bcm->ieee->iw_mode = iw_mode;
  2300. spin_unlock_irqrestore(&bcm->ieee->lock, flags);
  2301. if (iw_mode == IW_MODE_MONITOR)
  2302. bcm->net_dev->type = ARPHRD_IEEE80211;
  2303. else
  2304. bcm->net_dev->type = ARPHRD_ETHER;
  2305. if (!bcm->initialized)
  2306. return;
  2307. bcm43xx_mac_suspend(bcm);
  2308. status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2309. /* Reset status to infrastructured mode */
  2310. status &= ~(BCM43xx_SBF_MODE_AP | BCM43xx_SBF_MODE_MONITOR);
  2311. /*FIXME: We actually set promiscuous mode as well, until we don't
  2312. * get the HW mac filter working */
  2313. status |= BCM43xx_SBF_MODE_NOTADHOC | BCM43xx_SBF_MODE_PROMISC;
  2314. switch (iw_mode) {
  2315. case IW_MODE_MONITOR:
  2316. status |= (BCM43xx_SBF_MODE_PROMISC |
  2317. BCM43xx_SBF_MODE_MONITOR);
  2318. break;
  2319. case IW_MODE_ADHOC:
  2320. status &= ~BCM43xx_SBF_MODE_NOTADHOC;
  2321. break;
  2322. case IW_MODE_MASTER:
  2323. case IW_MODE_SECOND:
  2324. case IW_MODE_REPEAT:
  2325. /* TODO: No AP/Repeater mode for now :-/ */
  2326. TODO();
  2327. break;
  2328. case IW_MODE_INFRA:
  2329. /* nothing to be done here... */
  2330. break;
  2331. default:
  2332. printk(KERN_ERR PFX "Unknown iwmode %d\n", iw_mode);
  2333. }
  2334. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
  2335. bcm43xx_mac_enable(bcm);
  2336. }
  2337. /* This is the opposite of bcm43xx_chip_init() */
  2338. static void bcm43xx_chip_cleanup(struct bcm43xx_private *bcm)
  2339. {
  2340. bcm43xx_radio_turn_off(bcm);
  2341. if (!modparam_noleds)
  2342. bcm43xx_leds_exit(bcm);
  2343. bcm43xx_gpio_cleanup(bcm);
  2344. free_irq(bcm->irq, bcm);
  2345. bcm43xx_release_firmware(bcm);
  2346. }
  2347. /* Initialize the chip
  2348. * http://bcm-specs.sipsolutions.net/ChipInit
  2349. */
  2350. static int bcm43xx_chip_init(struct bcm43xx_private *bcm)
  2351. {
  2352. int err;
  2353. int iw_mode = bcm->ieee->iw_mode;
  2354. int tmp;
  2355. u32 value32;
  2356. u16 value16;
  2357. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  2358. BCM43xx_SBF_CORE_READY
  2359. | BCM43xx_SBF_400);
  2360. err = bcm43xx_request_firmware(bcm);
  2361. if (err)
  2362. goto out;
  2363. bcm43xx_upload_microcode(bcm);
  2364. err = bcm43xx_initialize_irq(bcm);
  2365. if (err)
  2366. goto out;
  2367. err = bcm43xx_gpio_init(bcm);
  2368. if (err)
  2369. goto err_free_irq;
  2370. bcm43xx_upload_initvals(bcm);
  2371. bcm43xx_radio_turn_on(bcm);
  2372. if (modparam_noleds)
  2373. bcm43xx_leds_turn_off(bcm);
  2374. else
  2375. bcm43xx_leds_update(bcm, 0);
  2376. bcm43xx_write16(bcm, 0x03E6, 0x0000);
  2377. err = bcm43xx_phy_init(bcm);
  2378. if (err)
  2379. goto err_radio_off;
  2380. /* Select initial Interference Mitigation. */
  2381. tmp = bcm->current_core->radio->interfmode;
  2382. bcm->current_core->radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
  2383. bcm43xx_radio_set_interference_mitigation(bcm, tmp);
  2384. bcm43xx_phy_set_antenna_diversity(bcm);
  2385. bcm43xx_radio_set_txantenna(bcm, BCM43xx_RADIO_TXANTENNA_DEFAULT);
  2386. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_B) {
  2387. value16 = bcm43xx_read16(bcm, 0x005E);
  2388. value16 |= 0x0004;
  2389. bcm43xx_write16(bcm, 0x005E, value16);
  2390. }
  2391. bcm43xx_write32(bcm, 0x0100, 0x01000000);
  2392. if (bcm->current_core->rev < 5)
  2393. bcm43xx_write32(bcm, 0x010C, 0x01000000);
  2394. value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2395. value32 &= ~ BCM43xx_SBF_MODE_NOTADHOC;
  2396. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
  2397. value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2398. value32 |= BCM43xx_SBF_MODE_NOTADHOC;
  2399. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
  2400. /*FIXME: For now, use promiscuous mode at all times; otherwise we don't
  2401. get broadcast or multicast packets */
  2402. value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2403. value32 |= BCM43xx_SBF_MODE_PROMISC;
  2404. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
  2405. if (iw_mode == IW_MODE_MONITOR) {
  2406. value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2407. value32 |= BCM43xx_SBF_MODE_PROMISC;
  2408. value32 |= BCM43xx_SBF_MODE_MONITOR;
  2409. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
  2410. }
  2411. value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2412. value32 |= 0x100000; //FIXME: What's this? Is this correct?
  2413. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
  2414. if (bcm->pio_mode) {
  2415. bcm43xx_write32(bcm, 0x0210, 0x00000100);
  2416. bcm43xx_write32(bcm, 0x0230, 0x00000100);
  2417. bcm43xx_write32(bcm, 0x0250, 0x00000100);
  2418. bcm43xx_write32(bcm, 0x0270, 0x00000100);
  2419. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0034, 0x0000);
  2420. }
  2421. /* Probe Response Timeout value */
  2422. /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
  2423. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0074, 0x0000);
  2424. if (iw_mode != IW_MODE_ADHOC && iw_mode != IW_MODE_MASTER) {
  2425. if ((bcm->chip_id == 0x4306) && (bcm->chip_rev == 3))
  2426. bcm43xx_write16(bcm, 0x0612, 0x0064);
  2427. else
  2428. bcm43xx_write16(bcm, 0x0612, 0x0032);
  2429. } else
  2430. bcm43xx_write16(bcm, 0x0612, 0x0002);
  2431. if (bcm->current_core->rev < 3) {
  2432. bcm43xx_write16(bcm, 0x060E, 0x0000);
  2433. bcm43xx_write16(bcm, 0x0610, 0x8000);
  2434. bcm43xx_write16(bcm, 0x0604, 0x0000);
  2435. bcm43xx_write16(bcm, 0x0606, 0x0200);
  2436. } else {
  2437. bcm43xx_write32(bcm, 0x0188, 0x80000000);
  2438. bcm43xx_write32(bcm, 0x018C, 0x02000000);
  2439. }
  2440. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0x00004000);
  2441. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_IRQ_MASK, 0x0001DC00);
  2442. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
  2443. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_IRQ_MASK, 0x0000DC00);
  2444. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_IRQ_MASK, 0x0001DC00);
  2445. value32 = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  2446. value32 |= 0x00100000;
  2447. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, value32);
  2448. bcm43xx_write16(bcm, BCM43xx_MMIO_POWERUP_DELAY, bcm43xx_pctl_powerup_delay(bcm));
  2449. assert(err == 0);
  2450. dprintk(KERN_INFO PFX "Chip initialized\n");
  2451. out:
  2452. return err;
  2453. err_radio_off:
  2454. bcm43xx_radio_turn_off(bcm);
  2455. bcm43xx_gpio_cleanup(bcm);
  2456. err_free_irq:
  2457. free_irq(bcm->irq, bcm);
  2458. goto out;
  2459. }
  2460. /* Validate chip access
  2461. * http://bcm-specs.sipsolutions.net/ValidateChipAccess */
  2462. static int bcm43xx_validate_chip(struct bcm43xx_private *bcm)
  2463. {
  2464. int err = -ENODEV;
  2465. u32 value;
  2466. u32 shm_backup;
  2467. shm_backup = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000);
  2468. bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0xAA5555AA);
  2469. if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0xAA5555AA) {
  2470. printk(KERN_ERR PFX "Error: SHM mismatch (1) validating chip\n");
  2471. goto out;
  2472. }
  2473. bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0x55AAAA55);
  2474. if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0x55AAAA55) {
  2475. printk(KERN_ERR PFX "Error: SHM mismatch (2) validating chip\n");
  2476. goto out;
  2477. }
  2478. bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, shm_backup);
  2479. value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2480. if ((value | 0x80000000) != 0x80000400) {
  2481. printk(KERN_ERR PFX "Error: Bad Status Bitfield while validating chip\n");
  2482. goto out;
  2483. }
  2484. value = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
  2485. if (value != 0x00000000) {
  2486. printk(KERN_ERR PFX "Error: Bad interrupt reason code while validating chip\n");
  2487. goto out;
  2488. }
  2489. err = 0;
  2490. out:
  2491. return err;
  2492. }
  2493. static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
  2494. {
  2495. int err, i;
  2496. int current_core;
  2497. u32 core_vendor, core_id, core_rev;
  2498. u32 sb_id_hi, chip_id_32 = 0;
  2499. u16 pci_device, chip_id_16;
  2500. u8 core_count;
  2501. memset(&bcm->core_chipcommon, 0, sizeof(struct bcm43xx_coreinfo));
  2502. memset(&bcm->core_pci, 0, sizeof(struct bcm43xx_coreinfo));
  2503. memset(&bcm->core_v90, 0, sizeof(struct bcm43xx_coreinfo));
  2504. memset(&bcm->core_pcmcia, 0, sizeof(struct bcm43xx_coreinfo));
  2505. memset(&bcm->core_80211, 0, sizeof(struct bcm43xx_coreinfo)
  2506. * BCM43xx_MAX_80211_CORES);
  2507. memset(&bcm->phy, 0, sizeof(struct bcm43xx_phyinfo)
  2508. * BCM43xx_MAX_80211_CORES);
  2509. memset(&bcm->radio, 0, sizeof(struct bcm43xx_radioinfo)
  2510. * BCM43xx_MAX_80211_CORES);
  2511. /* map core 0 */
  2512. err = _switch_core(bcm, 0);
  2513. if (err)
  2514. goto out;
  2515. /* fetch sb_id_hi from core information registers */
  2516. sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
  2517. core_id = (sb_id_hi & 0xFFF0) >> 4;
  2518. core_rev = (sb_id_hi & 0xF);
  2519. core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
  2520. /* if present, chipcommon is always core 0; read the chipid from it */
  2521. if (core_id == BCM43xx_COREID_CHIPCOMMON) {
  2522. chip_id_32 = bcm43xx_read32(bcm, 0);
  2523. chip_id_16 = chip_id_32 & 0xFFFF;
  2524. bcm->core_chipcommon.flags |= BCM43xx_COREFLAG_AVAILABLE;
  2525. bcm->core_chipcommon.id = core_id;
  2526. bcm->core_chipcommon.rev = core_rev;
  2527. bcm->core_chipcommon.index = 0;
  2528. /* While we are at it, also read the capabilities. */
  2529. bcm->chipcommon_capabilities = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_CAPABILITIES);
  2530. } else {
  2531. /* without a chipCommon, use a hard coded table. */
  2532. pci_device = bcm->pci_dev->device;
  2533. if (pci_device == 0x4301)
  2534. chip_id_16 = 0x4301;
  2535. else if ((pci_device >= 0x4305) && (pci_device <= 0x4307))
  2536. chip_id_16 = 0x4307;
  2537. else if ((pci_device >= 0x4402) && (pci_device <= 0x4403))
  2538. chip_id_16 = 0x4402;
  2539. else if ((pci_device >= 0x4610) && (pci_device <= 0x4615))
  2540. chip_id_16 = 0x4610;
  2541. else if ((pci_device >= 0x4710) && (pci_device <= 0x4715))
  2542. chip_id_16 = 0x4710;
  2543. #ifdef CONFIG_BCM947XX
  2544. else if ((pci_device >= 0x4320) && (pci_device <= 0x4325))
  2545. chip_id_16 = 0x4309;
  2546. #endif
  2547. else {
  2548. printk(KERN_ERR PFX "Could not determine Chip ID\n");
  2549. return -ENODEV;
  2550. }
  2551. }
  2552. /* ChipCommon with Core Rev >=4 encodes number of cores,
  2553. * otherwise consult hardcoded table */
  2554. if ((core_id == BCM43xx_COREID_CHIPCOMMON) && (core_rev >= 4)) {
  2555. core_count = (chip_id_32 & 0x0F000000) >> 24;
  2556. } else {
  2557. switch (chip_id_16) {
  2558. case 0x4610:
  2559. case 0x4704:
  2560. case 0x4710:
  2561. core_count = 9;
  2562. break;
  2563. case 0x4310:
  2564. core_count = 8;
  2565. break;
  2566. case 0x5365:
  2567. core_count = 7;
  2568. break;
  2569. case 0x4306:
  2570. core_count = 6;
  2571. break;
  2572. case 0x4301:
  2573. case 0x4307:
  2574. core_count = 5;
  2575. break;
  2576. case 0x4402:
  2577. core_count = 3;
  2578. break;
  2579. default:
  2580. /* SOL if we get here */
  2581. assert(0);
  2582. core_count = 1;
  2583. }
  2584. }
  2585. bcm->chip_id = chip_id_16;
  2586. bcm->chip_rev = (chip_id_32 & 0x000f0000) >> 16;
  2587. dprintk(KERN_INFO PFX "Chip ID 0x%x, rev 0x%x\n",
  2588. bcm->chip_id, bcm->chip_rev);
  2589. dprintk(KERN_INFO PFX "Number of cores: %d\n", core_count);
  2590. if (bcm->core_chipcommon.flags & BCM43xx_COREFLAG_AVAILABLE) {
  2591. dprintk(KERN_INFO PFX "Core 0: ID 0x%x, rev 0x%x, vendor 0x%x, %s\n",
  2592. core_id, core_rev, core_vendor,
  2593. bcm43xx_core_enabled(bcm) ? "enabled" : "disabled");
  2594. }
  2595. if (bcm->core_chipcommon.flags & BCM43xx_COREFLAG_AVAILABLE)
  2596. current_core = 1;
  2597. else
  2598. current_core = 0;
  2599. for ( ; current_core < core_count; current_core++) {
  2600. struct bcm43xx_coreinfo *core;
  2601. err = _switch_core(bcm, current_core);
  2602. if (err)
  2603. goto out;
  2604. /* Gather information */
  2605. /* fetch sb_id_hi from core information registers */
  2606. sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
  2607. /* extract core_id, core_rev, core_vendor */
  2608. core_id = (sb_id_hi & 0xFFF0) >> 4;
  2609. core_rev = (sb_id_hi & 0xF);
  2610. core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
  2611. dprintk(KERN_INFO PFX "Core %d: ID 0x%x, rev 0x%x, vendor 0x%x, %s\n",
  2612. current_core, core_id, core_rev, core_vendor,
  2613. bcm43xx_core_enabled(bcm) ? "enabled" : "disabled" );
  2614. core = NULL;
  2615. switch (core_id) {
  2616. case BCM43xx_COREID_PCI:
  2617. core = &bcm->core_pci;
  2618. if (core->flags & BCM43xx_COREFLAG_AVAILABLE) {
  2619. printk(KERN_WARNING PFX "Multiple PCI cores found.\n");
  2620. continue;
  2621. }
  2622. break;
  2623. case BCM43xx_COREID_V90:
  2624. core = &bcm->core_v90;
  2625. if (core->flags & BCM43xx_COREFLAG_AVAILABLE) {
  2626. printk(KERN_WARNING PFX "Multiple V90 cores found.\n");
  2627. continue;
  2628. }
  2629. break;
  2630. case BCM43xx_COREID_PCMCIA:
  2631. core = &bcm->core_pcmcia;
  2632. if (core->flags & BCM43xx_COREFLAG_AVAILABLE) {
  2633. printk(KERN_WARNING PFX "Multiple PCMCIA cores found.\n");
  2634. continue;
  2635. }
  2636. break;
  2637. case BCM43xx_COREID_ETHERNET:
  2638. core = &bcm->core_ethernet;
  2639. if (core->flags & BCM43xx_COREFLAG_AVAILABLE) {
  2640. printk(KERN_WARNING PFX "Multiple Ethernet cores found.\n");
  2641. continue;
  2642. }
  2643. break;
  2644. case BCM43xx_COREID_80211:
  2645. for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
  2646. core = &(bcm->core_80211[i]);
  2647. if (!(core->flags & BCM43xx_COREFLAG_AVAILABLE))
  2648. break;
  2649. core = NULL;
  2650. }
  2651. if (!core) {
  2652. printk(KERN_WARNING PFX "More than %d cores of type 802.11 found.\n",
  2653. BCM43xx_MAX_80211_CORES);
  2654. continue;
  2655. }
  2656. if (i != 0) {
  2657. /* More than one 80211 core is only supported
  2658. * by special chips.
  2659. * There are chips with two 80211 cores, but with
  2660. * dangling pins on the second core. Be careful
  2661. * and ignore these cores here.
  2662. */
  2663. if (bcm->pci_dev->device != 0x4324) {
  2664. dprintk(KERN_INFO PFX "Ignoring additional 802.11 core.\n");
  2665. continue;
  2666. }
  2667. }
  2668. switch (core_rev) {
  2669. case 2:
  2670. case 4:
  2671. case 5:
  2672. case 6:
  2673. case 7:
  2674. case 9:
  2675. break;
  2676. default:
  2677. printk(KERN_ERR PFX "Error: Unsupported 80211 core revision %u\n",
  2678. core_rev);
  2679. err = -ENODEV;
  2680. goto out;
  2681. }
  2682. core->phy = &bcm->phy[i];
  2683. core->phy->antenna_diversity = 0xffff;
  2684. core->phy->savedpctlreg = 0xFFFF;
  2685. core->phy->minlowsig[0] = 0xFFFF;
  2686. core->phy->minlowsig[1] = 0xFFFF;
  2687. core->phy->minlowsigpos[0] = 0;
  2688. core->phy->minlowsigpos[1] = 0;
  2689. spin_lock_init(&core->phy->lock);
  2690. core->radio = &bcm->radio[i];
  2691. core->radio->interfmode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN;
  2692. core->radio->channel = 0xFF;
  2693. core->radio->initial_channel = 0xFF;
  2694. core->radio->lofcal = 0xFFFF;
  2695. core->radio->initval = 0xFFFF;
  2696. core->radio->nrssi[0] = -1000;
  2697. core->radio->nrssi[1] = -1000;
  2698. core->dma = &bcm->dma[i];
  2699. core->pio = &bcm->pio[i];
  2700. break;
  2701. case BCM43xx_COREID_CHIPCOMMON:
  2702. printk(KERN_WARNING PFX "Multiple CHIPCOMMON cores found.\n");
  2703. break;
  2704. default:
  2705. printk(KERN_WARNING PFX "Unknown core found (ID 0x%x)\n", core_id);
  2706. }
  2707. if (core) {
  2708. core->flags |= BCM43xx_COREFLAG_AVAILABLE;
  2709. core->id = core_id;
  2710. core->rev = core_rev;
  2711. core->index = current_core;
  2712. }
  2713. }
  2714. if (!(bcm->core_80211[0].flags & BCM43xx_COREFLAG_AVAILABLE)) {
  2715. printk(KERN_ERR PFX "Error: No 80211 core found!\n");
  2716. err = -ENODEV;
  2717. goto out;
  2718. }
  2719. err = bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
  2720. assert(err == 0);
  2721. out:
  2722. return err;
  2723. }
  2724. static void bcm43xx_gen_bssid(struct bcm43xx_private *bcm)
  2725. {
  2726. const u8 *mac = (const u8*)(bcm->net_dev->dev_addr);
  2727. u8 *bssid = bcm->ieee->bssid;
  2728. switch (bcm->ieee->iw_mode) {
  2729. case IW_MODE_ADHOC:
  2730. random_ether_addr(bssid);
  2731. break;
  2732. case IW_MODE_MASTER:
  2733. case IW_MODE_INFRA:
  2734. case IW_MODE_REPEAT:
  2735. case IW_MODE_SECOND:
  2736. case IW_MODE_MONITOR:
  2737. memcpy(bssid, mac, ETH_ALEN);
  2738. break;
  2739. default:
  2740. assert(0);
  2741. }
  2742. }
  2743. static void bcm43xx_rate_memory_write(struct bcm43xx_private *bcm,
  2744. u16 rate,
  2745. int is_ofdm)
  2746. {
  2747. u16 offset;
  2748. if (is_ofdm) {
  2749. offset = 0x480;
  2750. offset += (bcm43xx_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
  2751. }
  2752. else {
  2753. offset = 0x4C0;
  2754. offset += (bcm43xx_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
  2755. }
  2756. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, offset + 0x20,
  2757. bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, offset));
  2758. }
  2759. static void bcm43xx_rate_memory_init(struct bcm43xx_private *bcm)
  2760. {
  2761. switch (bcm->current_core->phy->type) {
  2762. case BCM43xx_PHYTYPE_A:
  2763. case BCM43xx_PHYTYPE_G:
  2764. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_6MB, 1);
  2765. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_12MB, 1);
  2766. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_18MB, 1);
  2767. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_24MB, 1);
  2768. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_36MB, 1);
  2769. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_48MB, 1);
  2770. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_54MB, 1);
  2771. case BCM43xx_PHYTYPE_B:
  2772. bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_1MB, 0);
  2773. bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_2MB, 0);
  2774. bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_5MB, 0);
  2775. bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_11MB, 0);
  2776. break;
  2777. default:
  2778. assert(0);
  2779. }
  2780. }
  2781. static void bcm43xx_wireless_core_cleanup(struct bcm43xx_private *bcm)
  2782. {
  2783. bcm43xx_chip_cleanup(bcm);
  2784. bcm43xx_pio_free(bcm);
  2785. bcm43xx_dma_free(bcm);
  2786. bcm->current_core->flags &= ~ BCM43xx_COREFLAG_INITIALIZED;
  2787. }
  2788. /* http://bcm-specs.sipsolutions.net/80211Init */
  2789. static int bcm43xx_wireless_core_init(struct bcm43xx_private *bcm)
  2790. {
  2791. u32 ucodeflags;
  2792. int err;
  2793. u32 sbimconfiglow;
  2794. u8 limit;
  2795. if (bcm->chip_rev < 5) {
  2796. sbimconfiglow = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
  2797. sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
  2798. sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
  2799. if (bcm->bustype == BCM43xx_BUSTYPE_PCI)
  2800. sbimconfiglow |= 0x32;
  2801. else if (bcm->bustype == BCM43xx_BUSTYPE_SB)
  2802. sbimconfiglow |= 0x53;
  2803. else
  2804. assert(0);
  2805. bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow);
  2806. }
  2807. bcm43xx_phy_calibrate(bcm);
  2808. err = bcm43xx_chip_init(bcm);
  2809. if (err)
  2810. goto out;
  2811. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0016, bcm->current_core->rev);
  2812. ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, BCM43xx_UCODEFLAGS_OFFSET);
  2813. if (0 /*FIXME: which condition has to be used here? */)
  2814. ucodeflags |= 0x00000010;
  2815. /* HW decryption needs to be set now */
  2816. ucodeflags |= 0x40000000;
  2817. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_G) {
  2818. ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
  2819. if (bcm->current_core->phy->rev == 1)
  2820. ucodeflags |= BCM43xx_UCODEFLAG_UNKGPHY;
  2821. if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
  2822. ucodeflags |= BCM43xx_UCODEFLAG_UNKPACTRL;
  2823. } else if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_B) {
  2824. ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
  2825. if ((bcm->current_core->phy->rev >= 2) &&
  2826. (bcm->current_core->radio->version == 0x2050))
  2827. ucodeflags &= ~BCM43xx_UCODEFLAG_UNKGPHY;
  2828. }
  2829. if (ucodeflags != bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
  2830. BCM43xx_UCODEFLAGS_OFFSET)) {
  2831. bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
  2832. BCM43xx_UCODEFLAGS_OFFSET, ucodeflags);
  2833. }
  2834. /* Short/Long Retry Limit.
  2835. * The retry-limit is a 4-bit counter. Enforce this to avoid overflowing
  2836. * the chip-internal counter.
  2837. */
  2838. limit = limit_value(modparam_short_retry, 0, 0xF);
  2839. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0006, limit);
  2840. limit = limit_value(modparam_long_retry, 0, 0xF);
  2841. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0007, limit);
  2842. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0044, 3);
  2843. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0046, 2);
  2844. bcm43xx_rate_memory_init(bcm);
  2845. /* Minimum Contention Window */
  2846. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_B)
  2847. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000001f);
  2848. else
  2849. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000000f);
  2850. /* Maximum Contention Window */
  2851. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
  2852. bcm43xx_gen_bssid(bcm);
  2853. bcm43xx_write_mac_bssid_templates(bcm);
  2854. if (bcm->current_core->rev >= 5)
  2855. bcm43xx_write16(bcm, 0x043C, 0x000C);
  2856. if (!bcm->pio_mode) {
  2857. err = bcm43xx_dma_init(bcm);
  2858. if (err)
  2859. goto err_chip_cleanup;
  2860. } else {
  2861. err = bcm43xx_pio_init(bcm);
  2862. if (err)
  2863. goto err_chip_cleanup;
  2864. }
  2865. bcm43xx_write16(bcm, 0x0612, 0x0050);
  2866. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0416, 0x0050);
  2867. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0414, 0x01F4);
  2868. bcm43xx_mac_enable(bcm);
  2869. bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
  2870. bcm->current_core->flags |= BCM43xx_COREFLAG_INITIALIZED;
  2871. out:
  2872. return err;
  2873. err_chip_cleanup:
  2874. bcm43xx_chip_cleanup(bcm);
  2875. goto out;
  2876. }
  2877. static int bcm43xx_chipset_attach(struct bcm43xx_private *bcm)
  2878. {
  2879. int err;
  2880. u16 pci_status;
  2881. err = bcm43xx_pctl_set_crystal(bcm, 1);
  2882. if (err)
  2883. goto out;
  2884. bcm43xx_pci_read_config16(bcm, PCI_STATUS, &pci_status);
  2885. bcm43xx_pci_write_config16(bcm, PCI_STATUS, pci_status & ~PCI_STATUS_SIG_TARGET_ABORT);
  2886. out:
  2887. return err;
  2888. }
  2889. static void bcm43xx_chipset_detach(struct bcm43xx_private *bcm)
  2890. {
  2891. bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
  2892. bcm43xx_pctl_set_crystal(bcm, 0);
  2893. }
  2894. static inline void bcm43xx_pcicore_broadcast_value(struct bcm43xx_private *bcm,
  2895. u32 address,
  2896. u32 data)
  2897. {
  2898. bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_ADDR, address);
  2899. bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_DATA, data);
  2900. }
  2901. static int bcm43xx_pcicore_commit_settings(struct bcm43xx_private *bcm)
  2902. {
  2903. int err;
  2904. struct bcm43xx_coreinfo *old_core;
  2905. old_core = bcm->current_core;
  2906. err = bcm43xx_switch_core(bcm, &bcm->core_pci);
  2907. if (err)
  2908. goto out;
  2909. bcm43xx_pcicore_broadcast_value(bcm, 0xfd8, 0x00000000);
  2910. bcm43xx_switch_core(bcm, old_core);
  2911. assert(err == 0);
  2912. out:
  2913. return err;
  2914. }
  2915. /* Make an I/O Core usable. "core_mask" is the bitmask of the cores to enable.
  2916. * To enable core 0, pass a core_mask of 1<<0
  2917. */
  2918. static int bcm43xx_setup_backplane_pci_connection(struct bcm43xx_private *bcm,
  2919. u32 core_mask)
  2920. {
  2921. u32 backplane_flag_nr;
  2922. u32 value;
  2923. struct bcm43xx_coreinfo *old_core;
  2924. int err = 0;
  2925. value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTPSFLAG);
  2926. backplane_flag_nr = value & BCM43xx_BACKPLANE_FLAG_NR_MASK;
  2927. old_core = bcm->current_core;
  2928. err = bcm43xx_switch_core(bcm, &bcm->core_pci);
  2929. if (err)
  2930. goto out;
  2931. if (bcm->core_pci.rev < 6) {
  2932. value = bcm43xx_read32(bcm, BCM43xx_CIR_SBINTVEC);
  2933. value |= (1 << backplane_flag_nr);
  2934. bcm43xx_write32(bcm, BCM43xx_CIR_SBINTVEC, value);
  2935. } else {
  2936. err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ICR, &value);
  2937. if (err) {
  2938. printk(KERN_ERR PFX "Error: ICR setup failure!\n");
  2939. goto out_switch_back;
  2940. }
  2941. value |= core_mask << 8;
  2942. err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ICR, value);
  2943. if (err) {
  2944. printk(KERN_ERR PFX "Error: ICR setup failure!\n");
  2945. goto out_switch_back;
  2946. }
  2947. }
  2948. value = bcm43xx_read32(bcm, BCM43xx_PCICORE_SBTOPCI2);
  2949. value |= BCM43xx_SBTOPCI2_PREFETCH | BCM43xx_SBTOPCI2_BURST;
  2950. bcm43xx_write32(bcm, BCM43xx_PCICORE_SBTOPCI2, value);
  2951. if (bcm->core_pci.rev < 5) {
  2952. value = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
  2953. value |= (2 << BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT)
  2954. & BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
  2955. value |= (3 << BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT)
  2956. & BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
  2957. bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, value);
  2958. err = bcm43xx_pcicore_commit_settings(bcm);
  2959. assert(err == 0);
  2960. }
  2961. out_switch_back:
  2962. err = bcm43xx_switch_core(bcm, old_core);
  2963. out:
  2964. return err;
  2965. }
  2966. static void bcm43xx_softmac_init(struct bcm43xx_private *bcm)
  2967. {
  2968. ieee80211softmac_start(bcm->net_dev);
  2969. }
  2970. static void bcm43xx_periodic_work0_handler(void *d)
  2971. {
  2972. struct bcm43xx_private *bcm = d;
  2973. unsigned long flags;
  2974. //TODO: unsigned int aci_average;
  2975. spin_lock_irqsave(&bcm->lock, flags);
  2976. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_G) {
  2977. //FIXME: aci_average = bcm43xx_update_aci_average(bcm);
  2978. if (bcm->current_core->radio->aci_enable && bcm->current_core->radio->aci_wlan_automatic) {
  2979. bcm43xx_mac_suspend(bcm);
  2980. if (!bcm->current_core->radio->aci_enable &&
  2981. 1 /*FIXME: We are not scanning? */) {
  2982. /*FIXME: First add bcm43xx_update_aci_average() before
  2983. * uncommenting this: */
  2984. //if (bcm43xx_radio_aci_scan)
  2985. // bcm43xx_radio_set_interference_mitigation(bcm,
  2986. // BCM43xx_RADIO_INTERFMODE_MANUALWLAN);
  2987. } else if (1/*FIXME*/) {
  2988. //if ((aci_average > 1000) && !(bcm43xx_radio_aci_scan(bcm)))
  2989. // bcm43xx_radio_set_interference_mitigation(bcm,
  2990. // BCM43xx_RADIO_INTERFMODE_MANUALWLAN);
  2991. }
  2992. bcm43xx_mac_enable(bcm);
  2993. } else if (bcm->current_core->radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN) {
  2994. if (bcm->current_core->phy->rev == 1) {
  2995. //FIXME: implement rev1 workaround
  2996. }
  2997. }
  2998. }
  2999. bcm43xx_phy_xmitpower(bcm); //FIXME: unless scanning?
  3000. //TODO for APHY (temperature?)
  3001. if (likely(!bcm->shutting_down)) {
  3002. queue_delayed_work(bcm->workqueue, &bcm->periodic_work0,
  3003. BCM43xx_PERIODIC_0_DELAY);
  3004. }
  3005. spin_unlock_irqrestore(&bcm->lock, flags);
  3006. }
  3007. static void bcm43xx_periodic_work1_handler(void *d)
  3008. {
  3009. struct bcm43xx_private *bcm = d;
  3010. unsigned long flags;
  3011. spin_lock_irqsave(&bcm->lock, flags);
  3012. bcm43xx_phy_lo_mark_all_unused(bcm);
  3013. if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
  3014. bcm43xx_mac_suspend(bcm);
  3015. bcm43xx_calc_nrssi_slope(bcm);
  3016. bcm43xx_mac_enable(bcm);
  3017. }
  3018. if (likely(!bcm->shutting_down)) {
  3019. queue_delayed_work(bcm->workqueue, &bcm->periodic_work1,
  3020. BCM43xx_PERIODIC_1_DELAY);
  3021. }
  3022. spin_unlock_irqrestore(&bcm->lock, flags);
  3023. }
  3024. static void bcm43xx_periodic_work2_handler(void *d)
  3025. {
  3026. struct bcm43xx_private *bcm = d;
  3027. unsigned long flags;
  3028. spin_lock_irqsave(&bcm->lock, flags);
  3029. assert(bcm->current_core->phy->type == BCM43xx_PHYTYPE_G);
  3030. assert(bcm->current_core->phy->rev >= 2);
  3031. bcm43xx_mac_suspend(bcm);
  3032. bcm43xx_phy_lo_g_measure(bcm);
  3033. bcm43xx_mac_enable(bcm);
  3034. if (likely(!bcm->shutting_down)) {
  3035. queue_delayed_work(bcm->workqueue, &bcm->periodic_work2,
  3036. BCM43xx_PERIODIC_2_DELAY);
  3037. }
  3038. spin_unlock_irqrestore(&bcm->lock, flags);
  3039. }
  3040. static void bcm43xx_periodic_work3_handler(void *d)
  3041. {
  3042. struct bcm43xx_private *bcm = d;
  3043. unsigned long flags;
  3044. spin_lock_irqsave(&bcm->lock, flags);
  3045. /* Update device statistics. */
  3046. bcm43xx_calculate_link_quality(bcm);
  3047. if (likely(!bcm->shutting_down)) {
  3048. queue_delayed_work(bcm->workqueue, &bcm->periodic_work3,
  3049. BCM43xx_PERIODIC_3_DELAY);
  3050. }
  3051. spin_unlock_irqrestore(&bcm->lock, flags);
  3052. }
  3053. /* Delete all periodic tasks and make
  3054. * sure they are not running any longer
  3055. */
  3056. static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm)
  3057. {
  3058. cancel_delayed_work(&bcm->periodic_work0);
  3059. cancel_delayed_work(&bcm->periodic_work1);
  3060. cancel_delayed_work(&bcm->periodic_work2);
  3061. cancel_delayed_work(&bcm->periodic_work3);
  3062. flush_workqueue(bcm->workqueue);
  3063. }
  3064. /* Setup all periodic tasks. */
  3065. static void bcm43xx_periodic_tasks_setup(struct bcm43xx_private *bcm)
  3066. {
  3067. INIT_WORK(&bcm->periodic_work0, bcm43xx_periodic_work0_handler, bcm);
  3068. INIT_WORK(&bcm->periodic_work1, bcm43xx_periodic_work1_handler, bcm);
  3069. INIT_WORK(&bcm->periodic_work2, bcm43xx_periodic_work2_handler, bcm);
  3070. INIT_WORK(&bcm->periodic_work3, bcm43xx_periodic_work3_handler, bcm);
  3071. /* Periodic task 0: Delay ~15sec */
  3072. queue_delayed_work(bcm->workqueue, &bcm->periodic_work0,
  3073. BCM43xx_PERIODIC_0_DELAY);
  3074. /* Periodic task 1: Delay ~60sec */
  3075. queue_delayed_work(bcm->workqueue, &bcm->periodic_work1,
  3076. BCM43xx_PERIODIC_1_DELAY);
  3077. /* Periodic task 2: Delay ~120sec */
  3078. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_G &&
  3079. bcm->current_core->phy->rev >= 2) {
  3080. queue_delayed_work(bcm->workqueue, &bcm->periodic_work2,
  3081. BCM43xx_PERIODIC_2_DELAY);
  3082. }
  3083. /* Periodic task 3: Delay ~30sec */
  3084. queue_delayed_work(bcm->workqueue, &bcm->periodic_work3,
  3085. BCM43xx_PERIODIC_3_DELAY);
  3086. }
  3087. static void bcm43xx_security_init(struct bcm43xx_private *bcm)
  3088. {
  3089. bcm->security_offset = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
  3090. 0x0056) * 2;
  3091. bcm43xx_clear_keys(bcm);
  3092. }
  3093. /* This is the opposite of bcm43xx_init_board() */
  3094. static void bcm43xx_free_board(struct bcm43xx_private *bcm)
  3095. {
  3096. int i, err;
  3097. unsigned long flags;
  3098. spin_lock_irqsave(&bcm->lock, flags);
  3099. bcm->initialized = 0;
  3100. bcm->shutting_down = 1;
  3101. spin_unlock_irqrestore(&bcm->lock, flags);
  3102. bcm43xx_periodic_tasks_delete(bcm);
  3103. for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
  3104. if (!(bcm->core_80211[i].flags & BCM43xx_COREFLAG_AVAILABLE))
  3105. continue;
  3106. if (!(bcm->core_80211[i].flags & BCM43xx_COREFLAG_INITIALIZED))
  3107. continue;
  3108. err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
  3109. assert(err == 0);
  3110. bcm43xx_wireless_core_cleanup(bcm);
  3111. }
  3112. bcm43xx_pctl_set_crystal(bcm, 0);
  3113. spin_lock_irqsave(&bcm->lock, flags);
  3114. bcm->shutting_down = 0;
  3115. spin_unlock_irqrestore(&bcm->lock, flags);
  3116. }
  3117. static int bcm43xx_init_board(struct bcm43xx_private *bcm)
  3118. {
  3119. int i, err;
  3120. int num_80211_cores;
  3121. int connect_phy;
  3122. unsigned long flags;
  3123. might_sleep();
  3124. spin_lock_irqsave(&bcm->lock, flags);
  3125. bcm->initialized = 0;
  3126. bcm->shutting_down = 0;
  3127. spin_unlock_irqrestore(&bcm->lock, flags);
  3128. err = bcm43xx_pctl_set_crystal(bcm, 1);
  3129. if (err)
  3130. goto out;
  3131. err = bcm43xx_pctl_init(bcm);
  3132. if (err)
  3133. goto err_crystal_off;
  3134. err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_FAST);
  3135. if (err)
  3136. goto err_crystal_off;
  3137. tasklet_enable(&bcm->isr_tasklet);
  3138. num_80211_cores = bcm43xx_num_80211_cores(bcm);
  3139. for (i = 0; i < num_80211_cores; i++) {
  3140. err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
  3141. assert(err != -ENODEV);
  3142. if (err)
  3143. goto err_80211_unwind;
  3144. /* Enable the selected wireless core.
  3145. * Connect PHY only on the first core.
  3146. */
  3147. if (!bcm43xx_core_enabled(bcm)) {
  3148. if (num_80211_cores == 1) {
  3149. connect_phy = bcm->current_core->phy->connected;
  3150. } else {
  3151. if (i == 0)
  3152. connect_phy = 1;
  3153. else
  3154. connect_phy = 0;
  3155. }
  3156. bcm43xx_wireless_core_reset(bcm, connect_phy);
  3157. }
  3158. if (i != 0)
  3159. bcm43xx_wireless_core_mark_inactive(bcm, &bcm->core_80211[0]);
  3160. err = bcm43xx_wireless_core_init(bcm);
  3161. if (err)
  3162. goto err_80211_unwind;
  3163. if (i != 0) {
  3164. bcm43xx_mac_suspend(bcm);
  3165. bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  3166. bcm43xx_radio_turn_off(bcm);
  3167. }
  3168. }
  3169. bcm->active_80211_core = &bcm->core_80211[0];
  3170. if (num_80211_cores >= 2) {
  3171. bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
  3172. bcm43xx_mac_enable(bcm);
  3173. }
  3174. bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
  3175. bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_SELF, (u8 *)(bcm->net_dev->dev_addr));
  3176. dprintk(KERN_INFO PFX "80211 cores initialized\n");
  3177. bcm43xx_security_init(bcm);
  3178. bcm43xx_softmac_init(bcm);
  3179. bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_DYNAMIC);
  3180. spin_lock_irqsave(&bcm->lock, flags);
  3181. bcm->initialized = 1;
  3182. spin_unlock_irqrestore(&bcm->lock, flags);
  3183. if (bcm->current_core->radio->initial_channel != 0xFF) {
  3184. bcm43xx_mac_suspend(bcm);
  3185. bcm43xx_radio_selectchannel(bcm, bcm->current_core->radio->initial_channel, 0);
  3186. bcm43xx_mac_enable(bcm);
  3187. }
  3188. bcm43xx_periodic_tasks_setup(bcm);
  3189. assert(err == 0);
  3190. out:
  3191. return err;
  3192. err_80211_unwind:
  3193. tasklet_disable(&bcm->isr_tasklet);
  3194. /* unwind all 80211 initialization */
  3195. for (i = 0; i < num_80211_cores; i++) {
  3196. if (!(bcm->core_80211[i].flags & BCM43xx_COREFLAG_INITIALIZED))
  3197. continue;
  3198. bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  3199. bcm43xx_wireless_core_cleanup(bcm);
  3200. }
  3201. err_crystal_off:
  3202. bcm43xx_pctl_set_crystal(bcm, 0);
  3203. goto out;
  3204. }
  3205. static void bcm43xx_detach_board(struct bcm43xx_private *bcm)
  3206. {
  3207. struct pci_dev *pci_dev = bcm->pci_dev;
  3208. int i;
  3209. bcm43xx_chipset_detach(bcm);
  3210. /* Do _not_ access the chip, after it is detached. */
  3211. iounmap(bcm->mmio_addr);
  3212. pci_release_regions(pci_dev);
  3213. pci_disable_device(pci_dev);
  3214. /* Free allocated structures/fields */
  3215. for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
  3216. kfree(bcm->phy[i]._lo_pairs);
  3217. if (bcm->phy[i].dyn_tssi_tbl)
  3218. kfree(bcm->phy[i].tssi2dbm);
  3219. }
  3220. }
  3221. static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
  3222. {
  3223. u16 value;
  3224. u8 phy_version;
  3225. u8 phy_type;
  3226. u8 phy_rev;
  3227. int phy_rev_ok = 1;
  3228. void *p;
  3229. value = bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER);
  3230. phy_version = (value & 0xF000) >> 12;
  3231. phy_type = (value & 0x0F00) >> 8;
  3232. phy_rev = (value & 0x000F);
  3233. dprintk(KERN_INFO PFX "Detected PHY: Version: %x, Type %x, Revision %x\n",
  3234. phy_version, phy_type, phy_rev);
  3235. switch (phy_type) {
  3236. case BCM43xx_PHYTYPE_A:
  3237. if (phy_rev >= 4)
  3238. phy_rev_ok = 0;
  3239. /*FIXME: We need to switch the ieee->modulation, etc.. flags,
  3240. * if we switch 80211 cores after init is done.
  3241. * As we do not implement on the fly switching between
  3242. * wireless cores, I will leave this as a future task.
  3243. */
  3244. bcm->ieee->modulation = IEEE80211_OFDM_MODULATION;
  3245. bcm->ieee->mode = IEEE_A;
  3246. bcm->ieee->freq_band = IEEE80211_52GHZ_BAND |
  3247. IEEE80211_24GHZ_BAND;
  3248. break;
  3249. case BCM43xx_PHYTYPE_B:
  3250. if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6 && phy_rev != 7)
  3251. phy_rev_ok = 0;
  3252. bcm->ieee->modulation = IEEE80211_CCK_MODULATION;
  3253. bcm->ieee->mode = IEEE_B;
  3254. bcm->ieee->freq_band = IEEE80211_24GHZ_BAND;
  3255. break;
  3256. case BCM43xx_PHYTYPE_G:
  3257. if (phy_rev > 7)
  3258. phy_rev_ok = 0;
  3259. bcm->ieee->modulation = IEEE80211_OFDM_MODULATION |
  3260. IEEE80211_CCK_MODULATION;
  3261. bcm->ieee->mode = IEEE_G;
  3262. bcm->ieee->freq_band = IEEE80211_24GHZ_BAND;
  3263. break;
  3264. default:
  3265. printk(KERN_ERR PFX "Error: Unknown PHY Type %x\n",
  3266. phy_type);
  3267. return -ENODEV;
  3268. };
  3269. if (!phy_rev_ok) {
  3270. printk(KERN_WARNING PFX "Invalid PHY Revision %x\n",
  3271. phy_rev);
  3272. }
  3273. bcm->current_core->phy->version = phy_version;
  3274. bcm->current_core->phy->type = phy_type;
  3275. bcm->current_core->phy->rev = phy_rev;
  3276. if ((phy_type == BCM43xx_PHYTYPE_B) || (phy_type == BCM43xx_PHYTYPE_G)) {
  3277. p = kzalloc(sizeof(struct bcm43xx_lopair) * BCM43xx_LO_COUNT,
  3278. GFP_KERNEL);
  3279. if (!p)
  3280. return -ENOMEM;
  3281. bcm->current_core->phy->_lo_pairs = p;
  3282. }
  3283. return 0;
  3284. }
  3285. static int bcm43xx_attach_board(struct bcm43xx_private *bcm)
  3286. {
  3287. struct pci_dev *pci_dev = bcm->pci_dev;
  3288. struct net_device *net_dev = bcm->net_dev;
  3289. int err;
  3290. int i;
  3291. void __iomem *ioaddr;
  3292. unsigned long mmio_start, mmio_end, mmio_flags, mmio_len;
  3293. int num_80211_cores;
  3294. u32 coremask;
  3295. err = pci_enable_device(pci_dev);
  3296. if (err) {
  3297. printk(KERN_ERR PFX "unable to wake up pci device (%i)\n", err);
  3298. err = -ENODEV;
  3299. goto out;
  3300. }
  3301. mmio_start = pci_resource_start(pci_dev, 0);
  3302. mmio_end = pci_resource_end(pci_dev, 0);
  3303. mmio_flags = pci_resource_flags(pci_dev, 0);
  3304. mmio_len = pci_resource_len(pci_dev, 0);
  3305. /* make sure PCI base addr is MMIO */
  3306. if (!(mmio_flags & IORESOURCE_MEM)) {
  3307. printk(KERN_ERR PFX
  3308. "%s, region #0 not an MMIO resource, aborting\n",
  3309. pci_name(pci_dev));
  3310. err = -ENODEV;
  3311. goto err_pci_disable;
  3312. }
  3313. //FIXME: Why is this check disabled for BCM947XX? What is the IO_SIZE there?
  3314. #ifndef CONFIG_BCM947XX
  3315. if (mmio_len != BCM43xx_IO_SIZE) {
  3316. printk(KERN_ERR PFX
  3317. "%s: invalid PCI mem region size(s), aborting\n",
  3318. pci_name(pci_dev));
  3319. err = -ENODEV;
  3320. goto err_pci_disable;
  3321. }
  3322. #endif
  3323. err = pci_request_regions(pci_dev, DRV_NAME);
  3324. if (err) {
  3325. printk(KERN_ERR PFX
  3326. "could not access PCI resources (%i)\n", err);
  3327. goto err_pci_disable;
  3328. }
  3329. /* enable PCI bus-mastering */
  3330. pci_set_master(pci_dev);
  3331. /* ioremap MMIO region */
  3332. ioaddr = ioremap(mmio_start, mmio_len);
  3333. if (!ioaddr) {
  3334. printk(KERN_ERR PFX "%s: cannot remap MMIO, aborting\n",
  3335. pci_name(pci_dev));
  3336. err = -EIO;
  3337. goto err_pci_release;
  3338. }
  3339. net_dev->base_addr = (unsigned long)ioaddr;
  3340. bcm->mmio_addr = ioaddr;
  3341. bcm->mmio_len = mmio_len;
  3342. bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_VENDOR_ID,
  3343. &bcm->board_vendor);
  3344. bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_ID,
  3345. &bcm->board_type);
  3346. bcm43xx_pci_read_config16(bcm, PCI_REVISION_ID,
  3347. &bcm->board_revision);
  3348. err = bcm43xx_chipset_attach(bcm);
  3349. if (err)
  3350. goto err_iounmap;
  3351. err = bcm43xx_pctl_init(bcm);
  3352. if (err)
  3353. goto err_chipset_detach;
  3354. err = bcm43xx_probe_cores(bcm);
  3355. if (err)
  3356. goto err_chipset_detach;
  3357. num_80211_cores = bcm43xx_num_80211_cores(bcm);
  3358. /* Attach all IO cores to the backplane. */
  3359. coremask = 0;
  3360. for (i = 0; i < num_80211_cores; i++)
  3361. coremask |= (1 << bcm->core_80211[i].index);
  3362. //FIXME: Also attach some non80211 cores?
  3363. err = bcm43xx_setup_backplane_pci_connection(bcm, coremask);
  3364. if (err) {
  3365. printk(KERN_ERR PFX "Backplane->PCI connection failed!\n");
  3366. goto err_chipset_detach;
  3367. }
  3368. err = bcm43xx_read_sprom(bcm);
  3369. if (err)
  3370. goto err_chipset_detach;
  3371. err = bcm43xx_leds_init(bcm);
  3372. if (err)
  3373. goto err_chipset_detach;
  3374. for (i = 0; i < num_80211_cores; i++) {
  3375. err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
  3376. assert(err != -ENODEV);
  3377. if (err)
  3378. goto err_80211_unwind;
  3379. /* Enable the selected wireless core.
  3380. * Connect PHY only on the first core.
  3381. */
  3382. bcm43xx_wireless_core_reset(bcm, (i == 0));
  3383. err = bcm43xx_read_phyinfo(bcm);
  3384. if (err && (i == 0))
  3385. goto err_80211_unwind;
  3386. err = bcm43xx_read_radioinfo(bcm);
  3387. if (err && (i == 0))
  3388. goto err_80211_unwind;
  3389. err = bcm43xx_validate_chip(bcm);
  3390. if (err && (i == 0))
  3391. goto err_80211_unwind;
  3392. bcm43xx_radio_turn_off(bcm);
  3393. err = bcm43xx_phy_init_tssi2dbm_table(bcm);
  3394. if (err)
  3395. goto err_80211_unwind;
  3396. bcm43xx_wireless_core_disable(bcm);
  3397. }
  3398. bcm43xx_pctl_set_crystal(bcm, 0);
  3399. /* Set the MAC address in the networking subsystem */
  3400. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A)
  3401. memcpy(bcm->net_dev->dev_addr, bcm->sprom.et1macaddr, 6);
  3402. else
  3403. memcpy(bcm->net_dev->dev_addr, bcm->sprom.il0macaddr, 6);
  3404. bcm43xx_geo_init(bcm);
  3405. snprintf(bcm->nick, IW_ESSID_MAX_SIZE,
  3406. "Broadcom %04X", bcm->chip_id);
  3407. assert(err == 0);
  3408. out:
  3409. return err;
  3410. err_80211_unwind:
  3411. for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
  3412. kfree(bcm->phy[i]._lo_pairs);
  3413. if (bcm->phy[i].dyn_tssi_tbl)
  3414. kfree(bcm->phy[i].tssi2dbm);
  3415. }
  3416. err_chipset_detach:
  3417. bcm43xx_chipset_detach(bcm);
  3418. err_iounmap:
  3419. iounmap(bcm->mmio_addr);
  3420. err_pci_release:
  3421. pci_release_regions(pci_dev);
  3422. err_pci_disable:
  3423. pci_disable_device(pci_dev);
  3424. goto out;
  3425. }
  3426. static inline
  3427. s8 bcm43xx_rssi_postprocess(struct bcm43xx_private *bcm, u8 in_rssi,
  3428. int ofdm, int adjust_2053, int adjust_2050)
  3429. {
  3430. s32 tmp;
  3431. switch (bcm->current_core->radio->version) {
  3432. case 0x2050:
  3433. if (ofdm) {
  3434. tmp = in_rssi;
  3435. if (tmp > 127)
  3436. tmp -= 256;
  3437. tmp *= 73;
  3438. tmp /= 64;
  3439. if (adjust_2050)
  3440. tmp += 25;
  3441. else
  3442. tmp -= 3;
  3443. } else {
  3444. if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
  3445. if (in_rssi > 63)
  3446. in_rssi = 63;
  3447. tmp = bcm->current_core->radio->nrssi_lt[in_rssi];
  3448. tmp = 31 - tmp;
  3449. tmp *= -131;
  3450. tmp /= 128;
  3451. tmp -= 57;
  3452. } else {
  3453. tmp = in_rssi;
  3454. tmp = 31 - tmp;
  3455. tmp *= -149;
  3456. tmp /= 128;
  3457. tmp -= 68;
  3458. }
  3459. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_G &&
  3460. adjust_2050)
  3461. tmp += 25;
  3462. }
  3463. break;
  3464. case 0x2060:
  3465. if (in_rssi > 127)
  3466. tmp = in_rssi - 256;
  3467. else
  3468. tmp = in_rssi;
  3469. break;
  3470. default:
  3471. tmp = in_rssi;
  3472. tmp -= 11;
  3473. tmp *= 103;
  3474. tmp /= 64;
  3475. if (adjust_2053)
  3476. tmp -= 109;
  3477. else
  3478. tmp -= 83;
  3479. }
  3480. return (s8)tmp;
  3481. }
  3482. static inline
  3483. s8 bcm43xx_rssinoise_postprocess(struct bcm43xx_private *bcm, u8 in_rssi)
  3484. {
  3485. s8 ret;
  3486. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A) {
  3487. //TODO: Incomplete specs.
  3488. ret = 0;
  3489. } else
  3490. ret = bcm43xx_rssi_postprocess(bcm, in_rssi, 0, 1, 1);
  3491. return ret;
  3492. }
  3493. static inline
  3494. int bcm43xx_rx_packet(struct bcm43xx_private *bcm,
  3495. struct sk_buff *skb,
  3496. struct ieee80211_rx_stats *stats)
  3497. {
  3498. int err;
  3499. err = ieee80211_rx(bcm->ieee, skb, stats);
  3500. if (unlikely(err == 0))
  3501. return -EINVAL;
  3502. return 0;
  3503. }
  3504. int fastcall bcm43xx_rx(struct bcm43xx_private *bcm,
  3505. struct sk_buff *skb,
  3506. struct bcm43xx_rxhdr *rxhdr)
  3507. {
  3508. struct bcm43xx_plcp_hdr4 *plcp;
  3509. struct ieee80211_rx_stats stats;
  3510. struct ieee80211_hdr_4addr *wlhdr;
  3511. u16 frame_ctl;
  3512. int is_packet_for_us = 0;
  3513. int err = -EINVAL;
  3514. const u16 rxflags1 = le16_to_cpu(rxhdr->flags1);
  3515. const u16 rxflags2 = le16_to_cpu(rxhdr->flags2);
  3516. const u16 rxflags3 = le16_to_cpu(rxhdr->flags3);
  3517. const int is_ofdm = !!(rxflags1 & BCM43xx_RXHDR_FLAGS1_OFDM);
  3518. if (rxflags2 & BCM43xx_RXHDR_FLAGS2_TYPE2FRAME) {
  3519. plcp = (struct bcm43xx_plcp_hdr4 *)(skb->data + 2);
  3520. /* Skip two unknown bytes and the PLCP header. */
  3521. skb_pull(skb, 2 + sizeof(struct bcm43xx_plcp_hdr6));
  3522. } else {
  3523. plcp = (struct bcm43xx_plcp_hdr4 *)(skb->data);
  3524. /* Skip the PLCP header. */
  3525. skb_pull(skb, sizeof(struct bcm43xx_plcp_hdr6));
  3526. }
  3527. /* The SKB contains the PAYLOAD (wireless header + data)
  3528. * at this point. The FCS at the end is stripped.
  3529. */
  3530. memset(&stats, 0, sizeof(stats));
  3531. stats.mac_time = le16_to_cpu(rxhdr->mactime);
  3532. stats.rssi = bcm43xx_rssi_postprocess(bcm, rxhdr->rssi, is_ofdm,
  3533. !!(rxflags1 & BCM43xx_RXHDR_FLAGS1_2053RSSIADJ),
  3534. !!(rxflags3 & BCM43xx_RXHDR_FLAGS3_2050RSSIADJ));
  3535. stats.signal = rxhdr->signal_quality; //FIXME
  3536. //TODO stats.noise =
  3537. stats.rate = bcm43xx_plcp_get_bitrate(plcp, is_ofdm);
  3538. //printk("RX ofdm %d, rate == %u\n", is_ofdm, stats.rate);
  3539. stats.received_channel = bcm->current_core->radio->channel;
  3540. //TODO stats.control =
  3541. stats.mask = IEEE80211_STATMASK_SIGNAL |
  3542. //TODO IEEE80211_STATMASK_NOISE |
  3543. IEEE80211_STATMASK_RATE |
  3544. IEEE80211_STATMASK_RSSI;
  3545. if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A)
  3546. stats.freq = IEEE80211_52GHZ_BAND;
  3547. else
  3548. stats.freq = IEEE80211_24GHZ_BAND;
  3549. stats.len = skb->len;
  3550. bcm->stats.last_rx = jiffies;
  3551. if (bcm->ieee->iw_mode == IW_MODE_MONITOR)
  3552. return bcm43xx_rx_packet(bcm, skb, &stats);
  3553. wlhdr = (struct ieee80211_hdr_4addr *)(skb->data);
  3554. switch (bcm->ieee->iw_mode) {
  3555. case IW_MODE_ADHOC:
  3556. if (memcmp(wlhdr->addr1, bcm->net_dev->dev_addr, ETH_ALEN) == 0 ||
  3557. memcmp(wlhdr->addr3, bcm->ieee->bssid, ETH_ALEN) == 0 ||
  3558. is_broadcast_ether_addr(wlhdr->addr1) ||
  3559. is_multicast_ether_addr(wlhdr->addr1) ||
  3560. bcm->net_dev->flags & IFF_PROMISC)
  3561. is_packet_for_us = 1;
  3562. break;
  3563. case IW_MODE_INFRA:
  3564. default:
  3565. /* When receiving multicast or broadcast packets, filter out
  3566. the packets we send ourself; we shouldn't see those */
  3567. if (memcmp(wlhdr->addr3, bcm->ieee->bssid, ETH_ALEN) == 0 ||
  3568. memcmp(wlhdr->addr1, bcm->net_dev->dev_addr, ETH_ALEN) == 0 ||
  3569. (memcmp(wlhdr->addr3, bcm->net_dev->dev_addr, ETH_ALEN) &&
  3570. (is_broadcast_ether_addr(wlhdr->addr1) ||
  3571. is_multicast_ether_addr(wlhdr->addr1) ||
  3572. bcm->net_dev->flags & IFF_PROMISC)))
  3573. is_packet_for_us = 1;
  3574. break;
  3575. }
  3576. frame_ctl = le16_to_cpu(wlhdr->frame_ctl);
  3577. if ((frame_ctl & IEEE80211_FCTL_PROTECTED) && !bcm->ieee->host_decrypt) {
  3578. frame_ctl &= ~IEEE80211_FCTL_PROTECTED;
  3579. wlhdr->frame_ctl = cpu_to_le16(frame_ctl);
  3580. /* trim IV and ICV */
  3581. /* FIXME: this must be done only for WEP encrypted packets */
  3582. if (skb->len < 32) {
  3583. dprintkl(KERN_ERR PFX "RX packet dropped (PROTECTED flag "
  3584. "set and length < 32)\n");
  3585. return -EINVAL;
  3586. } else {
  3587. memmove(skb->data + 4, skb->data, 24);
  3588. skb_pull(skb, 4);
  3589. skb_trim(skb, skb->len - 4);
  3590. stats.len -= 8;
  3591. }
  3592. wlhdr = (struct ieee80211_hdr_4addr *)(skb->data);
  3593. }
  3594. switch (WLAN_FC_GET_TYPE(frame_ctl)) {
  3595. case IEEE80211_FTYPE_MGMT:
  3596. ieee80211_rx_mgt(bcm->ieee, wlhdr, &stats);
  3597. break;
  3598. case IEEE80211_FTYPE_DATA:
  3599. if (is_packet_for_us)
  3600. err = bcm43xx_rx_packet(bcm, skb, &stats);
  3601. break;
  3602. case IEEE80211_FTYPE_CTL:
  3603. break;
  3604. default:
  3605. assert(0);
  3606. return -EINVAL;
  3607. }
  3608. return err;
  3609. }
  3610. /* Do the Hardware IO operations to send the txb */
  3611. static inline int bcm43xx_tx(struct bcm43xx_private *bcm,
  3612. struct ieee80211_txb *txb)
  3613. {
  3614. int err = -ENODEV;
  3615. if (bcm->pio_mode)
  3616. err = bcm43xx_pio_transfer_txb(bcm, txb);
  3617. else
  3618. err = bcm43xx_dma_tx(bcm, txb);
  3619. return err;
  3620. }
  3621. static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev,
  3622. u8 channel)
  3623. {
  3624. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3625. unsigned long flags;
  3626. spin_lock_irqsave(&bcm->lock, flags);
  3627. bcm43xx_mac_suspend(bcm);
  3628. bcm43xx_radio_selectchannel(bcm, channel, 0);
  3629. bcm43xx_mac_enable(bcm);
  3630. spin_unlock_irqrestore(&bcm->lock, flags);
  3631. }
  3632. /* set_security() callback in struct ieee80211_device */
  3633. static void bcm43xx_ieee80211_set_security(struct net_device *net_dev,
  3634. struct ieee80211_security *sec)
  3635. {
  3636. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3637. struct ieee80211_security *secinfo = &bcm->ieee->sec;
  3638. unsigned long flags;
  3639. int keyidx;
  3640. dprintk(KERN_INFO PFX "set security called\n");
  3641. spin_lock_irqsave(&bcm->lock, flags);
  3642. for (keyidx = 0; keyidx<WEP_KEYS; keyidx++)
  3643. if (sec->flags & (1<<keyidx)) {
  3644. secinfo->encode_alg[keyidx] = sec->encode_alg[keyidx];
  3645. secinfo->key_sizes[keyidx] = sec->key_sizes[keyidx];
  3646. memcpy(secinfo->keys[keyidx], sec->keys[keyidx], SCM_KEY_LEN);
  3647. }
  3648. if (sec->flags & SEC_ACTIVE_KEY) {
  3649. secinfo->active_key = sec->active_key;
  3650. dprintk(KERN_INFO PFX " .active_key = %d\n", sec->active_key);
  3651. }
  3652. if (sec->flags & SEC_UNICAST_GROUP) {
  3653. secinfo->unicast_uses_group = sec->unicast_uses_group;
  3654. dprintk(KERN_INFO PFX " .unicast_uses_group = %d\n", sec->unicast_uses_group);
  3655. }
  3656. if (sec->flags & SEC_LEVEL) {
  3657. secinfo->level = sec->level;
  3658. dprintk(KERN_INFO PFX " .level = %d\n", sec->level);
  3659. }
  3660. if (sec->flags & SEC_ENABLED) {
  3661. secinfo->enabled = sec->enabled;
  3662. dprintk(KERN_INFO PFX " .enabled = %d\n", sec->enabled);
  3663. }
  3664. if (sec->flags & SEC_ENCRYPT) {
  3665. secinfo->encrypt = sec->encrypt;
  3666. dprintk(KERN_INFO PFX " .encrypt = %d\n", sec->encrypt);
  3667. }
  3668. if (bcm->initialized && !bcm->ieee->host_encrypt) {
  3669. if (secinfo->enabled) {
  3670. /* upload WEP keys to hardware */
  3671. char null_address[6] = { 0 };
  3672. u8 algorithm = 0;
  3673. for (keyidx = 0; keyidx<WEP_KEYS; keyidx++) {
  3674. if (!(sec->flags & (1<<keyidx)))
  3675. continue;
  3676. switch (sec->encode_alg[keyidx]) {
  3677. case SEC_ALG_NONE: algorithm = BCM43xx_SEC_ALGO_NONE; break;
  3678. case SEC_ALG_WEP:
  3679. algorithm = BCM43xx_SEC_ALGO_WEP;
  3680. if (secinfo->key_sizes[keyidx] == 13)
  3681. algorithm = BCM43xx_SEC_ALGO_WEP104;
  3682. break;
  3683. case SEC_ALG_TKIP:
  3684. FIXME();
  3685. algorithm = BCM43xx_SEC_ALGO_TKIP;
  3686. break;
  3687. case SEC_ALG_CCMP:
  3688. FIXME();
  3689. algorithm = BCM43xx_SEC_ALGO_AES;
  3690. break;
  3691. default:
  3692. assert(0);
  3693. break;
  3694. }
  3695. bcm43xx_key_write(bcm, keyidx, algorithm, sec->keys[keyidx], secinfo->key_sizes[keyidx], &null_address[0]);
  3696. bcm->key[keyidx].enabled = 1;
  3697. bcm->key[keyidx].algorithm = algorithm;
  3698. }
  3699. } else
  3700. bcm43xx_clear_keys(bcm);
  3701. }
  3702. spin_unlock_irqrestore(&bcm->lock, flags);
  3703. }
  3704. /* hard_start_xmit() callback in struct ieee80211_device */
  3705. static int bcm43xx_ieee80211_hard_start_xmit(struct ieee80211_txb *txb,
  3706. struct net_device *net_dev,
  3707. int pri)
  3708. {
  3709. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3710. int err = -ENODEV;
  3711. unsigned long flags;
  3712. spin_lock_irqsave(&bcm->lock, flags);
  3713. if (likely(bcm->initialized))
  3714. err = bcm43xx_tx(bcm, txb);
  3715. spin_unlock_irqrestore(&bcm->lock, flags);
  3716. return err;
  3717. }
  3718. static struct net_device_stats * bcm43xx_net_get_stats(struct net_device *net_dev)
  3719. {
  3720. return &(bcm43xx_priv(net_dev)->ieee->stats);
  3721. }
  3722. static void bcm43xx_net_tx_timeout(struct net_device *net_dev)
  3723. {
  3724. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3725. bcm43xx_controller_restart(bcm, "TX timeout");
  3726. }
  3727. #ifdef CONFIG_NET_POLL_CONTROLLER
  3728. static void bcm43xx_net_poll_controller(struct net_device *net_dev)
  3729. {
  3730. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3731. unsigned long flags;
  3732. local_irq_save(flags);
  3733. bcm43xx_interrupt_handler(bcm->irq, bcm, NULL);
  3734. local_irq_restore(flags);
  3735. }
  3736. #endif /* CONFIG_NET_POLL_CONTROLLER */
  3737. static int bcm43xx_net_open(struct net_device *net_dev)
  3738. {
  3739. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3740. return bcm43xx_init_board(bcm);
  3741. }
  3742. static int bcm43xx_net_stop(struct net_device *net_dev)
  3743. {
  3744. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3745. ieee80211softmac_stop(net_dev);
  3746. bcm43xx_disable_interrupts_sync(bcm, NULL);
  3747. bcm43xx_free_board(bcm);
  3748. return 0;
  3749. }
  3750. static void bcm43xx_init_private(struct bcm43xx_private *bcm,
  3751. struct net_device *net_dev,
  3752. struct pci_dev *pci_dev,
  3753. struct workqueue_struct *wq)
  3754. {
  3755. bcm->ieee = netdev_priv(net_dev);
  3756. bcm->softmac = ieee80211_priv(net_dev);
  3757. bcm->softmac->set_channel = bcm43xx_ieee80211_set_chan;
  3758. bcm->workqueue = wq;
  3759. #ifdef DEBUG_ENABLE_MMIO_PRINT
  3760. bcm43xx_mmioprint_initial(bcm, 1);
  3761. #else
  3762. bcm43xx_mmioprint_initial(bcm, 0);
  3763. #endif
  3764. #ifdef DEBUG_ENABLE_PCILOG
  3765. bcm43xx_pciprint_initial(bcm, 1);
  3766. #else
  3767. bcm43xx_pciprint_initial(bcm, 0);
  3768. #endif
  3769. bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
  3770. bcm->pci_dev = pci_dev;
  3771. bcm->net_dev = net_dev;
  3772. if (modparam_bad_frames_preempt)
  3773. bcm->bad_frames_preempt = 1;
  3774. spin_lock_init(&bcm->lock);
  3775. tasklet_init(&bcm->isr_tasklet,
  3776. (void (*)(unsigned long))bcm43xx_interrupt_tasklet,
  3777. (unsigned long)bcm);
  3778. tasklet_disable_nosync(&bcm->isr_tasklet);
  3779. if (modparam_pio) {
  3780. bcm->pio_mode = 1;
  3781. } else {
  3782. if (pci_set_dma_mask(pci_dev, DMA_30BIT_MASK) == 0) {
  3783. bcm->pio_mode = 0;
  3784. } else {
  3785. printk(KERN_WARNING PFX "DMA not supported. Falling back to PIO.\n");
  3786. bcm->pio_mode = 1;
  3787. }
  3788. }
  3789. bcm->rts_threshold = BCM43xx_DEFAULT_RTS_THRESHOLD;
  3790. /* default to sw encryption for now */
  3791. bcm->ieee->host_build_iv = 0;
  3792. bcm->ieee->host_encrypt = 1;
  3793. bcm->ieee->host_decrypt = 1;
  3794. bcm->ieee->iw_mode = BCM43xx_INITIAL_IWMODE;
  3795. bcm->ieee->tx_headroom = sizeof(struct bcm43xx_txhdr);
  3796. bcm->ieee->set_security = bcm43xx_ieee80211_set_security;
  3797. bcm->ieee->hard_start_xmit = bcm43xx_ieee80211_hard_start_xmit;
  3798. }
  3799. static int __devinit bcm43xx_init_one(struct pci_dev *pdev,
  3800. const struct pci_device_id *ent)
  3801. {
  3802. struct net_device *net_dev;
  3803. struct bcm43xx_private *bcm;
  3804. struct workqueue_struct *wq;
  3805. int err;
  3806. #ifdef CONFIG_BCM947XX
  3807. if ((pdev->bus->number == 0) && (pdev->device != 0x0800))
  3808. return -ENODEV;
  3809. #endif
  3810. #ifdef DEBUG_SINGLE_DEVICE_ONLY
  3811. if (strcmp(pci_name(pdev), DEBUG_SINGLE_DEVICE_ONLY))
  3812. return -ENODEV;
  3813. #endif
  3814. net_dev = alloc_ieee80211softmac(sizeof(*bcm));
  3815. if (!net_dev) {
  3816. printk(KERN_ERR PFX
  3817. "could not allocate ieee80211 device %s\n",
  3818. pci_name(pdev));
  3819. err = -ENOMEM;
  3820. goto out;
  3821. }
  3822. /* initialize the net_device struct */
  3823. SET_MODULE_OWNER(net_dev);
  3824. SET_NETDEV_DEV(net_dev, &pdev->dev);
  3825. net_dev->open = bcm43xx_net_open;
  3826. net_dev->stop = bcm43xx_net_stop;
  3827. net_dev->get_stats = bcm43xx_net_get_stats;
  3828. net_dev->tx_timeout = bcm43xx_net_tx_timeout;
  3829. #ifdef CONFIG_NET_POLL_CONTROLLER
  3830. net_dev->poll_controller = bcm43xx_net_poll_controller;
  3831. #endif
  3832. net_dev->wireless_handlers = &bcm43xx_wx_handlers_def;
  3833. net_dev->irq = pdev->irq;
  3834. net_dev->watchdog_timeo = BCM43xx_TX_TIMEOUT;
  3835. /* initialize the bcm43xx_private struct */
  3836. bcm = bcm43xx_priv(net_dev);
  3837. memset(bcm, 0, sizeof(*bcm));
  3838. wq = create_workqueue(DRV_NAME "_wq");
  3839. if (!wq) {
  3840. err = -ENOMEM;
  3841. goto err_free_netdev;
  3842. }
  3843. bcm43xx_init_private(bcm, net_dev, pdev, wq);
  3844. pci_set_drvdata(pdev, net_dev);
  3845. err = bcm43xx_attach_board(bcm);
  3846. if (err)
  3847. goto err_destroy_wq;
  3848. err = register_netdev(net_dev);
  3849. if (err) {
  3850. printk(KERN_ERR PFX "Cannot register net device, "
  3851. "aborting.\n");
  3852. err = -ENOMEM;
  3853. goto err_detach_board;
  3854. }
  3855. bcm43xx_debugfs_add_device(bcm);
  3856. assert(err == 0);
  3857. out:
  3858. return err;
  3859. err_detach_board:
  3860. bcm43xx_detach_board(bcm);
  3861. err_destroy_wq:
  3862. destroy_workqueue(wq);
  3863. err_free_netdev:
  3864. free_ieee80211softmac(net_dev);
  3865. goto out;
  3866. }
  3867. static void __devexit bcm43xx_remove_one(struct pci_dev *pdev)
  3868. {
  3869. struct net_device *net_dev = pci_get_drvdata(pdev);
  3870. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3871. bcm43xx_debugfs_remove_device(bcm);
  3872. unregister_netdev(net_dev);
  3873. bcm43xx_detach_board(bcm);
  3874. assert(bcm->ucode == NULL);
  3875. destroy_workqueue(bcm->workqueue);
  3876. free_ieee80211softmac(net_dev);
  3877. }
  3878. /* Hard-reset the chip. Do not call this directly.
  3879. * Use bcm43xx_controller_restart()
  3880. */
  3881. static void bcm43xx_chip_reset(void *_bcm)
  3882. {
  3883. struct bcm43xx_private *bcm = _bcm;
  3884. struct net_device *net_dev = bcm->net_dev;
  3885. struct pci_dev *pci_dev = bcm->pci_dev;
  3886. struct workqueue_struct *wq = bcm->workqueue;
  3887. int err;
  3888. int was_initialized = bcm->initialized;
  3889. netif_stop_queue(bcm->net_dev);
  3890. tasklet_disable(&bcm->isr_tasklet);
  3891. bcm->firmware_norelease = 1;
  3892. if (was_initialized)
  3893. bcm43xx_free_board(bcm);
  3894. bcm->firmware_norelease = 0;
  3895. bcm43xx_detach_board(bcm);
  3896. bcm43xx_init_private(bcm, net_dev, pci_dev, wq);
  3897. err = bcm43xx_attach_board(bcm);
  3898. if (err)
  3899. goto failure;
  3900. if (was_initialized) {
  3901. err = bcm43xx_init_board(bcm);
  3902. if (err)
  3903. goto failure;
  3904. }
  3905. netif_wake_queue(bcm->net_dev);
  3906. printk(KERN_INFO PFX "Controller restarted\n");
  3907. return;
  3908. failure:
  3909. printk(KERN_ERR PFX "Controller restart failed\n");
  3910. }
  3911. /* Hard-reset the chip.
  3912. * This can be called from interrupt or process context.
  3913. * Make sure to _not_ re-enable device interrupts after this has been called.
  3914. */
  3915. void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason)
  3916. {
  3917. bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  3918. printk(KERN_ERR PFX "Controller RESET (%s) ...\n", reason);
  3919. INIT_WORK(&bcm->restart_work, bcm43xx_chip_reset, bcm);
  3920. queue_work(bcm->workqueue, &bcm->restart_work);
  3921. }
  3922. #ifdef CONFIG_PM
  3923. static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state)
  3924. {
  3925. struct net_device *net_dev = pci_get_drvdata(pdev);
  3926. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3927. unsigned long flags;
  3928. int try_to_shutdown = 0, err;
  3929. dprintk(KERN_INFO PFX "Suspending...\n");
  3930. spin_lock_irqsave(&bcm->lock, flags);
  3931. bcm->was_initialized = bcm->initialized;
  3932. if (bcm->initialized)
  3933. try_to_shutdown = 1;
  3934. spin_unlock_irqrestore(&bcm->lock, flags);
  3935. netif_device_detach(net_dev);
  3936. if (try_to_shutdown) {
  3937. ieee80211softmac_stop(net_dev);
  3938. err = bcm43xx_disable_interrupts_sync(bcm, &bcm->irq_savedstate);
  3939. if (unlikely(err)) {
  3940. dprintk(KERN_ERR PFX "Suspend failed.\n");
  3941. return -EAGAIN;
  3942. }
  3943. bcm->firmware_norelease = 1;
  3944. bcm43xx_free_board(bcm);
  3945. bcm->firmware_norelease = 0;
  3946. }
  3947. bcm43xx_chipset_detach(bcm);
  3948. pci_save_state(pdev);
  3949. pci_disable_device(pdev);
  3950. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  3951. dprintk(KERN_INFO PFX "Device suspended.\n");
  3952. return 0;
  3953. }
  3954. static int bcm43xx_resume(struct pci_dev *pdev)
  3955. {
  3956. struct net_device *net_dev = pci_get_drvdata(pdev);
  3957. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3958. int err = 0;
  3959. dprintk(KERN_INFO PFX "Resuming...\n");
  3960. pci_set_power_state(pdev, 0);
  3961. pci_enable_device(pdev);
  3962. pci_restore_state(pdev);
  3963. bcm43xx_chipset_attach(bcm);
  3964. if (bcm->was_initialized) {
  3965. bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
  3966. err = bcm43xx_init_board(bcm);
  3967. }
  3968. if (err) {
  3969. printk(KERN_ERR PFX "Resume failed!\n");
  3970. return err;
  3971. }
  3972. netif_device_attach(net_dev);
  3973. /*FIXME: This should be handled by softmac instead. */
  3974. schedule_work(&bcm->softmac->associnfo.work);
  3975. dprintk(KERN_INFO PFX "Device resumed.\n");
  3976. return 0;
  3977. }
  3978. #endif /* CONFIG_PM */
  3979. static struct pci_driver bcm43xx_pci_driver = {
  3980. .name = BCM43xx_DRIVER_NAME,
  3981. .id_table = bcm43xx_pci_tbl,
  3982. .probe = bcm43xx_init_one,
  3983. .remove = __devexit_p(bcm43xx_remove_one),
  3984. #ifdef CONFIG_PM
  3985. .suspend = bcm43xx_suspend,
  3986. .resume = bcm43xx_resume,
  3987. #endif /* CONFIG_PM */
  3988. };
  3989. static int __init bcm43xx_init(void)
  3990. {
  3991. printk(KERN_INFO BCM43xx_DRIVER_NAME "\n");
  3992. bcm43xx_debugfs_init();
  3993. return pci_register_driver(&bcm43xx_pci_driver);
  3994. }
  3995. static void __exit bcm43xx_exit(void)
  3996. {
  3997. pci_unregister_driver(&bcm43xx_pci_driver);
  3998. bcm43xx_debugfs_exit();
  3999. }
  4000. module_init(bcm43xx_init)
  4001. module_exit(bcm43xx_exit)
  4002. /* vim: set ts=8 sw=8 sts=8: */