bcm43xx_main.c 114 KB

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