bcm43xx_main.c 109 KB

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