bcm43xx_main.c 116 KB

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